=================================================================== RCS file: /cvs/mandoc/Attic/apropos_db.c,v retrieving revision 1.20 retrieving revision 1.26 diff -u -p -r1.20 -r1.26 --- mandoc/Attic/apropos_db.c 2011/12/03 12:09:07 1.20 +++ mandoc/Attic/apropos_db.c 2011/12/16 20:06:58 1.26 @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.20 2011/12/03 12:09:07 kristaps Exp $ */ +/* $Id: apropos_db.c,v 1.26 2011/12/16 20:06:58 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -117,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 } }; @@ -153,7 +153,6 @@ btree_open(void) DB *db; memset(&info, 0, sizeof(BTREEINFO)); - info.lorder = 4321; info.flags = R_DUP; db = dbopen(MANDOC_DB, O_RDONLY, 0, DB_BTREE, &info); @@ -198,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; @@ -239,7 +238,7 @@ norm_utf8(unsigned int cp, char out[7]) return(0); out[rc] = '\0'; - return(rc); + return((size_t)rc); } /* @@ -366,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 { \ @@ -376,13 +376,23 @@ 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); + cp = val->data; rec->res.rec = *(recno_t *)key->data; 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); @@ -542,13 +552,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)); @@ -564,7 +577,6 @@ single_search(struct rectree *tree, const struct opts } else root = tree->len; - memset(&r, 0, sizeof(struct rec)); tree->len++; } @@ -572,6 +584,7 @@ single_search(struct rectree *tree, const struct opts (*idx->close)(idx); free(buf); + recfree(&r); return(1 == ch); } @@ -579,7 +592,6 @@ static void recfree(struct rec *rec) { - free(rec->res.type); free(rec->res.file); free(rec->res.cat); free(rec->res.title);