From cf7951650705f6912f48a0d74423660997ed9049 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 16 Jan 2011 03:46:22 +0000 Subject: In literal context, do not generate output line breaks between macro arguments. This fixes a long-standing bug reported repeatedly, in particular by naddy@ and brad@. Fix by kristaps@, minus one regression caught by my test suite. --- regress/usr.bin/mandoc/man/BI/literal.in | 2 +- usr.bin/mandoc/man_html.c | 20 +++------- usr.bin/mandoc/man_term.c | 64 +++++++++++++++++--------------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/regress/usr.bin/mandoc/man/BI/literal.in b/regress/usr.bin/mandoc/man/BI/literal.in index f1d7b4fdeba..ebd22a67992 100644 --- a/regress/usr.bin/mandoc/man/BI/literal.in +++ b/regress/usr.bin/mandoc/man/BI/literal.in @@ -3,7 +3,7 @@ gettext, dgettext, dcgettext \- translate message .SH SYNOPSIS .nf -.B "#include " +.B #include .sp .BI "char * gettext (const char * " msgid ); .BI "char * dgettext (const char * " domainname ", const char * " msgid ); diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index 78d2da75f6e..2f7d14cc16a 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.31 2011/01/16 02:56:47 schwarze Exp $ */ +/* $Id: man_html.c,v 1.32 2011/01/16 03:46:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -182,12 +182,6 @@ print_man_node(MAN_ARGS) bufinit(h); - /* - * FIXME: embedded elements within next-line scopes (e.g., `br' - * within an empty `B') will cause formatting to be forgotten - * due to scope closing out. - */ - switch (n->type) { case (MAN_ROOT): child = man_root_pre(m, n, mh, h); @@ -196,19 +190,19 @@ print_man_node(MAN_ARGS) if ('\0' == *n->string) { print_otag(h, TAG_P, 0, NULL); return; - } - - if (' ' == *n->string && MAN_LINE & n->flags) + } else if (' ' == *n->string && MAN_LINE & n->flags) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); - if (MANH_LITERAL & mh->fl) + if (MANH_LITERAL & mh->fl && + (NULL == n->next || + n->next->line > n->line)) print_otag(h, TAG_BR, 0, NULL); return; case (MAN_TBL): print_tbl(h, n->span); - break; + return; default: /* * Close out scope of font prior to opening a macro @@ -236,8 +230,6 @@ print_man_node(MAN_ARGS) case (MAN_ROOT): man_root_post(m, n, mh, h); break; - case (MAN_TBL): - break; default: if (mans[n->tok].post) (*mans[n->tok].post)(m, n, mh, h); diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 1f93e57d939..fc319fcbcdc 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.60 2011/01/16 02:56:47 schwarze Exp $ */ +/* $Id: man_term.c,v 1.61 2011/01/16 03:46:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -851,23 +851,31 @@ print_man_node(DECL_ARGS) size_t rm, rmax; int c; - c = 1; - switch (n->type) { case(MAN_TEXT): + /* + * If we have a blank line, output a vertical space. + * If we have a space as the first character, break + * before printing the line's data. + */ if ('\0' == *n->string) { term_vspace(p); - break; - } - - if (' ' == *n->string && MAN_LINE & n->flags) + return; + } else if (' ' == *n->string && MAN_LINE & n->flags) term_newln(p); term_word(p, n->string); - /* FIXME: this means that macro lines are munged! */ - - if (MANT_LITERAL & mt->fl) { + /* + * If we're in a literal context, make sure that words + * togehter on the same line stay together. This is a + * POST-printing call, so we check the NEXT word. Since + * -man doesn't have nested macros, we don't need to be + * more specific than this. + */ + if (MANT_LITERAL & mt->fl && + (NULL == n->next || + n->next->line > n->line)) { rm = p->rmargin; rmax = p->maxrmargin; p->rmargin = p->maxrmargin = TERM_MAXMARGIN; @@ -877,36 +885,34 @@ print_man_node(DECL_ARGS) p->rmargin = rm; p->maxrmargin = rmax; } - - break; + return; case (MAN_TBL): + /* + * Tables are preceded by a newline. Then process a + * table line, which will cause line termination, + */ if (TBL_SPAN_FIRST & n->span->flags) term_newln(p); term_tbl(p, n->span); - break; + return; default: - if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) - term_fontrepl(p, TERMFONT_NONE); - if (termacts[n->tok].pre) - c = (*termacts[n->tok].pre)(p, mt, n, m); break; } + if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) + term_fontrepl(p, TERMFONT_NONE); + + c = 1; + if (termacts[n->tok].pre) + c = (*termacts[n->tok].pre)(p, mt, n, m); + if (c && n->child) print_man_nodelist(p, mt, n->child, m); - switch (n->type) { - case (MAN_TEXT): - /* FALLTHROUGH */ - case (MAN_TBL): - break; - default: - if (termacts[n->tok].post) - (*termacts[n->tok].post)(p, mt, n, m); - if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) - term_fontrepl(p, TERMFONT_NONE); - break; - } + if (termacts[n->tok].post) + (*termacts[n->tok].post)(p, mt, n, m); + if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) + term_fontrepl(p, TERMFONT_NONE); if (MAN_EOS & n->flags) p->flags |= TERMP_SENTENCE; -- cgit v1.2.3