Annotation of researchv10no/libcbt/slvg.c, revision 1.1.1.1

1.1       root        1: #include "stdio.h"
                      2: /* change the output of btsalvage or btcat -R to sortable */
                      3: /* an 8 byte sortable sequence number is appended to each key
                      4:  * that slvg2 can keep only the last record with a given key */
                      5: 
                      6: char *buf;
                      7: int buflen;
                      8: long reccnt;
                      9: extern char *malloc(), *realloc();
                     10: 
                     11: main()
                     12: {      int n, i, j;
                     13:        for(;;) {
                     14:                if(read(0, &n, 2) == 0)
                     15:                        exit(0);
                     16:                if(n > buflen)
                     17:                        space(n);
                     18:                read(0, buf, n);
                     19:                reccnt++;
                     20:                out(buf, n, '\t');
                     21:                countout();
                     22:                read(0, &n, 2);
                     23:                if(n > buflen)
                     24:                        space(n);
                     25:                read(0, buf, n);
                     26:                j = n;
                     27:                for(i = 0; i < 4; i++) {
                     28:                        putchar('a' + (j & 0xf));
                     29:                        j >>= 4;
                     30:                }
                     31:                out(buf, n, '\n');
                     32:        }
                     33: }
                     34: 
                     35: space(n)
                     36: {
                     37:        while(n > buflen) {
                     38:                if(buflen == 0)
                     39:                        buf = malloc(buflen = 1024);
                     40:                else
                     41:                        buf = realloc(buf, buflen += 1024);
                     42:                if(buf == 0) {
                     43:                        fprintf(stderr, "buf[%d]failed\n", buflen);
                     44:                        exit(1);
                     45:                }
                     46:                
                     47:        }
                     48: }
                     49: 
                     50: out(s, n, c)
                     51: char *s;
                     52: {
                     53:        while(n-- > 0) {
                     54:                putchar('3' + ((*s >> 6) & 3));
                     55:                putchar((*s & 077) + ' ');
                     56:                s++;
                     57:        }
                     58:        putchar(c);
                     59: }
                     60: 
                     61: countout()
                     62: {      int i, n;
                     63:        n = reccnt;
                     64:        for(i = 7; i >= 0; i--)
                     65:                putchar('0' + ((n >> (4*i)) & 077));
                     66: }

unix.superglobalmegacorp.com

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