source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Multiple fixes with respect to .Eo: 1.
@ 2014-11-27 22:27 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-11-27 22:27 UTC (permalink / raw)
  To: source

Log Message:
-----------
Multiple fixes with respect to .Eo:
1. Correctly parse stray .Ec without preceding .Eo,
avoiding an assertion violation found by jsg@ with afl.
2. Correctly parse .Ec arguments when breaking another block.
3. Correct spacing around closing delimiter when breaking another block.
4. Sync some related formatting control from -Tascii to -Thtml.

Modified Files:
--------------
    mdocml:
        mdoc_html.c
        mdoc_macro.c
        mdoc_man.c
        mdoc_term.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_man.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.75 -r1.76
--- mdoc_man.c
+++ mdoc_man.c
@@ -85,6 +85,7 @@ static	int	  pre_en(DECL_ARGS);
 static	int	  pre_enc(DECL_ARGS);
 static	int	  pre_em(DECL_ARGS);
 static	int	  pre_skip(DECL_ARGS);
+static	int	  pre_eo(DECL_ARGS);
 static	int	  pre_ex(DECL_ARGS);
 static	int	  pre_fa(DECL_ARGS);
 static	int	  pre_fd(DECL_ARGS);
@@ -190,7 +191,7 @@ static	const struct manact manacts[MDOC_
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ec */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ef */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Em */
-	{ NULL, NULL, post_eo, NULL, NULL }, /* Eo */
+	{ cond_body, pre_eo, post_eo, NULL, NULL }, /* Eo */
 	{ NULL, pre_ux, NULL, "FreeBSD", NULL }, /* Fx */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Ms */
 	{ NULL, pre_no, NULL, NULL, NULL }, /* No */
@@ -607,8 +608,8 @@ print_node(DECL_ARGS)
 		 * node.
 		 */
 		act = manacts + n->tok;
-		cond = NULL == act->cond || (*act->cond)(meta, n);
-		if (cond && act->pre && ENDBODY_NOT == n->end)
+		cond = act->cond == NULL || (*act->cond)(meta, n);
+		if (cond && act->pre && (n->end == ENDBODY_NOT || n->nchild))
 			do_sub = (*act->pre)(meta, n);
 	}
 
@@ -1123,11 +1124,19 @@ post_en(DECL_ARGS)
 	return;
 }
 
+static int
+pre_eo(DECL_ARGS)
+{
+
+	outflags &= ~(MMAN_spc | MMAN_nl);
+	return(1);
+}
+
 static void
 post_eo(DECL_ARGS)
 {
 
-	if (MDOC_HEAD == n->type || MDOC_BODY == n->type)
+	if (n->end != ENDBODY_SPACE)
 		outflags &= ~MMAN_spc;
 }
 
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.147
retrieving revision 1.148
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.147 -r1.148
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -693,6 +693,7 @@ static int
 blk_exp_close(MACRO_PROT_ARGS)
 {
 	struct mdoc_node *body;		/* Our own body. */
+	struct mdoc_node *endbody;	/* Our own end marker. */
 	struct mdoc_node *later;	/* A sub-block starting later. */
 	struct mdoc_node *n;		/* For searching backwards. */
 
@@ -719,7 +720,7 @@ blk_exp_close(MACRO_PROT_ARGS)
 	 * both of our own and of pending sub-blocks.
 	 */
 	atok = rew_alt(tok);
-	body = later = NULL;
+	body = endbody = later = NULL;
 	for (n = mdoc->last; n; n = n->parent) {
 		if (MDOC_VALID & n->flags)
 			continue;
@@ -758,6 +759,10 @@ blk_exp_close(MACRO_PROT_ARGS)
 			if ( ! mdoc_endbody_alloc(mdoc, line, ppos,
 			    atok, body, ENDBODY_SPACE))
 				return(0);
+			if (maxargs) {
+				endbody = mdoc->last;
+				mdoc->next = MDOC_NEXT_CHILD;
+			}
 			break;
 		}
 
@@ -787,15 +792,28 @@ blk_exp_close(MACRO_PROT_ARGS)
 	if ( ! rew_sub(MDOC_BODY, mdoc, tok, line, ppos))
 		return(0);
 
-	if (NULL == later && maxargs > 0)
-		if ( ! mdoc_tail_alloc(mdoc, line, ppos, rew_alt(tok)))
+	if (maxargs && endbody == NULL) {
+		if (n == NULL) {
+			/*
+			 * Stray .Ec without previous .Eo:
+			 * Break the output line, ignore any arguments.
+			 */
+			if ( ! mdoc_elem_alloc(mdoc, line, ppos,
+			    MDOC_br, NULL))
+				return(0);
+			if ( ! rew_elem(mdoc, MDOC_br))
+				return(0);
+		} else if ( ! mdoc_tail_alloc(mdoc, line, ppos, atok))
 			return(0);
+	}
 
-	for (flushed = j = 0; ; j++) {
+	flushed = n == NULL;
+	for (j = 0; ; j++) {
 		lastarg = *pos;
 
 		if (j == maxargs && ! flushed) {
-			if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))
+			if ( ! (endbody != NULL ? rew_last(mdoc, endbody) :
+			    rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)))
 				return(0);
 			flushed = 1;
 		}
@@ -819,7 +837,8 @@ blk_exp_close(MACRO_PROT_ARGS)
 		}
 
 		if ( ! flushed) {
-			if ( ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))
+			if ( ! (endbody != NULL ? rew_last(mdoc, endbody) :
+			    rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)))
 				return(0);
 			flushed = 1;
 		}
@@ -831,7 +850,8 @@ blk_exp_close(MACRO_PROT_ARGS)
 		break;
 	}
 
-	if ( ! flushed && ! rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos))
+	if ( ! flushed && ! (endbody != NULL ? rew_last(mdoc, endbody) :
+	    rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)))
 		return(0);
 
 	if ( ! nl)
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_term.c,v
retrieving revision 1.294
retrieving revision 1.295
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.294 -r1.295
--- mdoc_term.c
+++ mdoc_term.c
@@ -350,7 +350,8 @@ print_mdoc_node(DECL_ARGS)
 		term_tbl(p, n->span);
 		break;
 	default:
-		if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
+		if (termacts[n->tok].pre &&
+		    (n->end == ENDBODY_NOT || n->nchild))
 			chld = (*termacts[n->tok].pre)
 				(p, &npair, meta, n);
 		break;
@@ -1917,10 +1918,11 @@ static void
 termp_quote_post(DECL_ARGS)
 {
 
-	if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
+	if (n->type != MDOC_BODY && n->type != MDOC_ELEM)
 		return;
 
-	if (MDOC_En != n->tok)
+	if ( ! (n->tok == MDOC_En ||
+	    (n->tok == MDOC_Eo && n->end == ENDBODY_SPACE)))
 		p->flags |= TERMP_NOSPACE;
 
 	switch (n->tok) {
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_html.c,v
retrieving revision 1.212
retrieving revision 1.213
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.212 -r1.213
--- mdoc_html.c
+++ mdoc_html.c
@@ -423,13 +423,12 @@ print_mdoc_node(MDOC_ARGS)
 		 * the "meta" table state.  This will be reopened on the
 		 * next table element.
 		 */
-		if (h->tblt) {
+		if (h->tblt != NULL) {
 			print_tblclose(h);
 			t = h->tags.head;
 		}
-
-		assert(NULL == h->tblt);
-		if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
+		assert(h->tblt == NULL);
+		if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
 			child = (*mdocs[n->tok].pre)(meta, n, h);
 		break;
 	}
@@ -454,8 +453,13 @@ print_mdoc_node(MDOC_ARGS)
 	case MDOC_EQN:
 		break;
 	default:
-		if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
-			(*mdocs[n->tok].post)(meta, n, h);
+		if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED)
+			break;
+		(*mdocs[n->tok].post)(meta, n, h);
+		if (n->end != ENDBODY_NOT)
+			n->pending->flags |= MDOC_ENDED;
+		if (n->end == ENDBODY_NOSPACE)
+			h->flags |= HTML_NOSPACE;
 		break;
 	}
 }
@@ -2142,10 +2146,11 @@ static void
 mdoc_quote_post(MDOC_ARGS)
 {
 
-	if (MDOC_BODY != n->type)
+	if (n->type != MDOC_BODY && n->type != MDOC_ELEM)
 		return;
 
-	if (MDOC_En != n->tok)
+	if ( ! (n->tok == MDOC_En ||
+	    (n->tok == MDOC_Eo && n->end == ENDBODY_SPACE)))
 		h->flags |= HTML_NOSPACE;
 
 	switch (n->tok) {
--
 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:[~2014-11-27 22:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-27 22:27 mdocml: Multiple fixes with respect to .Eo: 1 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).