diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-06-22 09:00:14 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-06-22 09:00:14 +0000 |
commit | 5044bcecea06e3f7270ba8a751e95bd8b209d957 (patch) | |
tree | 0ded93b440d7c3a5a587e40572ad66fa6cb1dfbc /makewhatis.c | |
parent | 4def41caaee51f9c08eab6ff3c620779f1255460 (diff) | |
download | mandoc-5044bcecea06e3f7270ba8a751e95bd8b209d957.tar.gz |
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).
Diffstat (limited to 'makewhatis.c')
-rw-r--r-- | makewhatis.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/makewhatis.c b/makewhatis.c index 363182d9..60b32589 100644 --- a/makewhatis.c +++ b/makewhatis.c @@ -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); |