source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Clean up the validation code for `It' macros:  use enum
Date: Mon, 31 May 2010 19:10:51 -0400 (EDT)	[thread overview]
Message-ID: <201005312310.o4VNApiw013712@krisdoz.my.domain> (raw)

Log Message:
-----------
Clean up the validation code for `It' macros:  use enum mdoc_list
instead of iterating over arguments and only scan with `-column', which
needs the count of arguments.

Modified Files:
--------------
    mdocml:
        mdoc_validate.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.88 -r1.89
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -929,72 +929,37 @@ post_an(POST_ARGS)
 static int
 post_it(POST_ARGS)
 {
-	/* FIXME: use mdoc_list! */
-	int		  type, i, cols;
+	int		  i, cols, rc;
+	enum mdoc_list	  lt;
 	struct mdoc_node *n, *c;
+	enum mandocerr	  er;
 
 	if (MDOC_BLOCK != mdoc->last->type)
 		return(1);
 
 	n = mdoc->last->parent->parent;
-	if (NULL == n->args) {
-		mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
-		return(0);
-	}
+	lt = n->data.list;
 
-	/* Some types require block-head, some not. */
-
-	/* LINTED */
-	for (cols = type = -1, i = 0; -1 == type && 
-			i < (int)n->args->argc; i++)
-		switch (n->args->argv[i].arg) {
-		case (MDOC_Tag):
-			/* FALLTHROUGH */
-		case (MDOC_Diag):
-			/* FALLTHROUGH */
-		case (MDOC_Hang):
-			/* FALLTHROUGH */
-		case (MDOC_Ohang):
-			/* FALLTHROUGH */
-		case (MDOC_Inset):
-			/* FALLTHROUGH */
-		case (MDOC_Bullet):
-			/* FALLTHROUGH */
-		case (MDOC_Dash):
-			/* FALLTHROUGH */
-		case (MDOC_Enum):
-			/* FALLTHROUGH */
-		case (MDOC_Hyphen):
-			/* FALLTHROUGH */
-		case (MDOC_Item):
-			type = n->args->argv[i].arg;
-			break;
-		case (MDOC_Column):
-			type = n->args->argv[i].arg;
-			cols = (int)n->args->argv[i].sz;
-			break;
-		default:
-			break;
-		}
-
-	if (-1 == type) {
+	if (LIST__NONE == lt) {
 		mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
 		return(0);
 	}
 
-	switch (type) {
-	case (MDOC_Tag):
-		if (NULL == mdoc->last->head->child)
-			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
-				return(0);
+	switch (lt) {
+	case (LIST_tag):
+		if (mdoc->last->head->child)
+			break;
+		/* FIXME: give this a dummy value. */
+		if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
+			return(0);
 		break;
-	case (MDOC_Hang):
+	case (LIST_hang):
 		/* FALLTHROUGH */
-	case (MDOC_Ohang):
+	case (LIST_ohang):
 		/* FALLTHROUGH */
-	case (MDOC_Inset):
+	case (LIST_inset):
 		/* FALLTHROUGH */
-	case (MDOC_Diag):
+	case (LIST_diag):
 		if (NULL == mdoc->last->head->child)
 			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
 				return(0);
@@ -1002,15 +967,15 @@ post_it(POST_ARGS)
 			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
 				return(0);
 		break;
-	case (MDOC_Bullet):
+	case (LIST_bullet):
 		/* FALLTHROUGH */
-	case (MDOC_Dash):
+	case (LIST_dash):
 		/* FALLTHROUGH */
-	case (MDOC_Enum):
+	case (LIST_enum):
 		/* FALLTHROUGH */
-	case (MDOC_Hyphen):
+	case (LIST_hyphen):
 		/* FALLTHROUGH */
-	case (MDOC_Item):
+	case (LIST_item):
 		if (mdoc->last->head->child)
 			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST))
 				return(0);
@@ -1018,33 +983,36 @@ post_it(POST_ARGS)
 			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
 				return(0);
 		break;
-	case (MDOC_Column):
+	case (LIST_column):
+		cols = -1;
+		for (i = 0; i < (int)n->args->argc; i++)
+			if (MDOC_Column == n->args->argv[i].arg) {
+				cols = (int)n->args->argv[i].sz;
+				break;
+			}
+
+		assert(-1 != cols);
 		assert(NULL == mdoc->last->head->child);
+
 		if (NULL == mdoc->last->body->child)
 			if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
 				return(0);
 
-		/* Count up the number of columns.  */
-		c = mdoc->last->child;
-		for (i = 0; c; c = c->next)
+		for (i = 0, c = mdoc->last->child; c; c = c->next)
 			if (MDOC_BODY == c->type)
 				i++;
 
-		if (i < cols) {
-			if ( ! mdoc_vmsg(mdoc, MANDOCERR_ARGCOUNT,
-					mdoc->last->line, 
-					mdoc->last->pos, 
-					"columns == %d (have %d)",
-					cols, i))
-				return(0);
-			break;
-		} else if (i == cols || i == cols + 1)
+		if (i < cols)
+			er = MANDOCERR_ARGCOUNT;
+		else if (i == cols || i == cols + 1)
 			break;
+		else
+			er = MANDOCERR_SYNTARGCOUNT;
 
-		mdoc_vmsg(mdoc, MANDOCERR_SYNTARGCOUNT,
+		rc = mdoc_vmsg(mdoc, er, 
 				mdoc->last->line, mdoc->last->pos, 
 				"columns == %d (have %d)", cols, i);
-		return(0);
+		return(rc);
 	default:
 		break;
 	}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2010-05-31 23:10 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=201005312310.o4VNApiw013712@krisdoz.my.domain \
    --to=kristaps@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).