symbol parsing improvement

This gets rid of a FIXME and K4056 internal bug report.

Allow the comma to be quoted as follows:
     SYMBOLS=S_ice:\,
or
     SYMBOLS=S_ice:','

Disclaimer:
The use of the comma on the map could conflict with future
use of that currently unused symbol for other intended purposes.
This commit is contained in:
nhmall
2023-12-04 14:20:07 -05:00
parent b0f5ad13e1
commit 418953e0e6
2 changed files with 30 additions and 10 deletions
+2
View File
@@ -6491,6 +6491,8 @@ escapes(const char *cp, /* might be 'tp', updating in place */
case 'r': case 'r':
cval = '\r'; cval = '\r';
break; break;
case ',':
cval = ',';
default: default:
cval = *cp; cval = *cp;
} }
+28 -10
View File
@@ -764,25 +764,43 @@ boolean
parsesymbols(register char *opts, int which_set) parsesymbols(register char *opts, int which_set)
{ {
int val; int val;
char *op, *symname, *strval; unsigned i;
char *symname, *strval, *ch = opts,
*first_unquoted_comma = 0, *first_unquoted_colon = 0;
const struct symparse *symp; const struct symparse *symp;
boolean is_glyph = FALSE; boolean is_glyph = FALSE;
/* /* are there any commas or colons that aren't quoted? */
* FIXME: for (i = 0; i < strlen(opts); ++i) {
* The parsing here (and next) yields incorrect results for char *prech, *postch;
* "S_sample=','" or "S_sample=':'".
*/
if ((op = strchr(opts, ',')) != 0) { ch++; /* we never want to match on the first char, so this is ok */
*op++ = '\0'; prech = ch - 1;
if (!parsesymbols(op, which_set)) postch = ch + 1;
if (*ch == ',') {
if (*prech == '\'' && *postch == '\'')
continue;
if (*prech == '\\')
continue;
}
if (*ch == ':') {
if (*prech == '\'' && *postch == '\'')
continue;
}
if (*ch == ',' && !first_unquoted_comma)
first_unquoted_comma = ch;
if (*ch == ':' && !first_unquoted_colon)
first_unquoted_colon = ch;
}
if (first_unquoted_comma != 0) {
*first_unquoted_comma++ = '\0';
if (!parsesymbols(first_unquoted_comma, which_set))
return FALSE; return FALSE;
} }
/* S_sample:string */ /* S_sample:string */
symname = opts; symname = opts;
strval = strchr(opts, ':'); strval = first_unquoted_colon;
if (!strval) if (!strval)
strval = strchr(opts, '='); strval = strchr(opts, '=');
if (!strval) if (!strval)