=================================================================== RCS file: /cvs/mandoc/Attic/apropos_db.c,v retrieving revision 1.9 retrieving revision 1.11 diff -u -p -r1.9 -r1.11 --- mandoc/Attic/apropos_db.c 2011/11/20 15:45:37 1.9 +++ mandoc/Attic/apropos_db.c 2011/11/23 09:55:28 1.11 @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.9 2011/11/20 15:45:37 kristaps Exp $ */ +/* $Id: apropos_db.c,v 1.11 2011/11/23 09:55:28 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -125,7 +125,7 @@ static int exprmark(const struct expr *, static struct expr *exprexpr(int, char *[], int *, int *, size_t *); static struct expr *exprterm(char *, int); static DB *index_open(void); -static int index_read(const DBT *, const DBT *, +static int index_read(const DBT *, const DBT *, int, const struct mchars *, struct rec *); static void norm_string(const char *, const struct mchars *, char **); @@ -133,7 +133,7 @@ static size_t norm_utf8(unsigned int, char[7]); static void recfree(struct rec *); static int single_search(struct rectree *, const struct opts *, const struct expr *, size_t terms, - struct mchars *); + struct mchars *, int); /* * Open the keyword mandoc-db database. @@ -345,7 +345,7 @@ index_open(void) * Returns 1 if an entry was unpacked, 0 if the database is insane. */ static int -index_read(const DBT *key, const DBT *val, +index_read(const DBT *key, const DBT *val, int index, const struct mchars *mc, struct rec *rec) { size_t left; @@ -364,6 +364,7 @@ index_read(const DBT *key, const DBT *val, cp = (char *)val->data; rec->res.rec = *(recno_t *)key->data; + rec->res.volume = index; INDEX_BREAD(rec->res.file); INDEX_BREAD(rec->res.cat); @@ -374,14 +375,13 @@ index_read(const DBT *key, const DBT *val, } /* - * Search mandocdb databases in argv (size argc) for the expression - * "expr". + * Search mandocdb databases in paths for expression "expr". * Filter out by "opts". * Call "res" with the results, which may be zero. * Return 0 if there was a database error, else return 1. */ int -apropos_search(int argc, char *argv[], const struct opts *opts, +apropos_search(int pathsz, char **paths, const struct opts *opts, const struct expr *expr, size_t terms, void *arg, void (*res)(struct res *, size_t, void *)) { @@ -392,19 +392,24 @@ apropos_search(int argc, char *argv[], const struct op memset(&tree, 0, sizeof(struct rectree)); + rc = 0; mc = mchars_alloc(); - for (rc = 1, i = 0; rc && i < argc; i++) { - /* FIXME: ugly warning: we shouldn't get here! */ - if (chdir(argv[i])) + /* + * Main loop. Change into the directory containing manpage + * databases. Run our expession over each database in the set. + */ + + for (i = 0; i < pathsz; i++) { + if (chdir(paths[i])) continue; - rc = single_search(&tree, opts, expr, terms, mc); - /* FIXME: warn and continue... ? */ + if ( ! single_search(&tree, opts, expr, terms, mc, i)) + goto out; } /* - * Count the matching files - * and feed them to the output handler. + * Count matching files, transfer to a "clean" array, then feed + * them to the output handler. */ for (mlen = i = 0; i < tree.len; i++) @@ -421,6 +426,8 @@ apropos_search(int argc, char *argv[], const struct op (*res)(ress, mlen, arg); free(ress); + rc = 1; +out: for (i = 0; i < tree.len; i++) recfree(&tree.node[i]); @@ -432,7 +439,7 @@ apropos_search(int argc, char *argv[], const struct op static int single_search(struct rectree *tree, const struct opts *opts, const struct expr *expr, size_t terms, - struct mchars *mc) + struct mchars *mc, int vol) { int root, leaf, ch; uint64_t mask; @@ -454,11 +461,11 @@ single_search(struct rectree *tree, const struct opts memset(&r, 0, sizeof(struct rec)); if (NULL == (btree = btree_open())) - return(0); + return(1); if (NULL == (idx = index_open())) { (*btree->close)(btree); - return(0); + return(1); } while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { @@ -519,7 +526,7 @@ single_search(struct rectree *tree, const struct opts break; r.lhs = r.rhs = -1; - if ( ! index_read(&key, &val, mc, &r)) + if ( ! index_read(&key, &val, vol, mc, &r)) break; /* XXX: this should be elsewhere, I guess? */