Annotation of researchv10no/cmd/btree/btsquash.c, revision 1.1

1.1     ! root        1: #include "stdio.h"
        !             2: #include "cbt.h"
        !             3: 
        !             4: extern int errno;
        !             5: mbuf key, value;
        !             6: char kbuf[NDSZ], vbuf[32767];
        !             7: bfile *bfd;
        !             8: FILE *pfd;
        !             9: extern FILE *popen();
        !            10: char iflag, rflag;
        !            11: 
        !            12: main(argc, argv)
        !            13: char **argv;
        !            14: {
        !            15:        if(argc != 2) {
        !            16:                fprintf(stderr, "usage; %s file-name\n", argv[0]);
        !            17:                exit(1);
        !            18:        }
        !            19:        bfd = bopen(argv[1], 0);
        !            20:        if(bfd == NULL)
        !            21:                fail(argv[1]);
        !            22:        strcpy(vbuf, "cbt creat ");
        !            23:        if(bfd->path[0]->htype & INDEX) {
        !            24:                iflag = 1;
        !            25:                strcat(vbuf, "-i ");
        !            26:        }
        !            27:        if(bfd->path[0]->htype & READONLY) {
        !            28:                rflag = 1;
        !            29:                strcat(vbuf, "-r");
        !            30:        }
        !            31:        sprintf(kbuf, "%s TS%d", vbuf, getpid());
        !            32:        if(system(kbuf) != 0) {
        !            33:                fprintf(stderr, "%s failed\n", kbuf);
        !            34:                exit(1);
        !            35:        }
        !            36:        /* this refers to the installed version? */
        !            37:        sprintf(kbuf, "cbt build -r TS%d", getpid());
        !            38:        pfd = popen(kbuf, "w");
        !            39:        if(pfd == NULL)
        !            40:                fail(kbuf);
        !            41:        key.mdata = kbuf;
        !            42:        value.mdata = vbuf;
        !            43:        errno = 0;
        !            44:        while(bread(bfd, &key, &value) != EOF) {
        !            45:                (void) fwrite((char *)&key.mlen, 1, sizeof(key.mlen), pfd);
        !            46:                (void) fwrite(key.mdata, 1, key.mlen, pfd);
        !            47:                (void) fwrite((char *)&value.mlen, 1, sizeof(value.mlen), pfd);
        !            48:                (void) fwrite(value.mdata, 1, value.mlen, pfd);
        !            49:                if(ferror(pfd))
        !            50:                        fail("write to build");
        !            51:        }
        !            52:        if(errno)
        !            53:                fail("extracting");
        !            54:        if(pclose(pfd) != 0)
        !            55:                fail("pipe close");
        !            56:        sprintf(kbuf, "%s.T", argv[1]);
        !            57:        sprintf(vbuf, "TS%d.T", getpid());
        !            58:        unlink(kbuf);
        !            59:        link(vbuf, kbuf);
        !            60:        if(iflag)
        !            61:                exit(0);
        !            62:        sprintf(kbuf, "%s.F", argv[1]);
        !            63:        sprintf(vbuf, "TS%d.F", getpid());
        !            64:        unlink(kbuf);
        !            65:        link(vbuf, kbuf);
        !            66:        if(errno)
        !            67:                perror("linking");
        !            68:        exit(0);
        !            69: }
        !            70: 
        !            71: fail(s)
        !            72: char *s;
        !            73: {
        !            74:        perror(s);
        !            75:        exit(2);
        !            76: }
        !            77: static struct D { struct D *a; char *b;} VER = {&VER,"\n81/4/26:btsquash.c\n"};
        !            78: /*0100011001101001*/

unix.superglobalmegacorp.com

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