#!/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"