- /* print lines, words, chars */
- wcp(wd, charct, wordct, linect);
- if(argc>1) {
- printf(" %s\n", argv[i]);
- } else
- printf("\n");
- fclose(fp);
+ }
+ else
+ fd = 0;
+ /* do it the hard way... */
+ for (gotsp = 1; len = read(fd, buf, MAXBSIZE);) {
+ if (len == -1) {
+ perror(file);
+ exit(1);
+ }
+ charct += len;
+ for (C = buf; len--; ++C)
+ switch(*C) {
+ case NL:
+ ++linect;
+ case TAB:
+ case SPACE:
+ gotsp = 1;
+ continue;
+ default:
+#ifdef notdef
+ /*
+ * This line of code implements the
+ * original V7 wc algorithm, i.e.
+ * a non-printing character doesn't
+ * toggle the "word" count, so that
+ * " ^D^F " counts as 6 spaces,
+ * while "foo^D^Fbar" counts as 8
+ * characters.
+ *
+ * test order is important -- gotsp
+ * will normally be NO, so test it
+ * first
+ */
+ if (gotsp && *C > SPACE && *C < DEL) {
+#endif
+ /*
+ * This line implements the manual
+ * page, i.e. a word is a "maximal
+ * string of characters delimited by
+ * spaces, tabs or newlines." Notice
+ * nothing was said about a character
+ * being printing or non-printing.
+ */
+ if (gotsp) {
+ gotsp = 0;
+ ++wordct;
+ }
+ }
+ }
+ if (doline) {