]> git.mxchange.org Git - flightgear.git/blob - scripts/tools/fg-check
Maik: add ROTORELTARGET and ROTORENGINEMAXRELTORQUE input axes
[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 XML syntax ..."
80 find . -name \*.xml|while read i; do
81         xmllint $i >/dev/null || RESULT "... in file \e[36m$i\e[m"
82 done
83
84
85 LOG "checking for 'if (foo) delete foo;' ..."
86 find . -iregex ".*\.\([ch]\(xx\|pp\)\|cc\|h\)$"|while read i; do perl -e '
87         my $i = 0;
88         my $name = $ARGV[0];
89         undef $/;
90         $_ = <>;
91         s/(if\s*\(([^\)]+)\)\s*delete(?:\s+|\s*\[\]\s*)\2\s*;)/print "$1\n" and $i++/ges;
92         print "\t... \033[36min file $name\033[m\n" if $i;
93 ' "$i"; done
94
95