From 5e5656652f6ba7bbed359df2ac0768dd571d51c6 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Wed, 13 Sep 2023 21:38:07 -0700 Subject: [PATCH] update error_table[] E_STRING symbols Now the "E_STRING" errsym strings in error_table[], with exception to the 1st E__BASE entry, all other errsym strings must match the following regular expression: ^E_[A-Z][A-Z0-9_]+$ Renamed "E_1OVER0" to "E_DIVBYZERO". Renamed "E_0OVER0" to "E_ZERODIVZERO". --- CHANGES | 3 +++ Makefile | 1 + errtbl.c | 38 +++++++++++++++++++++++++++++--------- func.c | 4 ++-- help/newerror | 2 -- value.c | 26 +++++++++++++------------- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/CHANGES b/CHANGES index b51a0c4..ebffc3b 100644 --- a/CHANGES +++ b/CHANGES @@ -292,6 +292,9 @@ The following are the changes from calc version 2.14.3.5 to date: Rename the #define E__COUNT to ECOUNT to avoid confusion with "E_STRING" error symbols. + Renamed "E_1OVER0" to "E_DIVBYZERO". + Renamed "E_0OVER0" to "E_ZERODIVZERO". + The following are the changes from calc version 2.14.3.4 to 2.14.3.5: diff --git a/Makefile b/Makefile index b5a48ca..60c61fc 100644 --- a/Makefile +++ b/Makefile @@ -3341,6 +3341,7 @@ clean: clobber: clean ${V} echo '=-=-=-=-= ${MAKE_FILE} start of $@ rule =-=-=-=-=' + ${RM} -f errcode${EXT} ${RM} -f ${SAMPLE_TARGETS} ${RM} -f ${SAMPLE_STATIC_TARGETS} ${RM} -f tags .hsrc hsrc diff --git a/errtbl.c b/errtbl.c index 20ddf30..65a342b 100644 --- a/errtbl.c +++ b/errtbl.c @@ -63,6 +63,18 @@ * * The final entry must have an errnum of -1, errsym of NULL and errmsg of NULL. * + * With exception to the 1st E__BASE entry, all other errsym strings + * must match the following regular expression: + * + * ^E_[A-Z][A-Z0-9_]+$ + * + * NOTE: The above regular expression is more restrictive them the + * "E_STRING" regular expression from help/errno, help/error, + * and help/strerror. This is because errsym strings that + * start with "E__" are special symbols that #define-d in errtbl.h, + * AND because errsym strings that are "^E_[0-9]+$" reserved for + * numeric aliases for errnum. + * * Keep the errmsg short enough that lines in this table are not too long. * You might want to keep the length of the errmsg to 80 characters or less. */ @@ -70,8 +82,8 @@ CONST struct errtbl error_table[] = { /* The E__BASE entry below must start with 10000 and must be first!! */ { 10000, "E__BASE", "No error" }, - { 10001, "E_1OVER0", "Division by zero" }, - { 10002, "E_0OVER0", "Indeterminate (0/0)" }, + { 10001, "E_DIVBYZERO", "Division by zero" }, + { 10002, "E_ZERODIVZERO", "Indeterminate (0/0)" }, { 10003, "E_ADD", "Bad arguments for +" }, { 10004, "E_SUB", "Bad arguments for binary -" }, { 10005, "E_MUL", "Bad arguments for *" }, @@ -745,12 +757,20 @@ verify_error_table(void) program, i, error_table[i].errsym); exit(19); } - for (p = error_table[i].errsym+2; *p != '\0'; ++p) { + p = error_table[i].errsym+2; + if (!isascii(*p) || !isupper(*p)) { + fprintf(stderr, "**** %s ERROR: error_table[%zu].errsym: %s " + "3rd E_STRING char is not UPPER letter, " + "must match the regular expression: %s\n", + program, i, error_table[i].errsym, "^E_[A-Z][A-Z0-9_]+$"); + exit(20); + } + for (p = error_table[i].errsym+3; *p != '\0'; ++p) { if (!isascii(*p) || !(isupper(*p) || isdigit(*p) || *p == '_')) { fprintf(stderr, "**** %s ERROR: error_table[%zu].errsym: %s " - "must match the regular expression: %s\n", + "E_STRING must match the regular expression: %s\n", program, i, error_table[i].errsym, "^E_[A-Z0-9_]+$"); - exit(20); + exit(21); } } @@ -760,7 +780,7 @@ verify_error_table(void) if (strlen(error_table[i].errmsg) <= 0) { fprintf(stderr, "**** %s ERROR: error_table[%zu].errmsg length: %zu must be > 0\n", program, i, strlen(error_table[i].errmsg)); - exit(21); + exit(22); } } @@ -770,17 +790,17 @@ verify_error_table(void) if (error_table[len-1].errnum != -1) { fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errnum: %d != -1\n", program, len-1, error_table[len-1].errnum); - exit(22); + exit(23); } if (error_table[len-1].errsym != NULL) { fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errsym != NULL\n", program, len-1); - exit(23); + exit(24); } if (error_table[len-1].errmsg != NULL) { fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errmsg != NULL\n", program, len-1); - exit(24); + exit(25); } return; } diff --git a/func.c b/func.c index 6a4d943..a6eef13 100644 --- a/func.c +++ b/func.c @@ -3348,7 +3348,7 @@ f_coth(int count, VALUE **vals) switch (vals[0]->v_type) { case V_NUM: if (qiszero(vals[0]->v_num)) - return error_value(E_1OVER0); + return error_value(E_DIVBYZERO); result.v_num = qcoth(vals[0]->v_num, err); result.v_type = V_NUM; break; @@ -3453,7 +3453,7 @@ f_csch(int count, VALUE **vals) switch (vals[0]->v_type) { case V_NUM: if (qiszero(vals[0]->v_num)) - return error_value(E_1OVER0); + return error_value(E_DIVBYZERO); result.v_num = qcsch(vals[0]->v_num, err); result.v_type = V_NUM; break; diff --git a/help/newerror b/help/newerror index d13d3f0..69393a9 100644 --- a/help/newerror +++ b/help/newerror @@ -69,8 +69,6 @@ LIMITS The number of new described error-values is not to exceed E__USERMAX-E__USERDEF (which is usually 12767 calls to the newerror function). - E_STRING is string matching the regular expression: "^E_[A-Z0-9]+$" - LINK LIBRARY none diff --git a/value.c b/value.c index 68c2edfa..26cf423 100644 --- a/value.c +++ b/value.c @@ -688,7 +688,7 @@ invertvalue(VALUE *vp, VALUE *vres) switch (vp->v_type) { case V_NUM: if (qiszero(vp->v_num)) - *vres = error_value(E_1OVER0); + *vres = error_value(E_DIVBYZERO); else vres->v_num = qinv(vp->v_num); return; @@ -700,7 +700,7 @@ invertvalue(VALUE *vp, VALUE *vres) return; case V_OCTET: if (*vp->v_octet == 0) { - *vres = error_value(E_1OVER0); + *vres = error_value(E_DIVBYZERO); return; } q1 = itoq((long) *vp->v_octet); @@ -713,7 +713,7 @@ invertvalue(VALUE *vp, VALUE *vres) *vres = objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); return; default: - if (vp->v_type == -E_1OVER0) { + if (vp->v_type == -E_DIVBYZERO) { vres->v_type = V_NUM; vres->v_num = qlink(&_qzero_); return; @@ -1874,7 +1874,7 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) } vres->v_type = v1->v_type; vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0 && v1->v_type != -E_1OVER0) + if (v1->v_type <= 0 && v1->v_type != -E_DIVBYZERO) return; if (v2->v_type <= 0) { vres->v_type = v2->v_type; @@ -1887,12 +1887,12 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) case V_NUM: /* deal with the division by 0 value */ - if (v1->v_type == -E_1OVER0) { + if (v1->v_type == -E_DIVBYZERO) { if (qisneg(real_v2)) { vres->v_type = V_NUM; vres->v_num = qlink(&_qzero_); } else { - vres->v_type = -E_1OVER0; + vres->v_type = -E_DIVBYZERO; } break; } @@ -1902,7 +1902,7 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) case V_NUM: if (qiszero(v1->v_num)) { if (qisneg(real_v2)) { - *vres = error_value(E_1OVER0); + *vres = error_value(E_DIVBYZERO); break; } vres->v_type = V_NUM; @@ -1950,12 +1950,12 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) case V_COM: /* deal with the division by 0 value */ - if (v1->v_type == -E_1OVER0) { + if (v1->v_type == -E_DIVBYZERO) { if (cisreal(v2->v_com) && qisneg(real_v2)) { vres->v_type = V_NUM; vres->v_num = qlink(&_qzero_); } else { - vres->v_type = -E_1OVER0; + vres->v_type = -E_DIVBYZERO; } break; } @@ -1965,7 +1965,7 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) case V_NUM: if (qiszero(v1->v_num)) { if (cisreal(v2->v_com) && qisneg(real_v2)) { - *vres = error_value(E_1OVER0); + *vres = error_value(E_DIVBYZERO); break; } /* @@ -2132,7 +2132,7 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres) if (v1->v_type <= 0) return; if (v2->v_type <= 0) { - if (testvalue(v1) && v2->v_type == -E_1OVER0) { + if (testvalue(v1) && v2->v_type == -E_DIVBYZERO) { vres->v_type = V_NUM; vres->v_num = qlink(&_qzero_); } @@ -2142,9 +2142,9 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres) } if (!testvalue(v2)) { if (testvalue(v1)) - *vres = error_value(E_1OVER0); + *vres = error_value(E_DIVBYZERO); else - *vres = error_value(E_0OVER0); + *vres = error_value(E_ZERODIVZERO); return; } vres->v_type = v1->v_type;