%%s 0/0/0 %%d D 1.1 25-Mar-82 12:16:40 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- wcnt.r 1114 asc 25-mar-82 09:06:54 v1.1 (sw-tools v1.1) #-h- main 654 asc 25-mar-82 09:06:34 v1.1 (sw-tools v1.1) ## wcnt - count (character) words in input file(s) DRIVER(wcnt) character getch character c, buf(MAXLINE) integer int, wc(2), twc(2), i integer open, getarg, ditoc call query("usage: wcnt [file] ...") initdi(twc) # initialize total word count to 0 for (i=1; getarg(i,buf,MAXLINE)!=EOF; i=i+1) { if (buf(1) == '-' & buf(2) == EOS) int = STDIN else { int = open(buf,READ) if (int == ERR) call cant(buf) } call wcount(int, wc) adddi(wc, twc) # add wc to twc if (int != STDIN) call close(int) } if (i==1) call wcount(STDIN, twc) i = ditoc(twc, buf, MAXCHARS) call putlin(buf, STDOUT) call putc('@n') DRETURN end #-h- wcount 314 asc 25-mar-82 09:06:35 v1.1 (sw-tools v1.1) ## wcount - count (character) words in file -int- subroutine wcount(int, wc) character getch character c integer inword, wc(2) initdi(wc) inword = NO while (getch(c,int) != EOF) if (c == ' ' | c == '@n' | c == '@t') inword = NO else if (inword == NO) { inword = YES incrdi(wc) } return end #-h- wcnt.fmt 591 asc 25-mar-82 09:06:56 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Wcnt (1) 11-Jan-79 (character) word count .sy wcnt [file] ... .ds wcnt counts (character) words in the named files, or in the standard input if no name appears. A word is a string of characters delimited by spaces, tabs, or newlines. wcnt could also be implemented as a shell script file: .ce tr ' @t@n' '@n' | tr '!@n' | ccnt .fl .sa lcnt; ccnt; the Unix command 'wc' .di A message is printed if an input file could not be opened; further processing is terminated. .au Original from Kernighan and Plauger's 'Software Tools', with modifications by Debbie Scherrer. .bu %%E 1