#!/bin/sh

TESTFILES="Makefile.am scanner.l parser.y .cvsignore test.input"

if [ ! $# -eq 1 ] ; then
   echo 1>&2 Usage: $0 test-name
   exit 1
fi

if test -e "$1" ; then
    echo 1>&2 "$1 exists already"
    exit 1
fi

mkdir $1 
if test "$?" -ne 0 ; then
    echo 1>&2 "mkdir $1 failed"
    exit 1
fi

for i in $TESTFILES ; do
    cp TEMPLATE/$i $1/$i
done

# Modify .cvsignore
echo "$1" >> "$1"/.cvsignore

# Modify top-level configure.in
sed '/--new-test-here--/i\
tests/'"$1"'/Makefile' < ../configure.in > configure.in.tmp

mv configure.in.tmp ../configure.in

# Modify  Makefile.am
sed '/^\(DIST_\)\?SUBDIRS/a\
	'"$1"' \\' < Makefile.am > Makefile.am.tmp

mv Makefile.am.tmp Makefile.am

# Modify new-test/Makefile.am
sed "s:TEMPLATE:$1:g" < "$1"/Makefile.am > "$1"/Makefile.am.tmp
mv "$1"/Makefile.am.tmp "$1"/Makefile.am
