More error checking of bad date specs.

This commit is contained in:
Dianne Skoll
2024-09-10 14:27:46 -04:00
parent c645db5ede
commit 56e62b1b4d
5 changed files with 39 additions and 10 deletions

View File

@@ -437,10 +437,24 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim)
break;
case T_Date:
if (trig->d != NO_DAY) {
DBufFree(&buf);
return E_DAY_TWICE;
}
if (trig->m != NO_MON) {
DBufFree(&buf);
return E_MON_TWICE;
}
if (trig->y != NO_YR) {
DBufFree(&buf);
return E_YR_TWICE;
}
if (tok.val < 0) {
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
DBufFree(&buf);
return -tok.val;
}
DBufFree(&buf);
if (trig->d != NO_DAY) return E_DAY_TWICE;
if (trig->m != NO_MON) return E_MON_TWICE;
if (trig->y != NO_YR) return E_YR_TWICE;
FromDSE(tok.val, &y, &m, &d);
trig->y = y;
trig->m = m;
@@ -893,6 +907,11 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type)
break;
case T_Date:
if (tok.val < 0) {
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
DBufFree(&buf);
return -tok.val;
}
DBufFree(&buf);
if (y != NO_YR) {
Eprint("%s: %s", which, ErrMsg[E_YR_TWICE]);
@@ -985,6 +1004,11 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type)
break;
case T_Date:
if (tok.val < 0) {
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
DBufFree(&buf);
return -tok.val;
}
DBufFree(&buf);
if (y != NO_YR) {
Eprint("%s: %s", word, ErrMsg[E_YR_TWICE]);

View File

@@ -692,6 +692,10 @@ void InitRemind(int argc, char const *argv[])
break;
case T_Date:
if (tok.val < 0) {
fprintf(stderr, "%s: `%s'\n", ErrMsg[-tok.val], arg);
Usage();
}
if (m != NO_MON || d != NO_DAY || y != NO_YR || dse != NO_DATE) Usage();
dse = tok.val;
break;

View File

@@ -350,6 +350,11 @@ int DoOmit(ParsePtr p)
return OK;
case T_Date:
if (tok.val < 0) {
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
DBufFree(&buf);
return -tok.val;
}
DBufFree(&buf);
if (y[seen_through] != NO_YR) return E_YR_TWICE;
if (m[seen_through] != NO_MON) return E_MON_TWICE;

View File

@@ -255,7 +255,9 @@ void FindNumericToken(char const *s, Token *t)
t->type = T_DateTime;
t->val = MINUTES_PER_DAY * dse + tim;
} else {
Wprint("%s: `%s'", ErrMsg[r], s_orig);
t->type = T_Date;
/* Store error message negated as val! */
t->val = -r;
}
return;
}

View File

@@ -5703,12 +5703,6 @@ REM 1 Jan 1873 MSG This should fail
../tests/test.rem(1122): Number `1873' is not recognized as a year or a day number
REM 1873-12-11 MSG Also bad.
../tests/test.rem(1123): Bad date specification: `1873-12-11'
../tests/test.rem(1123): Missing REM type; assuming MSG
../tests/test.rem(1123): Trig = Saturday, 16 February, 1991
../tests/test.rem(1123): Function `subst_ampm' defined at ../tests/test.rem:931 should take 1 argument, but actually takes 7
../tests/test.rem(1123): Function `subst_ampm' defined at ../tests/test.rem:931 should take 1 argument, but actually takes 7
1873-12-11 MSG Also bad.
# Don't want Remind to queue reminders
EXIT