home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / iplweb.icn < prev    next >
Text File  |  2001-05-02  |  5KB  |  186 lines

  1. ###############################################################################
  2. #
  3. #    File:     iplweb.icn
  4. #
  5. #    Subject:  Program to generate web pages from IPL header comments
  6. #
  7. #    Author:   Justin Kolb
  8. #
  9. #    Date:     May 2, 2001
  10. #
  11. ###############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ###############################################################################
  16. #
  17. #  iplweb [-ipl source] [dest]
  18. #
  19. #  Uses an environment variable IPL which is a path to the Icon Program Library
  20. #  as a default if -ipl is not specified, dest is the current directory if not
  21. #  specified.
  22. #
  23. #  Generates HTML directory in dest and makes an index to gprogs, gprocs,
  24. #  procs, and progs directories under HTML.  In each of these directories
  25. #  is a .html file for each of the .icn files in the referenced directory.
  26. #  A index to all of these files is also generated.  Each of the .html files
  27. #  contains the IPL standard comment header info inside.
  28. #
  29. ###############################################################################
  30.  
  31. link options
  32.  
  33. procedure main(arglist)
  34.    local opts, source, dest
  35.  
  36.    if opts := options(arglist, "-ipl:", errorproc) then {
  37.       source := opts["ipl"]
  38.       /source := getenv("IPL")
  39.       if /source then errorproc()
  40.       }
  41.    else errorproc()
  42.  
  43.    if *arglist > 0 then {
  44.       dest := arglist[1] || "/HTML"
  45.       }
  46.    else {
  47.       dest := "HTML"
  48.       }
  49.  
  50.    Build_HTML_Files(source, dest)
  51. end
  52.  
  53. procedure errorproc()
  54.    stop("Set IPL environment variable or use\n",
  55.     "iplweb [-ipl source] [destination]")
  56. end
  57.  
  58. procedure Build_HTML_Files(source_dir, dest)
  59.    local directory, dir_index_file, dir, dirlist, file_index_file,
  60.        prev_dir, full_path, file, file_info_file, source_file
  61.  
  62.    directory := ["/gprogs", "/gprocs", "/progs", "/procs"]
  63.  
  64.    system("mkdir " || dest)
  65.  
  66.    dir_index_file := open(dest || "/dirindex.html", "w")
  67.  
  68.    Init_Dir_Index(dir_index_file)
  69.  
  70.    every dir := !directory do {
  71.       dirlist := open("ls " || source_dir || dir || "/*.icn", "p")
  72.  
  73.       file_index_file := &null
  74.       prev_dir := ""
  75.  
  76.       while full_path := read(dirlist) do {
  77.      write(full_path)
  78.  
  79.      file := strip_file(full_path)
  80.  
  81.      if not (dir == prev_dir) then {
  82.             #Prev Dir
  83.         if not /file_index_file then {
  84.            Close_File_Index(file_index_file)
  85.  
  86.            close(file_index_file)
  87.            }
  88.  
  89.         # Next Dir
  90.         Index_Dir(dir_index_file, dir)
  91.  
  92.         system("mkdir " || dest || dir)
  93.  
  94.         file_index_file := open(dest || dir || "/fileindex.html", "w")
  95.  
  96.         Init_File_Index(file_index_file, dir)
  97.         }
  98.  
  99.      Index_File(file_index_file, file)
  100.  
  101.      file_info_file := open(dest || dir || file || ".html", "w")
  102.  
  103.      source_file := open(full_path)
  104.  
  105.      ProcessFileInfo(file_info_file, source_file)
  106.  
  107.      close(source_file)
  108.  
  109.      close(file_info_file)
  110.  
  111.      prev_dir := dir
  112.          }
  113.  
  114.       close(file_index_file)
  115.       }
  116.    Close_Dir_Index(dir_index_file)
  117.    close(dir_index_file)
  118. end
  119.  
  120. procedure Init_Dir_Index(file)
  121.    write(file, "<TITLE>IPL: The Icon Program Library Comment Documentaion</TITLE>")
  122.    write(file, "<H1>The Icon Program Library</H1><P>")
  123.    write(file, "<H2>Source Directorys</H2><P>")
  124.    write(file, "<UL>")
  125. end
  126.  
  127. procedure Index_Dir(file, dir)
  128.    write(file, "<LI><A HREF=\"" || dir[2:0] || "/fileindex.html\">" || dir[2:0] || "</A></LI>")
  129. end
  130.  
  131. procedure Close_Dir_Index(file)
  132.    write(file, "</UL>")
  133. end
  134.  
  135. procedure Init_File_Index(file, dir)
  136.    write(file, "<TITLE>IPL: The Icon Program Library Comment Documentation</TITLE>")
  137.    write(file, "<H1>The Icon Program Library</H1><P>")
  138.    write(file, "<H2>The " || dir[2:0] || " directory listing</H2><P>")
  139.    write(file, "<UL>")
  140. end
  141.  
  142. procedure Index_File(index, file)
  143.    write(index, "<LI><A HREF=\"" || file[2:0] || ".html\">" || file[2:0] || ".icn</A></LI>")
  144. end
  145.  
  146. procedure Close_File_Index(file)
  147.    write(file, "</UL>")
  148. end
  149.  
  150. procedure ProcessFileInfo(file, source)
  151.    local line, keywd, text
  152.  
  153.    write(file, "<TITLE>IPL: The Icon Program Library Comment Domumentaion</TITLE>")
  154.  
  155.    write(file, "<H1>The Icon Program Libary</H1><P>")
  156.  
  157.    while line := read(source) do line ? {
  158.       if not pos(0) then {
  159.      if tab(many('# \t')) &
  160.          (keywd := =("File:" | "Subject:" | "Author:" | "Date:" | "Authors:")\1) &
  161.          tab(many(' \t')) &
  162.          text := tab(0)
  163.      then {
  164.         case keywd of {
  165.            "File:"    : write(file, "<H2>" || text || "</H2><P>")
  166.            "Subject:" : write(file, "<H3>" || text || "</H3><P>")
  167.            "Author:"  : write(file, "<H3>" || text || "</H3><P>")
  168.            "Authors:" : write(file, "<H3>" || text || "</H3><P>") 
  169.            "Date:"    : write(file, "<H3>" || text || "</H3><P>")
  170.            }
  171.         }
  172.      else if tab(many('#'))\1 & tab(many(' \t')) & text := tab(0) then
  173.          write(file, "<PRE>" || text || "</PRE>")
  174.      }
  175.       }
  176. end
  177.  
  178. procedure strip_file(path)
  179.    local local_dir
  180.  
  181.    path ? {
  182.       every local_dir := tab(upto('/'))
  183.       return path[*local_dir + 1 : -4]
  184.       }
  185. end
  186.