source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Small cleanup of error reporting: call mandoc_msg() only once at
@ 2022-06-05 10:20 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2022-06-05 10:20 UTC (permalink / raw)
  To: source

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-05 10:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 10:20 mandoc: Small cleanup of error reporting: call mandoc_msg() only once at 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).