1: /* wc line and word count */
   2: 
   3: int buf[259];
   4: int wordct[2];
   5: int twordct[2];
   6: int linect[2];
   7: int tlinect[2];
   8: 
   9: main(argc,argv)
  10: char **argv;
  11: {
  12:     int i, token;
  13:     register char *p1, *p2;
  14:     register int c;
  15: 
  16:     i = 1;
  17:     do {
  18:         if(argc<=1) buf[0] = 0;
  19:         else if(fopen(argv[i],buf)<0) {
  20:             diag(argv[i]);
  21:             diag(": cannot open\n");
  22:             continue;
  23:         }
  24:         p1 = 0;
  25:         p2 = 0;
  26:         linect[0] = linect[1] = 0;
  27:         wordct[0] = wordct[1] = 0;
  28:         token = 0;
  29:         for(;;) {
  30:             if(p1 >= p2) {
  31:                 p1 = &buf[1];
  32:                 c = read(buf[0], p1, 512);
  33:                 if(c <= 0)
  34:                     break;
  35:                 p2 = p1+c;
  36:             }
  37:             c = 0;
  38:             c =| *p1++;
  39:             if(' '<c&&c<0177) {
  40:                 if(!token++) {
  41:                     if(++wordct[1]==0)
  42:                         wordct[0]++;
  43:                 }
  44:             } else {
  45:                 if(c=='\n') {
  46:                     if(++linect[1]==0)
  47:                         linect[0]++;
  48:                 }
  49:                 else if(c!=' '&&c!='\t')
  50:                     continue;
  51:                 token = 0;
  52:             }
  53:         }
  54:         printf("%7s ",locv(linect[0],linect[1]));
  55:         printf("%7s ",locv(wordct[0],wordct[1]));
  56:         printf("%s\n", argc<=1?"":argv[i]);
  57:         close(buf[0]);
  58:         ladd(tlinect, tlinect, linect);
  59:         ladd(twordct, twordct, wordct);
  60:     } while(++i<argc);
  61:     if(argc > 2) {
  62:         printf("%7s ",locv(tlinect[0],tlinect[1]));
  63:         printf("%7s ",locv(twordct[0],twordct[1]));
  64:         printf("total\n");
  65:     }
  66: }
  67: 
  68: diag(s)
  69: char *s;
  70: {
  71:     while(*s)
  72:         write(2,s++,1);
  73: }

Defined functions

diag defined in line 68; used 2 times
main defined in line 9; never used

Defined variables

buf defined in line 3; used 5 times
linect defined in line 6; used 7 times
tlinect defined in line 7; used 4 times
twordct defined in line 5; used 4 times
wordct defined in line 4; used 7 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 573
Valid CSS Valid XHTML 1.0 Strict