From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Cc: naddy@openbsd.org
Subject: [PATCH] man(7) .IP and .TP in literal mode
Date: Sun, 2 Jan 2011 13:41:18 +0100 [thread overview]
Message-ID: <20110102124118.GA21085@iris.usta.de> (raw)
Hi,
finally, i came around to finish the bunch of fixes to .IP and .TP
started during p2k10. Naddy, if you still remember which port it was
that needed this, feel free to re-test; otherwise, just ignore me.
Unfortunately, i don't remeber any more which one it was...
This is what needed fixing:
* The .IP HEAD uses the second argument as the width, not the last one.
* The .IP and .TP HEADs must be printed without literal mode, but literal
mode must be restored afterwards.
* After the .IP and .TP bodies, we only want term_newln(), not
term_flushln(), or we would get two blank lines in literal mode.
* The .TP HEAD does not use TWOSPACE, just like .IP doesn't either.
* In literal mode, clear NOLPAD after each line, or subsequent lines
would get no indentation whatsoever.
OK?
Yours,
Ingo
Index: usr.bin/mandoc/man_term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/man_term.c,v
retrieving revision 1.56
diff -u -p -r1.56 man_term.c
--- usr.bin/mandoc/man_term.c 19 Dec 2010 07:53:12 -0000 1.56
+++ usr.bin/mandoc/man_term.c 2 Jan 2011 12:09:53 -0000
@@ -514,7 +514,7 @@ pre_IP(DECL_ARGS)
{
const struct man_node *nn;
size_t len;
- int ival;
+ int savelit, ival;
switch (n->type) {
case (MAN_BODY):
@@ -534,15 +534,11 @@ pre_IP(DECL_ARGS)
len = mt->lmargin;
ival = -1;
- /* Calculate offset. */
-
+ /* Calculate the offset from the optional second argument. */
if (NULL != (nn = n->parent->head->child))
- if (NULL != (nn = nn->next)) {
- for ( ; nn->next; nn = nn->next)
- /* Do nothing. */ ;
+ if (NULL != (nn = nn->next))
if ((ival = a2width(p, nn->string)) >= 0)
len = (size_t)ival;
- }
switch (n->type) {
case (MAN_HEAD):
@@ -558,9 +554,15 @@ pre_IP(DECL_ARGS)
/* Set the saved left-margin. */
mt->lmargin = (size_t)ival;
- /* Don't print the length value. */
- for (nn = n->child; nn->next; nn = nn->next)
- print_man_node(p, mt, nn, m);
+ savelit = MANT_LITERAL & mt->fl;
+ mt->fl &= ~MANT_LITERAL;
+
+ if (n->child)
+ print_man_node(p, mt, n->child, m);
+
+ if (savelit)
+ mt->fl |= MANT_LITERAL;
+
return(0);
case (MAN_BODY):
p->offset = mt->offset + len;
@@ -586,7 +588,7 @@ post_IP(DECL_ARGS)
p->rmargin = p->maxrmargin;
break;
case (MAN_BODY):
- term_flushln(p);
+ term_newln(p);
p->flags &= ~TERMP_NOLPAD;
break;
default:
@@ -601,12 +603,11 @@ pre_TP(DECL_ARGS)
{
const struct man_node *nn;
size_t len;
- int ival;
+ int savelit, ival;
switch (n->type) {
case (MAN_HEAD):
p->flags |= TERMP_NOBREAK;
- p->flags |= TERMP_TWOSPACE;
break;
case (MAN_BODY):
p->flags |= TERMP_NOLPAD;
@@ -641,11 +642,17 @@ pre_TP(DECL_ARGS)
p->offset = mt->offset;
p->rmargin = mt->offset + len;
+ savelit = MANT_LITERAL & mt->fl;
+ mt->fl &= ~MANT_LITERAL;
+
/* Don't print same-line elements. */
- for (nn = n->child; nn; nn = nn->next)
+ for (nn = n->child; nn; nn = nn->next)
if (nn->line > n->line)
print_man_node(p, mt, nn, m);
+ if (savelit)
+ mt->fl |= MANT_LITERAL;
+
if (ival >= 0)
mt->lmargin = (size_t)ival;
@@ -675,7 +682,7 @@ post_TP(DECL_ARGS)
p->rmargin = p->maxrmargin;
break;
case (MAN_BODY):
- term_flushln(p);
+ term_newln(p);
p->flags &= ~TERMP_NOLPAD;
break;
default:
@@ -877,6 +884,7 @@ print_man_node(DECL_ARGS)
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
p->flags |= TERMP_NOSPACE;
term_flushln(p);
+ p->flags &= ~TERMP_NOLPAD;
p->rmargin = rm;
p->maxrmargin = rmax;
}
Index: regress/usr.bin/mandoc/man/Makefile
===================================================================
RCS file: regress/usr.bin/mandoc/man/Makefile
diff -N regress/usr.bin/mandoc/man/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/Makefile 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.10 2010/12/19 12:10:33 schwarze Exp $
+
+SUBDIR= nf IP TP
+
+groff groff-clean: _SUBDIRUSE
+
+.include <bsd.subdir.mk>
Index: regress/usr.bin/mandoc/man/Makefile.inc
===================================================================
RCS file: regress/usr.bin/mandoc/man/Makefile.inc
diff -N regress/usr.bin/mandoc/man/Makefile.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/Makefile.inc 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,3 @@
+# $OpenBSD: Makefile.inc,v 1.1 2009/10/28 03:20:42 schwarze Exp $
+
+.include "../Makefile.inc"
Index: regress/usr.bin/mandoc/man/IP/Makefile
===================================================================
RCS file: regress/usr.bin/mandoc/man/IP/Makefile
diff -N regress/usr.bin/mandoc/man/IP/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/IP/Makefile 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2010/07/01 05:29:57 schwarze Exp $
+
+REGRESS_TARGETS=literal width
+GROFF_TARGETS=literal width
+
+.include <bsd.regress.mk>
Index: regress/usr.bin/mandoc/man/IP/literal.in
===================================================================
RCS file: regress/usr.bin/mandoc/man/IP/literal.in
diff -N regress/usr.bin/mandoc/man/IP/literal.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/IP/literal.in 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,24 @@
+.TH IP-LITERAL 1
+.SH NAME
+IP-literal \- indented paragraphs in literal context
+.SH DESCRIPTION
+regular
+text
+.IP tag 10n
+indented
+text
+.PP
+regular
+text
+.nf
+literal
+text
+.IP tag 10n
+indented
+text
+.PP
+literal
+text
+.fi
+regular
+text
Index: regress/usr.bin/mandoc/man/IP/literal.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/man/IP/literal.out_ascii
diff -N regress/usr.bin/mandoc/man/IP/literal.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/IP/literal.out_ascii 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,25 @@
+IP-LITERAL(1) IP-LITERAL(1)
+
+
+
+N\bNA\bAM\bME\bE
+ IP-literal - indented paragraphs in literal context
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ regular text
+
+ tag indented text
+
+ regular text
+ literal
+ text
+
+ tag indented
+ text
+
+ literal
+ text
+ regular text
+
+
+
Index: regress/usr.bin/mandoc/man/IP/width.in
===================================================================
RCS file: regress/usr.bin/mandoc/man/IP/width.in
diff -N regress/usr.bin/mandoc/man/IP/width.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/IP/width.in 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,43 @@
+.TH IP-WIDTH 1
+.SH NAME
+IP-width \- indentation width of indented paragraphs
+.SH DESCRIPTION
+Regular mode:
+.IP tag 1n
+indented
+.br
+text
+.IP tag 2n
+indented
+.br
+text
+.IP tag 3n
+indented
+.br
+text
+.IP tag 4n
+indented
+.br
+text
+.IP tag 5n
+indented
+.br
+text
+.PP
+Literal mode:
+.nf
+.IP tag 1n
+indented
+text
+.IP tag 2n
+indented
+text
+.IP tag 3n
+indented
+text
+.IP tag 4n
+indented
+text
+.IP tag 5n
+indented
+text
Index: regress/usr.bin/mandoc/man/IP/width.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/man/IP/width.out_ascii
diff -N regress/usr.bin/mandoc/man/IP/width.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/IP/width.out_ascii 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,50 @@
+IP-WIDTH(1) IP-WIDTH(1)
+
+
+
+N\bNA\bAM\bME\bE
+ IP-width - indentation width of indented paragraphs
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ Regular mode:
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag indented
+ text
+
+ tag indented
+ text
+
+ Literal mode:
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag indented
+ text
+
+ tag indented
+ text
+
+
+
Index: regress/usr.bin/mandoc/man/TP/Makefile
===================================================================
RCS file: regress/usr.bin/mandoc/man/TP/Makefile
diff -N regress/usr.bin/mandoc/man/TP/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/TP/Makefile 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2010/07/01 05:29:57 schwarze Exp $
+
+REGRESS_TARGETS=literal width
+GROFF_TARGETS=literal width
+
+.include <bsd.regress.mk>
Index: regress/usr.bin/mandoc/man/TP/literal.in
===================================================================
RCS file: regress/usr.bin/mandoc/man/TP/literal.in
diff -N regress/usr.bin/mandoc/man/TP/literal.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/TP/literal.in 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,26 @@
+.TH TP-LITERAL 1
+.SH NAME
+TP-literal \- indented paragraphs in literal context
+.SH DESCRIPTION
+regular
+text
+.TP 10n
+tag
+indented
+text
+.PP
+regular
+text
+.nf
+literal
+text
+.TP 10n
+tag
+indented
+text
+.PP
+literal
+text
+.fi
+regular
+text
Index: regress/usr.bin/mandoc/man/TP/literal.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/man/TP/literal.out_ascii
diff -N regress/usr.bin/mandoc/man/TP/literal.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/TP/literal.out_ascii 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,25 @@
+TP-LITERAL(1) TP-LITERAL(1)
+
+
+
+N\bNA\bAM\bME\bE
+ TP-literal - indented paragraphs in literal context
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ regular text
+
+ tag indented text
+
+ regular text
+ literal
+ text
+
+ tag indented
+ text
+
+ literal
+ text
+ regular text
+
+
+
Index: regress/usr.bin/mandoc/man/TP/width.in
===================================================================
RCS file: regress/usr.bin/mandoc/man/TP/width.in
diff -N regress/usr.bin/mandoc/man/TP/width.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/TP/width.in 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,53 @@
+.TH TP-WIDTH 1
+.SH NAME
+TP-width \- indentation width of indented paragraphs
+.SH DESCRIPTION
+Regular mode:
+.TP 1n
+tag
+indented
+.br
+text
+.TP 2n
+tag
+indented
+.br
+text
+.TP 3n
+tag
+indented
+.br
+text
+.TP 4n
+tag
+indented
+.br
+text
+.TP 5n
+tag
+indented
+.br
+text
+.PP
+Literal mode:
+.nf
+.TP 1n
+tag
+indented
+text
+.TP 2n
+tag
+indented
+text
+.TP 3n
+tag
+indented
+text
+.TP 4n
+tag
+indented
+text
+.TP 5n
+tag
+indented
+text
Index: regress/usr.bin/mandoc/man/TP/width.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/man/TP/width.out_ascii
diff -N regress/usr.bin/mandoc/man/TP/width.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/TP/width.out_ascii 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,50 @@
+TP-WIDTH(1) TP-WIDTH(1)
+
+
+
+N\bNA\bAM\bME\bE
+ TP-width - indentation width of indented paragraphs
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ Regular mode:
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag indented
+ text
+
+ tag indented
+ text
+
+ Literal mode:
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag
+ indented
+ text
+
+ tag indented
+ text
+
+ tag indented
+ text
+
+
+
Index: regress/usr.bin/mandoc/man/nf/Makefile
===================================================================
RCS file: regress/usr.bin/mandoc/man/nf/Makefile
diff -N regress/usr.bin/mandoc/man/nf/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/nf/Makefile 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2010/07/01 05:29:57 schwarze Exp $
+
+REGRESS_TARGETS=indent
+GROFF_TARGETS=indent
+
+.include <bsd.regress.mk>
Index: regress/usr.bin/mandoc/man/nf/indent.in
===================================================================
RCS file: regress/usr.bin/mandoc/man/nf/indent.in
diff -N regress/usr.bin/mandoc/man/nf/indent.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/nf/indent.in 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,17 @@
+.TH NF-INDENT 1
+.SH NAME
+nf-indent \- indentation of literal blocks
+.SH DESCRIPTION
+Here comes
+an indented block:
+.nf
+oneword
+two words
+and three words
+This is a very long line; because it is indented, it is a bit too long to fit.
+blank line:
+
+end of literal
+.fi
+He is some more
+regular text.
Index: regress/usr.bin/mandoc/man/nf/indent.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/man/nf/indent.out_ascii
diff -N regress/usr.bin/mandoc/man/nf/indent.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/man/nf/indent.out_ascii 2 Jan 2011 12:09:53 -0000
@@ -0,0 +1,20 @@
+NF-INDENT(1) NF-INDENT(1)
+
+
+
+N\bNA\bAM\bME\bE
+ nf-indent - indentation of literal blocks
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ Here comes an indented block:
+ oneword
+ two words
+ and three words
+ This is a very long line; because it is indented, it is a bit too long to fit.
+ blank line:
+
+ end of literal
+ He is some more regular text.
+
+
+
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2011-01-02 12:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-02 12:41 Ingo Schwarze [this message]
2011-01-02 21:39 ` Kristaps Dzonsons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110102124118.GA21085@iris.usta.de \
--to=schwarze@usta.de \
--cc=naddy@openbsd.org \
--cc=tech@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).