#!/bin/sh
FONTPATH=$1
FONTSIZES=$2
VFPATH=$3
shift 3

BUTTONS=y
A4=''
SUBDIR=''
TEXFONTS=''
GREY=y
MAKEPK=y
BDPI=''
PS=y
DPS=''
NEWS=''
GHOST=y

while test $# -gt 0
do
	case $1 in
	-DNOBUTTONS)		BUTTONS=;;
	-DA4)			A4=y;;
	-DSEARCH_SUBDIRECTORIES) SUBDIR=y;;
	-DXDVIFONTS_ONLY)	TEXFONTS=y;;
	-DNOGREY)			GREY=;;
	-DMAKEPK)		MAKEPK=-DMAKEPKCMD=\\\"MakeTeXPK\\\";;
	-DMAKEPKCMD*)		MAKEPK=$1;;
	-DBDPI=*)		BDPI=$1;;
	-DPS_DPS)		DPS=y; GHOST=; PS=y;;
	-DPS_NEWS)		NEWS=y; GHOST=; PS=y;;
	-DPS_GS)		GHOST=y; PS=y;;
	-DMARKPAGE)		MARKPAGE=y;;
	-DTOC)			TOC=y;;
	-DPRINTDVI)		PRINTDVI=y;;
	-DPRCMDALL=*)		PRCMDALL=$1;;
	-DPRCMDCUR=*)		PRCMDCUR=$1;;
	-DPRCMDMRK=*)		PRCMDMRK=$1;;
	-DPRCMDRGN=*)		PRCMDRGN=$1;;
	-DPRCMDLST=*)		PRCMDLST=$1;;
	esac
	shift
done

if test -z "$BUTTONS";	then	echo	'/^#ifbuttons/,/^#/d';	fi
if test -z "$SUBDIR";	then	echo	'/^#ifsubdir/,/^#/d';	fi
if test -n "$TEXFONTS";	then	echo	'/^#iftexfonts/,/^#/d';	fi
if test -z "$GREY";	then	echo	'/^#ifgrey/,/^#/d';	fi
if test -z "$PS";	then	echo	'/^#ifps/,/^#/d';	fi
if test -z "$DPS";	then	echo	'/^#ifdps/,/^#/d';	fi
if test -z "$NEWS";	then	echo	'/^#ifnews/,/^#/d';	fi
if test -z "$GHOST";	then	echo	'/^#ifghost/,/^#/d';	fi
if test -z "$MAKEPK";	then	echo	'/^#ifmakepk/,/^#/d'
	else	echo	"s^%%mkpk%%^`echo $MAKEPK | sed s/-DMAKEPKCMD=//`^"
	fi
echo	'/^#/d'

if test -n "$A4"
then
	echo	's/%%defaultpagesize%%/21 x 29.7 cm (A4 size)/'
else
	echo	's/%%defaultpagesize%%/8.5 x 11 inches/'
fi

if test -n "$BDPI"
then
	echo	"s/%%bdpi%%/`echo $BDPI | sed s/-DBDPI=//`/"
else
	echo	's/%%bdpi%%/300/'
fi

echo	"s@%%DEFAULT_FONT_PATH%%   @.B $FONTPATH\\
@" | sed -e "s@:@\\\\\\
.TP\\\\\\
.B @g"

echo	"s/%%DEFAULT_FONT_SIZES%%/$FONTSIZES/" | sed -e "s/:/ :\\\\\\
/g"

if test -n "$VFPATH"
then
	echo	"s@%%DEFAULT_VF_PATH%%   @.TP\\
.B $VFPATH\\
@" | sed -e "s@:@\\\\\\
.TP\\\\\\
.B @g"
else
	echo	'/%%DEFAULT_VF_PATH%%/d'
fi
if test -z "$MARKPAGE";	then
	echo	'/^#ifmarkpage/,/^#endifmarkpage/d'
fi
if test -z "$TOC";	then
	echo	'/^#iftoc/,/^#endiftoc/d'
fi
if test -z "$PRINTDVI";	then
	echo	'/^#ifprintdvi/,/^#endifprintdvi/d'
else
	echo	"s_%%prcmdall%%_`echo $PRCMDALL | sed s/-DPRCMDALL=//`_"
	echo	"s_%%prcmdcur%%_`echo $PRCMDCUR | sed s/-DPRCMDCUR=//`_"
	echo	"s_%%prcmdmrk%%_`echo $PRCMDMRK | sed s/-DPRCMDMRK=//`_"
	echo	"s_%%prcmdrgn%%_`echo $PRCMDRGN | sed s/-DPRCMDRGN=//`_"
	echo	"s_%%prcmdlst%%_`echo $PRCMDLST | sed s/-DPRCMDLST=//`_"
fi
