tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Leading space in roff = leading newline.
@ 2011-01-11  1:10 Kristaps Dzonsons
  2011-01-11  1:12 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-01-11  1:10 UTC (permalink / raw)
  To: tech, Jason McIntyre

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Hi,

I came across a real gem in gm.1.  Apparently leading a line with a 
space causes a leading newline, as in

++++
The \fBGraphicsMagick\fP utilities recognize the following image formats:


\fBName\fP   \fBMode\fP \fBDescription\fP
  o  8BIM      *rw- Photoshop resource format
  o  8BIMTEXT  *rw- Photoshop resource format
  o  8BIMWTEXT *rw- Photoshop resource format
  o  APP1      *rw- Photoshop resource format
  o  ART       *r-- PF1: 1st Publisher
----

and so on.  It works with mdoc(7) and man(7).

Anybody against the following patch?

Thanks,

Kristaps


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3781 bytes --]

Index: libman.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libman.h,v
retrieving revision 1.44
diff -r1.44 libman.h
36a37
> #define	MAN_NEWLINE	(1 << 6) /* first macro/text in a line */
Index: man.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.7,v
retrieving revision 1.94
diff -r1.94 man.7
61a62,64
> .Pp
> If the first character of a line is whitespace, that line is printed
> verbatim, including the end-of-line.
Index: man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.c,v
retrieving revision 1.96
diff -r1.96 man.c
47c47
< static	struct man_node	*man_node_alloc(int, int, 
---
> static	struct man_node	*man_node_alloc(struct man *, int, int, 
131a132,133
> 	m->flags |= MAN_NEWLINE;
> 
232c234,235
< man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
---
> man_node_alloc(struct man *m, int line, int pos, 
> 		enum man_type type, enum mant tok)
240a244,247
> 
> 	if (MAN_NEWLINE & m->flags)
> 		p->flags |= MAN_LINE;
> 	m->flags &= ~MAN_NEWLINE;
250c257
< 	p = man_node_alloc(line, pos, MAN_ELEM, tok);
---
> 	p = man_node_alloc(m, line, pos, MAN_ELEM, tok);
263c270
< 	p = man_node_alloc(line, pos, MAN_HEAD, tok);
---
> 	p = man_node_alloc(m, line, pos, MAN_HEAD, tok);
276c283
< 	p = man_node_alloc(line, pos, MAN_BODY, tok);
---
> 	p = man_node_alloc(m, line, pos, MAN_BODY, tok);
289c296
< 	p = man_node_alloc(line, pos, MAN_BLOCK, tok);
---
> 	p = man_node_alloc(m, line, pos, MAN_BLOCK, tok);
302c309
< 	n = man_node_alloc(0, 0, MAN_TBL, MAN_MAX);
---
> 	n = man_node_alloc(m, 0, 0, MAN_TBL, MAN_MAX);
320c327
< 	n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
---
> 	n = man_node_alloc(m, line, pos, MAN_TEXT, MAN_MAX);
Index: man.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v
retrieving revision 1.50
diff -r1.50 man.h
99a100
> #define	MAN_LINE	(1 << 3) /* first macro/text on line */
Index: man_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v
retrieving revision 1.62
diff -r1.62 man_html.c
199a200,207
> 		if ('\0' == *n->string) {
> 			print_otag(h, TAG_P, 0, NULL);
> 			return;
> 		}
> 
> 		if (' ' == *n->string && MAN_LINE & n->flags)
> 			print_otag(h, TAG_BR, 0, NULL);
> 
200a209
> 
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.95
diff -r1.95 man_term.c
862c862
< 		if (0 == *n->string) {
---
> 		if ('\0' == *n->string) {
865c865,868
< 		}
---
> 		} 
> 
> 		if (' ' == *n->string && MAN_LINE & n->flags)
> 			term_newln(p);
880a884
> 
Index: mdoc.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.7,v
retrieving revision 1.174
diff -r1.174 mdoc.7
57a58,60
> .Pp
> If the first character of a line is whitespace, that line is printed
> verbatim, including the end-of-line.
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.142
diff -r1.142 mdoc_html.c
422a423,424
> 		if (' ' == *n->string && MDOC_LINE & n->flags)
> 			print_otag(h, TAG_BR, 0, NULL);
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.208
diff -r1.208 mdoc_term.c
317a318,319
> 		if (' ' == *n->string && MDOC_LINE & n->flags)
> 			term_newln(p);

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

* Re: Leading space in roff = leading newline.
  2011-01-11  1:10 Leading space in roff = leading newline Kristaps Dzonsons
@ 2011-01-11  1:12 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-01-11  1:12 UTC (permalink / raw)
  To: tech

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

> I came across a real gem in gm.1. Apparently leading a line with a space
> causes a leading newline, as in
>
> ++++
> The \fBGraphicsMagick\fP utilities recognize the following image formats:
>
>
> \fBName\fP \fBMode\fP \fBDescription\fP
> o 8BIM *rw- Photoshop resource format
> o 8BIMTEXT *rw- Photoshop resource format
> o 8BIMWTEXT *rw- Photoshop resource format
> o APP1 *rw- Photoshop resource format
> o ART *r-- PF1: 1st Publisher
> ----
>
> and so on. It works with mdoc(7) and man(7).
>
> Anybody against the following patch?

Blarg, now with diff -u.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 7158 bytes --]

Index: libman.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libman.h,v
retrieving revision 1.44
diff -u -r1.44 libman.h
--- libman.h	30 Nov 2010 15:36:28 -0000	1.44
+++ libman.h	11 Jan 2011 01:11:29 -0000
@@ -34,6 +34,7 @@
 #define	MAN_ILINE	(1 << 3) /* Ignored in next-line scope. */
 #define	MAN_LITERAL	(1 << 4) /* Literal input. */
 #define	MAN_BPLINE	(1 << 5)
+#define	MAN_NEWLINE	(1 << 6) /* first macro/text in a line */
 	enum man_next	 next; /* where to put the next node */
 	struct man_node	*last; /* the last parsed node */
 	struct man_node	*first; /* the first parsed node */
Index: man.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.7,v
retrieving revision 1.94
diff -u -r1.94 man.7
--- man.7	4 Jan 2011 23:32:21 -0000	1.94
+++ man.7	11 Jan 2011 01:11:29 -0000
@@ -59,6 +59,9 @@
 .Pp
 Blank lines are acceptable; where found, the output will assert a
 vertical space.
+.Pp
+If the first character of a line is whitespace, that line is printed
+verbatim, including the end-of-line.
 .Ss Comments
 Text following a
 .Sq \e\*q ,
Index: man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.c,v
retrieving revision 1.96
diff -u -r1.96 man.c
--- man.c	3 Jan 2011 11:31:26 -0000	1.96
+++ man.c	11 Jan 2011 01:11:29 -0000
@@ -44,7 +44,7 @@
 
 const	char * const *man_macronames = __man_macronames;
 
-static	struct man_node	*man_node_alloc(int, int, 
+static	struct man_node	*man_node_alloc(struct man *, int, int, 
 				enum man_type, enum mant);
 static	int		 man_node_append(struct man *, 
 				struct man_node *);
@@ -129,6 +129,8 @@
 man_parseln(struct man *m, int ln, char *buf, int offs)
 {
 
+	m->flags |= MAN_NEWLINE;
+
 	assert( ! (MAN_HALT & m->flags));
 	return(('.' == buf[offs] || '\'' == buf[offs]) ? 
 			man_pmacro(m, ln, buf, offs) : 
@@ -229,7 +231,8 @@
 
 
 static struct man_node *
-man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
+man_node_alloc(struct man *m, int line, int pos, 
+		enum man_type type, enum mant tok)
 {
 	struct man_node *p;
 
@@ -238,6 +241,10 @@
 	p->pos = pos;
 	p->type = type;
 	p->tok = tok;
+
+	if (MAN_NEWLINE & m->flags)
+		p->flags |= MAN_LINE;
+	m->flags &= ~MAN_NEWLINE;
 	return(p);
 }
 
@@ -247,7 +254,7 @@
 {
 	struct man_node *p;
 
-	p = man_node_alloc(line, pos, MAN_ELEM, tok);
+	p = man_node_alloc(m, line, pos, MAN_ELEM, tok);
 	if ( ! man_node_append(m, p))
 		return(0);
 	m->next = MAN_NEXT_CHILD;
@@ -260,7 +267,7 @@
 {
 	struct man_node *p;
 
-	p = man_node_alloc(line, pos, MAN_HEAD, tok);
+	p = man_node_alloc(m, line, pos, MAN_HEAD, tok);
 	if ( ! man_node_append(m, p))
 		return(0);
 	m->next = MAN_NEXT_CHILD;
@@ -273,7 +280,7 @@
 {
 	struct man_node *p;
 
-	p = man_node_alloc(line, pos, MAN_BODY, tok);
+	p = man_node_alloc(m, line, pos, MAN_BODY, tok);
 	if ( ! man_node_append(m, p))
 		return(0);
 	m->next = MAN_NEXT_CHILD;
@@ -286,7 +293,7 @@
 {
 	struct man_node *p;
 
-	p = man_node_alloc(line, pos, MAN_BLOCK, tok);
+	p = man_node_alloc(m, line, pos, MAN_BLOCK, tok);
 	if ( ! man_node_append(m, p))
 		return(0);
 	m->next = MAN_NEXT_CHILD;
@@ -299,7 +306,7 @@
 	struct man_node	*n;
 
 	/* FIXME: grab from span */
-	n = man_node_alloc(0, 0, MAN_TBL, MAN_MAX);
+	n = man_node_alloc(m, 0, 0, MAN_TBL, MAN_MAX);
 	n->span = span;
 
 	if ( ! man_node_append(m, n))
@@ -317,7 +324,7 @@
 
 	len = strlen(word);
 
-	n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
+	n = man_node_alloc(m, line, pos, MAN_TEXT, MAN_MAX);
 	n->string = mandoc_malloc(len + 1);
 	sv = strlcpy(n->string, word, len + 1);
 
Index: man.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v
retrieving revision 1.50
diff -u -r1.50 man.h
--- man.h	1 Jan 2011 12:59:17 -0000	1.50
+++ man.h	11 Jan 2011 01:11:29 -0000
@@ -97,6 +97,7 @@
 	int		 flags;
 #define	MAN_VALID	(1 << 0) /* has been validated */
 #define	MAN_EOS		(1 << 2) /* at sentence boundary */
+#define	MAN_LINE	(1 << 3) /* first macro/text on line */
 	enum man_type	 type; /* AST node type */
 	char		*string; /* TEXT node argument */
 	struct man_node	*head; /* BLOCK node HEAD ptr */
Index: man_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v
retrieving revision 1.62
diff -u -r1.62 man_html.c
--- man_html.c	7 Jan 2011 13:20:58 -0000	1.62
+++ man_html.c	11 Jan 2011 01:11:29 -0000
@@ -197,7 +197,16 @@
 		child = man_root_pre(m, n, mh, h);
 		break;
 	case (MAN_TEXT):
+		if ('\0' == *n->string) {
+			print_otag(h, TAG_P, 0, NULL);
+			return;
+		}
+
+		if (' ' == *n->string && MAN_LINE & n->flags)
+			print_otag(h, TAG_BR, 0, NULL);
+
 		print_text(h, n->string);
+
 		if (MANH_LITERAL & mh->fl)
 			print_otag(h, TAG_BR, 0, NULL);
 		return;
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.95
diff -u -r1.95 man_term.c
--- man_term.c	11 Jan 2011 00:39:00 -0000	1.95
+++ man_term.c	11 Jan 2011 01:11:29 -0000
@@ -859,10 +859,13 @@
 
 	switch (n->type) {
 	case(MAN_TEXT):
-		if (0 == *n->string) {
+		if ('\0' == *n->string) {
 			term_vspace(p);
 			break;
-		}
+		} 
+
+		if (' ' == *n->string && MAN_LINE & n->flags)
+			term_newln(p);
 
 		term_word(p, n->string);
 
@@ -878,6 +881,7 @@
 			p->rmargin = rm;
 			p->maxrmargin = rmax;
 		}
+
 		break;
 	case (MAN_TBL):
 		if (TBL_SPAN_FIRST & n->span->flags) 
Index: mdoc.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.7,v
retrieving revision 1.174
diff -u -r1.174 mdoc.7
--- mdoc.7	4 Jan 2011 23:32:21 -0000	1.174
+++ mdoc.7	11 Jan 2011 01:11:30 -0000
@@ -55,6 +55,9 @@
 All manuals must have
 .Ux
 line terminators.
+.Pp
+If the first character of a line is whitespace, that line is printed
+verbatim, including the end-of-line.
 .Ss Comments
 Text following a
 .Sq \e\*q ,
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.142
diff -u -r1.142 mdoc_html.c
--- mdoc_html.c	7 Jan 2011 13:20:58 -0000	1.142
+++ mdoc_html.c	11 Jan 2011 01:11:30 -0000
@@ -420,6 +420,8 @@
 		child = mdoc_root_pre(m, n, h);
 		break;
 	case (MDOC_TEXT):
+		if (' ' == *n->string && MDOC_LINE & n->flags)
+			print_otag(h, TAG_BR, 0, NULL);
 		print_text(h, n->string);
 		return;
 	case (MDOC_TBL):
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.208
diff -u -r1.208 mdoc_term.c
--- mdoc_term.c	6 Jan 2011 14:05:12 -0000	1.208
+++ mdoc_term.c	11 Jan 2011 01:11:30 -0000
@@ -315,6 +315,8 @@
 	
 	switch (n->type) {
 	case (MDOC_TEXT):
+		if (' ' == *n->string && MDOC_LINE & n->flags)
+			term_newln(p);
 		term_word(p, n->string);
 		break;
 	case (MDOC_TBL):

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

end of thread, other threads:[~2011-01-11  1:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-11  1:10 Leading space in roff = leading newline Kristaps Dzonsons
2011-01-11  1:12 ` 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).