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 / ilnkxref.icn < prev    next >
Text File  |  2000-08-03  |  3KB  |  109 lines

  1. ############################################################################
  2. #
  3. #    File:     ilnkxref.icn
  4. #
  5. #    Subject:  Program to produce Icon link cross reference
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     August 3, 2000
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Utility to create cross reference of library files used in Icon
  18. #  programs (i.e., those files named in "link" declarations).
  19. #
  20. #    ilnkxref [-options] <icon source file>...
  21. #
  22. #    options:
  23. #
  24. #        -p    sort by "popularity"
  25. #        -v    report progress information
  26. #
  27. ############################################################################
  28. #
  29. #  Requires: UNIX
  30. #
  31. ############################################################################
  32. #
  33. #  Links: wrap, options, sort
  34. #
  35. ############################################################################
  36.  
  37. link wrap, options, sort
  38.  
  39. procedure main(arg)
  40. local comma, f, fill, fn, head, heads, i, libname, line, linesize, maxfile,
  41.    maxlib, opt, p, popularity, proctable, root, sep, spaces, verbose, x
  42.    #
  43.    #  Initialize
  44.    #
  45.    opt := options(arg,"pv")
  46.    popularity := opt["p"]    # sort by popularity
  47.    verbose := opt["v"]        # report progress
  48.    if *arg = 0 then {
  49.       p := open("ls *.icn","rp")
  50.       while put(arg,read(p))
  51.       close(p)
  52.       }
  53.    spaces := ' \t'
  54.    sep := ' \t,'
  55.    proctable := table()
  56.    maxlib := maxfile := 0
  57.    #
  58.    # Gather information from files.
  59.    #
  60.    every fn := !arg do {
  61.       if \verbose then write(&errout,"File: ",fn)
  62.       f := open(fn) | stop("Can't open ",fn)
  63.       i := 0
  64.       every i := find("/",fn)
  65.       root := fn[1:find(".",fn,i + 1) | 0]
  66.       comma := &null
  67.       while line := read(f) do {
  68.      line ? {
  69.         tab(many(spaces))
  70.         if \comma | ="link " then {
  71.            if \verbose then write(&errout,"    ",line)
  72.            comma := &null
  73.            tab(many(spaces))
  74.            until pos(0) | match("#") do {
  75.           libname := tab(upto(sep) | 0)
  76.           put(\proctable[libname],root) | (proctable[libname] := [root])
  77.           maxlib <:= *libname
  78.           maxfile <:= *root
  79.           tab(many(spaces))
  80.           comma := &null
  81.           if comma := ="," then tab(many(spaces))
  82.           }
  83.            }
  84.         }
  85.      }
  86.       close(f)
  87.       }
  88.    #
  89.    #  Print the cross reference table.
  90.    #
  91.    write()
  92.    proctable := sort(proctable)
  93.    if \popularity then proctable := isort(proctable,popproc)
  94.    every x := !proctable do {
  95.       head := left(x[1],maxlib + 3)
  96.       heads := [left("(" || *x[2] || ")",maxlib + 3),
  97.             fill := repl(" ",*head)]
  98.       linesize := 78 - *head
  99.       every x := !sort(x[2]) do
  100.      if write(head,wrap(left(x,maxfile + 2),linesize)) then
  101.         head := get(heads)
  102.       write(head,wrap())
  103.       }
  104. end
  105.  
  106. procedure popproc(x)
  107.   return -*x[2]
  108. end
  109.