diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-27 18:54:01 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-27 18:54:01 +0000 |
commit | dd0e5f88129e79f476e873d84e50a2df6c0fb422 (patch) | |
tree | 2d2b5131656fc873d94e534c9f43e52d1c4a04f8 /apropos_db.c | |
parent | 9c9b2be283f5e152e4043a33013ba3f871580670 (diff) | |
download | mandoc-dd0e5f88129e79f476e873d84e50a2df6c0fb422.tar.gz |
Get us a whatis(1) mode for apropos(1).
This is from a patch to tech@ as critiqued by schwarze@, checked in to
get the ball rolling.
Diffstat (limited to 'apropos_db.c')
-rw-r--r-- | apropos_db.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/apropos_db.c b/apropos_db.c index fd302d87..7a423083 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -579,6 +579,50 @@ recfree(struct rec *rec) 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 * +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 = 0; pos < argc; pos++) { + sz = strlen(argv[pos]) + 16; + buf = mandoc_realloc(buf, sz); + strlcpy(buf, "~[[:<:]]", sz); + strlcat(buf, argv[pos], sz); + strlcat(buf, "[[:>:]]", sz); + if (NULL == (next = exprterm(buf, 0))) { + free(buf); + exprfree(e); + return(NULL); + } + if (NULL != e) + e->next = next; + 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) { @@ -729,7 +773,7 @@ exprterm(char *buf, int cs) e.mask = TYPE_Nm | TYPE_Nd; 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)) return(NULL); } |