aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apropos.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-14 10:07:06 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-14 10:07:06 +0000
commit0bf960c1fb936cb28f39f7d7c2b1b2817ebb14a0 (patch)
tree5d0fed038d44a8a49a97a2134db6ec9941f97b3c /apropos.c
parentee8f80a2285cf242861f49768d05d2efe5c1688b (diff)
downloadmandoc-0bf960c1fb936cb28f39f7d7c2b1b2817ebb14a0.tar.gz
mandoc-0bf960c1fb936cb28f39f7d7c2b1b2817ebb14a0.tar.zst
mandoc-0bf960c1fb936cb28f39f7d7c2b1b2817ebb14a0.zip
Have exprcomp() accept a string instead of an array-pointer. Also, collapse
the arguments in apropos(1) into a single string passed to exprcomp(). Ok schwarze@.
Diffstat (limited to 'apropos.c')
-rw-r--r--apropos.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/apropos.c b/apropos.c
index 6ed6f64c..a50b1a5e 100644
--- a/apropos.c
+++ b/apropos.c
@@ -1,4 +1,4 @@
-/* $Id: apropos.c,v 1.12 2011/11/13 11:10:27 schwarze Exp $ */
+/* $Id: apropos.c,v 1.13 2011/11/14 10:07:06 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -14,6 +14,10 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <getopt.h>
#include <limits.h>
@@ -34,6 +38,8 @@ int
main(int argc, char *argv[])
{
int ch;
+ size_t sz;
+ char *buf;
struct opts opts;
struct expr *e;
extern int optind;
@@ -66,11 +72,32 @@ main(int argc, char *argv[])
if (0 == argc)
return(EXIT_SUCCESS);
- if (NULL == (e = exprcomp(argc, argv))) {
+ /*
+ * Collapse expressions into a single string.
+ * First count up the contained strings, adding a space at the
+ * end of each (plus nil-terminator). Then merge.
+ */
+
+ for (sz = 0, ch = 0; ch < argc; ch++)
+ sz += strlen(argv[ch]) + 1;
+
+ buf = mandoc_malloc(++sz);
+
+ for (*buf = '\0', ch = 0; ch < argc; ch++) {
+ strlcat(buf, argv[ch], sz);
+ strlcat(buf, " ", sz);
+ }
+
+ buf[sz - 2] = '\0';
+
+ if (NULL == (e = exprcomp(buf))) {
fprintf(stderr, "Bad expression\n");
+ free(buf);
return(EXIT_FAILURE);
}
+ free(buf);
+
/*
* Configure databases.
* The keyword database is a btree that allows for duplicate