tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* [PATCH] man(7) .IP and .TP in literal mode
@ 2011-01-02 12:41 Ingo Schwarze
  2011-01-02 21:39 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: Ingo Schwarze @ 2011-01-02 12:41 UTC (permalink / raw)
  To: tech; +Cc: naddy

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] man(7) .IP and .TP in literal mode
  2011-01-02 12:41 [PATCH] man(7) .IP and .TP in literal mode Ingo Schwarze
@ 2011-01-02 21:39 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-01-02 21:39 UTC (permalink / raw)
  To: tech

> 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?

Fine by me.  Can you work this into man_html.c, too?  And does this 
require man.7 updates?

Thanks,

Kristaps
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-02 21:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-02 12:41 [PATCH] man(7) .IP and .TP in literal mode Ingo Schwarze
2011-01-02 21:39 ` Kristaps Dzonsons

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).