#! /bin/sh
a=$0
c=unknown
case $a in
/* )
  c=$a
  ;;
*/* )
  case $a in
  ./* )
    a=`echo $a | sed -e s+./++`
    ;;
  esac
  c=`pwd`/$a
  ;;
* )
  for d in $PATH
  do
    if test -x $d/$a
    then
      c=$d/$a
    fi
  done
  if test $c = "unknown" ;then
    echo "Unable to find full path for script. Please re-try"
    echo "launching it using a fully rooted path."
    exit 1
  fi
  ;;
esac
while test -h "$c"; do
  lt=`ls -l "$c" | sed 's/.*->[ ][ ]*//'`
  if echo "$lt" | grep -q '^/'; then
    c="$lt"
  else
    dir=`dirname "$c"`
    c="$dir/$lt"
  fi
done
here=`echo $c | sed -e 's+/[^/]*$++;s+/[^/]*$++'`
if [ -e TAGS ]; then \rm -i TAGS; fi
find $here/packages -type f -name "*.red" | xargs etags -a -l none \
    -r '/[ \t]*procedure[ \t]+\([^ \t(]+\)[( ;]/\1/' \
    -r '/[ \t]*\(inline|s?macro\|f?expr\)[ \t]+procedure[ \t]+\([^ \t(]+\)[( ;]/\2/' \
    -r '/[ \t]*symbolic[ \t]+\(inline|s?macro\|f?expr\)[ \t]+procedure[ \t]+\([^ \t(]+\)[( ;]/\2/' \
    -r '/[ \t]*\(symbolic\|algebraic\)[ \t]+procedure[ \t]+\([^ \t(]+\)[( ;]/\2/'
