Thursday, September 22, 2005

Line counter per function script

#!/bin/bash

# author: F. Chua

FILES=`find . -type f -name "*.c"`

# for each source file

#for FILE in $FILES
for FILE in $*
do
echo ""

echo "Reading $FILE..."

LEFT=(`grep -n "^{" $FILE | cut -d: -f1`)
RIGHT=(`grep -n "^}" $FILE | cut -d: -f1`)

CNT=0

while [[ ${LEFT[$CNT]} -ne "" ]]
do
TMP=${LEFT[$CNT]}
TMP=$(($TMP-1))
LAST=${RIGHT[$CNT]}
FIRST=$TMP

FUNCTION=`sed -n -e "$TMP p" $FILE | sed -e "s/\r//" | cut -d'(' -f1 | cut -d' ' -f2`

LINE=`sed -n -e "$FIRST,$LAST p" $FILE | sed -e "/^$/d" | wc -l`

echo $FUNCTION "=" $LINE " Lines"
CNT=$(($CNT+1))
done
done