-/* $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>
term = '\b';
break;
case 'C':
- if (buf[iarg] != '\'') {
- rval = ESCAPE_ERROR;
- goto out;
- }
rval = ESCAPE_SPECIAL;
term = '\b';
break;
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) {
case '[':
if (buf[++iarg] == ' ') {
iendarg = iend = iarg + 1;
+ err = MANDOCERR_ESC_ARG;
rval = ESCAPE_ERROR;
goto out;
}
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;
}
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
*resc = iesc;
switch (rval) {
- case ESCAPE_ERROR:
- if (err == MANDOCERR_OK)
- err = MANDOCERR_ESC_BAD;
- break;
case ESCAPE_UNSUPP:
err = MANDOCERR_ESC_UNSUPP;
break;