home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-bin0.lha / bin / MakeTeXPK < prev    next >
Text File  |  1996-10-12  |  10KB  |  283 lines

  1. #!/bin/sh
  2. # original MakeTeXPK -- make a new PK font, because one wasn't found.
  3. # Version of 12dec94.
  4. # (If you change or delete the word `original' on the previous line,
  5. # installation won't write this MakeTeXPK over yours.)
  6. #
  7. # This script must echo the name of the generated PK file (and nothing
  8. # else) to standard output. Yes, this is different from the original dvips.
  9. # Parameters:
  10. #   name dpi bdpi magnification [mode [destdir]]
  11. #
  12. #   `name' is the base name of the font, such as `cmr10'.
  13. #   `dpi' is the resolution the font is needed at.
  14. #   `bdpi' is the base resolution, used to intuit the mode to use.
  15. #   `magnification' is a string to pass to MF as the value of `mag'.
  16. #   `mode', if supplied, is the mode to use. Unless it's `default', in
  17. #     which case we guess. (This is so people can specify a destdir
  18. #     without a mode.)
  19. #   `destdir', if supplied, is either the absolute directory name to use
  20. #     (if it starts with a /) or relative to the default DESTDIR (if not).
  21.  
  22. # The root of where to put the new file. (Using the sh construct
  23. # ${var=value} is the tersest construct that lets an environment
  24. # variable `var' override the value given here.)
  25. : ${DESTROOT=${MTPK_DESTROOT-/ade/lib/texmf/fonts}}
  26.  
  27. # Define to `gsftopk' or `ps2pk' or whatever to make PK files for
  28. # PostScript fonts. If this is defined, PSMAPFILE must also be defined to
  29. # be your psfonts.map file or some equivalent.
  30. : ${ps_to_pk=gsftopk}
  31. : ${PSMAPFILE=/ade/lib/texmf/dvips/psfonts.map}
  32.  
  33. # Location of the files that map font name parts to directory names.
  34. : ${NAMEMAPDIR=/ade/lib/texmf/fontname}
  35.  
  36. # This is needed only if all the font directories were not included in
  37. # the compile-time path for gsftopk. 
  38. : ${DVIPSHEADERS=/ade/lib/ghostscript/type1:}
  39.  
  40. # If this directory doesn't exist, the DC fonts won't be attempted.
  41. : ${dcfontdir=/ade/lib/texmf/fonts/public/dc}
  42.  
  43. # If this directory doesn't exist, the Sauter stuff won't be attempted.
  44. : ${sauterdir=/ade/lib/texmf/fonts/public/sauter}
  45.  
  46. # If the true typeface directory cannot be determined from the fontname,
  47. # the files are installed here, relative to $DESTROOT.
  48. : ${default_namepart=tmp/pk}
  49.  
  50. # TEMPDIR needs to be unique for each process because of the possibility
  51. # of processes simultaneously running this script.
  52. TEMPDIR=${TMPDIR-/tmp}/mtpk.$$
  53.  
  54. if test $# -lt 4; then
  55.   echo "Usage: $0 name dpi bdpi mag [mode [destdir]]." >&2
  56.   exit 1
  57. fi
  58.  
  59. NAME=$1
  60. DPI=$2
  61. BDPI=$3
  62. MAG=$4
  63. MODE=$5
  64.  
  65. # DESTDIR is harder.
  66. case "$6" in
  67.   "")
  68.       # Nothing specified, so try to intuit the directory from the
  69.       # fontname. First the special cases: either $NAME matches an entire
  70.       # name in special.map, or it matches the abbreviation in
  71.       # special.map and ends with a numeral (for the pointsize).
  72.       # We (painfully) use only the minimal features in original awk.
  73.       if test -r $NAMEMAPDIR/special.map; then
  74.         namepart=`awk \
  75. '{if ($1 == NAME || (substr (NAME, 1, length ($1)) == $1 \
  76.                       && substr (NAME, length (NAME), 1) ~ /[0-9]/)) \
  77.      { print $2 "/" $3; exit; }}' NAME=$NAME $NAMEMAPDIR/special.map`
  78.  
  79.         if test -z "$namepart"; then
  80.           # Try the normal case. Source first.
  81.           s_abbrev=`echo $NAME | cut -c 1-1`
  82.           sourcedir=`awk '{ if ($1 == s_abbrev) { print $2; exit; }}' \
  83.                      s_abbrev=$s_abbrev $NAMEMAPDIR/source.map`
  84.  
  85.           if test -n "$sourcedir"; then
  86.             # We found the source. Try for the typeface.
  87.             t_abbrev=`echo $NAME | cut -c 2-3`
  88.             typefacedir=`awk '{ if ($1 == t_abbrev) { print $2; exit; }}' \
  89.                          t_abbrev=$t_abbrev $NAMEMAPDIR/typeface.map`
  90.  
  91.             if test -n "$typefacedir"; then
  92.               # Found everything.
  93.               namepart=$sourcedir/$typefacedir
  94.  
  95.             else
  96.               echo "$0: Could not map typeface abbreviation $t_abbrev." >&2
  97.             fi
  98.           else
  99.             echo "$0: Could not map source abbreviation $s_abbrev." >&2
  100.           fi
  101.         fi
  102.       else
  103.         # No map files.
  104.         :
  105.       fi
  106.       if test -z "$namepart"; then
  107.         # If we failed for whatever reason, default to a generic subdir.
  108.         namepart=$default_namepart
  109.       else
  110.         # Otherwise, get the `pk' in before we append the mode.
  111.         namepart=$namepart/pk 
  112.       fi
  113.       
  114.       # Finally, update the parent of the installation directory.
  115.       DESTROOT="$DESTROOT/$namepart"
  116.       ;;
  117.   /*) DESTDIR=$6;;           # Absolute, explicit destdir => use it.
  118.    *) DESTDIR=$DESTROOT/$6;; # Relative destdir => append to the default.
  119. esac
  120.  
  121. GFNAME=$NAME.$DPI'gf'
  122. PKNAME=$NAME.$DPI'pk'
  123.  
  124. # Clean up on normal or abnormal exit. DESTDIR changes, hence the eval.
  125. # AmigaOS hack:  Add a sleep to work around a race condition that allows
  126. # for a dying process to hold a lock on TEMPDIR long enough to prevent
  127. # it from being immediately deleted.
  128. trap "cd /; sleep 5; eval rm -rf $TEMPDIR \$DESTDIR/pktmp.$$" 0 1 2 15
  129.  
  130. # Allow fonts to be read and written (especially in case we make
  131. # directories) by everyone.  
  132. umask 0
  133.  
  134. # Possible local customizations?
  135. test -r /ade/lib/texmf/web2c/MakeTeXPK.site
  136.  
  137. # Remember where we were for the paths. We'd most like to replace `.',
  138. # wherever it is in the path, with $SAVEPWD, but we don't have access to the
  139. # compile-time path. So we are conservative, and put this at the end.
  140. SAVEPWD=`pwd`
  141.  
  142. # Go to the unique working directory.
  143. test -d $TEMPDIR || mkdir $TEMPDIR 
  144. cd $TEMPDIR || exit 1
  145.  
  146. # grep for the font in $PSMAPFILE, if some ps-to-pk is claimed to be supported.
  147. # We have to figure out the name of the base font -- $NAME is probably
  148. # something like pplr, but it's rpplr or pplr0 or pplr8r that's in psfonts.map.
  149. pattern="^r?$NAME"'(0|8r)?([     ]|$)' 
  150. test -n "$ps_to_pk" && egrep "$pattern" $PSMAPFILE >psline
  151. if test -s psline; then
  152.   # This is a PostScript font.
  153.   MODE=$ps_to_pk
  154.   case $ps_to_pk in
  155.        ps2pk*) special_part=`cat psline | sed -e 's/^.*"//' -e 's/".*$//'`
  156.                # .167 SlantFont
  157.                slant=`echo $special_part \
  158.                       | awk '{ if ($2 == SlantFont) print "-S" $1 }'`
  159.                extend=`echo $special_part \
  160.                        | awk '{ if ($2 == ExtendFont) print "-E" $1 }'`
  161.                cmd="$ps_to_pk -v -X$DPI $slant $extend $NAME";;
  162.             *) cmd="$ps_to_pk $NAME $DPI";;
  163.   esac
  164.  
  165.   # Update DESTDIR for new mode, and check if we were spuriously called.
  166.   test -z "$6" && DESTDIR="$DESTROOT/$MODE"
  167.   if test -r $DESTDIR/$PKNAME; then # sigh, this is repeated below
  168.     echo "$0: $DESTDIR/$PKNAME already exists." >&2
  169.     echo $DESTDIR/$PKNAME
  170.     exit 0
  171.   fi
  172.  
  173.   DVIPSHEADERS="$DVIPSHEADERS:$SAVEPWD"
  174.   export DVIPSHEADERS
  175.   echo "$0: Running $cmd" >&2
  176.   $cmd >&2 || { echo "$0: $ps_to_pk failed." >&2; exit 1; }
  177.  
  178. else
  179.   # Try Metafont.
  180.   MFINPUTS="$MFINPUTS:$SAVEPWD"
  181.   export MFINPUTS
  182.  
  183.   # If an explicit mode is not supplied, try to guess. You can get a
  184.   # list of extant modes from ftp.cs.umb.edu:pub/tex/modes.mf.
  185.   if test -z "$MODE" || test "$MODE" = default; then
  186.     case "$BDPI" in
  187.       85) MODE=sun;;
  188.      300) MODE=cx;;
  189.      600) MODE=ljfour;;
  190.     1270) MODE=linolo;;
  191.        *) echo "$0: Can't guess mode for $BDPI dpi devices." >&2
  192.           echo "$0: Use a config file, or update me." >&2
  193.           exit 1
  194.     esac
  195.   fi
  196.  
  197.   # If no destination directory specified, install font in directory
  198.   # named for the mode.
  199.   test -z "$6" && DESTDIR="$DESTROOT/$MODE"
  200.  
  201.   if test -r $DESTDIR/$PKNAME; then # sigh, this is repeated above
  202.     echo "$0: $DESTDIR/$PKNAME already exists." >&2
  203.     echo $DESTDIR/$PKNAME
  204.     exit 0
  205.   fi
  206.  
  207.   # Run Metafont. Always use plain Metafont, since reading cmbase.mf
  208.   # does not noticeably slow things down. Separate the filename from the
  209.   # rest, since we have to use ./$NAME if we generate something.
  210.   cmd="mf \mode:=$MODE; mag:=$MAG; scrollmode; input"
  211.   echo "$0: Running $cmd $NAME" >&2
  212.   if $cmd $NAME </dev/null >&2; then
  213.     : # Success already.
  214.   
  215.   else
  216.     # These other cases should really be part of MakeTeXMF.
  217.     # First have to figure out the real magnification, which means
  218.     # extracting the point size from the name -- a trailing number.
  219.     rootname=`echo $NAME | sed 's/[0-9]*$//'`
  220.     pointsize=`echo $NAME | sed "s/^$rootname//"`
  221.     case "$pointsize" in
  222.       11) realsize=10.95444;;    # \magstephalf
  223.       14) realsize=14.4;;    # \magstep2
  224.       17) realsize=17.28;;    # \magstep3
  225.       20) realsize=20.74;;    # \magstep4
  226.       25) realsize=24.88;;    # \magstep5
  227.        *) realsize=$pointsize;;
  228.     esac
  229.     mfname=$NAME.mf
  230.     rm -f $mfname # We are in $TEMPDIR, so this is safe.
  231.  
  232.     if test -z "$pointsize"; then
  233.       # No point size, so it can't be a DC or Sauter font. Give up.
  234.       :
  235.  
  236.     elif echo $NAME | grep '^dc' >/dev/null; then
  237.       echo "$0: Trying DC font." >&2
  238.       echo "if unknown dxbase: input dxbase fi;" >$mfname
  239.       echo "gensize:=$realsize;" >>$mfname
  240.       echo "generate $rootname." >>$mfname
  241.       echo "$0: Running $cmd ./$NAME" >&2
  242.       $cmd ./$mfname </dev/null >&2
  243.  
  244.     elif test -d $sauterdir; then
  245.       echo "$0: Trying interpolated/extrapolated (Sauter) font." >&2
  246.       echo "design_size:=$realsize;" >>$mfname
  247.       echo "input b-$rootname;" >>$mfname
  248.       echo "$0: Running $cmd ./$NAME" >&2
  249.       $cmd ./$mfname </dev/null >&2
  250.       # Result should go in the sauterdir, not the cm dir.
  251.       test -z "$6" && $DESTDIR=$sauterdir/pk/$MODE
  252.     fi # alternative mf sources
  253.   fi # first mf failed
  254.   
  255.   # If we couldn't make the font, quit.
  256.   test -r $GFNAME || \
  257.     { echo "$0: Metafont failed to make $GFNAME." >&2; exit 1; }
  258.  
  259.   # Success.  Make the PK file.
  260.   gftopk ./$GFNAME $PKNAME || exit 1
  261. fi
  262.  
  263. # If we get here, we've succeeded; move the final font to $DESTDIR.
  264. test -d $DESTDIR \
  265.   || mkdir $DESTDIR \
  266.   || { echo "$0: Could not mkdir $DESTDIR." >&2; exit 1; }
  267.  
  268. # Install the PK file carefully, since others may be working simultaneously.
  269. # Note that we use cp+rm rather than mv since mv may not work across filesystems.
  270. cp $PKNAME $DESTDIR/pktmp.$$ \
  271.   || { echo "$0: Could not cp $PKNAME $DESTDIR/pktmp.$$." >&2; exit 1; }
  272. rm $PKNAME \
  273.   || { echo "$0: Could not rm $PKNAKE." >&2; exit 1; }
  274.  
  275. cd $DESTDIR || exit 1
  276. mv pktmp.$$ $PKNAME
  277.  
  278. # If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
  279. # will think MakeTeXPK failed.  Any other output to stdout will also lose.
  280. echo $DESTDIR/$PKNAME
  281.