home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
BTREE.ZIP
/
BTDUMP.C
< prev
next >
Wrap
Text File
|
1989-08-31
|
3KB
|
141 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "btdump.c 1.1 - 89/07/03" */
#include <blkio.h>
#include <errno.h>
/* #include <stdlib.h> */
#define EXIT_SUCCESS 0 /* delete if you have stdlib.h */
#define EXIT_FAILURE 1
#include "btree_.h"
int cmp(/* void *buf1, void *buf2, size_t count */);
#define USAGE ("Usage: btdump filename")
/*man---------------------------------------------------------------------------
NAME
btdump - dump contents of a btree
SYNOPSIS
btdump filename
DESCRIPTION
The btdump command dumps the contents of btree file. The contents
of the header are displayed, followed by each individual node (in
preorder).
SEE ALSO
bta, btlist, btree.
NOTES
btdump is written for btrees sorted using the strncmp function. To
use it with with keys of a different type, modify the cmp function
in the file btdump.c.
------------------------------------------------------------------------------*/
int main(argc, argv)
int argc;
char *argv[];
{
int rs = 0;
btree_t * btp = NULL;
/* process command line arguments */
if (argc != 2) {
printf("%s\n", USAGE);
bexit(EXIT_FAILURE);
}
/* open btree */
btp = btopen(argv[1], "r", cmp);
if (btp == NULL) {
printf("*** Error opening btree. Error code %d.\n", errno);
bexit(EXIT_FAILURE);
}
/* lock btree */
rs = btlock(btp, BT_RDLKW);
if (rs == -1) {
printf("*** Error locking btree. Error code %d.\n", errno);
bexit(EXIT_FAILURE);
}
printf("HEADER:\n");
bt_dgbtree(btp);
rs = btdump(btp, btp->bthdr.root);
if (rs == -1) {
BTEPRINT;
bexit(EXIT_FAILURE);
}
/* unlock btree */
rs = btlock(btp, BT_UNLCK);
if (rs == -1) {
printf("*** Error unlocking btree. Error code %d.\n", errno);
bexit(EXIT_FAILURE);
}
/* close btree */
if (btclose(btp) == -1) {
printf("*** Error closing btree. Error code %d.\n", errno);
bexit(EXIT_FAILURE);
}
bexit(EXIT_SUCCESS);
}
int btdump(btp, node)
btree_t *btp;
bpos_t node;
{
int rs = 0;
int i = 0;
btnode_t * btnp = NULL;
if (node == 0) {
return 0;
}
/* read in node and display it */
btnp = bt_ndalloc(btp);
if (btnp == NULL) {
BTEPRINT;
return -1;
}
rs = bt_ndget(btp, node, btnp);
if (rs == -1) {
BTEPRINT;
bt_ndfree(btnp);
return -1;
}
printf("NODE POSITION: %ld.\n", node);
bt_dgnode(btp, btnp);
printf("\n");
for (i = 0; (i < btp->bthdr.m); i++) {
rs = btdump(btp, *bt_kychild_p(btnp, i));
if (rs == -1) {
bt_ndfree(btnp);
return -1;
}
}
bt_ndfree(btnp);
btnp = NULL;
return 0;
}
/* comparison function */
int cmp(buf1, buf2, count)
void *buf1;
void *buf2;
size_t count;
{
return strncmp((char *)buf1, (char *)buf2, count);
}