From 18796304f4f56bfb405d7b579eb9da2a7b547395 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 22 Jun 2011 09:00:14 +0000 Subject: 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). --- makewhatis.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'makewhatis.c') 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 * @@ -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); -- cgit v1.2.3-56-ge451