|
|
1.1 ! root 1: #include "stdio.h" ! 2: #define MAX 8192 ! 3: char tab = '\t'; ! 4: char *line, *oline; ! 5: char abuf[MAX], bbuf[MAX]; ! 6: int cnt, ocnt; ! 7: main() ! 8: { long lcnt = 0; ! 9: line = abuf; ! 10: oline = bbuf; ! 11: for(; !feof(stdin); ) { ! 12: lcnt++; ! 13: (void) fgets(line, MAX, stdin); ! 14: if(feof(stdin)) cnt = 0; ! 15: else cnt = strlen(line); ! 16: if(cnt >= MAX-1) { ! 17: fprintf(stderr, "line %ld too long\n", lcnt); ! 18: cnt = 0; ! 19: } ! 20: output(); ! 21: } ! 22: exit(0); ! 23: } ! 24: output() ! 25: { unsigned short u; ! 26: char *p; ! 27: if(ocnt <= 1) { /* oline was used to give ooline a newline */ ! 28: swtch(); ! 29: return; ! 30: } ! 31: if(cnt != 1) /* line isnt a newline to be added to oline */ ! 32: oline[--ocnt] = 0; ! 33: else oline[ocnt] = 0; ! 34: for(p = oline; *p && *p != tab; p++) ! 35: if(*p == '\n') break; ! 36: u = p - oline; ! 37: (void) fwrite((char *)&u, 1, sizeof(u), stdout); ! 38: (void) fwrite(oline, (int)u, 1, stdout); ! 39: if(*p == tab) ! 40: p++; ! 41: if(oline + ocnt - p < 0) ! 42: u = 0; ! 43: else u = oline + ocnt - p; ! 44: (void) fwrite((char *)&u, 1, sizeof(u), stdout); ! 45: (void) fwrite(p, (int)u, 1, stdout); ! 46: swtch(); ! 47: } ! 48: swtch() ! 49: { char *x; ! 50: x = line; ! 51: line = oline; ! 52: oline = x; ! 53: ocnt = cnt; ! 54: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.