updated to include more file types, plus better escaping to avoid matching files...
[feisty_meow.git] / scripts / buildor / buildor_count_code.sh
1 #!/bin/bash
2
3 TOTALS=0
4
5 codefile_list=(.c .cpp .h .java .pl .py .sh .wsdl .gwsdl .xml .properties .config .configuration .txt makefile\* )
6
7 for ((i=0 ; i < ${#codefile_list[@]}; i++)); do
8   if [ ! -z "$phrases" ]; then
9     phrases="$phrases -o"
10   fi
11   phrases="$phrases -iname \*${codefile_list[i]}"
12 done
13 #echo phrases is now $phrases
14
15 while true; do
16   export NAME_LIST_TEMP_FILE="$(mktemp "$TMP/zz_code_count.XXXXXX")"
17
18   dir="$1"; shift
19   if [ -z "$dir" ]; then
20     break;
21   fi
22 #echo dir is $dir
23
24   # for some reason we had to add an eval in front to get this
25   # working after escaping the asterisk (so as not to include
26   # local files that matched the patterns).
27   eval find "$dir" -type f $phrases >$NAME_LIST_TEMP_FILE
28
29 #echo ====================================================
30 #echo file $NAME_LIST_TEMP_FILE holds these matches:
31 #cat $NAME_LIST_TEMP_FILE
32 #echo ====================================================
33
34   while read line; do
35 #echo line is $line
36     count=$(grep -h -v -c "^[ ]*$" $line)
37     TOTALS=$(($TOTALS + $count))
38 #echo total is $TOTALS now
39   done < "$NAME_LIST_TEMP_FILE"
40   
41   rm $NAME_LIST_TEMP_FILE
42
43 done
44
45 echo "total lines of code=$TOTALS"
46