home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / exoten / icon / ilnkxref.icn < prev    next >
Encoding:
Text File  |  1990-03-08  |  2.1 KB  |  85 lines

  1. ############################################################################
  2. #
  3. #    Name:    ilnkxref.icn
  4. #
  5. #    Title:    Icon "link" Cross Reference Utility
  6. #
  7. #    Author:    Robert J. Alexander
  8. #
  9. #    Date:    December 5, 1989
  10. #
  11. ############################################################################
  12. #
  13. #  Utility to create cross reference of library files used in Icon
  14. #  programs (i.e., those files named in "link" declarations).
  15. #
  16. #    ilnkxref <icon source file>...
  17. #
  18. ############################################################################
  19. #
  20. #  Links: wrap
  21. #
  22. ############################################################################
  23.  
  24. link wrap
  25.  
  26. procedure main(arg)
  27.    local p, spaces, sep, proctable, maxlib, maxfile, fn, f, i, root
  28.    local comma, line, libname, x, head, fill
  29.    #
  30.    #  Initialize
  31.    #
  32.    if *arg = 0 then {
  33.       p := open("ls *.icn","rp")
  34.       while put(arg,read(p))
  35.       close(p)
  36.       }
  37.    spaces := ' \t'
  38.    sep := ' \t,'
  39.    proctable := table()
  40.    maxlib := maxfile := 0
  41.    #
  42.    # Gather information from files.
  43.    #
  44.    every fn := !arg do {
  45.       write(&errout,"File: ",fn)
  46.       f := open(fn) | stop("Can't open ",fn)
  47.       i := 0
  48.       every i := find("/",fn)
  49.       root := fn[1:find(".",fn,i + 1) | 0]
  50.       comma := &null
  51.       while line := read(f) do {
  52.      line ? {
  53.         tab(many(spaces))
  54.         if \comma | ="link " then {
  55.            write(&errout,"    ",line)
  56.            comma := &null
  57.            tab(many(spaces))
  58.            until pos(0) | match("#") do {
  59.           libname := tab(upto(sep) | 0)
  60.           put(\proctable[libname],root) | (proctable[libname] := [root])
  61.           maxlib <:= *libname
  62.           maxfile <:= *root
  63.           tab(many(spaces))
  64.           comma := &null
  65.           if comma := ="," then tab(many(spaces))
  66.           }
  67.            }
  68.         }
  69.      }
  70.       close(f)
  71.       }
  72.    #
  73.    #  Print the cross reference table.
  74.    #
  75.    write()
  76.    every x := !sort(proctable) do {
  77.       head := left(x[1],maxlib + 3)
  78.       fill := repl(" ",*head)
  79.       every x := !sort(x[2]) do {
  80.      write(head,wrap(left(x,maxfile + 2),78)) & head := fill
  81.      }
  82.       write(head,wrap())
  83.       }
  84. end
  85.