From a12d743a1cf7737c1fcb1fc649977f9261a857ba Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 6 Mar 2021 14:01:25 +0100 Subject: Add astyle formatting script/config (in progress) --- .astylerc | 24 ++++++++++++++++++++++++ format.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .astylerc create mode 100755 format.sh diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000..f7393c2 --- /dev/null +++ b/.astylerc @@ -0,0 +1,24 @@ +# Default style is used as a basis +# See http://astyle.sourceforge.net/astyle.html#_default_brace_style +# +# TODO: Struct members with overlong comments in server/global.h break +# in a very stupid way. Can we fix this here? +indent=force-tab=3 +attach-closing-while +indent-after-parens +indent-continuation=2 +# Space after if, while, for +pad-header +# Pad inside of parens +pad-paren-in +align-pointer=name +# Alignment with spaces +convert-tabs +max-code-length=120 +# Don't create backups +suffix=none +exclude=kernel +exclude=picohttpparser.c +exclude=picohttpdparser.h +exclude=crc32.c +exclude=inc/dnbd3 diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..e0d743c --- /dev/null +++ b/format.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if ! command -v astyle &> /dev/null; then + echo "astyle not found in path" + exit 1 +fi + +fifo="/tmp/format-$(date +%s%N)-$$-$RANDOM" +trap 'rm -f -- "$fifo"' EXIT + +mkfifo "$fifo" + +# TODO: Add ignore here since it doesn't work if we pass explicit file names +# :-( +LANG=C astyle --project --ignore-exclude-errors "$@" | tee "$fifo" | grep '^Formatted' & +# "Formatted src/server/server.h" + +#readarray -d$'\n' -t files < <( < "$fifo" grep '^Formatted' | sed -r 's/^Formatted\s*//' ) + +#for file in "${files[@]}"; do +while read -r file; do + echo "SEDing $file" + sed -i -r \ + 's/\*(const|_Atomic|volatile)/* \1/g;s/\( ((unsigned|const|void|\w+_t|char|int|short|long|struct|sockaddr\w+|\*|\s+)+) \)/(\1)/g' "$file" +done < <( < "$fifo" grep '^Formatted' | sed -r 's/^Formatted\s*//' ) + +wait -- cgit v1.2.3-55-g7522