add errsym builtin function

NOTE: errstr was renamed to errsym.

Added errsym builtin function.  The errsym(errnum | "E_STRING")
builtin, , when given a valid integer errnum that corresponds to a
calc error condition, will return an E_STRING string, AND when given
a valid E_STRING string that is associated with a calc error
condition, will return errnum integer that corresponds to a calc
error condition.

Supplying a non-integer numeric errnum code to error(), errno(),
strerror(), or errsym() will result in an error.
This commit is contained in:
Landon Curt Noll
2023-09-20 22:22:49 -07:00
parent 120527d375
commit 1a898caf3f
16 changed files with 366 additions and 55 deletions

10
CHANGES
View File

@@ -329,6 +329,16 @@ The following are the changes from calc version 2.14.3.5 to date:
computation error related E_STRING strings. Now related sets of computation error related E_STRING strings. Now related sets of
E_STRING strings end in _ (underscore) followed by digits. E_STRING strings end in _ (underscore) followed by digits.
Added errsym builtin function. The errsym(errnum | "E_STRING")
builtin, , when given a valid integer errnum that corresponds to a
calc error condition, will return an E_STRING string, AND when given
a valid E_STRING string that is associated with a calc error
condition, will return errnum integer that corresponds to a calc
error condition.
Supplying a non-integer numeric errnum code to error(), errno(),
strerror(), or errsym() will result in an error.
The following are the changes from calc version 2.14.3.4 to 2.14.3.5: The following are the changes from calc version 2.14.3.4 to 2.14.3.5:

View File

@@ -33,6 +33,7 @@
# To replace a Makefile variable, use := symbols. For example: # To replace a Makefile variable, use := symbols. For example:
# #
# CCWERR:= -Werror # CCWERR:= -Werror
# DEBUG:= -O0 -g
# #
# You can append to an existing Makefile variable using '+=' symbols. # You can append to an existing Makefile variable using '+=' symbols.
# For example: # For example:
@@ -67,7 +68,6 @@
# #
# Uncomment these lines: # Uncomment these lines:
# #
# DEBUG:= -O0 -g
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds # FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero # FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow # FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
@@ -77,6 +77,7 @@
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer # CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer # LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1 # CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
# DEBUG:= -O0 -g
#### ####
#### ####
@@ -98,7 +99,6 @@
# #
# Uncomment these lines: # Uncomment these lines:
# #
# DEBUG:= -O0 -g3
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds # FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero # FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow # FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
@@ -109,4 +109,5 @@
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer # CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer # LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1 # CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
DEBUG:= -O0 -g3
#### ####

View File

@@ -9791,9 +9791,143 @@ vrfy(config("redecl_warn",1)==0, '9608: config("redecl_warn",1)==0');
vrfy(config("dupvar_warn",1)==0, '9609: config("dupvar_warn",1)==0'); vrfy(config("dupvar_warn",1)==0, '9609: config("dupvar_warn",1)==0');
/* ************************************************ */ /* *********************************************** */
/* NOTE: ==> Room for new tests 9700-98899 here <== */ /* NOTE: ==> Room for new tests 9700-9899 here <== */
/* ************************************************ */ /* *********************************************** */
/*
* test 99dd: define vrfy_errsym and test E_STRING in error, errno, strerror, errsym
*/
print;
print '9900: Prep to test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")';
/*
* vrfy_errsym - verify errsym builtin function for valid errnum codes and errsym "E_STRING" strings
*/
define vrfy_errsym(testnum, errnum, e_string)
{
local res_errnum; /* errnum result of errsym(e_string) */
local res_errsym; /* errnum result of errsym(errnum) */
/*
* firewall
*/
if (!isint(testnum) || testnum <= 0) {
print '**** Non-true result (' : testnum : \
'): invalid vrfy_errsym testnum (must be int > 0) 1st arg:', testnum;
++prob;
return;
}
if (!isint(errnum) || errnum < 0) {
print '**** Non-true result (' : testnum : \
'): invalid vrfy_errsym errnum (must be int >= 0) 2nd arg:', errnum;
++prob;
return;
}
if (!isstr(e_string) || strlen(e_string) < 3 || strncmp(e_string, "E_", 2) != 0) {
print '**** Non-true result (' : testnum : \
'): invalid vrfy_errsym e_string (must be string starting with E_) 3rd arg:', e_string;
++prob;
return;
}
/*
* try errsym("E_STRING")
*/
res_errnum = errsym(e_string);
if (!isint(res_errnum)) {
print '**** Non-true result (' : testnum : \
'): errsym("' : e_string : '") returned non-integer:', res_errnum;
++prob;
return;
}
/*
* try errsym(errnum)
*/
res_errsym = errsym(errnum);
if (!isstr(res_errsym)) {
print '**** Non-true result (' : testnum : \
'): errsym(' : errnum : ') returned non-string:', res_errsym;
++prob;
return;
}
/*
* compare errnum and res_errnum
*/
if (errnum != res_errnum) {
print '**** Non-true result (' : testnum : \
'): vrfy_errsym errnum 2nd arg:', errnum, '!= errsym("' : e_string : '"):', res_errnum;
++prob;
return;
}
/*
* compare errsym and res_errsym
*/
if (strcmp(e_string, res_errsym) != 0) {
print '**** Non-true result (' : testnum : \
'): vrfy_errsym errsym 3rd arg: "' : e_string : '" != errsym(' : errnum : '): "' : res_errsym : '"';
++prob;
return;
}
/*
* report success
*/
print testnum : ': vrfy_errsym(' : testnum : ',', errnum : ', "' : e_string : '") passed';
return;
}
print '9901: parsed vrfy_errsym()';
++ecnt,;
print '9902: ++ecnt';
res = error("E_ADD");
print '9903: res = error("E_ADD")';
vrfy(iserror(res) == errsym("E_ADD"),
'9904: iserror(res) == errsym("E_ADD")');
vrfy(errno("E_ADD") == errsym("E_ADD"),
'9905: errno("E_ADD") == errsym("E_ADD")');
vrfy(errno() == errsym("E_ADD"),
'9906: errno() == errsym("E_ADD")');
vrfy(strerror("E_ADD") == "Bad arguments for +",
'9907: strerror("E_ADD") == "Bad arguments for +"');
vrfy(errsym("E__NONE") == 0,
'9909: errsym("E__NONE") == 0');
vrfy_errsym(
9910, 0, "E_0");
vrfy(errsym("E__BASE") == 10000,
'9911: errsym("E__BASE") == 10000');
vrfy_errsym(
9912, 10000, "E__BASE");
vrfy(errsym("E__HIGHEST") > errsym("E__BASE"),
'9913: errsym("E__HIGHEST") > errsym("E__BASE")');
vrfy(errsym("E__USERDEF") > errsym("E__HIGHEST"),
'9914: errsym("E__USERDEF") > errsym("E__HIGHEST")');
vrfy(errsym("E__USERDEF") == 20000,
'9915: errsym("E__USERDEF") == 20000');
vrfy_errsym(
9916, 20000, "E_20000");
vrfy(errsym("E__USERMAX") > errsym("E__USERDEF"),
'9917: errsym("E__USERMAX") > errsym("E__USERDEF")');
vrfy(errsym("E__USERMAX") == 32767,
'9918: errsym("E__USERMAX") == 32767');
vrfy_errsym(
9919, 32767, "E_32767");
print '9920: ending test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")';
/* ************************************************* */
/* NOTE: ==> Room for new tests 11000-98899 here <== */
/* ************************************************* */
/* ********************************************************* */ /* ********************************************************* */

View File

@@ -133,7 +133,7 @@
* is needed, add a new code to the bottom (just above the final NULL entry). * is needed, add a new code to the bottom (just above the final NULL entry).
* *
* Starting with calc version 2.15 the E_STRING errsym values became visible * Starting with calc version 2.15 the E_STRING errsym values became visible
* via the error, errno, errstr and strerror builtin interface. DO NOT change * via the error, errno, errsym and strerror builtin interface. DO NOT change
* the existing E_STRING errsym codes once a new code is released in a calc * the existing E_STRING errsym codes once a new code is released in a calc
* stable version. If a different E_STRING errsym code is needed, add a new * stable version. If a different E_STRING errsym code is needed, add a new
* entry to the bottom (just above the final NULL entry). * entry to the bottom (just above the final NULL entry).
@@ -692,11 +692,19 @@ CONST struct errtbl error_table[] = {
{ 10541, "E_CSC_5", "Invalid zero argument for cot" }, { 10541, "E_CSC_5", "Invalid zero argument for cot" },
{ 10542, "E_CSC_6", "Invalid complex argument for csc" }, { 10542, "E_CSC_6", "Invalid complex argument for csc" },
{ 10543, "E_ERROR_3", "String argument is not a valid E_STRING for error" }, { 10543, "E_ERROR_3", "String argument is not a valid E_STRING for error" },
{ 10544, "E_STRERROR_3", "String argument is not a valid E_STRING for strerror" }, { 10544, "E_ERROR_4", "Numeric argument is not an integer for error" },
{ 10545, "E_STRERROR_4", "errnum_2_errmsg returned NULL as called from strerror" }, { 10545, "E_STRERROR_3", "String argument is not a valid E_STRING for strerror" },
{ 10546, "E_ERRNO_1", "Invalid argument type for errno" }, { 10546, "E_STRERROR_4", "errnum_2_errmsg returned NULL as called from strerror" },
{ 10547, "E_ERRNO_2", "Numeric argument is outside valid errnum range for errno" }, { 10547, "E_STRERROR_5", "Numeric argument is not an integer for strerror" },
{ 10548, "E_ERRNO_3", "String argument is not a valid E_STRING for errno" }, { 10548, "E_ERRNO_1", "Invalid argument type for errno" },
{ 10549, "E_ERRNO_2", "Numeric argument is outside valid errnum range for errno" },
{ 10550, "E_ERRNO_3", "String argument is not a valid E_STRING for errno" },
{ 10551, "E_ERRNO_4", "Numeric argument is not an integer for errno" },
{ 10552, "E_ERRSYM_1", "Invalid argument type for errsym" },
{ 10553, "E_ERRSYM_2", "Numeric argument is outside valid errnum range for errsym" },
{ 10554, "E_ERRSYM_3", "String argument is not a valid E_STRING for errsym" },
{ 10555, "E_ERRSYM_4", "Numeric argument is not an integer for errsym" },
{ 10556, "E_ERRSYM_5", "Unable to create a valid E_STRING from the errnum for errsym" },
/* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */ /* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */
/* The next NULL entry must be last */ /* The next NULL entry must be last */
@@ -813,7 +821,7 @@ is_e_digits(CONST char *errsym)
* E__NONE <= errnum <= E__USERMAX * E__NONE <= errnum <= E__USERMAX
* *
* NOTE: This functions does NOT check of the errnum is in * NOTE: This functions does NOT check of the errnum is in
* some struct errtbl array. For that see find_estring_in_errtbl(). * some struct errtbl array. For that see find_errsym_in_errtbl().
* *
* given: * given:
* errnum errnum to check * errnum errnum to check
@@ -1107,7 +1115,7 @@ is_e_2string(CONST char *errsym)
/* /*
* find_estring_in_errtbl - given an E_STRING find it in a struct errtbl array * find_errsym_in_errtbl - given an E_STRING find it in a struct errtbl array
* *
* given: * given:
* errsym E_STRING to check * errsym E_STRING to check
@@ -1118,7 +1126,7 @@ is_e_2string(CONST char *errsym)
* NULL ==> NULL arg, or errsym not found * NULL ==> NULL arg, or errsym not found
*/ */
struct errtbl * struct errtbl *
find_estring_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl) find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl)
{ {
CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */
@@ -1457,7 +1465,7 @@ verify_error_table(void)
* setup the E__HIGHEST entry in private_error_alias[] to be an alias for * setup the E__HIGHEST entry in private_error_alias[] to be an alias for
* the highest assigned calc computation error code from error_table[]. * the highest assigned calc computation error code from error_table[].
*/ */
found = find_estring_in_errtbl("E__HIGHEST", private_error_alias); found = find_errsym_in_errtbl("E__HIGHEST", private_error_alias);
if (found == NULL) { if (found == NULL) {
fprintf(stderr, "**** %s ERROR: private_error_alias missing E__HIGHEST errsym entry", fprintf(stderr, "**** %s ERROR: private_error_alias missing E__HIGHEST errsym entry",
program); program);
@@ -1654,7 +1662,7 @@ errsym_2_errnum(CONST char *errsym)
/* /*
* look in private_error_alias[] for E__ errsym * look in private_error_alias[] for E__ errsym
*/ */
found = find_estring_in_errtbl(errsym, private_error_alias); found = find_errsym_in_errtbl(errsym, private_error_alias);
if (found != NULL) { if (found != NULL) {
/* return matching errnum */ /* return matching errnum */
return found->errnum; return found->errnum;
@@ -1669,7 +1677,7 @@ errsym_2_errnum(CONST char *errsym)
/* /*
* look in error_table[] for E_ errsym * look in error_table[] for E_ errsym
*/ */
found = find_estring_in_errtbl(errsym, error_table); found = find_errsym_in_errtbl(errsym, error_table);
if (found != NULL) { if (found != NULL) {
/* return matching errnum */ /* return matching errnum */
return found->errnum; return found->errnum;

View File

@@ -100,7 +100,7 @@ E_FUNC bool is_errnum_in_error_table(int errnum);
E_FUNC int e_digits_2_errnum(CONST char *errsym); E_FUNC int e_digits_2_errnum(CONST char *errsym);
E_FUNC bool is_e_1string(CONST char *errsym); E_FUNC bool is_e_1string(CONST char *errsym);
E_FUNC bool is_e_2string(CONST char *errsym); E_FUNC bool is_e_2string(CONST char *errsym);
E_FUNC struct errtbl *find_estring_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl); E_FUNC struct errtbl *find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl);
E_FUNC struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl); E_FUNC struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl);
E_FUNC CONST struct errtbl *lookup_errnum_in_error_table(int errnum); E_FUNC CONST struct errtbl *lookup_errnum_in_error_table(int errnum);
E_FUNC void verify_error_table(void); E_FUNC void verify_error_table(void);

124
func.c
View File

@@ -8001,7 +8001,7 @@ S_FUNC VALUE
f_error(int count, VALUE **vals) f_error(int count, VALUE **vals)
{ {
VALUE *vp; VALUE *vp;
long r; long newerr;
/* /*
* case: error() no args * case: error() no args
@@ -8009,7 +8009,7 @@ f_error(int count, VALUE **vals)
if (count == 0) { if (count == 0) {
/* fetch but do NOT set errno */ /* fetch but do NOT set errno */
r = set_errno(NULL_ERRNUM); newerr = set_errno(NULL_ERRNUM);
/* /*
* case: 1 arg * case: 1 arg
@@ -8021,8 +8021,8 @@ f_error(int count, VALUE **vals)
* case: negative or 0 v_type * case: negative or 0 v_type
*/ */
if (vp->v_type <= 0) { if (vp->v_type <= 0) {
r = (long) -vp->v_type; newerr = (long) -vp->v_type;
if (is_valid_errnum(r) == false) { if (is_valid_errnum(newerr) == false) {
error_value(E_ERROR_2); error_value(E_ERROR_2);
math_error("Numeric argument is outside valid errnum range for error"); math_error("Numeric argument is outside valid errnum range for error");
not_reached(); not_reached();
@@ -8038,8 +8038,8 @@ f_error(int count, VALUE **vals)
* case: error("E_STRING") * case: error("E_STRING")
*/ */
case V_STR: case V_STR:
r = errsym_2_errnum(vp->v_str->s_str); newerr = errsym_2_errnum(vp->v_str->s_str);
if (is_valid_errnum(r) == false) { if (is_valid_errnum(newerr) == false) {
error_value(E_ERROR_3); error_value(E_ERROR_3);
math_error("String argument is not a valid E_STRING for error"); math_error("String argument is not a valid E_STRING for error");
not_reached(); not_reached();
@@ -8050,8 +8050,13 @@ f_error(int count, VALUE **vals)
* case: error(errnum) * case: error(errnum)
*/ */
case V_NUM: case V_NUM:
r = qtoi(vp->v_num); if (qisfrac(vp->v_num)) {
if (is_valid_errnum(r) == false) { error_value(E_ERROR_4);
math_error("Numeric argument is not an integer for error");
not_reached();
}
newerr = qtoi(vp->v_num);
if (is_valid_errnum(newerr) == false) {
error_value(E_ERROR_2); error_value(E_ERROR_2);
math_error("Numeric argument is outside valid errnum range for error"); math_error("Numeric argument is outside valid errnum range for error");
not_reached(); not_reached();
@@ -8072,7 +8077,7 @@ f_error(int count, VALUE **vals)
/* /*
* return error * return error
*/ */
return error_value(r); return error_value(newerr);
} }
@@ -8135,6 +8140,11 @@ f_errno(int count, VALUE **vals)
* case: errno(errnum) * case: errno(errnum)
*/ */
case V_NUM: case V_NUM:
if (qisfrac(vp->v_num)) {
error_value(E_ERRNO_4);
math_error("Numeric argument is not an integer for errno");
not_reached();
}
newerr = qtoi(vp->v_num); newerr = qtoi(vp->v_num);
if (is_valid_errnum(newerr) == false) { if (is_valid_errnum(newerr) == false) {
error_value(E_ERRNO_2); error_value(E_ERRNO_2);
@@ -8223,6 +8233,11 @@ f_strerror(int count, VALUE **vals)
* case: strerror(errnum) * case: strerror(errnum)
*/ */
case V_NUM: case V_NUM:
if (qisfrac(vp->v_num)) {
error_value(E_STRERROR_5);
math_error("Numeric argument is not an integer for strerror");
not_reached();
}
errnum = qtoi(vp->v_num); errnum = qtoi(vp->v_num);
if (is_valid_errnum(errnum) == false) { if (is_valid_errnum(errnum) == false) {
error_value(E_STRERROR_2); error_value(E_STRERROR_2);
@@ -8270,6 +8285,95 @@ f_strerror(int count, VALUE **vals)
} }
S_FUNC VALUE
f_errsym(VALUE *vp)
{
int errnum = NULL_ERRNUM; /* global calc_errno value */
bool alloced = false; /* true ==> errsym is allocated, false ==> errsym is static */
char *errsym; /* converted errsym or NULL */
VALUE result; /* errno as a VALUE */
/* initialize VALUE */
result.v_subtype = V_NOSUBTYPE;
/*
* case: negative or 0 v_type OR errno(errnum)
*/
if (vp->v_type <= 0 || vp->v_type == V_NUM) {
/*
* case: negative or 0 v_type
*/
if (vp->v_type <= 0) {
/* convert negative type into a errnum calc_errno-like value */
errnum = (int) -vp->v_type;
/*
* case: errno(errnum)
*/
} else {
/* use arg[1] integer */
if (qisfrac(vp->v_num)) {
error_value(E_ERRSYM_4);
math_error("Numeric argument is not an integer for errsym");
not_reached();
}
errnum = qtoi(vp->v_num);
}
/*
* case: invalid errnum
*/
if (is_valid_errnum(errnum) == false) {
error_value(E_ERRSYM_2);
math_error("Numeric argument is outside valid errnum range for errsym");
not_reached();
}
/*
* convert errnum code into errsym "E_STRING"
*/
errsym = errnum_2_errsym(errnum, &alloced);
if (errsym == NULL) {
error_value(E_ERRSYM_5);
math_error("Unable to create a valid E_STRING from the errnum for errsym");
not_reached();
}
result.v_type = V_STR;
result.v_str = makenewstring(errsym);
if (alloced == true) {
free(errsym);
errsym = NULL;
alloced = false;
}
/*
* case: errno("E_STRING") arg
*/
} else if (vp->v_type == V_STR) {
/*
* convert E_STRING errsym to errno
*/
errnum = errsym_2_errnum(vp->v_str->s_str);
if (is_valid_errnum(errnum) == false) {
error_value(E_ERRSYM_3);
math_error("String argument is not a valid E_STRING for errsym");
not_reached();
}
result.v_type = V_NUM;
result.v_num = itoq((long) errnum);
}
/*
* return result
*/
return result;
}
S_FUNC VALUE S_FUNC VALUE
f_errcount(int count, VALUE **vals) f_errcount(int count, VALUE **vals)
{ {
@@ -11517,6 +11621,8 @@ STATIC CONST struct builtin builtins[] = {
"set or read calc_errno"}, "set or read calc_errno"},
{"error", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_error}, {"error", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_error},
"generate error value"}, "generate error value"},
{"errsym", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_errsym},
"convert between E_STRING errsym into a errnum number"},
{"estr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_estr}, {"estr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_estr},
"exact text string representation of value"}, "exact text string representation of value"},
{"euler", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_euler}, {"euler", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_euler},

View File

@@ -206,7 +206,7 @@ DETAIL_HELP= abs access acos acosh acot acoth acovercos acoversin \
calcpath catalan ceil cfappr cfsim char cmdbuf cmp comb conj cos cosh \ calcpath catalan ceil cfappr cfsim char cmdbuf cmp comb conj cos cosh \
cot coth count covercos coversin cp csc csch ctime d2dm d2dms d2g d2r \ cot coth count covercos coversin cp csc csch ctime d2dm d2dms d2g d2r \
delete den dereference det digit digits display dms2d dp epsilon \ delete den dereference det digit digits display dms2d dp epsilon \
errcount errmax errno error errstr estr euler eval exp fact factor \ errcount errmax errno error errsym estr euler eval exp fact factor \
fclose fcnt feof ferror fflush fgetc fgetfield fgetfile fgetline fgets \ fclose fcnt feof ferror fflush fgetc fgetfield fgetfile fgetline fgets \
fgetstr fib files floor fopen forall fpathopen fprintf fputc fputs \ fgetstr fib files floor fopen forall fpathopen fprintf fputc fputs \
fputstr frac free freebernoulli freeeuler freeglobals freeredc \ fputstr frac free freebernoulli freeeuler freeglobals freeredc \

View File

@@ -45,7 +45,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
errmax, errno, errorcodes, errstr, iserror, newerror, stoponerror, strerror errmax, errno, errorcodes, errsym, iserror, newerror, stoponerror, strerror
## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll ## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll
## ##

View File

@@ -42,7 +42,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
errcount, errno, errorcodes, errstr, iserror, newerror, stoponerror, strerror errcount, errno, errorcodes, errsym, iserror, newerror, stoponerror, strerror
## Copyright (C) 2006,2021,2023 Landon Curt Noll ## Copyright (C) 2006,2021,2023 Landon Curt Noll
## ##

View File

@@ -37,7 +37,7 @@ DESCRIPTION
errno(10003); /* error 10003 has a E_STRING of "E_ADD" */ errno(10003); /* error 10003 has a E_STRING of "E_ADD" */
errno("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ errno("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */
See help errstr for information on E_STRING errsym codes. See help errsym for information on E_STRING errsym codes.
For a list of the E_STRING associated with calc computation error For a list of the E_STRING associated with calc computation error
codes, see help errorcodes. codes, see help errorcodes.
@@ -102,8 +102,21 @@ LINK LIBRARY
CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */
bool is_e_digits(CONST char *errsym);
bool is_valid_errnum(int errnum);
bool is_errnum_in_error_table(int errnum);
bool is_e_1string(CONST char *errsym);
bool is_e_2string(CONST char *errsym);
struct errtbl *find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl);
struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl);
CONST struct errtbl *lookup_errnum_in_error_table(int errnum);
int errsym_2_errnum(CONST char *errsym);
char *errnum_2_errsym(int errnum, bool *palloced);
char *errnum_2_errmsg(int errnum, bool *palloced);
char *errsym_2_errmsg(CONST char *errsym, bool *palloced);
SEE ALSO SEE ALSO
errcount, errmax, errorcodes, errstr, iserror, newerror, stoponerror, strerror errcount, errmax, errorcodes, errsym, iserror, newerror, stoponerror, strerror
## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll ## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll
## ##

View File

@@ -52,7 +52,7 @@ DESCRIPTION
error(10003); /* error 10003 has a E_STRING of "E_ADD" */ error(10003); /* error 10003 has a E_STRING of "E_ADD" */
error("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ error("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */
See help errstr for information on E_STRING errsym codes. See help errsym for information on E_STRING errsym codes.
For a list of the E_STRING associated with calc computation error For a list of the E_STRING associated with calc computation error
codes, see help errorcodes. codes, see help errorcodes.
@@ -138,6 +138,19 @@ LINK LIBRARY
CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */
bool is_e_digits(CONST char *errsym);
bool is_valid_errnum(int errnum);
bool is_errnum_in_error_table(int errnum);
bool is_e_1string(CONST char *errsym);
bool is_e_2string(CONST char *errsym);
struct errtbl *find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl);
struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl);
CONST struct errtbl *lookup_errnum_in_error_table(int errnum);
int errsym_2_errnum(CONST char *errsym);
char *errnum_2_errsym(int errnum, bool *palloced);
char *errnum_2_errmsg(int errnum, bool *palloced);
char *errsym_2_errmsg(CONST char *errsym, bool *palloced);
SEE ALSO SEE ALSO
errcount, errmax, errorcodes, iserror, errno, strerror, newerror, errcount, errmax, errorcodes, iserror, errno, strerror, newerror,
stoponerror stoponerror

View File

@@ -1,8 +1,8 @@
NAME NAME
errstr - convert between "E_STRING" errsym into a errnum number errsym - convert between "E_STRING" errsym into a errnum number
SYNOPSIS SYNOPSIS
errstr(errnum | "E_STRING") errsym(errnum | "E_STRING")
TYPES TYPES
errnum integer errnum integer
@@ -18,7 +18,7 @@ DESCRIPTION
For example: For example:
; print errstr(10003) ; print errsym(10003)
E_ADD E_ADD
When an errnum that matches one of the following errtbl.h #define, When an errnum that matches one of the following errtbl.h #define,
@@ -35,7 +35,7 @@ DESCRIPTION
For example: For example:
; print errstr(0) ; print errsym(0)
E_NONE E_NONE
When E__NONE <= errnum < E__BASE, or when E__USERDEF <= errnum <= E__USERMAX, When E__NONE <= errnum < E__BASE, or when E__USERDEF <= errnum <= E__USERMAX,
@@ -44,7 +44,7 @@ DESCRIPTION
For example: For example:
; print errstr(123) ; print errsym(123)
E_123 E_123
For all other errnum values, an error is returned. For all other errnum values, an error is returned.
@@ -75,7 +75,7 @@ DESCRIPTION
For example: For example:
; print errstr("E_NONE") ; print errsym("E_NONE")
0 0
For all other E_STRING strings that start with "E__", an error is returned. For all other E_STRING strings that start with "E__", an error is returned.
@@ -91,18 +91,18 @@ DESCRIPTION
For example: For example:
; print errstr("E_ADD") ; print errsym("E_ADD")
10003 10003
For all other string arguments, an error is returned. For all other string arguments, an error is returned.
When errstr returns an integer, the global calc error count (see help errcount) When errsym returns an integer, the global calc error count (see help errcount)
is NOT changed. And of course, when errstr("E_STRING") returns an error, the is NOT changed. And of course, when errsym("E_STRING") returns an error, the
global calc error count is incremented by 1. global calc error count is incremented by 1.
Consider the E_MUL calc error condition: Consider the E_MUL calc error condition:
Given a E_STRING errsym, errstr("E_STRING") will return the errnum integer Given a E_STRING errsym, errsym("E_STRING") will return the errnum integer
error code that is associated with the E_STRING errsym. error code that is associated with the E_STRING errsym.
The 4th entry of struct errtbl error_table is: The 4th entry of struct errtbl error_table is:
@@ -116,8 +116,8 @@ DESCRIPTION
Thus 10005 is the errnum, "E_MUL" is the E_STRING errsym that is Thus 10005 is the errnum, "E_MUL" is the E_STRING errsym that is
associated with the errmsg error message: "Bad arguments for +". associated with the errmsg error message: "Bad arguments for +".
In the above example, errstr("E_MUL") will return 10005. In the above example, errsym("E_MUL") will return 10005.
Also errstr("E_10005") will also return 10005. Also errsym("E_10005") will also return 10005.
To complete the E_STRING use in the above example: To complete the E_STRING use in the above example:
@@ -128,16 +128,16 @@ DESCRIPTION
Both strerror(10005) and strerror("E_MUL") both return "Bad arguments for *" Both strerror(10005) and strerror("E_MUL") both return "Bad arguments for *"
EXAMPLE EXAMPLE
; print errstr("E_ADD"), errstr("E_SUB"), errstr("E_MUL"), errstr("E_DIV") ; print errsym("E_ADD"), errsym("E_SUB"), errsym("E_MUL"), errsym("E_DIV")
10003 10004 10005 10006 10003 10004 10005 10006
; print errstr("E__NONE"), errstr("E__BASE"), errstr("E__USERDEF"), errstr("E__USERMAX") ; print errsym("E__NONE"), errsym("E__BASE"), errsym("E__USERDEF"), errsym("E__USERMAX")
0 10000 20000 32767 0 10000 20000 32767
; print errstr(10003), errstr(10004), errstr(10005), errstr(10006) ; print errsym(10003), errsym(10004), errsym(10005), errsym(10006)
E_ADD E_SUB E_MUL E_DIV E_ADD E_SUB E_MUL E_DIV
; print errstr(0), errstr(10000), errstr(20000), errstr(32767) ; print errsym(0), errsym(10000), errsym(20000), errsym(32767)
E__NONE E__BASE E__USERDEF E__USERMAX E__NONE E__BASE E__USERDEF E__USERMAX
LIMITS LIMITS
@@ -150,10 +150,23 @@ LINK LIBRARY
CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */
bool is_e_digits(CONST char *errsym);
bool is_valid_errnum(int errnum);
bool is_errnum_in_error_table(int errnum);
bool is_e_1string(CONST char *errsym);
bool is_e_2string(CONST char *errsym);
struct errtbl *find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl);
struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl);
CONST struct errtbl *lookup_errnum_in_error_table(int errnum);
int errsym_2_errnum(CONST char *errsym);
char *errnum_2_errsym(int errnum, bool *palloced);
char *errnum_2_errmsg(int errnum, bool *palloced);
char *errsym_2_errmsg(CONST char *errsym, bool *palloced);
SEE ALSO SEE ALSO
errcount, errmax, errno, errorcodes, iserror, newerror, stoponerror, strerror errcount, errmax, errno, errorcodes, iserror, newerror, stoponerror, strerror
## Copyright (C) 1999-2006,2023 Landon Curt Noll ## Copyright (C) 2023 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -25,7 +25,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
errcount, errmax, errno, errorcodes, errstr, newerror, stoponerror, strerror errcount, errmax, errno, errorcodes, errsym, newerror, stoponerror, strerror
isassoc, isatty, isblk, isconfig, isdefined, iseven, isfile, isassoc, isatty, isblk, isconfig, isdefined, iseven, isfile,
ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj,

View File

@@ -73,7 +73,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
errcount, errmax, errno, errorcodes, errstr, iserror, stoponerror, strerror errcount, errmax, errno, errorcodes, errsym, iserror, stoponerror, strerror
## Copyright (C) 1999-2006,2023 Landon Curt Noll ## Copyright (C) 1999-2006,2023 Landon Curt Noll
## ##

View File

@@ -36,7 +36,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
errcount, errmax, errno, errorcodes, errstr, iserror, newerror, strerror errcount, errmax, errno, errorcodes, errsym, iserror, newerror, strerror
## Copyright (C) 2006,2021,2023 Landon Curt Noll ## Copyright (C) 2006,2021,2023 Landon Curt Noll
## ##

View File

@@ -33,7 +33,7 @@ DESCRIPTION
cstrerror(10003); /* error 10003 has a E_STRING of "E_ADD" */ cstrerror(10003); /* error 10003 has a E_STRING of "E_ADD" */
cstrerror("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ cstrerror("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */
See help errstr for information on E_STRING errsym codes. See help errsym for information on E_STRING errsym codes.
For a list of the E_STRING associated with calc computation error For a list of the E_STRING associated with calc computation error
codes, see help errorcodes. codes, see help errorcodes.
@@ -106,8 +106,21 @@ LINK LIBRARY
CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */
bool is_e_digits(CONST char *errsym);
bool is_valid_errnum(int errnum);
bool is_errnum_in_error_table(int errnum);
bool is_e_1string(CONST char *errsym);
bool is_e_2string(CONST char *errsym);
struct errtbl *find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl);
struct errtbl *find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl);
CONST struct errtbl *lookup_errnum_in_error_table(int errnum);
int errsym_2_errnum(CONST char *errsym);
char *errnum_2_errsym(int errnum, bool *palloced);
char *errnum_2_errmsg(int errnum, bool *palloced);
char *errsym_2_errmsg(CONST char *errsym, bool *palloced);
SEE ALSO SEE ALSO
errcount, errmax, errno, errorcodes, errstr, iserror, newerror, stoponerror errcount, errmax, errno, errorcodes, errsym, iserror, newerror, stoponerror
strcat, strcpy, strlen, strncmp, strncpy, strpos, strcat, strcpy, strlen, strncmp, strncpy, strpos,
strprintf, strscan, strscanf, substr, strprintf, strscan, strscanf, substr,