diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/main.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/man.1 | 13 | ||||
-rw-r--r-- | usr.bin/mandoc/manconf.h | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.1 | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/manpath.c | 21 | ||||
-rw-r--r-- | usr.bin/mandoc/tag.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/tag.h | 3 |
7 files changed, 67 insertions, 21 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 03fc058fce2..558dfc43adf 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.211 2018/08/23 19:32:03 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.212 2018/11/22 11:30:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org> @@ -488,8 +488,13 @@ main(int argc, char *argv[]) fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv); if (fd != -1) { if (use_pager) { - tag_files = tag_init(); 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; } if (resp == NULL) @@ -1150,7 +1155,7 @@ spawn_pager(struct tag_files *tag_files) const char *pager; char *cp; size_t cmdlen; - int argc; + int argc, use_ofn; pid_t pager_pid; pager = getenv("MANPAGER"); @@ -1166,7 +1171,7 @@ spawn_pager(struct tag_files *tag_files) */ argc = 0; - while (argc + 4 < MAX_PAGER_ARGS) { + while (argc + 5 < MAX_PAGER_ARGS) { argv[argc++] = cp; cp = strchr(cp, ' '); if (cp == NULL) @@ -1180,14 +1185,21 @@ spawn_pager(struct tag_files *tag_files) /* For more(1) and less(1), use the tag file. */ + use_ofn = 1; if ((cmdlen = strlen(argv[0])) >= 4) { cp = argv[0] + cmdlen - 4; if (strcmp(cp, "less") == 0 || strcmp(cp, "more") == 0) { argv[argc++] = mandoc_strdup("-T"); argv[argc++] = tag_files->tfn; + if (tag_files->tagname != NULL) { + argv[argc++] = mandoc_strdup("-t"); + argv[argc++] = tag_files->tagname; + use_ofn = 0; + } } } - argv[argc++] = tag_files->ofn; + if (use_ofn) + argv[argc++] = tag_files->ofn; argv[argc] = NULL; switch (pager_pid = fork()) { diff --git a/usr.bin/mandoc/man.1 b/usr.bin/mandoc/man.1 index 256097ecb98..6a0e2ca4588 100644 --- a/usr.bin/mandoc/man.1 +++ b/usr.bin/mandoc/man.1 @@ -1,9 +1,9 @@ -.\" $OpenBSD: man.1,v 1.31 2018/04/19 23:40:43 schwarze Exp $ +.\" $OpenBSD: man.1,v 1.32 2018/11/22 11:30:15 schwarze Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" Copyright (c) 2003, 2007, 2008, 2014 Jason McIntyre <jmc@openbsd.org> -.\" Copyright (c) 2010, 2011, 2014-2017 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2010, 2011, 2014-2018 Ingo Schwarze <schwarze@openbsd.org> .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -31,7 +31,7 @@ .\" .\" @(#)man.1 8.2 (Berkeley) 1/2/94 .\" -.Dd $Mdocdate: April 19 2018 $ +.Dd $Mdocdate: November 22 2018 $ .Dt MAN 1 .Os .Sh NAME @@ -266,6 +266,13 @@ and can be used to move to the next and to the previous place providing information about the term last searched for with .Ic :t . +The +.Fl O Cm tag Ns Op = Ns Ar term +option documented in the +.Xr mandoc 1 +manual opens a manual page at the definition of a specific +.Ar term +rather than at the beginning. .It Ev MANPATH The standard search path used by .Nm diff --git a/usr.bin/mandoc/manconf.h b/usr.bin/mandoc/manconf.h index 5c5026fb4af..5c8fba37df4 100644 --- a/usr.bin/mandoc/manconf.h +++ b/usr.bin/mandoc/manconf.h @@ -1,6 +1,6 @@ -/* $OpenBSD: manconf.h,v 1.6 2018/10/02 14:56:36 schwarze Exp $ */ +/* $OpenBSD: manconf.h,v 1.7 2018/11/22 11:30:15 schwarze Exp $ */ /* - * Copyright (c) 2011, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2011, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any @@ -30,6 +30,7 @@ struct manoutput { char *man; char *paper; char *style; + char *tag; size_t indent; size_t width; int fragment; diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 24d3f33fc29..af46152384c 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.154 2018/10/02 14:56:36 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.155 2018/11/22 11:30:15 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> .\" Copyright (c) 2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org> @@ -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: October 2 2018 $ +.Dd $Mdocdate: November 22 2018 $ .Dt MANDOC 1 .Os .Sh NAME @@ -290,6 +290,18 @@ One useful application is for checking that output formats in the same way as the .Xr mdoc 7 source it was generated from. +.It Cm tag Ns Op = Ns Ar term +If the formatted manual page is opened in a pager, +go to the definition of the +.Ar term +rather than showing the manual page from the beginning. +If no +.Ar term +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. .It Cm width Ns = Ns Ar width The output width is set to .Ar width diff --git a/usr.bin/mandoc/manpath.c b/usr.bin/mandoc/manpath.c index 56370e73bef..c01309ac6d3 100644 --- a/usr.bin/mandoc/manpath.c +++ b/usr.bin/mandoc/manpath.c @@ -1,4 +1,4 @@ -/* $OpenBSD: manpath.c,v 1.23 2018/10/02 14:56:36 schwarze Exp $ */ +/* $OpenBSD: manpath.c,v 1.24 2018/11/22 11:30:15 schwarze Exp $ */ /* * Copyright (c) 2011,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> @@ -232,8 +232,8 @@ int manconf_output(struct manoutput *conf, const char *cp, int fromfile) { const char *const toks[] = { - "includes", "man", "paper", "style", - "indent", "width", "fragment", "mdoc", "noval", "toc" + "includes", "man", "paper", "style", "indent", "width", + "tag", "fragment", "mdoc", "noval", "toc" }; const char *errstr; @@ -257,7 +257,7 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) warnx("-O %s=?: Missing argument value", toks[tok]); return -1; } - if ((tok == 6 || tok == 7) && *cp != '\0') { + if (tok > 6 && *cp != '\0') { warnx("-O %s: Does not take a value: %s", toks[tok], cp); return -1; } @@ -312,15 +312,22 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) warnx("-O width=%s is %s", cp, errstr); return -1; case 6: - conf->fragment = 1; + if (conf->tag != NULL) { + oldval = mandoc_strdup(conf->tag); + break; + } + conf->tag = mandoc_strdup(cp); return 0; case 7: - conf->mdoc = 1; + conf->fragment = 1; return 0; case 8: - conf->noval = 1; + conf->mdoc = 1; return 0; case 9: + conf->noval = 1; + return 0; + case 10: conf->toc = 1; return 0; default: diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c index e7d086e8606..6ae6faa2a7e 100644 --- a/usr.bin/mandoc/tag.c +++ b/usr.bin/mandoc/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.20 2018/10/23 20:41:59 schwarze Exp $ */ +/* $OpenBSD: tag.c,v 1.21 2018/11/22 11:30:15 schwarze Exp $ */ /* * Copyright (c) 2015, 2016, 2018 Ingo Schwarze <schwarze@openbsd.org> * @@ -16,6 +16,7 @@ */ #include <sys/types.h> +#include <err.h> #include <limits.h> #include <signal.h> #include <stddef.h> @@ -214,6 +215,11 @@ tag_write(void) if (tag_files.tfd <= 0) return; + if (tag_files.tagname != NULL && ohash_find(&tag_data, + ohash_qlookup(&tag_data, tag_files.tagname)) == NULL) { + warnx("%s: no such tag", tag_files.tagname); + tag_files.tagname = NULL; + } stream = fdopen(tag_files.tfd, "w"); entry = ohash_first(&tag_data, &slot); while (entry != NULL) { diff --git a/usr.bin/mandoc/tag.h b/usr.bin/mandoc/tag.h index c646b64097d..b5bfe0f370d 100644 --- a/usr.bin/mandoc/tag.h +++ b/usr.bin/mandoc/tag.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.h,v 1.7 2015/11/20 21:58:32 schwarze Exp $ */ +/* $OpenBSD: tag.h,v 1.8 2018/11/22 11:30:15 schwarze Exp $ */ /* * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> * @@ -18,6 +18,7 @@ struct tag_files { char ofn[20]; char tfn[20]; + char *tagname; int ofd; int tfd; pid_t tcpgid; |