mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 06:48:47 +02:00
Return T_Illegal with a negative tok.val if we can't parse a numeric token.
This commit is contained in:
36
src/dorem.c
36
src/dorem.c
@@ -437,24 +437,17 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim)
|
||||
break;
|
||||
|
||||
case T_Date:
|
||||
DBufFree(&buf);
|
||||
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);
|
||||
|
||||
FromDSE(tok.val, &y, &m, &d);
|
||||
trig->y = y;
|
||||
trig->m = m;
|
||||
@@ -702,6 +695,11 @@ int ParseRem(ParsePtr s, Trigger *trig, 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;
|
||||
}
|
||||
PushToken(DBufValue(&buf), s);
|
||||
DBufFree(&buf);
|
||||
trig->typ = MSG_TYPE;
|
||||
@@ -907,11 +905,6 @@ 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]);
|
||||
@@ -929,6 +922,11 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (tok.type == T_Illegal && tok.val < 0) {
|
||||
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
|
||||
DBufFree(&buf);
|
||||
return -tok.val;
|
||||
}
|
||||
if (y == NO_YR || m == NO_MON || d == NO_DAY) {
|
||||
Eprint("%s: %s", which, ErrMsg[E_INCOMPLETE]);
|
||||
DBufFree(&buf);
|
||||
@@ -1004,11 +1002,6 @@ 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]);
|
||||
@@ -1053,6 +1046,11 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (tok.type == T_Illegal && tok.val < 0) {
|
||||
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
|
||||
DBufFree(&buf);
|
||||
return -tok.val;
|
||||
}
|
||||
if (y == NO_YR || m == NO_MON || d == NO_DAY) {
|
||||
Eprint("%s: %s", word, ErrMsg[E_INCOMPLETE]);
|
||||
DBufFree(&buf);
|
||||
|
||||
@@ -692,10 +692,6 @@ 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;
|
||||
@@ -721,6 +717,10 @@ void InitRemind(int argc, char const *argv[])
|
||||
break;
|
||||
|
||||
default:
|
||||
if (tok.type == T_Illegal && tok.val < 0) {
|
||||
fprintf(stderr, "%s: `%s'\n", ErrMsg[-tok.val], arg);
|
||||
Usage();
|
||||
}
|
||||
Usage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,11 +350,6 @@ 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;
|
||||
@@ -404,6 +399,8 @@ int DoOmit(ParsePtr p)
|
||||
default:
|
||||
if (tok.type == T_Until) {
|
||||
Eprint("OMIT: UNTIL not allowed; did you mean THROUGH?");
|
||||
} else if (tok.type == T_Illegal && tok.val < 0) {
|
||||
Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf));
|
||||
} else {
|
||||
Eprint("%s: `%s' (OMIT)", ErrMsg[E_UNKNOWN_TOKEN],
|
||||
DBufValue(&buf));
|
||||
|
||||
38
src/token.c
38
src/token.c
@@ -255,7 +255,7 @@ void FindNumericToken(char const *s, Token *t)
|
||||
t->type = T_DateTime;
|
||||
t->val = MINUTES_PER_DAY * dse + tim;
|
||||
} else {
|
||||
t->type = T_Date;
|
||||
t->type = T_Illegal;
|
||||
/* Store error message negated as val! */
|
||||
t->val = -r;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ void FindNumericToken(char const *s, Token *t)
|
||||
|
||||
/* If we hit a comma, swallow it. This allows stuff
|
||||
like Jan 6, 1998 */
|
||||
if (*s == ',') {
|
||||
if (*s == ',' && *(s+1) == 0) {
|
||||
/* Classify the number we've got */
|
||||
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
|
||||
else if (t->val >= 1 && t->val <= 31) t->type = T_Day;
|
||||
@@ -309,7 +309,11 @@ void FindNumericToken(char const *s, Token *t)
|
||||
}
|
||||
|
||||
/* If we hit a non-digit, error! */
|
||||
if (*s) return;
|
||||
if (*s) {
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_NUMBER;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Classify the number we've got */
|
||||
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
|
||||
@@ -319,14 +323,24 @@ void FindNumericToken(char const *s, Token *t)
|
||||
} else if (*s == '*') {
|
||||
s++;
|
||||
PARSENUM(t->val, s);
|
||||
if (*s) return; /* Illegal token if followed by non-numeric char */
|
||||
if (*s) {
|
||||
/* Illegal token if followed by non-numeric char */
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_NUMBER;
|
||||
return;
|
||||
}
|
||||
t->type = T_Rep;
|
||||
return;
|
||||
} else if (*s == '+') {
|
||||
s++;
|
||||
if (*s == '+') { mult = -1; s++; }
|
||||
PARSENUM(t->val, s);
|
||||
if (*s) return; /* Illegal token if followed by non-numeric char */
|
||||
if (*s) {
|
||||
/* Illegal token if followed by non-numeric char */
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_NUMBER;
|
||||
return;
|
||||
}
|
||||
t->type = T_Delta;
|
||||
t->val *= mult;
|
||||
return;
|
||||
@@ -334,7 +348,12 @@ void FindNumericToken(char const *s, Token *t)
|
||||
s++;
|
||||
if (*s == '-') { mult = -1; s++; }
|
||||
PARSENUM(t->val, s);
|
||||
if (*s) return; /* Illegal token if followed by non-numeric char */
|
||||
if (*s) {
|
||||
/* Illegal token if followed by non-numeric char */
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_NUMBER;
|
||||
return;
|
||||
}
|
||||
t->type = T_Back;
|
||||
t->val *= mult;
|
||||
return;
|
||||
@@ -342,7 +361,12 @@ void FindNumericToken(char const *s, Token *t)
|
||||
s++;
|
||||
if (*s == '~') { mult = -1; s++; }
|
||||
PARSENUM(t->val, s);
|
||||
if (*s) return; /* Illegal token if followed by non-numeric char */
|
||||
if (*s) {
|
||||
/* Illegal token if followed by non-numeric char */
|
||||
t->type = T_Illegal;
|
||||
t->val = -E_BAD_NUMBER;
|
||||
return;
|
||||
}
|
||||
t->type = T_BackAdj;
|
||||
t->val *= mult;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user