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 / ipsplit.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  86 lines

  1. ############################################################################
  2. #
  3. #    File:     ipsplit.icn
  4. #
  5. #    Subject:  Program to split Icon program into files
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This progam reads an Icon program and writes each procedure to
  18. #  a separate file. The output file names consist of the procedure
  19. #  name with .icn appended.  If the -g option is specified, any glo-
  20. #  bal, link, and record declarations are written to that file. Oth-
  21. #  erwise they are written in the file for the procedure that
  22. #  immediately follows them.
  23. #  
  24. #     Comments and white space between declarations are attached to
  25. #  the next following declaration.
  26. #  
  27. #  Notes:
  28. #
  29. #     The program only recognizes declarations that start at the
  30. #  beginning of lines.  Comments and interline white space between
  31. #  declarations may not come out as intended.
  32. #  
  33. #     If the -g option is not specified, any global, link, or record
  34. #  declarations that follow the last procedure are discarded.
  35. #  
  36. ############################################################################
  37. #
  38. #  Links: options
  39. #
  40. ############################################################################
  41.  
  42. link options
  43.  
  44. procedure main(args)
  45.    local line, x, i, proctable, proclist, comments, gfile, gname, ofile
  46.    local opts
  47.  
  48.    comments := []
  49.  
  50.    opts := options(args,"g:")
  51.    if gname := \opts["g"] then {
  52.       gfile := open(gname,"w") | stop("*** cannot open ",gname)
  53.       }
  54.  
  55.    proctable := table()
  56.    while line := read() do {
  57.       if line ? {
  58.          ="procedure" &            #  procedure declaration
  59.          tab(many(' ')) &
  60.          proctable[tab(upto('('))] := x := []
  61.          } then {
  62.             while put(x,get(comments))    #  save it
  63.             put(x,line)
  64.             i := 1
  65.             while line := read() do {
  66.                put(x,line)
  67.                if line == "end" then break
  68.                }
  69.             }
  70.                     #  other declarations
  71.          else if \gfile & line ? =("global" | "record" | "link")
  72.          then {
  73.             while write(gfile,get(comments))
  74.             write(gfile,line)
  75.             }
  76.          else put(comments,line)
  77.          }
  78.    while write(\gfile,get(comments))
  79.    proclist := sort(proctable,3)    #  sort procedures
  80.    while x := get(proclist) do {    #  output procedures
  81.       ofile := open(x || ".icn","w") | stop("cannot write ",x,".icn")
  82.       every write(ofile,!get(proclist))
  83.       close(ofile)
  84.       }
  85. end
  86.