aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-06-27 12:20:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-06-27 12:20:18 +0000
commitb6723d5f5a8ba2f1931221d8b92823fd4654722f (patch)
tree5b76c593392113d5b6d4a9008dcf0b6559f4d41f /man_term.c
parent304ecda43472e85a726c792ca5c88b3f2655a892 (diff)
downloadmandoc-b6723d5f5a8ba2f1931221d8b92823fd4654722f.tar.gz
mandoc-b6723d5f5a8ba2f1931221d8b92823fd4654722f.tar.zst
mandoc-b6723d5f5a8ba2f1931221d8b92823fd4654722f.zip
Improve "man -h" output.
1. For pages lacking a SYNOPSIS, show the NAME section rather than nothing. 2. Do not print a stray blank before the beginning of a SYNOPSIS. Both issues reported by, and patch OK'ed by, tb@.
Diffstat (limited to 'man_term.c')
-rw-r--r--man_term.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/man_term.c b/man_term.c
index d867762d..6cb159e7 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.228 2019/01/05 21:18:26 schwarze Exp $ */
+/* $Id: man_term.c,v 1.229 2019/06/27 12:20:18 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -146,7 +146,7 @@ terminal_man(void *arg, const struct roff_meta *man)
{
struct mtermp mt;
struct termp *p;
- struct roff_node *n;
+ struct roff_node *n, *nc, *nn;
size_t save_defindent;
p = (struct termp *)arg;
@@ -165,18 +165,23 @@ terminal_man(void *arg, const struct roff_meta *man)
n = man->first->child;
if (p->synopsisonly) {
- while (n != NULL) {
- if (n->tok == MAN_SH &&
- n->child->child->type == ROFFT_TEXT &&
- !strcmp(n->child->child->string, "SYNOPSIS")) {
- if (n->child->next->child != NULL)
- print_man_nodelist(p, &mt,
- n->child->next->child, man);
- term_newln(p);
+ for (nn = NULL; n != NULL; n = n->next) {
+ if (n->tok != MAN_SH)
+ continue;
+ nc = n->child->child;
+ if (nc->type != ROFFT_TEXT)
+ continue;
+ if (strcmp(nc->string, "SYNOPSIS") == 0)
break;
- }
- n = n->next;
+ if (nn == NULL && strcmp(nc->string, "NAME") == 0)
+ nn = n;
}
+ if (n == NULL)
+ n = nn;
+ p->flags |= TERMP_NOSPACE;
+ if (n != NULL && (n = n->child->next->child) != NULL)
+ print_man_nodelist(p, &mt, n, man);
+ term_newln(p);
} else {
term_begin(p, print_man_head, print_man_foot, man);
p->flags |= TERMP_NOSPACE;