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

X10=
BUTTONS=
A4=
SUBDIR=
TEXFONTS=
GREY=
SELFILE=
PS=
MAKEPK=
BDPI=
SHRINK=

while test $# -gt 0
do
	case $1 in
	-DX10)			X10=y;;
	-DBUTTONS)		BUTTONS=y;;
	-DA4)			A4=y;;
	-DSEARCH_SUBDIRECTORIES) SUBDIR=y;;
	-DXDVIFONTS_ONLY)	TEXFONTS=y;;
	-DGREY)			GREY=y;;
	-DSELFILE)		SELFILE=y;;
	-DPS)			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;;
	-DMAKEPK)		MAKEPK=-DMAKEPKCMD=\\\"MakeTeXPK\\\";;
	-DMAKEPKCMD*)		MAKEPK=$1;;
	-DBDPI=*)		BDPI=$1;;
	-DDEFAULT_SHRINK=*)	SHRINK=$1;;
	esac
	shift
done

if test -n "$X10"
then
	echo	'/^#ifx11/,/^#/d'
	echo	's/%%dot%%//'
else
	echo	'/^#ifx10/,/^#/d'
	echo	's/%%dot%%/./'
fi

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 "$SELFILE";	then	echo	'/^#ifselfile/,/^#/d';	fi
if test -z "$PS";	then	echo	'/^#ifps/,/^#/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
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

if test -n "$SHRINK"
then
	echo	"s/%%shrink%%/`echo $SHRINK | sed s/-DDEFAULT_SHRINK=// | sed 's/\"//g'`/"
else
	echo	's/%%shrink%%/3/'
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
