#! /bin/sh

# runs trackstrace on a set of strace output files

prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin

PROG=`basename "$0"`

usage()
{
  echo "Usage: $PROG [OPTIONS] INPUT-FILE..."
  echo
  echo "Options:"
  echo "  -o DIRECTORY, --output=DIRECTORY"
  echo "         create output in DIRECTORY instead of in the input's directory"
  echo "  -h, --help"
  echo "         display this help and exit"
  echo "  -v, --version"
  echo "         output version information and exit"
}

OPTS=`getopt -o hvo: --long help,version,output: -n "$PROG" -- "$@"`

if [ $? -ne 0 ]
then
  echo
  usage
  exit 1
fi

eval set -- "$OPTS"

for o
do
  case "$o" in
    -h|--help)    
      usage
      exit 0;;
    -v|--version)
      echo polgen 1.3
      exit 0;;
    -o|--output)
      output="$2"
      shift 2;;
    --)
      shift
      break;;
  esac
done

if [ $# -lt 1 ]
then
  echo No input files
  echo
  usage
  exit 1
fi

if [ -z "$output" ]
then
  for i
  do
    $bindir/trackstrace -o "$i".tracked "$i"
  done
elif [ -d "$output" ]
then
  for i
  do
    $bindir/trackstrace -o "$output"/`basename "$i"`.tracked "$i"
  done
else
  echo Directory $output does not exist
  echo
  usage
  exit 1
fi
