%%s 10/10/214 %%d D 1.2 22-Jul-83 11:26:45 sventek 2 1 %%c Changed name to apropos, as per Virginia's advice. %%s 0/0/0 %%d D 1.1 22-Jul-83 10:47:05 sventek 1 0 %%c This is the initial distribution of the lookup utility, which performs %%c regular expression matches on the on-line documentation database. %%T %%I 1 %%D 2 #-h- clook 122 asc 21-jul-83 11:10:29 sventek (joseph sventek) %%E 2 %%I 2 #-h- clook 122 asc 22-jul-83 11:25:44 sventek (joseph sventek) %%E 2 common / clook / lstptr, ptr(MAX_PATTERNS) integer lstptr # last used ptr index pointer ptr # dynamic storage pointers %%D 2 #-h- lookup.r 4539 asc 22-jul-83 10:46:46 sventek (joseph sventek) %%E 2 %%I 2 #-h- apropos.r 4541 asc 22-jul-83 11:25:45 sventek (joseph sventek) %%E 2 #-h- defns 142 asc 21-jul-83 10:58:23 sventek (joseph sventek) define(MAX_PATTERNS,25) # maximum number of patterns on command line define(Mem_size,arith(MAX_PATTERNS,*,MAXPAT)) # size of dynamic storage %%D 2 #-h- main 744 asc 22-jul-83 09:58:38 sventek (joseph sventek) DRIVER(lookup) %%E 2 %%I 2 #-h- main 746 asc 22-jul-83 11:24:39 sventek (joseph sventek) DRIVER(apropos) %%E 2 integer i integer getarg, enter, getlin, length filedes fd filedes open character buf(MAXLINE) include clook DS_DECL(Mem,Mem_size) %%D 2 string usestr "usage: lookup pattern [pattern]..." %%E 2 %%I 2 string usestr "usage: apropos pattern [pattern]..." %%E 2 call query(usestr) lstptr = 0 for (i = 1; getarg(i, buf, MAXLINE) != EOF; i = i + 1) if (enter(buf) != OK) { call putlin("Error in pattern: ", ERROUT) call error(buf) } if (i == 1) # no pattern specified call error(usestr) fd = open("~man/mpath", READ) # open file with search path if (fd == ERR) call error("Error in locating search path of manual sections!") while (getlin(buf, fd) != EOF) { i = length(buf) buf(i) = EOS call dolook(buf) # scan this section } call close(fd) DRETURN end #-h- dolook 1627 asc 21-jul-83 11:01:30 sventek (joseph sventek) subroutine dolook(suffix) character suffix(ARB) character indfil(FILENAMESIZE), secfil(FILENAMESIZE), buf(MAXLINE), tmp(MAXLINE), name(FILENAMESIZE) integer junk, i, fsize(2), size(2), lndmrk(MAXPAT) integer getpat, getlin, getwrd, agethd, agtlin, match, xmatch filedes ifd, sfd filedes open linepointer lptr string indstr "~man/i" string secstr "~man/s" call concat(indstr, suffix, indfil) ifd = open(indfil, READ) if (ifd == ERR) { call putlin("Error opening index file for section: ", ERROUT) call remark(suffix) return } call concat(secstr, suffix, secfil) sfd = open(secfil, READ) if (sfd == ERR) { call close(ifd) call putlin("Error opening section file for section: ", ERROUT) call remark(suffix) return } junk = getpat("NAME$", lndmrk) while (getlin(buf, ifd) != EOF) # get next index { i = 1 junk = getwrd(buf, i, name) call ctoptr(buf, i, lptr) call seek(lptr, sfd) # seek to entry fsize(1) = MAX_INTEGER fsize(2) = 0 if (agethd(sfd, buf, size, fsize) != OK) # bad format archive { call close(sfd) call close(ifd) call putlin("Bad format for entry: ", ERROUT) call remark(name) return } while (agtlin(buf, sfd, size) != EOF) # get next line of entry if (match(buf, lndmrk) == YES) # found sentinel line { junk = getlin(buf, sfd) # fetch one-liner call strcpy(buf, tmp) # temporary for matches call fold(tmp) if (xmatch(tmp) == YES) call dsplay(buf, suffix) break } } call close(ifd) call close(sfd) return end #-h- dsplay 292 asc 21-jul-83 11:05:08 sventek (joseph sventek) subroutine dsplay(buf, suffix) character buf(ARB), suffix(ARB) integer i i = 1 call skipbl(buf, i) while (buf(i) != ' ') { call putch(buf(i), STDOUT) i = i + 1 } call putch('(', STDOUT) call putlin(suffix, STDOUT) call putch(')', STDOUT) call putlnl(buf(i), STDOUT) return end #-h- enter 815 asc 21-jul-83 11:01:31 sventek (joseph sventek) integer function enter(str) character str(ARB) integer pat(MAXPAT) integer size, i integer makpat, patsiz pointer node pointer dsget include clook DS_DECL(Mem,Mem_size) if (lstptr == 0) # initialize dynamic memory call dsinit(Mem_size) if (lstptr >= MAX_PATTERNS) { call remark("Too many patterns for internal storage!") return(ERR) } call fold(str) # assure case insensitivity if (makpat(str, 1, EOS, pat) == ERR) # error compiling pattern return(ERR) lstptr = lstptr + 1 for (size = 1; pat(size) != EOS; size = size + patsiz(pat, size)) ; node = dsget(size) if (node == LAMBDA) { call remark("Too many patterns for internal storage!") return(ERR) } ptr(lstptr) = node for (i = 1; i < size; i = i + 1, node = node + 1) Mem(node) = pat(i) Mem(node) = EOS return(OK) end #-h- xmatch 457 asc 21-jul-83 10:44:45 sventek (joseph sventek) integer function xmatch(buf) character buf(ARB) integer i, j, k, size, l, pat(MAXPAT) integer patsiz, match include clook DS_DECL(Mem,Mem_size) for (i = 1; i <= lstptr; i = i + 1) { for (j = ptr(i), k = 1; Mem(j) != EOS; j = j + size, k = k + size) { size = patsiz(Mem, j) for (l = 0; l < size; l = l + 1) pat(k+l) = Mem(j+l) } pat(k) = EOS if (match(buf, pat) == YES) return(YES) } return(NO) end %%D 2 #-h- lookup.fmt 807 asc 22-jul-83 10:46:49 sventek (joseph sventek) %%E 2 %%I 2 #-h- apropos.fmt 811 asc 22-jul-83 11:25:48 sventek (joseph sventek) %%E 2 .so ~bin/manhdr %%D 2 .hd Lookup (1) 22-Jul-83 %%E 2 %%I 2 .hd Apropos (1) 22-Jul-83 %%E 2 locate manual entries matching user-specified patterns .sy %%D 2 lookup pattern [pattern] ... %%E 2 %%I 2 apropos pattern [pattern] ... %%E 2 .ds %%D 2 lookup searches the on-line documentation system for entries which match %%E 2 %%I 2 apropos searches the on-line documentation system for entries which match %%E 2 the regular expression patterns supplied in the command line. For each entry so found, a one-line synopsis of the entry (similar to the one displayed by the tool `intro') is displayed on standard output, with the section where the entry may be found. The `man' utility can then be used to retrieve more information on the topic. .ex To get a list of all entries having anything to do with the mail system, type the following command: .ti +16 %%D 2 lookup mail %%E 2 %%I 2 apropos mail %%E 2 .fl Accesses the known files for each section in the ~man directory. .sa The tools 'intro' and 'man'; the Unix command 'man' .di .au Joe Sventek. %%E 1