home *** CD-ROM | disk | FTP | other *** search
/ Dream 45 / Amiga_Dream_45.iso / Amiga / Magazine / Dossier-LaTeX / AmiWeb2C.lha / source / web2c-6.1 / web2c / mp / convert.rexx < prev    next >
OS/2 REXX Batch file  |  1995-04-10  |  4KB  |  125 lines

  1. /*
  2.  * Convert MetaPost to C.
  3.  */
  4.  
  5. NL = '0A'X
  6.  
  7. AWKSCRIPTNAME  = 'amiga_script.awk'
  8. SEDSCRIPTNAME1 = 'amiga_script1.sed'
  9. SEDSCRIPTNAME2 = 'amiga_script2.sed'
  10. SEDSCRIPTNAME3 = 'amiga_script3.sed'
  11.  
  12. /*
  13.  * Prepare the AWK script.
  14.  */
  15. AWK =        'BEGIN {'                             || NL
  16. AWK = AWK || '    dot=0'                           || NL
  17. AWK = AWK || '}'                                   || NL
  18. AWK = AWK || '/\.$/ {'                             || NL
  19. AWK = AWK || '    if (dot) printf(".")'            || NL
  20. AWK = AWK || '    dot=1'                           || NL
  21. AWK = AWK || '    print substr($0,1,length($0)-1)' || NL
  22. AWK = AWK || '    next'                            || NL
  23. AWK = AWK || '}'                                   || NL
  24. AWK = AWK || '{'                                   || NL
  25. AWK = AWK || '    if (dot) printf(".")'            || NL
  26. AWK = AWK || '    print '                          || NL
  27. AWK = AWK || '    dot=0'                           || NL
  28. AWK = AWK || '}'                                   || NL
  29. AWK = AWK || 'END {'                               || NL
  30. AWK = AWK || '    if (dot) printf(".\n")'          || NL
  31. AWK = AWK || '}'
  32. If ~Open('output',AWKSCRIPTNAME,'Write') Then Do
  33.   Say "Can't open file `" || AWKSCRIPTNAME || "'"
  34.   Exit 10
  35. End
  36. Call WriteLn('output',AWK)
  37. Call Close('output')
  38.  
  39. /*
  40.  * Prepare the SED scripts.
  41.  */
  42. SED1 =         's/\.hh/.hhfield/g' || NL
  43. SED1 = SED1 || 's/\.lh/.lhfield/g'
  44. If ~Open('output',SEDSCRIPTNAME1,'Write') Then Do
  45.   Say "Can't open file `" || SEDSCRIPTNAME1 || "'"
  46.   Exit 10
  47. End
  48. Call WriteLn('output',SED1)
  49. Call Close('output')
  50.  
  51. SED2 =         's/else write/else\'                                            || NL
  52. SED2 = SED2 || 'write/'                                                        || NL
  53. SED2 = SED2 || 's/  *\([A-Za-z0-9]*\) *= *\(".*"\) *;'
  54. SED2 = SED2 || '/  (void) strcpy(\1 + 1, \2) ;/'                               || NL
  55. SED2 = SED2 || 's/  *nameoffile *= *poolname'
  56. SED2 = SED2 || '/  (void) strncpy(nameoffile+1, poolname, sizeof poolname)/'   || NL
  57. SED2 = SED2 || 's/  *nameoffile *= *pstabname'
  58. SED2 = SED2 || '/  (void) strncpy(nameoffile+1, pstabname, sizeof pstabname)/' || NL
  59. SED2 = SED2 || 's/ maxcoef\( *[^( ]\)/ lmaxcoef\1/g'                           || NL
  60. SED2 = SED2 || 's/ b1/ lb1/g'                                                  || NL
  61. SED2 = SED2 || 's/ b2/ lb2/g'                                                  || NL
  62. SED2 = SED2 || 's/ b3/ lb3/g'                                                  || NL
  63. SED2 = SED2 || '/ *read/ s/read *( *\([a-z]*\) *, *\([a-z]*\) *, *\([a-z]*\)'
  64. SED2 = SED2 || '/read (\1 , \2); read (\1, \3/g'
  65. If ~Open('output',SEDSCRIPTNAME2,'Write') Then Do
  66.   Say "Can't open file `" || SEDSCRIPTNAME2 || "'"
  67.   Exit 10
  68. End
  69. Call WriteLn('output',SED2)
  70. Call Close('output')
  71.  
  72. /*
  73.  * Don't even think about replacing this TAB character!
  74.  *                     V
  75.  */
  76. SED3 =         's/undef    TRAP/define TRAP/'                                   || NL
  77. SED3 = SED3 || 's/define memmax [0-9][0-9]*/define memmax 4500/'             || NL
  78. SED3 = SED3 || 's/define maxinternal [0-9][0-9]*/define maxinternal 100/'    || NL
  79. SED3 = SED3 || 's/define errorline [0-9][0-9]*/define errorline 64/'         || NL
  80. SED3 = SED3 || 's/define halferrorline [0-9][0-9]*/define halferrorline 32/' || NL
  81. SED3 = SED3 || 's/define maxprintline [0-9][0-9]*/define maxprintline 72/'   || NL
  82. SED3 = SED3 || 's/define memtop [0-9][0-9]*/define memtop 4500/'
  83. If ~Open('output',SEDSCRIPTNAME3,'Write') Then Do
  84.   Say "Can't open file `" || SEDSCRIPTNAME3 || "'"
  85.   Exit 10
  86. End
  87. Call WriteLn('output',SED3)
  88. Call Close('output')
  89.  
  90. /*
  91.  * OK, off we go!
  92.  */
  93. Address Command
  94.  
  95. "gawk -f" AWKSCRIPTNAME "../lib/common.defines ../lib/texmf.defines ../lib/texmfextras.defines mp.p > temp_a"
  96. "delete quiet" AWKSCRIPTNAME
  97.  
  98. "sed -f" SEDSCRIPTNAME1 "< temp_a > temp_b"
  99. "delete quiet temp_a" SEDSCRIPTNAME1
  100.  
  101. "../web2c/web2c -handytexmf.h -m < temp_b > temp_c"
  102. "delete temp_b quiet"
  103.  
  104. "sed -f" SEDSCRIPTNAME2 "< temp_c > temp_d"
  105. "delete quiet temp_c" SEDSCRIPTNAME2
  106.  
  107. "../web2c/fixwrites < temp_d > temp_e"
  108. "delete temp_d quiet"
  109.  
  110. "../web2c/regfix < temp_e > temp_f"
  111. "delete temp_e quiet"
  112.  
  113. "../web2c/splitup mp < temp_f"
  114. "delete temp_f quiet"
  115.  
  116. "type coerce.h andycoerce.add > xcoerce.h"
  117. "copy xcoerce.h coerce.h"
  118. "delete xcoerce.h quiet"
  119.  
  120. "sed -f" SEDSCRIPTNAME3 "< mpd.h > trap_mpd.h"
  121. "copy mpd.h orig_mpd.h"
  122. "delete quiet" SEDSCRIPTNAME3
  123.  
  124. Exit 0
  125.