|
|
1.1 ! root 1: #include "stdio.h" ! 2: #include "cbt.h" ! 3: #include "sys/types.h" ! 4: #include "sys/stat.h" ! 5: extern bfile *bopen(); ! 6: ! 7: long ndcnt[MXHT + 1]; ! 8: long frcnt, reccnt, reclen; ! 9: bfile *bt; ! 10: ! 11: main(argc, argv) ! 12: char **argv; ! 13: { int i, j; ! 14: for(i = 1; i < argc; i++) { ! 15: doarg(argv[i]); ! 16: for(j = 0; j <= MXHT; j++) ! 17: ndcnt[j] = 0; ! 18: frcnt = reccnt = reclen = 0; ! 19: if(i+1 < argc) ! 20: putchar('\n'); ! 21: } ! 22: exit(0); ! 23: } ! 24: ! 25: doarg(s) ! 26: char *s; ! 27: { struct stat statbuf; ! 28: long x; ! 29: int i; ! 30: bt = bopen(s, 0); ! 31: if(bt == NULL) { ! 32: i = strlen(s); ! 33: if(s[i-2] == '.') { ! 34: s[i-2] = 0; ! 35: if(s[i-1] == 'F') ! 36: return; ! 37: if(s[i-1] == 'T') ! 38: bt = bopen(s, 0); ! 39: } ! 40: if(bt == NULL) { ! 41: perror(s); ! 42: return; ! 43: } ! 44: } ! 45: fstat(bt->tfd, &statbuf); ! 46: printf("%s.T %ld bytes", s, statbuf.st_size); ! 47: if(bt->dfd > 0 && fstat(bt->dfd, &statbuf) == 0) ! 48: printf(", %s.F %ld bytes", s, statbuf.st_size); ! 49: putchar('\n'); ! 50: donode((ndaddr)0); ! 51: for(x = i = 0; i <= MXHT; i++) ! 52: x += ndcnt[i] * NDSZ; ! 53: printf("%ld bytes used in tree\n", x); ! 54: for(i = 0; i <= bt->height; i++) ! 55: printf(" %ld nodes at level %d", ndcnt[i], i); ! 56: printf("\n%ld bytes free\n", frcnt); ! 57: printf("%ld records totalling %ld bytes\n", reccnt, reclen); ! 58: bclose(bt); ! 59: } ! 60: ! 61: /* this routine believes the tree is well-formed */ ! 62: donode(n) ! 63: ndaddr n; ! 64: { char buf[NDSZ]; ! 65: hdr *b = (hdr *)buf; ! 66: int i; ! 67: (void) lseek(bt->tfd, (long)NDSZ * n, 0); ! 68: i = read(bt->tfd, buf, NDSZ); ! 69: if(i != NDSZ) { ! 70: printf("btreport: attempt to read node %d failed\n", n); ! 71: perror("breport"); ! 72: exit(1); ! 73: } ! 74: ndcnt[b->hlev]++; ! 75: frcnt += nfree(b); ! 76: if(b->hlev) ! 77: for(i = 0; i <= b->kcnt; i++) ! 78: donode(*ndadr(b, i)); ! 79: else ! 80: for(i = 0; i < b->kcnt; i++) { ! 81: reccnt++; ! 82: if(!(b->htype & INDEX)) ! 83: reclen += lfadr(b, i)->llen; ! 84: } ! 85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.