#-h- wcnt.r 1101 asc 25-apr-81 07:11:24 [002,100] #-h- main 659 asc 25-apr-81 06:58:54 [002,100] ## 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) == MINUS & 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(NEWLINE) DRETURN end #-h- wcount 318 asc 25-apr-81 06:58:56 [002,100] ## 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 == BLANK | c == NEWLINE | c == TAB) inword = NO else if (inword == NO) { inword = YES incrdi(wc) } return end #-h- wcnt.rof 859 asc 11-may-81 12:24:59 [002,100] .pl 60 .bp .rm 70 .in 0 .he 'WCNT'1/11/79'WCNT' .fo ''-#-' .fi NAME .br .in 7 wcnt - (character) word count .sp 1 .in SYNOPSIS .br .in 7 wcnt [file] ... .sp 1 .in DESCRIPTION .br .in 7 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 .sp 1 .in FILES .br .in 7 .sp 1 .in SEE ALSO .br .in 7 lcnt; ccnt; the Unix command 'wc' .sp 1 .in DIAGNOSTICS .br .in 7 A message is printed if an input file could not be opened; further processing is terminated. .sp 1 .in AUTHORS .br .in 7 .sp 1 Original from Kernighan and Plauger's 'Software Tools', with modifications by Debbie Scherrer. .sp 1 .in BUGS .br .in 7