-/* $Id: apropos_db.c,v 1.19 2011/12/02 00:21:56 kristaps Exp $ */
+/* $Id: apropos_db.c,v 1.27 2011/12/20 21:41:11 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
{ TYPE_Va, "Va" },
{ TYPE_Va, "Vt" },
{ TYPE_Xr, "Xr" },
- { INT_MAX, "any" },
+ { UINT64_MAX, "any" },
{ 0, NULL }
};
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)
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);
}
static size_t
norm_utf8(unsigned int cp, char out[7])
{
- size_t rc;
+ int rc;
rc = 0;
return(0);
out[rc] = '\0';
- return(rc);
+ return((size_t)rc);
}
/*
{
size_t left;
char *np, *cp;
+ char type;
#define INDEX_BREAD(_dst) \
do { \
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);
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));
} else
root = tree->len;
- memset(&r, 0, sizeof(struct rec));
tree->len++;
}
(*idx->close)(idx);
free(buf);
+ recfree(&r);
return(1 == ch);
}
recfree(struct rec *rec)
{
- free(rec->res.type);
free(rec->res.file);
free(rec->res.cat);
free(rec->res.title);