%%s 0/0/0 %%d D 1.1 25-Mar-82 12:16:33 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- wc.r 2968 asc 25-mar-82 09:06:01 v1.1 (sw-tools v1.1) #-h- defns 48 asc 25-mar-82 09:05:40 v1.1 (sw-tools v1.1) # include ratdef define(MAXNAME,FILENAMESIZE) #-h- main 1523 asc 25-mar-82 09:05:40 v1.1 (sw-tools v1.1) # wc - count lines, words, and characters in named files or STDIN DRIVER(wc) character arg(MAXLINE) integer open, getarg, index integer fd, i, j, words, lines, chars, nfiles integer nl(2), nw(2), nc(2), tl(2), tw(2), tc(2) string total "total" string usestr "usage: wc [-lwc] [file] ..." string null "" data words /YES/, lines /YES/, chars /YES/ # -lwc is default call query(usestr) initdi(tl) initdi(tw) initdi(tc) for (i = 1; getarg(i, arg, MAXNAME) != EOF; i = i + 1) if (arg(1) == '-' & arg(2) != EOS) { lines = NO words = NO chars = NO call fold(arg) if (index(arg, 'l') > 0) lines = YES if (index(arg, 'w') > 0) words = YES if (index(arg, 'c') > 0) chars = YES } else { nfiles = nfiles + 1 if (arg(1) == '-') fd = STDIN else fd = open(arg, READ) if (fd == ERR) { call putlin(arg, ERROUT) call remark(": can't open.") } else { call dowc(fd, nl, nw, nc) call printc(arg, nl, nw, nc, lines, words, chars) adddi(nl,tl) adddi(nw,tw) adddi(nc,tc) if (fd != STDIN) call close(fd) } } if (nfiles == 0) { # no args, do STDIN call dowc(STDIN, nl, nw, nc) call printc(null, nl, nw, nc, lines, words, chars) } else if (nfiles > 1) call printc(total, tl, tw, tc, lines, words, chars) DRETURN end #-h- dowc 482 asc 25-mar-82 09:05:42 v1.1 (sw-tools v1.1) # dowc - count lines, words, and characters in fd subroutine dowc(fd, nl, nw, nc) integer fd, nl(2), nw(2), nc(2) character getch character c integer inword initdi(nl) initdi(nw) initdi(nc) inword = NO while (getch(c, fd) != EOF) { incrdi(nc) if (c == '@n') incrdi(nl) if (c == ' ' | c == '@n' | c == '@t') inword = NO else if (inword == NO) { inword = YES incrdi(nw) } } return end #-h- printc 623 asc 25-mar-82 09:05:43 v1.1 (sw-tools v1.1) # printc - print count statistics for arg subroutine printc(arg, nl, nw, nc, lines, words, chars) character arg(ARB), buf(MAXCHARS) integer ditoc integer nl(2), nw(2), nc(2), lines, words, chars, junk if (lines == YES) { junk = ditoc(nl, buf, MAXCHARS) call putstr(buf, 8, STDOUT) } if (words == YES) { junk = ditoc(nw, buf, MAXCHARS) call putstr(buf, 8, STDOUT) } if (chars == YES) { junk = ditoc(nc, buf, MAXCHARS) call putstr(buf, 8, STDOUT) } call putc(' ') call putlin(arg, STDOUT) call putc('@n') return end #-h- wc.fmt 783 asc 25-mar-82 09:06:03 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Wc (1) 15-Feb-79 count lines, words, and characters in files .sy wc [-lwc] [file] ... .ds wc prints the number of lines, words, and characters in the named files. The filename "-" specifies the standard input. A total is also printed. A "word" is any sequence of characters delimited by white space. .sp The options -l, -w, and -c specify, respectively, that only the line, word, or character count be printed. For example, .sp .in +3 .nf wc -lc foo .in -3 .sp .fi prints the number of lines and characters in "foo". .sp If no files are given, wc reads its standard input and the total count is suppressed. .fi .fl .di name: can't open .in +5 Printed when an input file can't be opened; processing ceases .in -5 .au David Hanson and friends (U. of Arizona) .bu %%E 1