#!/bin/sh

output_include() {

  FILE=$1

  if [ "$FILE" != "" ]; then

    SUFFIX=`echo $FILE | sed -e 's/.*[.]//'`

    if [ "$SUFFIX" = "ssc" -o "$SUFFIX" = "inc" ]; then
      L=`cat $FILE | tr -d '\r' | grep -e '^[ ]*include' | sed -e 's/[^"]*["]//' -e 's/["].*//' | sed -e 's/^[.][/]//'`
    else
      L=`cat $FILE | tr -d '\r' | grep -e '^[ ]*source' | awk '{print $2}' | sed -e 's/^[.][/]//'`
    fi

    for i in $L ; do
      echo $i
      output_include $i
    done

  fi

}

for i in *.inc *.ssc *.tcl ; do

   echo "-- $i -------------------------------------------"

   #output_include $i
   output_include $i | sort | uniq -c

done

