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

shift

pascalfile=$1
basefile=`basename $1 .p`
cfile=$2

# We use cpascal.h instead of config.h because getopt.c and perhaps
# other straight C routines don't need or want the Pascal definitions of
# `chr' and the like.
hfile=cpascal.h
defnfile=

if test $# -eq 3; then
  hfile=$3.h
  defnfile=$3.defines
fi

cat ../lib/common.defines $defnfile $pascalfile \
	| ../web2c/web2c -h$hfile -c$basefile \
	| ../web2c/fixwrites $basefile > $cfile

if test $? -ne 0; then
  echo "web2c conversion failed, goodbye." 1>&2
  exit 1
fi
exit 0
