diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-03-25 23:23:02 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-03-25 23:23:02 +0000 |
commit | 3eb08fb47bcf0e1ec01c27c5277f79a45dc710c0 (patch) | |
tree | 555275197591833137f80018ab4c61b77f1f1273 | |
parent | 470d717c25312457deedde392732c5a1cb1ee2af (diff) |
merge 1.9.16, keeping local patches
This is mostly cleanup by kristaps@ after my rather hackish patch
to tolerate the non-text macros .na, .sp, .br in next-line scope;
plus some nesting issues fixed by him, all in man(7).
This survived a full cd /usr/src; make man.
-rw-r--r-- | usr.bin/mandoc/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/libman.h | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/man.7 | 26 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 88 | ||||
-rw-r--r-- | usr.bin/mandoc/man_action.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/man_html.c | 32 | ||||
-rw-r--r-- | usr.bin/mandoc/man_macro.c | 27 | ||||
-rw-r--r-- | usr.bin/mandoc/man_term.c | 80 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.1 | 20 |
9 files changed, 207 insertions, 104 deletions
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile index b50185ed6ba..fa3c9fe1736 100644 --- a/usr.bin/mandoc/Makefile +++ b/usr.bin/mandoc/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.27 2010/01/03 23:29:03 schwarze Exp $ +# $OpenBSD: Makefile,v 1.28 2010/03/25 23:23:01 schwarze Exp $ .include <bsd.own.mk> -VERSION=1.9.15 +VERSION=1.9.16 CFLAGS+=-DVERSION=\"${VERSION}\" CFLAGS+=-W -Wall -Wstrict-prototypes .if ${USE_GCC3:L} != "no" diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index 5ae5c4082e1..cc225c088ec 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.11 2009/12/22 23:58:00 schwarze Exp $ */ +/* $Id: libman.h,v 1.12 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -30,9 +30,10 @@ struct man { int pflags; int flags; #define MAN_HALT (1 << 0) -#define MAN_ELINE (1 << 1) /* Next-line element scope. */ -#define MAN_BLINE (1 << 2) /* Next-line block scope. */ -#define MAN_LITERAL (1 << 3) /* Literal input. */ +#define MAN_ELINE (1 << 1) /* Next-line element scope. */ +#define MAN_BLINE (1 << 2) /* Next-line block scope. */ +#define MAN_ILINE (1 << 3) /* Ignored in next-line scope. */ +#define MAN_LITERAL (1 << 4) /* Literal input. */ enum man_next next; struct man_node *last; struct man_node *first; @@ -44,6 +45,7 @@ enum merr { WMSEC, WDATE, WLNSCOPE, + WLNSCOPE2, WTSPACE, WTQUOTE, WNODATA, @@ -70,6 +72,7 @@ struct man_macro { #define MAN_SCOPED (1 << 0) #define MAN_EXPLICIT (1 << 1) /* See blk_imp(). */ #define MAN_FSCOPED (1 << 2) /* See blk_imp(). */ +#define MAN_NSCOPED (1 << 3) /* See in_line_eoln(). */ }; extern const struct man_macro *const man_macros; @@ -92,6 +95,7 @@ int man_body_alloc(struct man *, int, int, int); int man_elem_alloc(struct man *, int, int, int); void man_node_free(struct man_node *); void man_node_freelist(struct man_node *); +void man_node_unlink(struct man *, struct man_node *); void man_hash_init(void); int man_hash_find(const char *); int man_macroend(struct man *); diff --git a/usr.bin/mandoc/man.7 b/usr.bin/mandoc/man.7 index f68a0b6f2b3..b2d04bb2567 100644 --- a/usr.bin/mandoc/man.7 +++ b/usr.bin/mandoc/man.7 @@ -1,4 +1,4 @@ -.\" $Id: man.7,v 1.16 2010/02/18 02:11:26 schwarze Exp $ +.\" $Id: man.7,v 1.17 2010/03/25 23:23:01 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 18 2010 $ +.Dd $Mdocdate: March 25 2010 $ .Dt MAN 7 .Os . @@ -423,8 +423,8 @@ subsequent lines until closed by another block macro. .Ss Line Macros Line macros are generally scoped to the current line, with the body consisting of zero or more arguments. If a macro is scoped to the next -line and the line arguments are empty, the next line is used instead, -else the general syntax is used. Thus: +line and the line arguments are empty, the next line, which must be +text, is used instead. Thus: .Bd -literal -offset indent \&.I foo @@ -433,9 +433,15 @@ foo .Pp is equivalent to .Sq \&.I foo . -If next-line macros are invoked consecutively, only the last is used; in -other words, if a next-line macro is preceded by a block macro, it is -ignored. +If next-line macros are invoked consecutively, only the last is used. +If a next-line macro is followed by a non-next-line macro, an error is +raised (unless in the case of +.Sx \&br , +.Sx \&sp , +or +.Sx \&na ) . +.Pp +The syntax is as follows: .Bd -literal -offset indent \&.YO \(lBbody...\(rB \(lBbody...\(rB @@ -488,8 +494,10 @@ macros should not be used. They're included for compatibility. .Ss Block Macros Block macros are comprised of a head and body. Like for in-line macros, the head is scoped to the current line and, in one circumstance, the -next line; the body is scoped to subsequent lines and is closed out by a -subsequent block macro invocation. +next line (the next-line stipulations for line macros apply here as +well). +.Pp +The syntax is as follows: .Bd -literal -offset indent \&.YO \(lBhead...\(rB \(lBhead...\(rB diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 960db5052cd..5d94334ea9b 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.20 2010/03/02 01:00:39 schwarze Exp $ */ +/* $Id: man.c,v 1.21 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -31,6 +31,7 @@ const char *const __man_merrnames[WERRMAX] = { "invalid manual section", /* WMSEC */ "invalid date format", /* WDATE */ "scope of prior line violated", /* WLNSCOPE */ + "over-zealous prior line scope violation", /* WLNSCOPE2 */ "trailing whitespace", /* WTSPACE */ "unterminated quoted parameter", /* WTQUOTE */ "document has no body", /* WNODATA */ @@ -531,28 +532,38 @@ man_pmacro(struct man *m, int ln, char *buf) if ( ! man_pwarn(m, ln, i - 1, WTSPACE)) goto err; - /* Remove prior ELINE macro, if applicable. */ + /* + * Remove prior ELINE macro, as it's being clobbering by a new + * macro. Note that NSCOPED macros do not close out ELINE + * macros---they don't print text---so we let those slip by. + */ + + if ( ! (MAN_NSCOPED & man_macros[c].flags) && + m->flags & MAN_ELINE) { + assert(MAN_TEXT != m->last->type); + + /* + * This occurs in the following construction: + * .B + * .br + * .B + * .br + * I hate man macros. + * Flat-out disallow this madness. + */ + if (MAN_NSCOPED & man_macros[m->last->tok].flags) + return(man_perr(m, ln, ppos, WLNSCOPE)); - if (m->flags & MAN_ELINE) { n = m->last; + + assert(n); assert(NULL == n->child); assert(0 == n->nchild); + if ( ! man_nwarn(m, n, WLNSCOPE)) return(0); - if (n->prev) { - assert(n != n->parent->child); - assert(n == n->prev->next); - n->prev->next = NULL; - m->last = n->prev; - m->next = MAN_NEXT_SIBLING; - } else { - assert(n == n->parent->child); - n->parent->child = NULL; - m->last = n->parent; - m->next = MAN_NEXT_CHILD; - } - + man_node_unlink(m, n); man_node_free(n); m->flags &= ~MAN_ELINE; } @@ -565,9 +576,25 @@ man_pmacro(struct man *m, int ln, char *buf) goto err; out: - if ( ! (MAN_BLINE & fl) || (MAN_TEXT != m->last->type && - (NULL == m->last->child || MAN_TEXT != m->last->child->type))) + /* + * We weren't in a block-line scope when entering the + * above-parsed macro, so return. + */ + + if ( ! (MAN_BLINE & fl)) { + m->flags &= ~MAN_ILINE; return(1); + } + + /* + * If we're in a block scope, then allow this macro to slip by + * without closing scope around it. + */ + + if (MAN_ILINE & m->flags) { + m->flags &= ~MAN_ILINE; + return(1); + } /* * If we've opened a new next-line element scope, then return @@ -638,3 +665,28 @@ man_err(struct man *m, int line, int pos, int iserr, enum merr type) return(man_vwarn(m, line, pos, p)); } + + +void +man_node_unlink(struct man *m, struct man_node *n) +{ + + if (n->prev) { + n->prev->next = n->next; + if (m->last == n) { + assert(NULL == n->next); + m->last = n->prev; + m->next = MAN_NEXT_SIBLING; + } + } else { + n->parent->child = n->next; + if (m->last == n) { + assert(NULL == n->next); + m->last = n->parent; + m->next = MAN_NEXT_CHILD; + } + } + + if (n->next) + n->next->prev = n->prev; +} diff --git a/usr.bin/mandoc/man_action.c b/usr.bin/mandoc/man_action.c index ba0079c5ad0..ee9c20014a3 100644 --- a/usr.bin/mandoc/man_action.c +++ b/usr.bin/mandoc/man_action.c @@ -1,4 +1,4 @@ -/* $Id: man_action.c,v 1.12 2010/03/02 01:00:39 schwarze Exp $ */ +/* $Id: man_action.c,v 1.13 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -177,24 +177,8 @@ post_TH(struct man *m) if (n && (n = n->next)) m->meta.vol = mandoc_strdup(n->string); - /* - * The end document shouldn't have the prologue macros as part - * of the syntax tree (they encompass only meta-data). - */ - - if (m->last->parent->child == m->last) { - m->last->parent->child = NULL; - n = m->last; - m->last = m->last->parent; - m->next = MAN_NEXT_CHILD; - } else { - assert(m->last->prev); - m->last->prev->next = NULL; - n = m->last; - m->last = m->last->prev; - m->next = MAN_NEXT_SIBLING; - } - + n = m->last; + man_node_unlink(m, n); man_node_freelist(n); return(1); } diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index ec076849380..1d984a8833f 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.6 2010/03/02 01:00:39 schwarze Exp $ */ +/* $Id: man_html.c,v 1.7 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -180,6 +180,12 @@ 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, h); @@ -566,6 +572,8 @@ man_IP_pre(MAN_ARGS) SCALE_HS_INIT(&su, INDENT); width = 0; + /* Width is the last token. */ + if (MAN_IP == n->tok && NULL != nn) if (NULL != (nn = nn->next)) { for ( ; nn->next; nn = nn->next) @@ -573,8 +581,15 @@ man_IP_pre(MAN_ARGS) width = a2width(nn, &su); } - if (MAN_TP == n->tok && NULL != nn) - width = a2width(nn, &su); + /* Width is the first token. */ + + if (MAN_TP == n->tok && NULL != nn) { + /* Skip past non-text children. */ + while (nn && MAN_TEXT != nn->type) + nn = nn->next; + if (nn) + width = a2width(nn, &su); + } if (MAN_BLOCK == n->type) { bufcat_su(h, "margin-left", &su); @@ -599,11 +614,20 @@ man_IP_pre(MAN_ARGS) PAIR_STYLE_INIT(&tag, h); print_otag(h, TAG_DIV, 1, &tag); - /* With a length string, manually omit the last child. */ + /* + * Without a length string, we can print all of our children. + */ if ( ! width) return(1); + /* + * When a length has been specified, we need to carefully print + * our child context: IP gets all children printed but the last + * (the width), while TP gets all children printed but the first + * (the width). + */ + if (MAN_IP == n->tok) for (nn = n->child; nn->next; nn = nn->next) print_man_node(m, nn, h); diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 33832ecde15..c282ea3db7a 100644 --- a/usr.bin/mandoc/man_macro.c +++ b/usr.bin/mandoc/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.10 2010/03/02 01:00:39 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.11 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -36,7 +36,7 @@ static int rew_block(int, enum man_type, const struct man_node *); const struct man_macro __man_macros[MAN_MAX] = { - { in_line_eoln, 0 }, /* br */ + { in_line_eoln, MAN_NSCOPED }, /* br */ { in_line_eoln, 0 }, /* TH */ { blk_imp, MAN_SCOPED }, /* SH */ { blk_imp, MAN_SCOPED }, /* SS */ @@ -57,9 +57,9 @@ const struct man_macro __man_macros[MAN_MAX] = { { in_line_eoln, MAN_SCOPED }, /* I */ { in_line_eoln, 0 }, /* IR */ { in_line_eoln, 0 }, /* RI */ - { in_line_eoln, 0 }, /* na */ + { in_line_eoln, MAN_NSCOPED }, /* na */ { in_line_eoln, 0 }, /* i */ - { in_line_eoln, 0 }, /* sp */ + { in_line_eoln, MAN_NSCOPED }, /* sp */ { in_line_eoln, 0 }, /* nf */ { in_line_eoln, 0 }, /* fi */ { in_line_eoln, 0 }, /* r */ @@ -323,14 +323,29 @@ in_line_eoln(MACRO_PROT_ARGS) return(0); } + /* + * If no arguments are specified and this is MAN_SCOPED (i.e., + * next-line scoped), then set our mode to indicate that we're + * waiting for terms to load into our context. + */ + if (n == m->last && MAN_SCOPED & man_macros[tok].flags) { + assert( ! (MAN_NSCOPED & man_macros[tok].flags)); m->flags |= MAN_ELINE; return(1); } + /* Set ignorable context, if applicable. */ + + if (MAN_NSCOPED & man_macros[tok].flags) { + assert( ! (MAN_SCOPED & man_macros[tok].flags)); + m->flags |= MAN_ILINE; + } + /* - * Note that when TH is pruned, we'll be back at the root, so - * make sure that we don't clobber as its sibling. + * Rewind our element scope. Note that when TH is pruned, we'll + * be back at the root, so make sure that we don't clobber as + * its sibling. */ for ( ; m->last; m->last = m->last->parent) { diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 20c6d65d522..dcb24a50516 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.25 2010/03/02 01:24:04 schwarze Exp $ */ +/* $Id: man_term.c,v 1.26 2010/03/25 23:23:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -61,6 +61,8 @@ struct mtermp { struct termact { int (*pre)(DECL_ARGS); void (*post)(DECL_ARGS); + int flags; +#define MAN_NOTEXT (1 << 0) /* Never has text children. */ }; static int a2width(const struct man_node *); @@ -101,41 +103,41 @@ static void post_SS(DECL_ARGS); static void post_TP(DECL_ARGS); static const struct termact termacts[MAN_MAX] = { - { pre_br, NULL }, /* br */ - { NULL, NULL }, /* TH */ - { pre_SH, post_SH }, /* SH */ - { pre_SS, post_SS }, /* SS */ - { pre_TP, post_TP }, /* TP */ - { pre_PP, NULL }, /* LP */ - { pre_PP, NULL }, /* PP */ - { pre_PP, NULL }, /* P */ - { pre_IP, post_IP }, /* IP */ - { pre_HP, post_HP }, /* HP */ - { NULL, NULL }, /* SM */ - { pre_B, NULL }, /* SB */ - { pre_BI, NULL }, /* BI */ - { pre_BI, NULL }, /* IB */ - { pre_RB, NULL }, /* BR */ - { pre_RB, NULL }, /* RB */ - { NULL, NULL }, /* R */ - { pre_B, NULL }, /* B */ - { pre_I, NULL }, /* I */ - { pre_RI, NULL }, /* IR */ - { pre_RI, NULL }, /* RI */ - { NULL, NULL }, /* na */ - { pre_I, NULL }, /* i */ - { pre_sp, NULL }, /* sp */ - { pre_nf, NULL }, /* nf */ - { pre_fi, NULL }, /* fi */ - { NULL, NULL }, /* r */ - { NULL, NULL }, /* RE */ - { pre_RS, post_RS }, /* RS */ - { pre_ign, NULL }, /* DT */ - { pre_ign, NULL }, /* UC */ - { pre_ign, NULL }, /* PD */ - { pre_sp, NULL }, /* Sp */ - { pre_nf, NULL }, /* Vb */ - { pre_fi, NULL }, /* Ve */ + { pre_br, NULL, MAN_NOTEXT }, /* br */ + { NULL, NULL, 0 }, /* TH */ + { pre_SH, post_SH, 0 }, /* SH */ + { pre_SS, post_SS, 0 }, /* SS */ + { pre_TP, post_TP, 0 }, /* TP */ + { pre_PP, NULL, 0 }, /* LP */ + { pre_PP, NULL, 0 }, /* PP */ + { pre_PP, NULL, 0 }, /* P */ + { pre_IP, post_IP, 0 }, /* IP */ + { pre_HP, post_HP, 0 }, /* HP */ + { NULL, NULL, 0 }, /* SM */ + { pre_B, NULL, 0 }, /* SB */ + { pre_BI, NULL, 0 }, /* BI */ + { pre_BI, NULL, 0 }, /* IB */ + { pre_RB, NULL, 0 }, /* BR */ + { pre_RB, NULL, 0 }, /* RB */ + { NULL, NULL, 0 }, /* R */ + { pre_B, NULL, 0 }, /* B */ + { pre_I, NULL, 0 }, /* I */ + { pre_RI, NULL, 0 }, /* IR */ + { pre_RI, NULL, 0 }, /* RI */ + { NULL, NULL, MAN_NOTEXT }, /* na */ + { pre_I, NULL, 0 }, /* i */ + { pre_sp, NULL, MAN_NOTEXT }, /* sp */ + { pre_nf, NULL, 0 }, /* nf */ + { pre_fi, NULL, 0 }, /* fi */ + { NULL, NULL, 0 }, /* r */ + { NULL, NULL, 0 }, /* RE */ + { pre_RS, post_RS, 0 }, /* RS */ + { pre_ign, NULL, 0 }, /* DT */ + { pre_ign, NULL, 0 }, /* UC */ + { pre_ign, NULL, 0 }, /* PD */ + { pre_sp, NULL, MAN_NOTEXT }, /* Sp */ + { pre_nf, NULL, 0 }, /* Vb */ + { pre_fi, NULL, 0 }, /* Ve */ }; @@ -808,7 +810,8 @@ print_man_node(DECL_ARGS) } break; default: - term_fontrepl(p, TERMFONT_NONE); + 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; @@ -820,7 +823,8 @@ print_man_node(DECL_ARGS) if (MAN_TEXT != n->type) { if (termacts[n->tok].post) (*termacts[n->tok].post)(p, mt, n, m); - term_fontrepl(p, TERMFONT_NONE); + if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) + term_fontrepl(p, TERMFONT_NONE); } } diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 7dbf90bbb92..d34f39e56d3 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.21 2010/02/18 02:11:26 schwarze Exp $ +.\" $Id: mandoc.1,v 1.22 2010/03/25 23:23:01 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 18 2010 $ +.Dd $Mdocdate: March 25 2010 $ .Dt MANDOC 1 .Os . @@ -502,8 +502,8 @@ and .Fl T Ns Ar xhtml CSS2 styling used for .Fl m Ns Ar doc -input lists does not render properly in brain-dead browsers, such as -Internet Explorer 6 and earlier. +input lists does not render properly in older browsers, such as Internet +Explorer 6 and earlier. .Pp In .Fl T Ns Ar html @@ -525,3 +525,15 @@ font size escape documented in .Xr mdoc 7 and .Xr man 7 . +.Pp +Nesting elements within next-line element scopes of +.Fl m Ar Ns an , +such as +.Sq br +within an empty +.Sq B , +will confuse +.Fl T Ns Ar html +and +.Fl T Ns Ar xhtml +and cause it to forget the formatting. |