#!/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,'- Introductory text'
call lineout outdir'/intro',nextline
call separator
call charout outdir'/intro',text
call stream outdir'/intro','c','close'
call lineout index,'',
'Introductory text
'
call lineout doctext,''
call lineout doctext,'Introductory text
'
call charout doctext,HTMLify(text)
end
/* Each section is now written to a file. */
currenttype="major"
sectext=''
sec='A'
do until stream(infile)\="READY"
/* sections are named A-Z, then AA-AZ, BA-BZ, etc. Make sure the
section number is one of these. */
if sec="[" then sec="AA"
else if right(sec,1)="[" then sec=d2c(c2d(left(sec,1))+1)||'A'
/* now read in the section */
title=nextline
call separator
if currenttype="major" & type="minor" then do
/* The section just read in is the introductory text to a
collection of subsections. Write a "directory" entry in the
main index file and a bookmark in the document text, then
descend one level to start writing subsections */
call lineout index,'',
''||,
strip(title)||'
'
call lineout docindex,' - 'strip(title)''
call lineout doctext,''
maindir=outdir
outdir=outdir'/'sec
address
"mkdir" outdir
address
mainindex=index
index=outdir'/index.html'
/* For the "the whole section" option there will be the index
(secindex) and the text (sectext). The index will be
appended to the main document index, and similarly for the
text. Also, the section text will be appended to the index
to make the file for "the whole section". */
secindex=outdir'/whole.html'
sectext='/tmp/mkdocs@'random()
mainsec=sec
sec='A'
call lineout index,''strip(title)' - Contents'
call lineout index,'
'strip(title)'
'
call lineout index,''
call lineout index,'',
''||,
'The whole section (with HTML links)
'
call lineout secindex,''strip(title)''
call lineout secindex,''strip(title)'
'
call lineout secindex,'Contents
'
call lineout secindex,''
if translate(text,' ','0a'x)\="" then do
/* write the introductory text and add it to the index, if there
is any. */
call lineout outdir"/intro",title
call charout outdir"/intro",text
call stream outdir"/intro","c","close"
call lineout index,'',
'Introductory text
'
call lineout secindex,'- ' ||,
'Introductory text'
call lineout sectext,''
call lineout sectext,'
Introductory text
'
call charout sectext,HTMLify(text)
end
currenttype=type
iterate
end
/* the section or subsection is added to the index. */
call lineout index,'',
''||strip(title)||'
'
htext=HTMLify(text)
if sectext\='' then do
/* the subsection is added to the subsection text */
call lineout secindex,' - '||,
strip(title)||''
call lineout sectext,''
call lineout sectext,'
'strip(title)'
'
call charout sectext,htext
end
else do
/* the section is added to the section text */
call lineout docindex,'- 'strip(title)''
call lineout doctext,''
call lineout doctext,'
'strip(title)'
'
call charout doctext,htext
end
/* the section is written to a file */
call lineout outdir'/'sec,title
call charout outdir'/'sec,text
call stream outdir'/'sec,'c','close'
sec=d2c(c2d(sec)+1) /* advance the section name */
if currenttype="minor" & type="major" then do
/* The subsection just written out is the last subsection of a
section. The section index is terminated, then the section
is added to the main document and also written out as mentioned
above. */
call lineout secindex,'
'
call stream sectext,'c','close'
call stream secindex,'c','close'
call stream docindex,'c','close'
'tail +4' secindex '>>' docindex
'cat' sectext '>>' secindex '&& rm' sectext
call stream doctext,'c','close'
'tail +2' secindex '>>' doctext
sectext=''
call lineout index,''
call lineout index,'
'
call lineout index,''
call stream index,'c','close'
index=mainindex
outdir=maindir
sec=d2c(c2d(mainsec)+1)/* recover and advance the main section name */
currenttype=type
end
end
/* At the end of the document, the indexes are terminated and the document
text is appended to the contents. */
call lineout docindex,'
'
call stream docindex,'c','close'
call stream doctext,'c','close'
'cat' doctext '>>' docindex '&& rm' doctext
call lineout index,'
'
call lineout index,'' ||,
''
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