summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-06 14:01:25 +0100
committerSimon Rettberg2021-03-06 14:01:25 +0100
commita12d743a1cf7737c1fcb1fc649977f9261a857ba (patch)
tree935a6459324534d63129a6536561421a48d9a6ce
parent[BUILD] Add Github workflow to validate (lint) source code (diff)
downloaddnbd3-formatting.tar.gz
dnbd3-formatting.tar.xz
dnbd3-formatting.zip
Add astyle formatting script/config (in progress)formatting
-rw-r--r--.astylerc24
-rwxr-xr-xformat.sh27
2 files changed, 51 insertions, 0 deletions
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