#-h- cxref 237 asc 24-apr-81 15:56:11 [002,100] ## common block for xref tool # put on a file called "cxref" # (Used only by 'xref') common /cxref/ buf(MAXBUF), nextbf integer buf # holds trees and linked lists integer nextbf # next free element in buf, init = 1 #-h- xref.r 7190 asc 24-apr-81 15:56:14 [002,100] #-h- defns 687 asc 24-apr-81 15:51:13 [002,100] # include ratdef # layout of tree nodes define(LLINK,0) # pointer to left subtree define(RLINK,1) # pointer to right subtree define(LNLIST,2) # pointer to list of references define(LAST,3) # pointer to last reference entered define(ENTRY,4) # name (string) define(TNODESIZE,5)# size of node = TNODESIZE + length(name) + 1 # layout of linked list nodes define(LINENUM,0) # line number define(LINK,1) # pointer to next line number define(LNODESIZE,2) define(MAXBUF,15000) define(LINESIZE,80) # length of output lines (see pentry) define(MAXTOK,15) # maximum token size (see pentry) define(MAXNUM,5) # size of line number entry (see pentry) define(MAXNAME,FILENAMESIZE) #-h- main 1064 asc 24-apr-81 15:51:15 [002,100] # xref - make cross reference list of named files DRIVER(xref) character name(MAXTOK), arg(MAXNAME) integer fd, fflag, nfiles, bias, i, j integer open, getarg, ctoi string usestr "usage: xref [-b] [-f] [file] ..." data fflag/NO/, nfiles/0/, bias/0/ call query(usestr) for (i = 1; getarg(i, arg, MAXNAME) ^= EOF; i = i + 1) if (arg(1) == MINUS & (arg(2) == LETF | arg(2) == BIGF)) fflag = YES else if (arg(1) == MINUS & (arg(2) == LETB | arg(2) == BIGB)) { j = 3 bias = ctoi(arg, j) if (bias < 0) bias = 0 } else if ((arg(1) == MINUS & arg(2) ^= EOS) ) call error (usestr) else { if (arg(1) == MINUS) fd = STDIN else fd = open(arg, READ) if (fd == ERR) call cant(arg) call putlin(arg, STDOUT) call putc(COLON) call putc(NEWLINE) call doxref(fd, fflag, bias) nfiles = nfiles + 1 } if (nfiles == 0) call doxref(STDIN, fflag, bias) DRETURN end #-h- balloc 236 asc 24-apr-81 15:51:17 [002,100] # balloc - allocate n words in storage array buf; return index integer function balloc(n) integer n include cxref nextbf = nextbf + n if (nextbf > MAXBUF) call error("out of storage.") return(nextbf - n) end #-h- doxref 586 asc 24-apr-81 15:51:18 [002,100] # doxref-generate cross reference list for file fd; fold if fflag = YES subroutine doxref(fd, fflag, bias) integer fd, fflag, bias integer t, root integer gettok character token(MAXTOK) include cxref root = 0 nextbf = 1 lineno = bias + 1 repeat { t = gettok(token, MAXTOK, fd) if (t == EOF) break if (t == LETTER) { if (fflag == YES) call fold(token) call instl(token, lineno, root) } else if (t == NEWLINE) lineno = lineno + 1 } call tprint(root) return end #-h- gettok 1007 asc 24-apr-81 15:51:19 [002,100] # gettok - get text token from file fd character function gettok(token, size, fd) character token(ARB) integer size, fd character getch, type integer i character c, peek data peek /0/ if (peek == 0) # check for lookahead c = getch(c, fd) else { c = peek peek = 0 } for (; c ^= EOF; c = getch(c, fd)) { gettok = type(c) if (gettok == LETTER) { # start of name token(1) = c for (i = 2; getch(c, fd) ^= EOF; i = i + 1) if (type(c) == LETTER | type(c) == DIGIT) { if (i < size) token(i) = c } else break peek = c # went one too far if (i <= size) token(i) = EOS else token(size) = EOS return(LETTER) } else if (gettok == NEWLINE) { # newline must be returned peek = 0 return(NEWLINE) } } peek = 0 return(EOF) end #-h- instl 1076 asc 24-apr-81 15:51:21 [002,100] # instl - install name in tree with reference on lineno; update tree subroutine instl(name, lineno, tree) character name(ARB), temp(MAXNAME) integer lineno, tree integer cond, p, q integer balloc, strcmp, length include cxref p = tree for (q = 0; p ^= 0; p = buf(q)) { call icopys (buf, p+ENTRY, temp, 1) #convert from int to char cond = strcmp(name, temp) if (cond == 0) { q = balloc(LNODESIZE) # add a new element onto list buf(q+LINENUM) = lineno buf(q+LINK) = 0 buf(buf(p+LAST)+LINK) = q buf(p+LAST) = q return } else if (cond < 0) q = p + LLINK else q = p + RLINK } p = balloc(TNODESIZE+length(name)+1) # allocate and fill in new node buf(p+LLINK) = 0 buf(p+RLINK) = 0 call scopyi(name, 1, buf, p+ENTRY) if (q == 0) tree = p else buf(q) = p q = balloc(LNODESIZE) # insert first reference buf(q+LINENUM) = lineno buf(q+LINK) = 0 buf(p+LNLIST) = q buf(p+LAST) = q return end #-h- pentry 558 asc 24-apr-81 15:51:23 [002,100] # pentry - print name and list of references subroutine pentry(name, list) character name(ARB) integer list integer i, len include cxref call putstr(name, -MAXTOK - 1, STDOUT) len = MAXTOK + 1 for (i = list; i ^= 0; i = buf(i+LINK)) { if (len > LINESIZE - MAXNUM) { call putc(NEWLINE) call putstr(EOS, -MAXTOK - 1, STDOUT) len = MAXTOK + 1 } call putint(buf(i+LINENUM), MAXNUM, STDOUT) len = len + MAXNUM } if (len <= LINESIZE) call putc(NEWLINE) return end #-h- tprint 707 asc 24-apr-81 15:51:25 [002,100] # tprint - destructively print tree, left subtree first subroutine tprint(tree) integer tree integer p, q, sp character temp(MAXNAME) include cxref sp = 0 p = tree repeat { while (p ^= 0) if (buf(p+LLINK) ^= 0) { q = buf(p+LLINK) buf(p+LLINK) = sp sp = p p = q } else { call icopys (buf, p+ENTRY, temp, 1) call pentry(temp, buf(p+LNLIST)) p = buf(p+RLINK) } if (sp == 0) return call icopys (buf, sp+ENTRY, temp, 1) call pentry(temp, buf(sp+LNLIST)) p = buf(sp+RLINK) sp = buf(sp+LLINK) } return end #-h- icopys 326 asc 24-apr-81 15:51:26 [002,100] ## icopys - copy integer string at from(i) to char string at to(j) subroutine icopys(from, i, to, j) integer from(ARB) character to(ARB) integer i, j, k1, k2 k2 = j for (k1 = i; from(k1) != EOS; k1 = k1 + 1) { to(k2) = from(k1) k2 = k2 + 1 } to(k2) = EOS return end #-h- scopyi 323 asc 24-apr-81 15:51:27 [002,100] ## scopyi - copy char string at from(i) to integer string to(j) subroutine scopyi(from, i, to, j) character from(ARB) integer to(ARB) integer i, j, k1, k2 k2 = j for (k1 = i; from(k1) != EOS; k1 = k1 + 1) { to(k2) = from(k1) k2 = k2 + 1 } to(k2) = EOS return end #-h- xref.rof 1303 asc 11-may-81 12:26:28 [002,100] .pl 60 .bp 1 .in 0 .he 'XREF (1)'1/1/79'XREF (1)' .sp 2 .in +3 .fi .ti -3 NAME .br xref - make a cross reference of symbols .nf .sp .ti -3 SYNOPSIS .br xref [-f] [file] ... .fi .sp .ti -3 DESCRIPTION .br Xref produces a cross-reference list of the symbols in each of the named files on the standard output. Each symbol is listed followed by the numbers of the lines in which it appears. If no files are given, or the file "-" is specified, xref reads the standard input. .sp A symbol is defined as a string of letters, digits, underlines, or periods that begins with a letter. Symbols exceeding an internal limit are truncated. This limit is determined by the MAXTOK definition in the source code, and is currently set to 15. .sp Normally, xref treats upper- and lower-case letters as different characters. The -f option causes all letters to be folded to lower-case. .fi .sp .ne 2 .ti -3 DIAGNOSTICS .br out of storage .br .in +3 The file contains too many symbols or references to fit within the current limitations of xref. The size of the buffer is determined by the MAXBUF definition in the source code. .in -3 .fi .sp .ti -3 AUTHORS .br David Hanson and friends (U. of Arizona) .sp .ne 2 .ti -3 BUGS/DEFICIENCIES .br There should be a means of suppressing "junk" symbols such as "the", "a", etc.