home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / idx2html.zip / idx2html.cmd next >
OS/2 REXX Batch file  |  1994-12-11  |  4KB  |  106 lines

  1. /* idx2html.cmd - Convert Hobbes 00index.txt to WWW HTML file */
  2. /* Version 1.0, 11 December 1994                              */
  3. /* Written by Kevin.Lowey@Usask.CA                            */
  4.  
  5. parse arg inputfile outputfile ftp_site start_dir
  6.  
  7. if outputfile="" then do
  8.   say "idx2html: Convert Hobbes FTP 00index.txt files to html"
  9.   say "          Version 1.0, 11 December 1994"
  10.   say " "
  11.   say "USAGE: idx2html Index_file HTML_file [ftpsite] [starting_dir]"
  12.   say "     Index_File: Original 00index.txt file in the format used at Hobbes"
  13.   say "     HTML_file:  Filename to put the resulting HTML document into"
  14.   say "     ftpsite:    Optional name of FTP site being indexed."
  15.   say '                 Defaults to "ftp-os2.nmsu.edu"'
  16.   say "     starting_dir: Starting directory on that site."
  17.   say '                   Defaults to "OS2/"' 
  18.   say '                   Do not add the leading  "/". Trailing "/" optional'
  19.   say " "
  20.   say "DESCRIPTION:"
  21.   say "This program converts a 00index.txt file from an FTP site to a WWW"
  22.   say "html document. This allows people with web browsers to view the"
  23.   say "files and their descriptions listed in the 00index file, and download"
  24.   say "desired files immediately from the list".
  25.   say " "
  26.   say "INPUT FILE FORMAT"
  27.   say 'The input file format must be that used by "ftp-os2.nmsu.edu".'
  28.   say '- BLANK LINES are passed through unchanged'
  29.   Say '- If the first word on a nonblank line ends with ":", it is taken'
  30.   Say '  as a subdirectory name under the starting directory. All files'
  31.   Say '  listed under this section are relative to this new file name.'
  32.   Say '- The first word on all other lines are taken as file or directory'
  33.   Say '  names, with the rest of the line taken as a comment' 
  34.  
  35.   exit (1)
  36. end
  37.  
  38. /* Constants */
  39. if ftp_site = "" then do
  40.   ftp_site = "ftp-os2.nmsu.edu"
  41. end
  42.  
  43. if start_dir = "" then do
  44.   Start_dir = "os2/"
  45. end
  46.  
  47. pagetitle = ftp_site||" Directory: "||start_dir
  48.  
  49. html_start = '<a href="ftp://'||ftp_site||"/"||Start_dir
  50. if right(html_start,1) <> "/" then do
  51.   html_start = html_start||"/"
  52. end
  53.  
  54.  
  55. /* Variables */
  56. current_dir = ""
  57.  
  58. /* startup */
  59. call rxfuncadd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  60. call sysloadfuncs
  61. rc = sysfiledelete(outputfile)
  62.  
  63. /* Writing the header */
  64. say "Writing Header"
  65. call lineout outputfile, "<html>"
  66. call lineout outputfile, "<head>"
  67. call lineout outputfile, "<title>"
  68. call lineout outputfile, pagetitle
  69. call lineout outputfile, "</title>"
  70. call lineout outputfile, "</head>"
  71. call lineout outputfile, "<body>"
  72. call lineout outputfile, "<h1>"||pagetitle||"</h1>"
  73. call lineout outputfile, "<pre>"
  74.  
  75. /* Process */
  76. say "Processing ..."
  77. do while lines(inputfile) > 0
  78.   dataline = linein(inputfile)
  79.  
  80.   if length(strip(dataline)) = 0 then do
  81.     call lineout outputfile, dataline
  82.   end
  83.   else do
  84.     parse var dataline firstword endline
  85.  
  86.     if pos(":",firstword) = 0 then do  
  87.       outline = html_start||current_dir||firstword||'">'||firstword||'</a> '||endline
  88.       call lineout outputfile, outline
  89.     end /* then do */
  90.     else do
  91.       call lineout outputfile,dataline
  92.       current_dir = left(firstword,pos(":",firstword)-1)||'/'
  93.       Say "Processing Directory "||current_dir
  94.     end /* else do */
  95.   end /* else do */
  96. end
  97.  
  98. /* Writing the end */
  99. say "Writing Closing"
  100. call lineout outputfile,"</pre>"
  101. call lineout outputfile,"</body>"
  102. call lineout outputfile,"</html>"
  103.  
  104. say "Done"
  105. exit(0)
  106.