=================================================================== RCS file: /cvs/mandoc/Attic/apropos_db.c,v retrieving revision 1.18 retrieving revision 1.27 diff -u -p -r1.18 -r1.27 --- mandoc/Attic/apropos_db.c 2011/12/01 23:55:58 1.18 +++ mandoc/Attic/apropos_db.c 2011/12/20 21:41:11 1.27 @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.18 2011/12/01 23:55:58 kristaps Exp $ */ +/* $Id: apropos_db.c,v 1.27 2011/12/20 21:41:11 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -15,6 +15,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -24,8 +28,12 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) +# include # include +#elif defined(__APPLE__) +# include +# include #else # include #endif @@ -109,7 +117,7 @@ static const struct type types[] = { { TYPE_Va, "Va" }, { TYPE_Va, "Vt" }, { TYPE_Xr, "Xr" }, - { INT_MAX, "any" }, + { UINT64_MAX, "any" }, { 0, NULL } }; @@ -163,7 +171,7 @@ btree_read(const DBT *k, const DBT *v, const struct mchars *mc, struct db_val *dbv, char **buf) { - const struct db_val *vp; + struct db_val raw_dbv; /* Are our sizes sane? */ if (k->size < 2 || sizeof(struct db_val) != v->size) @@ -173,10 +181,10 @@ btree_read(const DBT *k, const DBT *v, 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); + memcpy(&raw_dbv, v->data, v->size); + dbv->rec = betoh32(raw_dbv.rec); + dbv->mask = betoh64(raw_dbv.mask); return(1); } @@ -189,7 +197,7 @@ btree_read(const DBT *k, const DBT *v, static size_t norm_utf8(unsigned int cp, char out[7]) { - size_t rc; + int rc; rc = 0; @@ -230,7 +238,7 @@ norm_utf8(unsigned int cp, char out[7]) return(0); out[rc] = '\0'; - return(rc); + return((size_t)rc); } /* @@ -357,6 +365,7 @@ index_read(const DBT *key, const DBT *val, int index, { size_t left; char *np, *cp; + char type; #define INDEX_BREAD(_dst) \ do { \ @@ -367,13 +376,24 @@ index_read(const DBT *key, const DBT *val, int index, cp = np + 1; \ } while (/* CONSTCOND */ 0) - left = val->size; - cp = (char *)val->data; + if (0 == (left = val->size)) + return(0); - rec->res.rec = *(recno_t *)key->data; + cp = val->data; + assert(sizeof(recno_t) == key->size); + memcpy(&rec->res.rec, key->data, key->size); rec->res.volume = index; - INDEX_BREAD(rec->res.type); + if ('d' == (type = *cp++)) + rec->res.type = RESTYPE_MDOC; + else if ('a' == type) + rec->res.type = RESTYPE_MAN; + else if ('c' == type) + rec->res.type = RESTYPE_CAT; + else + return(0); + + left--; INDEX_BREAD(rec->res.file); INDEX_BREAD(rec->res.cat); INDEX_BREAD(rec->res.title); @@ -533,13 +553,16 @@ single_search(struct rectree *tree, const struct opts if (opts->cat && strcasecmp(opts->cat, r.res.cat)) continue; - if (opts->arch && strcasecmp(opts->arch, r.res.arch)) - continue; + if (opts->arch && *r.res.arch) + if (strcasecmp(opts->arch, r.res.arch)) + continue; + tree->node = rs = mandoc_realloc (rs, (tree->len + 1) * sizeof(struct rec)); memcpy(&rs[tree->len], &r, sizeof(struct rec)); + memset(&r, 0, sizeof(struct rec)); rs[tree->len].matches = mandoc_calloc(terms, sizeof(int)); @@ -555,7 +578,6 @@ single_search(struct rectree *tree, const struct opts } else root = tree->len; - memset(&r, 0, sizeof(struct rec)); tree->len++; } @@ -563,6 +585,7 @@ single_search(struct rectree *tree, const struct opts (*idx->close)(idx); free(buf); + recfree(&r); return(1 == ch); } @@ -570,7 +593,6 @@ static void recfree(struct rec *rec) { - free(rec->res.type); free(rec->res.file); free(rec->res.cat); free(rec->res.title);