#!/mclab/imc/sun4/rexx -x /* Generate HTML sectioned documents from rexx.{info,ref,summary,tech} */ /* Invoke with a list of things to make; default is "info ref summary tech" */ instr=0; math=0 /* these variables are local to the separator() function */ /* Two environments: one current and one alternate. Change these as necessary. */ address command /* for quicker parsing */ address unix /* to address a Bourne shell */ docdir="/scratch/imc/www/docs" /* docs root directory on this machine */ rootdir="/oucl/users/ian.collier" /* href for my WWW home directory */ txtimage="/oucl/users/ian.collier/images/txt.gif" /* href for "text" image */ dirimage="/oucl/users/ian.collier/images/dir.gif" /* href for "menu" image */ upimage="/archive/images/gif/prev.gif" /* href for "go back" image */ force=0 parse arg list if list="" then list="info ref summary tech" else force=1 do until list="" parse var list item list infile=docdir"/rexx."item outdir=docdir"/rexx_"item outchk=outdir'/.chk' if \force then do /* only make the docs if... */ rc=1 parse source . . myself . if \newer(myself,outdir) /* this prog has been changed, or */ then if \newer(infile,outdir) /* the input file has been changed, */ then "ls -R" outdir "|wc | cmp -" outchk ">/dev/null 2>&1" /* or the check is incorrect (a file*/ /* might have been erased). */ if rc=0 then iterate end address "rm -r" outdir "mkdir" outdir /* make a fresh start */ address /* For the "the whole file" option there will be the index and the text. The index (docindex) and text (doctext) will be built up as the input file is parsed, then the text will be appended to the index. */ docindex=outdir"/whole.html" doctext="/tmp/mkdoc!"random() index=outdir"/index.html" /* the top-level menu */ select when item="info" then description="Tutorial" when item="ref" then description="Reference Manual" when item="summary" then description="Summary" when item="tech" then description="Technical Manual" end call lineout index,'The REXX/imc' description 'by Section' call lineout index,'

The REXX/imc' description 'by Section

' call lineout index,'' call lineout index,'*', ''||, 'The whole file (with HTML links)
' do 3 until nextline\="" nextline=linein(infile) /* Fetch the document's title line */ end call lineout docindex,''nextline'' call lineout docindex,'

'nextline'

' call lineout docindex,'

Contents

' if item="summary" then /* summary has no introductory text. */ do 3 until nextline\="" nextline=linein(infile) end else do /* write the introductory text and put it in the index */ call lineout docindex,'' call stream docindex,'c','close' call stream doctext,'c','close' 'cat' doctext '>>' docindex '&& rm' doctext call lineout index,'


' call lineout index,'' ||, 'Go back',
                      'to the Rexx Documentation menu' call stream index,'c','close' 'ls -R' outdir '|wc >' outchk end exit /* Use the 'find' Unix program to determine whether file1 is newer then file2 */ newer: procedure parse arg file1,file2 call '/usr/bin/find' file1,'-newer',file2,'-print' return symbol('result')\=='LIT' /* Note: The Regina-0.07a version of the above reads: newer: procedure parse arg file1,file2 call 'find'(file1,'-newer',file2,'-print') return result\=='' */ /* Output some text so that it looks OK in a HTML document */ HTMLify: procedure parse arg text /* remove initial and trailing blank lines */ do 2 do until first\='' | text=='' parse var text first '0a'x text end if text\='' & first\='' then first=first||'0a'x if first\='' then text=first || text text=reverse(text) end /* translate dangerous characters */ out='' chars='<>&' do forever p=verify(text,chars,'m') if p=0 then leave else if p=1 then do; left=''; parse var text c +1 text; end else parse var text left =(p) c +1 text select when c='&' then out=out || left || '&' when c='<' then out=out || left || '<' when c='>' then out=out || left || '>' end end /* add
 ... 
*/ return '
' || '0a'x || out || text || '0a'x || '
' || '0a'x /* The following function separates the document into sections. It reads the input file until the next section heading, returning the text of the section in "text" and the title of the next section in "nextline". A section heading can be "major" or "minor" according as to whether it is a subsection heading or a main section heading. This information is returned in "type". */ separator: procedure expose infile item text type nextline sep instr math text='' type='' sep='' do until type\='' nextline=linein(infile) if nextline="" & stream(infile)\="READY" then do type="major" /* the file always ends with a major separator */ return end if left(nextline,10)="__________" then do /* A horizontal line is a major separator. Read until the next nonblank line for the section heading. */ type="major" math=0 do 3 until nextline\="" sep=sep || nextline || '0a'x nextline=linein(infile) end leave end if item="ref" then do /* in rexx.ref there are some special separators */ if nextline="Mathematical Functions" then do type="minor" math=1 /* no more minor sections until the next horizontal line */ end else if \math then do /* The syntax of a function call denotes a minor section heading */ parse var nextline fn '(' if datatype(fn,'U') then type="minor" else if nextline='C2X, C2D, B2X, B2D, D2C, D2B, D2X, X2C, X2D' then type="minor" end end else do /* In the other files, a major section starts with a numbered title and a minor section starts with a parenthesised letter, for instance "(a)" or "3(b)". The number or letter is followed by a dot or space. */ if item="info" then line=substr(nextline,3) else line=nextline /* in rexx.info each line is indented by 2 spaces */ parse var line n '. ' 1 m ' ' if datatype(n,'W') & n==strip(n) then do;type="major";leave;end else if datatype(m,'W') & m==strip(m) then do;type="major";leave;end parse var line sp '(' letter ')' dot ' ' if (sp=''|datatype(sp,'w')) & length(sp)<=1 & (dot=='' | dot=='.') &, length(letter)=1 & datatype(letter,'l') then type="minor" end if type="" then text=text || nextline || '0a'x /* build up text */ end /* Finally, some special cases are necessary in rexx.ref. All instructions are minor sections; this is given by instr=1. */ if type="major" & item="ref" then do if right(nextline,1)=":" then nextline=left(nextline,length(nextline)-1) else if nextline="Instructions" then do; instr=1; return; end else if nextline="The REXX I/O Model" then instr=0 if instr then type="minor" end return