=================================================================== RCS file: /cvs/mandoc/man_term.c,v retrieving revision 1.146 retrieving revision 1.152 diff -u -p -r1.146 -r1.152 --- mandoc/man_term.c 2014/04/20 16:46:04 1.146 +++ mandoc/man_term.c 2014/10/20 02:33:06 1.152 @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.146 2014/04/20 16:46:04 schwarze Exp $ */ +/* $Id: man_term.c,v 1.152 2014/10/20 02:33:06 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -15,9 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include @@ -28,6 +26,7 @@ #include #include "mandoc.h" +#include "mandoc_aux.h" #include "out.h" #include "man.h" #include "term.h" @@ -142,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); + } } @@ -976,6 +987,8 @@ print_man_node(DECL_ARGS) goto out; case MAN_EQN: + if ( ! (n->flags & MAN_LINE)) + p->flags |= TERMP_NOSPACE; term_eqn(p, n->eqn); return; case MAN_TBL: @@ -1049,9 +1062,9 @@ print_man_nodelist(DECL_ARGS) static void print_man_foot(struct termp *p, const void *arg) { - char title[BUFSIZ]; - size_t datelen; - const struct man_meta *meta; + const struct man_meta *meta; + char *title; + size_t datelen; meta = (const struct man_meta *)arg; assert(meta->title); @@ -1060,7 +1073,8 @@ print_man_foot(struct termp *p, const void *arg) term_fontrepl(p, TERMFONT_NONE); - term_vspace(p); + if (meta->hasbody) + term_vspace(p); /* * Temporary, undocumented option to imitate mdoc(7) output. @@ -1069,13 +1083,16 @@ print_man_foot(struct termp *p, const void *arg) */ if ( ! p->mdocstyle) { - term_vspace(p); - term_vspace(p); - snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec); + if (meta->hasbody) { + term_vspace(p); + term_vspace(p); + } + mandoc_asprintf(&title, "%s(%s)", + meta->title, meta->msec); } else if (meta->source) { - strlcpy(title, meta->source, BUFSIZ); + title = mandoc_strdup(meta->source); } else { - title[0] = '\0'; + title = mandoc_strdup(""); } datelen = term_strlen(p, meta->date); @@ -1111,37 +1128,35 @@ print_man_foot(struct termp *p, const void *arg) term_word(p, title); term_flushln(p); + free(title); } static void print_man_head(struct termp *p, const void *arg) { - char buf[BUFSIZ], title[BUFSIZ]; - size_t buflen, titlen; - const struct man_meta *meta; + const struct man_meta *meta; + const char *volume; + char *title; + size_t vollen, titlen; meta = (const struct man_meta *)arg; assert(meta->title); assert(meta->msec); - if (meta->vol) - strlcpy(buf, meta->vol, BUFSIZ); - else - buf[0] = '\0'; - buflen = term_strlen(p, buf); + volume = NULL == meta->vol ? "" : meta->vol; + vollen = term_strlen(p, volume); /* Top left corner: manual title and section. */ - snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec); + mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec); titlen = term_strlen(p, title); p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; p->trailspace = 1; p->offset = 0; - p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ? - (p->maxrmargin - - term_strlen(p, buf) + term_len(p, 1)) / 2 : - p->maxrmargin - buflen; + p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? + (p->maxrmargin - vollen + term_len(p, 1)) / 2 : + p->maxrmargin - vollen; term_word(p, title); term_flushln(p); @@ -1150,10 +1165,10 @@ print_man_head(struct termp *p, const void *arg) p->flags |= TERMP_NOSPACE; p->offset = p->rmargin; - p->rmargin = p->offset + buflen + titlen < p->maxrmargin ? + p->rmargin = p->offset + vollen + titlen < p->maxrmargin ? p->maxrmargin - titlen : p->maxrmargin; - term_word(p, buf); + term_word(p, volume); term_flushln(p); /* Top right corner: title and section, again. */ @@ -1183,4 +1198,5 @@ print_man_head(struct termp *p, const void *arg) term_vspace(p); term_vspace(p); } + free(title); }