Debian Codegraph @

scripts/tools/fg-check

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Checks source code and data for potential problems.
4 # Meant to be executed before submitting/committing.
5
6
7 SELF=${0##*/}
8
9 # optional apps
10 RLE=$(which rle 2>/dev/null) # http://members.aon.at/mfranz/rle.tar.gz (depends on Qt lib)
11 AC3D_SCAN=$(which ac3d-scan 2>/dev/null) # http://members.aon.at/mfranz/ac3d-scan
12
13
14 function ERROR { echo -e "\e[31;1m$*\e[m"; }
15 function LOG { echo -e "\e[35m$*\e[m"; }
16 function RESULT { echo -e "\t$*"; }
17
18
19 TMP=$(mktemp -d -t $SELF.XXX) || (echo "$0: can't create temporary dir"; exit 1)
20 trap "rm -rf $TMP" 0 1 2 3 13 15
21
22
23 LOG "checking for spaces in filenames ..."
24 find .|grep " "|while read i; do RESULT "$i"; done
25
26
27 LOG "checking for upper-case extensions ..."
28 find .|while read i; do
29 case "$i" in .|..|CVS/*|*/CVS/*|*.Opt|*.README|*.Po|*.TXT) continue ;; esac
30 base=${i##*/}
31 ext=${base##*.}
32 [ "$base" == "$ext" ] && continue # has no extension
33 ext=${ext//[^a-zA-Z]/}
34 [ "$ext" ] || continue # only non-letters
35 lcext=$(echo $ext|sed -e 's,\(.*\),\L\1,')
36 [ "$ext" != "$lcext" ] && RESULT "$i"
37 done
38
39
40 LOG "checking for DOS line endings ..."
41 find . -type f|while read i; do
42 desc=$(file -b "$i")
43 case "$desc" in *text*)
44 grep " $" "$i" >/dev/null && RESULT "$i"
45 ;;
46 esac
47 done
48
49
50 LOG "checking for uncompressed textures ..."
51 find . -iname \*.rgb -o -iname \*.rgba|while read i; do
52 new=$TMP/sgi.rgb
53 if [ -x "$RLE" ]; then
54 cp "$i" $new && "$RLE" $new 2>&1|grep corrupt &>/dev/null && ERROR "\t$i ... FILE CORRUPTED"
55 else
56 convert "$i" -compress RLE sgi:$new
57 fi
58 perl -e '
59 my $file = shift;
60 my $old = -s $file;
61 my $new = -s shift;
62 if ($new < $old) {
63 printf "\t$file: could be %0.02f%% of current size (%d bytes less)\n",
64 100 * $new / $old, $old - $new;
65 }
66 ' "$i" $new
67 done
68
69
70 if [ -x "$AC3D_SCAN" ]; then
71 LOG "checking for AC3D sanity ..."
72 find . -iname \*.ac|while read i; do
73 case "$i" in configure.ac|*/configure.ac) continue ;; esac
74 result=$($AC3D_SCAN <$i 2>&1)
75 [ "$result" ] && echo -e "$result\n\t... in file \e[36m$i\e[m";
76 done
77 fi
78
79
80 LOG "checking for thumbnail file size (expected JPEG 171x128)"
81 find . -name thumbnail.jpg|while read i; do
82 id=$(identify "$i")
83 if ! echo $id|grep "JPEG 171x128" >/dev/null; then
84 RESULT "$i ... $id"
85 fi
86 done
87
88
89 LOG "checking for 'userarchive' flags (not allowed in aircraft XML files) ..."
90 find . -name \*.xml|while read i; do
91 if grep "userarchive" $i >/dev/null; then
92 RESULT "$i"
93 fi
94 done
95
96
97 LOG "checking for XML syntax ..."
98 find . -name \*.xml|while read i; do
99 xmllint $i >/dev/null || RESULT "... in file \e[36m$i\e[m"
100 done
101
102
103 LOG "checking for 'if (foo) delete foo;' ..."
104 find . -iregex ".*\.\([ch]\(xx\|pp\)\|cc\|h\)$"|while read i; do perl -e '
105 my $i = 0;
106 my $name = $ARGV[0];
107 undef $/;
108 $_ = <>;
109 s/(if\s*\(([^\)]+)\)\s*delete(?:\s+|\s*\[\]\s*)\2\s*;)/print "$1\n" and $i++/ges;
110 print "\t... \033[36min file $name\033[m\n" if $i;
111 ' "$i"; done
112
113