From 3b8a9f3d5a3fe6fb5c1f5e1bee2a81ec212fd501 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 1 Jan 2019 08:18:11 +0000 Subject: 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@ --- main.c | 25 +++++++++++++++++-------- mandoc.1 | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index ad9ebf97..22175639 100644 --- a/main.c +++ b/main.c @@ -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 * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze @@ -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 = ""; 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); diff --git a/mandoc.1 b/mandoc.1 index 777c657c..51dca28b 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.235 2018/12/28 00:15:11 schwarze Exp $ +.\" $Id: mandoc.1,v 1.236 2019/01/01 08:18:11 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014-2018 Ingo Schwarze @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 28 2018 $ +.Dd $Mdocdate: January 1 2019 $ .Dt MANDOC 1 .Os .Sh NAME @@ -307,8 +307,16 @@ If no is specified, reuse the first command line argument that is not a .Ar section number. -This is useful when it is the name of a manual page, -in particular the name of a library function. +If that argument is in +.Xr apropos 1 +.Ar key Ns = Ns Ar val +format, only the +.Ar val +is used rather than the argument as a whole. +This is useful for commands like +.Ql man -akO tag Ic=ulimit +to search for a keyword and jump right to its definition +in the matching manual pages. .It Cm width Ns = Ns Ar width The output width is set to .Ar width -- cgit v1.2.3-56-ge451