
# process options

USAGE="usage: $0 $OPTIONS file$EXTENSION"
HDIR=$SRLIB

for i
do
    case $i in
	$PATTERN)
	    OPTION=$i
	    shift;;
	-e)
	    HDIR=$SRSRC/links
	    shift;;
	-*)
	    echo "$USAGE" 1>&2
	    exit 1;;
	*)
	    break;;
    esac
done


#  validate file argument

INFILE=$1
BASE=`echo $INFILE | sed 's/\.[^.]*$//'`
SRFILE=$BASE.sr

if [ $# != 1 -o X$BASE$EXTENSION != "X$1" ]
then
    echo "$USAGE" 1>&2
    exit 1
fi

if [ ! -r $INFILE ]
    then
        echo 1>&2 "$0: cannot read $INFILE"
        exit 1
fi


# if .sr output file exists, check that it was generated by this tool
# so that we do not mistakenly blow away a good file.

BANNER="/* This SR file was generated by $NAME */"

if [ -r $SRFILE ]
    then
	LINE1=`sed 1q $SRFILE`
	if [ "$LINE1" != "$BANNER" ]
	    then
	        echo 1>&2 \
	    "$SRFILE exists and was not created by $NAME - will not overwrite"
                exit 1
        fi
fi


# build a .c file in /tmp that will be preprocessed to make the .sr file

TMPFILE=/tmp/$NAME$$.c
trap 'x=$?; /bin/rm -f $TMPFILE; exit $x' 0 1 2 15

/bin/cat $HDIR/$NAME.h $INFILE > $TMPFILE

echo "$BANNER" >$SRFILE


# define sed script for postprocessing the cpp results

SCRIPT='
s=/ *%=/\*=g
s=% */=\*/=g
s=/  */=//=g
s=\[  *]=[]=g
s=\*  *\*=\*\*=g
s/\~  *=/\~=/g
s/ *: *= */:=/g
'


# handle tool-specific options and build the .sr file 

