summaryrefslogtreecommitdiffstats
path: root/format.sh
diff options
context:
space:
mode:
Diffstat (limited to 'format.sh')
-rwxr-xr-xformat.sh27
1 files changed, 27 insertions, 0 deletions
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