=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/Attic/apropos_db.c,v retrieving revision 1.11 retrieving revision 1.12 diff -c -r1.11 -r1.12 *** src/usr.bin/mandoc/Attic/apropos_db.c 2011/11/29 22:30:56 1.11 --- src/usr.bin/mandoc/Attic/apropos_db.c 2011/12/03 14:53:12 1.12 *************** *** 1,4 **** ! /* $Id: apropos_db.c,v 1.11 2011/11/29 22:30:56 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze --- 1,4 ---- ! /* $Id: apropos_db.c,v 1.12 2011/12/03 14:53:12 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze *************** *** 15,20 **** --- 15,21 ---- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include #include #include #include *************** *** 114,121 **** }; static DB *btree_open(void); ! static int btree_read(const DBT *, ! const struct mchars *, char **); static int expreval(const struct expr *, int *); static void exprexec(const struct expr *, const char *, uint64_t, struct rec *); --- 115,123 ---- }; static DB *btree_open(void); ! static int btree_read(const DBT *, const DBT *, ! const struct mchars *, ! struct db_val *, char **); static int expreval(const struct expr *, int *); static void exprexec(const struct expr *, const char *, uint64_t, struct rec *); *************** *** 144,149 **** --- 146,152 ---- DB *db; memset(&info, 0, sizeof(BTREEINFO)); + info.lorder = 4321; info.flags = R_DUP; db = dbopen(MANDOC_DB, O_RDONLY, 0, DB_BTREE, &info); *************** *** 158,174 **** * Return 0 if the database is insane, else 1. */ static int ! btree_read(const DBT *v, const struct mchars *mc, char **buf) { ! /* Sanity: are we nil-terminated? */ ! assert(v->size > 0); ! ! if ('\0' != ((char *)v->data)[(int)v->size - 1]) return(0); ! norm_string((char *)v->data, mc, buf); return(1); } --- 161,184 ---- * Return 0 if the database is insane, else 1. */ static int ! btree_read(const DBT *k, const DBT *v, ! const struct mchars *mc, ! struct db_val *dbv, char **buf) { + const struct db_val *vp; ! /* Are our sizes sane? */ ! if (k->size < 2 || sizeof(struct db_val) != v->size) ! return(0); ! /* Is our string nil-terminated? */ ! if ('\0' != ((const char *)k->data)[(int)k->size - 1]) return(0); ! vp = v->data; ! norm_string((const char *)k->data, mc, buf); ! dbv->rec = betoh32(vp->rec); ! dbv->mask = betoh64(vp->mask); return(1); } *************** *** 442,455 **** struct mchars *mc, int vol) { int root, leaf, ch; - uint64_t mask; DBT key, val; DB *btree, *idx; char *buf; - recno_t rec; struct rec *rs; struct rec r; ! struct db_val *vbuf; root = -1; leaf = -1; --- 452,463 ---- struct mchars *mc, int vol) { int root, leaf, ch; DBT key, val; DB *btree, *idx; char *buf; struct rec *rs; struct rec r; ! struct db_val vb; root = -1; leaf = -1; *************** *** 469,488 **** } while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { ! if (key.size < 2 || sizeof(struct db_val) != val.size) break; - if ( ! btree_read(&key, mc, &buf)) - break; - vbuf = val.data; - rec = vbuf->rec; - mask = vbuf->mask; - /* * See if this keyword record matches any of the * expressions we have stored. */ ! if ( ! exprmark(expr, buf, mask, NULL)) continue; /* --- 477,490 ---- } while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { ! if ( ! btree_read(&key, &val, mc, &vb, &buf)) break; /* * See if this keyword record matches any of the * expressions we have stored. */ ! if ( ! exprmark(expr, buf, vb.mask, NULL)) continue; /* *************** *** 492,501 **** */ for (leaf = root; leaf >= 0; ) ! if (rec > rs[leaf].res.rec && rs[leaf].rhs >= 0) leaf = rs[leaf].rhs; ! else if (rec < rs[leaf].res.rec && rs[leaf].lhs >= 0) leaf = rs[leaf].lhs; else --- 494,503 ---- */ for (leaf = root; leaf >= 0; ) ! if (vb.rec > rs[leaf].res.rec && rs[leaf].rhs >= 0) leaf = rs[leaf].rhs; ! else if (vb.rec < rs[leaf].res.rec && rs[leaf].lhs >= 0) leaf = rs[leaf].lhs; else *************** *** 507,515 **** * try to evaluate it now and continue anyway. */ ! if (leaf >= 0 && rs[leaf].res.rec == rec) { if (0 == rs[leaf].matched) ! exprexec(expr, buf, mask, &rs[leaf]); continue; } --- 509,517 ---- * try to evaluate it now and continue anyway. */ ! if (leaf >= 0 && rs[leaf].res.rec == vb.rec) { if (0 == rs[leaf].matched) ! exprexec(expr, buf, vb.mask, &rs[leaf]); continue; } *************** *** 519,525 **** * database, then begin partial evaluation. */ ! key.data = &rec; key.size = sizeof(recno_t); if (0 != (*idx->get)(idx, &key, &val, 0)) --- 521,527 ---- * database, then begin partial evaluation. */ ! key.data = &vb.rec; key.size = sizeof(recno_t); if (0 != (*idx->get)(idx, &key, &val, 0)) *************** *** 543,554 **** rs[tree->len].matches = mandoc_calloc(terms, sizeof(int)); ! exprexec(expr, buf, mask, &rs[tree->len]); /* Append to our tree. */ if (leaf >= 0) { ! if (rec > rs[leaf].res.rec) rs[leaf].rhs = tree->len; else rs[leaf].lhs = tree->len; --- 545,556 ---- rs[tree->len].matches = mandoc_calloc(terms, sizeof(int)); ! exprexec(expr, buf, vb.mask, &rs[tree->len]); /* Append to our tree. */ if (leaf >= 0) { ! if (vb.rec > rs[leaf].res.rec) rs[leaf].rhs = tree->len; else rs[leaf].lhs = tree->len; *************** *** 570,575 **** --- 572,578 ---- recfree(struct rec *rec) { + free(rec->res.type); free(rec->res.file); free(rec->res.cat); free(rec->res.title);