There is no user definable stuff below this point. Really. We do some timing on the fly. This covers almost the complete run including but not limited to the conversion steps and the actual file installation. @d The main body of MakeTeXFont.rexx @@<Special introduction@> DUMMY = Time("Reset") @<Do the actual work@> ELAPSED = Time("ELAPSED") LOGSTRING = "created in "ELAPSEDLOGSTRING = LOGSTRING || ":"Right(ELAPSEDLOGSTRING = LOGSTRING || ":"Right(ELAPSEDCall Log(LOGSTRING) Exit 0 /* This is the end */ @| DUMMY ELAPSED LOGSTRING @
Here we set up the script for a good start. User breaks will be handled in a special subroutine. Several commands addressed to the operating system. @d Special introduction @Signal On BREAK_C Signal On BREAK_D Address COMMAND @| BREAK_C BREAK_D@
@d Do the actual work @@<Get the arguments this script is called with@> @<Create some internal defaults we need@> @<Run METAFONT to generate the font@> @<Run GFtoPK to convert the pixel format@> @<Install the files at the appropriate places@> @
The arguments of the CallMF 2 scripts are exactly those of version 1 for compatibility with the PasTEX drivers, but the parameters are used differently, i.e, more intensely. Do not mingle the two versions. @d Get the arguments this script is called with @Parse Arg FONTNAME DPI HBASE VBASE DRIVER PKFILEARG PKDIRARG .
LOGSTRING = "Making font" FONTNAME "at" DPI "dpi and base" LOGSTRING = LOGSTRING || " ("HBASE","VBASE")" Say LOGSTRING @| FONTNAME DPI HBASE VBASE DRIVER PKFILEARG PKDIRARG @
These files will show up in the current directory later and will be copied to the appropriate places further below. These are the `extended' file names used by METAFONT. @d Create some internal defaults we need @CURGFFILENAME = FONTNAME || "." || DPI || "gf" CURPKFILENAME = FONTNAME || "." || DPI || "pk" CURLOGFILENAME = FONTNAME || ".log" CURTFMFILENAME = FONTNAME || ".tfm"
LOGFILENAME = FONTNAME || "." || DPI || "log" @| CURGFFILENAME CURPKFILENAME CURLOGFILENAME CURTFMFILENAME LOGFILENAME @
Check the top level directories for the respective files. @d Create some internal defaults we need @Call SafeMakeDir(LOGDIR) Call SafeMakeFile(MASTERLOG) Call SafeMakeDir(PKDIR) Call SafeMakeDir(TFMDIR)
If 0 = KEEPGFFILES Then Call SafeMakeDir(GFDIR) @
With the new directory structure, ShowDVI and DVIprint already provide the <mode> we want to call METAFONT with. It comes as the rightmost subdirectory name in the PKDIRARG argument. The font configuration files can be set up so that only the <mode> part embraced to the left and right by single slashes is supplied. @d Run METAFONT to generate the font @@<Determine the mode we're in@> @<Determine the magnification@> @<Set up the command line options@> @<Call METAFONT@> @<Check for possible errors@> @
@d Determine the mode we're in @MODE = Left(PKDIRARG,LastPos("/",PKDIRARG)-1) MODE = SubStr(MODE,LastPos("/",MODE)+1) @| MODE @
The <mag> parameter for METAFONT is almost trivial. With the above setting we can omit the tedious calculations done in version 1. And there is no need for the dubious `config/modes' file any longer. @d Determine the magnification @MAG = DPI / HBASE @| MAG @
The missing information will come directly from METAFONT itself, because it should best know where the font files are located. TEX Directory Structure (TDS)TEX Directory Structure (TDS)TDSTDSTDS helps greatly reduce the effort to determine the other locations. Here we take for granted that the `missing font' actually was never created before and so we call METAFONT first (it won't be found, if TEX Directory Structure (TDS)TEX Directory Structure (TDS)TDSTDSTDS is not correctly set up). @d Set up the command line options @MFOPTIONS = "="MODE"; mag="MAG"; scrollmode; input" FONTNAME @| MFOPTIONS @
First, create the gf file and the tfm file and the log file by calling the METAFONT program. If anything below fails, you can proceed by hand; all necessary files will be present in the current directory. To allow `restart', METAFONT is not called when the expected output file is already present. So you should delete the gf file if parts are missing. @d Call METAFONT @Say "Calling MetaFont with base: &"BASE "and startup commands:" Say "`"MFOPTIONS"'"
If Exists(CURGFFILENAME) Then VIRMF '&'BASE '"'MFOPTIONS'"' Else RC = 0 /* Simulate a perfect result */ @| RC @
METAFONT returns codes 0, 5, 10, and 20 respectively, so we can take appropriate actions. There is a slight improvement over version 1, the log file is consulted to determine the name of the font driver file, which is almost never in the current directory. However, the log file is not sufficiently to determine the correct error position. @d Check for possible errors @ERRORCODE = RC
If 5 >= ERRORCODE Then Do If 0 < ERRORCODE Then Call Error Else Say FONTNAME "translated without errors." End; Else Do Call Error Exit 0 End @| ERRORCODE EDITSCRIPT MFREXXEDIT SOURCEFILE MFEdit.rexx @
Second, create the pk file by calling the GFtoPK program. This is done in the local directory, not yet in the final path. @d Run GFtoPK to convert the pixel format @GFTOPK CURGFFILENAME @<Check the output@> @| GFTOPK @
Don't delete the gf file on failure. The extra information attached to the pk file is a convenience, this and even more information is actually contained in the pk file itself (if the METAFONT base has `modes.mf' loaded). @d Check the output @If Exists(CURPKFILENAME) Then Do If 0 = KEEPGFFILES Then Delete CURGFFILENAME FileNote CURPKFILENAME '"mode='MODE', mag='MAG'"' End; Else Do Call Log("Where is my "CURPKFILENAME"?") Exit 5 End @
Third, check all directories needed for installation and try to move the created files appropriately. For this we consult the log file directly. @d Install the files at the appropriate places @@<Determine the source path@> @<Determine the supplier and the typeface@> @<Install the log file@> @<Install the tfm file@> @<Install the pk file@> @<Install the gf file@> @
@d Determine the source path @If Open('LOGFILE',CURLOGFILENAME,'READ') Then Do Call Log("Can't open "CURLOGFILENAME"!") Exit 10 End
LINE = ReadLn('LOGFILE') /* Dummy read the first intro line */ LINE = ReadLn('LOGFILE') /* Dummy read the second calling line */ LINE = ReadLn('LOGFILE') /* Read the third line for real */
SOURCEFILE = Word(LINE,1) /* The `driver' file is what we want */
If Close('LOGFILE') Then Do Call Log("Can't close "CURLOGFILENAME"!") Exit 10 End @| LOGFILE LINE SOURCEFILE @
Get the <supplier> and <typeface> parts of the directory names. Both keep the slash at the left, but not on the right side. This code is a bit tricky, so don't fool around with it. @d Determine the supplier and the typeface @SUPPLIER = SubStr(SOURCEFILE,Length(SOURCEDIR)+2) /* `+1' for the open brace and `+1' for the leftmost slash */ SUPPLIER = Left(SUPPLIER,LastPos("/",SUPPLIER)-1)
TYPEFACE = SubStr(SUPPLIER,LastPos("/",SUPPLIER)) SUPPLIER = Left(SUPPLIER,LastPos("/",SUPPLIER)-1) @| SUPPLIER TYPEFACE @
@d Install the log file @@<Check and create the log directory@> @<Copy the log file@> @
Check the directory structure for the renamed log file. The following steps directly document the TEX Directory Structure (TDS)TEX Directory Structure (TDS)TDSTDSTDS on my system and thus should be fairly easy to adopt for a (slightly) different scheme. @d Check and create the log directory @LOGDIR = LOGDIR || SUPPLIER Call SafeMakeDir(LOGDIR)
LOGDIR = LOGDIR || TYPEFACE Call SafeMakeDir(LOGDIR)
LOGDIR = LOGDIR || "/" || MODE Call SafeMakeDir(LOGDIR)
LOGDIR = LOGDIR || "/dpi" || DPI Call SafeMakeDir(LOGDIR)
LOGFILENAME = LOGDIR || "/" || LOGFILENAME @
We use `Copy/Delete' instead of `Rename' to overwrite the existing log file (e.g., from a failed call of MakeTeXfont). This works between devices, too. @d Copy the log file @Copy CURLOGFILENAME LOGFILENAME clone Delete CURLOGFILENAME @
@d Install the tfm file @@<Check and create the tfm directory@> @<Copy the tfm file@> @
Check the directory structure for the renamed tfm file. @d Check and create the tfm directory @TFMDIR = TFMDIR || SUPPLIER Call SafeMakeDir(TFMDIR)
TFMDIR = TFMDIR || TYPEFACE Call SafeMakeDir(TFMDIR)
TFMFILENAME = TFMDIR || "/" || CURTFMFILENAME @
Check the tfm file; if it doesn't exist, move it there and delete it here. Once a tfm file is correctly installed, it is valid for all pk files together (even if there were milder forms of warnings in the METAFONT run). @d Copy the tfm file @If Exists(TFMFILENAME) Then Do Copy CURTFMFILENAME TFMFILENAME clone Protect TFMFILENAME r End
Delete CURTFMFILENAME @
@d Install the pk file @@<Check and create the pk directory@> @<Copy the pk file@> @
Check the directory structure for the renamed pk file. @d Check and create the pk directory @PKDIR = PKDIR || SUPPLIER Call SafeMakeDir(PKDIR)
PKDIR = PKDIR || TYPEFACE Call SafeMakeDir(PKDIR)
PKDIR = PKDIR || "/" || MODE Call SafeMakeDir(PKDIR)
PKDIR = PKDIR || "/dpi" || DPI Call SafeMakedir(PKDIR)
PKFILENAME = PKDIR || "/" || CURPKFILENAME @
Look if the font already is installed. (Shouldn't happen!) @d Copy the pk file @If Exists(PKFILENAME) Then Do LOGSTRING = PKFILENAME LOGSTRING = LOGSTRING "already exists;" '0A'X LOGSTRING = LOGSTRING "check your driver's configuration!" Say LOGSTRING Call Log(LOGSTRING) Delete CURPKFILENAME Exit 5 End
Copy CURPKFILENAME PKFILENAME clone Delete CURPKFILENAME Protect PKFILENAME r @
The `generic font' files are only kept, when you modify this script in the section about `user-definable stuff'. @d Install the gf file @If 0 = KEEPGFFILES Then Do /* Optionally store GF files */ @<Check and create the gf directory@> @<Copy the gf file@> End @
Check the directory structure for the renamed gf file. @d Check and create the gf directory @GFDIR = GFDIR || SUPPLIER Call SafeMakeDir(GFDIR)
GFDIR = GFDIR || TYPEFACE Call SafeMakeDir(GFDIR)
GFDIR = GFDIR || "/" || MODE Call SafeMakeDir(GFDIR)
GFDIR = GFDIR || "/dpi" || DPI Call SafeMakedir(GFDIR)
GFFILENAME = GFDIR || "/" || CURGFFILENAME @
Look if the font already is installed. (Shouldn't happen!) @d Copy the gf file @If Exists(GFFILENAME) Then Do LOGSTRING = GFFILENAME LOGSTRING = LOGSTRING "already exists;" '0A'X LOGSTRING = LOGSTRING "check your driver's configuration!" Say LOGSTRING Call Log(LOGSTRING) Delete CURGFFILENAME Exit 5 End
Copy CURGFFILENAME GFFILENAME clone Delete CURGFFILENAME Protect GFFILENAME r @