#!/bin/sh

if [ `basename $PWD` = polyglot ]; then
  if [ -d polyglot ]; then
    cd polyglot
  fi
fi

if [ ! -d ast ]; then
  echo `basename $0`: run in the polyglot directory
  exit 1
fi

if [ $# -ne 1 ]; then
  echo usage `basename $0` ext-name
  exit 1
fi


if [ $1 = jl ]; then
list="
./ast
./frontend
./lex
./main
./parse
./types
./types/reflect
./util
./visit
./ext/jl
./ext/jl/ast
./ext/jl/qq
./ext/jl/parse
./ext/jl/types
"
elif [ -d ./ext/$1 ]; then
    list=`find ./ext/$1 -type d | egrep -v '/(examples|doc|old_types|runtime|tests?|CVS)' | egrep -v 'split/(util|config)'`
else
    echo ext $1 not found
exit 1
fi

for d in $list ; do
    echo $d 1>&2
    loc -t `/bin/ls -1 $d/* | grep -v jmatch[23].cup | grep -v jif.cup | egrep '\.(java|cup|ppg)$'` | tail -1 
done | awk 'BEGIN {sum=0} {sum += $NF} END {print sum}'

