blob: e0d743ce3b6779effbdfb27b59f6871d6afa96e3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
|