Better error than "type mismatch" if we assign a bad value to a system variable.

This commit is contained in:
Dianne Skoll
2026-01-19 18:49:03 -05:00
parent 04ea056820
commit 86e94009a4
4 changed files with 22 additions and 7 deletions

View File

@@ -138,6 +138,7 @@
#define E_EXPR_NODES_EXCEEDED 114
#define E_EXPECTING_EOXPR 115
#define E_EXPECTING_ATOM 116
#define E_BAD_VAL_FOR_SYSVAR 117
#ifdef MK_GLOBALS
#undef EXTERN
@@ -272,6 +273,7 @@ EXTERN char *ErrMsg[]
/* E_EXPR_NODES_EXCEEDED */ "Maximum expression complexity exceeded",
/* E_EXPECTING_EOXPR */ "Expecting operator or end-of-expression",
/* E_EXPECTING_ATOM */ "Expecting constant, variable, function call or (expression)",
/* E_BAD_VAL_FOR_SYSVAR */ "Invalid value for system variable",
}
#endif /* MK_GLOBALS */
;

View File

@@ -172,7 +172,7 @@ static int latitude_longitude_func(int do_set, Value *val, double *var, double m
} else {
if (val->type != STR_TYPE) return E_BAD_TYPE;
x = strtod_in_c_locale(val->v.str, &endptr);
if (*endptr) return E_BAD_TYPE;
if (*endptr) return E_BAD_VAL_FOR_SYSVAR;
}
if (x < min) return E_2LOW;
if (x > max) return E_2HIGH;
@@ -466,7 +466,7 @@ static int datetime_sep_func(int do_set, Value *val)
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, "T") &&
strcmp(val->v.str, "@")) {
return E_BAD_TYPE;
return E_BAD_VAL_FOR_SYSVAR;
}
DateTimeSep = val->v.str[0];
return OK;
@@ -512,7 +512,7 @@ static int default_color_func(int do_set, Value *val)
}
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (sscanf(val->v.str, "%d %d %d", &col_r, &col_g, &col_b) != 3) {
return E_BAD_TYPE;
return E_BAD_VAL_FOR_SYSVAR;
}
/* They either all have to be -1, or all between 0 and 255 */
if (col_r == -1 && col_g == -1 && col_b == -1) {
@@ -547,7 +547,7 @@ static int date_sep_func(int do_set, Value *val)
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, "/") &&
strcmp(val->v.str, "-")) {
return E_BAD_TYPE;
return E_BAD_VAL_FOR_SYSVAR;
}
DateSep = val->v.str[0];
return OK;
@@ -566,7 +566,7 @@ static int time_sep_func(int do_set, Value *val)
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, ":") &&
strcmp(val->v.str, ".")) {
return E_BAD_TYPE;
return E_BAD_VAL_FOR_SYSVAR;
}
TimeSep = val->v.str[0];
return OK;

View File

@@ -16762,7 +16762,12 @@ mbpad("
]8;;https://dianne.skoll.ca\Hello, linky!
]8;;\]8;;https://dianne.skoll.ca\Hello, linky!
]8;;\]8;;https://dianne.skoll.ca\Hello, linky!
]8;;\DynBuf Mallocs: 1120 mallocs; 31872640 bytes
]8;;\../tests/test.rem(1900): Invalid value for system variable
../tests/test.rem(1901): Invalid value for system variable
../tests/test.rem(1902): Invalid value for system variable
../tests/test.rem(1903): Invalid value for system variable
../tests/test.rem(1904): Invalid value for system variable
DynBuf Mallocs: 1124 mallocs; 31872896 bytes
Variable hash table statistics:
Entries: 100146; Buckets: 87719; Non-empty Buckets: 66303
Maxlen: 5; Minlen: 0; Avglen: 1.142; Stddev: 0.878; Avg nonempty len: 1.510
@@ -16784,7 +16789,7 @@ Expression nodes high-water: 302076
Expression nodes leaked: 0
Parse level high-water: 34
Max expr node evaluations per line: 2001
Total expression node evaluations: 106733
Total expression node evaluations: 106738
Test 2
@@ -25187,6 +25192,7 @@ TRANSLATE "Invalid multibyte sequence" ""
TRANSLATE "Maximum expression complexity exceeded" ""
TRANSLATE "Expecting operator or end-of-expression" ""
TRANSLATE "Expecting constant, variable, function call or (expression)" ""
TRANSLATE "Invalid value for system variable" ""
# Other Messages
TRANSLATE "%s function `%s' defined at %s(%s) does not use its argument" ""

View File

@@ -1896,6 +1896,13 @@ REM INFO "Url: https://dianne.skoll.ca" MSG Hello, linky!
REM INFO "Url: https://dianne.skoll.ca" MSF Hello, linky!
REM INFO "Url: https://dianne.skoll.ca" SPECIAL COLOR 255 0 0 Hello, linky!
# Bad values for system variables
SET $Latitude "Cabbage"
SET $Longitude "Carrots"
SET $TimeSep "FOO"
SET $DateSep "BAR"
SET $DefaultColor "My oh my, what lovely eyes!"
# Don't want Remind to queue reminders
EXIT