mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
improved calc computation error codes message array
Changed calc_errno a global int variable so that is may be directly accessed by libcalc users. Further improve help files for help/errno, help/error, help/newerror, help/stoponerror and help/strerror by adding to documentation of the calc error code system as well as libcalc interface where applicable. Changed #define E_USERDEF to #define E__USERDEF. Removed use of E_USERDEF, E__BASE, E__COUNT, and E__HIGHEST from custom/c_sysinfo because the c_sysinfo is just a demo and this will simplify the custom/Makefile. The include file calcerr.h is now the errsym.h include file. The calcerr.tbl has been replaced by errtbl.c and errtbl.h. The calcerr_c.awk, calcerr_c.sed, calcerr_h.awk, and calcerr_h.sed files are now obsolete and have been removed. The calcerr.c and calcerr.h now obsolete and are no longer built. The calc computation error codes, symbols and messages are now in a error_table[] array of struct errtbl. An E_STRING is a string corresponds to an error code #define. For example, the E_STRING for the calc error E_STRCAT, is the string "E_STRING". An E_STRING must now match the regular expression: "^E_[A-Z0-9_]+$". The old array error_table[] of error message strings has been replaced by a new error_table[] array of struct errtbl. The struct errtbl array holds calc errnum error codes, the related E_STRING symbol as a string, and the original related error message. To add new computation error codes, add them near the bottom of the error_table[] array, just before the NULL entry. The ./errcode utility, when run, will verify the consistency of the error_table[] array. The Makefile uses ./errcode -e to generate the contents of help/errorcodes file. The help errorcodes now prints information from the new cstruct errtbl error_table[] array. The help/errorcodes.hdr and help/errorcodes.sed files are now obsolete and have been removed. The Makefile uses ./errcode -d to generate the contents of the errsym.h include file. Updated .gitignore and trailblank to support the above changes.
This commit is contained in:
24
func.c
24
func.c
@@ -93,7 +93,8 @@
|
||||
#include "have_const.h"
|
||||
#include "have_unused.h"
|
||||
#include "calc.h"
|
||||
#include "calcerr.h"
|
||||
#include "errsym.h"
|
||||
#include "errtbl.h"
|
||||
#include "opcodes.h"
|
||||
#include "token.h"
|
||||
#include "func.h"
|
||||
@@ -132,7 +133,6 @@ S_FUNC int malloced_putenv(char *str);
|
||||
* external declarations
|
||||
*/
|
||||
EXTERN char cmdbuf[]; /* command line expression */
|
||||
EXTERN CONST char *error_table[E__COUNT+2]; /* calc coded error messages */
|
||||
E_FUNC void matrandperm(MATRIX *M);
|
||||
E_FUNC void listrandperm(LIST *lp);
|
||||
E_FUNC int idungetc(FILEID id, int ch);
|
||||
@@ -175,7 +175,7 @@ STATIC NUMBER _qfourhundred = { { _fourhundredval_, 1, 0 },
|
||||
/*
|
||||
* user-defined error strings
|
||||
*/
|
||||
STATIC short nexterrnum = E_USERDEF;
|
||||
STATIC short nexterrnum = E__USERDEF;
|
||||
STATIC STRINGHEAD newerrorstr;
|
||||
|
||||
#endif /* !FUNCLIST */
|
||||
@@ -8081,11 +8081,11 @@ f_newerror(int count, VALUE **vals)
|
||||
str = vals[0]->v_str->s_str;
|
||||
if (str == NULL || str[0] == '\0')
|
||||
str = "???";
|
||||
if (nexterrnum == E_USERDEF)
|
||||
if (nexterrnum == E__USERDEF)
|
||||
initstr(&newerrorstr);
|
||||
index = findstr(&newerrorstr, str);
|
||||
if (index >= 0) {
|
||||
errnum = E_USERDEF + index;
|
||||
errnum = E__USERDEF + index;
|
||||
} else {
|
||||
if (nexterrnum == 32767)
|
||||
math_error("Too many new error values");
|
||||
@@ -8131,7 +8131,7 @@ f_strerror(int count, VALUE **vals)
|
||||
i = E__BASE;
|
||||
|
||||
/* firewall - return generic error string if it is not assigned */
|
||||
if (i >= nexterrnum || (i > E__HIGHEST && i < E_USERDEF)
|
||||
if (i >= nexterrnum || (i > E__HIGHEST && i < E__USERDEF)
|
||||
|| (i < E__BASE && strerror(i) == NULL)) {
|
||||
size_t snprintf_len; /* malloced snprintf buffer length */
|
||||
snprintf_len = sizeof("Unknown error 12345678901234567890")+1;
|
||||
@@ -8151,12 +8151,12 @@ f_strerror(int count, VALUE **vals)
|
||||
cp = strerror(i);
|
||||
|
||||
/* user-described error */
|
||||
} else if (i >= E_USERDEF) {
|
||||
cp = namestr(&newerrorstr, i - E_USERDEF);
|
||||
} else if (i >= E__USERDEF) {
|
||||
cp = namestr(&newerrorstr, i - E__USERDEF);
|
||||
|
||||
/* calc-described error */
|
||||
} else {
|
||||
cp = (char *)error_table[i - E__BASE];
|
||||
cp = (char *)error_table[i - E__BASE].errmsg;
|
||||
}
|
||||
|
||||
/* return result as a V_STR */
|
||||
@@ -12105,11 +12105,11 @@ showerrors(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (nexterrnum == E_USERDEF)
|
||||
if (nexterrnum == E__USERDEF)
|
||||
printf("No new error-values created\n");
|
||||
for (i = E_USERDEF; i < nexterrnum; i++)
|
||||
for (i = E__USERDEF; i < nexterrnum; i++)
|
||||
printf("%d: %s\n", i,
|
||||
namestr(&newerrorstr, i - E_USERDEF));
|
||||
namestr(&newerrorstr, i - E__USERDEF));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user