diff options
author | 2012-12-31 22:34:01 +0000 | |
---|---|---|
committer | 2012-12-31 22:34:01 +0000 | |
commit | a14e0b203cb198751d379335fb5d870efe7d83f2 (patch) | |
tree | 1c252c2f8cf38f36b732f0649298194424862ba3 | |
parent | Do not mail out diffs of the /etc/moduli file. (diff) | |
download | wireguard-openbsd-a14e0b203cb198751d379335fb5d870efe7d83f2.tar.xz wireguard-openbsd-a14e0b203cb198751d379335fb5d870efe7d83f2.zip |
Rewrite indentation handling for nested lists in a more systematic way
to fix multiple issues reported by Todd Miller; thanks!
Specifically,
- avoid double indentation after .Bd inside .Bl
- set up correct indentation after .Bl inside .Bl
- set up correct indentation after .Dl and .D1 inside .Bl
While here, also
- set up correct indentation *inside* .Dl and .D1 inside .Bl.
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bl/nested.in | 32 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bl/nested.out_ascii | 24 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bl/tag.in | 12 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bl/tag.out_ascii | 10 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_man.c | 84 |
5 files changed, 121 insertions, 41 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/nested.in b/regress/usr.bin/mandoc/mdoc/Bl/nested.in index 5e59eeea1a0..c02a433230e 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/nested.in +++ b/regress/usr.bin/mandoc/mdoc/Bl/nested.in @@ -1,4 +1,4 @@ -.Dd April 12, 2010 +.Dd December 31, 2012 .Dt BL-NESTED 1 .Os OpenBSD .Sh NAME @@ -41,4 +41,34 @@ outer list inner list .El .El +tag: +.Bl -tag -width 4n +.It outer tag +outer text +.Bl -tag -width 4n +.It inner tag +inner text +.El +outer text +.El +.Bl -tag -width 4n +.It outer tag +.Bd -ragged -compact +outer text (display) +.Ed +.Bl -tag -width 4n +.It inner tag +inner text +.El +outer text +.El +.Bl -tag -width 4n +.It outer tag +.Dl outer text (one-line display) +.Bl -tag -width 4n +.It inner tag +inner text +.El +outer text +.El final text diff --git a/regress/usr.bin/mandoc/mdoc/Bl/nested.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/nested.out_ascii index b1db12657c1..c4185625125 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/nested.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bl/nested.out_ascii @@ -20,6 +20,28 @@ DDEESSCCRRIIPPTTIIOONN dash compact: -- outer list -- inner list + tag: + + outer tag + outer text + + inner tag + inner text + outer text + + outer tag + outer text (display) + + inner tag + inner text + outer text + + outer tag + outer text (one-line display) + + inner tag + inner text + outer text final text -OpenBSD April 12, 2010 OpenBSD +OpenBSD December 31, 2012 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Bl/tag.in b/regress/usr.bin/mandoc/mdoc/Bl/tag.in index a211ec8e020..aa363567be0 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/tag.in +++ b/regress/usr.bin/mandoc/mdoc/Bl/tag.in @@ -1,4 +1,4 @@ -.Dd November 18, 2012 +.Dd December 31, 2012 .Dt BL-TAG 1 .Os OpenBSD .Sh NAME @@ -48,7 +48,7 @@ b b .El .Pp -Non-numeric with specification: +Non-numeric width specification: .Bl -tag -width xxx .It tag text @@ -57,3 +57,11 @@ text .It tag text .El +.Pp +Embedded paragraph: +.Bl -tag -width Ds +.It tag +first paragraph +.Pp +second paragraph +.El diff --git a/regress/usr.bin/mandoc/mdoc/Bl/tag.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/tag.out_ascii index 340c5d3af87..4de81918454 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/tag.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bl/tag.out_ascii @@ -41,10 +41,16 @@ DDEESSCCRRIIPPTTIIOONN a b - Non-numeric with specification: + Non-numeric width specification: tag text tag text -OpenBSD November 18, 2012 OpenBSD + Embedded paragraph: + + tag first paragraph + + second paragraph + +OpenBSD December 31, 2012 OpenBSD diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 52483989b4b..e8cf9c82a86 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.45 2012/11/19 02:14:39 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.46 2012/12/31 22:34:01 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * @@ -39,6 +39,7 @@ static int cond_body(DECL_ARGS); static int cond_head(DECL_ARGS); static void font_push(char); static void font_pop(void); +static void mid_it(void); static void post__t(DECL_ARGS); static void post_bd(DECL_ARGS); static void post_bf(DECL_ARGS); @@ -438,6 +439,9 @@ print_offs(const char *v) print_word(buf); } +/* + * Set up the indentation for a list item; used from pre_it(). + */ void print_width(const char *v, const struct mdoc_node *child, size_t defsz) { @@ -466,16 +470,8 @@ print_width(const char *v, const struct mdoc_node *child, size_t defsz) chsz = (NULL != child && MDOC_TEXT == child->type) ? strlen(child->string) : 0; - /* - * If we are inside an enclosing list, - * preserve its indentation. - */ - if (Bl_stack_len && Bl_stack[Bl_stack_len - 1]) { - print_line(".RS", MMAN_Bk_susp); - snprintf(buf, sizeof(buf), "%ldn", - Bl_stack[Bl_stack_len - 1]); - print_word(buf); - } + /* Maybe we are inside an enclosing list? */ + mid_it(); /* * Save our own indentation, @@ -834,7 +830,6 @@ pre_bd(DECL_ARGS) static void post_bd(DECL_ARGS) { - char buf[24]; /* Close out this display. */ print_line(".RE", MMAN_nl); @@ -842,20 +837,9 @@ post_bd(DECL_ARGS) DISP_literal == n->norm->Bd.type) print_line(".fi", MMAN_nl); - /* - * If we are inside an enclosing list and the current - * list item is not yet finished, restore the correct - * indentation for what remains of that item. - */ - if (NULL != n->parent->next && - Bl_stack_len && Bl_stack[Bl_stack_len - 1]) { - print_line(".RS", MMAN_Bk_susp); - snprintf(buf, sizeof(buf), "%ldn", - Bl_stack[Bl_stack_len - 1]); - print_word(buf); - /* Remeber to close out this .RS block later. */ - Bl_stack_post[Bl_stack_len - 1] = 1; - } + /* Maybe we are inside an enclosing list? */ + if (NULL != n->parent->next) + mid_it(); } static int @@ -954,6 +938,11 @@ post_bl(DECL_ARGS) } outflags |= MMAN_PP | MMAN_nl; outflags &= ~(MMAN_sp | MMAN_br); + + /* Maybe we are inside an enclosing list? */ + if (NULL != n->parent->next) + mid_it(); + } static int @@ -988,7 +977,9 @@ static int pre_dl(DECL_ARGS) { - print_line(".RS 6n", MMAN_nl); + print_line(".RS", MMAN_Bk_susp); + print_offs("6n"); + outflags |= MMAN_nl; return(1); } @@ -997,6 +988,10 @@ post_dl(DECL_ARGS) { print_line(".RE", MMAN_nl); + + /* Maybe we are inside an enclosing list? */ + if (NULL != n->parent->next) + mid_it(); } static int @@ -1259,6 +1254,32 @@ pre_it(DECL_ARGS) return(1); } +/* + * This function is called after closing out an indented block. + * If we are inside an enclosing list, restore its indentation. + */ +static void +mid_it(void) +{ + char buf[24]; + + /* Nothing to do outside a list. */ + if (0 == Bl_stack_len || 0 == Bl_stack[Bl_stack_len - 1]) + return; + + /* The indentation has already been set up. */ + if (Bl_stack_post[Bl_stack_len - 1]) + return; + + /* Restore the indentation of the enclosing list. */ + print_line(".RS", MMAN_Bk_susp); + snprintf(buf, sizeof(buf), "%ldn", Bl_stack[Bl_stack_len - 1]); + print_word(buf); + + /* Remeber to close out this .RS block later. */ + Bl_stack_post[Bl_stack_len - 1] = 1; +} + static void post_it(DECL_ARGS) { @@ -1298,20 +1319,13 @@ post_it(DECL_ARGS) /* * Our indentation had to be restored - * after a child display. + * after a child display or child list. * Close out that indentation block now. */ if (Bl_stack_post[Bl_stack_len]) { print_line(".RE", MMAN_nl); Bl_stack_post[Bl_stack_len] = 0; } - - /* - * We are inside an enclosing list. - * Restore the indentation of that list. - */ - if (Bl_stack_len && Bl_stack[Bl_stack_len - 1]) - print_line(".RE", MMAN_nl); break; case (LIST_column): if (NULL != n->next) { |