summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apropos.17
-rw-r--r--main.c12
-rw-r--r--man.17
-rw-r--r--man_term.c38
-rw-r--r--mandoc.16
-rw-r--r--mdoc_term.c41
-rw-r--r--term.h1
-rw-r--r--term_ascii.c8
8 files changed, 78 insertions, 42 deletions
diff --git a/apropos.1 b/apropos.1
index cc169da2..01d6ac26 100644
--- a/apropos.1
+++ b/apropos.1
@@ -24,7 +24,7 @@
.Nd search manual page databases
.Sh SYNOPSIS
.Nm
-.Op Fl acfklVw
+.Op Fl acfhklVw
.Op Fl C Ar file
.Op Fl M Ar path
.Op Fl m Ar path
@@ -107,6 +107,11 @@ This overrides any earlier
and
.Fl l
options.
+.It Fl h
+Instead of showing the title lines, show the SYNOPSIS sections, just like
+.Xr man 1
+.Fl h
+would.
.It Fl k
Support the full
.Ar expression
diff --git a/main.c b/main.c
index 4c71266f..5c13d2f7 100644
--- a/main.c
+++ b/main.c
@@ -154,7 +154,7 @@ main(int argc, char *argv[])
show_usage = 0;
outmode = OUTMODE_DEF;
- while (-1 != (c = getopt(argc, argv, "aC:cfI:iklM:m:O:S:s:T:VW:w"))) {
+ while (-1 != (c = getopt(argc, argv, "aC:cfhI:iklM:m:O:S:s:T:VW:w"))) {
switch (c) {
case 'a':
outmode = OUTMODE_ALL;
@@ -168,6 +168,10 @@ main(int argc, char *argv[])
case 'f':
search.argmode = ARG_WORD;
break;
+ case 'h':
+ (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);
+ outmode = OUTMODE_ALL;
+ break;
case 'I':
if (strncmp(optarg, "os=", 3)) {
fprintf(stderr,
@@ -414,7 +418,7 @@ usage(enum argmode argmode)
switch (argmode) {
case ARG_FILE:
- fputs("usage: mandoc [-acfklV] [-Ios=name] "
+ fputs("usage: mandoc [-acfhklV] [-Ios=name] "
"[-mformat] [-Ooption] [-Toutput] [-Wlevel]\n"
"\t [file ...]\n", stderr);
break;
@@ -424,12 +428,12 @@ usage(enum argmode argmode)
"\t [section] name ...\n", stderr);
break;
case ARG_WORD:
- fputs("usage: whatis [-acfklVw] [-C file] "
+ fputs("usage: whatis [-acfhklVw] [-C file] "
"[-M path] [-m path] [-O outkey] [-S arch]\n"
"\t [-s section] name ...\n", stderr);
break;
case ARG_EXPR:
- fputs("usage: apropos [-acfklVw] [-C file] "
+ fputs("usage: apropos [-acfhklVw] [-C file] "
"[-M path] [-m path] [-O outkey] [-S arch]\n"
"\t [-s section] expression ...\n", stderr);
break;
diff --git a/man.1 b/man.1
index e9864676..eb266fe7 100644
--- a/man.1
+++ b/man.1
@@ -1,5 +1,4 @@
.\" $Id$
-.\" $OpenBSD: man.1,v 1.55 2014/04/03 06:15:18 jmc Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -97,9 +96,9 @@ and
.Fl l
options.
.It Fl h
-Display only the
-.Dq SYNOPSIS
-lines of the requested manual pages.
+Display only the SYNOPSIS lines of the requested manual pages.
+Implies
+.Fl a .
.It Fl k
A synonym for
.Xr apropos 1 .
diff --git a/man_term.c b/man_term.c
index 14d30cd5..17753c62 100644
--- a/man_term.c
+++ b/man_term.c
@@ -141,38 +141,50 @@ void
terminal_man(void *arg, const struct man *man)
{
struct termp *p;
- const struct man_node *n;
const struct man_meta *meta;
+ struct man_node *n;
struct mtermp mt;
p = (struct termp *)arg;
- if (0 == p->defindent)
- p->defindent = 7;
-
p->overstep = 0;
- p->maxrmargin = p->defrmargin;
+ p->rmargin = p->maxrmargin = p->defrmargin;
p->tabwidth = term_len(p, 5);
if (NULL == p->symtab)
p->symtab = mchars_alloc();
- n = man_node(man);
+ n = man_node(man)->child;
meta = man_meta(man);
- term_begin(p, print_man_head, print_man_foot, meta);
- p->flags |= TERMP_NOSPACE;
-
memset(&mt, 0, sizeof(struct mtermp));
mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
mt.offset = term_len(p, p->defindent);
mt.pardist = 1;
- if (n->child)
- print_man_nodelist(p, &mt, n->child, meta);
-
- term_end(p);
+ if (p->synopsisonly) {
+ while (n != NULL) {
+ if (n->tok == MAN_SH &&
+ n->child->child->type == MAN_TEXT &&
+ !strcmp(n->child->child->string, "SYNOPSIS")) {
+ if (n->child->next->child != NULL)
+ print_man_nodelist(p, &mt,
+ n->child->next->child, meta);
+ term_newln(p);
+ break;
+ }
+ n = n->next;
+ }
+ } else {
+ if (p->defindent == 0)
+ p->defindent = 7;
+ term_begin(p, print_man_head, print_man_foot, meta);
+ p->flags |= TERMP_NOSPACE;
+ if (n != NULL)
+ print_man_nodelist(p, &mt, n, meta);
+ term_end(p);
+ }
}
diff --git a/mandoc.1 b/mandoc.1
index 495043a2..063ea13f 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -23,7 +23,7 @@
.Nd format and display UNIX manuals
.Sh SYNOPSIS
.Nm mandoc
-.Op Fl acfklV
+.Op Fl acfhklV
.Sm off
.Op Fl I Cm os Li = Ar name
.Sm on
@@ -85,6 +85,10 @@ for the
.Xr mdoc 7
.Sq \&Os
macro.
+.It Fl h
+Display only the SYNOPSIS lines.
+Implies
+.Fl a .
.It Fl k
A synonym for
.Xr apropos 1 .
diff --git a/mdoc_term.c b/mdoc_term.c
index 4b4c4248..c010dfbb 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -252,34 +252,44 @@ static const struct termact termacts[MDOC_MAX] = {
void
terminal_mdoc(void *arg, const struct mdoc *mdoc)
{
- const struct mdoc_node *n;
const struct mdoc_meta *meta;
+ struct mdoc_node *n;
struct termp *p;
p = (struct termp *)arg;
- if (0 == p->defindent)
- p->defindent = 5;
-
p->overstep = 0;
- p->maxrmargin = p->defrmargin;
+ p->rmargin = p->maxrmargin = p->defrmargin;
p->tabwidth = term_len(p, 5);
if (NULL == p->symtab)
p->symtab = mchars_alloc();
- n = mdoc_node(mdoc);
+ n = mdoc_node(mdoc)->child;
meta = mdoc_meta(mdoc);
- term_begin(p, print_mdoc_head, print_mdoc_foot, meta);
-
- if (n->child) {
- if (MDOC_Sh != n->child->tok)
- term_vspace(p);
- print_mdoc_nodelist(p, NULL, meta, n->child);
+ if (p->synopsisonly) {
+ while (n != NULL) {
+ if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
+ if (n->child->next->child != NULL)
+ print_mdoc_nodelist(p, NULL,
+ meta, n->child->next->child);
+ term_newln(p);
+ break;
+ }
+ n = n->next;
+ }
+ } else {
+ if (p->defindent == 0)
+ p->defindent = 5;
+ term_begin(p, print_mdoc_head, print_mdoc_foot, meta);
+ if (n != NULL) {
+ if (n->tok != MDOC_Sh)
+ term_vspace(p);
+ print_mdoc_nodelist(p, NULL, meta, n);
+ }
+ term_end(p);
}
-
- term_end(p);
}
static void
@@ -463,9 +473,6 @@ print_mdoc_head(struct termp *p, const void *arg)
* switches on the manual section.
*/
- p->offset = 0;
- p->rmargin = p->maxrmargin;
-
assert(meta->vol);
if (NULL == meta->arch)
volume = mandoc_strdup(meta->vol);
diff --git a/term.h b/term.h
index 4fe518e8..96b7e51c 100644
--- a/term.h
+++ b/term.h
@@ -54,6 +54,7 @@ struct termp_tbl {
struct termp {
enum termtype type;
struct rofftbl tbl; /* table configuration */
+ int synopsisonly; /* print the synopsis only */
int mdocstyle; /* imitate mdoc(7) output */
size_t defindent; /* Default indent for text. */
size_t defrmargin; /* Right margin of the device. */
diff --git a/term_ascii.c b/term_ascii.c
index 753cc832..056f8c7a 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -58,7 +58,7 @@ static size_t locale_width(const struct termp *, int);
static struct termp *
ascii_init(enum termenc enc, char *outopts)
{
- const char *toks[4];
+ const char *toks[5];
char *v;
struct termp *p;
@@ -97,7 +97,8 @@ ascii_init(enum termenc enc, char *outopts)
toks[0] = "indent";
toks[1] = "width";
toks[2] = "mdoc";
- toks[3] = NULL;
+ toks[3] = "synopsis";
+ toks[4] = NULL;
while (outopts && *outopts)
switch (getsubopt(&outopts, UNCONST(toks), &v)) {
@@ -115,6 +116,9 @@ ascii_init(enum termenc enc, char *outopts)
p->mdocstyle = 1;
p->defindent = 5;
break;
+ case 3:
+ p->synopsisonly = 1;
+ break;
default:
break;
}