source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: starting a tbl(7) breaks man(7) next-line scope; triggered by a
@ 2015-01-30 21:29 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-01-30 21:29 UTC (permalink / raw)
  To: source

Log Message:
-----------
starting a tbl(7) breaks man(7) next-line scope;
triggered by a bug report from jsg@

Modified Files:
--------------
    mdocml:
        man.c

Revision Data
-------------
Index: man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -Lman.c -Lman.c -u -p -r1.148 -r1.149
--- man.c
+++ man.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -48,6 +48,10 @@ const	char *const __man_macronames[MAN_M
 
 const	char * const *man_macronames = __man_macronames;
 
+static	void		 man_alloc1(struct man *);
+static	void		 man_breakscope(struct man *, enum mant);
+static	void		 man_descope(struct man *, int, int);
+static	void		 man_free1(struct man *);
 static	struct man_node	*man_node_alloc(struct man *, int, int,
 				enum man_type, enum mant);
 static	void		 man_node_append(struct man *, struct man_node *);
@@ -56,9 +60,6 @@ static	void		 man_node_unlink(struct man
 				struct man_node *);
 static	int		 man_ptext(struct man *, int, char *, int);
 static	int		 man_pmacro(struct man *, int, char *, int);
-static	void		 man_free1(struct man *);
-static	void		 man_alloc1(struct man *);
-static	void		 man_descope(struct man *, int, int);
 
 
 const struct man_node *
@@ -337,6 +338,7 @@ man_addspan(struct man *man, const struc
 {
 	struct man_node	*n;
 
+	man_breakscope(man, MAN_MAX);
 	n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX);
 	n->span = sp;
 	man_node_append(man, n);
@@ -493,62 +495,11 @@ man_pmacro(struct man *man, int ln, char
 		    ln, offs - 1, NULL);
 
 	/*
-	 * Remove prior ELINE macro, as it's being clobbered by a new
-	 * macro.  Note that NSCOPED macros do not close out ELINE
-	 * macros---they don't print text---so we let those slip by.
+	 * Some macros break next-line scopes; otherwise, remember
+	 * whether we are in next-line scope for a block head.
 	 */
 
-	if ( ! (man_macros[tok].flags & MAN_NSCOPED) &&
-			man->flags & MAN_ELINE) {
-		n = man->last;
-		assert(MAN_TEXT != n->type);
-
-		/* Remove repeated NSCOPED macros causing ELINE. */
-
-		if (man_macros[n->tok].flags & MAN_NSCOPED)
-			n = n->parent;
-
-		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line,
-		    n->pos, "%s breaks %s", man_macronames[tok],
-		    man_macronames[n->tok]);
-
-		man_node_delete(man, n);
-		man->flags &= ~MAN_ELINE;
-	}
-
-	/*
-	 * Remove prior BLINE macro that is being clobbered.
-	 */
-	if ((man->flags & MAN_BLINE) &&
-	    (man_macros[tok].flags & MAN_BSCOPE)) {
-		n = man->last;
-
-		/* Might be a text node like 8 in
-		 * .TP 8
-		 * .SH foo
-		 */
-		if (n->type == MAN_TEXT)
-			n = n->parent;
-
-		/* Remove element that didn't end BLINE, if any. */
-		if ( ! (man_macros[n->tok].flags & MAN_BSCOPE))
-			n = n->parent;
-
-		assert(n->type == MAN_HEAD);
-		n = n->parent;
-		assert(n->type == MAN_BLOCK);
-		assert(man_macros[n->tok].flags & MAN_SCOPED);
-
-		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line,
-		    n->pos, "%s breaks %s", man_macronames[tok],
-		    man_macronames[n->tok]);
-
-		man_node_delete(man, n);
-		man->flags &= ~MAN_BLINE;
-	}
-
-	/* Remember whether we are in next-line scope for a block head. */
-
+	man_breakscope(man, tok);
 	bline = man->flags & MAN_BLINE;
 
 	/* Call to handler... */
@@ -581,6 +532,62 @@ man_pmacro(struct man *man, int ln, char
 	man_unscope(man, man->last->parent);
 	man_body_alloc(man, ln, ppos, man->last->tok);
 	return(1);
+}
+
+void
+man_breakscope(struct man *man, enum mant tok)
+{
+	struct man_node	*n;
+
+	/*
+	 * An element next line scope is open,
+	 * and the new macro is not allowed inside elements.
+	 * Delete the element that is being broken.
+	 */
+
+	if (man->flags & MAN_ELINE && (tok == MAN_MAX ||
+	    ! (man_macros[tok].flags & MAN_NSCOPED))) {
+		n = man->last;
+		assert(n->type != MAN_TEXT);
+		if (man_macros[n->tok].flags & MAN_NSCOPED)
+			n = n->parent;
+
+		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
+		    n->line, n->pos, "%s breaks %s",
+		    tok == MAN_MAX ? "TS" : man_macronames[tok],
+		    man_macronames[n->tok]);
+
+		man_node_delete(man, n);
+		man->flags &= ~MAN_ELINE;
+	}
+
+	/*
+	 * A block header next line scope is open,
+	 * and the new macro is not allowed inside block headers.
+	 * Delete the block that is being broken.
+	 */
+
+	if (man->flags & MAN_BLINE && (tok == MAN_MAX ||
+	    man_macros[tok].flags & MAN_BSCOPE)) {
+		n = man->last;
+		if (n->type == MAN_TEXT)
+			n = n->parent;
+		if ( ! (man_macros[n->tok].flags & MAN_BSCOPE))
+			n = n->parent;
+
+		assert(n->type == MAN_HEAD);
+		n = n->parent;
+		assert(n->type == MAN_BLOCK);
+		assert(man_macros[n->tok].flags & MAN_SCOPED);
+
+		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
+		    n->line, n->pos, "%s breaks %s",
+		    tok == MAN_MAX ? "TS" : man_macronames[tok],
+		    man_macronames[n->tok]);
+
+		man_node_delete(man, n);
+		man->flags &= ~MAN_BLINE;
+	}
 }
 
 /*
--
 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:[~2015-01-30 21:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30 21:29 mdocml: starting a tbl(7) breaks man(7) next-line scope; triggered by a 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).