=================================================================== RCS file: /cvs/mandoc/Attic/makewhatis.c,v retrieving revision 1.6 retrieving revision 1.9 diff -u -p -r1.6 -r1.9 --- mandoc/Attic/makewhatis.c 2011/06/21 14:16:05 1.6 +++ mandoc/Attic/makewhatis.c 2011/06/22 09:10:36 1.9 @@ -1,4 +1,4 @@ -/* $Id: makewhatis.c,v 1.6 2011/06/21 14:16:05 kristaps Exp $ */ +/* $Id: makewhatis.c,v 1.9 2011/06/22 09:10:36 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -241,7 +241,7 @@ main(int argc, char *argv[]) *db, /* keyword database */ *hash; /* temporary keyword hashtable */ DBT key, val; - size_t sv, rsz; + size_t sv; BTREEINFO info; /* btree configuration */ recno_t rec; /* current record number */ struct buf buf, /* keyword buffer */ @@ -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); } @@ -345,7 +335,7 @@ main(int argc, char *argv[]) mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); rec = 1; - rsz = 0; + hash = NULL; memset(&buf, 0, sizeof(struct buf)); memset(&dbuf, 0, sizeof(struct buf)); @@ -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) { @@ -416,16 +416,18 @@ main(int argc, char *argv[]) seq = R_FIRST; while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) { + seq = R_NEXT; + memcpy(vbuf, val.data, sizeof(uint32_t)); 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); - if ((*hash->del)(hash, &key, 0) < 0) { - perror("hash"); - exit((int)MANDOCLEVEL_SYSERR); - } - seq = R_NEXT; } if (ch < 0) { @@ -447,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); @@ -746,11 +751,12 @@ hash_put(DB *db, const struct buf *buf, int mask) DBT key, val; int rc; - key.data = buf->cp; - - if ((key.size = buf->len) < 2) + if (buf->len < 2) return; + key.data = buf->cp; + key.size = buf->len; + if ((rc = (*db->get)(db, &key, &val, 0)) < 0) { perror("hash"); exit((int)MANDOCLEVEL_SYSERR); @@ -760,9 +766,6 @@ hash_put(DB *db, const struct buf *buf, int mask) val.data = &mask; val.size = sizeof(int); - /*fprintf(stderr, "Hashing: [%s] (0x%x)\n", - (char *)key.data, mask);*/ - if ((rc = (*db->put)(db, &key, &val, 0)) < 0) { perror("hash"); exit((int)MANDOCLEVEL_SYSERR); @@ -772,9 +775,6 @@ hash_put(DB *db, const struct buf *buf, int mask) static void dbt_put(DB *db, const char *dbn, DBT *key, DBT *val) { - - if (0 == key->size) - return; assert(key->size); assert(val->size);