#!/bin/bash

# strips "//" and "/* */" style of comments and counts lines of code
# from given files
#
# jhuhta 2007-05-05

if [ $# -lt 1 ]; then
	echo "Syntax: $0 file1 ..."
	exit 1;
else
	total=0
	for file in $*; do
		if [ ! -f $file ]; then 
			echo "File \"$file\" not found, skipping"
		else
			echo -n "$file: "
			count=`sed -e 's/\/\/.*//' -e '
			/\/\*/!b
			:x
			/\*\//!{
			N
			bx
			}
			s/\/\*.*\*\/// ' $file | grep -v -P "^\s*$" | wc -l`
			let "total += $count"
			echo $count
		fi
	done
	echo total: $total
fi
