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

1.1     ! root        1: #include "stdio.h"
        !             2: #include "cbt.h"
        !             3: #define error(x, y) {fprintf(stderr, x, y); exit(1); }
        !             4: 
        !             5: int iflag, rflag;
        !             6: char node[NDSZ];
        !             7: char buf[512];
        !             8: extern char *malloc();
        !             9: 
        !            10: main(argc, argv)
        !            11: char **argv;
        !            12: {      int i, fd;
        !            13:        hdr *b;
        !            14:        char *p;
        !            15:        for(i = 1; i < argc; i++) {
        !            16:                if(argv[i][0] == '-') {
        !            17:                        for(p = argv[i] + 1; *p; p++)
        !            18:                                if(*p == 'i')
        !            19:                                        iflag = 1;
        !            20:                                else if(*p == 'r')
        !            21:                                        rflag = 1;
        !            22:                                else
        !            23:                                        error("unknown flag %c\n", *p);
        !            24:                        if(i >= argc - 1)
        !            25:                                error("file name?", 0);
        !            26:                        continue;
        !            27:                }
        !            28:                if(!iflag) {
        !            29:                        sprintf(buf, "%s.F", argv[i]);
        !            30:                        if((fd = creat(buf, 0666)) < 0) {
        !            31:                                perror(buf);
        !            32:                                exit(1);
        !            33:                        }
        !            34:                        close(fd);
        !            35:                }
        !            36:                sprintf(buf, "%s.T", argv[i]);
        !            37:                if((fd = creat(buf, 0666)) < 0) {
        !            38:                        perror(buf);
        !            39:                        if(!iflag) {
        !            40:                                sprintf(buf, "%s.F", argv[i]);
        !            41:                                unlink(buf);
        !            42:                        }
        !            43:                        exit(1);
        !            44:                }
        !            45:                b = (hdr *)node;
        !            46:                b->kcnt = 0;
        !            47:                if(iflag)
        !            48:                        b->htype |= INDEX;
        !            49:                if(rflag)
        !            50:                        b->htype |= READONLY;
        !            51:                nfree(b) = NDSZ - sizeof(hdr) - sizeof(trailer);
        !            52:                if(write(fd, node, NDSZ) != NDSZ)
        !            53:                        perror("failed");
        !            54:                close(fd);
        !            55:        }
        !            56:        exit(0);
        !            57: }
        !            58: static struct D { struct D *a; char *b;} VER = {&VER,"\n81/8/9:btcreat.c\n"};
        !            59: /*0011011101111110*/

unix.superglobalmegacorp.com

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