Path: utzoo!attcan!uunet!husc6!bbn!uwmcsd1!ig!agate!ucbvax!ean.ubc.ca!prindiville%ccrs.CDN From: prindiville%ccrs.CDN@ean.ubc.ca (John Edgecombe) Newsgroups: comp.os.vms Subject: Re: RUNOFF to TeX converter Message-ID: <22*prindiville@ccrs.cdn> Date: 11 Jul 88 21:54:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 908 Sorry about the previous send, I am still learning this mailer. I'll try again with a different method. +-+-+-+ Beginning of part 3 +-+-+-+ X if s = 'PAGE' then X listispagecommand := true X end Xend; X X X X[GLOBAL] PROCEDURE checkfordsrcommand( var infile, outfile : text; X`009 var dsrcommand : boolean ); Xvar X gotten : boolean; Xbegin X if flagclass(currentchar) = control then X begin X getnextchar(infile, gotten); X if gotten then X begin X if (flagclass(currentchar) <> comment) and (currentchar <> blank) then X dsrcommand := true X end X else X begin X dsrcommand := false; X texwrite(outfile, currentchar) X end X end X else X dsrcommand := false Xend; X X X X X[GLOBAL] PROCEDURE parsedsrcommand( var infile, outfile : text; var list : X`009 arglist; var anothercommand : boolean; V`009 var carrychar : boolean; var charcarried : ch Xar); Xconst X dontwritethem = false; Xtype V charidentity = (letter, separator, number, semicolon, quote, commentchar,new Xdsrcommand); Xvar X quotedchar : char; X argread : argument; X currentargclass : charidentity; X done, gotten, atseparator, endofdsrcommand : boolean; X i : integer; X X function charclass( ch : char ) : charidentity; X label X localexit; X begin X charclass := separator; X if flagclass( ch ) = control then X begin X charclass := newdsrcommand; X goto localexit X end; X if ch in ['a'..'z','A'..'Z'] then X begin X charclass := letter; X goto localexit X end; X if ch in ['+','-','0'..'9'] then X begin X charclass := number; X`009 goto localexit X end; X if ch in [chr(34), chr(39)] then X begin X charclass := quote; X goto localexit X end; X if flagclass(currentchar) = comment then X begin X charclass := commentchar; X goto localexit X end; X if ch = ';' then X charclass := semicolon; X localexit : nullstatement X end; X X procedure startarg( ch : char; var arg : argument; startset : setofargtype); X begin X initarg(arg, startset, ch, indexofunknowntexcommand, false); X end; X Xbegin X list := nulllist; X atseparator := false; X endofdsrcommand := false; X anothercommand := false; X carrychar := false; X repeat X currentargclass := charclass(currentchar); X case currentargclass of X `009 letter : begin X`009 atseparator := false; V`009 startarg(currentchar, argread, [dsrverb,stylespecifier, tex Xtpckstr,character]); X done := false; X repeat X`009 getnextchar(infile, gotten); X if gotten then X`009 begin X`009 if charclass(currentchar) = letter then X appendchartoarg(currentchar, argread) X else X done := true X end X`009 else X begin X done := true; X`009 endofdsrcommand := true X`009 end X`009 until done; X`009 appendargonlist(list, argread ) X end; X `009 number : begin X`009 atseparator := false; V`009 startarg(currentchar, argread, [int,signedint,textpckstr,nu Xlltype]); X done := false; X repeat X`009 getnextchar(infile, gotten); X if gotten then X`009 begin X`009 if charclass(currentchar) = number then X appendchartoarg(currentchar, argread) X else X done := true X end X`009 else X begin X done := true; X`009 endofdsrcommand := true X`009 end X`009 until done; X`009 appendargonlist(list, argread ) X end; X`009 separator : begin X`009 passblanks(infile, outfile, dontwritethem); X`009 if (atseparator) and (currentchar <> lastinputchar) then X`009 begin X`009 startarg(blank, argread, [nulltype]); X`009 appendargonlist(list, argread); X atseparator := false X`009 end X`009 else X`009 begin X if flagclass(currentchar) = control then X`009 endofdsrcommand := true X else X if charclass(currentchar) = separator then X begin X getnextchar(infile, gotten); X`009 if gotten then X atseparator := true X`009 else X begin X atseparator := false; X`009 startarg(blank, argread, [nulltype]); X`009 appendargonlist(list, argread); X`009 endofdsrcommand := true X end X end X`009 end V`009 end; X X`009semicolon : begin X endofdsrcommand := true; X`009 getnextchar(infile, gotten); X`009 if charclass(currentchar) = newdsrcommand then X`009 currentargclass := newdsrcommand X`009 else X`009 begin X`009 carrychar := true; X`009 charcarried := currentchar X`009 end X`009 end; X`009 quote : begin X`009 quotedchar := currentchar; X`009 getnextchar(infile, gotten); X if gotten then X`009 begin X`009 startarg(currentchar, argread, [quotedpckstr]); X`009 done := false; X`009 repeat X`009 getnextchar(infile, gotten); X`009 if gotten then X`009 begin X`009 if charclass(currentchar) = quote then X`009 begin X`009 getnextchar(infile, gotten); X`009 done := true; X`009 if not gotten then X`009 endofdsrcommand := true X`009 end X`009 else X`009 appendchartoarg(currentchar, argread) X`009 end X else X`009 begin X`009 endofdsrcommand := true; X`009 done := true X`009 end X`009 until done X`009 end X`009 else X`009 startarg(quotedchar, argread,[textpckstr,character]); X appendargonlist(list, argread) X end; X commentchar : begin X`009 endofdsrcommand := true X end; X newdsrcommand : begin X endofdsrcommand := true; X end X end; {case} X until endofdsrcommand; X if currentargclass <> newdsrcommand then X newline( infile, outfile, false) X else X anothercommand := true Xend; X`009 X X XPROCEDURE parsefile( var infile, outfile : text; textree : argtree ); Xconst X nocrlf = false; X putcrlf = true; Xvar X dsrcommandfound : boolean; X chargotten : boolean; X dsrarguments : arglist; X texcommandindex : integer; X nextcommandtowrite : integer; X successfulparse : boolean; X depthofsearch : integer; X anothercommand : boolean; X carrychar : boolean; X charcarried, copychar : char; Xbegin X ttywritestring('Translating input ...'); X totalgooddsrcommands := 0; X totalbaddsrcommands := 0; X nextcommandtowrite := indexofunknowntexcommand; X anothercommand := false; X repeat X putsecondarytexcommand( outfile, nextcommandtowrite); X repeat X checkfordsrcommand( infile, outfile, dsrcommandfound ); X if dsrcommandfound then X begin V parsedsrcommand( infile, outfile, dsrarguments, anothercommand,carrycha Xr,charcarried); X if listispagecommand( dsrarguments) then X begin X successfulparse := true; X texcommandindex := indexofpagecommand X end X else V searchtreeforlist( textree, dsrarguments,successfulparse, texcommandi Xndex, X depthofsearch); X if successfulparse then X begin X totalgooddsrcommands := totalgooddsrcommands + 1; V puttexcommand(outfile, texcommandindex, dsrarguments, nextcommandtowr Xite); X if carrychar then X begin X`009 copychar := currentchar; X`009 currentchar := charcarried; X`009 writecurrentchar( infile, outfile ); X`009 currentchar := copychar X end X end X else X begin X totalbaddsrcommands := totalbaddsrcommands + 1; X write(outfile,'%Unidentified RUNOFF command "'); X dumpthelist(outfile, dsrarguments); X writeln(outfile,'"') X end X end X else X anothercommand := false X until (not dsrcommandfound) and (not anothercommand); X repeat X writecurrentchar( infile, outfile ); X getnextchar(infile, chargotten) X until not chargotten; X newline(infile, outfile, putcrlf) X until eof(infile) Xend; X X X XEND. X X $ GOSUB UNPACK_FILE $ FILE_IS = "FLAGOPS.PAS" $ CHECKSUM_IS = 125287985 $ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY X[INHERIT('UTILITYOPS','ARGOPS')] X XMODULE FLAGOPS; X XCONST X X tab = 9; X ncharsintab = 8; X XTYPE X Xdsrflagtype = record X`009 representation : char; X`009 turnedon : boolean X `009 end; X X Xdsrflagclasses = (notaflag, control, uppercase, lowercase, quote, Xspace, underline, bold, overstrike, hyphenate, break, period, capitalize, Xendfootnote, comment, substitute); X Xflagtabletype = array[dsrflagclasses] of dsrflagtype; X Xtabrecordtype = record X`009 tabread : boolean; X`009 charcountintab : integer X`009 end; X Xstyletype = (undetermined, decimal, octal, hexidecimal, romanupper, romanlower, X`009 romanmixed, letterupper, letterlower, lettermixed, nostyle); X Xenhancmentstates = (notenhanced, singlecharenhanced, enhancmentlocked); X X X XVAR X X`009lastinputchar, currentchar : [EXTERNAL] char; X capitalizetext, lowercasetext : [EXTERNAL] boolean; X`009inputcontainstexcommands : [EXTERNAL] boolean; X inliteral : [EXTERNAL] boolean; X totallines, totalchars : [EXTERNAL] integer; X flagtable : [EXTERNAL] flagtabletype; X tabrecord : [EXTERNAL] tabrecordtype; X`009LOG : [EXTERNAL] text; X columncounter : [EXTERNAL] integer; X`009infootnote : [EXTERNAL] boolean; X`009boldactive : [EXTERNAL] enhancmentstates; X underlineactive : [EXTERNAL] enhancmentstates; X startnofillagain : [EXTERNAL] boolean; X fill : [EXTERNAL] boolean; X listnestlevel : [EXTERNAL] integer; X X X X[GLOBAL] PROCEDURE beginnofill( var outfile : text ); Xbegin X if (fill) and (listnestlevel = 0) then X begin X writeln(outfile,'{\obeylines \obeyspaces % - begin no fill'); X fill := false X end X else X begin X writeln(outfile,'% - RNOTOTEX obeylines, obeyspaces already active'); X writeln( log,'% - RNOTOTEX obeylines, obeyspaces already active') X end Xend; X X X X X[GLOBAL] PROCEDURE endnofill( var outfile : text ); Xbegin X if (not fill) and (listnestlevel = 0) then X begin X writeln(outfile,'} % - end of no fill'); X fill := true X end X else X begin X writeln(outfile,'% - RNOTOTEX obeylines, obeyspaces not active'); X writeln( log,'% - RNOTOTEX obeylines, obeyspaces not active') X end Xend; X X X X X X X[GLOBAL] PROCEDURE writeflagname( var outfile : text; f : dsrflagclasses ); Xbegin X case f of X notaflag : write(outfile,'?????'); X control : write(outfile,'CONTROL'); X uppercase : write(outfile,'UPPERCASE'); X lowercase : write(outfile,'LOWERCASE'); X quote : write(outfile,'QUOTE'); X space : write(outfile,'SPACE'); X underline : write(outfile,'UNDERLINE'); X bold : write(outfile,'BOLD'); X overstrike : write(outfile,'OVERSTRIKE'); X hyphenate : write(outfile,'HYPYENATE'); X capitalize : write(outfile,'CAPITALIZE'); X endfootnote : write(outfile,'END FOOTNOTE'); X comment : write(outfile,'COMMENT'); X substitute : write(outfile,'SUBSTITUTE') X end Xend; X X X X X X X[GLOBAL] FUNCTION isastylespecifier( arg : argument ) : styletype; Xlabel X routineexit; Xvar X s : pckstr; X classification : styletype; Xbegin X s := argliteral( arg, TRUE ); X classification := undetermined; X if (s.body[1] = 'D') and (s.length = 1) then X begin X classification := decimal; X goto routineexit X end; X if (s.body[1] = 'O') and (s.length = 1) then X begin X classification := octal; X goto routineexit X end; X if (s.body[1] = 'H') and (s.length = 1) then X begin X classification := hexidecimal; X goto routineexit X end; X if (s.body = 'RU') and (s.length = 2) then X begin X classification := romanupper; X goto routineexit X end; X if (s.body = 'RL') and (s.length = 2) then X begin X classification := romanlower; X goto routineexit X end; X if (s.body = 'RM') and (s.length = 2) then X begin X classification := romanmixed; X goto routineexit X end; X if (s.body = 'LU') and (s.length = 2) then X begin X classification := letterupper; X goto routineexit X end; X if (s.body = 'LL') and (s.length = 2) then X begin X classification := letterlower; X goto routineexit X end; X if (s.body = 'LM') and (s.length = 2) then X begin X classification := lettermixed; X goto routineexit X end; X routineexit : isastylespecifier := classification Xend; X X X X[GLOBAL] PROCEDURE initflagtable; Xvar X f : dsrflagclasses; Xbegin X for f := notaflag to substitute do X case f of X `009notaflag : begin X`009 flagtable[f].representation := blank; X`009 flagtable[f].turnedon := false X`009 end; X `009control : begin X`009 flagtable[f].representation := '.'; X`009 flagtable[f].turnedon := true X`009 end; X `009uppercase : begin X`009 flagtable[f].representation := '^'; X`009 flagtable[f].turnedon := true X`009 end; X `009lowercase : begin X`009 flagtable[f].representation := '\'; X`009 flagtable[f].turnedon := true X`009 end; X `009quote : begin X`009 flagtable[f].representation := '_'; X`009 flagtable[f].turnedon := true X`009 end; X `009space : begin X`009 flagtable[f].representation := '#'; X`009 flagtable[f].turnedon := true X`009 end; X `009underline : begin X`009 flagtable[f].representation := '&'; X`009 flagtable[f].turnedon := true X`009 end; X `009bold : begin X`009 flagtable[f].representation := '*'; X`009 flagtable[f].turnedon := false X`009 end; X `009overstrike : begin X`009 flagtable[f].representation := '%'; X`009 flagtable[f].turnedon := false X`009 end; X `009hyphenate : begin X`009 flagtable[f].representation := '='; X`009 flagtable[f].turnedon := false X`009 end; X `009break : begin X`009 flagtable[f].representation := '|'; X`009 flagtable[f].turnedon := false X`009 end; X `009period : begin X`009 flagtable[f].representation := '+'; X`009 flagtable[f].turnedon := false X`009 end; X `009capitalize : begin X`009 flagtable[f].representation := '<'; X`009 flagtable[f].turnedon := false X`009 end; X endfootnote : begin X flagtable[f].representation := '!'; X`009 flagtable[f].turnedon := false X`009 end; X `009comment : begin X`009 flagtable[f].representation := '!'; X`009 flagtable[f].turnedon := true X`009 end; X `009substitute : begin X`009 flagtable[f].representation := '$'; X`009 flagtable[f].turnedon := false X`009 end X end { case } Xend; {initflagtable} X X X X X[GLOBAL] FUNCTION flagclass( ch : char ) : dsrflagclasses; Xvar X class : dsrflagclasses; X foundclass : boolean; Xbegin X class := control; X foundclass := false; X while (class <> substitute) and ( not foundclass) do V if (ch = flagtable[class].representation) and (flagtable[class].turnedon)t Xhen X foundclass := true X else X class := succ(class); X if foundclass then X if inliteral then X`009if class = control then X`009 flagclass := control X`009else X`009 flagclass := notaflag X else X flagclass := class X else X flagclass := notaflag Xend; X X X X X[GLOBAL] PROCEDURE initcharreader(var f : text ); Xbegin X reset(f); X lastinputchar := blank; X read(f, currentchar); X totallines := 0; X totalchars := 0; X columncounter := 1; X if ord(currentchar) = tab then X begin X tabrecord.tabread := true; X tabrecord.charcountintab := ncharsintab X end X else X begin X tabrecord.tabread := false; X tabrecord.charcountintab := 0 X end Xend; X X X X X[GLOBAL] PROCEDURE getnextchar( var f : text; var gotten : boolean ); X X function nexttabcolumn( startingcolumn : integer ) : integer; X var X i : integer; X begin X i := startingcolumn; X repeat X i := i + 1 X until (i-1) mod ncharsintab = 0; X nexttabcolumn := i; X writeln(log,'nexttabcolumn input = ',startingcolumn:1,', output = ',i:1) X end; X Xbegin X gotten := false; X if NOT eof(f) then X if NOT eoln(f) then X with tabrecord do X begin X lastinputchar := currentchar; X gotten := true; X columncounter := columncounter + 1; X if (tabread) and (charcountintab > 0) then X begin X`009 currentchar := blank; X`009 charcountintab := charcountintab - 1; X`009 if charcountintab = 0 then tabread := false X`009end X`009else X`009begin X totalchars := totalchars + 1; X read( f, currentchar ); X if currentchar < blank then X begin X if ord(currentchar) = tab then X begin X tabread := true; V charcountintab := nexttabcolumn( columncounter ) - columncounter X-1; X writeln(log,'charcountintab = ',charcountintab) X end; X`009 currentchar := blank X end X end X end Xend; X X X V[GLOBAL] PROCEDURE startunderline( var outfile : text; class : enhancmentstates X); Xbegin X if class <> notenhanced then X case underlineactive of X notenhanced : begin X`009 write(outfile,'\underline{'); X`009 underlineactive := class X`009 end; X singlecharenhanced : nullstatement; X enhancmentlocked : nullstatement X end; X underlineactive := class Xend; X X X X X[GLOBAL] PROCEDURE stopunderline( var outfile : text ); Xbegin X case underlineactive of X notenhanced : nullstatement; X singlecharenhanced : begin X`009 write(outfile,'} '); X`009 underlineactive := notenhanced X`009 end; X enhancmentlocked : nullstatement X end Xend; X X X X X[GLOBAL] PROCEDURE startbold( var outfile : text; class : enhancmentstates); Xbegin X if class <> notenhanced then X case boldactive of X notenhanced : begin X`009 write(outfile,'{\bf '); X`009 boldactive := class X`009 end; X singlecharenhanced : nullstatement; X enhancmentlocked : nullstatement X end; X boldactive := class Xend; X X X X X[GLOBAL] PROCEDURE stopbold( var outfile : text ); Xbegin X case boldactive of X notenhanced : nullstatement; X singlecharenhanced : begin X`009 write(outfile,'} '); X`009 boldactive := notenhanced X`009 end; X enhancmentlocked : nullstatement X end Xend; X X X X X V[GLOBAL] PROCEDURE passblanks( var infile, outfile : text; writethem : boolean X); Xvar X gotten, keeppassing : boolean; Xbegin X keeppassing := true; X gotten := true; X repeat X if (currentchar = blank) and (gotten) then X begin X if writethem then write(outfile, blank ); X getnextchar(infile, gotten) X end X else X keeppassing := false X until NOT keeppassing Xend; X X X X[GLOBAL] PROCEDURE texwrite( var f : text; ch : char ); Xconst X maxtrys = 2; Xvar X ntrys : integer; X written : boolean; Xbegin X ntrys := 0; X written := false; X repeat X if (inputcontainstexcommands) or (inliteral) then X write(f, ch, error := continue) X else X if ch >= blank then X if ch in ['#','$','%','&','_','^','{','}','~'] then X write(f, '\',ch, error := continue) X else X if ch = '\' then X write(f,'\backslash ', error := continue) X else X write(f, ch, error := continue); X if status(f) > 0 then X begin X writeln(f, error := continue); X ntrys := ntrys + 1 X end X else X written := true X until (written) or (ntrys > maxtrys); X if ntrys > maxtrys then X errorexit('TEXWRITE','error writing to output') Xend; X X X X[GLOBAL] PROCEDURE writecurrentchar( var infile, outfile : text ); Xvar X gotten : boolean; Xbegin X if capitalizetext then X currentchar := capchar( currentchar ); X if lowercasetext then X currentchar := lcchar( currentchar ); X case flagclass(currentchar) of X notaflag : begin X`009 stopunderline( outfile ); X`009 stopbold( outfile ); X`009 texwrite(outfile, currentchar) X end; X`009control : begin X`009 stopunderline( outfile ); X`009 stopbold( outfile ); X`009 texwrite(outfile, currentchar) X end; X `009uppercase : begin X getnextchar(infile, gotten); X if gotten then X case flagclass(currentchar) of X`009`009 underline : startunderline( outfile, enhancmentlocked); X`009 bold : startbold( outfile, enhancmentlocked ); X otherwise texwrite(outfile, capchar(currentchar)) X end X`009 end; X `009lowercase : begin X getnextchar(infile, gotten); X if gotten then X`009 case flagclass(currentchar) of X`009`009 underline : begin X`009 if underlineactive <> notenhanced then X`009 write(outfile,'} '); X`009 underlineactive := notenhanced X`009 end; X`009 bold : begin X if boldactive <> notenhanced then X `009 write(outfile,'} '); X`009 boldactive := notenhanced X`009 end; X otherwise texwrite(outfile, lcchar(currentchar)) X end X`009 end; X `009quote : begin X`009 getnextchar(infile, gotten); X if gotten then X`009 texwrite(outfile, currentchar ) X`009 end; X `009space : write(outfile,'\ '); X `009underline : begin X getnextchar(infile, gotten ); X if gotten then X begin X startunderline( outfile, singlecharenhanced); X`009 texwrite(outfile, currentchar) X end X`009 else X`009 texwrite(outfile, currentchar) X end; X `009bold : begin X`009 getnextchar(infile, gotten); X if gotten then X begin X startbold( outfile, singlecharenhanced); X`009 texwrite(outfile, currentchar) X`009 end X`009 else X`009 texwrite(outfile, currentchar) X`009 end; X `009overstrike : begin X`009 getnextchar(infile, gotten); X if gotten then X begin X`009 startbold( outfile, singlecharenhanced); X`009 texwrite(outfile, currentchar) X`009 end X`009 else X`009 texwrite(outfile, currentchar) X`009 end; X `009hyphenate : write(outfile,'--'); X `009break : writeln(outfile,'\linebreak'); X `009period : write(outfile,'\nonfrenchspacing '); X `009capitalize : begin X`009 getnextchar( infile, gotten); X`009 if gotten then X`009 texwrite(outfile, capchar(currentchar)) X`009 end; X endfootnote : begin X`009 if (columncounter = 1) and (infootnote) then X`009 begin X if not fill then X`009 endnofill( outfile ); X`009 `009 writeln(outfile,'} % - end of footnote'); X`009 writeln( log,'} % - end of footnote'); X infootnote := false; X`009 if startnofillagain then X`009 begin X`009 startnofillagain := false; X`009 beginnofill( outfile ) X`009 end X`009 end X`009 else X`009 texwrite(outfile, currentchar) X`009 end; X `009comment : begin X if flagclass(lastinputchar) = control then X`009 write(outfile,'% ') X else X`009 texwrite(outfile,currentchar) X`009 end; X `009substitute : texwrite(outfile, currentchar) X end { case } Xend; X X X X X[GLOBAL] PROCEDURE newline( var infile, outfile : text; putcrlf : boolean ); Xvar -+-+-+-+-+ End of part 3 +-+-+-+-+-