home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / texlatex.zip / web2c72.zip / bin / mktexpk < prev    next >
Text File  |  1999-09-14  |  8KB  |  216 lines

  1. #!sh
  2. # original mktexpk -- make a new PK font, because one wasn't found.
  3. # (If you change or delete the word `original' on the previous line,
  4. # installation won't write this script over yours.)
  5. # te@informatik.uni-hannover.de, kb@mail.tug.org, and infovore@xs4all.nl.
  6. # Public domain.
  7.  
  8. version='$Id: mktexpk,v 1.21 1998/02/20 16:23:22 olaf Exp $'
  9. progname=`echo $0 | sed 's%.*/%%'`
  10. usage="Usage: $progname [OPTION] NAME [REDIRECT],
  11.   Create a PK font.
  12.  
  13. --dpi DPI           use resolution DPI.
  14. --bdpi BDPI         use base resolution BDPI.
  15. --mag MAG           use magnificiation MAG.
  16. --mfmode MODE       use MODE as the METAFONT mode.
  17. --destdir DESTDIR   write fonts in DESTDIR.
  18.  
  19. Try to create a PK file for NAME at resolution DPI, with an assumed
  20. device base resolution of BDPI, and a Metafont \`mag' of MAG. Use MODE
  21. for the METAFONT mode.  Use DESTDIR for the root of where to install
  22. into, either the absolute directory name to use (if it starts with a
  23. /) or relative to the default DESTDIR (if not). REDIRECT, if supplied,
  24. is a string of the form '>&n', where n is the number of the file
  25. descriptor which is to receive, instead of stdout, the name of the
  26. newly created pk file."
  27.  
  28. # Handle non-positional options, except for --version/--help
  29. while test $# -gt 0; do
  30.   case "$1" in
  31.     --destdir) shift; DEST="$1"; shift ;;
  32.     --dpi) shift; DPI="$1"; shift ;;
  33.     --bdpi) shift; BDPI="$1"; shift ;;
  34.     --mfmode) shift; test "x$1" != "x/" && MODE="$1"; shift ;;
  35.     --mag) shift; MAG="$1"; shift;;
  36.     --version|-version) break ;;
  37.     --help|-help) break ;;
  38.     *) break ;;
  39.   esac
  40. done
  41.  
  42. if test "x$2" != x; then
  43.   tail="`echo \"x$2\" | sed 's/^x>&//' | grep '^[0-9]*$'`"
  44.   if test -z "$tail"; then
  45.     echo "$progname: argument '$2' ignored - bad file number" >&2
  46.   elif test "$tail" != 1; then
  47.       eval 'exec 1>&$tail'
  48.   fi
  49. fi
  50.  
  51. mt_max_args=2
  52.  
  53. # Common code for all scripts.
  54. : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
  55. : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
  56. test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
  57. if test ! -f "$MT_MKTEX_OPT"; then
  58.   echo "$progname: Cannot find mktex.opt; check your installation." >&2
  59.   exit 1
  60. fi
  61.  
  62. . "$MT_MKTEX_OPT"
  63.  
  64. # Since we want to pass the generated filename and only that filename
  65. # back to the caller on standard output, we do some redirections so
  66. # regular echo's will end up on stderr, and do an echo >$STDOUT at the end.
  67. # Then the contents of $STDOUT will be echoed to stdout by a trap.
  68.  
  69. # start of redirection stdout -> stderr, stdin <- /dev/null
  70. (
  71.  
  72. NAME=$1
  73.  
  74. # grep for the font in $PSMAPFILE.  These are base font names, such as
  75. # rpplr (the original) or pplr0 (an interim step) or pplr8r (current).
  76. : ${PSMAPFILE=`kpsewhich psfonts.map`}
  77. pattern="^$NAME"'([     ]|$)' 
  78. psline=`egrep "$pattern" $PSMAPFILE`
  79. if test -n "$psline"; then
  80.   MODE=modeless
  81.   # ps_to_pk is set in mktex.opt
  82.   case $ps_to_pk in
  83.     ps2pk)
  84.       set x `echo "$psline" | sed 's%[<["]%%g'`
  85.       shift; shift; shift;
  86.       encoding=; psname=; slant=; extend=
  87.       while test ! -z "$1"; do
  88.         case "$1" in
  89.           *.enc)       encoding="-e $1";;
  90.           *.pf[ab])    psname="$1";;
  91.           *SlantFont)  slant="-S $lastopt";;
  92.           *ExtendFont) extend="-E $lastopt";;
  93.         esac
  94.         lastopt="$1"
  95.         shift
  96.       done
  97.       test -n "$psname" ||
  98.         { pfa=`(kpsewhich $NAME.pfa 2>/dev/null)`; psname=$pfa; }
  99.       test -n "$psname" ||
  100.         { pfb=`(kpsewhich $NAME.pfb 2>/dev/null)`; psname=$pfb; }
  101.       ANAME=`echo $NAME | sed 's/8r$/8a/'`
  102.       test -n "$psname" ||
  103.         { pfa=`(kpsewhich $ANAME.pfa 2>/dev/null)`; psname=$pfa; }
  104.       test -n "$psname" ||
  105.         { pfb=`(kpsewhich $ANAME.pfb 2>/dev/null)`; psname=$pfb; }
  106.       if [ -z "$psname" ]; then
  107.         echo "$progname: cannot find $NAME.pfa or $NAME.pfb. Trying gsftopk." >&2
  108.         cmd="gsftopk $NAME $DPI"
  109.       else
  110.         cmd="ps2pk -v -X$DPI -R$BDPI $slant $extend $encoding $psname $NAME.${DPI}pk"
  111.       fi
  112.       ;;
  113.     *)
  114.       cmd="$ps_to_pk $NAME $DPI" 
  115.       ;;
  116.   esac
  117. else
  118.   # Check that $BDPI and $MODE are consistent; if not, ignore the mode and
  119.   # hope we can correctly guess it from bdpi.  (People like to specify the
  120.   # resolution on the command line, not the mode so much.)
  121.   if test -n "$MODE"; then
  122.     mf_bdpi=`mf \
  123. '\mode:='$MODE';mode_setup;message"BDPI= "&decimal round pixels_per_inch;end.'\
  124.              </dev/null \
  125.              | awk '/DPI=/ {print $2}'`
  126.     if test "x$mf_bdpi" != x$BDPI; then
  127.       echo "$progname: Mismatched mode $MODE and resolution $BDPI; ignoring mode." >&2
  128.       MODE=
  129.     fi
  130.   fi
  131.  
  132.   # If an explicit mode is not supplied, try to guess. You can get a
  133.   # list of extant modes from ftp://ftp.tug.org/tex/modes.mf.
  134.   if test -z "$MODE" || test "x$MODE" = xdefault; then
  135.     case "$BDPI" in
  136.       85) MODE=sun;;
  137.      100) MODE=nextscrn;;
  138.      180) MODE=toshiba;;
  139.      300) MODE=cx;;
  140.      400) MODE=nexthi;;
  141.      600) MODE=ljfour;;
  142.     1270) MODE=linoone;;
  143.        *) echo "$progname: Can't guess mode for $BDPI dpi devices." >&2
  144.           echo "$progname: Use a config file, or update me." >&2
  145.           exit 1
  146.     esac
  147.   fi
  148.  
  149.   # Run Metafont. Always use plain Metafont, since reading cmbase.mf
  150.   # does not noticeably slow things down.
  151.   cmd="mf \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
  152. fi
  153.  
  154. OIFS=$IFS; IFS=$SEP
  155. set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
  156. IFS=$OIFS
  157.  
  158. PKDEST="$1"
  159. PKDESTDIR=`echo "$PKDEST" | sed -e 's%/[^/][^/]*$%%' -e 's%^.:%%'` # can't rely on dirname
  160. PKNAME=`basename "$PKDEST"`
  161. GFNAME=$NAME.${DPI}gf
  162.  
  163. if test -r "$PKDESTDIR/$PKNAME"; then
  164.   echo "$progname: $PKDESTDIR/$PKNAME already exists." >&2
  165.   echo "$PKDESTDIR/$PKNAME" >$STDOUT
  166.   "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
  167.   exit 0
  168. fi
  169.  
  170. "$MT_MKTEXDIR" "$PKDESTDIR"
  171. if test ! -d "$PKDESTDIR"; then
  172.   echo "$progname: mktexdir $PKDESTDIR failed." >&2
  173.   exit 1
  174. fi
  175.  
  176. echo "$progname: Running $cmd"
  177. $cmd </dev/null || {
  178.   # Don't abort if only "Strange path" errors occurr.
  179.   grep '^!' $NAME.log >$$.errs 2>/dev/null
  180.   grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
  181.   if cmp $$.errs $$.strange >/dev/null 2>&1 \
  182.     && test -s $$.strange >/dev/null 2>&1; then
  183.     echo "$progname: warning: \`$cmd' caused strange path errors." >&2
  184.   else
  185.     echo "$progname: \`$cmd' failed." >&2
  186.     test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
  187.     exit 1;
  188.   fi
  189. }
  190.  
  191. test -r $GFNAME && { gftopk ./$GFNAME $PKNAME || exit 1; }
  192. test ! -f $PKNAME && test -f $NAME.${DPI}pk && mv $NAME.${DPI}pk $PKNAME
  193. if test ! -s $PKNAME; then
  194.   echo "$progname: \`$cmd' failed to make $PKNAME." >&2
  195.   exit 1
  196. fi
  197.  
  198. # Install the PK file carefully, since others may be working simultaneously.
  199. # Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
  200. mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
  201.   || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
  202. cd $PKDESTDIR || exit 1
  203. chmod `kpsestat -xst,go-w .` pk$$.tmp
  204. test -r $PKNAME || mv pk$$.tmp $PKNAME || exit 1
  205.  
  206. # Update ls-R if necessary.
  207. "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
  208.  
  209. # If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
  210. # will think mktexpk failed.  Any other output to stdout will also lose.
  211. echo "$PKDESTDIR/$PKNAME" >$STDOUT
  212. echo "$progname: $PKDESTDIR/$PKNAME: successfully generated." >&2
  213. ) 1>&2 </dev/null
  214.