#!/bin/sh

if [ -d src ]; then src=src; else src=.; fi
echo "counting lines in $src:"

find $src -name RCS -prune -o -name '*~' -o -type f -print | xargs wc -l \
  | awk 'BEGIN {c = h = i = t = r = o = "no";} \
      ($2~/\.c$/){c+=$1; next} ($2~/\.h$/){h+=$1; next} \
      ($2~/\.in$|\/configure$|\/ac[^/]*.m4$/){i+=$1; next} \
      ($2~/\.[nt]?roff$|\.1$|\.3$|\.man$/){r+=$1; next} \
      ($2~/\/TAGS[^/]*$/){t+=$1; next} ($2!="total"){o+=$1; next} \
      END {print ".c files:   ",c,"lines"; print ".h files:   ",h,"lines"; \
           print "conf files: ",i,"lines"; print "roff files: ",r,"lines"; \
           print "other files:",o,"lines";
           print "total:      ",c+h+i+r+o,"lines"; \
           print "tags files: ",t,"lines"}'
