source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: correct handling of blank lines after \c
@ 2017-06-17 13:06 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-17 13:06 UTC (permalink / raw)
  To: source

Log Message:
-----------
correct handling of blank lines after \c

Modified Files:
--------------
    mdocml:
        man.c
        man_term.c
        mdoc.c
    mdocml/regress/roff/esc:
        c.in
        c.out_ascii
        c_man.in
        c_man.out_ascii

Revision Data
-------------
Index: man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -Lman.c -Lman.c -u -p -r1.174 -r1.175
--- man.c
+++ man.c
@@ -76,6 +76,8 @@ static int
 man_ptext(struct roff_man *man, int line, char *buf, int offs)
 {
 	int		 i;
+	const char 	*cp, *sp;
+	char		*ep;
 
 	/* Literal free-form text whitespace is preserved. */
 
@@ -89,19 +91,36 @@ man_ptext(struct roff_man *man, int line
 		/* Skip leading whitespace. */ ;
 
 	/*
-	 * Blank lines are ignored in next line scope and right
-	 * after headings but add a single vertical space elsewhere.
+	 * Blank lines are ignored in next line scope
+	 * and right after headings and cancel preceding \c,
+	 * but add a single vertical space elsewhere.
 	 */
 
 	if (buf[i] == '\0') {
-		if (man->flags & (MAN_ELINE | MAN_BLINE))
+		if (man->flags & (MAN_ELINE | MAN_BLINE)) {
 			mandoc_msg(MANDOCERR_BLK_BLANK, man->parse,
 			    line, 0, NULL);
-		else if (man->last->tok != MAN_SH &&
-		    man->last->tok != MAN_SS) {
-			roff_elem_alloc(man, line, offs, ROFF_sp);
-			man->next = ROFF_NEXT_SIBLING;
+			return 1;
 		}
+		if (man->last->tok == MAN_SH || man->last->tok == MAN_SS)
+			return 1;
+		switch (man->last->type) {
+		case ROFFT_TEXT:
+			sp = man->last->string;
+			cp = ep = strchr(sp, '\0') - 2;
+			if (cp < sp || cp[0] != '\\' || cp[1] != 'c')
+				break;
+			while (cp > sp && cp[-1] == '\\')
+				cp--;
+			if ((ep - cp) % 2)
+				break;
+			*ep = '\0';
+			return 1;
+		default:
+			break;
+		}
+		roff_elem_alloc(man, line, offs, ROFF_sp);
+		man->next = ROFF_NEXT_SIBLING;
 		return 1;
 	}
 
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.c,v
retrieving revision 1.266
retrieving revision 1.267
diff -Lmdoc.c -Lmdoc.c -u -p -r1.266 -r1.267
--- mdoc.c
+++ mdoc.c
@@ -179,6 +179,7 @@ static int
 mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs)
 {
 	struct roff_node *n;
+	const char	 *cp, *sp;
 	char		 *c, *ws, *end;
 
 	n = mdoc->last;
@@ -244,15 +245,30 @@ mdoc_ptext(struct roff_man *mdoc, int li
 		mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
 		    line, (int)(ws-buf), NULL);
 
+	/*
+	 * Blank lines are allowed in no-fill mode
+	 * and cancel preceding \c,
+	 * but add a single vertical space elsewhere.
+	 */
+
 	if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) {
+		switch (mdoc->last->type) {
+		case ROFFT_TEXT:
+			sp = mdoc->last->string;
+			cp = end = strchr(sp, '\0') - 2;
+			if (cp < sp || cp[0] != '\\' || cp[1] != 'c')
+				break;
+			while (cp > sp && cp[-1] == '\\')
+				cp--;
+			if ((end - cp) % 2)
+				break;
+			*end = '\0';
+			return 1;
+		default:
+			break;
+		}
 		mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse,
 		    line, (int)(c - buf), NULL);
-
-		/*
-		 * Insert a `sp' in the case of a blank line.  Technically,
-		 * blank lines aren't allowed, but enough manuals assume this
-		 * behaviour that we want to work around it.
-		 */
 		roff_elem_alloc(mdoc, line, offs, ROFF_sp);
 		mdoc->last->flags |= NODE_VALID | NODE_ENDED;
 		mdoc->next = ROFF_NEXT_SIBLING;
Index: man_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_term.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -Lman_term.c -Lman_term.c -u -p -r1.206 -r1.207
--- man_term.c
+++ man_term.c
@@ -872,7 +872,10 @@ print_man_node(DECL_ARGS)
 		 * before printing the line's data.
 		 */
 		if (*n->string == '\0') {
-			term_vspace(p);
+			if (p->flags & TERMP_NONEWLINE)
+				term_newln(p);
+			else
+				term_vspace(p);
 			return;
 		} else if (*n->string == ' ' && n->flags & NODE_LINE &&
 		    (p->flags & TERMP_NONEWLINE) == 0)
Index: c.out_ascii
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/esc/c.out_ascii,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregress/roff/esc/c.out_ascii -Lregress/roff/esc/c.out_ascii -u -p -r1.2 -r1.3
--- regress/roff/esc/c.out_ascii
+++ regress/roff/esc/c.out_ascii
@@ -7,5 +7,9 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      No space between "one" and "word": oneword
 
      oneword
+     Blank line after \c: one word
+
+     one
+     word
 
 OpenBSD                        December 2, 2014                        OpenBSD
Index: c_man.in
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/esc/c_man.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/esc/c_man.in -Lregress/roff/esc/c_man.in -u -p -r1.1 -r1.2
--- regress/roff/esc/c_man.in
+++ regress/roff/esc/c_man.in
@@ -9,4 +9,13 @@ word
 one\c
 word
 .fi
+Blank line after \ec:
+one\c
+
+word
+.nf
+one\c
+
+word
+.fi
 final text
Index: c.in
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/esc/c.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/esc/c.in -Lregress/roff/esc/c.in -u -p -r1.1 -r1.2
--- regress/roff/esc/c.in
+++ regress/roff/esc/c.in
@@ -15,3 +15,12 @@ word
 one\c
 word
 .Ed
+Blank line after \ec:
+one\c
+
+word
+.Bd -literal
+one\c
+
+word
+.Ed
Index: c_man.out_ascii
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/esc/c_man.out_ascii,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/esc/c_man.out_ascii -Lregress/roff/esc/c_man.out_ascii -u -p -r1.1 -r1.2
--- regress/roff/esc/c_man.out_ascii
+++ regress/roff/esc/c_man.out_ascii
@@ -8,6 +8,9 @@ N\bNA\bAM\bME\bE
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
        No space between "one" and "word": oneword
        oneword
+       Blank line after \c: one word
+       one
+       word
        final text
 
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-17 13:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-17 13:06 mdocml: correct handling of blank lines after \c schwarze

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