1: #define LB 250 2: int one; 3: int two; 4: int three; 5: 6: char *ldr[3]; 7: 8: char ib1[518]; 9: char ib2[518]; 10: main(argc,argv) 11: char *argv[]; 12: { 13: extern fout; 14: int l; 15: char lb1[LB],lb2[80]; 16: 17: ldr[0] = ""; 18: ldr[1] = "\t"; 19: ldr[2] = "\t\t"; 20: if(argc > 1) { 21: if(*argv[1] == '-' && argv[1][1] != 0) { 22: l = 1; 23: while(*++argv[1]) { 24: switch(*argv[1]) { 25: case'1': 26: if(!one) { 27: one = 1; 28: ldr[1][0] = 29: ldr[2][l--] = '\0'; 30: } 31: break; 32: case '2': 33: if(!two) { 34: two = 1; 35: ldr[2][l--] = '\0'; 36: } 37: break; 38: case '3': 39: three = 1; 40: break; 41: default: 42: printf("Illegal flag: %c\n",*argv[1]); 43: exit(); 44: } 45: } 46: argv++; 47: argc--; 48: } 49: } 50: 51: if(argc < 3) { 52: printf("Argc = %d\n",argc); 53: exit(); 54: } 55: 56: openfil(argv[1],ib1); 57: openfil(argv[2],ib2); 58: fout = dup(1); 59: 60: 61: if(rd(ib1,lb1) < 0) { 62: if(rd(ib2,lb2) < 0) exit(); 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) fexit(); 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: char *buf; 95: { 96: 97: register int i; 98: i = 0; 99: while((*buf = getc(file)) >=0) { 100: if(*buf == '\n' || i > LB-2) { 101: *buf = '\0'; 102: return(0); 103: } 104: i++; 105: buf++; 106: } 107: return(-1); 108: } 109: 110: wr(str,n) 111: char *str; 112: { 113: 114: switch(n) { 115: 116: case 1: 117: if(one) return; 118: break; 119: 120: case 2: 121: if(two) return; 122: break; 123: 124: case 3: 125: if(three) return; 126: } 127: printf("%s%s\n",ldr[n-1],str); 128: } 129: 130: copy(ibuf,lbuf,n) 131: { 132: do { 133: wr(lbuf,n); 134: } while(rd(ibuf,lbuf) >= 0); 135: 136: flush(); 137: exit(); 138: } 139: 140: compare(a,b) 141: char *a,*b; 142: { 143: register char *ra,*rb; 144: 145: ra = --a; 146: rb = --b; 147: while(*++ra == *++rb) 148: if(*ra == '\0') return(0); 149: if(*ra < *rb) return(1); 150: return(2); 151: } 152: fexit() 153: { 154: flush(); 155: exit(); 156: } 157: 158: openfil(s,b) 159: char *s; 160: int *b; 161: { 162: if(s[0]=='-' && s[1]==0) 163: b[0] = 0; 164: else if(fopen(s, b) == -1) { 165: printf("Can't open %s\n", s); 166: exit(1); 167: } 168: }