Updating listings to an HTML page

Contributed by: Wayne Swanson

Источник: PillarSoft

NOTE: There is some extraneous code included in this snippet to allow some lines that contain html to display properly. There are comments included to point out what lines they are.

For the most part, what we have done is to split up and concatenated some the html code. I'm sure you will recognize the extraneous bits and should be able to remove it. In the following example the ^ sign underlines the added code that can be deleted for use in a standard .cmd file.

snippetlink.index='<'||'LI><'||'A HREF="'||'snippets/'||Filespec('N',list.index)||'">'||Gettitle()||'<'||'/A>'
                    ^^^^    ^^^^                                                                      ^^^^

You will find three lines approximately like this and in the GetTitle subroutine you will find two more with this type of change.


While getting started with this site I got a bunch of new snippets from Doug Rickman. I didn't want to do all the new the listings by hand so I wrote a little script that would get the information from the html snippets pages and put it together with the static parts of the main Rexx.html page to build the newly updated version of Rexx.html.

Now when a new submission comes in I can drop it into the directory it belongs in and run this script to update the main webpage for this site. It was a 20 minute job that will save many hours of work. That is one of the real beauties of Rexx. I thought I might as well post it as it might be useful to someone. :-)

To start with I put the, more or less, "static parts" of the html page in separate files so I could make any global changes easily. Then the script gets the file listings in the snippet directories, extracts the TITLE information from each of them and rewrites the main page with the new information.

Easy? You bet... Rexx comes to the rescue again.


/**********************************************************************/
/* Get listings of titles and html page names and write               */
/* a new Rexx.html file with the updated information                  */
/**********************************************************************/
If Rxfuncquery('SysDropFuncs')
Then Do
  Call Rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  Call SysLoadFuncs
End

/**********************************************************************/
/* Setup                                                              */
/**********************************************************************/
crlf='0d0a'x
curdir=Directory()
rc = SysFileDelete('rexx.bak')
'@copy rexx.html rexx.bak'
rc = SysFileDelete('rexx.html')

/**********************************************************************/
/* HTML code is concatanated in the next three loops so it will       */
/* appear properly on this webpage. You will want to remove the       */
/* concatanation from these lines to simplify it                      */
/**********************************************************************/
/**********************************************************************/
/* Get the snippet directory information build the                    */
/* html line for it and store it in SnippetLink.                      */
/**********************************************************************/
Call SysFileTree curdir||'\snippets\*.*','List','FO'
Do index=1 To list.0
  snippetlink.index='<'||'LI><'||'A HREF="'||'snippets/'||Filespec('N',list.index)||'">'||Gettitle()||'<'||'/A>'
End
snippetlink.0=list.0

/**********************************************************************/
/* Get the VisPro/Rexx directory information build the                */
/* html line for it and store it in VPLink.                           */
/**********************************************************************/
Call SysFileTree curdir||'\VPsnippets\*.*','List','FO'
Do index=1 To list.0
  vplink.index='<'||'LI><'||'A HREF="'||'vpsnippets/'||Filespec('N',list.index)||'">'||Gettitle()||'<'||'/A>'
End
vplink.0=list.0

/**********************************************************************/
/* Get the help directory information build the                       */
/* html line for it and store it in HelpLink.                         */
/**********************************************************************/
Call SysFileTree curdir||'\help\*.*','List','FO'
Do index=1 To list.0
  helplink.index='<'||'LI><'||'A HREF="'||'help/'||Filespec('N',list.index)||'">'||Gettitle()||'<'||'/A>'
End
helplink.0=list.0

/**********************************************************************/
/* Write the new file                                                 */
/**********************************************************************/
Call Writefile

Exit
/**********************************************************************/
/************************ END OF PROGRAM ******************************/
/**********************************************************************/

/**********************************************************************/
/* Get title information out of the html file the stem                */
/* variable "List.index" always holds the new filename                */
/**********************************************************************/
Gettitle:

value = Charin(list.index,1,400)
Call Stream list.index,'C','CLOSE'
/* TITLE is concatanated so it would appear on an html page */
/* You will want to remove the concatanation from it        */
titlestart = Pos('<'||'TITLE>',value,1)
titleend = Pos('<'||'/TITLE>',value,1)
If titlestart>0 & titleend>0 Then Do
  title=Substr(value, titlestart+7, (titleend-titlestart)-7)
End
Return title

/**********************************************************************/
/* Write out "rexx.html" by reading the static html files and         */
/* writing them to the final file along with the new information      */
/* I cheat by using "Rexx1,Rexx2,Rexx3 and Rexx4" as the names of the */
/* actual files as well as the variables that carry their contents    */
/* That is probably not a good habit for you to get into :-)          */
/**********************************************************************/
Writefile:

rexx1=Getinfo(rexx1)
rexx1 = insert(date('L'),rexx1,289) /* Set the "Last update:" date    */
Call Charout 'rexx.html',rexx1
Do index=1 To snippetlink.0
  Call Charout 'rexx.html',snippetlink.index||crlf
End

rexx2=Getinfo(rexx2)
Call Charout 'rexx.html',rexx2
Do index=1 To vplink.0
  Call Charout 'rexx.html',vplink.index||crlf
End

rexx3=Getinfo(rexx3)
Call Charout 'rexx.html',rexx3
Do index=1 To helplink.0
  Call Charout 'rexx.html',helplink.index||crlf
End

rexx4=Getinfo(rexx4)
Call Charout 'rexx.html',rexx4
Call Stream 'rexx.html','C','CLOSE'

Return

/**********************************************************************/
/* Reads a file into a variable                                       */
/**********************************************************************/
Getinfo:
Parse Arg filename
value = Charin(filename,1,Chars(filename))
rc=Stream(filename,'c','close')
Return value