aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-09-03 05:22:45 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-09-03 05:22:45 +0000
commit02046d75d7ec4c27ec31d04e15c9d9fe018a01ab (patch)
tree88fb456e129ed40338e63c83d92faea4da97a7b1 /man_term.c
parent62dcabc9f407fb96cb3f2517d3f6d5f39dd756b1 (diff)
downloadmandoc-02046d75d7ec4c27ec31d04e15c9d9fe018a01ab.tar.gz
mandoc-02046d75d7ec4c27ec31d04e15c9d9fe018a01ab.tar.zst
mandoc-02046d75d7ec4c27ec31d04e15c9d9fe018a01ab.zip
Implement the traditional -h option for man(1): show the SYNOPSIS only.
As usual, we get mandoc -h and apropos -h for free. Try stuff like "apropos -h In=dirent" or "apropos -h Fa=timespec". Only useful for terminal output, so -Tps, -Tpdf, -Thtml ignore -h for now.
Diffstat (limited to 'man_term.c')
-rw-r--r--man_term.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/man_term.c b/man_term.c
index d61b728d..3057d326 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.150 2014/08/10 23:54:41 schwarze Exp $ */
+/* $Id: man_term.c,v 1.151 2014/09/03 05:22:45 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
+ }
}