Debian Codegraph @

batch/make/beautify

raw
1 #!/bin/sh
2 # Applies astyle on all source files
3 # usage: beautify <source directory> <tagfile> <astyle-options>
4 # if the sources should stay untouched or
5 # beautify -t <source directory> <tagfile> <astyle-options>
6 # if changed sources should be marked
7
8 # set -x
9
10 TOUCH=false
11
12 SRCDIR="$1"
13 shift
14 if test "$SRCDIR" = "-t"; then
15 TOUCH=true
16 SRCDIR="$1"
17 shift
18 fi
19
20 TAGFILE=$SRCDIR/"$1"
21 shift
22
23 # mark tag file as really old file so everything will be beautified at first
24 test -r $TAGFILE || touch -t 198001010000 $TAGFILE
25
26 # find all edited source files
27 for f in `find $SRCDIR \( -name \*.cpp -o -name \*.h \) -a -cnewer $TAGFILE`; do
28 echo "Beautifying $f"
29
30 # copy and beautify
31 cp $f $f.beautify
32 astyle $f.beautify "$@"
33
34 # test and touch/move back to original
35 test "$TOUCH" = "false" && touch -r $f $f.beautify
36 diff $f.beautify $f > /dev/null || mv $f.beautify $f
37 rm -f $f.beautify*
38 done
39
40 # retouch tag file
41 rm -f $TAGFILE
42 echo "x" > $TAGFILE