source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Small cleanup of error reporting: call mandoc_msg() only once at
Date: Sun, 5 Jun 2022 05:20:24 -0500 (EST)	[thread overview]
Message-ID: <3365a0aba3e66d2a@mandoc.bsd.lv> (raw)

Log Message:
-----------
Small cleanup of error reporting:
call mandoc_msg() only once at the end, not sometimes in the middle,
classify incomplete, non-expanding escape sequences as ESCAPE_ERROR,
and also reduce the number of return statemants;
no formatting change intended.

Modified Files:
--------------
    mandoc:
        roff_escape.c

Revision Data
-------------
Index: roff_escape.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff_escape.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lroff_escape.c -Lroff_escape.c -u -p -r1.8 -r1.9
--- roff_escape.c
+++ roff_escape.c
@@ -98,6 +98,7 @@ roff_escape(const char *buf, const int l
 	iarg = iendarg = iend = inam + 1;
 	maxl = INT_MAX;
 	term = '\0';
+	err = MANDOCERR_OK;
 	switch (buf[inam]) {
 
 	/* Escape sequences taking no arguments at all. */
@@ -312,6 +313,10 @@ roff_escape(const char *buf, const int l
 			/* Ignore an incomplete argument except for \w. */
 			if (buf[inam] != 'w')
 				iendarg = iarg;
+			if (rval == ESCAPE_EXPAND)
+				err = MANDOCERR_ESC_BAD;
+			else
+				rval = ESCAPE_ERROR;
 			break;
 		}
 		if (buf[iendarg] == term) {
@@ -343,9 +348,6 @@ roff_escape(const char *buf, const int l
 			iend = ++iendarg;
 		}
 	}
-	if (resc != NULL && ((maxl != INT_MAX && maxl != 0) ||
-	    (term != '\0' && buf[iendarg] != term)))
-		mandoc_msg(MANDOCERR_ESC_BAD, ln, iesc, "%s", buf + iesc);
 
 	/* Post-process depending on the content of the argument. */
 
@@ -481,18 +483,17 @@ out:
 		err = MANDOCERR_ESC_UNSUPP;
 		break;
 	case ESCAPE_UNDEF:
-		if (buf[inam] == '\\' || buf[inam] == '.')
-			return rval;
-		err = MANDOCERR_ESC_UNDEF;
+		if (buf[inam] != '\\' && buf[inam] != '.')
+			err = MANDOCERR_ESC_UNDEF;
 		break;
 	case ESCAPE_SPECIAL:
-		if (mchars_spec2cp(buf + iarg, argl) >= 0)
-			return rval;
-		err = MANDOCERR_ESC_BAD;
+		if (mchars_spec2cp(buf + iarg, argl) < 0)
+			err = MANDOCERR_ESC_BAD;
 		break;
 	default:
-		return rval;
+		break;
 	}
-	mandoc_msg(err, ln, iesc, "%.*s", iend - iesc, buf + iesc);
+	if (err != MANDOCERR_OK)
+		mandoc_msg(err, ln, iesc, "%.*s", iend - iesc, buf + iesc);
 	return rval;
 }
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


                 reply	other threads:[~2022-06-05 10:20 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=3365a0aba3e66d2a@mandoc.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.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).