From e417239619a92473ea324c24e36637ec1dcd6518 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Mon, 28 Sep 2015 11:13:38 -0400 Subject: [PATCH] updated to be a bit more useful; now has a list of file types to scan, including perl bash python and java. iterates reasonably across multiple dir parameters and should handle weird space inclusions etc. --- scripts/buildor/buildor_count_code.sh | 50 +++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/scripts/buildor/buildor_count_code.sh b/scripts/buildor/buildor_count_code.sh index 5703c759..2d8c894e 100644 --- a/scripts/buildor/buildor_count_code.sh +++ b/scripts/buildor/buildor_count_code.sh @@ -1,17 +1,47 @@ #!/bin/bash -export OUT="$(mktemp "$TMP/zz_code_count.XXXXXX")" - -find $* -iname "*.cpp" -o -iname "*.h" -o -iname "*.c" >$OUT - 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? + +codefile_list=(.c .cpp .h .java .pl .py .sh) +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 + break; + fi -rm $OUT +#echo dir is $dir + +#set -o xtrace +##hmmm: how to turn off tracing thing? + + find "$dir" -type f $phrases >$NAME_LIST_TEMP_FILE + +#echo ==================================================== +#echo file holds these matches: +#cat $NAME_LIST_TEMP_FILE +#echo ==================================================== + + while read line; do +#echo line is $line + count=$(grep -h -v -c "^[ ]*$" $line) + 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" -- 2.34.1