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:
Landon Curt Noll
2023-09-13 02:45:33 -07:00
parent 1507adb261
commit a6824debbc
26 changed files with 1236 additions and 941 deletions

68
errtbl.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* errtbl - calc error code table entry
*
* Copyright (C) 2023 Ernest Bowen and Landon Curt Noll
*
* 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
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2023/09/12 20:55:14
* File existed as early as: 2023
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(INCLUDE_ERRTBL_H)
#define INCLUDE_ERRTBL_H
#include "have_const.h"
#include "decl.h"
/*
* primary error code defines
*/
#define E__NONE 0 /* calc_errno cleared: libc errno codes above here */
#define E__BASE 10000 /* calc errors start above here */
#define E__USERDEF 20000 /* user defined error codes start here */
#define E__USERMAX 32767 /* maximum user defined error code */
/*
* calc error code, error symbol and error message
*/
struct errtbl {
int errnum; /* calc error code or -1 */
char *errsym; /* error symbol string - must match the regular expression: ^E_[A-Z0-9_]+$ or NULL */
char *errmsg; /* calc error message or NULL */
};
/*
* The error_table[] array represents the calc computation error related
* error codes, symbols and messages.
*
* The errnum of the 1st entry error_table[0] must be E__BASE.
*
* All errnum for the following entries just be consecutive,
* except for the final NULL entry.
*
* The final entry must have an errnum of -1, errsym of NULL and errmsg of NULL.
*/
EXTERN CONST struct errtbl error_table[]; /* calc error codes, error symbols and error messages */
#endif /* !INCLUDE_ERRTBL_H */