source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Improve handling of next-line scope broken by end of file.
Date: Wed, 30 Jul 2014 19:01:39 -0400 (EDT)	[thread overview]
Message-ID: <201407302301.s6UN1d5V018419@krisdoz.my.domain> (raw)

Log Message:
-----------
Improve handling of next-line scope broken by end of file.
Detect the condition earlier, report in the error message 
which block is broken, and delete the broken block.
Consequently, empty section headers can no longer happen.

Modified Files:
--------------
    mdocml:
        man_macro.c
        man_validate.c

Revision Data
-------------
Index: man_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_validate.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -Lman_validate.c -Lman_validate.c -u -p -r1.100 -r1.101
--- man_validate.c
+++ man_validate.c
@@ -62,7 +62,6 @@ static	int	  post_vs(CHKARGS);
 static	int	  post_fi(CHKARGS);
 static	int	  post_ft(CHKARGS);
 static	int	  post_nf(CHKARGS);
-static	int	  post_sec(CHKARGS);
 static	int	  post_TH(CHKARGS);
 static	int	  post_UC(CHKARGS);
 static	int	  pre_sec(CHKARGS);
@@ -78,7 +77,6 @@ static	v_check	  posts_le1[] = { check_l
 static	v_check	  posts_nf[] = { check_eq0, post_nf, NULL };
 static	v_check	  posts_par[] = { check_par, NULL };
 static	v_check	  posts_part[] = { check_part, NULL };
-static	v_check	  posts_sec[] = { post_sec, NULL };
 static	v_check	  posts_sp[] = { post_vs, check_le1, NULL };
 static	v_check	  posts_th[] = { check_ge2, check_le5, post_TH, NULL };
 static	v_check	  posts_uc[] = { post_UC, NULL };
@@ -88,8 +86,8 @@ static	v_check	  pres_sec[] = { pre_sec,
 static	const struct man_valid man_valids[MAN_MAX] = {
 	{ NULL, posts_br }, /* br */
 	{ NULL, posts_th }, /* TH */
-	{ pres_sec, posts_sec }, /* SH */
-	{ pres_sec, posts_sec }, /* SS */
+	{ pres_sec, NULL }, /* SH */
+	{ pres_sec, NULL }, /* SS */
 	{ NULL, NULL }, /* TP */
 	{ NULL, posts_par }, /* LP */
 	{ NULL, posts_par }, /* PP */
@@ -190,12 +188,7 @@ static int
 check_root(CHKARGS)
 {
 
-	if ((MAN_BLINE | MAN_ELINE) & man->flags)
-		mandoc_msg(MANDOCERR_BLK_LINE, man->parse,
-		    0, 0, "at end of file");
-
-	man->flags &= ~MAN_BLINE;
-	man->flags &= ~MAN_ELINE;
+	assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
 
 	if (NULL == man->first->child)
 		man_nmsg(man, n, MANDOCERR_DOC_EMPTY);
@@ -322,17 +315,6 @@ pre_sec(CHKARGS)
 	if (MAN_BLOCK == n->type)
 		man->flags &= ~MAN_LITERAL;
 	return(1);
-}
-
-static int
-post_sec(CHKARGS)
-{
-
-	if ( ! (MAN_HEAD == n->type && 0 == n->nchild))
-		return(1);
-
-	man_nmsg(man, n, MANDOCERR_SYNTARGCOUNT);
-	return(0);
 }
 
 static int
Index: man_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_macro.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -Lman_macro.c -Lman_macro.c -u -p -r1.86 -r1.87
--- man_macro.c
+++ man_macro.c
@@ -104,13 +104,35 @@ man_unscope(struct man *man, const struc
 	to = to->parent;
 	n = man->last;
 	while (n != to) {
-		if (NULL == to &&
-		    MAN_BLOCK == n->type &&
-		    0 == (MAN_VALID & n->flags) &&
-		    MAN_EXPLICIT & man_macros[n->tok].flags)
-			mandoc_msg(MANDOCERR_BLK_NOEND,
-			    man->parse, n->line, n->pos,
-			    man_macronames[n->tok]);
+
+		/* Reached the end of the document? */
+
+		if (to == NULL && ! (n->flags & MAN_VALID)) {
+			if (man->flags & (MAN_BLINE | MAN_ELINE) &&
+			    man_macros[n->tok].flags & MAN_SCOPED) {
+				mandoc_vmsg(MANDOCERR_BLK_LINE,
+				    man->parse, n->line, n->pos,
+				    "EOF breaks %s",
+				    man_macronames[n->tok]);
+				if (man->flags & MAN_ELINE)
+					man->flags &= ~MAN_ELINE;
+				else {
+					assert(n->type == MAN_HEAD);
+					n = n->parent;
+					man->flags &= ~MAN_BLINE;
+				}
+				man->last = n;
+				n = n->parent;
+				man_node_delete(man, man->last);
+				continue;
+			}
+			if (n->type == MAN_BLOCK &&
+			    man_macros[n->tok].flags & MAN_EXPLICIT)
+				mandoc_msg(MANDOCERR_BLK_NOEND,
+				    man->parse, n->line, n->pos,
+				    man_macronames[n->tok]);
+		}
+
 		/*
 		 * We might delete the man->last node
 		 * in the post-validation phase.
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-07-30 23:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201407302301.s6UN1d5V018419@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).