]> git.mxchange.org Git - flightgear.git/blob - scripts/tools/fg-check
47798ca42a9b4f1dd1582ee693f633f5a24090c7
[flightgear.git] / scripts / tools / fg-check
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 &>/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 "\r$" "$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         if file "$i"|grep -v RLE >/dev/null; then
53                 new=$TMP/sgi.rgb
54                 convert "$i" -compress RLE sgi:$new
55                 [ -x "$RLE" ] && $RLE $new 2>/dev/null
56                 perl -e '
57                         my $file = shift;
58                         my $old = -s $file;
59                         my $new = -s shift;
60                         if ($new < $old) {
61                                 printf "\t$file:  could be %0.02f%% of current size (%d bytes less)\n",
62                                                 100 * $new / $old, $old - $new;
63                         }
64                 ' "$i" $new
65         fi
66 done
67
68
69 if [ -x "$AC3D_SCAN" ]; then
70         LOG "checking for AC3D sanity ..."
71         find . -iname \*.ac|while read i; do
72                 case "$i" in configure.ac|*/configure.ac) continue ;; esac
73                 result=$($AC3D_SCAN <$i 2>&1)
74                 [ "$result" ] && echo -e "$result\n\t... in file \e[36m$i\e[m";
75         done
76 fi
77
78
79 LOG "checking for thumbnail file size (expected JPEG 171x128)"
80 find . -name thumbnail.jpg|while read i; do
81         id=$(identify "$i")
82         if ! echo $id|grep "JPEG 171x128" >/dev/null; then
83                 RESULT "$i ... $id"
84         fi
85 done
86
87
88 LOG "checking for 'userarchive' flags (not allowed in aircraft XML files) ..."
89 find . -name \*.xml|while read i; do
90         if grep "userarchive" $i >/dev/null; then
91                 RESULT "$i"
92         fi
93 done
94
95
96 LOG "checking for XML syntax ..."
97 find . -name \*.xml|while read i; do
98         xmllint $i >/dev/null || RESULT "... in file \e[36m$i\e[m"
99 done
100
101
102 LOG "checking for 'if (foo) delete foo;' ..."
103 find . -iregex ".*\.\([ch]\(xx\|pp\)\|cc\|h\)$"|while read i; do perl -e '
104         my $i = 0;
105         my $name = $ARGV[0];
106         undef $/;
107         $_ = <>;
108         s/(if\s*\(([^\)]+)\)\s*delete(?:\s+|\s*\[\]\s*)\2\s*;)/print "$1\n" and $i++/ges;
109         print "\t... \033[36min file $name\033[m\n" if $i;
110 ' "$i"; done
111
112