#!/bin/rc
# mktexpk -- make a new PK font, because one wasn't found.
#
# (If you change or delete the word `original' on the previous line,
# installation won't write this script over yours.)
#
# te@informatik.uni-hannover.de, kb@mail.tug.org, and infovore@xs4all.nl.
# Public domain.
#
# translated to rc by rsc
rfork e
version='$Id: mktexpk,v 1.21 1998/02/20 16:23:22 olaf Exp $'
progname=`{echo $0 | sed 's%.*/%%'}
usage='Usage: '$progname' [OPTION] NAME [REDIRECT],
Create a PK font.
--dpi DPI use resolution DPI.
--bdpi BDPI use base resolution BDPI.
--mag MAG use magnificiation MAG.
--mfmode MODE use MODE as the METAFONT mode.
--destdir DESTDIR write fonts in DESTDIR.
Try to create a PK file for NAME at resolution DPI, with an assumed
device base resolution of BDPI, and a Metafont `mag'' of MAG. Use MODE
for the METAFONT mode. Use DESTDIR for the root of where to install
into, either the absolute directory name to use (if it starts with a
/) or relative to the default DESTDIR (if not). REDIRECT, if supplied,
is a string of the form ''>[1=n]'', where n is the number of the file
descriptor which is to receive, instead of stdout, the name of the
newly created pk file.'
DPI=''
DEST=''
BDPI=''
MODE=''
# Handle non-positional options, except for --version/--help
break=no
while(! ~ $#* 0 && ~ $break no) {
switch($1) {
case --destdir
shift
DEST=$1
shift
case --dpi
shift
DPI=$1
shift
case --bdpi
shift
BDPI=$1
shift
case --mfmode
shift
if(! ~ $1 /)
MODE=$1
shift
case --mag
shift
MAG=$1
shift
case -version --version -help --help
break=yes
case *
break=yes
}
}
if(! ~ $2 '') {
tail=`{echo $2 | sed 's/^>[1=(.*)]/' | grep '^[0-9]*$'}
if(~ $#tail 0) {
echo $progname: argument $2 ignored - bad file number >[1=2]
tail=1
}
}
mt_max_args=2
if(~ $#MT_TEXMFMAIN 0 || ~ $MT_TEXMFMAIN '')
MT_TEXMFMAIN=`{kpsewhich --expand-path'=$TEXMFMAIN'}
if(~ $#MT_MKTEX_OPT_RC 0 || ~ $MT_MKTEX_OPT_RC '')
MT_MKTEX_OPT_RC=`{kpsewhich --format'=web2c files' mktex.opt.rc}
! ~ $"MT_MKTEX_OPT_RC '' || MT_MKTEX_OPT_RC=$MT_TEXMFMAIN/web2c/mktex.opt.rc
if(! test -f $MT_MKTEX_OPT_RC) {
echo $progname': cannot find mktex.opt; check your installation.' >[1=2]
exit oops
}
. $MT_MKTEX_OPT_RC
# Since we want to pass the generated filename and only that filename
# back to the caller on standard output, we do some redirections so
# regular echo's will end up on stderr, and do an echo >$STDOUT at the end.
# Then the contents of $STDOUT will be echoed to stdout by a trap.
# start of redirection stdout -> stderr, stdin <- /dev/null
>[1=2] </dev/null { # brace to end of file
NAME=$1
# grep for the font in $PSMAPFILE. These are base font names, such as
# rpplr (the original) or pplr0 (an interim step) or pplr8r (current).
if(~ $#PSMAPFILE 0 || ~ $PSMAPFILE '')
PSMAPFILE=`{kpsewhich psfonts.map}
if(~ $#PSMAPFILE 0) {
echo cannot find psfonts.map
exit psfonts.map
}
pattern='^'$NAME'([ ]|$)'
psline=`{grep $pattern $PSMAPFILE}
if(! ~ $#psline 0) {
MODE=modeless
# ps_to_pk is set in mktex.opt
switch($ps_to_pk) {
case ps2pk
*=`{echo $psline | sed 's%[<["]%%g'}
shift
shift
shift
encoding=()
psname=()
slant=()
extend=()
while(! ~ $#* 0) {
switch($1) {
case *.enc
encoding='-e '$1
case *.pf[ab]
psname=$1
case *SlantFont
slant='-S '$lastopt
case *ExtendFont
extend='-E '$lastopt
}
lastopt=$1
shift
}
ANAME=`{echo $NAME | sed 's/8r$/8a/'}
for(try in $NAME.pfa $NAME.pfb $ANAME.pfa $ANAME.pfb) {
if(~ $#psname 0) {
pfa=`{kpsewhich $try >[2]/dev/null}
psname=$pfa
}
}
if(~ $#psname 0) {
echo $progname: cannot find $NAME.pfa nor $NAME.pfb. Trying gsftopk >[1=2]
cmd=(gsftopk $NAME $DPI)
}
if not {
cmd=(ps2pk -v -X$DPI -R$BDPI $slant $extend $encoding $psname $NAME.$DPI'pk')
}
case *
cmd=($ps_to_pk $NAME $DPI)
}
}
if not {
# Check that $BDPI and $MODE are consistent; if not, ignore the mode and
# hope we can correctly guess it from bdpi. (People like to specify the
# resolution on the command line, not the mode so much.)
if(~ $"MODE '') { # ugh
mf_bdpi=`{mf \
'\mode:='$MODE';mode_setup;message"BDPI= "&decimal round pixels_per_inch;end.'\
</dev/null \
| awk '/DPI=/ {print $2}'}
if(! ~ $mf_bdpi $BDPI) {
echo $progname: Mismatched mode $MODE and resolution $BDPI; ignoring mode. >[1=2]
MODE=''
}
}
# If an explicit mode is not supplied, try to guess. You can get a
# list of extant modes from ftp://ftp.tug.org/tex/modes.mf.
if(~ $MODE '' default) {
switch($BDPI) {
case 85
MODE=sun
case 100
MODE=gnot
case 180
MODE=toshiba
case 300
MODE=cx
case 400
MODE=nexthi
case 600
MODE=ljfour
case 1270
MODE=linoone
case *
echo $progname: can''''t guess mode for $BDPI dpi devices >[1=2]
echo $progname: use a config file, or update me. >[1=2]
exit dpiguess
}
}
# Run Metafont. Always use plain Metafont, since reading cmbase.mf
# does not noticeably slow things down.
cmd=(mf '\mode:='$MODE'; mag:='$MAG'; nonstopmode; input '$NAME)
}
oifs=$ifs
ifs=$SEP *=(`{$MT_MKTEXNAM $NAME $DPI $MODE $DEST})
ifs=$oifs
PKDEST=$1
PKDESTDIR=`{echo $PKDEST | sed 's%/[^/][^/]*$%%'} # can't rely on dirname
PKNAME=`{basename $PKDEST}
GFNAME=$NAME.$DPI'gf'
if(test -r $PKDESTDIR/$PKNAME) {
echo $progname: $PKDESTDIR/$PKNAME already exists >[1=2]
echo $PKDESTDIR/$PKNAME >$STDOUT
$MT_MKTEXUPD $PKDESTDIR $PKNAME
exit
}
$MT_MKTEXDIR $PKDESTDIR
if(! test -d $PKDESTDIR) {
echo $progname: mktexdir $PKDESTDIR failed. >[1=2]
exit
}
echo $progname: Running $cmd
$cmd </dev/null || {
# Don't abort if only "Strange path" errors occurr.
grep '^!' $NAME.log >$pid.errs >[2]/dev/null
grep '^! Strange path' $pid.errs >$pid.strange >[2]/dev/null
if(cmp -s $pid.errs $pid.strange && test -s $pid.strange)
echo $progname: warning: $cmd caused strange path errors >[1=2]
if not {
echo $progname: $cmd failed >[1=2]
test -s $NAME.log && mv -f $NAME.log $KPSE_DOT
exit failed
}
}
test -r $GFNAME &&
{gftopk ./$GFNAME $PKNAME || exit gf}
! test -f $PKNAME &&
test -f $NAME.$DPI'pk' &&
mv $NAME.$DPI'pk' $PKNAME
if(! test -s $PKNAME) {
echo $progname: $cmd failed to make $PKNAME >[1=2]
exit fail2
}
# Install the PK file carefully, since others may be working simultaneously.
# Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
mv $PKNAME $PKDESTDIR/pk$pid.tmp >[2]/dev/null ||
cp $PKNAME $PKDESTDIR/pk$pid.tmp ||
exit mvcpfail
cd $PKDESTDIR || exit cdfail
chmod `{kpsestat -xst,go-w .} pk$pid.tmp
test -r $PKNAME || mv pk$pid.tmp $PKNAME || exit nopk
$MT_MKTEXUPD $PKDESTDIR $PKNAME
# If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
# will think mktexpk failed. Any other output to stdout will also lose.
echo $PKDESTDIR/$PKNAME >$STDOUT
echo $progname: $PKDESTDIR/$PKNAME: successfully generated >[1=2]
}
|