]> git.cameronkatri.com Git - mandoc.git/blobdiff - roff_escape.c
Split the excessively generic diagnostic message "invalid escape sequence"
[mandoc.git] / roff_escape.c
index 777d753bc0d29f8db039d9d1af46d3326f741e3e..333e0e3fe47094da9b49b49ac3a4e231d0ad298f 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD$ */
+/* $Id: roff_escape.c,v 1.13 2022/06/07 09:54:40 schwarze Exp $ */
 /*
  * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2020, 2022
  *               Ingo Schwarze <schwarze@openbsd.org>
@@ -206,10 +206,6 @@ roff_escape(const char *buf, const int ln, const int aesc,
                term = '\b';
                break;
        case 'C':
-               if (buf[iarg] != '\'') {
-                       rval = ESCAPE_ERROR;
-                       goto out;
-               }
                rval = ESCAPE_SPECIAL;
                term = '\b';
                break;
@@ -274,12 +270,15 @@ roff_escape(const char *buf, const int ln, const int aesc,
                goto out_sub;
 
        if (term == '\b') {
-               if ((buf[inam] == 'N' && isdigit((unsigned char)buf[iarg])) ||
-                   (buf[inam] == 'h' && strchr(" %&()*+-./0123456789:<=>",
-                    buf[iarg]) != NULL)) {
-                       iendarg = iend = iarg + 1;
-                       rval = ESCAPE_ERROR;
-                       goto out;
+               if (strchr("BDHLRSvxNhl", buf[inam]) != NULL &&
+                   strchr(" %&()*+-./0123456789:<=>", buf[iarg]) != NULL) {
+                       err = MANDOCERR_ESC_DELIM;
+                       if (rval != ESCAPE_EXPAND)
+                               rval = ESCAPE_ERROR;
+                       if (buf[inam] != 'D') {
+                               iendarg = iend = iarg + 1;
+                               goto out;
+                       }
                }
                term = buf[iarg++];
        } else if (term == '\0' && maxl == INT_MAX) {
@@ -293,6 +292,7 @@ roff_escape(const char *buf, const int ln, const int aesc,
                case '[':
                        if (buf[++iarg] == ' ') {
                                iendarg = iend = iarg + 1;
+                               err = MANDOCERR_ESC_ARG;
                                rval = ESCAPE_ERROR;
                                goto out;
                        }
@@ -370,13 +370,23 @@ roff_escape(const char *buf, const int ln, const int aesc,
                case '2':
                case '3':
                case '4':
-                       rval = argl == 1 ? ESCAPE_IGNORE : ESCAPE_ERROR;
+                       if (argl == 1)
+                               rval = ESCAPE_IGNORE;
+                       else {
+                               err = MANDOCERR_ESC_ARG;
+                               rval = ESCAPE_ERROR;
+                       }
                        break;
                case '5':
-                       rval = buf[iarg - 1] == '[' ? ESCAPE_UNSUPP :
-                           ESCAPE_ERROR;
+                       if (buf[iarg - 1] == '[')
+                               rval = ESCAPE_UNSUPP;
+                       else {
+                               err = MANDOCERR_ESC_ARG;
+                               rval = ESCAPE_ERROR;
+                       }
                        break;
                default:
+                       err = MANDOCERR_ESC_ARG;
                        rval = ESCAPE_ERROR;
                        break;
                }
@@ -388,9 +398,16 @@ roff_escape(const char *buf, const int ln, const int aesc,
        switch (rval) {
        case ESCAPE_FONT:
                rval = mandoc_font(buf + iarg, argl);
+               if (rval == ESCAPE_ERROR)
+                       err = MANDOCERR_ESC_ARG;
                break;
 
        case ESCAPE_SPECIAL:
+               if (argl == 0) {
+                       err = MANDOCERR_ESC_BADCHAR;
+                       rval = ESCAPE_ERROR;
+                       break;
+               }
 
                /*
                 * The file chars.c only provides one common list of
@@ -484,10 +501,6 @@ out:
 
        *resc = iesc;
        switch (rval) {
-       case ESCAPE_ERROR:
-               if (err == MANDOCERR_OK)
-                       err = MANDOCERR_ESC_BAD;
-               break;
        case ESCAPE_UNSUPP:
                err = MANDOCERR_ESC_UNSUPP;
                break;