#!/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