~ivantis/armagetronad/sty+ct+ivantis

« back to all changes in this revision

Viewing changes to batch/make/beautify

  • Committer: ivantis
  • Date: 2008-09-09 21:33:18 UTC
  • Revision ID: ivantis@ivantis.net-20080909213318-k43y6yuq0zd6wbsa
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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