%%s 0/0/0 %%d D 1.1 25-Mar-82 12:07:21 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- cgrep 481 asc 25-mar-82 08:01:16 v1.1 (sw-tools v1.1) # cgrep - common block for grep # place on a file named cgrep # used only by grep common / cgrep / count, header, list, except, casind integer count # if grep is to count matches, only; init = NO integer header # if grep is display file header; init = YES integer list # if grep is to only list files with at least on match; init=NO integer except # if grep is to use line which do not match expression; init=NO integer casind # if grep is to be case insensitive; init=NO #-h- grep.r 2588 asc 25-mar-82 08:01:17 v1.1 (sw-tools v1.1) #-h- defns 19 asc 25-mar-82 08:01:05 v1.1 (sw-tools v1.1) define(NUMWIDTH,6) #-h- main 1280 asc 25-mar-82 08:01:05 v1.1 (sw-tools v1.1) DRIVER(grep) integer exprst, i, j integer getarg, index, getpat, equal integer pat(MAXPAT) filedes fd filedes open character arg(MAXARG) include cgrep string usestr "usage: grep [-chilx] expression [file] ..." string illmsg "illegal pattern: " string minust "-" string stdins "stdin" call query(usestr) count = NO header = YES list = NO except = NO casind = NO if (getarg(1, arg, MAXARG) == EOF) call error(usestr) else if (arg(1) == '-') { exprst = 2 call fold(arg) if (index(arg, 'c') > 0) count = YES if (index(arg, 'h') > 0) header = NO if (index(arg, 'i') > 0) casind = YES if (index(arg, 'l') > 0) list = YES if (index(arg, 'x') > 0) except = YES } else exprst = 1 if (getarg(exprst, arg, MAXARG) == EOF) call error(usestr) if( casind == YES ) call fold(arg) if (getpat(arg, pat) == ERR) { call putlin(illmsg, ERROUT) call error(arg) } for ([i=1; j=exprst+1]; getarg(j, arg, MAXARG) != EOF; [i=i+1; j=j+1]) { if (equal(arg, minust) == YES) { fd = STDIN call strcpy(stdins, arg) } else { fd = open(arg, READ) if (fd == ERR) call cant(arg) } call dogrep(fd, arg, pat) if (fd != STDIN) call close(fd) } if (i == 1) call dogrep(STDIN, stdins, pat) DRETURN end #-h- dogrep 1070 asc 25-mar-82 08:01:06 v1.1 (sw-tools v1.1) subroutine dogrep(fd, file, pat) filedes fd integer mcount, matchd, pat(MAXPAT) integer getlin, match character file(FILENAMESIZE), line(MAXLINE), tmplin(MAXLINE) include cgrep mcount = 0 while (getlin(line, fd) != EOF) { if( casind == YES ) { call strcpy( line, tmplin) call fold(tmplin) matchd = match( tmplin, pat) } else matchd = match(line, pat) if ((matchd == YES & except == NO) | (matchd == NO & except == YES)) { mcount = mcount + 1 if (mcount == 1 & count == NO) if (list == YES) # only list files { call putlin(file, STDOUT) call putch('@n', STDOUT) return } else if (header == YES) { call putch('@n', STDOUT) call putlin(file, STDOUT) call putch(':', STDOUT) call putch('@n', STDOUT) } if (count == NO) call putlin(line, STDOUT) } } if (count == YES) { call putint(mcount, NUMWIDTH, STDOUT) call putch(' ', STDOUT) call putlin(file, STDOUT) call putch('@n', STDOUT) } return end #-h- grep.fmt 1143 asc 25-mar-82 08:01:18 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Grep (1) 2-May-81 search file[s] for a pattern .sy grep [-chilx] expression [file] ... .ds `grep' searches the names files (or standard input if none are specified) for occurrences of the expression. The set of valid expressions are the same as those for `find', `ch' and `ed'. The manual entries for those tools may be consulted for full details. The output of `grep' is dependent upon which switches are selected: .sp .in +5 .ti -5 None When one or more occurrences of the expression are found in a file, the file name is displayed, with each line in which the expression occurs listed below the file name. .sp .ti -3 -c Only the number of matching lines in each file is displayed. .sp .ti -3 -h Do not display the file names. .sp .ti -3 -i Make comparisons case insensitive. .sp .ti -3 -l Only the names of files which contain matching lines are displayed, one per line. .sp .ti -3 -x Display (or count) only those lines which do NOT contain the expression. .in -5 .fl none .sa .nf find - find groups of expressions in a file ch - globally change expressions within a file ed - text editor .fi .di .au Joe Sventek .bu %%E 1