#!/bin/sh
# Convert WEB programs not needing special treatment to Java.
# 
# $1 is the Pascal file to be converted.
# $2 is the Java file to be created.
# $3, if present, is extended with .defines, 
# and prepended along with the common definitions.

: ${srcdir=.}

usage="Usage: $0 <basefile>."
basefile=

while test $# -gt 0; do
  case $1 in
    -*) echo "$1?" >&2; echo "$usage" >&2; exit 1;;
     *) if test -n "$basefile"; then
          echo "$1?" >&2; echo "$usage" >&2; exit 1; fi
        basefile=$1;;
  esac
  shift
done
if test -z "$basefile"; then
  echo "Missing basefile argument." >&2
  echo "$usage" >&2
  exit 1
fi

pascalfile=$basefile.p
javafile=$basefile.java

# This is for tangleboot if the build and source directories are different.
test -r $pascalfile || pascalfile=$srcdir/$pascalfile

more_defines=
web2java_options=-j$basefile
precmd=
midcmd=
postcmd=
output="> $javafile"
output_files="$javafile $basefile.h"

# Do it.
eval "cat $srcdir/web2java/common.defines $more_defines $pascalfile \
  $precmd \
  | $srcdir/web2java/web2java $web2java_options \
  $midcmd \
  $postcmd \
  $output"

exit 0
