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 | 7f0964d6bed1077435683bcb011c0c605f6a0255 (patch) | |
tree | 546ec179ee4d7b7a9fa2be1d9b8d222d47bf09c3 /apropos_db.c | |
parent | 70b854a8e664254f12bc43f940791a2514b10cfc (diff) | |
download | mandoc-7f0964d6bed1077435683bcb011c0c605f6a0255.tar.gz mandoc-7f0964d6bed1077435683bcb011c0c605f6a0255.tar.zst mandoc-7f0964d6bed1077435683bcb011c0c605f6a0255.zip |
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 | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/apropos_db.c b/apropos_db.c index 4f1a325b..4e41a22b 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.12 2011/11/26 22:38:11 schwarze Exp $ */ +/* $Id: apropos_db.c,v 1.13 2011/11/27 18:54:01 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -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); } |