version 1.13, 2022/06/07 09:54:40 |
version 1.14, 2022/06/08 13:23:57 |
Line 59 mandoc_escape(const char **rendarg, const char **rarg, |
|
Line 59 mandoc_escape(const char **rendarg, const char **rarg, |
|
* sequence are returned in *resc ... *rend. |
* sequence are returned in *resc ... *rend. |
* Otherwise, *resc is set to aesc and the positions of the escape |
* Otherwise, *resc is set to aesc and the positions of the escape |
* sequence starting at aesc are returned. |
* sequence starting at aesc are returned. |
* Diagnostic messages are generated if and only if resc != NULL, |
* Diagnostic messages are generated if and only if ln != 0, |
* that is, if and only if called by roff_expand(). |
* that is, if and only if called by roff_expand(). |
*/ |
*/ |
enum mandoc_esc |
enum mandoc_esc |
Line 72 roff_escape(const char *buf, const int ln, const int a |
|
Line 72 roff_escape(const char *buf, const int ln, const int a |
|
int iendarg; /* index right after the argument */ |
int iendarg; /* index right after the argument */ |
int iend; /* index right after the sequence */ |
int iend; /* index right after the sequence */ |
int sesc, snam, sarg, sendarg, send; /* for sub-escape */ |
int sesc, snam, sarg, sendarg, send; /* for sub-escape */ |
|
int escterm; /* whether term is escaped */ |
int maxl; /* expected length of the argument */ |
int maxl; /* expected length of the argument */ |
int argl; /* actual length of the argument */ |
int argl; /* actual length of the argument */ |
int c, i; /* for \[char...] parsing */ |
int c, i; /* for \[char...] parsing */ |
int valid_A; /* for \A parsing */ |
int valid_A; /* for \A parsing */ |
enum mandoc_esc rval; /* return value */ |
enum mandoc_esc rval; /* return value */ |
|
enum mandoc_esc stype; /* for sub-escape */ |
enum mandocerr err; /* diagnostic code */ |
enum mandocerr err; /* diagnostic code */ |
char term; /* byte terminating the argument */ |
char term; /* byte terminating the argument */ |
|
|
Line 264 roff_escape(const char *buf, const int ln, const int a |
|
Line 266 roff_escape(const char *buf, const int ln, const int a |
|
|
|
/* Decide how to end the argument. */ |
/* Decide how to end the argument. */ |
|
|
|
escterm = 0; |
|
stype = ESCAPE_EXPAND; |
if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) && |
if ((term == '\b' || (term == '\0' && maxl == INT_MAX)) && |
buf[iarg] == buf[iesc] && roff_escape(buf, ln, iendarg, |
buf[iarg] == buf[iesc]) { |
&sesc, &snam, &sarg, &sendarg, &send) == ESCAPE_EXPAND) |
stype = roff_escape(buf, ln, iendarg, |
goto out_sub; |
&sesc, &snam, &sarg, &sendarg, &send); |
|
if (stype == ESCAPE_EXPAND) |
|
goto out_sub; |
|
} |
|
|
if (term == '\b') { |
if (term == '\b') { |
if (strchr("BDHLRSvxNhl", buf[inam]) != NULL && |
if (stype == ESCAPE_UNDEF) |
|
iarg++; |
|
if (stype != ESCAPE_EXPAND && stype != ESCAPE_UNDEF) { |
|
if (strchr("BHLRSNhlvx", buf[inam]) != NULL && |
|
strchr(" ,.0DLOXYZ^abdhlortuvx|~", |
|
buf[snam]) != NULL) { |
|
err = MANDOCERR_ESC_DELIM; |
|
iend = send; |
|
iarg = iendarg = sesc; |
|
goto out; |
|
} |
|
escterm = 1; |
|
iarg = send; |
|
term = buf[snam]; |
|
} else if (strchr("BDHLRSvxNhl", buf[inam]) != NULL && |
strchr(" %&()*+-./0123456789:<=>", buf[iarg]) != NULL) { |
strchr(" %&()*+-./0123456789:<=>", buf[iarg]) != NULL) { |
err = MANDOCERR_ESC_DELIM; |
err = MANDOCERR_ESC_DELIM; |
if (rval != ESCAPE_EXPAND) |
if (rval != ESCAPE_EXPAND) |
Line 280 roff_escape(const char *buf, const int ln, const int a |
|
Line 301 roff_escape(const char *buf, const int ln, const int a |
|
goto out; |
goto out; |
} |
} |
} |
} |
term = buf[iarg++]; |
if (term == '\b') |
|
term = buf[iarg++]; |
} else if (term == '\0' && maxl == INT_MAX) { |
} else if (term == '\0' && maxl == INT_MAX) { |
if (buf[inam] == 'n' && (buf[iarg] == '+' || buf[iarg] == '-')) |
if (buf[inam] == 'n' && (buf[iarg] == '+' || buf[iarg] == '-')) |
iarg++; |
iarg++; |
Line 311 roff_escape(const char *buf, const int ln, const int a |
|
Line 333 roff_escape(const char *buf, const int ln, const int a |
|
while (maxl > 0) { |
while (maxl > 0) { |
if (buf[iendarg] == '\0') { |
if (buf[iendarg] == '\0') { |
err = MANDOCERR_ESC_INCOMPLETE; |
err = MANDOCERR_ESC_INCOMPLETE; |
if (rval != ESCAPE_EXPAND) |
if (rval != ESCAPE_EXPAND && |
|
rval != ESCAPE_OVERSTRIKE) |
rval = ESCAPE_ERROR; |
rval = ESCAPE_ERROR; |
/* Ignore an incomplete argument except for \w. */ |
/* Usually, ignore an incomplete argument. */ |
if (buf[inam] != 'w') |
if (strchr("Aow", buf[inam]) == NULL) |
iendarg = iarg; |
iendarg = iarg; |
break; |
break; |
} |
} |
if (buf[iendarg] == term) { |
if (escterm == 0 && buf[iendarg] == term) { |
iend = iendarg + 1; |
iend = iendarg + 1; |
break; |
break; |
} |
} |
if (buf[inam] == 'N' && |
|
isdigit((unsigned char)buf[iendarg]) == 0) { |
|
iend = iendarg + 1; |
|
break; |
|
} |
|
if (buf[iendarg] == buf[iesc]) { |
if (buf[iendarg] == buf[iesc]) { |
switch (roff_escape(buf, ln, iendarg, |
stype = roff_escape(buf, ln, iendarg, |
&sesc, &snam, &sarg, &sendarg, &send)) { |
&sesc, &snam, &sarg, &sendarg, &send); |
case ESCAPE_EXPAND: |
if (stype == ESCAPE_EXPAND) |
goto out_sub; |
goto out_sub; |
case ESCAPE_UNDEF: |
iend = send; |
|
if (escterm == 1 && |
|
(buf[snam] == term || buf[inam] == 'N')) |
break; |
break; |
default: |
if (stype != ESCAPE_UNDEF) |
valid_A = 0; |
valid_A = 0; |
break; |
iendarg = send; |
} |
} else if (buf[inam] == 'N' && |
iendarg = iend = send; |
isdigit((unsigned char)buf[iendarg]) == 0) { |
|
iend = iendarg + 1; |
|
break; |
} else { |
} else { |
if (buf[iendarg] == ' ' || buf[iendarg] == '\t') |
if (buf[iendarg] == ' ' || buf[iendarg] == '\t') |
valid_A = 0; |
valid_A = 0; |
|
|
rval = ESCAPE_EXPAND; |
rval = ESCAPE_EXPAND; |
|
|
out: |
out: |
|
if (resc != NULL) |
|
*resc = iesc; |
if (rnam != NULL) |
if (rnam != NULL) |
*rnam = inam; |
*rnam = inam; |
if (rarg != NULL) |
if (rarg != NULL) |
|
|
*rendarg = iendarg; |
*rendarg = iendarg; |
if (rend != NULL) |
if (rend != NULL) |
*rend = iend; |
*rend = iend; |
if (resc == NULL) |
if (ln == 0) |
return rval; |
return rval; |
|
|
/* |
/* |
|
|
* from the parser, not when called from the formatters. |
* from the parser, not when called from the formatters. |
*/ |
*/ |
|
|
*resc = iesc; |
|
switch (rval) { |
switch (rval) { |
case ESCAPE_UNSUPP: |
case ESCAPE_UNSUPP: |
err = MANDOCERR_ESC_UNSUPP; |
err = MANDOCERR_ESC_UNSUPP; |