version 1.12, 2011/11/26 22:38:11 |
version 1.16, 2011/11/29 10:53:42 |
|
|
int regex; /* is regex? */ |
int regex; /* is regex? */ |
int index; /* index in match array */ |
int index; /* index in match array */ |
uint64_t mask; /* type-mask */ |
uint64_t mask; /* type-mask */ |
int cs; /* is case-sensitive? */ |
|
int and; /* is rhs of logical AND? */ |
int and; /* is rhs of logical AND? */ |
char *v; /* search value */ |
char *v; /* search value */ |
regex_t re; /* compiled re, if regex */ |
regex_t re; /* compiled re, if regex */ |
Line 366 index_read(const DBT *key, const DBT *val, int index, |
|
Line 365 index_read(const DBT *key, const DBT *val, int index, |
|
rec->res.rec = *(recno_t *)key->data; |
rec->res.rec = *(recno_t *)key->data; |
rec->res.volume = index; |
rec->res.volume = index; |
|
|
|
INDEX_BREAD(rec->res.type); |
INDEX_BREAD(rec->res.file); |
INDEX_BREAD(rec->res.file); |
INDEX_BREAD(rec->res.cat); |
INDEX_BREAD(rec->res.cat); |
INDEX_BREAD(rec->res.title); |
INDEX_BREAD(rec->res.title); |
Line 579 recfree(struct rec *rec) |
|
Line 579 recfree(struct rec *rec) |
|
free(rec->matches); |
free(rec->matches); |
} |
} |
|
|
|
/* |
|
* Compile a list of straight-up terms. |
|
* The arguments are re-written into ~[[:<:]]term[[:>:]], or "term" |
|
* surrounded by word boundaries, then pumped through exprterm(). |
|
* Terms are case-insensitive. |
|
* This emulates whatis(1) behaviour. |
|
*/ |
struct expr * |
struct expr * |
|
termcomp(int argc, char *argv[], size_t *tt) |
|
{ |
|
char *buf; |
|
int pos; |
|
struct expr *e, *next; |
|
size_t sz; |
|
|
|
buf = NULL; |
|
e = NULL; |
|
*tt = 0; |
|
|
|
for (pos = argc - 1; pos >= 0; pos--) { |
|
sz = strlen(argv[pos]) + 18; |
|
buf = mandoc_realloc(buf, sz); |
|
strlcpy(buf, "Nm~[[:<:]]", sz); |
|
strlcat(buf, argv[pos], sz); |
|
strlcat(buf, "[[:>:]]", sz); |
|
if (NULL == (next = exprterm(buf, 0))) { |
|
free(buf); |
|
exprfree(e); |
|
return(NULL); |
|
} |
|
next->next = e; |
|
e = next; |
|
(*tt)++; |
|
} |
|
|
|
free(buf); |
|
return(e); |
|
} |
|
|
|
/* |
|
* Compile a sequence of logical expressions. |
|
* See apropos.1 for a grammar of this sequence. |
|
*/ |
|
struct expr * |
exprcomp(int argc, char *argv[], size_t *tt) |
exprcomp(int argc, char *argv[], size_t *tt) |
{ |
{ |
int pos, lvl; |
int pos, lvl; |
Line 650 exprexpr(int argc, char *argv[], int *pos, int *lvl, s |
|
Line 693 exprexpr(int argc, char *argv[], int *pos, int *lvl, s |
|
++(*pos); |
++(*pos); |
++(*lvl); |
++(*lvl); |
next = mandoc_calloc(1, sizeof(struct expr)); |
next = mandoc_calloc(1, sizeof(struct expr)); |
next->cs = 1; |
|
next->subexpr = exprexpr(argc, argv, pos, lvl, tt); |
next->subexpr = exprexpr(argc, argv, pos, lvl, tt); |
if (NULL == next->subexpr) { |
if (NULL == next->subexpr) { |
free(next); |
free(next); |
Line 701 exprterm(char *buf, int cs) |
|
Line 743 exprterm(char *buf, int cs) |
|
|
|
memset(&e, 0, sizeof(struct expr)); |
memset(&e, 0, sizeof(struct expr)); |
|
|
e.cs = cs; |
|
|
|
/* Choose regex or substring match. */ |
/* Choose regex or substring match. */ |
|
|
if (NULL == (e.v = strpbrk(buf, "=~"))) { |
if (NULL == (e.v = strpbrk(buf, "=~"))) { |
Line 729 exprterm(char *buf, int cs) |
|
Line 769 exprterm(char *buf, int cs) |
|
e.mask = TYPE_Nm | TYPE_Nd; |
e.mask = TYPE_Nm | TYPE_Nd; |
|
|
if (e.regex) { |
if (e.regex) { |
i = REG_EXTENDED | REG_NOSUB | cs ? 0 : REG_ICASE; |
i = REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE); |
if (regcomp(&e.re, e.v, i)) |
if (regcomp(&e.re, e.v, i)) |
return(NULL); |
return(NULL); |
} |
} |
Line 774 exprmark(const struct expr *p, const char *cp, |
|
Line 814 exprmark(const struct expr *p, const char *cp, |
|
if (p->regex) { |
if (p->regex) { |
if (regexec(&p->re, cp, 0, NULL, 0)) |
if (regexec(&p->re, cp, 0, NULL, 0)) |
continue; |
continue; |
} else if (p->cs) { |
} else if (NULL == strcasestr(cp, p->v)) |
if (NULL == strstr(cp, p->v)) |
continue; |
continue; |
|
} else { |
|
if (NULL == strcasestr(cp, p->v)) |
|
continue; |
|
} |
|
|
|
if (NULL == ms) |
if (NULL == ms) |
return(1); |
return(1); |