1: /*int mbuf[1024]; /*INSTR*/ 2: int ig 100; 3: int esw; 4: int initf 1; 5: char ssp[270]; 6: char *sym[9] {ssp, 7: ssp + 30, 8: ssp + 60, 9: ssp + 90, 10: ssp + 120, 11: ssp + 150, 12: ssp + 180, 13: ssp + 210, 14: ssp + 240, 15: ssp + 270 16: }; 17: 18: main(argc, argv) 19: char *argv[]; 20: { 21: auto f,fct,file,i; 22: 23: if(argc < 2) { 24: printf("Usage: crpost [-d] file1 file2 ...\n"); 25: exit(); 26: } 27: 28: if(*argv[1] == '-') { 29: if(argv[1][1] == 'E') { 30: fct = 3; 31: esw = 1; 32: goto on; 33: } 34: fct = argv[1][1] - '0'; 35: if((fct < 1) || (fct > 9)) { 36: printf("-d: 0 < d < 10\n"); 37: exit(); 38: } 39: if(argv[1][2] == 'x') { 40: ig = fct-1; 41: } 42: on: 43: argv++; 44: argc--; 45: } else { 46: fct = 3; 47: } 48: 49: f = 0; 50: while(++f < argc) { 51: file = open(argv[f], 0); 52: 53: edf(file, fct); 54: 55: close(file); 56: } 57: flsh(0); 58: 59: exit(); 60: } 61: 62: int lno 1; 63: 64: edf(file, fct) 65: { 66: auto i,j,l; 67: extern lno,etext; 68: char brk,*buf,bufsp[150],line[150]; 69: char extern *sym[]; 70: 71: /* monitor(&main,&etext,&mbuf,1024); /*INSTR*/ 72: for(i = 0; i < fct; i++) 73: *sym[i] = 0200; 74: fields: 75: l = -1; 76: buf = &bufsp; 77: 78: for(i = 0; i < fct; ++i) { 79: buf--; 80: 81: swt: 82: 83: switch(*++buf = get(file)) { 84: 85: default: 86: if(esw && *buf >= 'A' && *buf <= 'Z' 87: && i == 0) 88: *buf =| 040; 89: goto swt; 90: 91: case -1: 92: *buf = ' '; 93: case '\t': 94: if(i == ig) continue; 95: brk = *buf; 96: *buf = '\0'; 97: buf = &bufsp; 98: if(comp(buf, sym[i])) { 99: if(esw && i == 0) { 100: line[0] = line[1] = '\t'; 101: l = 1; 102: goto rest; 103: } 104: line[++l] = '\t'; 105: continue; 106: } else { 107: copy(buf, sym[i]); 108: l =+ copy(buf, &line[++l]); 109: line[--l] = brk; 110: if(l < 8 && esw && i == 0) 111: line[++l] = '\t'; 112: j = i; 113: while(++j < fct) 114: *sym[j] = 0200; 115: continue; 116: } 117: 118: case '\n': 119: lno++; 120: brk = *buf; 121: *buf = '\0'; 122: buf = &bufsp; 123: if(comp(buf, sym[i])) { 124: goto fields; 125: } else { 126: copy(buf, sym[i]); 127: l =+ copy(buf, &line[++l]); 128: line[--l] = '\n'; 129: j = i; 130: while(++j < fct) 131: *sym[j] = 0; 132: goto out; 133: } 134: 135: case '\0': 136: goto fexit; 137: } 138: } 139: 140: rest: 141: while((line[++l] = get(file)) != '\n') 142: if(line[l] == '\0') goto fexit; 143: 144: lno++; 145: out: 146: if(*line != '\t') { 147: put(0,"\n",1); 148: lno++; 149: } 150: 151: put(0,line,++l); 152: 153: goto fields; 154: 155: fexit: 156: /* monitor(0); /*INSTR*/ 157: return(0); 158: 159: } 160: 161: 162: copy(a, b) 163: char *a,*b; 164: { 165: char *c; 166: 167: b--; 168: c = --a; 169: while(*++b = *++a); 170: return(a - c); 171: } 172: 173: comp(a, b) 174: char *a, *b; 175: { 176: /* printf("comp: %s %s\n",a,b); /*DEBUG*/ 177: a--; 178: b--; 179: while(*++a == *++b) { 180: if(*a == '\0') return(1); 181: } 182: return(0); 183: } 184: 185: 186: char buf[512]; 187: int nread 1; 188: 189: get(ifile) int ifile; 190: { 191: 192: char static *ibuf; 193: 194: if(--nread){ 195: return(*ibuf++); 196: } 197: 198: if(nread = read(ifile,buf,512)){ 199: if(nread < 0)goto err; 200: 201: ibuf = buf; 202: return(*ibuf++); 203: } 204: 205: nread = 1; 206: return(0); 207: 208: err: 209: nread = 1; 210: printf("read error\n"); 211: return(0); 212: 213: } 214: 215: 216: int tp[1] 1; 217: int optr[4]; 218: char bsp[512]; 219: 220: char *obuf[1] bsp; 221: 222: int nflush; 223: 224: put(fil,string,n) 225: char *string; 226: { 227: int i; 228: char *o; 229: 230: /*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/ 231: 232: string--; 233: 234: if((i = optr[fil] + n - 512) >= 0) { 235: n =- i; 236: o = &obuf[fil][optr[fil]] -1; 237: while(--n >= 0) 238: *++o = *++string; 239: optr[fil] = 512; 240: flsh(fil); 241: n = i; 242: } 243: 244: o = &obuf[fil][optr[fil]] - 1; 245: optr[fil] =+ n; 246: 247: while(--n >= 0) { 248: *++o = *++string; 249: } 250: return(0); 251: } 252: 253: flsh(fil) 254: { 255: extern tp[]; 256: 257: if(optr[fil] <= 0) return(optr[fil]); 258: 259: nflush++; 260: if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil]) 261: return(-1); 262: optr[fil] = 0; 263: return(0); 264: }