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

Defined functions

compare defined in line 144; used 1 times
  • in line 70
copy defined in line 133; used 6 times
main defined in line 13; never used
openfil defined in line 156; used 3 times
rd defined in line 94; used 9 times
wr defined in line 113; used 4 times

Defined variables

ldr defined in line 8; used 7 times
one defined in line 4; used 3 times
sccsid defined in line 1; never used
three defined in line 6; used 2 times
two defined in line 5; used 3 times

Defined macros

LB defined in line 3; used 3 times
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2891
Valid CSS Valid XHTML 1.0 Strict