1: fields 0;
   2: letters 0;
   3: linec;
   4: mode;
   5: uniq;
   6: 
   7: main(argc, argv)
   8: int argc;
   9: char *argv[];
  10: {
  11:     extern fin, fout;
  12:     int f;
  13:     static char b1[1000], b2[1000];
  14: 
  15: loop:
  16:     if(argc > 1) {
  17:         if(*argv[1] == '-') {
  18:             if(argv[1][1] <= '9')
  19:                 fields = conv(&argv[1][1]);
  20:             else mode = argv[1][1];
  21:             argc--;
  22:             argv++;
  23:             goto loop;
  24:         }
  25:         if(*argv[1] == '+') {
  26:             letters = conv(&argv[1][1]);
  27:             argc--;
  28:             argv++;
  29:             goto loop;
  30:         }
  31:         f = open(argv[1], 0);
  32:         if(f < 0) {
  33:             printf("cannot open %s\n", argv[1]);
  34:             exit();
  35:         }
  36:         fin = f;
  37:     } else
  38:         fin = dup(0);
  39:     if(argc > 2) {
  40:         f = creat(argv[2], 0666);
  41:         if(f < 0) {
  42:             printf("cannot create %s\n", argv[2]);
  43:             exit();
  44:         }
  45:         fout = f;
  46:     } else
  47:         fout = dup(1);
  48:     close(0);
  49:     close(1);
  50:     gline(b1);
  51: l1:
  52:     linec++;
  53:     if(gline(b2)) {
  54:         pline(b1);
  55:         flush();
  56:         exit();
  57:     }
  58:     if(equal(b1, b2)) goto l1;
  59:     pline(b1);
  60:     linec = 0;
  61: l2:
  62:     linec++;
  63:     if(gline(b1)) {
  64:         pline(b2);
  65:         flush();
  66:         exit();
  67:     }
  68:     if(equal(b1, b2)) goto l2;
  69:     pline(b2);
  70:     linec = 0;
  71:     goto l1;
  72: }
  73: 
  74: gline(buf)
  75: char buf[];
  76: {
  77:     int c;
  78: 
  79:     while((c = getchar()) != '\n') {
  80:         if(c == '\0')
  81:             return(1);
  82:         *buf++ = c;
  83:     }
  84:     *buf = 0;
  85:     return(0);
  86: }
  87: 
  88: pline(buf)
  89: char buf[];
  90: {
  91:     int c;
  92: 
  93:     switch(mode) {
  94: 
  95:     case 'u':
  96:         if(uniq) {;
  97:             uniq = 0;
  98:             return;
  99:         }
 100:         break;
 101: 
 102:     case 'd':
 103:         if(uniq) break;
 104:         return;
 105: 
 106:     case 'c':
 107:         printf("%4d ", linec);
 108:     }
 109:     uniq = 0;
 110:     while((c = *buf++) != 0)
 111:         putchar(c);
 112:     putchar('\n');
 113: }
 114: 
 115: equal(b1, b2)
 116: char b1[], b2[];
 117: {
 118:     int c;
 119: 
 120:     b1 = skip(b1);
 121:     b2 = skip(b2);
 122:     while((c = *b1++) != 0)
 123:         if(c != *b2++) return(0);
 124:     if(*b2 != 0)
 125:         return(0);
 126:     uniq++;
 127:     return(1);
 128: }
 129: 
 130: char *
 131: skip(s)
 132: char *s;
 133: {
 134:     int nf, nl;
 135: 
 136:     nf = nl = 0;
 137:     while(nf++ < fields) {
 138:         while(*s==' ' || *s=='\t')
 139:             s++;
 140:         while( !(*s==' ' || *s=='\t') )
 141:             if(*s == 0) return(s);
 142:             else s++;
 143:     }
 144:     while(nl++ < letters)
 145:             if(*s == 0) return(s);
 146:             else s++;
 147:     return(s);
 148: }
 149: 
 150: conv(s)
 151: char *s;
 152: {
 153:     int d, n;
 154: 
 155:     n = 0;
 156:     for(;;) {
 157:         d = *s++ - '0';
 158:         if(0>d || d>9) break;
 159:         n = n*10 + d;
 160:     }
 161:     return(n);
 162: }

Defined functions

conv defined in line 150; used 2 times
equal defined in line 115; used 2 times
gline defined in line 74; used 3 times
main defined in line 7; never used
pline defined in line 88; used 4 times
skip defined in line 130; used 2 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 763
Valid CSS Valid XHTML 1.0 Strict