updated to be a bit more useful; now has a list of file types to scan, including...
authorChris Koeritz <fred@gruntose.com>
Mon, 28 Sep 2015 15:13:38 +0000 (11:13 -0400)
committerChris Koeritz <fred@gruntose.com>
Mon, 28 Sep 2015 15:13:38 +0000 (11:13 -0400)
scripts/buildor/buildor_count_code.sh

index 5703c759746df90d6707242fd2336b74fc0ed407..2d8c894e9b39518d01b4ee3edee5d72aaa092a26 100644 (file)
@@ -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"