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 >
Wrap
OS/2 REXX Batch file
|
1995-04-10
|
4KB
|
125 lines
/*
* Convert MetaPost to C.
*/
NL = '0A'X
AWKSCRIPTNAME = 'amiga_script.awk'
SEDSCRIPTNAME1 = 'amiga_script1.sed'
SEDSCRIPTNAME2 = 'amiga_script2.sed'
SEDSCRIPTNAME3 = 'amiga_script3.sed'
/*
* Prepare the AWK script.
*/
AWK = 'BEGIN {' || NL
AWK = AWK || ' dot=0' || NL
AWK = AWK || '}' || NL
AWK = AWK || '/\.$/ {' || NL
AWK = AWK || ' if (dot) printf(".")' || NL
AWK = AWK || ' dot=1' || NL
AWK = AWK || ' print substr($0,1,length($0)-1)' || NL
AWK = AWK || ' next' || NL
AWK = AWK || '}' || NL
AWK = AWK || '{' || NL
AWK = AWK || ' if (dot) printf(".")' || NL
AWK = AWK || ' print ' || NL
AWK = AWK || ' dot=0' || NL
AWK = AWK || '}' || NL
AWK = AWK || 'END {' || NL
AWK = AWK || ' if (dot) printf(".\n")' || NL
AWK = AWK || '}'
If ~Open('output',AWKSCRIPTNAME,'Write') Then Do
Say "Can't open file `" || AWKSCRIPTNAME || "'"
Exit 10
End
Call WriteLn('output',AWK)
Call Close('output')
/*
* Prepare the SED scripts.
*/
SED1 = 's/\.hh/.hhfield/g' || NL
SED1 = SED1 || 's/\.lh/.lhfield/g'
If ~Open('output',SEDSCRIPTNAME1,'Write') Then Do
Say "Can't open file `" || SEDSCRIPTNAME1 || "'"
Exit 10
End
Call WriteLn('output',SED1)
Call Close('output')
SED2 = 's/else write/else\' || NL
SED2 = SED2 || 'write/' || NL
SED2 = SED2 || 's/ *\([A-Za-z0-9]*\) *= *\(".*"\) *;'
SED2 = SED2 || '/ (void) strcpy(\1 + 1, \2) ;/' || NL
SED2 = SED2 || 's/ *nameoffile *= *poolname'
SED2 = SED2 || '/ (void) strncpy(nameoffile+1, poolname, sizeof poolname)/' || NL
SED2 = SED2 || 's/ *nameoffile *= *pstabname'
SED2 = SED2 || '/ (void) strncpy(nameoffile+1, pstabname, sizeof pstabname)/' || NL
SED2 = SED2 || 's/ maxcoef\( *[^( ]\)/ lmaxcoef\1/g' || NL
SED2 = SED2 || 's/ b1/ lb1/g' || NL
SED2 = SED2 || 's/ b2/ lb2/g' || NL
SED2 = SED2 || 's/ b3/ lb3/g' || NL
SED2 = SED2 || '/ *read/ s/read *( *\([a-z]*\) *, *\([a-z]*\) *, *\([a-z]*\)'
SED2 = SED2 || '/read (\1 , \2); read (\1, \3/g'
If ~Open('output',SEDSCRIPTNAME2,'Write') Then Do
Say "Can't open file `" || SEDSCRIPTNAME2 || "'"
Exit 10
End
Call WriteLn('output',SED2)
Call Close('output')
/*
* Don't even think about replacing this TAB character!
* V
*/
SED3 = 's/undef TRAP/define TRAP/' || NL
SED3 = SED3 || 's/define memmax [0-9][0-9]*/define memmax 4500/' || NL
SED3 = SED3 || 's/define maxinternal [0-9][0-9]*/define maxinternal 100/' || NL
SED3 = SED3 || 's/define errorline [0-9][0-9]*/define errorline 64/' || NL
SED3 = SED3 || 's/define halferrorline [0-9][0-9]*/define halferrorline 32/' || NL
SED3 = SED3 || 's/define maxprintline [0-9][0-9]*/define maxprintline 72/' || NL
SED3 = SED3 || 's/define memtop [0-9][0-9]*/define memtop 4500/'
If ~Open('output',SEDSCRIPTNAME3,'Write') Then Do
Say "Can't open file `" || SEDSCRIPTNAME3 || "'"
Exit 10
End
Call WriteLn('output',SED3)
Call Close('output')
/*
* OK, off we go!
*/
Address Command
"gawk -f" AWKSCRIPTNAME "../lib/common.defines ../lib/texmf.defines ../lib/texmfextras.defines mp.p > temp_a"
"delete quiet" AWKSCRIPTNAME
"sed -f" SEDSCRIPTNAME1 "< temp_a > temp_b"
"delete quiet temp_a" SEDSCRIPTNAME1
"../web2c/web2c -handytexmf.h -m < temp_b > temp_c"
"delete temp_b quiet"
"sed -f" SEDSCRIPTNAME2 "< temp_c > temp_d"
"delete quiet temp_c" SEDSCRIPTNAME2
"../web2c/fixwrites < temp_d > temp_e"
"delete temp_d quiet"
"../web2c/regfix < temp_e > temp_f"
"delete temp_e quiet"
"../web2c/splitup mp < temp_f"
"delete temp_f quiet"
"type coerce.h andycoerce.add > xcoerce.h"
"copy xcoerce.h coerce.h"
"delete xcoerce.h quiet"
"sed -f" SEDSCRIPTNAME3 "< mpd.h > trap_mpd.h"
"copy mpd.h orig_mpd.h"
"delete quiet" SEDSCRIPTNAME3
Exit 0