white_spaceonly: allow header files
[smatch.git] / smatch_scripts / whitespace_only.sh
blobb290565526a5aad406b5b5a5edceeef20b81d710
1 #!/bin/bash -e
3 usage()
5 echo "usage: $0 <patch file>"
6 exit 1
9 if [ "$1" = "" ] ; then
10 usage
13 if [ "$1" = "--compile" ] ; then
14 compile=true
15 shift
18 SCRIPT_DIR=$(dirname $0)
19 if [ -e $SCRIPT_DIR/kchecker ] ; then
20 KCHECKER=$SCRIPT_DIR/kchecker
21 STRIP=$SCRIPT_DIR/strip_whitespace.pl
22 elif which kchecker | grep kchecker > /dev/null ; then
23 KCHECKER=kchecker
24 STRIP=strip_whitespace.pl
25 else
26 echo "$SCRIPT_DIR"
27 echo "kchecker script not found."
28 exit 1
31 PATCH=$1
33 files=$(grep ^+++ $PATCH | cut -f 1 | cut -b 5-)
34 if [ "$files" = "" ] ; then
35 usage
38 if ! cat $PATCH | patch -p1 --dry-run > /dev/null ; then
39 echo "Couldn't apply patch"
40 exit 1
43 before=$(mktemp /tmp/before.XXXXXXXXXX)
44 after=$(mktemp /tmp/after.XXXXXXXXXX)
45 tmpfile=$(mktemp)
47 for file in $files ; do
48 file=${file#*/}
50 $STRIP $file > $before
51 if [ "$compile" = "true" ] ; then
52 $KCHECKER --test-parsing --outfile=$before $file
53 mv $before $tmpfile
54 $STRIP $file > $before
55 cat $tmpfile >> $before
57 cat $PATCH | patch -p1
58 $STRIP $file > $after
59 if [ "$compile" = "true" ] ; then
60 $KCHECKER --test-parsing --outfile=$after $file
61 mv $after $tmpfile
62 $STRIP $file > $after
63 cat $tmpfile >> $after
65 cat $PATCH | patch -p1 -R
67 if [ ! -s $before ] ; then
68 echo "Error: No result"
69 exit 1
72 if diff $before $after > /dev/null ; then
73 echo
74 echo Only white space changed
75 echo
76 else
77 echo '!!#$%@$%@^@#$^@#%@$%@$%@#%$@#%!!'
78 echo '!! !!'
79 echo '!! This patch changes stuff !!'
80 echo '!! !!'
81 echo '!!#$%@$%@^@#$^@#%@$%@$%@#%$@#%!!'
83 diff -u $before $after
85 rm -f $before $after $tmpfile
86 done