home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # Name: ilnkxref.icn
- #
- # Title: Icon "link" Cross Reference Utility
- #
- # Author: Robert J. Alexander
- #
- # Date: December 5, 1989
- #
- ############################################################################
- #
- # Utility to create cross reference of library files used in Icon
- # programs (i.e., those files named in "link" declarations).
- #
- # ilnkxref <icon source file>...
- #
- ############################################################################
- #
- # Links: wrap
- #
- ############################################################################
-
- link wrap
-
- procedure main(arg)
- local p, spaces, sep, proctable, maxlib, maxfile, fn, f, i, root
- local comma, line, libname, x, head, fill
- #
- # Initialize
- #
- if *arg = 0 then {
- p := open("ls *.icn","rp")
- while put(arg,read(p))
- close(p)
- }
- spaces := ' \t'
- sep := ' \t,'
- proctable := table()
- maxlib := maxfile := 0
- #
- # Gather information from files.
- #
- every fn := !arg do {
- write(&errout,"File: ",fn)
- f := open(fn) | stop("Can't open ",fn)
- i := 0
- every i := find("/",fn)
- root := fn[1:find(".",fn,i + 1) | 0]
- comma := &null
- while line := read(f) do {
- line ? {
- tab(many(spaces))
- if \comma | ="link " then {
- write(&errout," ",line)
- comma := &null
- tab(many(spaces))
- until pos(0) | match("#") do {
- libname := tab(upto(sep) | 0)
- put(\proctable[libname],root) | (proctable[libname] := [root])
- maxlib <:= *libname
- maxfile <:= *root
- tab(many(spaces))
- comma := &null
- if comma := ="," then tab(many(spaces))
- }
- }
- }
- }
- close(f)
- }
- #
- # Print the cross reference table.
- #
- write()
- every x := !sort(proctable) do {
- head := left(x[1],maxlib + 3)
- fill := repl(" ",*head)
- every x := !sort(x[2]) do {
- write(head,wrap(left(x,maxfile + 2),78)) & head := fill
- }
- write(head,wrap())
- }
- end
-