1: #include <stdio.h>
   2: #define LB 256
   3: int one;
   4: int two;
   5: int three;
   6: 
   7: char    *ldr[3];
   8: 
   9: FILE *ib1;
  10: FILE *ib2;
  11: FILE *openfil();
  12: main(argc,argv)
  13: char    *argv[];
  14: {
  15:     int l;
  16:     char    lb1[LB],lb2[LB];
  17: 
  18:     ldr[0] = "";
  19:     ldr[1] = "\t";
  20:     ldr[2] = "\t\t";
  21:     if(argc > 1)  {
  22:         if(*argv[1] == '-' && argv[1][1] != 0) {
  23:             l = 1;
  24:             while(*++argv[1]) {
  25:                 switch(*argv[1]) {
  26:                 case'1':
  27:                     if(!one) {
  28:                         one = 1;
  29:                         ldr[1][0] =
  30:                         ldr[2][l--] = '\0';
  31:                     }
  32:                     break;
  33:                 case '2':
  34:                     if(!two) {
  35:                         two = 1;
  36:                         ldr[2][l--] = '\0';
  37:                     }
  38:                     break;
  39:                 case '3':
  40:                     three = 1;
  41:                     break;
  42:                 default:
  43:                 fprintf(stderr,"comm: illegal flag\n");
  44:                 exit(1);
  45:                 }
  46:             }
  47:             argv++;
  48:             argc--;
  49:         }
  50:     }
  51: 
  52:     if(argc < 3) {
  53:         fprintf(stderr,"comm: arg count\n");
  54:         exit(1);
  55:     }
  56: 
  57:     ib1 = openfil(argv[1]);
  58:     ib2 = openfil(argv[2]);
  59: 
  60: 
  61:     if(rd(ib1,lb1) < 0) {
  62:         if(rd(ib2,lb2) < 0) exit(0);
  63:         copy(ib2,lb2,2);
  64:     }
  65:     if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
  66: 
  67:     while(1) {
  68: 
  69:         switch(compare(lb1,lb2)) {
  70: 
  71:             case 0:
  72:                 wr(lb1,3);
  73:                 if(rd(ib1,lb1) < 0) {
  74:                     if(rd(ib2,lb2) < 0) exit(0);
  75:                     copy(ib2,lb2,2);
  76:                 }
  77:                 if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
  78:                 continue;
  79: 
  80:             case 1:
  81:                 wr(lb1,1);
  82:                 if(rd(ib1,lb1) < 0) copy(ib2,lb2,2);
  83:                 continue;
  84: 
  85:             case 2:
  86:                 wr(lb2,2);
  87:                 if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
  88:                 continue;
  89:         }
  90:     }
  91: }
  92: 
  93: rd(file,buf)
  94: FILE *file;
  95: char *buf;
  96: {
  97: 
  98:     register int i, c;
  99:     i = 0;
 100:     while((c = getc(file)) != EOF) {
 101:         *buf = c;
 102:         if(c == '\n' || i > LB-2) {
 103:             *buf = '\0';
 104:             return(0);
 105:         }
 106:         i++;
 107:         buf++;
 108:     }
 109:     return(-1);
 110: }
 111: 
 112: wr(str,n)
 113:     char    *str;
 114: {
 115: 
 116:     switch(n) {
 117: 
 118:         case 1:
 119:             if(one) return;
 120:             break;
 121: 
 122:         case 2:
 123:             if(two) return;
 124:             break;
 125: 
 126:         case 3:
 127:             if(three)   return;
 128:     }
 129:     printf("%s%s\n",ldr[n-1],str);
 130: }
 131: 
 132: copy(ibuf,lbuf,n)
 133: FILE *ibuf;
 134: char *lbuf;
 135: {
 136:     do {
 137:         wr(lbuf,n);
 138:     } while(rd(ibuf,lbuf) >= 0);
 139: 
 140:     exit(0);
 141: }
 142: 
 143: compare(a,b)
 144:     char    *a,*b;
 145: {
 146:     register char *ra,*rb;
 147: 
 148:     ra = --a;
 149:     rb = --b;
 150:     while(*++ra == *++rb)
 151:         if(*ra == '\0') return(0);
 152:     if(*ra < *rb)   return(1);
 153:     return(2);
 154: }
 155: FILE *openfil(s)
 156: char *s;
 157: {
 158:     FILE *b;
 159:     if(s[0]=='-' && s[1]==0)
 160:         b = stdin;
 161:     else if((b=fopen(s,"r")) == NULL) {
 162:         fprintf(stderr,"comm: cannot open %s\n",s);
 163:         exit(1);
 164:     }
 165:     return(b);
 166: }

Defined functions

compare defined in line 143; used 1 times
  • in line 69
copy defined in line 132; used 6 times
main defined in line 12; never used
openfil defined in line 155; used 3 times
rd defined in line 93; used 9 times
wr defined in line 112; used 4 times

Defined variables

ldr defined in line 7; used 7 times
one defined in line 3; used 3 times
three defined in line 5; used 2 times
two defined in line 4; used 3 times

Defined macros

LB defined in line 2; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 890
Valid CSS Valid XHTML 1.0 Strict