diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-10 19:53:13 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-10 19:53:13 +0000 |
commit | 80f833cf040f5fefb18badd53d2aa008031c4946 (patch) | |
tree | 19322c57b3a2345bae267d2958370f4a53aab659 | |
parent | 02452d0882c9712c3bf2f3111250cde6426730bf (diff) |
multiple fixes to -Tascii .HP rendering:
* do not add an excessive blank line before the block
* in literal mode, start a new line after the tag
getting this to work requires some general (print_man_node) fixes:
* in literal mode, break the output line at the end of each
input line, not just after those input lines ending in text
* but don't break it when there was no output on the line
* and adjust the margins after the .HP tag
these general fixes require an adjustment to -Tascii .TP rendering:
* set up NOBREAK mode before the body, not after the head
finally, based on all this, implement -Tman .Bl -hang in terms of .HP
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/Makefile | 5 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/literal.in | 26 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/literal.out_ascii | 27 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/macrotag.in | 13 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/macrotag.out_ascii | 17 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/manyargs.in | 45 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/manyargs.out_ascii | 43 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/spacing.in | 25 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/HP/spacing.out_ascii | 27 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/Makefile | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/nf/indent.in | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/man/nf/indent.out_ascii | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Bl/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/man_term.c | 69 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_man.c | 32 |
15 files changed, 299 insertions, 46 deletions
diff --git a/regress/usr.bin/mandoc/man/HP/Makefile b/regress/usr.bin/mandoc/man/HP/Makefile new file mode 100644 index 00000000000..50e5e9d8826 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2012/07/10 19:53:12 schwarze Exp $ + +REGRESS_TARGETS = literal spacing manyargs macrotag + +.include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/man/HP/literal.in b/regress/usr.bin/mandoc/man/HP/literal.in new file mode 100644 index 00000000000..e7caee1cc73 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/literal.in @@ -0,0 +1,26 @@ +.TH HP-LITERAL 1 "January 4, 2011" OpenBSD +.SH NAME +HP-literal \- hanged paragraphs in literal context +.SH DESCRIPTION +regular +text +.HP 10n +tag +indented +text +.PP +regular +text +.nf +literal +text +.HP 10n +tag +indented +text +.PP +literal +text +.fi +regular +text diff --git a/regress/usr.bin/mandoc/man/HP/literal.out_ascii b/regress/usr.bin/mandoc/man/HP/literal.out_ascii new file mode 100644 index 00000000000..6facd371dcc --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/literal.out_ascii @@ -0,0 +1,27 @@ +HP-LITERAL(1) OpenBSD Reference Manual HP-LITERAL(1) + + + +NNAAMMEE + HP-literal - hanged paragraphs in literal context + +DDEESSCCRRIIPPTTIIOONN + regular text + + tag indented text + + regular text + literal + text + + tag + indented + text + + literal + text + regular text + + + +OpenBSD January 4, 2011 HP-LITERAL(1) diff --git a/regress/usr.bin/mandoc/man/HP/macrotag.in b/regress/usr.bin/mandoc/man/HP/macrotag.in new file mode 100644 index 00000000000..6582498c4df --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/macrotag.in @@ -0,0 +1,13 @@ +.TH HP-MACROTAG 1 "September 20, 2011" OpenBSD +.SH NAME +HP-macrotag \- macro in the head of a tagged paragraph +.SH DESCRIPTION +regular +text +.HP +.B longindent +indented +text +.PP +regular +text diff --git a/regress/usr.bin/mandoc/man/HP/macrotag.out_ascii b/regress/usr.bin/mandoc/man/HP/macrotag.out_ascii new file mode 100644 index 00000000000..deb7daa9d08 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/macrotag.out_ascii @@ -0,0 +1,17 @@ +HP-MACROTAG(1) OpenBSD Reference Manual HP-MACROTAG(1) + + + +NNAAMMEE + HP-macrotag - macro in the head of a tagged paragraph + +DDEESSCCRRIIPPTTIIOONN + regular text + + lloonnggiinnddeenntt indented text + + regular text + + + +OpenBSD September 20, 2011 HP-MACROTAG(1) diff --git a/regress/usr.bin/mandoc/man/HP/manyargs.in b/regress/usr.bin/mandoc/man/HP/manyargs.in new file mode 100644 index 00000000000..b49e6649863 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/manyargs.in @@ -0,0 +1,45 @@ +.TH HP-MANYARGS 1 "January 4, 2011" OpenBSD +.SH NAME +HP-manyargs \- too many header args for hanged blocks +.SH DESCRIPTION +regular +text +.HP 10n +tag1 +indented +text +.PP +regular +text +.HP 10n tag1 +tag2 +indented +text +.PP +regular +text +.HP 10n tag2 tag1 +tag3 +indented +text +.nf +literal +text +.HP 10n +tag1 +indented +text +.PP +literal +text +.HP 10n tag1 +tag2 +indented +text +.PP +literal +text +.HP 10n tag2 tag1 +tag3 +indented +text diff --git a/regress/usr.bin/mandoc/man/HP/manyargs.out_ascii b/regress/usr.bin/mandoc/man/HP/manyargs.out_ascii new file mode 100644 index 00000000000..087ccda48f5 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/manyargs.out_ascii @@ -0,0 +1,43 @@ +HP-MANYARGS(1) OpenBSD Reference Manual HP-MANYARGS(1) + + + +NNAAMMEE + HP-manyargs - too many header args for hanged blocks + +DDEESSCCRRIIPPTTIIOONN + regular text + + tag1 indented text + + regular text + + tag2 indented text + + regular text + + tag3 indented text + literal + text + + tag1 + indented + text + + literal + text + + tag2 + indented + text + + literal + text + + tag3 + indented + text + + + +OpenBSD January 4, 2011 HP-MANYARGS(1) diff --git a/regress/usr.bin/mandoc/man/HP/spacing.in b/regress/usr.bin/mandoc/man/HP/spacing.in new file mode 100644 index 00000000000..550b27fe3d5 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/spacing.in @@ -0,0 +1,25 @@ +.TH HP-SPACING 1 "February 5, 2011" OpenBSD +.SH NAME +HP-spacing \- spacing in hanged lists +.SH DESCRIPTION +Normal text. +.HP +tag +Indented text. +.HP +four +Indented text. +.HP +ffive +Indented text. +.HP +sixsix +Indented text. +.HP +seseven +Indented text. +.HP +a much longer tag +Indented text. +.LP +Normal text. diff --git a/regress/usr.bin/mandoc/man/HP/spacing.out_ascii b/regress/usr.bin/mandoc/man/HP/spacing.out_ascii new file mode 100644 index 00000000000..0cd618e17b9 --- /dev/null +++ b/regress/usr.bin/mandoc/man/HP/spacing.out_ascii @@ -0,0 +1,27 @@ +HP-SPACING(1) OpenBSD Reference Manual HP-SPACING(1) + + + +NNAAMMEE + HP-spacing - spacing in hanged lists + +DDEESSCCRRIIPPTTIIOONN + Normal text. + + tag Indented text. + + four Indented text. + + ffive Indented text. + + sixsix Indented text. + + seseven Indented text. + + a much longer tag Indented text. + + Normal text. + + + +OpenBSD February 5, 2011 HP-SPACING(1) diff --git a/regress/usr.bin/mandoc/man/Makefile b/regress/usr.bin/mandoc/man/Makefile index b7641eded6f..592ce732287 100644 --- a/regress/usr.bin/mandoc/man/Makefile +++ b/regress/usr.bin/mandoc/man/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.8 2012/07/07 17:47:58 schwarze Exp $ +# $OpenBSD: Makefile,v 1.9 2012/07/10 19:53:12 schwarze Exp $ -SUBDIR= nf BI EX IP PP RS TH TP +SUBDIR = nf BI EX HP IP PP RS TH TP ascii groff groff-clean obj-clean tman: _SUBDIRUSE diff --git a/regress/usr.bin/mandoc/man/nf/indent.in b/regress/usr.bin/mandoc/man/nf/indent.in index d776541b02b..8c6aedbb669 100644 --- a/regress/usr.bin/mandoc/man/nf/indent.in +++ b/regress/usr.bin/mandoc/man/nf/indent.in @@ -11,6 +11,10 @@ and three words This is a very long line; because it is indented, it is a bit too long to fit. blank line: +line with only a zero-width space: +\& +line with only a normal space character: + end of literal .fi He is some more diff --git a/regress/usr.bin/mandoc/man/nf/indent.out_ascii b/regress/usr.bin/mandoc/man/nf/indent.out_ascii index 970c11f8bc9..a2fb7f7893c 100644 --- a/regress/usr.bin/mandoc/man/nf/indent.out_ascii +++ b/regress/usr.bin/mandoc/man/nf/indent.out_ascii @@ -13,6 +13,10 @@ DDEESSCCRRIIPPTTIIOONN This is a very long line; because it is indented, it is a bit too long to fit. blank line: + line with only a zero-width space: + + line with only a normal space character: + end of literal He is some more regular text. diff --git a/regress/usr.bin/mandoc/mdoc/Bl/Makefile b/regress/usr.bin/mandoc/mdoc/Bl/Makefile index 34d28159333..0ff97ce5b11 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Bl/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.10 2012/07/10 15:33:41 schwarze Exp $ +# $OpenBSD: Makefile,v 1.11 2012/07/10 19:53:12 schwarze Exp $ REGRESS_TARGETS = item inset diag ohang bullet dash enum hang tag REGRESS_TARGETS += column extend nested @@ -10,6 +10,6 @@ REGRESS_TARGETS+=multitype multitag empty unclosed SKIP_GROFF ?= empty -SKIP_TMAN ?= tag hang column extend nested multitype multitag empty +SKIP_TMAN ?= tag column extend nested multitype multitag empty .include <bsd.regress.mk> diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index ba7ae8bfc5f..03a612ad28b 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,7 +1,7 @@ -/* $Id: man_term.c,v 1.83 2012/06/02 20:07:09 schwarze Exp $ */ +/* $Id: man_term.c,v 1.84 2012/07/10 19:53:11 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -476,13 +476,16 @@ pre_HP(DECL_ARGS) print_bvspace(p, n); return(1); case (MAN_BODY): - p->flags |= TERMP_NOBREAK; - p->flags |= TERMP_TWOSPACE; break; default: return(0); } + if ( ! (MANT_LITERAL & mt->fl)) { + p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_TWOSPACE; + } + len = mt->lmargin[mt->lmargincur]; ival = -1; @@ -512,9 +515,6 @@ post_HP(DECL_ARGS) { switch (n->type) { - case (MAN_BLOCK): - term_flushln(p); - break; case (MAN_BODY): term_flushln(p); p->flags &= ~TERMP_NOBREAK; @@ -692,6 +692,8 @@ pre_TP(DECL_ARGS) case (MAN_BODY): p->offset = mt->offset + len; p->rmargin = p->maxrmargin; + p->flags &= ~TERMP_NOBREAK; + p->flags &= ~TERMP_TWOSPACE; break; default: break; @@ -709,9 +711,6 @@ post_TP(DECL_ARGS) switch (n->type) { case (MAN_HEAD): term_flushln(p); - p->flags &= ~TERMP_NOBREAK; - p->flags &= ~TERMP_TWOSPACE; - p->rmargin = p->maxrmargin; break; case (MAN_BODY): term_newln(p); @@ -908,29 +907,8 @@ print_man_node(DECL_ARGS) term_newln(p); term_word(p, n->string); + goto out; - /* - * 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 && ! (TERMP_NOBREAK & p->flags) && - (NULL == n->next || - n->next->line > n->line)) { - rm = p->rmargin; - rmax = p->maxrmargin; - p->rmargin = p->maxrmargin = TERM_MAXMARGIN; - p->flags |= TERMP_NOSPACE; - term_flushln(p); - p->rmargin = rm; - p->maxrmargin = rmax; - } - - if (MAN_EOS & n->flags) - p->flags |= TERMP_SENTENCE; - return; case (MAN_EQN): term_eqn(p, n->eqn); return; @@ -962,6 +940,31 @@ print_man_node(DECL_ARGS) if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) term_fontrepl(p, TERMFONT_NONE); +out: + /* + * If we're in a literal context, make sure that words + * together 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 && ! (TERMP_NOBREAK & p->flags) && + NULL != n->next && n->next->line > n->line) { + rm = p->rmargin; + rmax = p->maxrmargin; + p->rmargin = p->maxrmargin = TERM_MAXMARGIN; + p->flags |= TERMP_NOSPACE; + if (NULL != n->string && '\0' != *n->string) + term_flushln(p); + else + term_newln(p); + if (rm < rmax && n->parent->tok == MAN_HP) { + p->offset = rm; + p->rmargin = rmax; + } else + p->rmargin = rm; + p->maxrmargin = rmax; + } if (MAN_EOS & n->flags) p->flags |= TERMP_SENTENCE; } diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index d38ada18b3c..f455fb5fe8b 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.28 2012/07/10 14:35:57 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.29 2012/07/10 19:53:11 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * @@ -96,7 +96,7 @@ static int pre_ux(DECL_ARGS); static int pre_xr(DECL_ARGS); static void print_word(const char *); static void print_offs(const char *); -static void print_width(const char *); +static void print_width(const char *, const struct mdoc_node *); static void print_count(int *); static void print_node(DECL_ARGS); @@ -356,22 +356,34 @@ print_offs(const char *v) } void -print_width(const char *v) +print_width(const char *v, const struct mdoc_node *child) { char buf[24]; struct roffsu su; - size_t sz; + size_t sz, chsz; + + /* XXX Rough estimation, might have multiple parts. */ + chsz = (NULL != child && MDOC_TEXT == child->type) ? + strlen(child->string) : 0; if (a2roffsu(v, &su, SCALE_MAX)) { if (SCALE_EN == su.unit) sz = su.scale; else { + if (chsz) + print_word(".HP"); + else + print_word(".TP"); print_word(v); return; } } else sz = strlen(v); + if (chsz > sz) + print_word(".HP"); + else + print_word(".TP"); snprintf(buf, sizeof(buf), "%ldn", sz + 2); print_word(buf); } @@ -1023,8 +1035,7 @@ pre_it(DECL_ARGS) case (LIST_dash): /* FALLTHROUGH */ case (LIST_hyphen): - print_word(".TP"); - print_width(bln->norm->Bl.width); + print_width(bln->norm->Bl.width, NULL); outflags |= MMAN_nl; font_push('B'); if (LIST_bullet == bln->norm->Bl.type) @@ -1034,15 +1045,18 @@ pre_it(DECL_ARGS) font_pop(); break; case (LIST_enum): - print_word(".TP"); - print_width(bln->norm->Bl.width); + print_width(bln->norm->Bl.width, NULL); outflags |= MMAN_nl; print_count(&bln->norm->Bl.count); outflags |= MMAN_nl; break; + case (LIST_hang): + print_width(bln->norm->Bl.width, n->child); + outflags |= MMAN_nl; + break; default: if (bln->norm->Bl.width) - print_width(bln->norm->Bl.width); + print_width(bln->norm->Bl.width, n->child); break; } outflags |= MMAN_nl; |