From d9796e72e5f709336c1ae1527cc332bc0a61593c Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Mon, 9 Dec 2024 19:55:23 -0500 Subject: [PATCH] Allow error messages to be localized. --- src/calendar.c | 10 +++---- src/dorem.c | 60 ++++++++++++++++++++--------------------- src/dosubst.c | 10 +++---- src/expr.c | 72 +++++++++++++++++++++++++------------------------- src/files.c | 14 +++++----- src/funcs.c | 8 +++--- src/hbcal.c | 2 +- src/init.c | 48 ++++++++++++++++----------------- src/main.c | 35 +++++++++++++++--------- src/omit.c | 4 +-- src/protos.h | 1 + src/sort.c | 2 +- src/trigger.c | 10 +++---- src/userfns.c | 8 +++--- src/var.c | 10 +++---- tests/test.cmp | 2 ++ tests/test.rem | 5 ++++ 17 files changed, 159 insertions(+), 142 deletions(-) diff --git a/src/calendar.c b/src/calendar.c index 7118af06..bce4df7d 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1250,7 +1250,7 @@ static void PrintLeft(char const *s, int width, char pad) buf = calloc(len+1, sizeof(wchar_t)); if (!buf) { /* Uh-oh... cannot recover */ - fprintf(stderr, "%s\n", ErrMsg[E_NO_MEM]); + fprintf(stderr, "%s\n", GetErr(E_NO_MEM)); exit(EXIT_FAILURE); } } @@ -1335,7 +1335,7 @@ static void PrintCentered(char const *s, int width, char *pad) buf = calloc(len+1, sizeof(wchar_t)); if (!buf) { /* Uh-oh... cannot recover */ - fprintf(stderr, "%s\n", ErrMsg[E_NO_MEM]); + fprintf(stderr, "%s\n", GetErr(E_NO_MEM)); exit(EXIT_FAILURE); } } @@ -1645,7 +1645,7 @@ static void GenerateCalEntries(int col) r=IncludeFile(InitialFile); if (r) { - fprintf(ErrFp, "%s %s: %s\n", ErrMsg[E_ERR_READING], InitialFile, ErrMsg[r]); + fprintf(ErrFp, "%s %s: %s\n", GetErr(E_ERR_READING), InitialFile, GetErr(r)); exit(EXIT_FAILURE); } @@ -1653,7 +1653,7 @@ static void GenerateCalEntries(int col) r = ReadLine(); if (r == E_EOF) return; if (r) { - Eprint("%s: %s", ErrMsg[E_ERR_READING], ErrMsg[r]); + Eprint("%s: %s", GetErr(E_ERR_READING), GetErr(r)); exit(EXIT_FAILURE); } s = FindInitialToken(&tok, CurLine); @@ -1734,7 +1734,7 @@ static void GenerateCalEntries(int col) r=DoCalRem(&p, col); break; } - if (r && (!Hush || r != E_RUN_DISABLED)) Eprint("%s", ErrMsg[r]); + if (r && (!Hush || r != E_RUN_DISABLED)) Eprint("%s", GetErr(r)); /* Destroy the parser - free up resources it may be tying up */ DestroyParser(&p); diff --git a/src/dorem.c b/src/dorem.c index 887cb8c4..ccef690f 100644 --- a/src/dorem.c +++ b/src/dorem.c @@ -284,7 +284,7 @@ int DoRem(ParsePtr p) dse = ComputeTrigger(trig.scanfrom, &trig, &tim, &r, 1); if (r) { if (PurgeMode) { - PurgeEchoLine("%s: %s\n", "#!P! Problem calculating trigger date", ErrMsg[r]); + PurgeEchoLine("%s: %s\n", "#!P! Problem calculating trigger date", GetErr(r)); PurgeEchoLine("%s\n", CurLine); } if (r == E_CANT_TRIG && trig.maybe_uncomputable) { @@ -698,7 +698,7 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim) default: if (tok.type == T_Illegal && tok.val < 0) { - Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf)); + Eprint("%s: `%s'", GetErr(-tok.val), DBufValue(&buf)); DBufFree(&buf); return -tok.val; } @@ -808,7 +808,7 @@ static int ParseTimeTrig(ParsePtr s, TimeTrig *tim) default: if (tok.type == T_Illegal && tok.val < 0) { - Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf)); + Eprint("%s: `%s'", GetErr(-tok.val), DBufValue(&buf)); DBufFree(&buf); return -tok.val; } @@ -887,7 +887,7 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type) case T_Year: DBufFree(&buf); if (y != NO_YR) { - Eprint("%s: %s", which, ErrMsg[E_YR_TWICE]); + Eprint("%s: %s", which, GetErr(E_YR_TWICE)); return E_YR_TWICE; } y = tok.val; @@ -896,7 +896,7 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type) case T_Month: DBufFree(&buf); if (m != NO_MON) { - Eprint("%s: %s", which, ErrMsg[E_MON_TWICE]); + Eprint("%s: %s", which, GetErr(E_MON_TWICE)); return E_MON_TWICE; } m = tok.val; @@ -905,7 +905,7 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type) case T_Day: DBufFree(&buf); if (d != NO_DAY) { - Eprint("%s: %s", which, ErrMsg[E_DAY_TWICE]); + Eprint("%s: %s", which, GetErr(E_DAY_TWICE)); return E_DAY_TWICE; } d = tok.val; @@ -914,15 +914,15 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type) case T_Date: DBufFree(&buf); if (y != NO_YR) { - Eprint("%s: %s", which, ErrMsg[E_YR_TWICE]); + Eprint("%s: %s", which, GetErr(E_YR_TWICE)); return E_YR_TWICE; } if (m != NO_MON) { - Eprint("%s: %s", which, ErrMsg[E_MON_TWICE]); + Eprint("%s: %s", which, GetErr(E_MON_TWICE)); return E_MON_TWICE; } if (d != NO_DAY) { - Eprint("%s: %s", which, ErrMsg[E_DAY_TWICE]); + Eprint("%s: %s", which, GetErr(E_DAY_TWICE)); return E_DAY_TWICE; } FromDSE(tok.val, &y, &m, &d); @@ -930,12 +930,12 @@ static int ParseUntil(ParsePtr s, Trigger *t, int type) default: if (tok.type == T_Illegal && tok.val < 0) { - Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf)); + Eprint("%s: `%s'", GetErr(-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]); + Eprint("%s: %s", which, GetErr(E_INCOMPLETE)); DBufFree(&buf); return E_INCOMPLETE; } @@ -984,7 +984,7 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) case T_Year: DBufFree(&buf); if (y != NO_YR) { - Eprint("%s: %s", word, ErrMsg[E_YR_TWICE]); + Eprint("%s: %s", word, GetErr(E_YR_TWICE)); return E_YR_TWICE; } y = tok.val; @@ -993,7 +993,7 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) case T_Month: DBufFree(&buf); if (m != NO_MON) { - Eprint("%s: %s", word, ErrMsg[E_MON_TWICE]); + Eprint("%s: %s", word, GetErr(E_MON_TWICE)); return E_MON_TWICE; } m = tok.val; @@ -1002,7 +1002,7 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) case T_Day: DBufFree(&buf); if (d != NO_DAY) { - Eprint("%s: %s", word, ErrMsg[E_DAY_TWICE]); + Eprint("%s: %s", word, GetErr(E_DAY_TWICE)); return E_DAY_TWICE; } d = tok.val; @@ -1011,15 +1011,15 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) case T_Date: DBufFree(&buf); if (y != NO_YR) { - Eprint("%s: %s", word, ErrMsg[E_YR_TWICE]); + Eprint("%s: %s", word, GetErr(E_YR_TWICE)); return E_YR_TWICE; } if (m != NO_MON) { - Eprint("%s: %s", word, ErrMsg[E_MON_TWICE]); + Eprint("%s: %s", word, GetErr(E_MON_TWICE)); return E_MON_TWICE; } if (d != NO_DAY) { - Eprint("%s: %s", word, ErrMsg[E_DAY_TWICE]); + Eprint("%s: %s", word, GetErr(E_DAY_TWICE)); return E_DAY_TWICE; } FromDSE(tok.val, &y, &m, &d); @@ -1028,19 +1028,19 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) case T_Back: DBufFree(&buf); if (type != SCANFROM_TYPE) { - Eprint("%s: %s", word, ErrMsg[E_INCOMPLETE]); + Eprint("%s: %s", word, GetErr(E_INCOMPLETE)); return E_INCOMPLETE; } if (y != NO_YR) { - Eprint("%s: %s", word, ErrMsg[E_YR_TWICE]); + Eprint("%s: %s", word, GetErr(E_YR_TWICE)); return E_YR_TWICE; } if (m != NO_MON) { - Eprint("%s: %s", word, ErrMsg[E_MON_TWICE]); + Eprint("%s: %s", word, GetErr(E_MON_TWICE)); return E_MON_TWICE; } if (d != NO_DAY) { - Eprint("%s: %s", word, ErrMsg[E_DAY_TWICE]); + Eprint("%s: %s", word, GetErr(E_DAY_TWICE)); return E_DAY_TWICE; } if (tok.val < 0) { @@ -1054,12 +1054,12 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type) default: if (tok.type == T_Illegal && tok.val < 0) { - Eprint("%s: `%s'", ErrMsg[-tok.val], DBufValue(&buf)); + Eprint("%s: `%s'", GetErr(-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]); + Eprint("%s: %s", word, GetErr(E_INCOMPLETE)); DBufFree(&buf); return E_INCOMPLETE; } @@ -1471,7 +1471,7 @@ int ShouldTriggerReminder(Trigger *t, TimeTrig *tim, int dse, int *err) } if (iter > max) { *err = E_CANT_TRIG; - Eprint("Delta: Bad OMITFUNC? %s", ErrMsg[E_CANT_TRIG]); + Eprint("Delta: Bad OMITFUNC? %s", GetErr(E_CANT_TRIG)); return 0; } } @@ -1690,7 +1690,7 @@ static int ShouldTriggerBasedOnWarn(Trigger *t, int dse, int *err) /* If no proper function exists, barf... */ if (UserFuncExists(t->warn) != 1) { - Eprint("%s: `%s'", ErrMsg[M_BAD_WARN_FUNC], t->warn); + Eprint("%s: `%s'", GetErr(M_BAD_WARN_FUNC), t->warn); return (dse == DSEToday); } for (i=1; ; i++) { @@ -1698,14 +1698,14 @@ static int ShouldTriggerBasedOnWarn(Trigger *t, int dse, int *err) s = buffer; r = EvalExpr(&s, &v, NULL); if (r) { - Eprint("%s: `%s': %s", ErrMsg[M_BAD_WARN_FUNC], - t->warn, ErrMsg[r]); + Eprint("%s: `%s': %s", GetErr(M_BAD_WARN_FUNC), + t->warn, GetErr(r)); return (dse == DSEToday); } if (v.type != INT_TYPE) { DestroyValue(v); - Eprint("%s: `%s': %s", ErrMsg[M_BAD_WARN_FUNC], - t->warn, ErrMsg[E_BAD_TYPE]); + Eprint("%s: `%s': %s", GetErr(M_BAD_WARN_FUNC), + t->warn, GetErr(E_BAD_TYPE)); return (dse == DSEToday); } @@ -1735,7 +1735,7 @@ static int ShouldTriggerBasedOnWarn(Trigger *t, int dse, int *err) } } if (iter > max) { - Eprint("Delta: Bad OMITFUNC? %s", ErrMsg[E_CANT_TRIG]); + Eprint("Delta: Bad OMITFUNC? %s", GetErr(E_CANT_TRIG)); return 0; } if (j == DSEToday) return 1; diff --git a/src/dosubst.c b/src/dosubst.c index ff1baa01..86e385cc 100644 --- a/src/dosubst.c +++ b/src/dosubst.c @@ -128,7 +128,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, } DestroyValue(v); } else { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } if (r != OK) { @@ -158,7 +158,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, } DestroyValue(v); } else { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } if (r != OK) { @@ -184,7 +184,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, } DestroyValue(v); } else { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } if (r != OK) { @@ -312,7 +312,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, } DestroyValue(v); } else { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } @@ -388,7 +388,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, } DestroyValue(v); } else { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } switch(UPPER(c)) { diff --git a/src/expr.c b/src/expr.c index 92231427..d2827d7e 100644 --- a/src/expr.c +++ b/src/expr.c @@ -282,7 +282,7 @@ debug_evaluation(Value *ans, int r, char const *fmt, ...) vfprintf(ErrFp, fmt, argptr); fprintf(ErrFp, " => "); if (r != OK) { - fprintf(ErrFp, "%s\n", ErrMsg[r]); + fprintf(ErrFp, "%s\n", GetErr(r)); } else { PrintValue(ans, ErrFp); fprintf(ErrFp, "\n"); @@ -321,7 +321,7 @@ debug_evaluation_binop(Value *ans, int r, Value *v1, Value *v2, char const *fmt, } fprintf(ErrFp, " => "); if (r != OK) { - fprintf(ErrFp, "%s\n", ErrMsg[r]); + fprintf(ErrFp, "%s\n", GetErr(r)); } else { PrintValue(ans, ErrFp); fprintf(ErrFp, "\n"); @@ -353,7 +353,7 @@ debug_evaluation_unop(Value *ans, int r, Value *v1, char const *fmt, ...) } fprintf(ErrFp, " => "); if (r != OK) { - fprintf(ErrFp, "%s\n", ErrMsg[r]); + fprintf(ErrFp, "%s\n", GetErr(r)); } else { PrintValue(ans, ErrFp); fprintf(ErrFp, "\n"); @@ -426,11 +426,11 @@ eval_builtin(expr_node *node, Value *locals, Value *ans, int *nonconst) /* Check that we have the right number of argumens */ if (node->num_kids < f->minargs) { - Eprint("%s(): %s", f->name, ErrMsg[E_2FEW_ARGS]); + Eprint("%s(): %s", f->name, GetErr(E_2FEW_ARGS)); return E_2FEW_ARGS; } if (node->num_kids > f->maxargs && f->maxargs != NO_MAX) { - Eprint("%s(): %s", f->name, ErrMsg[E_2MANY_ARGS]); + Eprint("%s(): %s", f->name, GetErr(E_2MANY_ARGS)); return E_2MANY_ARGS; } @@ -506,14 +506,14 @@ eval_builtin(expr_node *node, Value *locals, Value *ans, int *nonconst) /* Debug */ if (DebugFlag & DB_PRTEXPR) { if (r) { - fprintf(ErrFp, "%s", ErrMsg[r]); + fprintf(ErrFp, "%s", GetErr(r)); } else { PrintValue(ans, ErrFp); } fprintf(ErrFp, "\n"); } if (r != OK) { - Eprint("%s(): %s", f->name, ErrMsg[r]); + Eprint("%s(): %s", f->name, GetErr(r)); } /* Clean up */ if (info.args) { @@ -546,7 +546,7 @@ debug_enter_userfunc(expr_node *node, Value *locals, int nargs) } else { fname = node->u.value.v.str; } - fprintf(ErrFp, "%s %s(", ErrMsg[E_ENTER_FUN], fname); + fprintf(ErrFp, "%s %s(", GetErr(E_ENTER_FUN), fname); for (i=0; iu.value.v.str; } - fprintf(ErrFp, "%s %s(", ErrMsg[E_LEAVE_FUN], fname); + fprintf(ErrFp, "%s %s(", GetErr(E_LEAVE_FUN), fname); for (i=0; inum_kids < f->nargs) { - DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, ErrMsg[E_2FEW_ARGS])); - Eprint("%s(): %s", f->name, ErrMsg[E_2FEW_ARGS]); + DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, GetErr(E_2FEW_ARGS))); + Eprint("%s(): %s", f->name, GetErr(E_2FEW_ARGS)); return E_2FEW_ARGS; } if (node->num_kids > f->nargs) { - DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, ErrMsg[E_2MANY_ARGS])); - Eprint("%s(): %s", f->name, ErrMsg[E_2MANY_ARGS]); + DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, GetErr(E_2MANY_ARGS))); + Eprint("%s(): %s", f->name, GetErr(E_2MANY_ARGS)); return E_2MANY_ARGS; } @@ -643,7 +643,7 @@ eval_userfunc(expr_node *node, Value *locals, Value *ans, int *nonconst) /* Too many args to fit on stack; put on heap */ new_locals = malloc(node->num_kids * sizeof(Value)); if (!new_locals) { - DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, ErrMsg[E_NO_MEM])); + DBG(fprintf(ErrFp, "%s(...) => %s\n", fname, GetErr(E_NO_MEM))); return E_NO_MEM; } } else { @@ -694,7 +694,7 @@ eval_userfunc(expr_node *node, Value *locals, Value *ans, int *nonconst) if (r != OK) { /* We print the error here in order to get the call stack trace */ - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } if (pushed == OK) pop_call(); @@ -850,7 +850,7 @@ evaluate_expr_node(expr_node *node, Value *locals, Value *ans, int *nonconst) /* Operator? Evaluate it */ r = node->u.operator_func(node, locals, ans, nonconst); if (r != OK) { - Eprint("`%s': %s", get_operator_name(node), ErrMsg[r]); + Eprint("`%s': %s", get_operator_name(node), GetErr(r)); } return r; } @@ -1541,7 +1541,7 @@ static int parse_expr_token(DynamicBuffer *buf, char const **in) } (*in)++; } else { - Eprint("%s `%c' (did you mean `%c%c'?)", ErrMsg[E_PARSE_ERR], c, c, c); + Eprint("%s `%c' (did you mean `%c%c'?)", GetErr(E_PARSE_ERR), c, c, c); return E_PARSE_ERR; } return OK; @@ -1633,10 +1633,10 @@ static int parse_expr_token(DynamicBuffer *buf, char const **in) if (!ISID(c) && c != '$') { if (!c) { - Eprint("%s", ErrMsg[E_EOLN]); + Eprint("%s", GetErr(E_EOLN)); return E_EOLN; } - Eprint("%s `%c'", ErrMsg[E_ILLEGAL_CHAR], c); + Eprint("%s `%c'", GetErr(E_ILLEGAL_CHAR), c); return E_ILLEGAL_CHAR; } @@ -1831,7 +1831,7 @@ static expr_node * parse_function_call(char const **e, int *r, Var *locals, int return free_expr_tree(node); } if (TOKEN_IS(")")) { - Eprint("%s `)'", ErrMsg[E_PARSE_ERR]); + Eprint("%s `)'", GetErr(E_PARSE_ERR)); *r = E_PARSE_ERR; return free_expr_tree(node); } @@ -1859,7 +1859,7 @@ static expr_node * parse_function_call(char const **e, int *r, Var *locals, int if (*r != OK) { if (node->type == N_BUILTIN_FUNC) { f = node->u.builtin_func; - Eprint("%s: %s", f->name, ErrMsg[*r]); + Eprint("%s: %s", f->name, GetErr(*r)); } return free_expr_tree(node); } @@ -1881,7 +1881,7 @@ static int set_constant_value(expr_node *atom) atom->type = N_CONSTANT; if (!*s) { - Eprint("%s", ErrMsg[E_EOLN]); + Eprint("%s", GetErr(E_EOLN)); return E_EOLN; } ampm = 0; @@ -1905,15 +1905,15 @@ static int set_constant_value(expr_node *atom) } else if (*s == '\'') { /* It's a literal date */ s++; if ((r=ParseLiteralDateOrTime(&s, &dse, &tim)) != 0) { - Eprint("%s: %s", ErrMsg[r], DBufValue(&ExprBuf)); + Eprint("%s: %s", GetErr(r), DBufValue(&ExprBuf)); return r; } if (*s != '\'') { if (dse != NO_DATE) { - Eprint("%s: %s", ErrMsg[E_BAD_DATE], DBufValue(&ExprBuf)); + Eprint("%s: %s", GetErr(E_BAD_DATE), DBufValue(&ExprBuf)); return E_BAD_DATE; } else { - Eprint("%s: %s", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf)); + Eprint("%s: %s", GetErr(E_BAD_TIME), DBufValue(&ExprBuf)); return E_BAD_TIME; } } @@ -1944,7 +1944,7 @@ static int set_constant_value(expr_node *atom) if (*s == ':' || *s == '.' || *s == TimeSep) { /* Must be a literal time */ s++; if (!isdigit(*s)) { - Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf)); + Eprint("%s: `%s'", GetErr(E_BAD_TIME), DBufValue(&ExprBuf)); return E_BAD_TIME; } h = val; @@ -1963,12 +1963,12 @@ static int set_constant_value(expr_node *atom) } } if (*s || h>23 || m>59) { - Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf)); + Eprint("%s: `%s'", GetErr(E_BAD_TIME), DBufValue(&ExprBuf)); return E_BAD_TIME; } if (ampm) { if (h < 1 || h > 12) { - Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf)); + Eprint("%s: `%s'", GetErr(E_BAD_TIME), DBufValue(&ExprBuf)); return E_BAD_TIME; } if (ampm == 'a') { @@ -1987,7 +1987,7 @@ static int set_constant_value(expr_node *atom) } /* Not a time - must be a number */ if (*s) { - Eprint("%s: `%s'", ErrMsg[E_BAD_NUMBER], DBufValue(&ExprBuf)); + Eprint("%s: `%s'", GetErr(E_BAD_NUMBER), DBufValue(&ExprBuf)); return E_BAD_NUMBER; } atom->u.value.type = INT_TYPE; @@ -1995,7 +1995,7 @@ static int set_constant_value(expr_node *atom) return OK; } atom->u.value.type = ERR_TYPE; - Eprint("`%s': %s", DBufValue(&ExprBuf), ErrMsg[E_ILLEGAL_CHAR]); + Eprint("`%s': %s", DBufValue(&ExprBuf), GetErr(E_ILLEGAL_CHAR)); return E_ILLEGAL_CHAR; } @@ -2037,7 +2037,7 @@ static int make_atom(expr_node *atom, Var *locals) /* System Variable */ if (*(s) == '$' && isalpha(*(s+1))) { if (!FindSysVar(s+1)) { - Eprint("%s: `%s'", ErrMsg[E_NOSUCH_VAR], s); + Eprint("%s: `%s'", GetErr(E_NOSUCH_VAR), s); return E_NOSUCH_VAR; } if (strlen(s+1) < SHORT_NAME_BUF) { @@ -2117,7 +2117,7 @@ static expr_node *parse_atom(char const **e, int *r, Var *locals, int level) /* Check that it's a valid ID or constant */ s = DBufValue(&ExprBuf); if (!*s) { - Eprint("%s", ErrMsg[E_EOLN]); + Eprint("%s", GetErr(E_EOLN)); *r = E_EOLN; return NULL; } @@ -2126,7 +2126,7 @@ static expr_node *parse_atom(char const **e, int *r, Var *locals, int level) *s != '$' && *s != '"' && *s != '\'') { - Eprint("%s `%c'", ErrMsg[E_ILLEGAL_CHAR], *s); + Eprint("%s `%c'", GetErr(E_ILLEGAL_CHAR), *s); *r = E_ILLEGAL_CHAR; return NULL; } @@ -2512,7 +2512,7 @@ expr_node *parse_expression(char const **e, int *r, Var *locals) } putc('\n', ErrFp); if (*r != OK) { - fprintf(ErrFp, " => Error: %s\n", ErrMsg[*r]); + fprintf(ErrFp, " => Error: %s\n", GetErr(*r)); } else { fprintf(ErrFp, " => "); print_expr_tree(node, ErrFp); diff --git a/src/files.c b/src/files.c index fbc088ed..590fe754 100644 --- a/src/files.c +++ b/src/files.c @@ -519,7 +519,7 @@ static int NextChainedFile(IncludeStruct *i) if (OpenFile(cur->filename) == OK) { return OK; } else { - Eprint("%s: %s", ErrMsg[E_CANT_OPEN], cur->filename); + Eprint("%s: %s", GetErr(E_CANT_OPEN), cur->filename); } } return E_EOF; @@ -537,7 +537,7 @@ static int PopFile(void) int j; if (!Hush && NumIfs) { - Eprint("%s", ErrMsg[E_MISS_ENDIF]); + Eprint("%s", GetErr(E_MISS_ENDIF)); for (j=NumIfs-1; j >=0; j--) { fprintf(ErrFp, "%s(%d): IF without ENDIF\n", FileName, IfLinenos[j]); } @@ -610,7 +610,7 @@ int DoInclude(ParsePtr p, enum TokTypes tok) DBufInit(&path); if ( (r=ParseToken(p, &buf)) ) return r; e = VerifyEoln(p); - if (e) Eprint("%s", ErrMsg[e]); + if (e) Eprint("%s", GetErr(e)); if (tok == T_IncludeR && *(DBufValue(&buf)) != '/') { /* Relative include: Include relative to dir @@ -1028,7 +1028,7 @@ int IncludeFile(char const *fname) if (SetupGlobChain(fname, i) == OK) { /* Glob succeeded */ if (!i->chain) { /* Oops... no matching files */ if (!Hush) { - Eprint("%s: %s", fname, ErrMsg[E_NO_MATCHING_REMS]); + Eprint("%s: %s", fname, GetErr(E_NO_MATCHING_REMS)); } PopFile(); return E_NO_MATCHING_REMS; @@ -1042,14 +1042,14 @@ int IncludeFile(char const *fname) if (!OpenFile(fc->filename)) { return OK; } - Eprint("%s: %s", ErrMsg[E_CANT_OPEN], fc->filename); + Eprint("%s: %s", GetErr(E_CANT_OPEN), fc->filename); RunDisabled = oldRunDisabled; } /* Couldn't open anything... bail */ return PopFile(); } else { if (!Hush) { - Eprint("%s: %s", fname, ErrMsg[E_NO_MATCHING_REMS]); + Eprint("%s: %s", fname, GetErr(E_NO_MATCHING_REMS)); } } return E_NO_MATCHING_REMS; @@ -1063,7 +1063,7 @@ int IncludeFile(char const *fname) return OK; } RunDisabled = oldRunDisabled; - Eprint("%s: %s", ErrMsg[E_CANT_OPEN], fname); + Eprint("%s: %s", GetErr(E_CANT_OPEN), fname); /* Ugh! We failed! */ PopFile(); return E_CANT_OPEN; diff --git a/src/funcs.c b/src/funcs.c index b50e5085..d39f1241 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -1299,10 +1299,10 @@ static int FChoose(expr_node *node, Value *locals, Value *ans, int *nonconst) cur = cur->sibling; } PUT(") => "); - PUT(ErrMsg[E_BAD_TYPE]); + PUT(GetErr(E_BAD_TYPE)); OUT(); } - Eprint("choose(): %s", ErrMsg[E_BAD_TYPE]); + Eprint("choose(): %s", GetErr(E_BAD_TYPE)); return E_BAD_TYPE; } n = v.v.val; @@ -2013,7 +2013,7 @@ static int FIif(expr_node *node, Value *locals, Value *ans, int *nonconst) cur = cur->sibling; } PUT(") => "); - PUT(ErrMsg[E_IIF_ODD]); + PUT(GetErr(E_IIF_ODD)); OUT(); } return E_IIF_ODD; @@ -2752,7 +2752,7 @@ static int SunStuff(int rise, double cosz, int dse) /* Get offset from UTC */ if (CalculateUTC) { if (CalcMinsFromUTC(dse, 12*60, &mins, NULL)) { - Eprint(ErrMsg[E_MKTIME_PROBLEM]); + Eprint(GetErr(E_MKTIME_PROBLEM)); return NO_TIME; } } else mins = MinsFromUTC; diff --git a/src/hbcal.c b/src/hbcal.c index acfd8512..cf1185d3 100644 --- a/src/hbcal.c +++ b/src/hbcal.c @@ -474,7 +474,7 @@ int ComputeJahr(int y, int m, int d, int *ans) } if (d > monlen[m]) { - Eprint("%d %s %d: %s", d, HebMonthNames[m], y, ErrMsg[E_BAD_HEBDATE]); + Eprint("%d %s %d: %s", d, HebMonthNames[m], y, GetErr(E_BAD_HEBDATE)); return E_BAD_HEBDATE; } diff --git a/src/init.c b/src/init.c index 4e1c1370..a5459ccd 100644 --- a/src/init.c +++ b/src/init.c @@ -216,7 +216,7 @@ void InitRemind(int argc, char const *argv[]) RealToday = SystemDate(&CurYear, &CurMon, &CurDay); if (RealToday < 0) { - fprintf(ErrFp, ErrMsg[M_BAD_SYS_DATE], BASE); + fprintf(ErrFp, GetErr(M_BAD_SYS_DATE), BASE); exit(EXIT_FAILURE); } DSEToday = RealToday; @@ -625,7 +625,7 @@ void InitRemind(int argc, char const *argv[]) case 'l': case 'L': DebugFlag |= DB_PRTLINE; break; case 'f': case 'F': DebugFlag |= DB_TRACE_FILES; break; default: - fprintf(ErrFp, ErrMsg[M_BAD_DB_FLAG], *(arg-1)); + fprintf(ErrFp, GetErr(M_BAD_DB_FLAG), *(arg-1)); } } break; @@ -660,7 +660,7 @@ void InitRemind(int argc, char const *argv[]) break; default: - fprintf(ErrFp, ErrMsg[M_BAD_OPTION], *(arg-1)); + fprintf(ErrFp, GetErr(M_BAD_OPTION), *(arg-1)); } } @@ -728,7 +728,7 @@ void InitRemind(int argc, char const *argv[]) default: if (tok.type == T_Illegal && tok.val < 0) { - fprintf(stderr, "%s: `%s'\n", ErrMsg[-tok.val], arg); + fprintf(stderr, "%s: `%s'\n", GetErr(-tok.val), arg); Usage(); } Usage(); @@ -852,7 +852,7 @@ static void ChgUser(char const *user) pwent = getpwnam(user); if (!pwent) { - fprintf(ErrFp, ErrMsg[M_BAD_USER], user); + fprintf(ErrFp, GetErr(M_BAD_USER), user); exit(EXIT_FAILURE); } @@ -860,24 +860,24 @@ static void ChgUser(char const *user) /* Started as root, so drop privileges */ #ifdef HAVE_INITGROUPS if (initgroups(pwent->pw_name, pwent->pw_gid) < 0) { - fprintf(ErrFp, ErrMsg[M_NO_CHG_GID], pwent->pw_gid); + fprintf(ErrFp, GetErr(M_NO_CHG_GID), pwent->pw_gid); exit(EXIT_FAILURE); }; #endif if (setgid(pwent->pw_gid) < 0) { - fprintf(ErrFp, ErrMsg[M_NO_CHG_GID], pwent->pw_gid); + fprintf(ErrFp, GetErr(M_NO_CHG_GID), pwent->pw_gid); exit(EXIT_FAILURE); } if (setuid(pwent->pw_uid) < 0) { - fprintf(ErrFp, ErrMsg[M_NO_CHG_UID], pwent->pw_uid); + fprintf(ErrFp, GetErr(M_NO_CHG_UID), pwent->pw_uid); exit(EXIT_FAILURE); } } home = malloc(strlen(pwent->pw_dir) + 6); if (!home) { - fprintf(ErrFp, "%s", ErrMsg[M_NOMEM_ENV]); + fprintf(ErrFp, "%s", GetErr(M_NOMEM_ENV)); exit(EXIT_FAILURE); } sprintf(home, "HOME=%s", pwent->pw_dir); @@ -885,7 +885,7 @@ static void ChgUser(char const *user) shell = malloc(strlen(pwent->pw_shell) + 7); if (!shell) { - fprintf(ErrFp, "%s", ErrMsg[M_NOMEM_ENV]); + fprintf(ErrFp, "%s", GetErr(M_NOMEM_ENV)); exit(EXIT_FAILURE); } sprintf(shell, "SHELL=%s", pwent->pw_shell); @@ -894,14 +894,14 @@ static void ChgUser(char const *user) if (pwent->pw_uid) { username = malloc(strlen(pwent->pw_name) + 6); if (!username) { - fprintf(ErrFp, "%s", ErrMsg[M_NOMEM_ENV]); + fprintf(ErrFp, "%s", GetErr(M_NOMEM_ENV)); exit(EXIT_FAILURE); } sprintf(username, "USER=%s", pwent->pw_name); putenv(username); logname= malloc(strlen(pwent->pw_name) + 9); if (!logname) { - fprintf(ErrFp, "%s", ErrMsg[M_NOMEM_ENV]); + fprintf(ErrFp, "%s", GetErr(M_NOMEM_ENV)); exit(EXIT_FAILURE); } sprintf(logname, "LOGNAME=%s", pwent->pw_name); @@ -919,7 +919,7 @@ DefineFunction(char const *str) r = DoFset(&p); DestroyParser(&p); if (r != OK) { - fprintf(ErrFp, "-i option: %s: %s\n", str, ErrMsg[r]); + fprintf(ErrFp, "-i option: %s: %s\n", str, GetErr(r)); } } /***************************************************************/ @@ -946,7 +946,7 @@ static void InitializeVar(char const *str) if (isalpha(*str) || *str == '_' || (r > 0 && *str == '(') || (r == 0 && *str == '$') || (r > 0 && isdigit(*str))) { varname[r++] = *str; } else { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_ILLEGAL_CHAR]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(E_ILLEGAL_CHAR)); return; } } @@ -959,13 +959,13 @@ static void InitializeVar(char const *str) } varname[r] = 0; if (!*varname) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(E_MISS_VAR)); return; } if (!*str) { /* Setting a system var does require =expr on the commandline */ if (*varname == '$') { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EQ]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(E_MISS_EQ)); return; } val.type = INT_TYPE; @@ -975,41 +975,41 @@ static void InitializeVar(char const *str) r = PreserveVar(varname); } if (r) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(r)); } return; } if (!*varname) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(E_MISS_VAR)); return; } expr = str+1; if (!*expr) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EXPR]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(E_MISS_EXPR)); return; } r=EvalExpr(&expr, &val, NULL); if (r) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(r)); return; } if (*varname == '$') { r=SetSysVar(varname+1, &val); DestroyValue(val); - if (r) fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + if (r) fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(r)); return; } r=SetVar(varname, &val); if (r) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(r)); return; } r=PreserveVar(varname); - if (r) fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + if (r) fprintf(ErrFp, GetErr(M_I_OPTION), GetErr(r)); return; } @@ -1025,7 +1025,7 @@ AddTrustedUser(char const *username) pwent = getpwnam(username); if (!pwent) { - fprintf(ErrFp, ErrMsg[M_BAD_USER], username); + fprintf(ErrFp, GetErr(M_BAD_USER), username); exit(EXIT_FAILURE); } TrustedUsers[NumTrustedUsers] = pwent->pw_uid; diff --git a/src/main.c b/src/main.c index 2d2eeb65..47b9f6ab 100644 --- a/src/main.c +++ b/src/main.c @@ -172,11 +172,11 @@ int main(int argc, char *argv[]) if (!Hush) { if (DestroyOmitContexts(1)) - Eprint("%s", ErrMsg[E_PUSH_NOPOP]); + Eprint("%s", GetErr(E_PUSH_NOPOP)); if (!Daemon && !NextMode && !NumTriggered && !NumQueued) { - printf("%s\n", ErrMsg[E_NOREMINDERS]); + printf("%s\n", GetErr(E_NOREMINDERS)); } else if (!Daemon && !NextMode && !NumTriggered) { - printf(ErrMsg[M_QUEUED], NumQueued); + printf(GetErr(M_QUEUED), NumQueued); } } @@ -196,7 +196,7 @@ int main(int argc, char *argv[]) return 0; } if (pid == -1) { - fprintf(ErrFp, "%s", ErrMsg[E_CANTFORK]); + fprintf(ErrFp, "%s", GetErr(E_CANTFORK)); return 1; } } @@ -258,14 +258,14 @@ static void DoReminders(void) } if (FileAccessDate < 0) { - fprintf(ErrFp, "%s: `%s': %s.\n", ErrMsg[E_CANTACCESS], InitialFile, strerror(errno)); + fprintf(ErrFp, "%s: `%s': %s.\n", GetErr(E_CANTACCESS), InitialFile, strerror(errno)); exit(EXIT_FAILURE); } r=IncludeFile(InitialFile); if (r) { - fprintf(ErrFp, "%s %s: %s\n", ErrMsg[E_ERR_READING], - InitialFile, ErrMsg[r]); + fprintf(ErrFp, "%s %s: %s\n", GetErr(E_ERR_READING), + InitialFile, GetErr(r)); exit(EXIT_FAILURE); } @@ -273,7 +273,7 @@ static void DoReminders(void) r = ReadLine(); if (r == E_EOF) return; if (r) { - Eprint("%s: %s", ErrMsg[E_ERR_READING], ErrMsg[r]); + Eprint("%s: %s", GetErr(E_ERR_READING), GetErr(r)); exit(EXIT_FAILURE); } s = FindInitialToken(&tok, CurLine); @@ -381,14 +381,14 @@ static void DoReminders(void) } if (r && (!Hush || r != E_RUN_DISABLED)) { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } if (PurgeMode) { if (!purge_handled) { PurgeEchoLine("%s\n", CurLine); } else { if (r) { - PurgeEchoLine("#!P! Could not parse next line: %s\n", ErrMsg[r]); + PurgeEchoLine("#!P! Could not parse next line: %s\n", GetErr(r)); PurgeEchoLine("%s\n", CurLine); } } @@ -1045,7 +1045,7 @@ int DoIf(ParsePtr p) else { if ( (r = EvaluateExpr(p, &v)) ) { syndrome = IF_TRUE | BEFORE_ELSE; - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } else if ( (v.type != STR_TYPE && v.v.val) || (v.type == STR_TYPE && strcmp(v.v.str, "")) ) { @@ -1130,7 +1130,7 @@ int DoIfTrig(ParsePtr p) if (r) { if (r != E_CANT_TRIG || !trig.maybe_uncomputable) { if (!Hush || r != E_RUN_DISABLED) { - Eprint("%s", ErrMsg[r]); + Eprint("%s", GetErr(r)); } } syndrome = IF_FALSE | BEFORE_ELSE; @@ -1194,7 +1194,7 @@ int VerifyEoln(ParsePtr p) if (*DBufValue(&buf) && (*DBufValue(&buf) != '#') && (*DBufValue(&buf) != ';')) { - Eprint("%s: `%s'", ErrMsg[E_EXPECTING_EOL], DBufValue(&buf)); + Eprint("%s: `%s'", GetErr(E_EXPECTING_EOL), DBufValue(&buf)); DBufFree(&buf); return E_EXTRANEOUS_TOKEN; } @@ -2025,3 +2025,12 @@ int GetOnceDate(void) } return OnceDate; } + +char const *GetErr(int r) +{ + char const *s = GetTranslatedString(ErrMsg[r]); + if (s) { + return s; + } + return ErrMsg[r]; +} diff --git a/src/omit.c b/src/omit.c index 62cf5afa..b4af39de 100644 --- a/src/omit.c +++ b/src/omit.c @@ -394,9 +394,9 @@ int DoOmit(ParsePtr p) 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)); + Eprint("%s: `%s'", GetErr(-tok.val), DBufValue(&buf)); } else { - Eprint("%s: `%s' (OMIT)", ErrMsg[E_UNKNOWN_TOKEN], + Eprint("%s: `%s' (OMIT)", GetErr(E_UNKNOWN_TOKEN), DBufValue(&buf)); } DBufFree(&buf); diff --git a/src/protos.h b/src/protos.h index 4dcf50bc..05dcf134 100644 --- a/src/protos.h +++ b/src/protos.h @@ -268,3 +268,4 @@ void InitVars(void); void InitUserFunctions(void); void InitTranslationTable(void); char const *GetTranslatedString(char const *orig); +char const *GetErr(int r); diff --git a/src/sort.c b/src/sort.c index e0b9055c..8d992944 100644 --- a/src/sort.c +++ b/src/sort.c @@ -77,7 +77,7 @@ int InsertIntoSortBuffer(int dse, int tim, char const *body, int typ, int prio) int ShouldGoAfter; if (!new) { - Eprint("%s", ErrMsg[E_NO_MEM]); + Eprint("%s", GetErr(E_NO_MEM)); IssueSortedReminders(); SortByDate = 0; SortByTime = 0; diff --git a/src/trigger.c b/src/trigger.c index 8203b771..21b9aa37 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -265,7 +265,7 @@ static int NextSimpleTrig(int startdate, Trigger *trig, int *err) return j; default: - Eprint("NextSimpleTrig %s %d", ErrMsg[E_SWERR], typ); + Eprint("NextSimpleTrig %s %d", GetErr(E_SWERR), typ); *err = E_SWERR; return -1; } @@ -560,7 +560,7 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim, (trig->d == NO_DAY || trig->m == NO_MON || trig->y == NO_YR)) { - Eprint("%s", ErrMsg[E_REP_FULSPEC]); + Eprint("%s", GetErr(E_REP_FULSPEC)); *err = E_REP_FULSPEC; return -1; } @@ -580,7 +580,7 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim, trig->expired = 1; if (DebugFlag & DB_PRTTRIG) { fprintf(ErrFp, "%s(%d): %s\n", - FileName, LineNo, ErrMsg[E_EXPIRED]); + FileName, LineNo, GetErr(E_EXPIRED)); } return -1; } @@ -630,7 +630,7 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim, trig->expired = 1; if (DebugFlag & DB_PRTTRIG) { fprintf(ErrFp, "%s(%d): %s\n", - FileName, LineNo, ErrMsg[E_EXPIRED]); + FileName, LineNo, GetErr(E_EXPIRED)); } if (save_in_globals) { LastTriggerDate = result; @@ -655,7 +655,7 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim, trig->expired = 1; if (DebugFlag & DB_PRTTRIG) { fprintf(ErrFp, "%s(%d): %s\n", - FileName, LineNo, ErrMsg[E_EXPIRED]); + FileName, LineNo, GetErr(E_EXPIRED)); } return -1; } diff --git a/src/userfns.c b/src/userfns.c index 2020106e..8a1ca0f1 100644 --- a/src/userfns.c +++ b/src/userfns.c @@ -117,13 +117,13 @@ int DoFrename(ParsePtr p) return r; } if (FindBuiltinFunc(DBufValue(&newbuf))) { - Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], DBufValue(&newbuf)); + Eprint("%s: `%s'", GetErr(E_REDEF_FUNC), DBufValue(&newbuf)); DBufFree(&oldbuf); DBufFree(&newbuf); return E_REDEF_FUNC; } if (FindBuiltinFunc(DBufValue(&oldbuf))) { - Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], DBufValue(&oldbuf)); + Eprint("%s: `%s'", GetErr(E_REDEF_FUNC), DBufValue(&oldbuf)); DBufFree(&oldbuf); DBufFree(&newbuf); return E_REDEF_FUNC; @@ -243,7 +243,7 @@ int DoFset(ParsePtr p) DBufFree(&buf); if (!Hush) { if (FindBuiltinFunc(func->name)) { - Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], func->name); + Eprint("%s: `%s'", GetErr(E_REDEF_FUNC), func->name); } } func->node = NULL; @@ -308,7 +308,7 @@ int DoFset(ParsePtr p) (void) ParseNonSpaceChar(p, &r, 0); } if (p->isnested) { - Eprint("%s", ErrMsg[E_CANTNEST_FDEF]); + Eprint("%s", GetErr(E_CANTNEST_FDEF)); DestroyUserFunc(func); return E_PARSE_ERR; } diff --git a/src/var.c b/src/var.c index 8f78bcff..49aa0a87 100644 --- a/src/var.c +++ b/src/var.c @@ -28,9 +28,9 @@ #include "err.h" #define UPPER(c) (islower(c) ? toupper(c) : c) -#define VARIABLE ErrMsg[E_VAR] -#define VALUE ErrMsg[E_VAL] -#define UNDEF ErrMsg[E_UNDEF] +#define VARIABLE GetErr(E_VAR) +#define VALUE GetErr(E_VAL) +#define UNDEF GetErr(E_UNDEF) static int IntMin = INT_MIN; static int IntMax = INT_MAX; @@ -574,7 +574,7 @@ int GetVarValue(char const *str, Value *val) v=FindVar(str, 0); if (!v) { - Eprint("%s: `%s'", ErrMsg[E_NOSUCH_VAR], str); + Eprint("%s: `%s'", GetErr(E_NOSUCH_VAR), str); return E_NOSUCH_VAR; } return CopyValue(val, &v->v); @@ -1010,7 +1010,7 @@ int SetSysVar(char const *name, Value *value) SysVar *v = FindSysVar(name); if (!v) return E_NOSUCH_VAR; if (!v->modifiable) { - Eprint("%s: `$%s'", ErrMsg[E_CANT_MODIFY], name); + Eprint("%s: `$%s'", GetErr(E_CANT_MODIFY), name); return E_CANT_MODIFY; } diff --git a/tests/test.cmp b/tests/test.cmp index bfb00acb..4228dbc9 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -16073,6 +16073,8 @@ Dedup-9996 Dedup-9997 Dedup-9998 Dedup-9999 +../tests/test.rem(1250): `/': Ya tried to divide by zero, ya FOOOL!!!!! +../tests/test.rem(1252): `/': Division by zero Var hash: total = 100141; maxlen = 5; avglen = 1.142 Func hash: total = 100016; maxlen = 5; avglen = 1.140 Dedup hash: total = 10000; maxlen = 7; avglen = 1.828 diff --git a/tests/test.rem b/tests/test.rem index d817820a..e28b7949 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -1246,6 +1246,11 @@ TRANSLATE DUMP DO torture-test.rem +TRANSLATE "Division by zero" "Ya tried to divide by zero, ya FOOOL!!!!!" +set a 1/0 +TRANSLATE "Division by zero" +set a 1/0 + # Output expression-node stats DEBUG +s