user_data: make a function static
[smatch.git] / smatch_scripts / whitespace_only.sh
blob975e6571e1e760911a5eaf37c663cd37de08503a
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 if ! $KCHECKER --test-parsing --outfile=$before $file ; then
53 echo "warning: compile failed."
55 mv $before $tmpfile
56 $STRIP $file > $before
57 cat $tmpfile >> $before
59 cat $PATCH | patch -p1
60 $STRIP $file > $after
61 if [ "$compile" = "true" ] ; then
62 if ! $KCHECKER --test-parsing --outfile=$after $file ; then
63 echo "warning: compile failed. *again*"
65 mv $after $tmpfile
66 $STRIP $file > $after
67 cat $tmpfile >> $after
69 cat $PATCH | patch -p1 -R
71 if [ ! -s $before ] ; then
72 echo "Error: No result"
73 exit 1
76 if diff $before $after > /dev/null ; then
77 echo
78 echo Only white space changed
79 echo
80 else
81 echo '!!#$%@$%@^@#$^@#%@$%@$%@#%$@#%!!'
82 echo '!! !!'
83 echo '!! This patch changes stuff !!'
84 echo '!! !!'
85 echo '!!#$%@$%@^@#$^@#%@$%@$%@#%$@#%!!'
87 diff -u $before $after
89 rm -f $before $after $tmpfile
90 done