1 /* wc - count lines, words and characters Author: David Messer */
9 * Usage: wc [-lwc] [names]
14 * c - count characters.
16 * Flags l, w, and c are default.
17 * Words are delimited by any non-alphabetic character.
19 * Released into the PUBLIC-DOMAIN 02/10/86
21 * If you find this program to be of use to you, a donation of
22 * whatever you think it is worth will be cheerfully accepted.
24 * Written by: David L. Messer
25 * P.O. Box 19130, Mpls, MN, 55119
26 * Program (heavily) modified by Andy Tanenbaum
30 int lflag
; /* Count lines */
31 int wflag
; /* Count words */
32 int cflag
; /* Count characters */
34 long lcount
; /* Count of lines */
35 long wcount
; /* Count of words */
36 long ccount
; /* Count of characters */
38 long ltotal
; /* Total count of lines */
39 long wtotal
; /* Total count of words */
40 long ctotal
; /* Total count of characters */
42 int main(int argc
, char **argv
);
58 if (argc
> 1 && *cp
++ == '-') {
60 k
++; /* points to first file */
63 case 'l': lflag
++; break;
64 case 'w': wflag
++; break;
65 case 'c': cflag
++; break;
72 /* If no flags are set, treat as wc -lwc. */
73 if (!lflag
&& !wflag
&& !cflag
) {
80 tflag
= files
>= 2; /* set if # files > 1 */
82 /* Check to see if input comes from std input. */
85 if (lflag
) printf(" %6ld", lcount
);
86 if (wflag
) printf(" %6ld", wcount
);
87 if (cflag
) printf(" %6ld", ccount
);
93 /* There is an explicit list of files. Loop on files. */
97 if ((f
= fopen(argv
[k
], "r")) == NULL
) {
98 fprintf(stderr
, "wc: cannot open %s\n", argv
[k
]);
101 if (lflag
) printf(" %6ld", lcount
);
102 if (wflag
) printf(" %6ld", wcount
);
103 if (cflag
) printf(" %6ld", ccount
);
104 printf(" %s\n", argv
[k
]);
111 if (lflag
) printf(" %6ld", ltotal
);
112 if (wflag
) printf(" %6ld", wtotal
);
113 if (cflag
) printf(" %6ld", ctotal
);
124 register int word
= 0;
130 while ((c
= getc(f
)) != EOF
) {
140 if (c
== '\n' || c
== '\f') lcount
++;
149 fprintf(stderr
, "Usage: wc [-lwc] [name ...]\n");