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

View File

@@ -247,8 +247,7 @@ SINGULAR_FILES= binding bug change errorcode type
# These files are found (but not built) in the distribution
#
DISTLIST= ${STD_HELP_FILES} ${DETAIL_HELP} ${MAKE_FILE} \
obj.file builtin.top builtin.end funclist.sed \
errorcodes.hdr errorcodes.sed
obj.file builtin.top builtin.end funclist.sed
# These files are used to make (but not built) a calc .a link library
#
@@ -361,10 +360,9 @@ contrib: ../CONTRIB-CODE
${TRUE}; \
fi
errorcodes: ../calcerr.h errorcodes.hdr errorcodes.sed
errorcodes: ../errcode${EXT}
${RM} -f $@
${CAT} errorcodes.hdr > $@
${SED} -n -f errorcodes.sed < ../calcerr.h >> $@
../errcode${EXT} -e > $@
${CHMOD} 0444 $@
-@if [ -z "${Q}" ]; then \
echo ''; \
@@ -639,8 +637,7 @@ detail_help_list:
! -name archive ! -name assoc ! -name builtin.end \
! -name builtin.top ! -name command ! -name config \
! -name contrib ! -name credit ! -name custom ! -name define \
! -name environment ! -name errorcodes.hdr \
! -name errorcodes.sed ! -name expression ! -name file \
! -name environment ! -name expression ! -name file \
! -name funclist.c ! -name funclist.sed ! -name help \
! -name history ! -name interrupt ! -name intro ! -name list \
! -name mat ! -name obj.file ! -name operator \

View File

@@ -2,10 +2,11 @@ NAME
errno - return or set a the global calc_errno value
SYNOPSIS
errno([errnum])
errno([errnum | "E_STRING"])
TYPES
errnum integer
E_STRING string
return integer
@@ -68,6 +69,8 @@ LIMITS
LINK LIBRARY
int calc_errno; /* global calc_errno value */
E_STRING is C string matching the regular expression: "^E_[A-Z0-9_]+$"
SEE ALSO
errmax, errcount, error, strerror, iserror, newerror, errorcodes,
stoponerror

View File

@@ -2,10 +2,11 @@ NAME
error - raise a calc error condition
SYNOPSIS
error([errnum])
error([errnum | "E_STRING"])
TYPES
errnum integer, defaults to errno()
E_STRING string
return null value or error value
@@ -74,10 +75,13 @@ DESCRIPTION
The following constants are part of the calc error code mechanism:
E__BASE == 10000 # 1 less than the 1st calc computation error code
E_USERDEF == 20000 # User defined error codes start
E_USERMAX == 32767 # maximum user defined error code
E__BASE < E__HIGHEST < E_USERDEF # How E__HIGHEST is bounded
E__COUNT == E__HIGHEST - E__BASE # Number of calc computation error codes
E__COUNT # number of calc computation error codes (not including E__BASE)
E__HIGHEST # highest assigned calc computation error code
E__USERDEF == 20000 # user defined error codes start here
E__USERMAX == 32767 # maximum user defined error code
See help errorcodes for the actual values of the above constants.
@@ -111,6 +115,8 @@ EXAMPLE
LIMITS
0 <= errnum <= 32767
E_STRING is C string matching the regular expression: "^E_[A-Z0-9_]+$"
LINK LIBRARY
int calc_errno; /* global calc_errno value */

View File

@@ -1,25 +0,0 @@
Calc generated error codes (see the error help file):
## Copyright (C) 1999,2023 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: 1995/12/18 03:19:11
## File existed as early as: 1995
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
0 calc_errno cleared: libc errno codes above here
10000 calc errors start above here

View File

@@ -1,23 +0,0 @@
/^#define E_[^_].*[ ][1-9][0-9]*[ ]\/\* .* \*\//s/#define E_.*[ ]\([1-9][0-9]*\)[ ]*\/\* \(.*\)[ ][ ]*\*\// \1 \2/p
## Copyright (C) 1999 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: 1995/12/18 03:19:11
## File existed as early as: 1995
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -66,9 +66,11 @@ EXAMPLE
triangle side length <= 0: 20000
LIMITS
The number of new described error-values is not to exceed E_USERMAX-E_USERDEF
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

View File

@@ -2,10 +2,11 @@ NAME
strerror - returns a string describing an error value
SYNOPSIS
strerror([errnum])
strerror([errnum | "E_STRING"])
TYPES
errnum integer
E_STRING string
return string
@@ -78,6 +79,8 @@ EXAMPLE
LIMITS
0 <= errnum <= 32767
E_STRING is C string matching the regular expression: "^E_[A-Z0-9_]+$"
LINK LIBRARY
int calc_errno; /* global calc_errno value */
CONST char *error_table[E__COUNT+2]; /* calc coded error messages */