1: static char *sccsid = "@(#)wc.c	4.6 (Berkeley) 6/1/83";
   2: /* wc line and word count */
   3: 
   4: #include <stdio.h>
   5: long    linect, wordct, charct;
   6: long    tlinect, twordct, tcharct;
   7: char    *wd = "lwc";
   8: 
   9: main(argc, argv)
  10: char **argv;
  11: {
  12:     int i, token;
  13:     register FILE *fp;
  14:     register int c;
  15:     char *p;
  16: 
  17:     while (argc > 1 && *argv[1] == '-') {
  18:         switch (argv[1][1]) {
  19:         case 'l': case 'w': case 'c':
  20:             wd = argv[1]+1;
  21:             break;
  22:         default:
  23:         usage:
  24:             fprintf(stderr, "Usage: wc [-lwc] [files]\n");
  25:             exit(1);
  26:         }
  27:         argc--;
  28:         argv++;
  29:     }
  30: 
  31:     i = 1;
  32:     fp = stdin;
  33:     do {
  34:         if(argc>1 && (fp=fopen(argv[i], "r")) == NULL) {
  35:             perror(argv[i]);
  36:             continue;
  37:         }
  38:         linect = 0;
  39:         wordct = 0;
  40:         charct = 0;
  41:         token = 0;
  42:         for(;;) {
  43:             c = getc(fp);
  44:             if (c == EOF)
  45:                 break;
  46:             charct++;
  47:             if(' '<c&&c<0177) {
  48:                 if(!token) {
  49:                     wordct++;
  50:                     token++;
  51:                 }
  52:                 continue;
  53:             }
  54:             if(c=='\n') {
  55:                 linect++;
  56:             }
  57:             else if(c!=' '&&c!='\t')
  58:                 continue;
  59:             token = 0;
  60:         }
  61:         /* print lines, words, chars */
  62:         wcp(wd, charct, wordct, linect);
  63:         if(argc>1) {
  64:             printf(" %s\n", argv[i]);
  65:         } else
  66:             printf("\n");
  67:         fclose(fp);
  68:         tlinect += linect;
  69:         twordct += wordct;
  70:         tcharct += charct;
  71:     } while(++i<argc);
  72:     if(argc > 2) {
  73:         wcp(wd, tcharct, twordct, tlinect);
  74:         printf(" total\n");
  75:     }
  76:     exit(0);
  77: }
  78: 
  79: wcp(wd, charct, wordct, linect)
  80: register char *wd;
  81: long charct; long wordct; long linect;
  82: {
  83:     while (*wd) switch (*wd++) {
  84:     case 'l':
  85:         ipr(linect);
  86:         break;
  87: 
  88:     case 'w':
  89:         ipr(wordct);
  90:         break;
  91: 
  92:     case 'c':
  93:         ipr(charct);
  94:         break;
  95: 
  96:     }
  97: }
  98: 
  99: ipr(num)
 100: long num;
 101: {
 102:     printf(" %7ld", num);
 103: }

Defined functions

ipr defined in line 99; used 3 times
main defined in line 9; never used
wcp defined in line 79; used 2 times

Defined variables

charct defined in line 5; used 7 times
linect defined in line 5; used 7 times
sccsid defined in line 1; never used
tcharct defined in line 6; used 2 times
tlinect defined in line 6; used 2 times
twordct defined in line 6; used 2 times
wd defined in line 7; used 7 times
wordct defined in line 5; used 7 times
Last modified: 1983-07-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 725
Valid CSS Valid XHTML 1.0 Strict