mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Better error messages for ill-formed time.
This commit is contained in:
@@ -805,6 +805,11 @@ static int ParseTimeTrig(ParsePtr s, TimeTrig *tim)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (tok.type == T_Illegal && tok.val < 0) {
|
||||
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
|
||||
DBufFree(&buf);
|
||||
return -tok.val;
|
||||
}
|
||||
if (tim->ttime == NO_TIME) return E_EXPECT_TIME;
|
||||
|
||||
PushToken(DBufValue(&buf), s);
|
||||
|
||||
24
src/token.c
24
src/token.c
@@ -275,8 +275,18 @@ void FindNumericToken(char const *s, Token *t)
|
||||
if (*s == ':' || *s == '.' || *s == TimeSep) {
|
||||
s++;
|
||||
hour = t->val;
|
||||
if (!isdigit(*s)) {
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_TIME;
|
||||
return;
|
||||
}
|
||||
PARSENUM(min, s);
|
||||
if (min > 59) return; /* Illegal time */
|
||||
if (min > 59) {
|
||||
/* Illegal time */
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_TIME;
|
||||
return;
|
||||
}
|
||||
/* Check for p[m] or a[m] */
|
||||
if (*s == 'A' || *s == 'a' || *s == 'P' || *s == 'p') {
|
||||
ampm = tolower(*s);
|
||||
@@ -285,9 +295,17 @@ void FindNumericToken(char const *s, Token *t)
|
||||
s++;
|
||||
}
|
||||
}
|
||||
if (*s) return; /* Illegal time */
|
||||
if (*s) {
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_TIME;
|
||||
return;
|
||||
}
|
||||
if (ampm) {
|
||||
if (hour < 1 || hour > 12) return;
|
||||
if (hour < 1 || hour > 12) {
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_TIME;
|
||||
return;
|
||||
}
|
||||
if (ampm == 'a') {
|
||||
if (hour == 12) {
|
||||
hour = 0;
|
||||
|
||||
@@ -3380,7 +3380,7 @@ REM DURATION 15:00 MSG Should fail... need AT if you have DURATION.
|
||||
|
||||
# Parsing of AM/PM times
|
||||
REM AT 0:00am MSG foo 0a
|
||||
../tests/test.rem(595): Expecting time after AT
|
||||
../tests/test.rem(595): Ill-formed time: `0:00am'
|
||||
REM AT 1:00AM MSG foo 1a
|
||||
../tests/test.rem(596): Trig = Saturday, 16 February, 1991 AT 01:00
|
||||
foo 1a
|
||||
@@ -3430,9 +3430,9 @@ REM AT 12:00am MSG foo 12a
|
||||
foo 12a
|
||||
|
||||
REM AT 13:00AM MSG foo 13a
|
||||
../tests/test.rem(608): Expecting time after AT
|
||||
../tests/test.rem(608): Ill-formed time: `13:00AM'
|
||||
REM AT 0:00pm MSG foo 0p
|
||||
../tests/test.rem(609): Expecting time after AT
|
||||
../tests/test.rem(609): Ill-formed time: `0:00pm'
|
||||
REM AT 1:00PM MSG foo 1p
|
||||
../tests/test.rem(610): Trig = Saturday, 16 February, 1991 AT 13:00
|
||||
foo 1p
|
||||
@@ -3482,7 +3482,7 @@ REM AT 12:00pm MSG foo 12p
|
||||
foo 12p
|
||||
|
||||
REM AT 13:00PM MSG foo 13p
|
||||
../tests/test.rem(622): Expecting time after AT
|
||||
../tests/test.rem(622): Ill-formed time: `13:00PM'
|
||||
|
||||
DEBUG +x
|
||||
SET x 0:00am + 0
|
||||
|
||||
Reference in New Issue
Block a user