summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-06-22 09:00:14 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-06-22 09:00:14 +0000
commit18796304f4f56bfb405d7b579eb9da2a7b547395 (patch)
tree09e12b2c75b4c8684969e5a7d2518b906cc92657
parentab1fd909bf6f9416911e5d92f01adf299d376de7 (diff)
downloadmandoc-18796304f4f56bfb405d7b579eb9da2a7b547395.tar.gz
mandoc-18796304f4f56bfb405d7b579eb9da2a7b547395.tar.zst
mandoc-18796304f4f56bfb405d7b579eb9da2a7b547395.zip
Try again to get the transfer from hash to btree working. This time
just closing and re-opening the database, as deleting records with (*hash->del) either in the scan loop or after it causes uncertain behaviour (left-over keys, mystery keys, etc.). This finally does the Right Thing (tm).
-rw-r--r--makewhatis.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/makewhatis.c b/makewhatis.c
index 433dfcbb..122f5f8f 100644
--- a/makewhatis.c
+++ b/makewhatis.c
@@ -1,4 +1,4 @@
-/* $Id: makewhatis.c,v 1.7 2011/06/21 23:37:27 kristaps Exp $ */
+/* $Id: makewhatis.c,v 1.8 2011/06/22 09:00:14 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -306,23 +306,14 @@ main(int argc, char *argv[])
* For the keyword database, open a BTREE database that allows
* duplicates.
* For the index database, use a standard RECNO database type.
- * For the temporary keyword hashtable, use the HASH database
- * type.
*/
- hash = dbopen(NULL, MANDOC_FLAGS, 0644, DB_HASH, NULL);
- if (NULL == hash) {
- perror("hash");
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
memset(&info, 0, sizeof(BTREEINFO));
info.flags = R_DUP;
db = dbopen(fbbuf, MANDOC_FLAGS, 0644, DB_BTREE, &info);
if (NULL == db) {
perror(fbbuf);
- (*hash->close)(hash);
exit((int)MANDOCLEVEL_SYSERR);
}
@@ -331,7 +322,6 @@ main(int argc, char *argv[])
if (NULL == db) {
perror(ibbuf);
(*db->close)(db);
- (*hash->close)(hash);
exit((int)MANDOCLEVEL_SYSERR);
}
@@ -358,6 +348,16 @@ main(int argc, char *argv[])
while (NULL != (fn = *argv++)) {
mparse_reset(mp);
+ if (hash)
+ (*hash->close)(hash);
+
+ hash = dbopen(NULL, MANDOC_FLAGS, 0644, DB_HASH, NULL);
+
+ if (NULL == hash) {
+ perror("hash");
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+
/* Parse and get (non-empty) AST. */
if (mparse_readfd(mp, -1, fn) >= MANDOCLEVEL_FATAL) {
@@ -422,11 +422,12 @@ main(int argc, char *argv[])
val.size = sizeof(vbuf);
val.data = vbuf;
+ printf("Added: %s (%zu): 0x%x\n",
+ (char *)key.data, key.size,
+ *(int *)val.data);
+
dbt_put(db, fbbuf, &key, &val);
- ch = (*hash->del)(hash, &key, R_CURSOR);
- if (ch < 0)
- break;
}
if (ch < 0) {
@@ -448,13 +449,16 @@ main(int argc, char *argv[])
val.data = dbuf.cp;
val.size = dbuf.len;
+ printf("Indexed: %s\n", fn);
+
dbt_put(idx, ibbuf, &key, &val);
rec++;
}
(*db->close)(db);
(*idx->close)(idx);
- (*hash->close)(hash);
+ if (hash)
+ (*hash->close)(hash);
mparse_free(mp);
@@ -772,9 +776,6 @@ static void
dbt_put(DB *db, const char *dbn, DBT *key, DBT *val)
{
- if (0 == key->size)
- return;
-
assert(key->size);
assert(val->size);