comparison TOOLS/checktree.sh @ 16240:d4cf25d45b13

Script to check (CVS) source-tree for anomalies, like MSDOS line endings etc..
author ivo
date Wed, 17 Aug 2005 01:50:05 +0000
parents
children 13ac8d0ba7fd
comparison
equal deleted inserted replaced
16239:87da68468e6d 16240:d4cf25d45b13
1 #!/bin/sh
2
3 # -----------------------------------------------------------------------------
4
5 # Check source-tree for anomalies
6 #
7 # (C)opyright 2005 by Ivo van Poorten
8 # Licensed under GNU General Public License version 2
9 #
10 # Thanks to Melchior Franz of the FlightGear project for the original idea
11 # of a source-tree checker and Torinthiel for the feedback along the way.
12
13 # $Id$
14
15 # -----------------------------------------------------------------------------
16
17 # Default settings
18
19 _spaces=yes
20 _extensions=yes
21 _crlf=yes
22 _trailws=no
23 _rcsid=no
24 _oll=no
25
26 _color=yes
27 _head=yes
28 _cvs=yes
29 _files=
30
31 # -----------------------------------------------------------------------------
32
33 # Avoid locale problems
34
35 export LC_ALL=C
36
37 # -----------------------------------------------------------------------------
38
39 # Helper functions
40
41 enable_all_tests() {
42 _spaces=yes
43 _extensions=yes
44 _crlf=yes
45 _trailws=yes
46 _rcsid=yes
47 _oll=yes
48 }
49
50 disable_all_tests() {
51 _spaces=no
52 _extensions=no
53 _crlf=no
54 _trailws=no
55 _rcsid=no
56 _oll=no
57 }
58
59 printoption() {
60 echo " -(no)$1 $2 [default: $3]"
61 }
62
63 printhead() {
64 test "$_head" = "yes" && echo -e "$COLB$1$COLE"
65 }
66
67 all_filenames() {
68 test "$_files" != "" && echo "$_files" && return
69
70 if [ "$_cvs" == "no" ]; then
71 find . -type f \
72 | grep -v "\.\#\|\~$\|\.depend\|\/CVS\/\|config.mak\|^\./config\.h" \
73 | grep -v "^\./version\.h\|\.o$\|\.a$"
74 else
75 list_cvs .
76 fi
77 }
78
79 list_cvs() {
80 for i in `grep "^/" $1/CVS/Entries | cut -d '/' -f 2`; do
81 echo $1/$i
82 done
83 for j in `grep "^D/" $1/CVS/Entries | cut -d '/' -f 2`; do
84 list_cvs $1/$j
85 done
86 }
87
88 # -----------------------------------------------------------------------------
89
90 # Parse command line
91
92 for i in "$@"; do
93 case "$i" in
94 -help)
95 echo -e "\n$0 [options] [files]\n"
96 echo -e "options:\n"
97 printoption "spaces " "test for spaces in filenames" "$_spaces"
98 printoption "extensions" "test for uppercase extensions" "$_extensions"
99 printoption "crlf " "test for MSDOS line endings" "$_crlf"
100 printoption "trailws " "test for trailing whitespace" "$_trailws"
101 printoption "rcsid " "test for missing RCS Id's" "$_rcsid"
102 printoption "oll " "test for overly long lines" "$_oll"
103 echo
104 printoption "all " "enable all tests" "no"
105 echo
106 printoption "color " "colored output" "$_color"
107 printoption "head " "print heading for each test" "$_head"
108 printoption "cvs " "use CVS/ to determine which files to check" \
109 "$_cvs"
110 echo -e "\nIf no files are specified, the whole tree is traversed."
111 echo -e "If there are, -(no)cvs has no effect.\n"
112 exit
113 ;;
114 -oll)
115 _oll=yes
116 ;;
117 -nooll)
118 _oll=no
119 ;;
120 -cvs)
121 _cvs=yes
122 ;;
123 -nocvs)
124 _cvs=no
125 ;;
126 -head)
127 _head=yes
128 ;;
129 -nohead)
130 _head=no
131 ;;
132 -color)
133 _color=yes
134 ;;
135 -nocolor)
136 _color=no
137 ;;
138 -spaces)
139 _spaces=yes
140 ;;
141 -nospaces)
142 _spaces=no
143 ;;
144 -extensions)
145 _extensions=yes
146 ;;
147 -noextensions)
148 _extensions=no
149 ;;
150 -crlf)
151 _crlf=yes
152 ;;
153 -nocrlf)
154 _crlf=no
155 ;;
156 -trailws)
157 _trailws=yes
158 ;;
159 -notrailws)
160 _trailws=no
161 ;;
162 -rcsid)
163 _rcsid=yes
164 ;;
165 -norcsid)
166 _rcsid=no
167 ;;
168 -all)
169 enable_all_tests
170 ;;
171 -noall)
172 disable_all_tests
173 ;;
174 -none)
175 disable_all
176 ;;
177 -*)
178 echo "unknown option: $i" >&2
179 exit 0
180 ;;
181 *)
182 _files="$_files $i"
183 ;;
184 esac
185 done
186
187 # -----------------------------------------------------------------------------
188
189 # Set heading color
190
191 if [ "$_color" == "yes" ]; then
192 COLB="\e[36m"
193 COLE="\e[m"
194 else
195 COLB=""
196 COLE=""
197 fi
198
199 # Generate filelist once so -cvs isn't _that_ much slower than -nocvs anymore
200
201 filelist=`all_filenames`
202
203 # -----------------------------------------------------------------------------
204
205 # DO CHECKS
206
207 # -----------------------------------------------------------------------------
208
209 if [ "$_spaces" == "yes" ]; then
210 printhead "checking for spaces in filenames ..."
211 find . | grep " "
212 fi
213
214 # -----------------------------------------------------------------------------
215
216 if [ "$_extensions" == "yes" ]; then
217 printhead "checking for uppercase extensions ..."
218 echo $filelist | grep "\.[[:upper:]]\+$" | grep -v "\.S$"
219 fi
220
221 # -----------------------------------------------------------------------------
222
223 if [ "$_crlf" == "yes" ]; then
224 printhead "checking for MSDOS line endings ..."
225 grep -l -I "
226 " $filelist
227 fi
228
229 # -----------------------------------------------------------------------------
230
231 if [ "$_trailws" == "yes" ]; then
232 printhead "checking for trailing whitespace ..."
233 grep -l -I "[[:space:]]\+$" $filelist
234 fi
235
236 # -----------------------------------------------------------------------------
237
238 if [ "$_rcsid" == "yes" ]; then
239 printhead "checking for missing RCS \$Id\$ or \$Revision\$ tags ..."
240 grep -L -I "\$\(Id\|Revision\)[[:print:]]\+\$" $filelist
241 fi
242
243 # -----------------------------------------------------------------------------
244
245 if [ "$_oll" == "yes" ]; then
246 printhead "checking for overly long lines (over 79 characters) ..."
247 grep -l -I "^[[:print:]]\{80,\}$" $filelist
248 fi
249
250 # -----------------------------------------------------------------------------
251
252 # End
253