|
|
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: char dest[FNAMELEN];
12:
13: main(argc, argv)
14: char **argv;
15: {
16: int oflag = 0;
17:
18: dest[0] = 0;
19: if(argc > 2){
20: if(strncmp(argv[1], "-o", 2))
21: goto usage;
22: strcpy(dest, &argv[1][2]);
23: argv[1] = argv[2];
24: argc--;
25: oflag = 1;
26: }
27: if(argc != 2) {
28: usage:
29: fprintf(stderr, "usage; %s [-odest] file-name\n", argv[0]);
30: exit(1);
31: }
32: if(dest[0] == 0)
33: sprintf(dest, "TS%d", getpid());
34: bfd = bopen(argv[1], 0);
35: if(bfd == NULL)
36: fail(argv[1]);
37: strcpy(vbuf, "cbt creat ");
38: if(bfd->path[0]->htype & INDEX) {
39: iflag = 1;
40: strcat(vbuf, "-i ");
41: }
42: if(bfd->path[0]->htype & READONLY) {
43: rflag = 1;
44: strcat(vbuf, "-r");
45: }
46: sprintf(kbuf, "%s %s", vbuf, dest);
47: if(system(kbuf) != 0) {
48: fprintf(stderr, "%s failed\n", kbuf);
49: exit(1);
50: }
51: sprintf(kbuf, "cbt build -r %s", dest);
52: pfd = popen(kbuf, "w");
53: if(pfd == NULL)
54: fail(kbuf);
55: key.mdata = kbuf;
56: value.mdata = vbuf;
57: errno = 0;
58: while(bread(bfd, &key, &value) != EOF) {
59: (void) fwrite((char *)&key.mlen, 1, sizeof(key.mlen), pfd);
60: (void) fwrite(key.mdata, 1, key.mlen, pfd);
61: (void) fwrite((char *)&value.mlen, 1, sizeof(value.mlen), pfd);
62: (void) fwrite(value.mdata, 1, value.mlen, pfd);
63: if(ferror(pfd))
64: fail("write to build");
65: }
66: if(errno)
67: fail("extracting");
68: if(pclose(pfd) != 0)
69: fail("pipe close");
70: if(oflag == 0){
71: sprintf(kbuf, "%s.T", argv[1]);
72: sprintf(vbuf, "TS%d.T", getpid());
73: unlink(kbuf);
74: link(vbuf, kbuf);
75: if(iflag)
76: exit(0);
77: sprintf(kbuf, "%s.F", argv[1]);
78: sprintf(vbuf, "TS%d.F", getpid());
79: unlink(kbuf);
80: link(vbuf, kbuf);
81: if(errno)
82: perror("linking");
83: }
84: exit(0);
85: }
86:
87: fail(s)
88: char *s;
89: {
90: perror(s);
91: exit(2);
92: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.