X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Fbuildor%2Fbuildor_count_code.sh;h=3bd9fcedb32388983df48385586059bb858606e2;hb=2b85d7ecc6d0e163ec13e20d4e2d0040008fe45c;hp=5703c759746df90d6707242fd2336b74fc0ed407;hpb=2952ccf47b80174880141a7ecfa122089f349b8d;p=feisty_meow.git diff --git a/scripts/buildor/buildor_count_code.sh b/scripts/buildor/buildor_count_code.sh index 5703c759..3bd9fced 100644 --- a/scripts/buildor/buildor_count_code.sh +++ b/scripts/buildor/buildor_count_code.sh @@ -1,17 +1,48 @@ #!/bin/bash -export OUT="$(mktemp "$TMP/zz_code_count.XXXXXX")" +TOTALS=0 -find $* -iname "*.cpp" -o -iname "*.h" -o -iname "*.c" >$OUT +codefile_list=(.c .cpp .h .java .pl .py .sh .wsdl .gwsdl .xml .properties .config .configuration .txt makefile\* ) -TOTALS=0 -for i in $(cat $OUT); do - count=$(grep -h -v -c "^[ ]*$" $i) - TOTALS=$(expr $TOTALS + $count) -#hmmm: is there a better way to do the addition? +for ((i=0 ; i < ${#codefile_list[@]}; i++)); do + if [ ! -z "$phrases" ]; then + phrases="$phrases -o" + fi + phrases="$phrases -iname \*${codefile_list[i]}" done +#echo phrases is now $phrases + +while true; do + export NAME_LIST_TEMP_FILE="$(mktemp "$TMP/zz_code_count.XXXXXX")" + + dir="$1"; shift + if [ -z "$dir" ]; then + rm $NAME_LIST_TEMP_FILE + + break; + fi +#echo dir is $dir -rm $OUT + # for some reason we had to add an eval in front to get this + # working after escaping the asterisk (so as not to include + # local files that matched the patterns). + eval find "$dir" -type f $phrases >$NAME_LIST_TEMP_FILE + +#echo ==================================================== +#echo file $NAME_LIST_TEMP_FILE holds these matches: +#cat $NAME_LIST_TEMP_FILE +#echo ==================================================== + + while read input_text; do +#echo input_text is $input_text + count=$(grep -h -v -c "^[ ]*$" $input_text) + TOTALS=$(($TOTALS + $count)) +#echo total is $TOTALS now + done < "$NAME_LIST_TEMP_FILE" + + rm $NAME_LIST_TEMP_FILE + +done -echo total lines of code=$TOTALS +echo "total lines of code=$TOTALS"