home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
gfx
/
edit
/
tsmorph
/
src
/
texinfo2html.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-02-03
|
10KB
|
349 lines
/* Rexx program to convert .texinfo file to .html
*
* Also processes some amigaguide commands
*
* Only works on specific @commands!!
*
* SLOW
*
* $VER: texinfo2HTML.rexx 1.2 (2.2.94)
*
*/
parse arg arg1 arg2 arg3
arg2 = strip(arg2)
arg3 = strip(arg3)
move = 0
if open('infile',arg1,'r') then do
if open('texinfofile',arg3,'w') then do
if open('outfile',arg2,'w') then do
line = myreadln()
do while ~eof('infile')
if substr(line,1,1) = "@" then do
w = upper(word(line,1))
select
when w = "@@REMARK" then
nop
when w = "@@FONT" then
nop
when w = "@CINDEX" then
nop
when w = "@SETTITLE" then
call writeln('outfile',"<TITLE>"mystrip(delword(line,1,1))"</TITLE>")
when w = "@PARAGRAPHINDENT" then
nop
when w = "@NODE" then do
say line
if upper(word(line,2)) ~= "TOP" then do
call close('outfile')
ts = delword(line,1,1)
t = index(ts,",")
if t>0 then
arg2 = mystrip(left(ts,t-1))||".html"
else
arg2 = mystrip(ts)||".html"
if ~open('outfile',arg2,'w') then do
say "Error opening '"arg2"'"
call close()
return
end
end
end
when w = "@TOP" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H1>"ts"</H1>")
call writeln('outfile',"<HR>")
up1 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@CHAPTER" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H1>"ts"</H1>")
call writeln('outfile',"<HR>")
call writeln('outfile',up1)
up2 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@UNNUMBEREDSEC" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H2>"ts"</H2>")
call writeln('outfile',"<HR>")
call writeln('outfile',up2)
up3 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@UNNUMBEREDSUBSEC" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H3>"ts"</H3>")
call writeln('outfile',"<HR>")
call writeln('outfile',up3)
up4 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@UNNUMBEREDSUBSUBSEC" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H4>"ts"</H4>")
call writeln('outfile',"<HR>")
call writeln('outfile',up4)
up5 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@UNNUMBERED" then do
ts = mystrip(delword(line,1,1))
call writeln('outfile',"<TITLE>"ts"</TITLE>")
call writeln('outfile',"<H2>"ts"</H2>")
call writeln('outfile',"<HR>")
call writeln('outfile',up5)
up2 = "<A HREF="arg2"><img src=Images/Up></A><P>"
end
when w = "@ITEMIZE" then
call convertitemize()
when w = "@EXAMPLE" then do
call writeln('outfile',"<PRE>")
line = myreadln()
do while ~eof('infile') & (upper(line) ~= "@END EXAMPLE")
call writeln('outfile',mystrip(line))
line = myreadln()
end
call writeln('outfile',"</PRE>")
end
when w = "@MENU" then do
line = myreadln()
call writeln('outfile',"<MENU>")
do while ~eof('infile') & substr(line,1,1) ~= "*"
call writeln('outfile',"<B>"line"</B>")
line = myreadln()
end
do while ~eof('infile') & upper(line) ~= "@END MENU"
select
when line = "" then
call writeln('outfile',"<P>")
when substr(line,1,1) = "*" then do
if move>0 then do
move = 0
call writeln('outfile',"</UL>")
end
call writech('outfile',"<LI><A HREF=")
call writech('outfile',mystrip(strip(substr(line,index(line,":")+1),," "))||".html>") /* One is NBSP */
call writeln('outfile',mystrip(strip(substr(line,3,index(line,":")-3),," "))||"</A>") /* One is NBSP */
end
when line = "" then
call writeln('outfile',"<P>")
otherwise
if move=0 then do
call writech('outfile',"<UL>")
move = 1
end
call writeln('outfile',myconvert(line))
end
line = myreadln()
end
if move>0 then do
move = 0
call writeln('outfile',"</UL>")
end
call writeln('outfile',"</MENU>")
end
otherwise
call writeln('outfile',myconvert(line))
end
end
else
if line = "" then
call writeln('outfile',"<P>")
else
call writeln('outfile',myconvert(line))
line = myreadln()
end
call close('outfile')
end
else
say "Error opening '"arg2"'"
call close('texinfofile')
end
else
say "Error opening '"arg3"'"
call close('infile')
end
else do
say "Error opening '"arg1"'"
end
return
mystrip: procedure
parse arg line1
if index(line1,"@") > 0 then do
line2 = ""
do i=1 to length(line1) by 1
if substr(line1,i,1) = "@" then
select
when substr(line1,i,5) = "@ref{" then do
line3 = substr(line1,i+5)
line3 = substr(line3,1,index(line3,"}")-1)
line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||" "
i = index(line1,"}",i)
end
when substr(line1,i,6) = "@xref{" then do
line3 = substr(line1,i+6)
line3 = substr(line3,1,index(line3,"}")-1)
line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||" "
i = index(line1,"}",i)
end
when substr(line1,i,5) = '@@@{"' then do
line3 = substr(line1,i+5)
line3 = substr(line3,1,index(line3,"/Main")-1)
line2 = line2 || mystrip(substr(line3,1,index(line3,"ALINK")-3))||" "
i = index(line1,"}",i)
end
when substr(line1,i,7) = "@@@{u@}" then
i = i+6
when substr(line1,i,8) = "@@@{uu@}" then
i = i+7
when substr(line1,i,2) = "@@" then do
line2 = line2 || "@"
i = i + 1
end
otherwise
do j=i to length(line1) by 1 while substr(line1,j,1) ~= "{"
nop
end
i = j
end
else
if substr(line1,i,1) = "}" then
nop
else
line2 = line2 || substr(line1,i,1)
end
return line2
end
else
return line1
myconvert: procedure
parse arg line1
if index(line1,"@") > 0 then do
line2 = ""
do i=1 to length(line1) by 1
if substr(line1,i,1) = "@" then
select
when substr(line1,i,5) = "@ref{" then do
line3 = substr(line1,i+5)
line3 = substr(line3,1,index(line3,"}")-1)
line2 = line2 || "<A HREF="
line2 = line2 || mystrip(substr(line3,1,index(line3,",")-1)) || ".html>"
line2 = line2 || mystrip(substr(line3,index(line3,",")+1)) || "</A>"
i = index(line1,"}",i)
end
when substr(line1,i,6) = "@xref{" then do
line3 = substr(line1,i+6)
line3 = substr(line3,1,index(line3,"}")-1)
line2 = line2 || "See <A HREF="
line2 = line2 || mystrip(substr(line3,1,index(line3,",")-1))||".html>"
line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||"</A>"
i = index(line1,"}",i)
end
when substr(line1,i,5) = '@@@{"' then do
line3 = substr(line1,i+5)
line3 = substr(line3,1,index(line3,"/Main")-1)
line2 = line2 || "<A HREF=/"
line2 = line2 || mystrip(substr(line3,index(line3,"ALINK")+7))||">"
line2 = line2 || mystrip(substr(line3,1,index(line3,"ALINK")-3))||"</A>"
i = index(line1,"}",i)
end
when substr(line1,i,7) = "@@@{u@}" then do
i = i+6
line2 = line2 || "<B>"
end
when substr(line1,i,8) = "@@@{uu@}" then do
i = i+7
line2 = line2 || "</B>"
end
when substr(line1,i,2) = "@@" then do
line2 = line2 || "@"
i = i + 1
end
when upper(substr(line1,i,6)) = "@CODE{" then do
line2 = line2 || "<B>"
do j=i+6 to length(line1) by 1 while substr(line1,j,1) ~= "}"
line2 = line2 || substr(line1,j,1)
end
line2 = line2 || "</B>"
i = j
end
when upper(su