home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / text / font / metafont / rexx / maketexfont.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-12-21  |  11.4 KB  |  432 lines

  1. /*
  2. ** AREXX $VER: MakeTeXFont 1.01
  3. **
  4. ** Send new features and bug reports to 
  5. **
  6. ** Martin Bokaemper
  7. ** Reuthstr. 12
  8. ** 91099 Poxdorf
  9. ** Germany
  10. **
  11. ** Email: mnbokaem@cip.e-technik.uni-erlangen.de (Internet)
  12. **        mab@ame.zer (Zerberus)
  13. **
  14. ** Ulrich Wisser
  15. ** Heerstr. 125
  16. ** 53111 Bonn
  17. **
  18. ** HISTORY:
  19. **
  20. ** 0.80: My 'works-fine-for-me' version modified by Georg Hessmann 13.04.91
  21. **       + Variables for all directories and filenames
  22. **       + ^C and ^D detection 
  23. **       + support for a 'modefile' containing site-specific information
  24. **       + searches for standard magsteps 
  25. **       + support for different format-files
  26. **
  27. ** 0.81: + take new Parameters 'drivertype' and 'pkfilename' 
  28. **       Georg Hessmann 17.04.91
  29. **
  30. ** 0.82: + History 
  31. **       + a lot of small improvements and bugfixes
  32. **       + looking for PK-directory for each device 
  33. **       + checking if the font already exists
  34. **       Martin Bokaemper 21.04.91
  35. **
  36. ** 0.84: + add new parameter 'pkdir' (new since driver version V1.10)
  37. **       Georg Hessmann 09.06.91
  38. **
  39. ** 0.85: + fixed a pkdir/pkfilename mixing bug
  40. **       + slight modifications, now works with old driver versions
  41. **       + changed exit codes
  42. **       + always calls uses plain.base (absolutely no gain in using cmbase)
  43. **       J\"org H\"ohle 24.6.91, 01.08.91
  44. **
  45. ** 0.86: + fixed makedir(pkname) bug
  46. **       J\"org H\"ohle 06.08.91
  47. **
  48. ** 0.90: + add makedir(pkdir)
  49. **       + delete localfont entry in 'modes' file
  50. **       Georg Hessmann 28.08.91
  51. **
  52. ** 1.00: + only one logfile entry per call
  53. **       + ERROR: now reports interpreted sourceline
  54. **       + fonts can be copied to mf:<mode> for font-caching
  55. **       + magstep calculation improved.  now same as in ShowDVI/DVIPrint
  56. **       + MISSING: \scrollmode correctly inserted
  57. **       Ulrich Wisser 25.08.92
  58. **
  59. ** 1.01: + bumped revision number because of partial integration of
  60. **       + versions 0.91 and 1.0 and some personal modifications.
  61. **       Andreas Scherer 31.10.93
  62. */
  63.  
  64. Signal On ERROR
  65. Signal On BREAK_C
  66. Signal On BREAK_D
  67.  
  68. /*
  69. ** Files / Directories
  70. */
  71. LOGDIR       = "MF:log"                 /* directory of the logfiles    */
  72.                                         /* without trailing slash!      */
  73. LOGNAME      = LOGDIR"/MakeTeXFont.log" /* logfile                      */
  74. PKDIR        = "TeX:pk/"                /* Where pk fonts are copied to */
  75. MODEFILENAME = "MF:config/modes"        /* description of the modes     */
  76. TEXTFM       = "TeX:fonts/"             /* TeX tfm-files directory      */
  77. VIRMF        = "MF:bin/VirMF"
  78. GFTOPK       = "MF:bin/GFtoPK"
  79. FONTFILENAME = "TeX:config/fontvols"
  80.  
  81. /*
  82. ** Bases. Put in others, if you like.
  83. */
  84. NORMALBASE = "plain"
  85.  
  86. /*
  87. ** Arguments
  88. */
  89. Parse Arg FNTNAME DPI HBASEDPI VBASEDPI DRIVERTYPE PKFILENAME PKDIR .
  90.  
  91. Say "Making font "FNTNAME" at "DPI" dpi and base ("HBASEDPI","VBASEDPI")"
  92.  
  93. If ~Show('Libraries','rexxsupport.library') Then Do
  94.   If ~AddLib('rexxsupport.library',0,-30) Then Do
  95.      Say "No RexxSupport.library ... No Metafont!"
  96.      Exit 5
  97.   End
  98. End
  99.  
  100. DUMMY = Time("Reset")
  101.  
  102. If ~Exists(LOGDIR) Then Do
  103.   Address COMMAND 'MakeDir 'LOGDIR
  104.   If ~Exists(LOGDIR) Then Do
  105.     Call Log("Could not create logdir="LOGDIR)
  106.     Exit 5
  107.   End
  108.   Say "logfile-directory ("LOGDIR"/) did not exist. It was created."
  109. End
  110.  
  111. If ~Exists(LOGNAME) Then Do
  112.   Address COMMAND 'echo >'||LOGNAME
  113.   If ~Exists(LOGNAME) Then Do
  114.     Call Log("Could not create logfile="LOGDIR"/"LOGNAME)
  115.     Exit 5
  116.   End
  117.   Say "logfile did not exist. It was created."
  118. End
  119.  
  120. FNTNAME    = Translate(FNTNAME,XRange('a','z'),XRange('A','Z')) /* lower */
  121. DPI        = Strip(DPI)
  122. HBASEDPI   = Strip(HBASEDPI)
  123. VBASEDPI   = Strip(VBASEDPI)
  124. DRIVERTYPE = Translate(DRIVERTYPE,XRange('a','z'),XRange('A','Z')) /* lower */
  125. PKFILENAME = Translate(PKFILENAME,XRange('a','z'),XRange('A','Z')) /* lower */
  126. PKDIR      = Translate(PKDIR,XRange('a','z'),XRange('A','Z')) /* lower */
  127.  
  128. /*
  129. ** Changed 19.07.92 by Ulrich Wisser
  130. ** Needed to calculate correct DPI sizes
  131. */
  132. Numeric DIGITS 12
  133.  
  134. /*
  135. ** What magstep should the font have?
  136. */
  137. MAG = DPI/HBASEDPI
  138.  
  139. /*
  140. ** MAGMULT.NUM.I set to correct values!
  141. ** 21.07.92 by Ulrich Wisser
  142. ** Needed to calculate correct DPI values.
  143. */
  144. MAGMULT.0      = 13            /* number of saved MagSteps */
  145.  
  146. MAGMULT.NUM.1  = 1.0           /* MagStep(0)   */
  147. MAGMULT.STR.1  = "0"
  148. MAGMULT.NUM.2  = 1.09544511501 /* MagStep(0.5) */
  149. MAGMULT.STR.2  = "0.5"
  150. MAGMULT.NUM.3  = 1.2           /* MagStep(1)   */
  151. MAGMULT.STR.3  = "1"
  152. MAGMULT.NUM.4  = 1.31453413801 /* MagStep(1.5) */
  153. MAGMULT.STR.4  = "1.5"
  154. MAGMULT.NUM.5  = 1.44          /* MagStep(2)   */
  155. MAGMULT.STR.5  = "2"
  156. MAGMULT.NUM.6  = 1.57744096561 /* MagStep(2.5) */
  157. MAGMULT.STR.6  = "2.5"
  158. MAGMULT.NUM.7  = 1.728         /* MagStep(3)   */
  159. MAGMULT.STR.7  = "3"
  160. MAGMULT.NUM.8  = 2.0736        /* MagStep(4)   */
  161. MAGMULT.STR.8  = "4"
  162. MAGMULT.NUM.9  = 2.48832       /* MagStep(5)   */
  163. MAGMULT.STR.9  = "5"
  164. MAGMULT.NUM.10 = 2.985984      /* MagStep(6)   */
  165. MAGMULT.STR.10 = "6"
  166. MAGMULT.NUM.11 = 3.5831808     /* MagStep(7)   */
  167. MAGMULT.STR.11 = "7"
  168. MAGMULT.NUM.12 = 4.29981696    /* MagStep(8)   */
  169. MAGMULT.STR.12 = "8"
  170. MAGMULT.NUM.13 = 5.159780352   /* MagStep(9)   */
  171. MAGMULT.STR.13 = "9"
  172.  
  173. MAGMULT.STR.DEFAULT = "???"
  174. MAGSTR              = MAGMULT.STR.DEFAULT
  175.  
  176. /*
  177. ** Changed 21.07.92 by Ulrich Wisser
  178. ** DPI rounding caused troubles sometimes, e.g., for
  179. ** magstep2 with ShowDVI 44x44
  180. */
  181. Do I = 1 To MAGMULT.0
  182.   MAGDPI = (MAGMULT.NUM.I * HBASEDPI) + 0.5
  183.   If Pos('.',MAGDPI) > 0 Then
  184.     MAGDPI = Left(MAGDPI,Pos('.',MAGDPI)-1)
  185.   If MAGDPI = DPI Then Do
  186.     MAG    = MAGMULT.NUM.I
  187.     MAGSTR = MAGMULT.STR.I
  188.     Leave I
  189.   End
  190. End
  191.  
  192. If MAGSTR ~= MAGMULT.STR.DEFAULT Then MAG = 'magstep('magstr')'
  193.  
  194. /*
  195. ** Modes ... search the correct mode in the file MODEFILENAME (see above).
  196. */
  197. If ~Open('MODEFILE',MODEFILENAME,'READ') Then Do
  198.   Call Log("Can't find file "MODEFILENAME"!")
  199.   Exit 5
  200. End
  201.  
  202. /*
  203. ** 29.10.1993 Andreas Scherer: I keep this from version 0.91, because my
  204. ** configuration depends on argument PKDIR.
  205. ** In case this doesn't work, put in the following by Ulrich Wisser:
  206. **
  207. **   Do Until(XRES==HBASEDPI & YRES == VBASEDPI) | EOF('MODEFILE')
  208. **     LINE = ReadLn('MODEFILE')
  209. **     LINE = Readln('MODEFILE')
  210. **     LINE = Strip(Translate(LINE, ' ', '   '))
  211. **     MODE = Word(LINE,1)
  212. **     XRES = Word(LINE,2)
  213. **     YRES = Word(LINE,3)
  214. **   End
  215. **
  216. ** Maybe this could work with an additional entry
  217. **     PKDIR = Word(LINE,4)
  218. */
  219. Do Until (XRES == HBASEDPI & YRES == VBASEDPI) | EOF('MODEFILE')
  220.   Parse Value Translate(Readln('MODEFILE'),'','2009'X) With MODE XRES YRES PKDIR .
  221. End
  222.  
  223. If ~Close('MODEFILE') Then
  224.   Call Log("Can't close mode-file!")
  225.  
  226. If XRES ~= HBASEDPI | YRES ~= VBASEDPI Then Do
  227.   MODE = '' /* for pretty log-entry */
  228.   Call Log("Can't find matching mode!  Make an update in your "MODEFILENAME" file.")
  229.   Exit 5
  230. End
  231.  
  232. /*
  233. ** Produce the complete name of the file.
  234. */
  235. If PKFILENAME="" Then
  236.   PKNAME = PKDIR||DPI'/'FNTNAME'.'DPI'pk'
  237. Else
  238.   PKNAME = PKDIR||PKFILENAME
  239.  
  240. /*
  241. ** Look if the font already is there.
  242. */
  243. If Exists(PKNAME) Then Do
  244.   Say "The font "PKNAME" already exists!"
  245.   Say "Check your driver's configuration!"
  246.   Call Log(PKNAME" already exists; check your driver's configuration!")
  247.   Exit 5
  248. End
  249.  
  250. /*
  251. ** Install the options MetaFont is called with.
  252. */
  253. FORMAT = NORMALBASE
  254.  
  255. If MAGSTR ~= MAGMULT.STR.DEFAULT Then
  256.   OPTIONS = "\mode:="MODE"; mag:=magstep("MAGSTR"); scrollmode; input "FNTNAME
  257. Else
  258.   OPTIONS = "\mode:="mode"; mag:="MAG"; scrollmode; input "FNTNAME
  259.  
  260. DUMMY = Pragma("directory","MF:")
  261. Address COMMAND
  262.  
  263. /*
  264. ** First: Create the GF-file and the TFM-file and the LOG-file
  265. ** by calling the METAFONT progam.  If anything below fails, you
  266. ** can proceed by hand; all necessary files will be present.
  267. */
  268. Say "Calling MetaFont with format: &"FORMAT
  269. Say "and startup commands: '"OPTIONS"'"
  270.  
  271. VIRMF '&'FORMAT' "'OPTIONS'"'
  272.  
  273. /*
  274. ** My version of METAFONT returns codes 0, 5, 10 or 20.
  275. ** Take appropriate actions.
  276. */
  277. ERRORCODE = RC
  278.  
  279. If 5 >= ERRORCODE Then Do
  280.   If 0 < ERRORCODE Then
  281.     Say "Translation problem, MetaFont returned "ERRORCODE"."
  282.   Else
  283.     Say FNTNAME" translated without errors."
  284. End; Else Do
  285.   Say "Translation error, MetaFont returned "ERRORCODE"."
  286.   EDITSCRIPT = Word(MyGetEnv("MFREXXEDIT"),1)
  287.   If "" = EDITSCRIPT Then
  288.     EDITSCRIPT = 'MFEdit.rexx'
  289.   Say "Start editor for "FNTNAME" with "EDITSCRIPT"."
  290.   EDITSCRIPT FNTNAME 0
  291.   Exit 5
  292. End
  293.  
  294. /*
  295. ** Second: Create the PK-file by calling the GFtoPK program.
  296. ** This is done in the "MF:" directory, not in the final path.
  297. */
  298. GFTOPK FNTNAME'.'DPI'gf'
  299.  
  300. /*
  301. ** Don't delete the GF-file on failure.
  302. */
  303. If Exists(FNTNAME'.'DPI'pk') Then Do
  304.   Delete FNTNAME'.'DPI'gf'
  305.   FileNote FNTNAME'.'DPI'pk' ' "mode='MODE', magstep='MAGSTR'"'
  306. End
  307.  
  308. /*
  309. ** Third: Create all needed directories and try to move the
  310. ** files appropriately.
  311. */
  312.  
  313. /*
  314. ** Don't include last '/' in PKDIR, makedir doesn't like it.
  315. */
  316. PKDIR2 = Left(PKDIR,LastPos("/",PKDIR)-1)
  317.  
  318. If ~Exists(PKDIR2) Then
  319.   If ~MakeDir(PKDIR2) Then Do
  320.     Call Log("MakeDir "PKDIR2" failed")
  321.     Exit 5
  322.   End
  323.  
  324. /*
  325. ** A '/' is required to exist in PKNAME
  326. */
  327.  
  328. /*
  329. ** Don't include last '/' in FULLDIR, makedir doesn't like it.
  330. */
  331. FULLDIR = Left(PKNAME,LastPos("/",PKNAME)-1)
  332.  
  333. If ~Exists(FULLDIR) Then
  334.   If ~MakeDir(FULLDIR) Then Do
  335.     Call Log("MakeDir "FULLDIR" failed")
  336.     Exit 5
  337.   End
  338.  
  339. /*
  340. ** Check the TFM-file; if it doesn't exist, move it there
  341. ** and delete it here.
  342. */
  343. If Exists(TEXTFM) & ~Exists(TEXTFM||FNTNAME'.tfm') Then Do
  344.   Copy FNTNAME'.tfm' TEXTFM clone
  345.   Protect TEXTFM||FNTNAME'.tfm' r
  346. End
  347.  
  348. Delete FNTNAME'.tfm'
  349.  
  350. /*
  351. ** The following section makes a copy of the pk-file to MF:<mode>/PKFILENAME
  352. ** This is useful if you like to copy all new font-files to disks for
  353. ** future font-caching.  See the documentation for further details.
  354. */
  355. /*
  356. If ~Exists(MODE) Then Do
  357.   If ~MakeDir(MODE) Then Do
  358.     Call Log("Makedir "MODE" failed!")
  359.   End
  360. End
  361. If ~Exists(MODE'/'DPI) Then Do
  362.   If ~MakeDir(MODE'/'DPI) Then Do
  363.     Call Log("Makedir "MODE"/"DPI" failed!")
  364.   End
  365. End
  366. If Exists(MODE) Then
  367.   Copy FNTNAME'.'DPI'pk' MODE'/'PKFILENAME
  368. */
  369.  
  370. Copy FNTNAME'.'DPI'pk' PKNAME clone
  371. Delete FNTNAME'.'DPI'pk'
  372. Protect PKNAME r
  373.  
  374. /*
  375. ** Copy/Delete instead Rename to overwrite existing logfile (e.g., from
  376. ** a failed call of MakeTeXfont). Replace by 'move' if you have ARP:
  377. ** i.e., add a line here ``copy = "move" or "mv"''.  This seems to be
  378. ** the case for Ulrich Wisser in Version 1.0, as he uses "move" here.
  379. ** I still assume that most people want to use this script with the
  380. ** original WorkBench, so double moving would cause this to crash.
  381. ** Also, copy/delete unlike move works between devices, too.
  382. */
  383. Copy FNTNAME'.log' LOGDIR'/'FNTNAME'.'DPI'log'
  384. Delete FNTNAME'.log'
  385.  
  386. ELAPSED = Time("ELAPSED")
  387. Call Log("created in "ELAPSED%3600":"Right(ELAPSED%60//60,2,'0')":"Right(ELAPSED%1//60,2,'0'))
  388.  
  389. Exit 0
  390.  
  391. /*
  392. ** Log-function
  393. */
  394. LOG: Procedure Expose LOGNAME FNTNAME MODE HBASEDPI VBASEDPI DPI MAGSTR
  395. Parse Arg MSG
  396.  
  397. MESSAGE = Date()" "Time()": "FNTNAME" for "MODE" ("HBASEDPI","VBASEDPI") with "DPI" dpi (mag="MAGSTR") "'0A'X || MSG
  398. Say MESSAGE
  399.  
  400. If ~Open(LOGFILE,LOGNAME,'Append') Then Do
  401.   Say "Can't open logfile!"
  402.   Return
  403. End
  404.  
  405. DUMMY = Writeln(LOGFILE,MESSAGE)
  406. If ~Close(LOGFILE) Then
  407.   Say "Can't close logfile!"
  408.  
  409. Return
  410.  
  411. /*
  412. ** Signal-functions.
  413. */
  414. ERROR:
  415.   DOLINE = 'call log("errorlevel 'rc' in line 'sigl': "'sourceline(sigl)')'
  416.   Interpret(DOLINE)
  417.   If Exists(FNNAME'.log') Then Do
  418.     Copy FNTNAME'.log' FNTNAME'.'DPI'log'
  419.     Delete FNTNAME'.log'
  420.   End
  421.   Exit 1
  422.  
  423. BREAK_C:
  424. BREAK_D:
  425.   Call Log "execution aborted!"
  426.   If Exists(FNTNAME'.'DPI'gf') Then
  427.     DUMMY = Delete FNTNAME'.'DPI'gf'
  428.   If Exists(FNTNAME'.log') Then
  429.     DUMMY = Delete FNTNAME'.log'
  430.  
  431.   Exit 1
  432.