=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/roff_escape.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/mandoc/roff_escape.c 2022/06/01 23:20:19 1.6 --- src/usr.bin/mandoc/roff_escape.c 2022/06/02 11:28:16 1.7 *************** *** 1,4 **** ! /* $OpenBSD: roff_escape.c,v 1.6 2022/06/01 23:20:19 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2020, 2022 * Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: roff_escape.c,v 1.7 2022/06/02 11:28:16 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2020, 2022 * Ingo Schwarze *************** *** 41,47 **** int iarg, iendarg, iend; enum mandoc_esc rval; ! rval = roff_escape(--*rendarg, 0, 0, NULL, &iarg, &iendarg, &iend); assert(rval != ESCAPE_EXPAND); if (rarg != NULL) *rarg = *rendarg + iarg; --- 41,48 ---- int iarg, iendarg, iend; enum mandoc_esc rval; ! rval = roff_escape(--*rendarg, 0, 0, ! NULL, NULL, &iarg, &iendarg, &iend); assert(rval != ESCAPE_EXPAND); if (rarg != NULL) *rarg = *rendarg + iarg; *************** *** 63,82 **** */ enum mandoc_esc roff_escape(const char *buf, const int ln, const int aesc, ! int *resc, int *rarg, int *rendarg, int *rend) { int iesc; /* index of leading escape char */ int iarg; /* index beginning the argument */ int iendarg; /* index right after the argument */ int iend; /* index right after the sequence */ ! int sesc, sarg, sendarg, send; /* for sub-escape */ int maxl; /* expected length of the argument */ int argl; /* actual length of the argument */ int c, i; /* for \[char...] parsing */ int valid_A; /* for \A parsing */ enum mandoc_esc rval; /* return value */ enum mandocerr err; /* diagnostic code */ - char esc_name; char term; /* byte terminating the argument */ /* --- 64,83 ---- */ enum mandoc_esc roff_escape(const char *buf, const int ln, const int aesc, ! int *resc, int *rnam, int *rarg, int *rendarg, int *rend) { int iesc; /* index of leading escape char */ + int inam; /* index of escape name */ int iarg; /* index beginning the argument */ int iendarg; /* index right after the argument */ int iend; /* index right after the sequence */ ! int sesc, snam, sarg, sendarg, send; /* for sub-escape */ int maxl; /* expected length of the argument */ int argl; /* actual length of the argument */ int c, i; /* for \[char...] parsing */ int valid_A; /* for \A parsing */ enum mandoc_esc rval; /* return value */ enum mandocerr err; /* diagnostic code */ char term; /* byte terminating the argument */ /* *************** *** 84,104 **** * it only makes a difference in copy mode. */ ! iesc = iarg = aesc; do { ! iarg++; ! } while (buf[iarg] == 'E'); /* * Sort the following cases first by syntax category, * then by escape sequence type, and finally by ASCII code. */ ! esc_name = buf[iarg]; ! iendarg = iend = ++iarg; maxl = INT_MAX; term = '\0'; ! switch (esc_name) { /* Escape sequences taking no arguments at all. */ --- 85,104 ---- * it only makes a difference in copy mode. */ ! iesc = inam = aesc; do { ! inam++; ! } while (buf[inam] == 'E'); /* * Sort the following cases first by syntax category, * then by escape sequence type, and finally by ASCII code. */ ! iarg = iendarg = iend = inam + 1; maxl = INT_MAX; term = '\0'; ! switch (buf[inam]) { /* Escape sequences taking no arguments at all. */ *************** *** 269,280 **** if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) && buf[iarg] == buf[iesc] && roff_escape(buf, ln, iendarg, ! &sesc, &sarg, &sendarg, &send) == ESCAPE_EXPAND) goto out_sub; if (term == '\b') { ! if ((esc_name == 'N' && isdigit((unsigned char)buf[iarg])) || ! (esc_name == 'h' && strchr(" %&()*+-./0123456789:<=>", buf[iarg]) != NULL)) { iendarg = iend = iarg + 1; rval = ESCAPE_ERROR; --- 269,280 ---- if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) && buf[iarg] == buf[iesc] && roff_escape(buf, ln, iendarg, ! &sesc, &snam, &sarg, &sendarg, &send) == ESCAPE_EXPAND) 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; *************** *** 282,288 **** } term = buf[iarg++]; } else if (term == '\0' && maxl == INT_MAX) { ! if (esc_name == 'n' && (buf[iarg] == '+' || buf[iarg] == '-')) iarg++; switch (buf[iarg]) { case '(': --- 282,288 ---- } term = buf[iarg++]; } else if (term == '\0' && maxl == INT_MAX) { ! if (buf[inam] == 'n' && (buf[iarg] == '+' || buf[iarg] == '-')) iarg++; switch (buf[iarg]) { case '(': *************** *** 310,316 **** while (maxl > 0) { if (buf[iendarg] == '\0') { /* Ignore an incomplete argument except for \w. */ ! if (esc_name != 'w') iendarg = iarg; break; } --- 310,316 ---- while (maxl > 0) { if (buf[iendarg] == '\0') { /* Ignore an incomplete argument except for \w. */ ! if (buf[inam] != 'w') iendarg = iarg; break; } *************** *** 318,331 **** iend = iendarg + 1; break; } ! if (esc_name == 'N' && isdigit((unsigned char)buf[iendarg]) == 0) { iend = iendarg + 1; break; } if (buf[iendarg] == buf[iesc]) { switch (roff_escape(buf, ln, iendarg, ! &sesc, &sarg, &sendarg, &send)) { case ESCAPE_EXPAND: goto out_sub; case ESCAPE_UNDEF: --- 318,331 ---- iend = iendarg + 1; break; } ! if (buf[inam] == 'N' && isdigit((unsigned char)buf[iendarg]) == 0) { iend = iendarg + 1; break; } if (buf[iendarg] == buf[iesc]) { switch (roff_escape(buf, ln, iendarg, ! &sesc, &snam, &sarg, &sendarg, &send)) { case ESCAPE_EXPAND: goto out_sub; case ESCAPE_UNDEF: *************** *** 350,356 **** /* Post-process depending on the content of the argument. */ argl = iendarg - iarg; ! switch (esc_name) { case '*': if (resc == NULL && argl == 2 && buf[iarg] == '.' && buf[iarg + 1] == 'T') --- 350,356 ---- /* Post-process depending on the content of the argument. */ argl = iendarg - iarg; ! switch (buf[inam]) { case '*': if (resc == NULL && argl == 2 && buf[iarg] == '.' && buf[iarg + 1] == 'T') *************** *** 449,460 **** --- 449,463 ---- out_sub: iesc = sesc; + inam = snam; iarg = sarg; iendarg = sendarg; iend = send; rval = ESCAPE_EXPAND; out: + if (rnam != NULL) + *rnam = inam; if (rarg != NULL) *rarg = iarg; if (rendarg != NULL) *************** *** 478,484 **** err = MANDOCERR_ESC_UNSUPP; break; case ESCAPE_UNDEF: ! if (esc_name == '\\') return rval; err = MANDOCERR_ESC_UNDEF; break; --- 481,487 ---- err = MANDOCERR_ESC_UNSUPP; break; case ESCAPE_UNDEF: ! if (buf[inam] == '\\') return rval; err = MANDOCERR_ESC_UNDEF; break;