tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: reduce MANDOCERR_SYNTARGCOUNT in libman
Date: Sun, 16 Jan 2011 23:34:31 +0100	[thread overview]
Message-ID: <20110116223431.GB11566@iris.usta.de> (raw)
In-Reply-To: <20110115160836.GA1833@britannica.bec.de>

Hi,

recently, Joerg observed that in libman, .fi with arguments causes a fatal
error - and i say, for no good reason.  The same holds for all the other
argument count checking in libman.

Thus, here is a patch to downgrade all those fatal MANDOCERR_SYNTARGCOUNT
errors to non-fatal MANDOCERR_ARGCOUNT errors.

The affected macros are:

 .br .sp .nf .fi .na with arguments - now skipping the arguments
 .TH lacking arguments - using empty strings instead like groff
 .TH with excessive arguments - skipping those

All these edge cases now work for me.

OK?

Yours,
  Ingo


Index: man_html.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/man_html.c,v
retrieving revision 1.33
diff -u -p -r1.33 man_html.c
--- man_html.c	16 Jan 2011 19:41:16 -0000	1.33
+++ man_html.c	16 Jan 2011 22:28:19 -0000
@@ -96,7 +96,7 @@ static	const struct htmlman mans[MAN_MAX
 	{ man_I_pre, NULL }, /* I */
 	{ man_alt_pre, NULL }, /* IR */
 	{ man_alt_pre, NULL }, /* RI */
-	{ NULL, NULL }, /* na */
+	{ man_ign_pre, NULL }, /* na */
 	{ man_br_pre, NULL }, /* sp */
 	{ man_literal_pre, NULL }, /* nf */
 	{ man_literal_pre, NULL }, /* fi */
@@ -649,7 +649,7 @@ man_literal_pre(MAN_ARGS)
 	} else
 		mh->fl &= ~MANH_LITERAL;
 
-	return(1);
+	return(0);
 }
 
 
Index: man_term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/man_term.c,v
retrieving revision 1.61
diff -u -p -r1.61 man_term.c
--- man_term.c	16 Jan 2011 03:46:21 -0000	1.61
+++ man_term.c	16 Jan 2011 22:28:20 -0000
@@ -122,7 +122,7 @@ static	const struct termact termacts[MAN
 	{ pre_I, NULL, 0 }, /* I */
 	{ pre_alternate, NULL, 0 }, /* IR */
 	{ pre_alternate, NULL, 0 }, /* RI */
-	{ NULL, NULL, MAN_NOTEXT }, /* na */
+	{ pre_ign, NULL, MAN_NOTEXT }, /* na */
 	{ pre_sp, NULL, MAN_NOTEXT }, /* sp */
 	{ pre_literal, NULL, 0 }, /* nf */
 	{ pre_literal, NULL, 0 }, /* fi */
@@ -251,7 +251,7 @@ pre_literal(DECL_ARGS)
 	else
 		mt->fl &= ~MANT_LITERAL;
 
-	return(1);
+	return(0);
 }
 
 /* ARGSUSED */
Index: man_validate.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/man_validate.c,v
retrieving revision 1.39
diff -u -p -r1.39 man_validate.c
--- man_validate.c	16 Jan 2011 19:27:25 -0000	1.39
+++ man_validate.c	16 Jan 2011 22:28:20 -0000
@@ -50,7 +50,6 @@ static	int	  check_part(CHKARGS);
 static	int	  check_root(CHKARGS);
 static	int	  check_sec(CHKARGS);
 static	int	  check_text(CHKARGS);
-static	int	  check_title(CHKARGS);
 
 static	int	  post_AT(CHKARGS);
 static	int	  post_fi(CHKARGS);
@@ -67,7 +66,7 @@ static	v_check	  posts_nf[] = { check_eq
 static	v_check	  posts_par[] = { check_par, NULL };
 static	v_check	  posts_part[] = { check_part, NULL };
 static	v_check	  posts_sec[] = { check_sec, NULL };
-static	v_check	  posts_th[] = { check_ge2, check_le5, check_title, post_TH, NULL };
+static	v_check	  posts_th[] = { check_ge2, check_le5, post_TH, NULL };
 static	v_check	  posts_uc[] = { post_UC, NULL };
 static	v_check	  pres_bline[] = { check_bline, NULL };
 
@@ -197,29 +196,6 @@ check_root(CHKARGS) 
 
 
 static int
-check_title(CHKARGS) 
-{
-	const char	*p;
-
-	assert(n->child);
-	/* FIXME: is this sufficient? */
-	if ('\0' == *n->child->string) {
-		man_nmsg(m, n, MANDOCERR_SYNTARGCOUNT);
-		return(0);
-	}
-
-	for (p = n->child->string; '\0' != *p; p++)
-		/* Only warn about this once... */
-		if (isalpha((u_char)*p) && ! isupper((u_char)*p)) {
-			man_nmsg(m, n, MANDOCERR_UPPERCASE);
-			break;
-		}
-
-	return(1);
-}
-
-
-static int
 check_text(CHKARGS) 
 {
 	char		*p;
@@ -263,10 +239,10 @@ check_##name(CHKARGS) \
 { \
 	if (n->nchild ineq (x)) \
 		return(1); \
-	man_vmsg(m, MANDOCERR_SYNTARGCOUNT, n->line, n->pos, \
+	man_vmsg(m, MANDOCERR_ARGCOUNT, n->line, n->pos, \
 			"line arguments %s %d (have %d)", \
 			#ineq, (x), n->nchild); \
-	return(0); \
+	return(1); \
 }
 
 INEQ_DEFINE(0, ==, eq0)
@@ -393,6 +369,7 @@ check_bline(CHKARGS)
 static int
 post_TH(CHKARGS)
 {
+	const char	*p;
 
 	if (m->meta.title)
 		free(m->meta.title);
@@ -412,14 +389,26 @@ post_TH(CHKARGS)
 	/* ->TITLE<- MSEC DATE SOURCE VOL */
 
 	n = n->child;
-	assert(n);
-	m->meta.title = mandoc_strdup(n->string);
+	if (n && n->string) {
+		for (p = n->string; '\0' != *p; p++) {
+			/* Only warn about this once... */
+			if (isalpha((u_char)*p) && ! isupper((u_char)*p)) {
+				man_nmsg(m, n, MANDOCERR_UPPERCASE);
+				break;
+			}
+		}
+		m->meta.title = mandoc_strdup(n->string);
+	} else
+		m->meta.title = mandoc_strdup("");
 
 	/* TITLE ->MSEC<- DATE SOURCE VOL */
 
-	n = n->next;
-	assert(n);
-	m->meta.msec = mandoc_strdup(n->string);
+	if (n)
+		n = n->next;
+	if (n && n->string)
+		m->meta.msec = mandoc_strdup(n->string);
+	else
+		m->meta.msec = mandoc_strdup("");
 
 	/* TITLE MSEC ->DATE<- SOURCE VOL */
 
@@ -430,7 +419,8 @@ post_TH(CHKARGS)
 	 * string, then use the current date.
 	 */
 
-	n = n->next;
+	if (n)
+		n = n->next;
 	if (n && n->string && *n->string) {
 		m->meta.date = mandoc_a2time
 			(MTIME_ISO_8601, n->string);
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

       reply	other threads:[~2011-01-16 22:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20110115160836.GA1833@britannica.bec.de>
2011-01-16 22:34 ` Ingo Schwarze [this message]
2011-01-16 22:57   ` Kristaps Dzonsons

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=20110116223431.GB11566@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@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).