int stopstop;
DB *globaldb;
+#if 0
void append __P((DB *, char **));
+#endif
+#ifdef STATISTICS
void bstat __P((DB *, char **));
+#endif
void cursor __P((DB *, char **));
void delcur __P((DB *, char **));
void delete __P((DB *, char **));
+#ifdef DEBUG
void dump __P((DB *, char **));
+#endif
void first __P((DB *, char **));
void get __P((DB *, char **));
void help __P((DB *, char **));
void keydata __P((DBT *, DBT *));
void last __P((DB *, char **));
void list __P((DB *, char **));
+#if 0
void load __P((DB *, char **));
+#endif
+#ifdef STATISTICS
void mstat __P((DB *, char **));
+#endif
void next __P((DB *, char **));
int parse __P((char *, char **, int));
void previous __P((DB *, char **));
+#ifdef DEBUG
void show __P((DB *, char **));
+#endif
+void rlist __P((DB *, char **));
void usage __P((void));
void user __P((DB *));
cmd_table commands[] = {
"?", 0, 0, help, "help", NULL,
+#if 0
"a", 2, 1, append, "append key def", "append key with data def",
+#endif
+#ifdef STATISTICS
"b", 0, 0, bstat, "bstat", "stat btree",
+#endif
"c", 1, 1, cursor, "cursor word", "move cursor to word",
"delc", 0, 0, delcur, "delcur", "delete key the cursor references",
"dele", 1, 1, delete, "delete word", "delete word",
+#ifdef DEBUG
"d", 0, 0, dump, "dump", "dump database",
+#endif
"f", 0, 0, first, "first", "move cursor to first record",
"g", 1, 1, get, "get key", "locate key",
"h", 0, 0, help, "help", "print command summary",
"in", 2, 1, insert, "insert key def", "insert key with data def",
"la", 0, 0, last, "last", "move cursor to last record",
"li", 1, 1, list, "list file", "list to a file",
+#if 0
"loa", 1, 0, load, "load file", NULL,
+#endif
"loc", 1, 1, get, "get key", NULL,
+#ifdef STATISTICS
"m", 0, 0, mstat, "mstat", "stat memory pool",
+#endif
"n", 0, 0, next, "next", "move cursor forward one record",
"p", 0, 0, previous, "previous", "move cursor back one record",
"q", 0, 0, NULL, "quit", "quit",
+ "rli", 1, 1, rlist, "rlist file", "list to a file (recursive)",
+#ifdef DEBUG
"sh", 1, 0, show, "show page", "dump a page",
+#endif
{ NULL },
};
char **argv;
{
int c;
+ int omode;
DB *db;
BTREEINFO b;
progname = *argv;
+ omode = O_RDONLY;
b.flags = 0;
b.cachesize = 0;
b.maxkeypage = 0;
b.prefix = NULL;
b.lorder = 0;
- while ((c = getopt(argc, argv, "bc:di:lp:ru")) != -1) {
+ while ((c = getopt(argc, argv, "bc:di:lp:ruw")) != -1) {
switch (c) {
case 'b':
- b.lorder = BIG_ENDIAN;
+ b.lorder = DB_BIG_ENDIAN;
break;
case 'c':
b.cachesize = atoi(optarg);
dict = optarg;
break;
case 'l':
- b.lorder = LITTLE_ENDIAN;
+ b.lorder = DB_LITTLE_ENDIAN;
break;
case 'p':
b.psize = atoi(optarg);
case 'u':
b.flags = 0;
break;
+ case 'w':
+ omode = O_RDWR;
+ break;
default:
usage();
}
argv += optind;
if (recno)
- db = dbopen(*argv == NULL ? NULL : *argv, O_RDWR|O_BINARY,
+ db = dbopen(*argv == NULL ? NULL : *argv, omode|O_BINARY,
0, DB_RECNO, NULL);
else
- db = dbopen(*argv == NULL ? NULL : *argv, O_CREAT|O_RDWR|O_BINARY,
+ db = dbopen(*argv == NULL ? NULL : *argv, O_CREAT|omode|O_BINARY,
0600, DB_BTREE, &b);
if (db == NULL) {
uselast: last = i;
(*commands[i].func)(db, argv);
}
- if ((db->sync)(db) == RET_ERROR)
+ if ((db->sync)(db, 0) == RET_ERROR)
perror("dbsync");
else if ((db->close)(db) == RET_ERROR)
perror("dbclose");
return (argc);
}
+#if 0
void
append(db, argv)
DB *db;
break;
}
}
+#endif
void
cursor(db, argv)
}
}
+#ifdef DEBUG
void
dump(db, argv)
DB *db;
{
__bt_dump(db);
}
+#endif
void
first(db, argv)
(void)fprintf(fp, "%s\n", key.data);
status = (*db->seq)(db, &key, &data, R_NEXT);
}
+ (void)fclose(fp);
+ if (status == RET_ERROR)
+ perror("list/seq");
+}
+
+void
+rlist(db, argv)
+ DB *db;
+ char **argv;
+{
+ DBT data, key;
+ FILE *fp;
+ int status;
+ void *cookie;
+
+ cookie = NULL;
+ if ((fp = fopen(argv[1], "w")) == NULL) {
+ (void)fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
+ return;
+ }
+ status = bt_rseq(db, &key, &data, &cookie, R_FIRST);
+ while (status == RET_SUCCESS) {
+ (void)fprintf(fp, "%s\n", key.data);
+ status = bt_rseq(db, &key, &data, &cookie, R_NEXT);
+ }
+ (void)fclose(fp);
if (status == RET_ERROR)
perror("list/seq");
}
+#if 0
DB *BUGdb;
void
load(db, argv)
}
(void)fclose(fp);
}
+#endif
void
next(db, argv)
}
}
+#ifdef DEBUG
void
show(db, argv)
DB *db;
if (pg == 0)
__bt_dmpage(h);
else
- __bt_dpage(h);
+ __bt_dpage(db, h);
mpool_put(t->bt_mp, h, 0);
}
+#endif
+#ifdef STATISTICS
void
bstat(db, argv)
DB *db;
(void)printf("MPOOL\n");
mpool_stat(((BTREE *)db->internal)->bt_mp);
}
+#endif
void
keydata(key, data)
usage()
{
(void)fprintf(stderr,
- "usage: %s [-bdlu] [-c cache] [-i file] [-p page] [file]\n",
+ "usage: %s [-bdluw] [-c cache] [-i file] [-p page] [file]\n",
progname);
exit (1);
}