Annotation of researchv10no/cmd/btree/btran.c, revision 1.1.1.1

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:        u = p - oline;
                     36:        (void) fwrite((char *)&u, 1, sizeof(u), stdout);
                     37:        (void) fwrite(oline, (int)u, 1, stdout);
                     38:        if(*p == tab)
                     39:                p++;
                     40:        if(oline + ocnt - p < 0)
                     41:                u = 0;
                     42:        else u = oline + ocnt - p;
                     43:        (void) fwrite((char *)&u, 1, sizeof(u), stdout);
                     44:        (void) fwrite(p, (int)u, 1, stdout);
                     45:        swtch();
                     46: }
                     47: swtch()
                     48: {      char *x;
                     49:        x = line;
                     50:        line = oline;
                     51:        oline = x;
                     52:        ocnt = cnt;
                     53: }
                     54: static char VER[] = "\n80/2/13:btran.c\n";
                     55: /*1111100011110011*/

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.