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

  1. ############################################################################
  2. #
  3. #    File:     ilump.icn
  4. #
  5. #    Subject:  Program to lump linked Icon source files
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     November 14, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #  usage:  ilump [file...]
  18. #
  19. #     ilump copies one or more Icon source files, incorporating recursively
  20. #  the source code for files named by "link" directives.  This produces a
  21. #  standalone source program in one file, which is useful with certain
  22. #  profiling and visualization tools.
  23. #
  24. #     Searching for link'd source files is similar to the action of Iconc
  25. #  under UNIX.  If a link'd file is not found in the current directory,
  26. #  directories specified by the LPATH environment variable are tried.
  27. #
  28. ############################################################################
  29.  
  30.  
  31. global path, todo
  32.  
  33.  
  34. procedure main(args)
  35.    local fname
  36.  
  37.    path := [""]
  38.    getenv("LPATH") ? repeat {
  39.       tab(many(' '))
  40.       if pos(0) then
  41.          break
  42.       put(path, tab(upto(' ')|0) || "/")
  43.    }
  44.    todo := args
  45.    if *todo = 0 then
  46.       dofile(&input)
  47.    while fname := get(todo) do
  48.       dofile(newfile(fname))
  49. end
  50.  
  51.  
  52. #  newfile(fname) -- open and return a file, if it wasn't seen earlier
  53.  
  54. procedure newfile(fname)
  55.    local f, fullname
  56.    static done
  57.    initial done := set()
  58.  
  59.    if member(done, fname) then
  60.       fail
  61.    insert(done, fname)
  62.    if f := open(fullname := !path || fname) then {
  63.       write("\n\n\n#", right("  " || fullname, 78, "="), "\n\n\n")
  64.       return f
  65.       }
  66.    else {
  67.       write(&errout, "can't open ", fname)
  68.       write("\n\n\n#", right("  can't open " || fname, 78, "="), "\n\n\n")
  69.       fail
  70.       }
  71. end
  72.  
  73.  
  74. #  dofile(f) -- copy one file, stacking file names seen on link directives
  75.  
  76. procedure dofile(f)
  77.    local line, base
  78.    static idset
  79.    initial idset := &letters ++ &digits ++ '_'
  80.  
  81.    while line := read(f) do {
  82.       line ? {
  83.          tab(many(' \t'))
  84.          if ="link" & not any(idset) then {
  85.             write("#====== ", line)
  86.             repeat {
  87.                tab(many(' \t,'))
  88.                if pos(0) | ="#" then
  89.                   break
  90.                if ="\"" then
  91.                   base := tab(upto('"')|0)
  92.                else
  93.                   base := tab(many(idset)) | break
  94.                put(todo, base || ".icn")
  95.                }
  96.             }
  97.          else {
  98.             write(line)
  99.             }
  100.          }
  101.       }
  102.     
  103.    close(f)
  104. end
  105.