=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/Attic/apropos_db.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/mandoc/Attic/apropos_db.c 2011/11/17 14:52:32 1.5 --- src/usr.bin/mandoc/Attic/apropos_db.c 2011/11/17 15:38:27 1.6 *************** *** 1,4 **** ! /* $Id: apropos_db.c,v 1.5 2011/11/17 14:52:32 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze --- 1,4 ---- ! /* $Id: apropos_db.c,v 1.6 2011/11/17 15:38:27 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze *************** *** 19,24 **** --- 19,25 ---- #include #include #include + #include #include #include #include *************** *** 41,47 **** struct expr { int regex; int index; ! int mask; int and; char *v; regex_t re; --- 42,48 ---- struct expr { int regex; int index; ! uint64_t mask; int and; char *v; regex_t re; *************** *** 49,70 **** }; struct type { ! int mask; const char *name; }; static const struct type types[] = { { TYPE_An, "An" }, { TYPE_Cd, "Cd" }, { TYPE_Er, "Er" }, { TYPE_Ev, "Ev" }, { TYPE_Fn, "Fn" }, { TYPE_Fn, "Fo" }, { TYPE_In, "In" }, { TYPE_Nd, "Nd" }, { TYPE_Nm, "Nm" }, { TYPE_Pa, "Pa" }, { TYPE_St, "St" }, { TYPE_Va, "Va" }, { TYPE_Va, "Vt" }, { TYPE_Xr, "Xr" }, --- 50,96 ---- }; struct type { ! uint64_t mask; const char *name; }; static const struct type types[] = { { TYPE_An, "An" }, + { TYPE_Ar, "Ar" }, + { TYPE_At, "At" }, + { TYPE_Bsx, "Bsx" }, + { TYPE_Bx, "Bx" }, { TYPE_Cd, "Cd" }, + { TYPE_Cm, "Cm" }, + { TYPE_Dv, "Dv" }, + { TYPE_Dx, "Dx" }, + { TYPE_Em, "Em" }, { TYPE_Er, "Er" }, { TYPE_Ev, "Ev" }, + { TYPE_Fa, "Fa" }, + { TYPE_Fl, "Fl" }, { TYPE_Fn, "Fn" }, { TYPE_Fn, "Fo" }, + { TYPE_Ft, "Ft" }, + { TYPE_Fx, "Fx" }, + { TYPE_Ic, "Ic" }, { TYPE_In, "In" }, + { TYPE_Lb, "Lb" }, + { TYPE_Li, "Li" }, + { TYPE_Lk, "Lk" }, + { TYPE_Ms, "Ms" }, + { TYPE_Mt, "Mt" }, { TYPE_Nd, "Nd" }, { TYPE_Nm, "Nm" }, + { TYPE_Nx, "Nx" }, + { TYPE_Ox, "Ox" }, { TYPE_Pa, "Pa" }, + { TYPE_Rs, "Rs" }, + { TYPE_Sh, "Sh" }, + { TYPE_Ss, "Ss" }, { TYPE_St, "St" }, + { TYPE_Sy, "Sy" }, + { TYPE_Tn, "Tn" }, { TYPE_Va, "Va" }, { TYPE_Va, "Vt" }, { TYPE_Xr, "Xr" }, *************** *** 74,82 **** static DB *btree_open(void); static int btree_read(const DBT *, const struct mchars *, char **); ! static int exprexecpre(const struct expr *, const char *, int); static void exprexecpost(const struct expr *, ! const char *, int, int *, size_t); static struct expr *exprterm(char *, int, int); static DB *index_open(void); static int index_read(const DBT *, const DBT *, --- 100,108 ---- static DB *btree_open(void); static int btree_read(const DBT *, const struct mchars *, char **); ! static int exprexecpre(const struct expr *, const char *, uint64_t); static void exprexecpost(const struct expr *, ! const char *, uint64_t, int *, size_t); static struct expr *exprterm(char *, int, int); static DB *index_open(void); static int index_read(const DBT *, const DBT *, *************** *** 381,387 **** const struct expr *expr, size_t terms, struct mchars *mc) { ! int root, leaf, mask; DBT key, val; DB *btree, *idx; int ch; --- 407,413 ---- const struct expr *expr, size_t terms, struct mchars *mc) { ! int root, leaf; DBT key, val; DB *btree, *idx; int ch; *************** *** 389,394 **** --- 415,421 ---- recno_t rec; struct rec *recs; struct rec srec; + struct db_val *vbuf; root = -1; leaf = -1; *************** *** 412,433 **** * The key must have something in it, and the value must * have the correct tags/recno mix. */ ! if (key.size < 2 || 8 != val.size) break; if ( ! btree_read(&key, mc, &buf)) break; - mask = *(int *)val.data; - /* * See if this keyword record matches any of the * expressions we have stored. */ ! if ( ! exprexecpre(expr, buf, mask)) continue; - memcpy(&rec, val.data + 4, sizeof(recno_t)); - /* * O(log n) scan for prior records. Since a record * number is unbounded, this has decent performance over --- 439,458 ---- * The key must have something in it, and the value must * have the correct tags/recno mix. */ ! if (key.size < 2 || sizeof(struct db_val) != val.size) break; if ( ! btree_read(&key, mc, &buf)) break; /* * See if this keyword record matches any of the * expressions we have stored. */ ! vbuf = val.data; ! if ( ! exprexecpre(expr, buf, vbuf->mask)) continue; + rec = vbuf->rec; /* * O(log n) scan for prior records. Since a record * number is unbounded, this has decent performance over *************** *** 445,451 **** if (leaf >= 0 && recs[leaf].rec == rec) { if (0 == recs[leaf].matches[0]) exprexecpost ! (expr, buf, mask, recs[leaf].matches, terms); continue; } --- 470,476 ---- if (leaf >= 0 && recs[leaf].rec == rec) { if (0 == recs[leaf].matches[0]) exprexecpost ! (expr, buf, vbuf->mask, recs[leaf].matches, terms); continue; } *************** *** 478,484 **** mandoc_calloc(terms + 1, sizeof(int)); exprexecpost ! (expr, buf, mask, recs[tree->len].matches, terms); /* Append to our tree. */ --- 503,509 ---- mandoc_calloc(terms + 1, sizeof(int)); exprexecpost ! (expr, buf, vbuf->mask, recs[tree->len].matches, terms); /* Append to our tree. */ *************** *** 642,648 **** * Return 1 if any expression evaluates to true, else 0. */ static int ! exprexecpre(const struct expr *p, const char *cp, int mask) { for ( ; NULL != p; p = p->next) { --- 667,673 ---- * Return 1 if any expression evaluates to true, else 0. */ static int ! exprexecpre(const struct expr *p, const char *cp, uint64_t mask) { for ( ; NULL != p; p = p->next) { *************** *** 666,672 **** */ static void exprexecpost(const struct expr *e, const char *cp, ! int mask, int *matches, size_t matchsz) { const struct expr *p; int match; --- 691,697 ---- */ static void exprexecpost(const struct expr *e, const char *cp, ! uint64_t mask, int *matches, size_t matchsz) { const struct expr *p; int match;