diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2019-01-01 08:18:11 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2019-01-01 08:18:11 +0000 |
commit | 3b8a9f3d5a3fe6fb5c1f5e1bee2a81ec212fd501 (patch) | |
tree | 8b4c017d96a1addce6d5ee35c251c86e52f6b025 /main.c | |
parent | 2fd178dd414bc5241e3bfcc62b303d84f58bb147 (diff) | |
download | mandoc-3b8a9f3d5a3fe6fb5c1f5e1bee2a81ec212fd501.tar.gz mandoc-3b8a9f3d5a3fe6fb5c1f5e1bee2a81ec212fd501.tar.zst mandoc-3b8a9f3d5a3fe6fb5c1f5e1bee2a81ec212fd501.zip |
Support taking the -O tag value from apropos(1) key=value search terms;
feature improvement suggested by kn@.
While here, also make "-O value" work from standard input.
OK kn@
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.315 2018/12/30 00:49:55 schwarze Exp $ */ +/* $Id: main.c,v 1.316 2019/01/01 08:18:11 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org> @@ -123,7 +123,7 @@ main(int argc, char *argv[]) struct manpage *res, *resp; const char *progname, *sec, *thisarg; char *conf_file, *defpaths, *auxpaths; - char *oarg; + char *oarg, *tagarg; unsigned char *uc; size_t i, sz; int prio, best_prio; @@ -368,6 +368,17 @@ main(int argc, char *argv[]) #endif } + /* + * Use the first argument for -O tag in addition to + * using it as a search term for man(1) or apropos(1). + */ + + if (conf.output.tag != NULL && *conf.output.tag == '\0') { + tagarg = argc > 0 && search.argmode == ARG_EXPR ? + strchr(*argv, '=') : NULL; + conf.output.tag = tagarg == NULL ? *argv : tagarg + 1; + } + /* man(1), whatis(1), apropos(1) */ if (search.argmode != ARG_FILE) { @@ -480,8 +491,10 @@ main(int argc, char *argv[]) curp.mp = mparse_alloc(options, curp.os_e, curp.os_s); if (argc < 1) { - if (use_pager) + if (use_pager) { tag_files = tag_init(); + tag_files->tagname = conf.output.tag; + } thisarg = "<stdin>"; mandoc_msg_setinfilename(thisarg); parse(&curp, STDIN_FILENO, thisarg); @@ -518,11 +531,7 @@ main(int argc, char *argv[]) if (use_pager) { use_pager = 0; tag_files = tag_init(); - if (conf.output.tag != NULL && - tag_files->tagname == NULL) - tag_files->tagname = - *conf.output.tag != '\0' ? - conf.output.tag : *argv; + tag_files->tagname = conf.output.tag; } mandoc_msg_setinfilename(thisarg); |