1. Auto HTML creator
andyK wrote/ mikeD wrote:
>1> Automatic HTML page _creator_
>[... stuff about template, list of (sub)topics, entire HTML and dirs]
>[... sample topics.txt, linktemplate.txt]
> Hmm, it's not very clear. (e.g. No template.txt, no sample HTML,
> no obvious way to relate the topics with filenames, etc...)
okay, after a few hours, here is a sorta almost real close to
working code, and the data files...
several restrictions are still to be got around:
1:topic name length has to be exactly 8 characters
(had to do that to get it working first)
2:don't know if longfile names will work yet
3:replacing a squished CR back
(page generated has no CR in it...funny :> )
------------------ creator.ex------------
--program inputs from a data file a list of topics for
--a web site, then uses a template to generate html pages
--that have the proper name and title and such.
--saves the newly created html page as <topicname>.html
constant SCREEN = 1
constant TRUE = 1
sequence links, topics, template, newfile, newfilename
links = {} topics = {} template = {}
newfile = {} newfilename = {}
function ReadFile(sequence filename)
--reads a file, returns a sequence
sequence data
integer fileNum
object line
data = {}
fileNum = open(filename, "r")
if fileNum = -1 then
printf(SCREEN, "readfile cannot open %s\n", filename)
abort(1)
else
while TRUE do
line = gets(fileNum)
if atom(line) then
-- end of file
close(fileNum)
return data
end if
data = data & {line}
end while
end if
end function
function SearchReplace( sequence lookinhere,
sequence lookfor, sequence replace)
--this function needs a lotta work still
--8 character only restriction for starters
--replaces the word <lookfor> within <lookinhere>
--with <replace>
integer location
for index = 1 to length(lookinhere) do
location = match(lookfor, lookinhere[index])
if location != 0 then
for subindex = location to location + 7 do
lookinhere[index][subindex] = replace[subindex-location+1]
end for
end if
end for
return lookinhere
end function
procedure SaveFile(sequence filename, sequence data)
--saves the newly created page replete with
--titles and such based on template to filename
--which is generated based on <topic>.htm
integer fileNum
fileNum = open(filename, "w")
if fileNum = -1 then
puts(SCREEN,"error in savefile, cant open\n")
abort(1)
end if
for index = 1 to length(data) do
puts(fileNum,data[index])
end for
close(fileNum)
end procedure
--links = ReadFile("links.txt")
--getting links to work is another day's project
topics = ReadFile("topics.txt")
template = ReadFile("template.txt")
for index = 1 to length(topics) - 1 do --squish EOF
newfile = SearchReplace(template,"template",topics[index])
newfilename = {}
newfilename = newfilename & topics[index]
newfilename = newfilename[1..length(newfilename)-1] --squish CR
newfilename = newfilename & ".htm"
SaveFile(newfilename, newfile)
end for
-----------end creator.ex------------
-----------topics.txt---------------
computer
plumbing
electric
children
hardware
internet
----------------end-----------------
--this really should be template.html shrug
-----------template.txt------------
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<META NAME="Author" CONTENT="Hawke'">
<META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (Win95; U)
[Netscape]">
<TITLE>Manufacturer's Manifest--template</TITLE>
</HEAD>
<BODY TEXT="#C0C0C0" BGCOLOR="#FFFFFF" LINK="#9AD3FE"
VLINK="#999999" ALINK="#006600" BACKGROUND="darkparchment.jpg">
<DL><DL>
<CENTER><B><I><FONT FACE="Times New Roman,Times"><FONT SIZE=+4>
The Manufacturer's Manifest</FONT></FONT></I></B></CENTER>
<IMG SRC="Colorful Stone Stripe.gif" HEIGHT=5 WIDTH=100%
ALIGN=ABSCENTER>
<CENTER><B><U><FONT FACE="Courier New,Courier"><FONT COLOR="#993366">
<FONT SIZE=+3>Template</FONT></FONT></FONT></U></B></CENTER>
<CENTER><FONT FACE="Courier New,Courier"><FONT
COLOR="#000000"> </FONT></FONT></CENTER>
<CENTER><TABLE BORDER=10 CELLSPACING=3 CELLPADDING=2 COLS=4 WIDTH="85%"
HEIGHT="80%">
<TR ALIGN=LEFT VALIGN=BOTTOM>
<TD><IMG SRC="littleblueball.gif" HEIGHT=12 WIDTH=12><B>
<A HREF="link.html">Link</A></B></TD>
<TD> </TD><TD> </TD><TD> </TD>
</TR>
<TR ALIGN=LEFT VALIGN=BOTTOM>
</TR>
<TR ALIGN=LEFT VALIGN=BOTTOM>
</TR>
<TR ALIGN=LEFT VALIGN=BOTTOM>
</TR>
</TABLE></CENTER>
<IMG SRC="Colorful Stone Stripe.gif" HEIGHT=5 WIDTH=100%
ALIGN=ABSCENTER>
<BR>
<CENTER><FONT SIZE=+1><B>This site is courtesy of </B><I>
<FONT FACE="Arial,Helvetica"><FONT COLOR="#999999">
<A
and our <FONT COLOR="#999999">
<A HREF="sponsors.html">sponsors</A></FONT>.</B></FONT></CENTER>
<IMG SRC="Colorful Stone Stripe.gif" HEIGHT=5 WIDTH=100%
ALIGN=ABSCENTER>
------------------------------end------------------
okay okay okay sorry
long post...shoulda zipped....
take care--Hawke'