From 3c18e6e25b9dbdf82adc56a58df124a0aa238352 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Sat, 19 Aug 2023 19:20:32 -0700 Subject: [PATCH] changed C source to use C booleans with backward compatibility Fix "Under source code control" date for new version.h file. Sorted the order of symbols printed by "make env". Test if exists and set HAVE_STDBOOL_H accordingly in have_stdbool.h. Added HAVE_STDBOOL_H to allow one to force this value. Added "bool.h" include file to support use of boolean symbols, true and false for pre-c99 C compilers. The "bool.h" include file defines TRUE as true, FALSE as false, and BOOL as bool: for backward compatibility. The sign in a ZVALUE is now of type SIGN, whcih is either SB32 when CALC2_COMPAT is defined, or a bool. Replaced in C source, TRUE with true, FALSE with false, and BOOL with bool. --- .gitignore | 1 + CHANGES | 19 +++++- LIBRARY | 6 +- Makefile | 125 +++++++++++++++++++++++++++++++----- Makefile.config | 12 ++++ addop.c | 28 ++++---- assocfunc.c | 34 +++++----- blkcpy.c | 24 +++---- blkcpy.h | 12 ++-- block.c | 18 +++--- block.h | 4 +- bool.h | 85 +++++++++++++++++++++++++ byteswap.c | 44 ++++++------- cal/ellip.cal | 4 +- cal/specialfunctions.cal | 10 +-- calc.c | 96 ++++++++++++++-------------- calc.h | 54 ++++++++-------- cmath.h | 8 +-- codegen.c | 94 +++++++++++++-------------- comfunc.c | 20 +++--- commath.c | 10 +-- config.c | 114 ++++++++++++++++----------------- config.h | 34 +++++----- const.c | 10 +-- custom.c | 12 ++-- custom.h | 4 +- custom/Makefile | 8 +++ custom/c_pmodm127.c | 6 +- custom/c_sysinfo.c | 8 +-- custom/custtbl.c | 10 +-- file.c | 134 +++++++++++++++++++-------------------- file.h | 10 +-- func.c | 18 ++++-- func.h | 4 +- hash.c | 66 +++++++++---------- hash.h | 6 +- hist.c | 12 ++-- lib_calc.c | 78 +++++++++++------------ listfunc.c | 20 +++--- longbits.c | 4 +- matfunc.c | 54 ++++++++-------- obj.c | 24 +++---- opcodes.c | 64 +++++++++---------- poly.c | 18 +++--- qfunc.c | 32 +++++----- qio.c | 18 +++--- qmath.c | 36 +++++------ qmath.h | 26 ++++---- qmod.c | 12 ++-- qtrans.c | 22 +++---- quickhash.c | 6 +- sha1.c | 18 +++--- str.c | 36 +++++------ symbol.c | 8 +-- symbol.h | 4 +- token.c | 42 ++++++------ token.h | 12 ++-- value.c | 56 ++++++++-------- value.h | 34 +++++----- version.h | 6 +- zfunc.c | 124 +++++++++++++++++++++--------------- zio.c | 22 +++---- zmath.c | 78 +++++++++++------------ zmath.h | 116 +++++++++++++++------------------ zmod.c | 48 +++++++------- zmul.c | 6 +- zprime.c | 78 +++++++++++------------ zrand.c | 10 +-- zrand.h | 2 +- zrandom.c | 28 ++++---- zrandom.h | 4 +- 71 files changed, 1267 insertions(+), 1043 deletions(-) create mode 100644 bool.h diff --git a/.gitignore b/.gitignore index f668798..17be3ed 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ have_offscl.h have_posscl.h have_rusage.h have_statfs.h +have_stdbool.h have_stdlib.h have_stdvs have_strdup.h diff --git a/CHANGES b/CHANGES index 8fc8529..f012af3 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,23 @@ The following are the changes from calc version 2.14.3.5 to date: version 2 compatibility. When MAJOR_VER <= 2, CALC2_COMPAT is defined. This is anticipation for a future calc version 3 code. + Sorted the order of symbols printed by "make env". + + Test if exists and set HAVE_STDBOOL_H accordingly + in have_stdbool.h. Added HAVE_STDBOOL_H to allow one to force + this value. + + Added "bool.h" include file to support use of boolean symbols, + true and false for pre-c99 C compilers. The "bool.h" include + file defines TRUE as true, FALSE as false, and BOOL as bool: + for backward compatibility. + + The sign in a ZVALUE is now of type SIGN, whcih is either + SB32 when CALC2_COMPAT is defined, or a bool. + + Replaced in C source, TRUE with true, FALSE with false, and + BOOL with bool. + The following are the changes from calc version 2.14.3.4 to 2.14.3.5: @@ -8847,7 +8864,7 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1: A small bug in the library file regress.cal was fixed. -## Copyright (C) 2001-2017,2021,2022 Landon Curt Noll +## Copyright (C) 2001-2017,2021-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 diff --git a/LIBRARY b/LIBRARY index 9602db2..4d9283a 100644 --- a/LIBRARY +++ b/LIBRARY @@ -415,7 +415,7 @@ the low order bits converted. There are two types of comparisons you can make on ZVALUEs. This is whether or not they are equal, or the ordering on size of the numbers. The zcmp -function tests whether two ZVALUEs are equal, returning TRUE if they differ. +function tests whether two ZVALUEs are equal, returning true if they differ. The zrel function tests the relative sizes of two ZVALUEs, returning -1 if the first one is smaller, 0 if they are the same, and 1 if the first one is larger. @@ -605,7 +605,7 @@ only used for complex numbers. Examples of macros are: cisodd(c) (number is has odd real and imaginary parts) There is only one comparison you can make for COMPLEX values, and that is -for equality. The ccmp function returns TRUE if two complex numbers differ. +for equality. The ccmp function returns true if two complex numbers differ. There are three predefined values for complex numbers. You should clink them when you want to use them. They are _czero_, _cone_, and _conei_. @@ -622,7 +622,7 @@ call. This is not required, but is does bring things to a closure. The function libcalc_call_me_last() takes no args and returns void. You need call libcalc_call_me_last() only once. -## Copyright (C) 1999,2021 David I. Bell and Landon Curt Noll +## Copyright (C) 1999,2021,2023 David I. Bell 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 diff --git a/Makefile b/Makefile index 3b31a51..d05d772 100644 --- a/Makefile +++ b/Makefile @@ -162,9 +162,9 @@ CALCOBJS= calc.o # these .h files are needed to build the math link library # -LIB_H_SRC= alloc.h banned.h blkcpy.h block.h byteswap.h calc.h cmath.h \ - config.h custom.h decl.h file.h func.h hash.h hist.h jump.h \ - label.h lib_util.h lib_calc.h nametype.h \ +LIB_H_SRC= alloc.h banned.h blkcpy.h block.h bool.h byteswap.h calc.h \ + cmath.h config.h custom.h decl.h file.h func.h hash.h hist.h \ + jump.h label.h lib_util.h lib_calc.h nametype.h \ opcodes.h prime.h qmath.h sha1.h str.h strl.h \ symbol.h token.h value.h zmath.h zrand.h zrandom.h attribute.h @@ -179,7 +179,7 @@ BUILD_H_SRC= align32.h args.h calcerr.h conf.h endian_calc.h \ have_uid_t.h have_unistd.h have_unused.h have_urandom.h \ have_ustat.h longbits.h terminal.h have_environ.h \ have_arc4random.h have_limits.h charbit.h have_sys_vfs.h \ - have_sys_param.h have_sys_mount.h have_statfs.h + have_sys_param.h have_sys_mount.h have_statfs.h have_stdbool.h # we build these .c files during the make # @@ -926,6 +926,42 @@ have_limits.h: ${MK_SET} ${TRUE}; \ fi +have_stdbool.h: ${MK_SET} + ${Q} ${RM} -f $@ + ${H} echo 'forming $@' + ${Q} echo '/*' > $@ + ${Q} echo ' * DO NOT EDIT -- generated by the Makefile rule $@' >> $@ + ${Q} echo ' */' >> $@ + ${Q} echo '' >> $@ + ${Q} echo '' >> $@ + ${Q} echo '#if !defined(CALC_HAVE_STDBOOL_H)' >> $@ + ${Q} echo '#define CALC_HAVE_STDBOOL_H' >> $@ + ${Q} echo '' >> $@ + ${Q} echo '' >> $@ + ${Q} echo '/* do we have ? */' >> $@ + -${Q} if [ X"${HAVE_STDBOOL_H}" = X"YES" ]; then \ + echo '#define HAVE_STDBOOL_H /* yes */' >> $@; \ + elif [ X"${HAVE_STDBOOL_H}" = X"NO" ]; then \ + echo '#undef HAVE_STDBOOL_H /* no */' >> $@; \ + elif echo '#include ' | ${CC} -E - ${S}; then \ + echo '#define HAVE_STDBOOL_H /* yes */' >> $@; \ + else \ + echo '#undef HAVE_STDBOOL_H /* no */' >> $@; \ + fi + ${Q} echo '' >> $@ + ${Q} echo '' >> $@ + ${Q} echo '#endif /* !CALC_HAVE_STDBOOL_H */' >> $@ + ${H} echo '$@ formed' + -@if [ -z "${Q}" ]; then \ + echo ''; \ + echo '=-=-= start of $@ =-=-='; \ + ${CAT} $@; \ + echo '=-=-= end of $@ =-=-='; \ + echo ''; \ + else \ + ${TRUE}; \ + fi + have_string.h: ${MK_SET} ${Q} ${RM} -f $@ ${H} echo 'forming $@' @@ -2676,7 +2712,6 @@ env: @echo 'ALIGN32=${ALIGN32}'; echo '' @echo 'ALLOW_CUSTOM=${ALLOW_CUSTOM}'; echo '' @echo 'AR=${AR}'; echo '' - @echo 'arch=${arch}'; echo '' @echo 'ARCH_CFLAGS=${ARCH_CFLAGS}'; echo '' @echo 'AWK=${AWK}'; echo '' @echo 'BINDIR=${BINDIR}'; echo '' @@ -2684,16 +2719,16 @@ env: @echo 'BUILD_C_SRC=${BUILD_C_SRC}'; echo '' @echo 'BUILD_H_SRC=${BUILD_H_SRC}'; echo '' @echo 'BYTE_ORDER=${BYTE_ORDER}'; echo '' - @echo 'CALC_DYNAMIC_LIBS=${CALC_DYNAMIC_LIBS}'; echo '' - @echo 'CALC_ENV=${CALC_ENV}'; echo '' - @echo 'CALC_INCDIR=${CALC_INCDIR}'; echo '' @echo 'CALCLIBLIST=${CALCLIBLIST}'; echo '' @echo 'CALCOBJS=${CALCOBJS}'; echo '' @echo 'CALCPAGER=${CALCPAGER}'; echo '' @echo 'CALCPATH=${CALCPATH}'; echo '' @echo 'CALCRC=${CALCRC}'; echo '' - @echo 'CALC_SHAREDIR=${CALC_SHAREDIR}'; echo '' @echo 'CALCSRC=${CALCSRC}'; echo '' + @echo 'CALC_DYNAMIC_LIBS=${CALC_DYNAMIC_LIBS}'; echo '' + @echo 'CALC_ENV=${CALC_ENV}'; echo '' + @echo 'CALC_INCDIR=${CALC_INCDIR}'; echo '' + @echo 'CALC_SHAREDIR=${CALC_SHAREDIR}'; echo '' @echo 'CALC_STATIC_LIBS=${CALC_STATIC_LIBS}'; echo '' @echo 'CAT=${CAT}'; echo '' @echo 'CATDIR=${CATDIR}'; echo '' @@ -2716,11 +2751,11 @@ env: @echo 'CONFIG_MKF=${CONFIG_MKF}'; echo '' @echo 'CP=${CP}'; echo '' @echo 'CSCRIPT_TARGETS=${CSCRIPT_TARGETS}'; echo '' - @echo 'C_SRC=${C_SRC}'; echo '' @echo 'CTAGS=${CTAGS}'; echo '' @echo 'CUSTOMCALDIR=${CUSTOMCALDIR}'; echo '' @echo 'CUSTOMHELPDIR=${CUSTOMHELPDIR}'; echo '' @echo 'CUSTOMINCDIR=${CUSTOMINCDIR}'; echo '' + @echo 'C_SRC=${C_SRC}'; echo '' @echo 'DATE=${DATE}'; echo '' @echo 'DEBUG=${DEBUG}'; echo '' @echo 'DEFAULT_LIB_INSTALL_PATH=${DEFAULT_LIB_INSTALL_PATH}'; echo '' @@ -2735,7 +2770,6 @@ env: @echo 'FPOS_POS_BITS=${FPOS_POS_BITS}'; echo '' @echo 'GREP=${GREP}'; echo '' @echo 'H=${H}'; echo '' - @echo 'hardware=${hardware}'; echo '' @echo 'HAVE_ARC4RANDOM=${HAVE_ARC4RANDOM}'; echo '' @echo 'HAVE_CONST=${HAVE_CONST}'; echo '' @echo 'HAVE_ENVIRON=${HAVE_ENVIRON}'; echo '' @@ -2753,6 +2787,7 @@ env: @echo 'HAVE_POSSCL=${HAVE_POSSCL}'; echo '' @echo 'HAVE_PRAGMA_GCC_POSION=${HAVE_PRAGMA_GCC_POSION}'; echo '' @echo 'HAVE_STATFS=${HAVE_STATFS}'; echo '' + @echo 'HAVE_STDBOOL_H=${HAVE_STDBOOL_H}'; echo '' @echo 'HAVE_STDLIB_H=${HAVE_STDLIB_H}'; echo '' @echo 'HAVE_STRDUP=${HAVE_STRDUP}'; echo '' @echo 'HAVE_STRING_H=${HAVE_STRING_H}'; echo '' @@ -2760,11 +2795,11 @@ env: @echo 'HAVE_STRLCPY=${HAVE_STRLCPY}'; echo '' @echo 'HAVE_SYS_MOUNT_H=${HAVE_SYS_MOUNT_H}'; echo '' @echo 'HAVE_SYS_PARAM_H=${HAVE_SYS_PARAM_H}'; echo '' - @echo 'HAVE_SYS_TIME_H=${HAVE_SYS_TIME_H}'; echo '' @echo 'HAVE_SYS_TIMES_H=${HAVE_SYS_TIMES_H}'; echo '' + @echo 'HAVE_SYS_TIME_H=${HAVE_SYS_TIME_H}'; echo '' @echo 'HAVE_SYS_VFS_H=${HAVE_SYS_VFS_H}'; echo '' - @echo 'HAVE_TIME_H=${HAVE_TIME_H}'; echo '' @echo 'HAVE_TIMES_H=${HAVE_TIMES_H}'; echo '' + @echo 'HAVE_TIME_H=${HAVE_TIME_H}'; echo '' @echo 'HAVE_UID_T=${HAVE_UID_T}'; echo '' @echo 'HAVE_UNISTD_H=${HAVE_UNISTD_H}'; echo '' @echo 'HAVE_UNUSED=${HAVE_UNUSED}'; echo '' @@ -2782,15 +2817,15 @@ env: @echo 'LATE_TARGETS=${LATE_TARGETS}'; echo '' @echo 'LCC=${LCC}'; echo '' @echo 'LDCONFIG=${LDCONFIG}'; echo '' - @echo 'LD_DEBUG=${LD_DEBUG}'; echo '' @echo 'LDFLAGS=${LDFLAGS}'; echo '' + @echo 'LD_DEBUG=${LD_DEBUG}'; echo '' @echo 'LD_SHARE=${LD_SHARE}'; echo '' @echo 'LIBCALC_SHLIB=${LIBCALC_SHLIB}'; echo '' @echo 'LIBCUSTCALC_SHLIB=${LIBCUSTCALC_SHLIB}'; echo '' @echo 'LIBDIR=${LIBDIR}'; echo '' - @echo 'LIB_H_SRC=${LIB_H_SRC}'; echo '' @echo 'LIBOBJS=${LIBOBJS}'; echo '' @echo 'LIBSRC=${LIBSRC}'; echo '' + @echo 'LIB_H_SRC=${LIB_H_SRC}'; echo '' @echo 'LICENSE=${LICENSE}'; echo '' @echo 'LN=${LN}'; echo '' @echo 'LOCAL_MKF=${LOCAL_MKF}'; echo '' @@ -2835,9 +2870,8 @@ env: @echo 'SPLINT_OPTS=${SPLINT_OPTS}'; echo '' @echo 'SYM_DYNAMIC_LIBS=${SYM_DYNAMIC_LIBS}'; echo '' @echo 'T=${T}'; echo '' - @echo 'target=${target}'; echo '' - @echo 'TARGET_MKF=${TARGET_MKF}'; echo '' @echo 'TARGETS=${TARGETS}'; echo '' + @echo 'TARGET_MKF=${TARGET_MKF}'; echo '' @echo 'TEE=${TEE}'; echo '' @echo 'TERMCONTROL=${TERMCONTROL}'; echo '' @echo 'TOUCH=${TOUCH}'; echo '' @@ -2856,6 +2890,9 @@ env: @echo 'WNO_IMPLICT=${WNO_IMPLICT};' echo '' @echo 'WNO_LONG_LONG=${WNO_LONG_LONG}'; echo '' @echo 'XARGS=${XARGS}'; echo '' + @echo 'arch=${arch}'; echo '' + @echo 'hardware=${hardware}'; echo '' + @echo 'target=${target}'; echo '' @echo '=-=-=-=-= ${MAKE_FILE} end of major make variable dump =-=-=-=-=' mkdebug: env version.c @@ -3764,6 +3801,7 @@ addop.o: alloc.h addop.o: attribute.h addop.o: banned.h addop.o: block.h +addop.o: bool.h addop.o: byteswap.h addop.o: calc.h addop.o: calcerr.h @@ -3804,6 +3842,7 @@ assocfunc.o: assocfunc.c assocfunc.o: attribute.h assocfunc.o: banned.h assocfunc.o: block.h +assocfunc.o: bool.h assocfunc.o: byteswap.h assocfunc.o: calcerr.h assocfunc.o: charbit.h @@ -3832,6 +3871,7 @@ blkcpy.o: banned.h blkcpy.o: blkcpy.c blkcpy.o: blkcpy.h blkcpy.o: block.h +blkcpy.o: bool.h blkcpy.o: byteswap.h blkcpy.o: calc.h blkcpy.o: calcerr.h @@ -3862,6 +3902,7 @@ block.o: attribute.h block.o: banned.h block.o: block.c block.o: block.h +block.o: bool.h block.o: byteswap.h block.o: calcerr.h block.o: charbit.h @@ -3887,6 +3928,7 @@ block.o: zmath.h byteswap.o: alloc.h byteswap.o: attribute.h byteswap.o: banned.h +byteswap.o: bool.h byteswap.o: byteswap.c byteswap.o: byteswap.h byteswap.o: charbit.h @@ -3908,6 +3950,7 @@ calc.o: args.h calc.o: attribute.h calc.o: banned.h calc.o: block.h +calc.o: bool.h calc.o: byteswap.h calc.o: calc.c calc.o: calc.h @@ -3961,6 +4004,7 @@ codegen.o: alloc.h codegen.o: attribute.h codegen.o: banned.h codegen.o: block.h +codegen.o: bool.h codegen.o: byteswap.h codegen.o: calc.h codegen.o: calcerr.h @@ -3999,6 +4043,7 @@ codegen.o: zmath.h comfunc.o: alloc.h comfunc.o: attribute.h comfunc.o: banned.h +comfunc.o: bool.h comfunc.o: byteswap.h comfunc.o: charbit.h comfunc.o: cmath.h @@ -4020,6 +4065,7 @@ comfunc.o: zmath.h commath.o: alloc.h commath.o: attribute.h commath.o: banned.h +commath.o: bool.h commath.o: byteswap.h commath.o: charbit.h commath.o: cmath.h @@ -4040,6 +4086,7 @@ config.o: alloc.h config.o: attribute.h config.o: banned.h config.o: block.h +config.o: bool.h config.o: byteswap.h config.o: calc.h config.o: calcerr.h @@ -4076,6 +4123,7 @@ const.o: alloc.h const.o: attribute.h const.o: banned.h const.o: block.h +const.o: bool.h const.o: byteswap.h const.o: calc.h const.o: calcerr.h @@ -4104,6 +4152,7 @@ custom.o: alloc.h custom.o: attribute.h custom.o: banned.h custom.o: block.h +custom.o: bool.h custom.o: byteswap.h custom.o: calc.h custom.o: calcerr.h @@ -4138,6 +4187,7 @@ file.o: alloc.h file.o: attribute.h file.o: banned.h file.o: block.h +file.o: bool.h file.o: byteswap.h file.o: calc.h file.o: calcerr.h @@ -4173,6 +4223,7 @@ file.o: zmath.h fposval.o: alloc.h fposval.o: attribute.h fposval.o: banned.h +fposval.o: bool.h fposval.o: byteswap.h fposval.o: charbit.h fposval.o: decl.h @@ -4196,6 +4247,7 @@ func.o: alloc.h func.o: attribute.h func.o: banned.h func.o: block.h +func.o: bool.h func.o: byteswap.h func.o: calc.h func.o: calcerr.h @@ -4243,6 +4295,7 @@ hash.o: alloc.h hash.o: attribute.h hash.o: banned.h hash.o: block.h +hash.o: bool.h hash.o: byteswap.h hash.o: calc.h hash.o: calcerr.h @@ -4369,6 +4422,7 @@ help.o: alloc.h help.o: attribute.h help.o: banned.h help.o: block.h +help.o: bool.h help.o: byteswap.h help.o: calc.h help.o: calcerr.h @@ -4400,6 +4454,7 @@ hist.o: alloc.h hist.o: attribute.h hist.o: banned.h hist.o: block.h +hist.o: bool.h hist.o: byteswap.h hist.o: calc.h hist.o: calcerr.h @@ -4436,6 +4491,7 @@ input.o: alloc.h input.o: attribute.h input.o: banned.h input.o: block.h +input.o: bool.h input.o: byteswap.h input.o: calc.h input.o: calcerr.h @@ -4476,6 +4532,7 @@ label.o: alloc.h label.o: attribute.h label.o: banned.h label.o: block.h +label.o: bool.h label.o: byteswap.h label.o: calc.h label.o: calcerr.h @@ -4508,6 +4565,7 @@ lib_calc.o: alloc.h lib_calc.o: attribute.h lib_calc.o: banned.h lib_calc.o: block.h +lib_calc.o: bool.h lib_calc.o: byteswap.h lib_calc.o: calc.h lib_calc.o: calcerr.h @@ -4549,6 +4607,7 @@ lib_calc.o: zrandom.h lib_util.o: alloc.h lib_util.o: attribute.h lib_util.o: banned.h +lib_util.o: bool.h lib_util.o: byteswap.h lib_util.o: charbit.h lib_util.o: decl.h @@ -4568,6 +4627,7 @@ listfunc.o: alloc.h listfunc.o: attribute.h listfunc.o: banned.h listfunc.o: block.h +listfunc.o: bool.h listfunc.o: byteswap.h listfunc.o: calcerr.h listfunc.o: charbit.h @@ -4603,6 +4663,7 @@ matfunc.o: alloc.h matfunc.o: attribute.h matfunc.o: banned.h matfunc.o: block.h +matfunc.o: bool.h matfunc.o: byteswap.h matfunc.o: calcerr.h matfunc.o: charbit.h @@ -4633,6 +4694,7 @@ math_error.o: args.h math_error.o: attribute.h math_error.o: banned.h math_error.o: block.h +math_error.o: bool.h math_error.o: byteswap.h math_error.o: calc.h math_error.o: calcerr.h @@ -4662,6 +4724,7 @@ obj.o: alloc.h obj.o: attribute.h obj.o: banned.h obj.o: block.h +obj.o: bool.h obj.o: byteswap.h obj.o: calc.h obj.o: calcerr.h @@ -4697,6 +4760,7 @@ opcodes.o: alloc.h opcodes.o: attribute.h opcodes.o: banned.h opcodes.o: block.h +opcodes.o: bool.h opcodes.o: byteswap.h opcodes.o: calc.h opcodes.o: calcerr.h @@ -4736,6 +4800,7 @@ opcodes.o: zrandom.h pix.o: alloc.h pix.o: attribute.h pix.o: banned.h +pix.o: bool.h pix.o: byteswap.h pix.o: charbit.h pix.o: decl.h @@ -4756,6 +4821,7 @@ poly.o: alloc.h poly.o: attribute.h poly.o: banned.h poly.o: block.h +poly.o: bool.h poly.o: byteswap.h poly.o: calcerr.h poly.o: charbit.h @@ -4782,6 +4848,7 @@ poly.o: zmath.h prime.o: alloc.h prime.o: attribute.h prime.o: banned.h +prime.o: bool.h prime.o: byteswap.h prime.o: charbit.h prime.o: decl.h @@ -4802,6 +4869,7 @@ prime.o: zmath.h qfunc.o: alloc.h qfunc.o: attribute.h qfunc.o: banned.h +qfunc.o: bool.h qfunc.o: byteswap.h qfunc.o: charbit.h qfunc.o: config.h @@ -4824,6 +4892,7 @@ qio.o: alloc.h qio.o: args.h qio.o: attribute.h qio.o: banned.h +qio.o: bool.h qio.o: byteswap.h qio.o: charbit.h qio.o: config.h @@ -4845,6 +4914,7 @@ qio.o: zmath.h qmath.o: alloc.h qmath.o: attribute.h qmath.o: banned.h +qmath.o: bool.h qmath.o: byteswap.h qmath.o: charbit.h qmath.o: config.h @@ -4865,6 +4935,7 @@ qmath.o: zmath.h qmod.o: alloc.h qmod.o: attribute.h qmod.o: banned.h +qmod.o: bool.h qmod.o: byteswap.h qmod.o: charbit.h qmod.o: config.h @@ -4885,6 +4956,7 @@ qmod.o: zmath.h qtrans.o: alloc.h qtrans.o: attribute.h qtrans.o: banned.h +qtrans.o: bool.h qtrans.o: byteswap.h qtrans.o: charbit.h qtrans.o: decl.h @@ -4904,6 +4976,7 @@ quickhash.o: alloc.h quickhash.o: attribute.h quickhash.o: banned.h quickhash.o: block.h +quickhash.o: bool.h quickhash.o: byteswap.h quickhash.o: calcerr.h quickhash.o: charbit.h @@ -4933,6 +5006,7 @@ sample_many.o: alloc.h sample_many.o: attribute.h sample_many.o: banned.h sample_many.o: block.h +sample_many.o: bool.h sample_many.o: byteswap.h sample_many.o: calc.h sample_many.o: calcerr.h @@ -4963,6 +5037,7 @@ sample_rand.o: alloc.h sample_rand.o: attribute.h sample_rand.o: banned.h sample_rand.o: block.h +sample_rand.o: bool.h sample_rand.o: byteswap.h sample_rand.o: calc.h sample_rand.o: calcerr.h @@ -4992,6 +5067,7 @@ sample_rand.o: zrandom.h seed.o: alloc.h seed.o: attribute.h seed.o: banned.h +seed.o: bool.h seed.o: byteswap.h seed.o: charbit.h seed.o: decl.h @@ -5028,6 +5104,7 @@ sha1.o: alloc.h sha1.o: attribute.h sha1.o: banned.h sha1.o: block.h +sha1.o: bool.h sha1.o: byteswap.h sha1.o: calcerr.h sha1.o: charbit.h @@ -5055,6 +5132,7 @@ size.o: alloc.h size.o: attribute.h size.o: banned.h size.o: block.h +size.o: bool.h size.o: byteswap.h size.o: calcerr.h size.o: charbit.h @@ -5084,6 +5162,7 @@ str.o: alloc.h str.o: attribute.h str.o: banned.h str.o: block.h +str.o: bool.h str.o: byteswap.h str.o: calc.h str.o: calcerr.h @@ -5127,6 +5206,7 @@ symbol.o: alloc.h symbol.o: attribute.h symbol.o: banned.h symbol.o: block.h +symbol.o: bool.h symbol.o: byteswap.h symbol.o: calc.h symbol.o: calcerr.h @@ -5161,6 +5241,7 @@ token.o: args.h token.o: attribute.h token.o: banned.h token.o: block.h +token.o: bool.h token.o: byteswap.h token.o: calc.h token.o: calcerr.h @@ -5191,6 +5272,7 @@ value.o: alloc.h value.o: attribute.h value.o: banned.h value.o: block.h +value.o: bool.h value.o: byteswap.h value.o: calc.h value.o: calcerr.h @@ -5227,6 +5309,7 @@ version.o: alloc.h version.o: attribute.h version.o: banned.h version.o: block.h +version.o: bool.h version.o: byteswap.h version.o: calc.h version.o: calcerr.h @@ -5258,6 +5341,7 @@ version.o: zmath.h zfunc.o: alloc.h zfunc.o: attribute.h zfunc.o: banned.h +zfunc.o: bool.h zfunc.o: byteswap.h zfunc.o: charbit.h zfunc.o: decl.h @@ -5276,6 +5360,7 @@ zio.o: alloc.h zio.o: args.h zio.o: attribute.h zio.o: banned.h +zio.o: bool.h zio.o: byteswap.h zio.o: charbit.h zio.o: config.h @@ -5296,6 +5381,7 @@ zio.o: zmath.h zmath.o: alloc.h zmath.o: attribute.h zmath.o: banned.h +zmath.o: bool.h zmath.o: byteswap.h zmath.o: charbit.h zmath.o: decl.h @@ -5313,6 +5399,7 @@ zmath.o: zmath.h zmod.o: alloc.h zmod.o: attribute.h zmod.o: banned.h +zmod.o: bool.h zmod.o: byteswap.h zmod.o: charbit.h zmod.o: config.h @@ -5333,6 +5420,7 @@ zmod.o: zmod.c zmul.o: alloc.h zmul.o: attribute.h zmul.o: banned.h +zmul.o: bool.h zmul.o: byteswap.h zmul.o: charbit.h zmul.o: config.h @@ -5354,6 +5442,7 @@ zprime.o: alloc.h zprime.o: attribute.h zprime.o: banned.h zprime.o: block.h +zprime.o: bool.h zprime.o: byteswap.h zprime.o: calcerr.h zprime.o: charbit.h @@ -5384,6 +5473,7 @@ zrand.o: alloc.h zrand.o: attribute.h zrand.o: banned.h zrand.o: block.h +zrand.o: bool.h zrand.o: byteswap.h zrand.o: calcerr.h zrand.o: charbit.h @@ -5413,6 +5503,7 @@ zrandom.o: alloc.h zrandom.o: attribute.h zrandom.o: banned.h zrandom.o: block.h +zrandom.o: bool.h zrandom.o: byteswap.h zrandom.o: calcerr.h zrandom.o: charbit.h diff --git a/Makefile.config b/Makefile.config index f122222..44bba5f 100644 --- a/Makefile.config +++ b/Makefile.config @@ -705,6 +705,18 @@ HAVE_LIMITS_H= #HAVE_LIMITS_H= YES #HAVE_LIMITS_H= NO +# Determine if we have the include file. +# +# HAVE_STDBOOL_H= let the Makefile look for the include file +# HAVE_STDBOOL_H= YES assume that the include file exists +# HAVE_STDBOOL_H= NO assume that the include file does not exist +# +# When in doubt, leave HAVE_STDBOOL_H empty. +# +HAVE_STDBOOL_H= +#HAVE_STDBOOL_H= YES +#HAVE_STDBOOL_H= NO + # Determine if our compiler allows the unused attribute # # If HAVE_UNUSED is empty, this Makefile will run the have_unused program diff --git a/addop.c b/addop.c index 2005075..b3aa18e 100644 --- a/addop.c +++ b/addop.c @@ -1,7 +1,7 @@ /* * addop - add opcodes to a function being compiled * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -136,16 +136,16 @@ showfunctions(void) /* * Initialize a function for definition. - * Newflag is TRUE if we should allocate a new function structure, + * Newflag is true if we should allocate a new function structure, * instead of the usual overwriting of the template function structure. * The new structure is returned in the global curfunc variable. * * given: * name name of function - * newflag TRUE if need new structure + * newflag true if need new structure */ void -beginfunc(char *name, BOOL newflag) +beginfunc(char *name, bool newflag) { register FUNC *fp; /* current function */ @@ -210,7 +210,7 @@ endfunc(void) if (curfunc != functemplate) free(curfunc); if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { - dumpnames = TRUE; + dumpnames = true; for (size = 0; size < fp->f_opcodecount; ) { printf("%ld: ", (unsigned long)size); size += dumpop(&fp->f_opcodes[size]); @@ -322,7 +322,7 @@ freefunc(FUNC *fp) } if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { printf("Freeing function \"%s\"\n",namestr(&funcnames,index)); - dumpnames = FALSE; + dumpnames = false; for (i = 0; i < fp->f_opcodecount; ) { printf("%ld: ", i); i += dumpop(&fp->f_opcodes[i]); @@ -411,7 +411,7 @@ void writeindexop(void) { if (oldop == OP_INDEXADDR) - curfunc->f_opcodes[curfunc->f_opcodecount - 1] = TRUE; + curfunc->f_opcodes[curfunc->f_opcodecount - 1] = true; } @@ -426,12 +426,12 @@ addop(long op) register FUNC *fp; /* current function */ NUMBER *q, *q1, *q2; unsigned long count; - BOOL cut; + bool cut; int diff; fp = curfunc; count = fp->f_opcodecount; - cut = TRUE; + cut = true; diff = 2; q = NULL; if ((count + 5) >= maxopcodes) { @@ -488,7 +488,7 @@ addop(long op) oldop = OP_ELEMVALUE; break; default: - cut = FALSE; + cut = false; } if (cut) { @@ -522,7 +522,7 @@ addop(long op) oldoldop = OP_NOP; return; default: - cut = FALSE; + cut = false; } if (cut) { fp->f_opcodecount -= diff; @@ -547,7 +547,7 @@ addop(long op) switch (op) { case OP_DIV: if (qiszero(q2)) { - cut = FALSE; + cut = false; break; } q = qqdiv(q1,q2); @@ -563,12 +563,12 @@ addop(long op) break; case OP_POWER: if (qisfrac(q2) || qisneg(q2)) - cut = FALSE; + cut = false; else q = qpowi(q1,q2); break; default: - cut = FALSE; + cut = false; } if (cut) { qfree(q1); diff --git a/assocfunc.c b/assocfunc.c index f481d8b..191f8e7 100644 --- a/assocfunc.c +++ b/assocfunc.c @@ -1,7 +1,7 @@ /* * assocfunc - association table routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -47,15 +47,15 @@ S_FUNC ASSOCELEM *elemindex(ASSOC *ap, long index); -S_FUNC BOOL compareindices(VALUE *v1, VALUE *v2, long dim); +S_FUNC bool compareindices(VALUE *v1, VALUE *v2, long dim); S_FUNC void resize(ASSOC *ap, long newsize); S_FUNC void assoc_elemfree(ASSOCELEM *ep); /* * Return the address of the value specified by normal indexing of - * an association. The create flag is TRUE if a value is going to be - * assigned into the specified indexing location. If create is FALSE and + * an association. The create flag is true if a value is going to be + * assigned into the specified indexing location. If create is false and * the index value doesn't exist, a pointer to a NULL value is returned. * * given: @@ -65,7 +65,7 @@ S_FUNC void assoc_elemfree(ASSOCELEM *ep); * indices table of values being indexed by */ VALUE * -associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices) +associndex(ASSOC *ap, bool create, long dim, VALUE *indices) { ASSOCELEM **listhead; ASSOCELEM *ep; @@ -266,9 +266,9 @@ associndices(ASSOC *ap, long index) /* * Compare two associations to see if they are identical. - * Returns TRUE if they are different. + * Returns true if they are different. */ -BOOL +bool assoccmp(ASSOC *ap1, ASSOC *ap2) { ASSOCELEM **table1; @@ -280,9 +280,9 @@ assoccmp(ASSOC *ap1, ASSOC *ap2) long dim; if (ap1 == ap2) - return FALSE; + return false; if (ap1->a_count != ap2->a_count) - return TRUE; + return true; table1 = ap1->a_table; size1 = ap1->a_size; @@ -294,7 +294,7 @@ assoccmp(ASSOC *ap1, ASSOC *ap2) for (ep2 = ap2->a_table[hash % size2]; ; ep2 = ep2->e_next) { if (ep2 == NULL) - return TRUE; + return true; if (ep2->e_hash != hash) continue; if (ep2->e_dim != dim) @@ -304,10 +304,10 @@ assoccmp(ASSOC *ap1, ASSOC *ap2) break; } if (comparevalue(&ep1->e_value, &ep2->e_value)) - return TRUE; + return true; } } - return FALSE; + return false; } @@ -520,20 +520,20 @@ assocprint(ASSOC *ap, long max_print) /* * Compare two lists of index values to see if they are identical. - * Returns TRUE if they are the same. + * Returns true if they are the same. */ -S_FUNC BOOL +S_FUNC bool compareindices(VALUE *v1, VALUE *v2, long dim) { int i; for (i = 0; i < dim; i++) if (v1[i].v_type != v2[i].v_type) - return FALSE; + return false; while (dim-- > 0) if (comparevalue(v1++, v2++)) - return FALSE; + return false; - return TRUE; + return true; } diff --git a/blkcpy.c b/blkcpy.c index 9ecdcee..9c40e0a 100644 --- a/blkcpy.c +++ b/blkcpy.c @@ -1,7 +1,7 @@ /* * blkcpy - general values and related routines used by the calculator * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 Landon Curt Noll and Ernest Bowen * * Primary author: Landon Curt Noll * @@ -56,7 +56,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi) { BLOCK *sblk; BLOCK *dblk; - BOOL noreloc; + bool noreloc; sblk = NULL; dblk = NULL; @@ -376,7 +376,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi) */ int copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi, - BOOL noreloc) + bool noreloc) { long i; long newlen; @@ -589,7 +589,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi) if (num == 0) return 0; - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return E_COPYF1; fp = fiop->fp; @@ -613,7 +613,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi) * copyfile2blk - copy file to block */ int -copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc) +copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, bool noreloc) { FILEIO *fiop; FILE *fp; @@ -626,7 +626,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc) if (id < 3) /* excludes copying from stdin */ return E_COPYF1; - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return E_COPYF1; @@ -698,7 +698,7 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi) return 0; if (ssi + num > len) return E_COPY5; /* Insufficient memory in str */ - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return E_COPYF1; fp = fiop->fp; @@ -723,7 +723,7 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi) */ int copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi, - BOOL noreloc) + bool noreloc) { long newlen; long newsize; @@ -766,7 +766,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi, */ int copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi, - BOOL noreloc) + bool noreloc) { long len; long newlen; @@ -887,7 +887,7 @@ copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi) * copyostr2blk - copy octet-specified string to block */ int -copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc) +copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,bool noreloc) { size_t len; size_t newlen; @@ -987,7 +987,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n) */ int copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, - BOOL noreloc) + bool noreloc) { size_t newlen; size_t newsize; @@ -1024,7 +1024,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, #if CALC_BYTE_ORDER == LITTLE_ENDIAN memmove(dblk->data+dsi, (char *)(snum->num.v+ssi), num*sizeof(HALF)); #else - swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), FALSE); + swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), false); memmove(dblk->data+dsi, (char *)(swnum->v+ssi), num*sizeof(HALF)); zfree(*swnum); #endif diff --git a/blkcpy.h b/blkcpy.h index cbced65..4f8a0ac 100644 --- a/blkcpy.h +++ b/blkcpy.h @@ -37,21 +37,21 @@ E_FUNC int copystod(VALUE *, long, long, VALUE *, long); /* * specific copy functions */ -E_FUNC int copyblk2blk(BLOCK *, long, long, BLOCK *, long, BOOL); +E_FUNC int copyblk2blk(BLOCK *, long, long, BLOCK *, long, bool); E_FUNC int copyblk2file(BLOCK *, long, long, FILEID, long); E_FUNC int copyblk2mat(BLOCK *, long, long, MATRIX *, long); E_FUNC int copyblk2num(BLOCK *, long, long, NUMBER *, long, NUMBER **); E_FUNC int copyblk2str(BLOCK *, long, long, STRING *, long); -E_FUNC int copyfile2blk(FILEID, long, long, BLOCK *, long, BOOL); +E_FUNC int copyfile2blk(FILEID, long, long, BLOCK *, long, bool); E_FUNC int copylist2list(LIST *, long, long, LIST *, long); E_FUNC int copylist2mat(LIST *, long, long, MATRIX *, long); -E_FUNC int copymat2blk(MATRIX *, long, long, BLOCK *, long, BOOL); +E_FUNC int copymat2blk(MATRIX *, long, long, BLOCK *, long, bool); E_FUNC int copymat2list(MATRIX *, long, long, LIST *, long); E_FUNC int copymat2mat(MATRIX *, long, long, MATRIX *, long); -E_FUNC int copynum2blk(NUMBER *, long, long, BLOCK *, long, BOOL); -E_FUNC int copyostr2blk(char *, long, long, BLOCK *, long, BOOL); +E_FUNC int copynum2blk(NUMBER *, long, long, BLOCK *, long, bool); +E_FUNC int copyostr2blk(char *, long, long, BLOCK *, long, bool); E_FUNC int copyostr2str(char *, long, long, STRING *, long); -E_FUNC int copystr2blk(STRING *, long, long, BLOCK *, long, BOOL); +E_FUNC int copystr2blk(STRING *, long, long, BLOCK *, long, bool); E_FUNC int copystr2file(STRING *, long, long, FILEID, long); E_FUNC int copystr2str(STRING *, long, long, STRING *, long); diff --git a/block.c b/block.c index ddcacf1..48b8c92 100644 --- a/block.c +++ b/block.c @@ -1,7 +1,7 @@ /* * block - fixed, dynamic, fifo and circular memory blocks * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 Landon Curt Noll and Ernest Bowen * * Primary author: Landon Curt Noll * @@ -427,8 +427,8 @@ blk_copy(BLOCK *blk) * b second BLOCK * * returns: - * TRUE => BLOCKs are different - * FALSE => BLOCKs are the same + * true => BLOCKs are different + * false => BLOCKs are the same */ int blk_cmp(BLOCK *a, BLOCK *b) @@ -438,11 +438,11 @@ blk_cmp(BLOCK *a, BLOCK *b) */ if (a == b) { /* pointers to the same object */ - return FALSE; + return false; } if (a == NULL || b == NULL) { /* one pointer is NULL, so they differ */ - return TRUE; + return true; } /* @@ -450,7 +450,7 @@ blk_cmp(BLOCK *a, BLOCK *b) */ if (a->datalen != b->datalen) { /* different lengths are different */ - return TRUE; + return true; } /* @@ -460,13 +460,13 @@ blk_cmp(BLOCK *a, BLOCK *b) */ if (memcmp(a->data, b->data, a->datalen) != 0) { /* different sections are different */ - return TRUE; + return true; } /* * the blocks are the same */ - return FALSE; + return false; } @@ -479,7 +479,7 @@ void blk_print(BLOCK *blk) { long i; - BOOL havetail; + bool havetail; USB8 *ptr; /* XXX - should use the config parameters for better print control */ diff --git a/block.h b/block.h index 128e3fd..faa3006 100644 --- a/block.h +++ b/block.h @@ -1,7 +1,7 @@ /* * block - fixed, dynamic, fifo and circular memory blocks * - * Copyright (C) 1999-2007,2014,2021 Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2007,2014,2021,2023 Landon Curt Noll and Ernest Bowen * * Primary author: Landon Curt Noll * @@ -122,7 +122,7 @@ * number of octets of a block to print, 0 means all * * config("blkverbose", boolean) - * TRUE => print all lines, FALSE => skip dup lines + * true => print all lines, false => skip dup lines * * config("blkbase", "base") * output block base = { "hex", "octal", "char", "binary", "raw" } diff --git a/bool.h b/bool.h new file mode 100644 index 0000000..e14a71d --- /dev/null +++ b/bool.h @@ -0,0 +1,85 @@ +/* + * bool - calc standard truth :-) + * + * Copyright (C) 2023 David I. Bell and Landon Curt Noll + * + * Primary author: David I. Bell + * + * 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/07/19 17:58:42 + * File existed as early as: 1990 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(INCLUDE_BOOL_H) +#define INCLUDE_BOOL_H + + +#if defined(HAVE_STDBOOL_H) +#include +#endif /* HAVE_STDBOOL_H */ + + +/* + * standard truth :-) + */ +#if !defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) + +/* have a C99 compiler - we should have , true, false */ + +#elif !defined(__cplusplus) + +/* do not have a C99 compiler - fake a header file */ +typedef unsigned char bool; +#undef true +#define true ((bool)(1)) +#undef false +#define false ((bool)(0)) + +#endif /* standard truth :-) */ + + +/* + * calc historic booleans + */ +#undef TRUE +#define TRUE ((bool) true) +#undef FALSE +#define FALSE ((bool) false) +#undef BOOL +#define BOOL bool + + +/* + * booltostr - convert a boolean to a string + */ +#if !defined(booltostr) +#define booltostr(x) ((x) ? "true" : "false") +#endif + + +/* + * strtobool - convert a string to a boolean + */ +#if !defined(strtobool) +#define strtobool(x) ((bool) ((x) != NULL && !strcmp((x), "true"))) +#endif + + +#endif /* !INCLUDE_BOOL_H*/ diff --git a/byteswap.c b/byteswap.c index 6a5b5ca..8dd1aae 100644 --- a/byteswap.c +++ b/byteswap.c @@ -1,7 +1,7 @@ /* * byteswap - byte swapping routines * - * Copyright (C) 1999,2021,2022 Landon Curt Noll + * Copyright (C) 1999,2021-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 @@ -80,7 +80,7 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a ZVALUE to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -90,7 +90,7 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len) * Little Endian) the elements of a ZVALUE. */ ZVALUE * -swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) +swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { /* * allocate storage if needed @@ -128,7 +128,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) */ if (all) { SWAP_B8_IN_LEN(&dest->len, &src->len); - SWAP_B8_IN_BOOL(&dest->sign, &src->sign); + SWAP_B8_IN_bool(&dest->sign, &src->sign); } else { dest->len = src->len; dest->sign = src->sign; @@ -148,7 +148,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a NUMBER to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -158,7 +158,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * Little Endian) the elements of a NUMBER. */ NUMBER * -swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) +swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { /* * allocate storage if needed @@ -212,7 +212,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a COMPLEX to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -222,7 +222,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * Little Endian) the elements of a COMPLEX. */ COMPLEX * -swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all) +swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { /* * allocate storage if needed @@ -360,7 +360,7 @@ swap_HALFs(HALF *dest, HALF *src, LEN len) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a ZVALUE to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -370,7 +370,7 @@ swap_HALFs(HALF *dest, HALF *src, LEN len) * Little Endian) the elements of a ZVALUE. */ ZVALUE * -swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) +swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { /* * allocate storage if needed @@ -407,7 +407,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) */ if (all) { SWAP_B16_IN_LEN(&dest->len, &src->len); - SWAP_B16_IN_BOOL(&dest->sign, &src->sign); + SWAP_B16_IN_bool(&dest->sign, &src->sign); } else { dest->len = src->len; dest->sign = src->sign; @@ -427,7 +427,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a NUMBER to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -437,7 +437,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * Little Endian) the elements of a NUMBER. */ NUMBER * -swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) +swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { /* * allocate storage if needed @@ -491,7 +491,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a COMPLEX to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -501,7 +501,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * Little Endian) the elements of a COMPLEX. */ COMPLEX * -swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all) +swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { /* * allocate storage if needed @@ -555,7 +555,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a ZVALUE to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -565,7 +565,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all) * Little Endian) the elements of a ZVALUE. */ ZVALUE * -swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) +swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { /* * allocate storage if needed @@ -603,7 +603,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) */ if (all) { SWAP_HALF_IN_LEN(&dest->len, &src->len); - SWAP_HALF_IN_BOOL(&dest->sign, &src->sign); + SWAP_HALF_IN_bool(&dest->sign, &src->sign); } else { dest->len = src->len; dest->sign = src->sign; @@ -623,7 +623,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a NUMBER to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -633,7 +633,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all) * Little Endian) the elements of a NUMBER. */ NUMBER * -swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) +swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { /* * allocate storage if needed @@ -687,7 +687,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * dest - pointer to where the swapped src will be put or * NULL to allocate the storage * src - pointer to a COMPLEX to swap - * all - TRUE => swap every element, FALSE => swap only the + * all - true => swap every element, false => swap only the * multi-precision storage * * returns: @@ -697,7 +697,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all) * Little Endian) the elements of a COMPLEX. */ COMPLEX * -swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all) +swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { /* * allocate storage if needed diff --git a/cal/ellip.cal b/cal/ellip.cal index 32ef4df..4c4bb4a 100644 --- a/cal/ellip.cal +++ b/cal/ellip.cal @@ -1,7 +1,7 @@ /* * ellip - attempt to factor numbers using elliptic functions * - * Copyright (C) 1999 David I. Bell + * Copyright (C) 1999,2023 David I. Bell * * 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 @@ -53,7 +53,7 @@ * B is the limit of the primes that make up the high power that the * point is raised to for each factoring attempt (default 100). * force is a flag to attempt to factor numbers even if they are - * thought to already be prime (default FALSE). + * thought to already be prime (default false). * * Making B larger makes the power the point being raised to contain more * prime factors, thus increasing the chance that the order of the point diff --git a/cal/specialfunctions.cal b/cal/specialfunctions.cal index 898c90a..06b0569 100644 --- a/cal/specialfunctions.cal +++ b/cal/specialfunctions.cal @@ -1,7 +1,7 @@ /* * specialfunctions - special functions (e.g.: gamma, zeta, psi) * - * Copyright (C) 2013,2021 Christoph Zurnieden + * Copyright (C) 2013,2021,2023 Christoph Zurnieden * * 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 @@ -802,8 +802,8 @@ define NUMBER_NEGATIVE_INFINITY() return -(1 / epsilon()); } -static TRUE = 1; -static FALSE = 0; +static true = 1; +static false = 0; define g(prec) { @@ -827,9 +827,9 @@ define __CZ__series_converged(new, old, max) } if (abs(re(new - old)) <= eps * abs(re(new)) && abs(im(new - old)) <= eps * abs(im(new))) { - return TRUE; + return true; } - return FALSE; + return false; } define __CZ__ei_power(z) diff --git a/calc.c b/calc.c index 21c9434..ae6aa13 100644 --- a/calc.c +++ b/calc.c @@ -1,9 +1,7 @@ /* * calc - arbitrary precision calculator * - * Copyright (C) 1999-2013,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen - * - * Primary author: David I. Bell + * Copyright (C) 1999-2013,2021-2023 David I. Bell, Landon Curt Noll and Ernest Bowen * * 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 @@ -93,7 +91,7 @@ */ S_FUNC void intint(int arg); /* interrupt routine */ S_FUNC void calc_interrupt(char *fmt, ...); -S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, BOOL haveendstr); +S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr); S_FUNC void set_run_state(run state); /* @@ -111,10 +109,10 @@ main(int argc, char **argv) char *cp; char *endcp; char *bp; - BOOL done = FALSE; - BOOL havearg; - BOOL haveendstr; - BOOL stdin_closed = FALSE; + bool done = false; + bool havearg; + bool haveendstr; + bool stdin_closed = false; size_t len; /* @@ -135,7 +133,7 @@ main(int argc, char **argv) index = 1; cp = endcp = NULL; maxindex = argc; - havecommands = FALSE; + havecommands = false; while (index < maxindex && !done) { cp = argv[index]; if (*cp == '\0') { @@ -143,9 +141,9 @@ main(int argc, char **argv) continue; } for (;;) { - havearg = FALSE; + havearg = false; if (*cp != '-') { - done = TRUE; + done = true; break; } ++cp; @@ -153,7 +151,7 @@ main(int argc, char **argv) cp++; while (*cp == ' ') ++cp; - done = TRUE; + done = true; break; } @@ -168,27 +166,27 @@ main(int argc, char **argv) /* * error if libcustcalc was compiled with CUSTOM undefined */ - if (custom_compiled() != TRUE) { + if (custom_compiled() != true) { math_error("%s: calc was built with custom functions enabled, " "custom_compiled() returned: %d != %d", - program, custom_compiled(), TRUE); + program, custom_compiled(), true); exit(1); } /* * indicate that custom functions are now allowed */ - allow_custom = TRUE; + allow_custom = true; break; #else /* CUSTOM */ /* * error if libcustcalc was compiled with CUSTOM defined */ - if (custom_compiled() != FALSE) { + if (custom_compiled() != false) { math_error("%s: calc was built with custom functions disabled, " "custom_compiled() returned: %d != %d", - program, custom_compiled(), FALSE); + program, custom_compiled(), false); } /* @@ -203,13 +201,13 @@ main(int argc, char **argv) exit(1); #endif /* CUSTOM */ case 'e': - no_env = TRUE; + no_env = true; break; case 'h': want_defhelp = 1; break; case 'i': - i_flag = TRUE; + i_flag = true; break; case 'm': cp++; @@ -246,7 +244,7 @@ main(int argc, char **argv) fprintf(stderr, "??? m-arg"); exit(4); } - havearg = TRUE; + havearg = true; break; case 'n': /* @@ -255,22 +253,22 @@ main(int argc, char **argv) */ break; case 'O': - use_old_std = TRUE; + use_old_std = true; break; case 'p': - p_flag = TRUE; + p_flag = true; break; case 'q': - q_flag = TRUE; + q_flag = true; break; case 'u': - u_flag = TRUE; + u_flag = true; break; case 'c': - c_flag = TRUE; + c_flag = true; break; case 'd': - d_flag = TRUE; + d_flag = true; break; case 'v': /* @@ -297,12 +295,12 @@ main(int argc, char **argv) * calc_debug:resource_debug:user_debug */ if (nextcp(&cp, &index, argc, argv, - FALSE)) { + false)) { fprintf(stderr, "-D expects argument\n"); exit(5); } - havearg = TRUE; + havearg = true; if (*cp != ':') { if (*cp < '0' || *cp > '9') { fprintf(stderr, @@ -323,13 +321,13 @@ main(int argc, char **argv) if (*cp != ':') { if (nextcp(&cp, &index, argc, argv, - FALSE) + false) || *cp != ':') break; } } if (nextcp(&cp, &index, argc, argv, - FALSE)) { + false)) { fprintf(stderr, "-D : expects" " argument\n"); @@ -355,14 +353,14 @@ main(int argc, char **argv) if (*cp != ':') { if (nextcp(&cp, &index, argc, argv, - FALSE) + false) || *cp != ':') { break; } } } if (nextcp(&cp, &index, argc, argv, - FALSE)) { + false)) { fprintf(stderr, "-D : : expects" " argument\n"); exit(11); @@ -395,7 +393,7 @@ main(int argc, char **argv) " filename\n"); exit(15); } - havearg = TRUE; + havearg = true; if (cmdlen > 0) cmdbuf[cmdlen++] = ' '; strlcpy(cmdbuf + cmdlen, "read ", @@ -479,12 +477,12 @@ main(int argc, char **argv) cmdlen++; /* -f implies -s */ - s_flag = TRUE; + s_flag = true; maxindex = index + 1; break; case 's': - s_flag = TRUE; + s_flag = true; maxindex = index + 1; break; default: @@ -544,11 +542,11 @@ main(int argc, char **argv) if (havecommands) { cmdbuf[cmdlen++] = '\n'; cmdbuf[cmdlen] = '\0'; - if (p_flag != TRUE) { + if (p_flag != true) { if (fclose(stdin)) { perror("main(): fclose(stdin) failed:"); } - stdin_closed = TRUE; + stdin_closed = true; } } @@ -559,7 +557,7 @@ main(int argc, char **argv) * unbuffered mode */ if (u_flag) { - if (stdin_closed == FALSE) { + if (stdin_closed == false) { setbuf(stdin, NULL); } setbuf(stdout, NULL); @@ -571,7 +569,7 @@ main(int argc, char **argv) libcalc_call_me_first(); if (u_flag) { if (conf->calc_debug & CALCDBG_TTY) { - if (stdin_closed == FALSE) { + if (stdin_closed == false) { printf("main: stdin set to unbuffered before " "calling libcalc_call_me_first()\n"); } else { @@ -647,7 +645,7 @@ main(int argc, char **argv) while (run_state == RUN_RCFILES) { fprintf(stderr, "Error in rcfiles\n"); if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(FALSE); + getcommands(false); if (inputlevel() == 0) { closeinput(); runrcfiles(); @@ -668,7 +666,7 @@ main(int argc, char **argv) if (havecommands) { set_run_state(RUN_CMD_ARGS); (void) openstring(cmdbuf, strlen(cmdbuf)); - getcommands(FALSE); + getcommands(false); closeinput(); } set_run_state(RUN_PRE_TOP_LEVEL); @@ -677,7 +675,7 @@ main(int argc, char **argv) while (run_state == RUN_CMD_ARGS) { fprintf(stderr, "Error in commands\n"); if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(FALSE); + getcommands(false); if (inputlevel() == 0) set_run_state(RUN_PRE_TOP_LEVEL); closeinput(); @@ -703,7 +701,7 @@ main(int argc, char **argv) openterminal(); } set_run_state(RUN_TOP_LEVEL); - getcommands(TRUE); + getcommands(true); } if (p_flag || (!i_flag && havecommands)) set_run_state(RUN_EXIT); @@ -713,7 +711,7 @@ main(int argc, char **argv) if (conf->calc_debug & CALCDBG_RUNSTATE) printf("main: run_state = TOP_LEVEL\n"); if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(TRUE); + getcommands(true); if (!inputisterminal()) { closeinput(); continue; @@ -737,7 +735,7 @@ main(int argc, char **argv) break; } - stdin_tty = TRUE; + stdin_tty = true; if (conf->calc_debug & CALCDBG_TTY) printf("main: stdin_tty is %d\n", stdin_tty); @@ -746,7 +744,7 @@ main(int argc, char **argv) } else { if (stdin_tty) { reinitialize(); - getcommands(TRUE); + getcommands(true); } else if (inputisterminal() && !p_flag && (!havecommands||i_flag)) { closeinput(); @@ -766,7 +764,7 @@ main(int argc, char **argv) set_run_state(RUN_EXIT_WITH_ERROR); break; } - stdin_tty = TRUE; + stdin_tty = true; if (conf->calc_debug & CALCDBG_TTY) printf("main: stdin_tty is %d\n", stdin_tty); @@ -804,7 +802,7 @@ intint(int UNUSED(arg)) not_reached(); } if (abortlevel >= ABORT_MATH) - _math_abort_ = TRUE; + _math_abort_ = true; printf("\n[Abort level %d]\n", abortlevel); } @@ -842,7 +840,7 @@ calc_interrupt(char *fmt, ...) } S_FUNC int -nextcp(char **cpp, int *ip, int argc, char **argv, BOOL haveendstr) +nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr) { char *cp; int index; diff --git a/calc.h b/calc.h index 1a57f3f..eb186b8 100644 --- a/calc.h +++ b/calc.h @@ -1,7 +1,7 @@ /* * calc - definitions for calculator program * - * Copyright (C) 1999-2007,2014,2021 David I. Bell + * Copyright (C) 1999-2007,2014,2021,2023 David I. Bell * * 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 @@ -104,9 +104,9 @@ E_FUNC FILEID openid(char *name, char *mode); E_FUNC FILEID openpathid(char *name, char *mode, char *pathlist); E_FUNC FILEID indexid(long index); -E_FUNC BOOL validid(FILEID id); -E_FUNC BOOL errorid(FILEID id); -E_FUNC BOOL eofid(FILEID id); +E_FUNC bool validid(FILEID id); +E_FUNC bool errorid(FILEID id); +E_FUNC bool eofid(FILEID id); E_FUNC int closeid(FILEID id); E_FUNC int getcharid(FILEID id); E_FUNC int idprintf(FILEID id, char *fmt, int count, VALUE **vals); @@ -157,7 +157,7 @@ E_FUNC int nextchar(void); E_FUNC void reread(void); E_FUNC void resetinput(void); E_FUNC void setprompt(char *); -E_FUNC BOOL inputisterminal(void); +E_FUNC bool inputisterminal(void); E_FUNC int inputlevel(void); E_FUNC long calclevel(void); E_FUNC char *inputname(void); @@ -172,12 +172,12 @@ E_FUNC NUMBER *constvalue(unsigned long index); E_FUNC long addnumber(char *str); E_FUNC long addqconstant(NUMBER *q); E_FUNC void initstack(void); -E_FUNC void getcommands(BOOL toplevel); +E_FUNC void getcommands(bool toplevel); E_FUNC void givehelp(char *type); E_FUNC void libcalc_call_me_first(void); E_FUNC void libcalc_call_me_last(void); -E_FUNC BOOL calc_tty(int fd); -E_FUNC BOOL orig_tty(int fd); +E_FUNC bool calc_tty(int fd); +E_FUNC bool orig_tty(int fd); E_FUNC void showerrors(void); E_FUNC char *calc_strdup(CONST char *); @@ -187,7 +187,7 @@ E_FUNC char *calc_strdup(CONST char *); E_FUNC void initialize(void); E_FUNC void reinitialize(void); #if !defined(_WIN32) && !defined(_WIN64) -E_FUNC int isatty(int tty); /* TRUE if fd is a tty */ +E_FUNC int isatty(int tty); /* true if fd is a tty */ #endif E_FUNC char *version(void); /* return version string */ @@ -195,33 +195,33 @@ E_FUNC char *version(void); /* return version string */ * global flags and definitions */ EXTERN int abortlevel; /* current level of aborts */ -EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */ +EXTERN bool inputwait; /* true if in a terminal input wait */ -EXTERN int p_flag; /* TRUE => pipe mode */ -EXTERN int q_flag; /* TRUE => don't execute rc files */ -EXTERN int u_flag; /* TRUE => unbuffer stdin and stdout */ -EXTERN int d_flag; /* TRUE => disable heading, resource_debug */ -EXTERN int c_flag; /* TRUE => continue after error if permitted */ -EXTERN int i_flag; /* TRUE => try to go interactive after error */ -E_FUNC int s_flag; /* TRUE => keep args as strings for argv() */ +EXTERN int p_flag; /* true => pipe mode */ +EXTERN int q_flag; /* true => don't execute rc files */ +EXTERN int u_flag; /* true => unbuffer stdin and stdout */ +EXTERN int d_flag; /* true => disable heading, resource_debug */ +EXTERN int c_flag; /* true => continue after error if permitted */ +EXTERN int i_flag; /* true => try to go interactive after error */ +E_FUNC int s_flag; /* true => keep args as strings for argv() */ EXTERN long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ -EXTERN BOOL abort_now; /* TRUE => try to go interactive */ +EXTERN bool abort_now; /* true => try to go interactive */ E_FUNC int argc_value; /* count of argv[] strings for argv() builtin */ E_FUNC char **argv_value; /* argv[] strings for argv() builtin */ EXTERN char *pager; /* $PAGER or default */ -EXTERN int stdin_tty; /* TRUE if stdin is a tty */ -EXTERN int havecommands; /* TRUE if have cmd args) */ +EXTERN int stdin_tty; /* true if stdin is a tty */ +EXTERN int havecommands; /* true if have cmd args) */ EXTERN char *program; /* our name */ EXTERN char *base_name; /* basename of our name */ EXTERN char cmdbuf[]; /* command line expression */ EXTERN char *script_name; /* program name or -f filename arg or NULL */ EXTERN int abortlevel; /* current level of aborts */ -EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */ +EXTERN bool inputwait; /* true if in a terminal input wait */ EXTERN VALUE *stack; /* execution stack */ -EXTERN int dumpnames; /* TRUE => dump names rather than indices */ +EXTERN int dumpnames; /* true => dump names rather than indices */ EXTERN char *calcpath; /* $CALCPATH or default */ EXTERN char *calcrc; /* $CALCRC or default */ @@ -229,13 +229,13 @@ EXTERN char *calcbindings; /* $CALCBINDINGS or default */ EXTERN char *home; /* $HOME or default */ EXTERN char *shell; /* $SHELL or default */ -EXTERN int no_env; /* TRUE (-e) => ignore env vars on startup */ +EXTERN int no_env; /* true (-e) => ignore env vars on startup */ EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */ -EXTERN int use_old_std; /* TRUE (-O) => use classic configuration */ +EXTERN int use_old_std; /* true (-O) => use classic configuration */ -EXTERN int allow_read; /* FALSE => don't open any files for reading */ -EXTERN int allow_write; /* FALSE => don't open any files for writing */ -EXTERN int allow_exec; /* FALSE => may not execute any commands */ +EXTERN int allow_read; /* false => don't open any files for reading */ +EXTERN int allow_write; /* false => don't open any files for writing */ +EXTERN int allow_exec; /* false => may not execute any commands */ /* * calc startup and run state diff --git a/cmath.h b/cmath.h index 75b7b40..ce79859 100644 --- a/cmath.h +++ b/cmath.h @@ -77,7 +77,7 @@ E_FUNC COMPLEX *c_neg(COMPLEX *c); E_FUNC COMPLEX *c_inv(COMPLEX *c); E_FUNC COMPLEX *c_int(COMPLEX *c); E_FUNC COMPLEX *c_frac(COMPLEX *c); -E_FUNC BOOL c_cmp(COMPLEX *c1, COMPLEX *c2); +E_FUNC bool c_cmp(COMPLEX *c1, COMPLEX *c2); /* @@ -123,9 +123,9 @@ E_FUNC COMPLEX *c_agd(COMPLEX *c, NUMBER *epsilon); /* * external functions */ -E_FUNC COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); -E_FUNC COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); -E_FUNC COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); +E_FUNC COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all); +E_FUNC COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all); +E_FUNC COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all); /* diff --git a/codegen.c b/codegen.c index ae3b24e..ecff052 100644 --- a/codegen.c +++ b/codegen.c @@ -1,7 +1,7 @@ /* * codegen - module to generate opcodes from the input tokens * - * Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2017,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -55,13 +55,13 @@ #include "banned.h" /* include after system header <> includes */ -STATIC BOOL rdonce; /* TRUE => do not reread this file */ +STATIC bool rdonce; /* true => do not reread this file */ FUNC *curfunc; S_FUNC int getsymvalue(char *name, VALUE *v_p); -S_FUNC int getfilename(char *name, size_t namelen, BOOL *once); -S_FUNC BOOL getid(char *buf); +S_FUNC int getfilename(char *name, size_t namelen, bool *once); +S_FUNC bool getid(char *buf); S_FUNC void getshowstatement(void); S_FUNC void getfunction(void); S_FUNC void ungetfunction(void); @@ -101,7 +101,7 @@ S_FUNC int getshiftexpr(void); S_FUNC int getreference(void); S_FUNC int getincdecexpr(void); S_FUNC int getterm(void); -S_FUNC int getidexpr(BOOL okmat, int autodef); +S_FUNC int getidexpr(bool okmat, int autodef); S_FUNC long getinitlist(void); #define INDICALLOC 8 @@ -121,14 +121,14 @@ STATIC int maxindices; * The toplevel flag indicates whether we are at the top interactive level. */ void -getcommands(BOOL toplevel) +getcommands(bool toplevel) { char name[MAXCMD+1+1]; /* program name */ /* firewall */ name[0] = '\0'; name[MAXCMD+1] = '\0'; - abort_now = FALSE; + abort_now = false; /* getcommands */ if (!toplevel) @@ -184,7 +184,7 @@ getcommands(BOOL toplevel) CALCEXT,rdonce); switch (open_ret) { case 0: - getcommands(FALSE); + getcommands(false); closeinput(); continue; case 1: @@ -227,7 +227,7 @@ getcommands(BOOL toplevel) default: rescantoken(); initstack(); - if (evaluate(FALSE)) + if (evaluate(false)) updateoldvalue(curfunc); freefunc(curfunc); if (abort_now) { @@ -252,18 +252,18 @@ getcommands(BOOL toplevel) /* * Evaluate a line of statements. * This is done by treating the current line as a function body, - * compiling it, and then executing it. Returns TRUE if the line + * compiling it, and then executing it. Returns true if the line * successfully compiled and executed. The last expression result * is saved in the f_savedvalue element of the current function. - * The nestflag variable should be FALSE for the outermost evaluation - * level, and TRUE for all other calls (such as the 'eval' function). + * The nestflag variable should be false for the outermost evaluation + * level, and true for all other calls (such as the 'eval' function). * The function name begins with an asterisk to indicate specialness. * * given: - * nestflag TRUE if this is a nested evaluation + * nestflag true if this is a nested evaluation */ -BOOL -evaluate(BOOL nestflag) +bool +evaluate(bool nestflag) { char *funcname; int loop = 1; /* 0 => end the main while loop */ @@ -296,9 +296,9 @@ evaluate(BOOL nestflag) addop(OP_RETURN); checklabels(); if (errorcount) - return FALSE; + return false; calculate(curfunc, 0); - return TRUE; + return true; } /* @@ -334,7 +334,7 @@ ungetfunction(void) return; } name = tokensymbol(); - endscope(name, FALSE); + endscope(name, false); continue; case T_NEWLINE: @@ -374,7 +374,7 @@ getfunction(void) scanerror(T_SEMICOLON, "Using builtin function name"); return; } - beginfunc(name, FALSE); + beginfunc(name, false); enterfuncscope(); if (gettoken() != T_LEFTPAREN) { scanerror(T_SEMICOLON, @@ -466,7 +466,7 @@ getbody(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, int oldmode; oldmode = tokenmode(TM_DEFAULT); - while (TRUE) { + while (true) { switch (gettoken()) { case T_RIGHTBRACE: (void) tokenmode(oldmode); @@ -495,7 +495,7 @@ getdeclarations(int symtype) { int res = 0; - while (TRUE) { + while (true) { switch (gettoken()) { case T_COMMA: continue; @@ -631,7 +631,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL label; LABEL label1, label2, label3, label4; /* locations for jumps */ int type; - BOOL printeol; + bool printeol; int oldmode; addopone(OP_DEBUG, linenumber()); @@ -960,7 +960,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, break; case T_PRINT: - printeol = TRUE; + printeol = true; for (;;) { switch (gettoken()) { case T_RIGHTPAREN: @@ -979,14 +979,14 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, addop(OP_PRINTSPACE); /*FALLTHRU*/ case T_COLON: - printeol = FALSE; + printeol = false; break; case T_STRING: - printeol = TRUE; + printeol = true; addopone(OP_PRINTSTRING, tokenstring()); break; default: - printeol = TRUE; + printeol = true; rescantoken(); (void) getopassignment(); addopone(OP_PRINT, (long) PRINT_NORMAL); @@ -1195,7 +1195,7 @@ getoneobj(long index, int symtype) if (gettoken() == T_SYMBOL) { if (symtype == SYM_UNDEFINED) { rescantoken(); - (void) getidexpr(TRUE, 1); + (void) getidexpr(true, 1); } else { symname = tokensymbol(); definesymbol(symname, symtype); @@ -1278,7 +1278,7 @@ getonematrix(int symtype) if (gettoken() == T_SYMBOL) { if (symtype == SYM_UNDEFINED) { rescantoken(); - (void) getidexpr(FALSE, 1); + (void) getidexpr(false, 1); } else { name = tokensymbol(); definesymbol(name, symtype); @@ -2141,7 +2141,7 @@ getterm(void) case T_SYMBOL: rescantoken(); - type = getidexpr(TRUE, 0); + type = getidexpr(true, 0); break; case T_MULT: @@ -2164,7 +2164,7 @@ getterm(void) break; } rescantoken(); - type = getidexpr(TRUE, T_GLOBAL); + type = getidexpr(true, T_GLOBAL); break; case T_LOCAL: @@ -2174,7 +2174,7 @@ getterm(void) break; } rescantoken(); - type = getidexpr(TRUE, T_LOCAL); + type = getidexpr(true, T_LOCAL); break; case T_STATIC: @@ -2184,7 +2184,7 @@ getterm(void) break; } rescantoken(); - type = getidexpr(TRUE, T_STATIC); + type = getidexpr(true, T_STATIC); break; case T_LEFTBRACKET: @@ -2238,7 +2238,7 @@ getterm(void) * Returns the type of expression found. */ S_FUNC int -getidexpr(BOOL okmat, int autodef) +getidexpr(bool okmat, int autodef) { int type; char name[SYMBOLSIZE+1]; /* symbol name */ @@ -2339,15 +2339,15 @@ getsymvalue(char *name, VALUE *v_p) * Read in a filename for a read or write command. * Both quoted and unquoted filenames are handled here. * The name must be terminated by an end of line or semicolon. - * Returns TRUE if the filename was successfully parsed. + * Returns true if the filename was successfully parsed. * * given: * name filename to read * namelen length of filename buffer including NUL byte - * once non-NULL => set to TRUE of -once read + * once non-NULL => set to true of -once read */ S_FUNC int -getfilename(char *name, size_t namelen, BOOL *once) +getfilename(char *name, size_t namelen, bool *once) { STRING *s; char *symstr; /* symbol string */ @@ -2532,7 +2532,7 @@ getmatargs(void) */ dim = 0; if (gettoken() == T_RIGHTBRACKET) { - addoptwo(OP_INDEXADDR, (long) dim, (long) FALSE); + addoptwo(OP_INDEXADDR, (long) dim, (long) false); return; } rescantoken(); @@ -2542,7 +2542,7 @@ getmatargs(void) switch (gettoken()) { case T_RIGHTBRACKET: addoptwo(OP_INDEXADDR, (long) dim, - (long) FALSE); + (long) false); return; case T_COMMA: break; @@ -2580,9 +2580,9 @@ getelement(void) /* * Read in a single symbol name and copy its value into the given buffer. - * Returns TRUE if a valid symbol id was found. + * Returns true if a valid symbol id was found. */ -S_FUNC BOOL +S_FUNC bool getid(char *buf) { int type; @@ -2592,16 +2592,16 @@ getid(char *buf) scanerror(T_NULL, "Reserved keyword used as symbol name"); type = T_SYMBOL; *buf = '\0'; - return FALSE; + return false; } if (type != T_SYMBOL) { rescantoken(); scanerror(T_NULL, "Symbol name expected"); *buf = '\0'; - return FALSE; + return false; } strlcpy(buf, tokensymbol(), SYMBOLSIZE+1); - return TRUE; + return true; } @@ -2687,11 +2687,11 @@ usesymbol(char *name, int autodef) if (type == SYM_GLOBAL) { warning("Unnecessary global specifier"); } - addopptr(OP_GLOBALADDR, (char *) addglobal(name, FALSE)); + addopptr(OP_GLOBALADDR, (char *) addglobal(name, false)); return; } if (autodef == T_STATIC) { - addopptr(OP_GLOBALADDR, (char *) addglobal(name, TRUE)); + addopptr(OP_GLOBALADDR, (char *) addglobal(name, true)); return; } if (autodef == T_LOCAL) { @@ -2721,7 +2721,7 @@ usesymbol(char *name, int autodef) scanerror(T_NULL, "\"%s\" is undefined", name); return; } - (void) addglobal(name, FALSE); + (void) addglobal(name, false); addopptr(OP_GLOBALADDR, (char *) findglobal(name)); } @@ -2740,7 +2740,7 @@ getcallargs(char *name) long index; /* function index */ long op; /* opcode to add */ int argcount; /* number of arguments */ - BOOL addrflag; + bool addrflag; op = OP_CALL; index = getbuiltinfunc(name); diff --git a/comfunc.c b/comfunc.c index 1cda8db..816530f 100644 --- a/comfunc.c +++ b/comfunc.c @@ -1,7 +1,7 @@ /* * comfunc - extended precision complex arithmetic non-primitive routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -538,7 +538,7 @@ c_ln(COMPLEX *c, NUMBER *epsilon) COMPLEX * c_log(COMPLEX *c, NUMBER *epsilon) { - int need_new_cln_10 = TRUE; /* FALSE => use cached cln_10 value */ + int need_new_cln_10 = true; /* false => use cached cln_10 value */ COMPLEX *ln_c; /* ln(x) */ COMPLEX *ret; /* base 10 logarithm of x */ @@ -557,19 +557,19 @@ c_log(COMPLEX *c, NUMBER *epsilon) if (cln_10_epsilon == NULL) { /* first time call */ cln_10_epsilon = qcopy(epsilon); - } else if (qcmp(cln_10_epsilon, epsilon) == TRUE) { + } else if (qcmp(cln_10_epsilon, epsilon) == true) { /* replaced cached value with epsilon arg */ qfree(cln_10_epsilon); cln_10_epsilon = qcopy(epsilon); } else if (cln_10 != NULL) { /* the previously computed ln(2) is OK to use */ - need_new_cln_10 = FALSE; + need_new_cln_10 = false; } /* * compute ln(10) if needed */ - if (need_new_cln_10 == TRUE) { + if (need_new_cln_10 == true) { if (cln_10 != NULL) { comfree(cln_10); } @@ -596,7 +596,7 @@ c_cos(COMPLEX *c, NUMBER *epsilon) COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; NUMBER *epsilon1; long n; - BOOL neg; + bool neg; if (qiszero(epsilon)) { math_error("Zero epsilon for ccos"); @@ -646,7 +646,7 @@ c_sin(COMPLEX *c, NUMBER *epsilon) COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; NUMBER *qtmp, *epsilon1; long n; - BOOL neg; + bool neg; if (qiszero(epsilon)) { math_error("Zero epsilon for csin"); @@ -775,7 +775,7 @@ COMPLEX * c_asinh(COMPLEX *c, NUMBER *epsilon) { COMPLEX *tmp1, *tmp2, *tmp3; - BOOL neg; + bool neg; neg = qisneg(c->real); tmp1 = neg ? c_neg(c) : clink(c); @@ -952,7 +952,7 @@ c_gd(COMPLEX *c, NUMBER *epsilon) NUMBER *sin, *cos; NUMBER *eps; int n, n1; - BOOL neg; + bool neg; if (cisreal(c)) { q1 = qscale(c->real, -1); @@ -1221,7 +1221,7 @@ cprintfr(COMPLEX *c) r = c->real; i = c->imag; if (!qiszero(r) || qiszero(i)) - qprintfr(r, 0L, FALSE); + qprintfr(r, 0L, false); if (qiszero(i)) return; if (!qiszero(r) && !qisneg(i)) diff --git a/commath.c b/commath.c index 32e0f51..c876ec7 100644 --- a/commath.c +++ b/commath.c @@ -1,7 +1,7 @@ /* * commath - extended precision complex arithmetic primitive routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -560,13 +560,13 @@ qqtoc(NUMBER *q1, NUMBER *q2) /* - * Compare two complex numbers for equality, returning FALSE if they are equal, - * and TRUE if they differ. + * Compare two complex numbers for equality, returning false if they are equal, + * and true if they differ. */ -BOOL +bool c_cmp(COMPLEX *c1, COMPLEX *c2) { - BOOL i; + bool i; i = qcmp(c1->real, c2->real); if (!i) diff --git a/config.c b/config.c index 6ec1cde..4b0fde9 100644 --- a/config.c +++ b/config.c @@ -1,7 +1,7 @@ /* * config - configuration routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -147,17 +147,17 @@ CONFIG oldstd = { /* backward compatible standard configuration */ 20, /* current output digits for float or exp */ NULL, /* loaded in at startup - default error for real functions */ EPSILONPREC_DEFAULT, /* binary precision of epsilon */ - FALSE, /* tracing flags */ + false, /* tracing flags */ MAXPRINT_DEFAULT, /* number of elements to print */ MUL_ALG2, /* size of number to use multiply alg 2 */ SQ_ALG2, /* size of number to use square alg 2 */ POW_ALG2, /* size of modulus to use REDC for powers */ REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ - TRUE, /* TRUE ==> print a tilde on approximations */ - FALSE, /* TRUE ==> print a space after tilde on approximations */ - FALSE, /* TRUE ==> print spaces around / in fractions */ - FALSE, /* TRUE ==> print spaces around + or - in complex values */ - TRUE, /* TRUE ==> print tab before numeric values */ + true, /* true ==> print a tilde on approximations */ + false, /* true ==> print a space after tilde on approximations */ + false, /* true ==> print spaces around / in fractions */ + false, /* true ==> print spaces around + or - in complex values */ + true, /* true ==> print tab before numeric values */ 0, /* quomod() default rounding mode */ 2, /* quotient // default rounding mode */ 0, /* mod % default rounding mode */ @@ -167,42 +167,42 @@ CONFIG oldstd = { /* backward compatible standard configuration */ 8, /* cfsim() default rounding mode */ 2, /* output default rounding mode */ 24, /* round()/bround() default rounding mode */ - FALSE, /* TRUE ==> print leading 0 before decimal pt */ - 0, /* TRUE ==> print trailing 0's */ + false, /* true ==> print leading 0 before decimal pt */ + 0, /* true ==> print trailing 0's */ MAXSCANCOUNT, /* max scan errors before abort */ PROMPT1, /* normal prompt */ PROMPT2, /* prompt when inside multi-line input */ BLK_DEF_MAXPRINT, /* number of octets of a block to print */ - FALSE, /* skip duplicate block output lines */ + false, /* skip duplicate block output lines */ BLK_BASE_HEX, /* block octet print base */ BLK_FMT_HD_STYLE, /* block output format */ 0, /* internal calc debug level */ 3, /* calc resource file debug level */ 0, /* user defined debug level */ - FALSE, /* TRUE ==> print Quit or abort executed messages */ + false, /* true ==> print Quit or abort executed messages */ CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ NULL, /* our name */ NULL, /* basename of our name */ #if defined(_WIN32) || defined(_WIN64) - TRUE, /* TRUE ==> running under windows */ + true, /* true ==> running under windows */ #else - FALSE, /* FALSE ==> not using windows */ + false, /* false ==> not using windows */ #endif #if defined(__CYGWIN__) - TRUE, /* TRUE ==> compiled under cygwin */ + true, /* true ==> compiled under cygwin */ #else - FALSE, /* FALSE ==> not compiled with cygwin */ + false, /* false ==> not compiled with cygwin */ #endif #if defined(CUSTOM) - TRUE, /* TRUE ==> compiled with -DCUSTOM */ + true, /* true ==> compiled with -DCUSTOM */ #else - FALSE, /* FALSE ==> compiled without -DCUSTOM */ + false, /* false ==> compiled without -DCUSTOM */ #endif - &allow_custom, /* *TRUE=> custom functions are enabled */ + &allow_custom, /* *true=> custom functions are enabled */ NULL, /* version */ BASEB, /* base for calculations */ - TRUE, /* TRUE ==> warn when redeclaring */ - TRUE, /* TRUE ==> warn when variable names collide */ + true, /* true ==> warn when redeclaring */ + true, /* true ==> warn when variable names collide */ }; CONFIG newstd = { /* new non-backward compatible configuration */ MODE_INITIAL, /* current output mode */ @@ -210,17 +210,17 @@ CONFIG newstd = { /* new non-backward compatible configuration */ 20, /* current output digits for float or exp */ NULL, /* loaded in at startup - default error for real functions */ EPSILONPREC_DEFAULT, /* binary precision of epsilon */ - FALSE, /* tracing flags */ + false, /* tracing flags */ MAXPRINT_DEFAULT, /* number of elements to print */ MUL_ALG2, /* size of number to use multiply alg 2 */ SQ_ALG2, /* size of number to use square alg 2 */ POW_ALG2, /* size of modulus to use REDC for powers */ REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ - TRUE, /* TRUE ==> print a tilde on approximations */ - FALSE, /* TRUE ==> print spaces around / in fractions */ - FALSE, /* TRUE ==> print a space after tilde on approximations */ - FALSE, /* TRUE ==> print spaces around + or - in complex values */ - TRUE, /* TRUE ==> print tab before numeric values */ + true, /* true ==> print a tilde on approximations */ + false, /* true ==> print spaces around / in fractions */ + false, /* true ==> print a space after tilde on approximations */ + false, /* true ==> print spaces around + or - in complex values */ + true, /* true ==> print tab before numeric values */ 0, /* quomod() default rounding mode */ 2, /* quotient // default rounding mode */ 0, /* mod % default rounding mode */ @@ -230,42 +230,42 @@ CONFIG newstd = { /* new non-backward compatible configuration */ 8, /* cfsim() default rounding mode */ 24, /* output default rounding mode */ 24, /* round()/bround() default rounding mode */ - TRUE, /* TRUE ==> print leading 0 before decimal pt */ - 0, /* TRUE ==> print trailing 0's */ + true, /* true ==> print leading 0 before decimal pt */ + 0, /* true ==> print trailing 0's */ MAXSCANCOUNT, /* max scan errors before abort */ "; ", /* normal prompt */ ";; ", /* prompt when inside multi-line input */ BLK_DEF_MAXPRINT, /* number of octets of a block to print */ - FALSE, /* skip duplicate block output lines */ + false, /* skip duplicate block output lines */ BLK_BASE_HEX, /* block octet print base */ BLK_FMT_HD_STYLE, /* block output format */ 0, /* internal calc debug level */ 3, /* calc resource file debug level */ 0, /* user defined debug level */ - FALSE, /* TRUE ==> print Quit or abort executed messages */ + false, /* true ==> print Quit or abort executed messages */ CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ NULL, /* our name */ NULL, /* basename of our name */ #if defined(_WIN32) || defined(_WIN64) - TRUE, /* TRUE ==> running under windows */ + true, /* true ==> running under windows */ #else - FALSE, /* FALSE ==> not using windows */ + false, /* false ==> not using windows */ #endif #if defined(__CYGWIN__) - TRUE, /* TRUE ==> compiled under cygwin */ + true, /* true ==> compiled under cygwin */ #else - FALSE, /* FALSE ==> not compiled with cygwin */ + false, /* false ==> not compiled with cygwin */ #endif #if defined(CUSTOM) - TRUE, /* TRUE ==> compiled with -DCUSTOM */ + true, /* true ==> compiled with -DCUSTOM */ #else - FALSE, /* FALSE ==> compiled without -DCUSTOM */ + false, /* false ==> compiled without -DCUSTOM */ #endif - &allow_custom, /* *TRUE ==> custom functions are enabled */ + &allow_custom, /* *true ==> custom functions are enabled */ NULL, /* version */ BASEB, /* base for calculations */ - TRUE, /* TRUE ==> warn when redeclaring */ - TRUE, /* TRUE ==> warn when variable names collide */ + true, /* true ==> warn when redeclaring */ + true, /* true ==> warn when variable names collide */ }; CONFIG *conf = NULL; /* loaded in at startup - current configuration */ @@ -358,23 +358,23 @@ STATIC NAMETYPE ctrl_d[] = { /* * Possible binary config state values */ -#define TRUE_STRING "true" -#define FALSE_STRING "false" +#define true_STRING "true" +#define false_STRING "false" STATIC NAMETYPE truth[] = { - {TRUE_STRING, TRUE}, - {"t", TRUE}, - {"on", TRUE}, - {"yes", TRUE}, - {"y", TRUE}, - {"set", TRUE}, - {"1", TRUE}, - {FALSE_STRING, FALSE}, - {"f", FALSE}, - {"off", FALSE}, - {"no", FALSE}, - {"n", FALSE}, - {"unset", FALSE}, - {"0", FALSE}, + {true_STRING, true}, + {"t", true}, + {"on", true}, + {"yes", true}, + {"y", true}, + {"set", true}, + {"1", true}, + {false_STRING, false}, + {"f", false}, + {"off", false}, + {"no", false}, + {"n", false}, + {"unset", false}, + {"0", false}, {NULL, 0} }; @@ -1468,9 +1468,9 @@ config_value(CONFIG *cfg, int type, VALUE *vp) * cfg2 - 2nd CONFIG to compare * * return: - * TRUE if configurations differ + * true if configurations differ */ -BOOL +bool config_cmp(CONFIG *cfg1, CONFIG *cfg2) { /* diff --git a/config.h b/config.h index 7c183f1..ed6391e 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ /* * config - configuration routines * - * Copyright (C) 1999-2007,2014,2021 Landon Curt Noll and David I. Bell + * Copyright (C) 1999-2007,2014,2021,2023 Landon Curt Noll and David I. Bell * * Primary author: Landon Curt Noll * @@ -133,11 +133,11 @@ struct config { LEN sq2; /* size of number to use square algorithm 2 */ LEN pow2; /* size of modulus to use REDC for powers */ LEN redc2; /* size of modulus to use REDC algorithm 2 */ - BOOL tilde_ok; /* OK to print a tilde on approximations */ - BOOL tilde_space; /* print space after tilde on approximations */ - BOOL fraction_space; /* TRUE => print spaces around / in fractions */ - BOOL complex_space; /* TRUE => print spaces around + or - in complex values */ - BOOL tab_ok; /* OK to print tab before numeric values */ + bool tilde_ok; /* OK to print a tilde on approximations */ + bool tilde_space; /* print space after tilde on approximations */ + bool fraction_space; /* true => print spaces around / in fractions */ + bool complex_space; /* true => print spaces around + or - in complex values */ + bool tab_ok; /* OK to print tab before numeric values */ LEN quomod; /* quomod() default rounding mode */ LEN quo; /* quotient // default rounding mode */ LEN mod; /* mod % default rounding mode */ @@ -147,30 +147,30 @@ struct config { LEN cfsim; /* cfsim() default rounding mode */ LEN outround; /* output default rounding mode */ LEN round; /* round()/bround() default rounding mode */ - BOOL leadzero; /* OK to print leading 0 before decimal pt */ - BOOL fullzero; /* OK to print trailing 0's */ + bool leadzero; /* OK to print leading 0 before decimal pt */ + bool fullzero; /* OK to print trailing 0's */ long maxscancount; /* max scan errors before abort */ char *prompt1; /* normal prompt */ char *prompt2; /* prompt when inside multi-line input */ int blkmaxprint; /* octets of a block to print, 0 => all */ - BOOL blkverbose; /* TRUE => print all lines if a block */ + bool blkverbose; /* true => print all lines if a block */ int blkbase; /* block output base */ int blkfmt; /* block output style */ long calc_debug; /* internal debug, see CALC_DEBUG_XYZ below */ long resource_debug; /* resource debug, see RSCDBG_XYZ below */ long user_debug; /* user defined debug value: 0 default */ - BOOL verbose_quit; /* TRUE => print Quit or abort executed msg */ + bool verbose_quit; /* true => print Quit or abort executed msg */ int ctrl_d; /* see CTRL_D_xyz below */ char *program; /* our name */ char *base_name; /* basename of our name */ - BOOL windows; /* TRUE => running under MS windows */ - BOOL cygwin; /* TRUE => compiled with cygwin */ - BOOL compile_custom; /* TRUE => compiled with -DCUSTOM */ - BOOL *allow_custom; /* ptr to if custom functions are allowed */ + bool windows; /* true => running under MS windows */ + bool cygwin; /* true => compiled with cygwin */ + bool compile_custom; /* true => compiled with -DCUSTOM */ + bool *allow_custom; /* ptr to if custom functions are allowed */ char *version; /* calc version string */ int baseb; /* base for calculations */ - BOOL redecl_warn; /* TRUE => warn of redeclaring variables */ - BOOL dupvar_warn; /* TRUE => warn of var name collisions */ + bool redecl_warn; /* true => warn of redeclaring variables */ + bool dupvar_warn; /* true => warn of var name collisions */ }; typedef struct config CONFIG; @@ -225,7 +225,7 @@ E_FUNC void config_free(CONFIG *cfg); E_FUNC void config_print(CONFIG *cfg); E_FUNC int configtype(char*); E_FUNC void config_print(CONFIG*); -E_FUNC BOOL config_cmp(CONFIG*, CONFIG*); +E_FUNC bool config_cmp(CONFIG*, CONFIG*); #endif /* !INCLUDE_CONFIG_H */ diff --git a/const.c b/const.c index 655b87e..b0c70d5 100644 --- a/const.c +++ b/const.c @@ -1,7 +1,7 @@ /* * const - constant number storage module * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -99,7 +99,7 @@ addqconstant(NUMBER *q) HALF numlow; /* bottom value of numerator */ HALF denlow; /* bottom value of denominator */ long first; /* first non-null position found */ - BOOL havefirst; + bool havefirst; if (constavail <= 0) { if (consttable == NULL) { @@ -120,7 +120,7 @@ addqconstant(NUMBER *q) numlow = q->num.v[0]; denlow = q->den.v[0]; first = 0; - havefirst = FALSE; + havefirst = false; tp = consttable; for (index = 0; index < constcount; index++, tp++) { t = *tp; @@ -129,7 +129,7 @@ addqconstant(NUMBER *q) } if (t->links == 0) { if (!havefirst) { - havefirst = TRUE; + havefirst = true; first = index; } continue; @@ -140,7 +140,7 @@ addqconstant(NUMBER *q) *tp = consttable[first]; consttable[first] = q; } else { - havefirst = TRUE; + havefirst = true; first = index; } continue; diff --git a/custom.c b/custom.c index e26159e..00a9cce 100644 --- a/custom.c +++ b/custom.c @@ -1,7 +1,7 @@ /* * custom - interface for custom software and hardware interfaces * - * Copyright (C) 1999-2006,2018,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2006,2018,2021-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 @@ -54,7 +54,7 @@ EXTERN CONST struct custom cust[]; /* custom interface table */ #include "banned.h" /* include after system header <> includes */ -BOOL allow_custom = FALSE; /* TRUE => custom builtins allowed */ +bool allow_custom = false; /* true => custom builtins allowed */ /* @@ -71,10 +71,10 @@ custom(char *name, int count, VALUE **vals) /* * error if libcustcalc was compiled with CUSTOM undefined */ - if (custom_compiled() != TRUE) { + if (custom_compiled() != true) { math_error("libcustcalc was compiled with CUSTOM undefined " "custom_compiled() returned: %d != %d", - custom_compiled(), TRUE); + custom_compiled(), true); not_reached(); } @@ -113,10 +113,10 @@ custom(char *name, int count, VALUE **vals) /* * error if libcustcalc was compiled with CUSTOM defined */ - if (custom_compiled() != FALSE) { + if (custom_compiled() != false) { math_error("libcustcalc was compiled with CUSTOM defined " "custom_compiled() returned: %d != %d", - custom_compiled(), FALSE); + custom_compiled(), false); not_reached(); } diff --git a/custom.h b/custom.h index 65d358e..f2b1f63 100644 --- a/custom.h +++ b/custom.h @@ -73,9 +73,9 @@ struct custom { * * These are the required interfaces. The dummy.c stubs these interfaces too. */ -E_FUNC BOOL custom_compiled(void); /* return TRUE if libcustcalc compiled CUSTOM defined, FALSE otherwise */ +E_FUNC bool custom_compiled(void); /* return true if libcustcalc compiled CUSTOM defined, false otherwise */ E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */ -EXTERN BOOL allow_custom; /* TRUE => custom builtins allowed */ +EXTERN bool allow_custom; /* true => custom builtins allowed */ E_FUNC void showcustom(void); /* print custom functions */ E_FUNC void customhelp(char *); /* direct custom help */ E_FUNC void init_custreg(void); /* initialize custom registers */ diff --git a/custom/Makefile b/custom/Makefile index 540591b..277f4a1 100644 --- a/custom/Makefile +++ b/custom/Makefile @@ -691,6 +691,7 @@ c_argv.o: ../alloc.h c_argv.o: ../attribute.h c_argv.o: ../banned.h c_argv.o: ../block.h +c_argv.o: ../bool.h c_argv.o: ../byteswap.h c_argv.o: ../calc.h c_argv.o: ../calcerr.h @@ -722,6 +723,7 @@ c_devnull.o: ../alloc.h c_devnull.o: ../attribute.h c_devnull.o: ../banned.h c_devnull.o: ../block.h +c_devnull.o: ../bool.h c_devnull.o: ../byteswap.h c_devnull.o: ../calcerr.h c_devnull.o: ../charbit.h @@ -753,6 +755,7 @@ c_help.o: ../alloc.h c_help.o: ../attribute.h c_help.o: ../banned.h c_help.o: ../block.h +c_help.o: ../bool.h c_help.o: ../byteswap.h c_help.o: ../calcerr.h c_help.o: ../charbit.h @@ -784,6 +787,7 @@ c_pmodm127.o: ../alloc.h c_pmodm127.o: ../attribute.h c_pmodm127.o: ../banned.h c_pmodm127.o: ../block.h +c_pmodm127.o: ../bool.h c_pmodm127.o: ../byteswap.h c_pmodm127.o: ../calcerr.h c_pmodm127.o: ../charbit.h @@ -814,6 +818,7 @@ c_pzasusb8.o: ../alloc.h c_pzasusb8.o: ../attribute.h c_pzasusb8.o: ../banned.h c_pzasusb8.o: ../block.h +c_pzasusb8.o: ../bool.h c_pzasusb8.o: ../byteswap.h c_pzasusb8.o: ../calcerr.h c_pzasusb8.o: ../charbit.h @@ -844,6 +849,7 @@ c_register.o: ../alloc.h c_register.o: ../attribute.h c_register.o: ../banned.h c_register.o: ../block.h +c_register.o: ../bool.h c_register.o: ../byteswap.h c_register.o: ../calc.h c_register.o: ../calcerr.h @@ -875,6 +881,7 @@ c_sysinfo.o: ../alloc.h c_sysinfo.o: ../attribute.h c_sysinfo.o: ../banned.h c_sysinfo.o: ../block.h +c_sysinfo.o: ../bool.h c_sysinfo.o: ../byteswap.h c_sysinfo.o: ../calc.h c_sysinfo.o: ../calcerr.h @@ -913,6 +920,7 @@ custtbl.o: ../alloc.h custtbl.o: ../attribute.h custtbl.o: ../banned.h custtbl.o: ../block.h +custtbl.o: ../bool.h custtbl.o: ../byteswap.h custtbl.o: ../calcerr.h custtbl.o: ../charbit.h diff --git a/custom/c_pmodm127.c b/custom/c_pmodm127.c index 5201f95..346156a 100644 --- a/custom/c_pmodm127.c +++ b/custom/c_pmodm127.c @@ -70,7 +70,7 @@ ZVALUE p255 = { /* static declarations */ S_FUNC void zmod5_or_zmod(ZVALUE *zp); -STATIC BOOL havelastmod = FALSE; +STATIC bool havelastmod = false; STATIC ZVALUE lastmod[1]; STATIC ZVALUE lastmodinv[1]; @@ -122,14 +122,14 @@ c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals) if (havelastmod && zcmp(q, *lastmod)) { zfree(*lastmod); zfree(*lastmodinv); - havelastmod = FALSE; + havelastmod = false; } if (!havelastmod) { zcopy(q, lastmod); zbitvalue(2 * q.len * BASEB, &temp); zquo(temp, q, lastmodinv, 0); zfree(temp); - havelastmod = TRUE; + havelastmod = true; } /* diff --git a/custom/c_sysinfo.c b/custom/c_sysinfo.c index cefbeb3..8c00dc5 100644 --- a/custom/c_sysinfo.c +++ b/custom/c_sysinfo.c @@ -136,8 +136,8 @@ STATIC struct infoname sys_info[] = { (FULL)E__COUNT}, {"E__HIGHEST", "highest calc error", NULL, (FULL)E__HIGHEST}, - {"FALSE", "boolean false", NULL, - (FULL)FALSE}, + {"false", "boolean false", NULL, + (FULL)false}, {"FILEPOS_BITS", "file position size in bits", NULL, (FULL)FILEPOS_BITS}, {"FULL_BITS", "bits in a FULL", NULL, @@ -248,8 +248,8 @@ STATIC struct infoname sys_info[] = { (FULL)TOPHALF}, {"TOPLONG", "top long bit", NULL, (FULL)TOPLONG}, - {"TRUE", "boolean true", NULL, - (FULL)TRUE}, + {"true", "boolean true", NULL, + (FULL)true}, {"USUAL_ELEMENTS", "usual number of elements for objects", NULL, (FULL)USUAL_ELEMENTS}, {"REGNUM_MAX", "highest custom register number", NULL, diff --git a/custom/custtbl.c b/custom/custtbl.c index 2219982..6f3cd7b 100644 --- a/custom/custtbl.c +++ b/custom/custtbl.c @@ -39,16 +39,16 @@ * custom_compiled - determine if custom functions are compiled into libcustcalc * * returns: -s* TRUE ==> libcustcalc was compiled with CUSTOM defined - * FALSE ==> libcustcalc was compiled with CUSTOM undefined +s* true ==> libcustcalc was compiled with CUSTOM defined + * false ==> libcustcalc was compiled with CUSTOM undefined */ -E_FUNC BOOL +E_FUNC bool custom_compiled(void) { #if defined(CUSTOM) - return TRUE; + return true; #else /* CUSTOM */ - return FALSE; + return false; #endif /* CUSTOM */ } diff --git a/file.c b/file.c index f78b3af..e9fa782 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* * file - file I/O routines callable by users * - * Copyright (C) 1999-2007,2018,2021,2022 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2007,2018,2021-2023 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -73,11 +73,11 @@ E_FUNC FILE *f_open(char *name, char *mode); */ STATIC FILEIO files[MAXFILES] = { {FILEID_STDIN, NULL, (dev_t)0, (ino_t)0, - "(stdin)", TRUE, FALSE, FALSE, FALSE, 'r', "r"}, + "(stdin)", true, false, false, false, 'r', "r"}, {FILEID_STDOUT, NULL, (dev_t)0, (ino_t)0, - "(stdout)", FALSE, TRUE, FALSE, FALSE, 'w', "w"}, + "(stdout)", false, true, false, false, 'w', "w"}, {FILEID_STDERR, NULL, (dev_t)0, (ino_t)0, - "(stderr)", FALSE, TRUE, FALSE, FALSE, 'w', "w"} + "(stderr)", false, true, false, false, 'w', "w"} }; @@ -94,9 +94,9 @@ S_FUNC int get_open_pos(FILE *fp, ZVALUE *res); S_FUNC ZVALUE off_t2z(off_t siz); S_FUNC ZVALUE dev2z(dev_t dev); S_FUNC ZVALUE inode2z(ino_t inode); -S_FUNC void getscanfield(FILE *fp, BOOL skip, unsigned int width, +S_FUNC void getscanfield(FILE *fp, bool skip, unsigned int width, int scannum, char *scanptr, char **strptr); -S_FUNC void getscanwhite(FILE *fp, BOOL skip, unsigned int width, +S_FUNC void getscanwhite(FILE *fp, bool skip, unsigned int width, int scannum, char **strptr); S_FUNC int fscanfile(FILE *fp, char *fmt, int count, VALUE **vals); S_FUNC void freadnum(FILE *fp, VALUE *valptr); @@ -145,8 +145,8 @@ file_init(void) char *tname; fiop->name = NULL; - files[idnum].reading = TRUE; - files[idnum].writing = TRUE; + files[idnum].reading = true; + files[idnum].writing = true; files[idnum].action = 0; memset(files[idnum].mode, 0, MODE_LEN+1); /* @@ -163,13 +163,13 @@ file_init(void) if (fp) { strlcpy(files[idnum].mode, "r", sizeof(files[idnum].mode)); - files[idnum].writing = FALSE; + files[idnum].writing = false; } else { fp = (FILE *) fdopen(i, "w"); if (fp) { strlcpy(files[idnum].mode, "w", sizeof(files[idnum].mode)); - files[idnum].reading = FALSE; + files[idnum].reading = false; } else continue; @@ -244,10 +244,10 @@ init_fileio(FILEIO *fiop, char *name, char *mode, fiop->fp = fp; fiop->dev = sbufp->st_dev; fiop->inode = sbufp->st_ino; - fiop->reading = FALSE; - fiop->writing = FALSE; - fiop->appending = FALSE; - fiop->binary = FALSE; + fiop->reading = false; + fiop->writing = false; + fiop->appending = false; + fiop->binary = false; fiop->action = 0; memset(fiop->mode, 0, sizeof(fiop->mode)); @@ -264,7 +264,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note read mode */ strlcpy(modestr, "r", sizeof(modestr)); - fiop->reading = TRUE; + fiop->reading = true; /* note binary mode even though mode is not used / ignored */ if (strchr(mode, 'b') != NULL) { @@ -273,7 +273,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note if reading and writing */ if (strchr(mode, '+') != NULL) { - fiop->writing = TRUE; + fiop->writing = true; strlcat(modestr, "+", sizeof(modestr)); } @@ -282,7 +282,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note write mode */ strlcpy(modestr, "w", sizeof(modestr)); - fiop->writing = TRUE; + fiop->writing = true; /* note binary mode even though mode is not used / ignored */ if (strchr(mode, 'b') != NULL) { @@ -291,7 +291,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note if reading and writing */ if (strchr(mode, '+') != NULL) { - fiop->reading = TRUE; + fiop->reading = true; strlcat(modestr, "+", sizeof(modestr)); } @@ -300,8 +300,8 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note append mode */ strlcpy(modestr, "a", sizeof(modestr)); - fiop->writing = TRUE; - fiop->appending = TRUE; + fiop->writing = true; + fiop->appending = true; /* note binary mode even though mode is not used / ignored */ if (strchr(mode, 'b') != NULL) { @@ -310,7 +310,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode, /* note if reading and writing */ if (strchr(mode, '+') != NULL) { - fiop->reading = TRUE; + fiop->reading = true; strlcat(modestr, "+", sizeof(modestr)); } @@ -591,7 +591,7 @@ findid(FILEID id, int writable) /* * Return whether or not a file id is valid. This is used for if tests. */ -BOOL +bool validid(FILEID id) { return (findid(id, -1) != NULL); @@ -616,7 +616,7 @@ indexid(long index) /* - * Close the specified file id. Returns TRUE if there was an error. + * Close the specified file id. Returns true if there was an error. * Closing of stdin, stdout, or stderr is illegal, but closing of already * closed files is allowed. */ @@ -685,7 +685,7 @@ closeall(void) /* * Return whether or not an error occurred to a file. */ -BOOL +bool errorid(FILEID id) { FILEIO *fiop; /* file structure */ @@ -700,7 +700,7 @@ errorid(FILEID id) /* * Return whether or not end of file occurred to a file. */ -BOOL +bool eofid(FILEID id) { FILEIO *fiop; /* file structure */ @@ -777,14 +777,14 @@ readid(FILEID id, int flags, STRING **retstr) char buf[READSIZE]; /* temporary buffer */ char *b; int c; - BOOL nlstop, nullstop, wsstop, rmstop, done; + bool nlstop, nullstop, wsstop, rmstop, done; FILEPOS fpos; STRING *newstr; totlen = 0; str = NULL; - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return 1; nlstop = (flags & 1); @@ -868,7 +868,7 @@ getcharid(FILEID id) FILEIO *fiop; FILEPOS fpos; - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return -2; if (fiop->action == 'w') { @@ -973,12 +973,12 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) int oldmode, newmode; long olddigits, newdigits; long width, precision; - BOOL didneg, didprecision; + bool didneg, didprecision; FILEPOS fpos; - BOOL printstring; - BOOL printchar; + bool printstring; + bool printchar; - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return 1; if (fiop->action == 'r') { @@ -989,8 +989,8 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) fiop->action = 'w'; - printstring = FALSE; - printchar = FALSE; + printstring = false; + printchar = false; math_setfp(fiop->fp); @@ -1003,14 +1003,14 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) /* * Here to handle formats. */ - didneg = FALSE; - didprecision = FALSE; + didneg = false; + didprecision = false; width = 0; precision = 0; ch = *fmt++; if (ch == '-') { - didneg = TRUE; + didneg = true; ch = *fmt++; } while ((ch >= '0') && (ch <= '9')) { @@ -1018,7 +1018,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) ch = *fmt++; } if (ch == '.') { - didprecision = TRUE; + didprecision = true; ch = *fmt++; while ((ch >= '0') && (ch <= '9')) { precision = precision * 10 + (ch - '0'); @@ -1037,10 +1037,10 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) switch (ch) { case 's': - printstring = TRUE; + printstring = true; /*FALLTHRU*/ case 'c': - printchar = TRUE; + printchar = true; case 'd': break; case 'f': @@ -1212,7 +1212,7 @@ idfputc(FILEID id, int ch) FILEPOS fpos; /* get the file info pointer */ - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return 1; if (fiop->action == 'r') { @@ -1247,7 +1247,7 @@ idungetc(FILEID id, int ch) { FILEIO *fiop; - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return -2; if (fiop->action != 'r') @@ -1273,7 +1273,7 @@ idfputs(FILEID id, STRING *str) long len; /* get the file info pointer */ - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return 1; @@ -1310,7 +1310,7 @@ idfputstr(FILEID id, char *str) FILEPOS fpos; /* get the file info pointer */ - fiop = findid(id, TRUE); + fiop = findid(id, true); if (fiop == NULL) return 1; @@ -1992,7 +1992,7 @@ zfilesize(FILEID id) void showfiles(void) { - BOOL listed[MAXFILES]; + bool listed[MAXFILES]; FILEIO *fiop; FILE *fp; struct stat sbuf; @@ -2001,7 +2001,7 @@ showfiles(void) int i, j; for (i = 0; i < idnum; i++) { - listed[i] = FALSE; + listed[i] = false; fiop = &files[ioindex[i]]; fp = fiop->fp; if (fstat(fileno(fp), &sbuf) < 0) { @@ -2027,7 +2027,7 @@ showfiles(void) if (listed[j] || sizes[j] == -1) continue; if (inodes[j] == inodes[i]) { - listed[j] = TRUE; + listed[j] = true; fiop = &files[ioindex[j]]; printf("\t = "); printid(fiop->id, PRINT_UNAMBIG); @@ -2052,7 +2052,7 @@ showfiles(void) * strptr pointer to where the new field pointer may be found */ S_FUNC void -getscanfield(FILE *fp, BOOL skip, unsigned int width, int scannum, +getscanfield(FILE *fp, bool skip, unsigned int width, int scannum, char *scanptr, char **strptr) { char *str; /* current string */ @@ -2061,7 +2061,7 @@ getscanfield(FILE *fp, BOOL skip, unsigned int width, int scannum, char buf[READSIZE]; /* temporary buffer */ int c; char *b; - BOOL comp; /* Use complement of scanset */ + bool comp; /* Use complement of scanset */ unsigned int chnum; totlen = 0; @@ -2131,7 +2131,7 @@ getscanfield(FILE *fp, BOOL skip, unsigned int width, int scannum, * strptr pointer to where the new field pointer may be found */ S_FUNC void -getscanwhite(FILE *fp, BOOL skip, unsigned int width, int scannum, +getscanwhite(FILE *fp, bool skip, unsigned int width, int scannum, char **strptr) { char *str; /* current string */ @@ -2140,7 +2140,7 @@ getscanwhite(FILE *fp, BOOL skip, unsigned int width, int scannum, char buf[READSIZE]; /* temporary buffer */ int c; char *b; - BOOL comp; /* Use complement of scanset */ + bool comp; /* Use complement of scanset */ unsigned int chnum; totlen = 0; @@ -2207,8 +2207,8 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals) int scannum; /* Number of characters in scanlist */ char *scanptr; /* Start of scanlist */ char *str; - BOOL comp; /* True scanset is complementary */ - BOOL skip; /* True if string to be skipped rather than read */ + bool comp; /* True scanset is complementary */ + bool skip; /* True if string to be skipped rather than read */ int width; VALUE *var; /* lvalue to be assigned to */ unsigned short subtype; /* for var->v_subtype */ @@ -2347,7 +2347,7 @@ fscanfid(FILEID id, char *fmt, int count, VALUE **vals) FILE *fp; FILEPOS fpos; - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return -2; @@ -2404,20 +2404,20 @@ freadnum(FILE *fp, VALUE *valptr) HALF *a; FULL f; long decimals, exp; - BOOL sign, negexp, havedp, imag, exptoobig; + bool sign, negexp, havedp, imag, exptoobig; decimals = 0; exp = 0; - sign = FALSE; - negexp = FALSE; - havedp = FALSE; - imag = FALSE; - exptoobig = FALSE; + sign = false; + negexp = false; + havedp = false; + imag = false; + exptoobig = false; ch = fgetc(fp); if (ch == '+' || ch == '-') { if (ch == '-') - sign = TRUE; + sign = true; ch = fgetc(fp); } num.v = alloc(1); @@ -2446,7 +2446,7 @@ freadnum(FILE *fp, VALUE *valptr) decimals++; } else if (ch == '.') - havedp = TRUE; + havedp = true; else break; ch = fgetc(fp); @@ -2455,20 +2455,20 @@ freadnum(FILE *fp, VALUE *valptr) ch = fgetc(fp); if (ch == '+' || ch == '-') { if (ch == '-') - negexp = TRUE; + negexp = true; ch = fgetc(fp); } while (ch >= '0' && ch <= '9') { if (!exptoobig) { exp = (exp * 10) + ch - '0'; if (exp > 1000000) - exptoobig = TRUE; + exptoobig = true; } ch = fgetc(fp); } } if (ch == 'i' || ch == 'I') { - imag = TRUE; + imag = true; } else { ungetc(ch, fp); } @@ -2648,7 +2648,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res) long k = 0; /* get FILEIO */ - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return -2; @@ -2767,7 +2767,7 @@ frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res) char *s; /* str comparison pointer */ /* get FILEIO */ - fiop = findid(id, FALSE); + fiop = findid(id, false); if (fiop == NULL) return -2; diff --git a/file.h b/file.h index 38a20c9..d03d1fa 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* * file - file I/O routines callable by users * - * Copyright (C) 1999-2007,2014,2021 David I. Bell and Landon Curt Noll + * Copyright (C) 1999-2007,2014,2021,2023 David I. Bell and Landon Curt Noll * * Primary author: David I. Bell * @@ -48,10 +48,10 @@ typedef struct { dev_t dev; /* file device */ ino_t inode; /* file inode */ char *name; /* file name */ - BOOL reading; /* TRUE if opened for reading */ - BOOL writing; /* TRUE if opened for writing */ - BOOL appending; /* TRUE if also opened for appending */ - BOOL binary; /* TRUE if binary mode - mode ignored/unused */ + bool reading; /* true if opened for reading */ + bool writing; /* true if opened for writing */ + bool appending; /* true if also opened for appending */ + bool binary; /* true if binary mode - mode ignored/unused */ char action; /* most recent use for 'r', 'w' or 0 */ char mode[MODE_LEN+1]; /* open mode */ } FILEIO; diff --git a/func.c b/func.c index 5a3aac3..0ad4afd 100644 --- a/func.c +++ b/func.c @@ -256,7 +256,7 @@ f_eval(VALUE *vp) enterfilescope(); temp_stoponerror = stoponerror; stoponerror = -1; - if (evaluate(TRUE)) { + if (evaluate(true)) { stoponerror = temp_stoponerror; closeinput(); exitfilescope(); @@ -1219,7 +1219,7 @@ f_srandom(int count, VALUE **vals) "srandom number seed must be an integer"); not_reached(); } - result.v_random = zsrandom1(vals[0]->v_num->num, TRUE); + result.v_random = zsrandom1(vals[0]->v_num->num, true); break; case V_RANDOM: /* srandom(state) */ @@ -1303,7 +1303,7 @@ f_primetest(int count, NUMBER **vals) S_FUNC VALUE f_setbit(int count, VALUE **vals) { - BOOL r; + bool r; long index; VALUE result; @@ -3793,7 +3793,7 @@ f_arg(int count, VALUE **vals) S_FUNC NUMBER * f_legtoleg(NUMBER *val1, NUMBER *val2) { - return qlegtoleg(val1, val2, FALSE); + return qlegtoleg(val1, val2, false); } @@ -3932,7 +3932,7 @@ f_quomod(int count, VALUE **vals) VALUE *v1, *v2, *v3, *v4, *v5; VALUE result; long rnd; - BOOL res; + bool res; short s3, s4; /* to preserve subtypes of v3, v4 */ v1 = vals[0]; @@ -6177,7 +6177,7 @@ f_protect(int count, VALUE **vals) VALUE *v1, *v2, *v3; VALUE result; - BOOL have_nblock; + bool have_nblock; /* initialize VALUE */ result.v_type = V_NULL; @@ -7306,7 +7306,7 @@ S_FUNC VALUE f_rm(int count, VALUE **vals) { VALUE result; - int force; /* TRUE -> -f was given as 1st arg */ + int force; /* true -> -f was given as 1st arg */ int i; int j; @@ -10165,6 +10165,10 @@ STATIC CONST struct builtin builtins[] = { "hypotenuse of right triangle within accuracy c"}, {"ilog", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, "integral log of a to integral base b"}, +#if 0 /* XXX - to be added later */ + {"ilogn", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, + "same is ilog"}, +#endif /* XXX */ {"ilog10", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog10}, "integral log of a number base 10"}, {"ilog2", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog2}, diff --git a/func.h b/func.h index 1fdfaf9..7de4365 100644 --- a/func.h +++ b/func.h @@ -76,12 +76,12 @@ E_FUNC FUNC *curfunc; /* NOTE: This is a function pointer, we need E_FUNC */ */ E_FUNC FUNC *findfunc(long index); E_FUNC char *namefunc(long index); -E_FUNC BOOL evaluate(BOOL nestflag); +E_FUNC bool evaluate(bool nestflag); E_FUNC long adduserfunc(char *name); E_FUNC void rmuserfunc(char *name); E_FUNC void rmalluserfunc(void); E_FUNC long getuserfunc(char *name); -E_FUNC void beginfunc(char *name, BOOL newflag); +E_FUNC void beginfunc(char *name, bool newflag); E_FUNC int builtinopcode(long index); E_FUNC char *builtinname(long index); E_FUNC int dumpop(unsigned long *pc); diff --git a/hash.c b/hash.c index 4969367..343a44b 100644 --- a/hash.c +++ b/hash.c @@ -1,7 +1,7 @@ /* * hash - one-way hash routines * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2021-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 @@ -53,7 +53,7 @@ E_FUNC void MD5_init_state(HASH*); /* - * hash_long can deal with BOOL's, int's, FLAGS's and LEN's + * hash_long can deal with bool's, int's, FLAGS's and LEN's */ #define hash_bool(type, val, state) (hash_long((type), (long)(val), (state))) #define hash_int(type, val, state) (hash_long((type), (long)(val), (state))) @@ -103,7 +103,7 @@ hash_init(int type, HASH *state) * clear hash value */ memset((void*)state, 0, sizeof(HASH)); - state->bytes = TRUE; + state->bytes = true; /* * search for the hash_setup function @@ -194,8 +194,8 @@ hash_copy(HASH *state) * b second hash state * * returns: - * TRUE => hash states are different - * FALSE => hash states are the same + * true => hash states are different + * false => hash states are the same */ int hash_cmp(HASH *a, HASH *b) @@ -205,15 +205,15 @@ hash_cmp(HASH *a, HASH *b) */ if (a == b) { /* pointers to the same object */ - return FALSE; + return false; } if (a == NULL || b == NULL) { /* one pointer is NULL, so they differ */ - return TRUE; + return true; } if (a->cmp == NULL || b->cmp == NULL) { /* one cmp function is NULL, so they differ */ - return TRUE; + return true; } /* @@ -221,7 +221,7 @@ hash_cmp(HASH *a, HASH *b) */ if (a->hashtype != b->hashtype) { /* different hash types are different */ - return TRUE; + return true; } /* @@ -278,7 +278,7 @@ hash_final(HASH *state) * The input is a long. If a long is smaller than 64 bits, we will * hash a final 32 bits of zeros. * - * This function is OK to hash BOOL's, unsigned long's, unsigned int's + * This function is OK to hash bool's, unsigned long's, unsigned int's * signed int's as well as FLAG's and LEN's. */ HASH * @@ -297,7 +297,7 @@ hash_long(int type, long longval, HASH *state) * setup for the hash_long */ (state->chkpt)(state); - state->bytes = FALSE; /* data to be read as words */ + state->bytes = false; /* data to be read as words */ /* * catch the zero numeric value special case @@ -363,7 +363,7 @@ hash_zvalue(int type, ZVALUE zval, HASH *state) * setup for the ZVALUE hash */ (state->chkpt)(state); - state->bytes = FALSE; /* data to be read as words */ + state->bytes = false; /* data to be read as words */ /* * catch the zero numeric value special case @@ -470,7 +470,7 @@ HASH * hash_number(int type, void *n, HASH *state) { NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */ - BOOL sign; /* sign of the denominator */ + bool sign; /* sign of the denominator */ /* * initialize if state is NULL @@ -483,7 +483,7 @@ hash_number(int type, void *n, HASH *state) * setup for the NUMBER hash */ (state->chkpt)(state); - state->bytes = FALSE; + state->bytes = false; /* * process the numerator @@ -543,7 +543,7 @@ hash_complex(int type, void *c, HASH *state) * setup for the COMPLEX hash */ (state->chkpt)(state); - state->bytes = FALSE; + state->bytes = false; /* * catch the zero special case @@ -612,7 +612,7 @@ hash_str(int type, char *str, HASH *state) */ if (!state->bytes) { (state->chkpt)(state); - state->bytes = TRUE; + state->bytes = true; } len = strlen(str); @@ -655,7 +655,7 @@ hash_STR(int type, STRING *str, HASH *state) */ if (!state->bytes) { (state->chkpt)(state); - state->bytes = TRUE; + state->bytes = true; } /* @@ -697,7 +697,7 @@ hash_usb8(int type, USB8 *byte, int len, HASH *state) */ if (!state->bytes) { (state->chkpt)(state); - state->bytes = TRUE; + state->bytes = true; } /* @@ -748,7 +748,7 @@ hash_value(int type, void *v, HASH *state) switch (value->v_type) { case V_NULL: (state->chkpt)(state); - state->bytes = TRUE; + state->bytes = true; break; case V_INT: @@ -790,7 +790,7 @@ hash_value(int type, void *v, HASH *state) /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); - state->bytes = TRUE; + state->bytes = true; /* hash all the elements of the matrix */ for (i=0; i < value->v_mat->m_size; ++i) { @@ -798,7 +798,7 @@ hash_value(int type, void *v, HASH *state) /* hash the next matrix value */ state = hash_value(type, value->v_mat->m_table+i, state); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ } break; @@ -814,7 +814,7 @@ hash_value(int type, void *v, HASH *state) /* hash the next list value */ state = hash_value(type, &ep->e_value, state); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ } break; @@ -822,7 +822,7 @@ hash_value(int type, void *v, HASH *state) /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); - state->bytes = TRUE; + state->bytes = true; /* hash the association */ assochead = value->v_assoc->a_table; @@ -834,7 +834,7 @@ hash_value(int type, void *v, HASH *state) /* hash the next association value */ state = hash_value(type, &aep->e_value, state); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ } assochead++; } @@ -844,7 +844,7 @@ hash_value(int type, void *v, HASH *state) /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); - state->bytes = TRUE; /* reading bytes */ + state->bytes = true; /* reading bytes */ /* hash the object name and then the element values */ @@ -859,7 +859,7 @@ hash_value(int type, void *v, HASH *state) /* hash the next object value */ state = hash_value(type, vp, state); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ } break; @@ -919,7 +919,7 @@ hash_value(int type, void *v, HASH *state) (USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8); (state->update)(state, (USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ break; case V_RANDOM: @@ -934,7 +934,7 @@ hash_value(int type, void *v, HASH *state) (USB8 *)&(value->v_random->buffer), BASEB/8); state = hash_zvalue(type, value->v_random->r, state); state = hash_zvalue(type, value->v_random->n, state); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ break; case V_CONFIG: @@ -972,9 +972,9 @@ hash_value(int type, void *v, HASH *state) state = hash_long(type, (long)value->v_config->maxscancount, state); state = hash_str(type, value->v_config->prompt1, state); - state->bytes = FALSE; /* as if just read words */ + state->bytes = false; /* as if just read words */ state = hash_str(type, value->v_config->prompt2, state); - state->bytes = FALSE; /* as if just read words */ + state->bytes = false; /* as if just read words */ state = hash_int(type, value->v_config->blkmaxprint, state); state = hash_bool(type, value->v_config->blkverbose, state); state = hash_int(type, value->v_config->blkbase, state); @@ -994,9 +994,9 @@ hash_value(int type, void *v, HASH *state) state = hash_bool(type, value->v_config->compile_custom, state); if (value->v_config->allow_custom != NULL && *(value->v_config->allow_custom)) { - state = hash_bool(type, TRUE, state); + state = hash_bool(type, true, state); } else { - state = hash_bool(type, FALSE, state); + state = hash_bool(type, false, state); } state = hash_str(type, value->v_config->version, state); state = hash_int(type, value->v_config->baseb, state); @@ -1018,7 +1018,7 @@ hash_value(int type, void *v, HASH *state) state = hash_int(type, value->v_hash->unionsize, state); (state->update)(state, value->v_hash->h_union.data, state->unionsize); - state->bytes = FALSE; /* as if reading words */ + state->bytes = false; /* as if reading words */ break; case V_BLOCK: diff --git a/hash.h b/hash.h index 899d482..ec0b16a 100644 --- a/hash.h +++ b/hash.h @@ -1,7 +1,7 @@ /* * hash - one-way hash routines * - * Copyright (C) 1999-2007,2014 Landon Curt Noll + * Copyright (C) 1999-2007,2014,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 @@ -60,13 +60,13 @@ typedef struct hashstate HASH; struct hashstate { int hashtype; /* XYZ_HASH_TYPE debug value */ - BOOL bytes; /* TRUE => reading bytes rather than words */ + bool bytes; /* true => reading bytes rather than words */ void (*update)(HASH*, USB8*, USB32); /* update arbitrary length */ void (*chkpt)(HASH*); /* checkpoint a state */ void (*note)(int, HASH*); /* note a special value */ void (*type)(int, HASH*); /* note a VALUE type */ ZVALUE (*final)(HASH*); /* complete hash state */ - int (*cmp)(HASH*,HASH*); /* compare to states, TRUE => a!=b */ + int (*cmp)(HASH*,HASH*); /* compare to states, true => a!=b */ void (*print)(HASH*); /* print the value of a hash */ int base; /* XYZ_BASE special hash value */ int chunksize; /* XYZ_CHUNKSIZE input chunk size */ diff --git a/hist.c b/hist.c index 457c424..19d32ee 100644 --- a/hist.c +++ b/hist.c @@ -1,7 +1,7 @@ /* * hist - interactive readline module * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -94,7 +94,7 @@ STATIC struct { int linelen; int histcount; /* valid history entries */ int curhist; - BOOL virgin_line; /* 1 => never typed chars, 0 => chars typed */ + bool virgin_line; /* 1 => never typed chars, 0 => chars typed */ } HS; @@ -277,7 +277,7 @@ hist_getline(char *prompt, char *buf, size_t len) HS.end = buf; HS.mark = NULL; HS.linelen = -1; - HS.virgin_line = TRUE; + HS.virgin_line = true; /* * prep the I/O @@ -303,7 +303,7 @@ hist_getline(char *prompt, char *buf, size_t len) read_key(); /* chars typed, no longer virgin */ - HS.virgin_line = FALSE; + HS.virgin_line = false; } /* @@ -348,7 +348,7 @@ hist_init(char *filename) */ if (filename == NULL) filename = HIST_BINDING_FILE; - if (opensearchfile(filename, calcpath, NULL, FALSE) > 0) + if (opensearchfile(filename, calcpath, NULL, false) > 0) return HIST_NOFILE; /* @@ -995,7 +995,7 @@ delete_char(int UNUSED(key)) */ if ((HS.end == HS.buf) && (conf->ctrl_d == CTRL_D_EMPTY_EOF || - (conf->ctrl_d == CTRL_D_VIRGIN_EOF && HS.virgin_line == TRUE))) { + (conf->ctrl_d == CTRL_D_VIRGIN_EOF && HS.virgin_line == true))) { quit_calc(0); } diff --git a/lib_calc.c b/lib_calc.c index 32ef0bb..3b31647 100644 --- a/lib_calc.c +++ b/lib_calc.c @@ -1,7 +1,7 @@ /* * lib_calc - calc link library initialization and shutdown routines * - * Copyright (C) 1999-2007,2018,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2018,2021-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 @@ -113,9 +113,9 @@ E_FUNC uid_t geteuid(); /* * Common definitions */ -int use_old_std = FALSE; /* TRUE => use old classic configuration */ +int use_old_std = false; /* true => use old classic configuration */ int abortlevel; /* current level of aborts */ -BOOL inputwait; /* TRUE if in a terminal input wait */ +bool inputwait; /* true if in a terminal input wait */ char *program = "calc"; /* our name */ char *base_name = "calc"; /* basename of our name */ char cmdbuf[MAXCMD+1+1+1]; /* command line expression + "\n\0" + guard */ @@ -126,21 +126,21 @@ char *script_name = NULL; /* program name or -f filename arg or NULL */ /* * global permissions */ -int allow_read = TRUE; /* FALSE => may not open any files for reading */ -int allow_write = TRUE; /* FALSE => may not open any files for writing */ -int allow_exec = TRUE; /* FALSE => may not execute any commands */ +int allow_read = true; /* false => may not open any files for reading */ +int allow_write = true; /* false => may not open any files for writing */ +int allow_exec = true; /* false => may not execute any commands */ /* * global flags */ -int p_flag = FALSE; /* TRUE => pipe mode */ -int q_flag = FALSE; /* TRUE => don't execute rc files */ -int u_flag = FALSE; /* TRUE => unbuffer stdin and stdout */ -int d_flag = FALSE; /* TRUE => disable heading, resource_debug == 0 */ -int c_flag = FALSE; /* TRUE => continue on error if permitted */ -int i_flag = FALSE; /* TRUE => go interactive if permitted */ -int s_flag = FALSE; /* TRUE => keep args as strings for argv() */ +int p_flag = false; /* true => pipe mode */ +int q_flag = false; /* true => don't execute rc files */ +int u_flag = false; /* true => unbuffer stdin and stdout */ +int d_flag = false; /* true => disable heading, resource_debug == 0 */ +int c_flag = false; /* true => continue on error if permitted */ +int i_flag = false; /* true => go interactive if permitted */ +int s_flag = false; /* true => keep args as strings for argv() */ /* @@ -156,10 +156,10 @@ char *calc_history = NULL; /* $CALCHISTFILE or ~/.calc_history */ char *calc_helpdir = NULL; /* $CALCHELP or /usr/local/share/calc/help */ /* $CALCCUSTOMHELP or /usr/local/share/calc/custhelp */ char *calc_customhelpdir = NULL; -int stdin_tty = FALSE; /* TRUE if stdin is a tty */ -int havecommands = FALSE; /* TRUE if have one or more cmd args */ +int stdin_tty = false; /* true if stdin is a tty */ +int havecommands = false; /* true if have one or more cmd args */ long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */ -BOOL abort_now = FALSE; /* TRUE => go interactive now, if permitted */ +bool abort_now = false; /* true => go interactive now, if permitted */ /* non-zero => calc_scanerr_jmpbuf ready */ int calc_use_scanerr_jmpbuf = 0; @@ -186,7 +186,7 @@ unsigned long calc_warn_cnt = 0; int argc_value = 0; /* count of argv[] strings for argv() builtin */ char **argv_value = NULL; /* argv[] strings for argv() builtin */ -int no_env = FALSE; /* TRUE (-e) => ignore env vars on startup */ +int no_env = false; /* true (-e) => ignore env vars on startup */ long errmax = ERRMAX; /* if >= 0, maximum value for errcount */ NUMBER *epsilon_default; /* default allowed error for float calcs */ @@ -216,7 +216,7 @@ STATIC ttystruct *fd_orig = NULL; /* fd original state */ STATIC ttystruct *fd_cur = NULL; /* fd current state */ S_FUNC void initenv(void); /* setup calc environment */ S_FUNC int find_tty_state(int fd); /* find slot for saved tty state */ -STATIC BOOL initialized = FALSE; /* TRUE => initialize() has been run */ +STATIC bool initialized = false; /* true => initialize() has been run */ /* @@ -301,7 +301,7 @@ libcalc_call_me_first(void) exit(85); } conf = config_copy(&newstd); /* more magic to fake early str2q() */ - conf->tab_ok = FALSE; + conf->tab_ok = false; newstd.epsilon = str2q(EPSILON_DEFAULT); oldstd.epsilon = str2q(EPSILON_DEFAULT); @@ -425,7 +425,7 @@ initialize(void) /* * note that we are done */ - initialized = TRUE; + initialized = true; } @@ -439,8 +439,8 @@ reinitialize(void) * process commands (from stdin, not the command line) */ abortlevel = 0; - _math_abort_ = FALSE; - inputwait = FALSE; + _math_abort_ = false; + inputwait = false; math_cleardiversions(); math_setfp(stdout); resetscopes(); @@ -840,10 +840,10 @@ find_tty_state(int fd) * fd the descriptor for calc's interactive use * * Returns: - * TRUE state change was successful - * FALSE unable to change state of descriptor for interactive use + * true state change was successful + * false unable to change state of descriptor for interactive use */ -BOOL +bool calc_tty(int fd) { int slot; /* the saved descriptor slot or -1 */ @@ -855,7 +855,7 @@ calc_tty(int fd) if (slot < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot get saved descriptor slot\n"); - return FALSE; + return false; } #if defined(USE_SGTTY) @@ -867,7 +867,7 @@ calc_tty(int fd) if (fd_setup[slot] < 0 && ioctl(fd, TIOCGETP, fd_orig+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot TIOCGETP fd %d\n", fd); - return FALSE; + return false; } /* setup for new state */ fd_cur[slot] = fd_orig[slot]; @@ -877,7 +877,7 @@ calc_tty(int fd) if (ioctl(fd, TIOCSETP, fd_cur+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot TIOCSETP fd %d\n", fd); - return FALSE; + return false; } if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: stty -ECHO +CBREAK: fd %d\n", fd); @@ -890,7 +890,7 @@ calc_tty(int fd) if (fd_setup[slot] < 0 && ioctl(fd, TCGETA, fd_orig+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot TCGETA fd %d\n", fd); - return FALSE; + return false; } /* setup for new state */ fd_cur[slot] = fd_orig[slot]; @@ -903,7 +903,7 @@ calc_tty(int fd) if (ioctl(fd, TCSETAW, fd_cur+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot TCSETAW fd %d\n", fd); - return FALSE; + return false; } if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " @@ -917,7 +917,7 @@ calc_tty(int fd) if (fd_setup[slot] < 0 && tcgetattr(fd, fd_orig+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot tcgetattr fd %d\n", fd); - return FALSE; + return false; } /* setup for new state */ fd_cur[slot] = fd_orig[slot]; @@ -930,7 +930,7 @@ calc_tty(int fd) if (tcsetattr(fd, TCSANOW, fd_cur+slot) < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: Cannot tcsetattr fd %d\n", fd); - return FALSE; + return false; } if (conf->calc_debug & CALCDBG_TTY) printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " @@ -945,7 +945,7 @@ calc_tty(int fd) * note that the tty slot is on use */ fd_setup[slot] = fd; - return TRUE; + return true; } @@ -959,10 +959,10 @@ calc_tty(int fd) * fd the descriptor to restore * * Returns: - * TRUE restore was successful - * FALSE unable to restore descriptor to original state + * true restore was successful + * false unable to restore descriptor to original state */ -BOOL +bool orig_tty(int fd) { int slot; /* the saved descriptor slot or -1 */ @@ -974,7 +974,7 @@ orig_tty(int fd) if (slot < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("orig_tty: Cannot get saved descriptor slot\n"); - return FALSE; + return false; } /* @@ -983,7 +983,7 @@ orig_tty(int fd) if (fd_setup[slot] < 0) { if (conf->calc_debug & CALCDBG_TTY) printf("orig_tty: no state saved for fd %d\n", fd); - return FALSE; + return false; } #if defined(USE_SGTTY) @@ -1031,5 +1031,5 @@ orig_tty(int fd) * libcalc_call_me_last() function from re-restoring it. */ fd_setup[slot] = -1; - return TRUE; + return true; } diff --git a/listfunc.c b/listfunc.c index a8e29f9..b2a34f7 100644 --- a/listfunc.c +++ b/listfunc.c @@ -1,7 +1,7 @@ /* * listfunc - list handling routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -392,7 +392,7 @@ listelement(LIST *lp, long index) register LISTELEM *ep; /* current list element */ long dist; /* distance to element */ long temp; /* temporary distance */ - BOOL forward; /* TRUE if need to walk forwards */ + bool forward; /* true if need to walk forwards */ if (index < 0) index += lp->l_count; @@ -430,12 +430,12 @@ listelement(LIST *lp, long index) if ((temp >= 0) && (temp < dist)) { dist = temp; ep = lp->l_cache; - forward = TRUE; + forward = true; } if ((temp < 0) && (-temp < dist)) { dist = -temp; ep = lp->l_cache; - forward = FALSE; + forward = false; } } /* @@ -458,28 +458,28 @@ listelement(LIST *lp, long index) /* * Compare two lists to see if they are identical. - * Returns TRUE if they are different. + * Returns true if they are different. */ -BOOL +bool listcmp(LIST *lp1, LIST *lp2) { LISTELEM *e1, *e2; long count; if (lp1 == lp2) - return FALSE; + return false; if (lp1->l_count != lp2->l_count) - return TRUE; + return true; e1 = lp1->l_first; e2 = lp2->l_first; count = lp1->l_count; while (count-- > 0) { if (comparevalue(&e1->e_value, &e2->e_value)) - return TRUE; + return true; e1 = e1->e_next; e2 = e2->e_next; } - return FALSE; + return false; } diff --git a/longbits.c b/longbits.c index 5ea299d..020d310 100644 --- a/longbits.c +++ b/longbits.c @@ -66,8 +66,8 @@ * undefined ==> do not use USB64 nor SB64 * * BOOL_B64 - * If HAVE_B64 undefined ==> FALSE - * If HAVE_B64 defined ==> TRUE + * If HAVE_B64 undefined ==> false + * If HAVE_B64 defined ==> true * * USB64 unsigned 64 bit value if HAVE_B64 is defined * SB64 signed 64 bit value if HAVE_B64 is defined diff --git a/matfunc.c b/matfunc.c index 056fea4..953df17 100644 --- a/matfunc.c +++ b/matfunc.c @@ -1,7 +1,7 @@ /* * matfunc - extended precision rational arithmetic matrix functions * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -563,7 +563,7 @@ matshift(MATRIX *m, long n) val = m->m_table; vres = res->m_table; for (index = m->m_size; index > 0; index--) - shiftvalue(val++, &temp, FALSE, vres++); + shiftvalue(val++, &temp, false, vres++); qfree(temp.v_num); return res; } @@ -846,18 +846,18 @@ matfrac(MATRIX *m) /* * Index a matrix normally by the specified set of index values. * Returns the address of the matrix element if it is valid, or generates - * an error if the index values are out of range. The create flag is TRUE + * an error if the index values are out of range. The create flag is true * if the element is to be written, but this is ignored here. * * given: * mp matrix to operate on - * create TRUE => create if element does not exist + * create true => create if element does not exist * dim dimension of the indexing * indices table of values being indexed by */ /*ARGSUSED*/ VALUE * -matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices) +matindex(MATRIX *mp, bool UNUSED(create), long dim, VALUE *indices) { NUMBER *q; /* index value */ VALUE *vp; @@ -1218,7 +1218,7 @@ matdet(MATRIX *m) VALUE *pivot, *div, *val; VALUE *vp, *vv; VALUE tmp1, tmp2, tmp3; - BOOL neg; /* whether to negate determinant */ + bool neg; /* whether to negate determinant */ if (m->m_dim < 2) { vp = m->m_table; @@ -1243,7 +1243,7 @@ matdet(MATRIX *m) * corresponding column by using row operations. Copy the original * matrix so that we don't destroy it. */ - neg = FALSE; + neg = false; m = matcopy(m); n = (m->m_max[0] - m->m_min[0] + 1); pivot = div = m->m_table; @@ -1518,9 +1518,9 @@ matfree(MATRIX *m) /* * Test whether a matrix has any "nonzero" values. - * Returns TRUE if so. + * Returns true if so. */ -BOOL +bool mattest(MATRIX *m) { register VALUE *vp; @@ -1530,9 +1530,9 @@ mattest(MATRIX *m) i = m->m_size; while (i-- > 0) { if (testvalue(vp++)) - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -1562,31 +1562,31 @@ matsum(MATRIX *m, VALUE *vres) /* * Test whether or not two matrices are equal. * Equality is determined by the shape and values of the matrices, - * but not by their index bounds. Returns TRUE if they differ. + * but not by their index bounds. Returns true if they differ. */ -BOOL +bool matcmp(MATRIX *m1, MATRIX *m2) { VALUE *v1, *v2; long i; if (m1 == m2) - return FALSE; + return false; if ((m1->m_dim != m2->m_dim) || (m1->m_size != m2->m_size)) - return TRUE; + return true; for (i = 0; i < m1->m_dim; i++) { if ((m1->m_max[i] - m1->m_min[i]) != (m2->m_max[i] - m2->m_min[i])) - return TRUE; + return true; } v1 = m1->m_table; v2 = m2->m_table; i = m1->m_size; while (i-- > 0) { if (comparevalue(v1++, v2++)) - return TRUE; + return true; } - return FALSE; + return false; } @@ -1698,9 +1698,9 @@ matrandperm(MATRIX *m) /* * Test whether or not a matrix is the identity matrix. - * Returns TRUE if so. + * Returns true if so. */ -BOOL +bool matisident(MATRIX *m) { register VALUE *val; /* current value */ @@ -1713,13 +1713,13 @@ matisident(MATRIX *m) if (m->m_dim == 1) { for (row = m->m_min[0]; row <= m->m_max[0]; row++, val++) { if (val->v_type != V_NUM || !qisone(val->v_num)) - return FALSE; + return false; } - return TRUE; + return true; } if ((m->m_dim != 2) || ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1]))) - return FALSE; + return false; for (row = m->m_min[0]; row <= m->m_max[0]; row++) { /* * We could use col = m->m_min[1]; col < m->m_max[1] @@ -1729,18 +1729,18 @@ matisident(MATRIX *m) */ for (col = m->m_min[0]; col <= m->m_max[0]; col++) { if (val->v_type != V_NUM) - return FALSE; + return false; if (row == col) { if (!qisone(val->v_num)) - return FALSE; + return false; } else { if (!qiszero(val->v_num)) - return FALSE; + return false; } val++; } } - return TRUE; + return true; } diff --git a/obj.c b/obj.c index ba4923f..b774083 100644 --- a/obj.c +++ b/obj.c @@ -1,7 +1,7 @@ /* * obj - object handling primitives * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -173,8 +173,8 @@ STATIC OBJECTACTIONS **objects; /* table of actions for objects */ STATIC long maxobjcount = 0; S_FUNC VALUE objpowi(VALUE *vp, NUMBER *q); -S_FUNC BOOL objtest(OBJECT *op); -S_FUNC BOOL objcmp(OBJECT *op1, OBJECT *op2); +S_FUNC bool objtest(OBJECT *op); +S_FUNC bool objcmp(OBJECT *op1, OBJECT *op2); S_FUNC void objprint(OBJECT *op); @@ -402,9 +402,9 @@ objprint(OBJECT *op) /* * Test an object for being "nonzero". * This is the default routine if the user's is not defined. - * Returns TRUE if any of the elements are "nonzero". + * Returns true if any of the elements are "nonzero". */ -S_FUNC BOOL +S_FUNC bool objtest(OBJECT *op) { int i; /* loop counter */ @@ -412,30 +412,30 @@ objtest(OBJECT *op) i = op->o_actions->oa_count; while (--i >= 0) { if (testvalue(&op->o_table[i])) - return TRUE; + return true; } - return FALSE; + return false; } /* - * Compare two objects for equality, returning TRUE if they differ. + * Compare two objects for equality, returning true if they differ. * This is the default routine if the user's is not defined. * For equality, all elements must be equal. */ -S_FUNC BOOL +S_FUNC bool objcmp(OBJECT *op1, OBJECT *op2) { int i; /* loop counter */ if (op1->o_actions != op2->o_actions) - return TRUE; + return true; i = op1->o_actions->oa_count; while (--i >= 0) { if (comparevalue(&op1->o_table[i], &op2->o_table[i])) - return TRUE; + return true; } - return FALSE; + return false; } diff --git a/opcodes.c b/opcodes.c index a9efab5..05601f4 100644 --- a/opcodes.c +++ b/opcodes.c @@ -1,7 +1,7 @@ /* * opcodes - opcode execution module * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -56,17 +56,17 @@ STATIC VALUE stackarray[MAXSTACK]; /* storage for stack */ STATIC VALUE oldvalue; /* previous calculation value */ -STATIC BOOL saveval = TRUE; /* to enable or disable saving */ +STATIC bool saveval = true; /* to enable or disable saving */ STATIC int calc_errno; /* most recent error-number */ STATIC int errcount; /* counts calls to error_value */ -STATIC BOOL go; +STATIC bool go; STATIC long calc_depth; /* * global symbols */ VALUE *stack; /* current location of top of stack */ -int dumpnames; /* names if TRUE, otherwise indices */ +int dumpnames; /* names if true, otherwise indices */ char *funcname; /* function being executed */ long funcline; /* function line being executed */ @@ -102,7 +102,7 @@ typedef union { void (*func_nul)(FUNC *); /* OPNUL */ void (*func_one)(FUNC *, long); /* OPONE */ void (*func_two)(FUNC *, long, long); /* OPTWO */ - void (*func_jmp)(FUNC *, BOOL *); /* OPJMP */ + void (*func_jmp)(FUNC *, bool *); /* OPJMP */ void (*func_ret)(FUNC *); /* OPRET */ void (*func_glb)(FUNC *, GLOBAL *); /* OPGLB */ void (*func_par)(FUNC *, int, VALUE *, long); /* OPPAR */ @@ -552,7 +552,7 @@ S_FUNC void o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag) { int i; - BOOL flag; + bool flag; VALUE *val; VALUE *vp; VALUE indices[MAXDIM]; /* index values */ @@ -1565,7 +1565,7 @@ o_links(FUNC *UNUSED(fp)) { VALUE *vp; long links; - BOOL haveaddress; + bool haveaddress; vp = stack; haveaddress = (vp->v_type == V_ADDR); @@ -2564,7 +2564,7 @@ o_return(FUNC *UNUSED(fp)) S_FUNC void -o_jumpz(FUNC *UNUSED(fp), BOOL *dojump) +o_jumpz(FUNC *UNUSED(fp), bool *dojump) { VALUE *vp; int i; /* result of comparison */ @@ -2582,12 +2582,12 @@ o_jumpz(FUNC *UNUSED(fp), BOOL *dojump) } stack--; if (!i) - *dojump = TRUE; + *dojump = true; } S_FUNC void -o_jumpnz(FUNC *UNUSED(fp), BOOL *dojump) +o_jumpnz(FUNC *UNUSED(fp), bool *dojump) { VALUE *vp; int i; /* result of comparison */ @@ -2605,7 +2605,7 @@ o_jumpnz(FUNC *UNUSED(fp), BOOL *dojump) } stack--; if (i) - *dojump = TRUE; + *dojump = true; } @@ -2613,17 +2613,17 @@ o_jumpnz(FUNC *UNUSED(fp), BOOL *dojump) * jumpnn invokes a jump if top value points to a null value */ S_FUNC void -o_jumpnn(FUNC *UNUSED(fp), BOOL *dojump) +o_jumpnn(FUNC *UNUSED(fp), bool *dojump) { if (stack->v_addr->v_type) { - *dojump = TRUE; + *dojump = true; stack--; } } S_FUNC void -o_condorjump(FUNC *UNUSED(fp), BOOL *dojump) +o_condorjump(FUNC *UNUSED(fp), bool *dojump) { VALUE *vp; @@ -2632,7 +2632,7 @@ o_condorjump(FUNC *UNUSED(fp), BOOL *dojump) vp = vp->v_addr; if (vp->v_type == V_NUM) { if (!qiszero(vp->v_num)) { - *dojump = TRUE; + *dojump = true; return; } if (stack->v_type == V_NUM) @@ -2641,14 +2641,14 @@ o_condorjump(FUNC *UNUSED(fp), BOOL *dojump) return; } if (testvalue(vp)) - *dojump = TRUE; + *dojump = true; else freevalue(stack--); } S_FUNC void -o_condandjump(FUNC *UNUSED(fp), BOOL *dojump) +o_condandjump(FUNC *UNUSED(fp), bool *dojump) { VALUE *vp; @@ -2657,7 +2657,7 @@ o_condandjump(FUNC *UNUSED(fp), BOOL *dojump) vp = vp->v_addr; if (vp->v_type == V_NUM) { if (qiszero(vp->v_num)) { - *dojump = TRUE; + *dojump = true; return; } if (stack->v_type == V_NUM) @@ -2666,7 +2666,7 @@ o_condandjump(FUNC *UNUSED(fp), BOOL *dojump) return; } if (!testvalue(vp)) - *dojump = TRUE; + *dojump = true; else freevalue(stack--); } @@ -2678,7 +2678,7 @@ o_condandjump(FUNC *UNUSED(fp), BOOL *dojump) * If they are equal, pop both values and do not jump. */ S_FUNC void -o_casejump(FUNC *UNUSED(fp), BOOL *dojump) +o_casejump(FUNC *UNUSED(fp), bool *dojump) { VALUE *v1, *v2; int r; @@ -2692,16 +2692,16 @@ o_casejump(FUNC *UNUSED(fp), BOOL *dojump) r = comparevalue(v1, v2); freevalue(stack--); if (r) - *dojump = TRUE; + *dojump = true; else freevalue(stack--); } S_FUNC void -o_jump(FUNC *UNUSED(fp), BOOL *dojump) +o_jump(FUNC *UNUSED(fp), bool *dojump) { - *dojump = TRUE; + *dojump = true; } @@ -3072,7 +3072,7 @@ o_leftshift(FUNC *UNUSED(fp)) v1 = v1->v_addr; if (v2->v_type == V_ADDR) v2 = v2->v_addr; - shiftvalue(v1, v2, FALSE, &tmp); + shiftvalue(v1, v2, false, &tmp); freevalue(stack--); freevalue(stack); *stack = tmp; @@ -3091,7 +3091,7 @@ o_rightshift(FUNC *UNUSED(fp)) v1 = v1->v_addr; if (v2->v_type == V_ADDR) v2 = v2->v_addr; - shiftvalue(v1, v2, TRUE, &tmp); + shiftvalue(v1, v2, true, &tmp); freevalue(stack--); freevalue(stack); *stack = tmp; @@ -3278,14 +3278,14 @@ o_quit(FUNC *fp, long index) printf("quit or abort executed\n"); if (!inputisterminal() && !strcmp(fp->f_name, "*")) closeinput(); - go = FALSE; + go = false; } S_FUNC void o_abort(FUNC *fp, long index) { - abort_now = TRUE; + abort_now = true; o_quit(fp, index); } @@ -3504,7 +3504,7 @@ o_show(FUNC *fp, long arg) printf("Function not defined\n"); return; } - dumpnames = FALSE; + dumpnames = false; for (size = 0; size < fp->f_opcodecount; ) { printf("%ld: ", (long)size); size += dumpop(&fp->f_opcodes[size]); @@ -4097,7 +4097,7 @@ calculate(FUNC *fp, int argcount) unsigned int opnum; /* current opcode number */ int origargcount; /* original number of arguments */ unsigned int i; /* loop counter */ - BOOL dojump; /* TRUE if jump is to occur */ + bool dojump; /* true if jump is to occur */ char *oldname; /* old function name being executed */ VALUE *beginstack; /* beginning of stack frame */ VALUE *args; /* pointer to function arguments */ @@ -4108,7 +4108,7 @@ calculate(FUNC *fp, int argcount) oldline = funcline; funcname = fp->f_name; funcline = 0; - go = TRUE; + go = true; ++calc_depth; origargcount = argcount; while ((unsigned)argcount < fp->f_paramcount) { @@ -4153,7 +4153,7 @@ calculate(FUNC *fp, int argcount) } op = &opcodes[opnum]; if (conf->traceflags & TRACE_OPCODES) { - dumpnames = FALSE; + dumpnames = false; printf("%8s, pc %4ld: ", fp->f_name, pc); (void)dumpop(&fp->f_opcodes[pc]); } @@ -4177,7 +4177,7 @@ calculate(FUNC *fp, int argcount) break; case OPJMP: /* jump opcodes (one extra pointer arg) */ - dojump = FALSE; + dojump = false; (*op->o_func.func_jmp)(fp, &dojump); if (dojump) pc = fp->f_opcodes[pc]; diff --git a/poly.c b/poly.c index 5945f36..94abd9c 100644 --- a/poly.c +++ b/poly.c @@ -1,7 +1,7 @@ /* * poly - polynomial functions * - * Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll + * Copyright (C) 1999,2021,2023 Ernest Bowen and Landon Curt Noll * * Primary author: Ernest Bowen * @@ -33,13 +33,13 @@ #include "banned.h" /* include after system header <> includes */ -BOOL +bool evp(LISTELEM *cp, LISTELEM *x, VALUE *vres) { VALUE v, tmp1, tmp2; - BOOL s; + bool s; - s = FALSE; + s = false; while (cp) { if (s) { mulvalue(vres, &x->e_value, &tmp1); @@ -55,7 +55,7 @@ evp(LISTELEM *cp, LISTELEM *x, VALUE *vres) freevalue(vres); *vres = tmp2; } else { - s = TRUE; + s = true; *vres = tmp1; } } @@ -65,7 +65,7 @@ evp(LISTELEM *cp, LISTELEM *x, VALUE *vres) freevalue(vres); *vres = tmp1; } else { - s = TRUE; + s = true; copyvalue(&v, vres); } } @@ -75,7 +75,7 @@ evp(LISTELEM *cp, LISTELEM *x, VALUE *vres) } -BOOL +bool evalpoly(LIST *clist, LISTELEM *x, VALUE *vres) { LISTELEM *cp; @@ -83,13 +83,13 @@ evalpoly(LIST *clist, LISTELEM *x, VALUE *vres) cp = clist->l_first; if (cp == NULL) - return FALSE; + return false; if (x == NULL) { v = cp->e_value; if (v.v_type == V_LIST) return evalpoly(v.v_list, x->e_next, vres); copyvalue(&v, vres); - return TRUE; + return true; } return evp(clist->l_last, x, vres); } diff --git a/qfunc.c b/qfunc.c index 79d0ca9..70324ed 100644 --- a/qfunc.c +++ b/qfunc.c @@ -1,7 +1,7 @@ /* * qfunc - extended precision rational arithmetic non-primitive functions * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -112,7 +112,7 @@ qminv(NUMBER *q1, NUMBER *q2) r = qalloc(); if (s) { zfree(z1); - z2.sign = TRUE; + z2.sign = true; r->num = z2; return r; } @@ -168,7 +168,7 @@ qpowermod(NUMBER *q1, NUMBER *q2, NUMBER *q3) r = qalloc(); if (s) { zfree(z1); - z2.sign = TRUE; + z2.sign = true; r->num = z2; return r; } @@ -187,7 +187,7 @@ NUMBER * qpowi(NUMBER *q1, NUMBER *q2) { register NUMBER *r; - BOOL invert, sign; + bool invert, sign; ZVALUE num, zden, z2; if (qisfrac(q2)) { @@ -275,7 +275,7 @@ qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) * If the wantneg flag is nonzero, then negative square root is returned. */ NUMBER * -qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg) +qlegtoleg(NUMBER *q, NUMBER *epsilon, bool wantneg) { NUMBER *res, *qtmp1, *qtmp2; ZVALUE num; @@ -454,10 +454,10 @@ qisqrt(NUMBER *q) /* * Return whether or not a number is an exact square. */ -BOOL +bool qissquare(NUMBER *q) { - BOOL flag; + bool flag; flag = zissquare(q->num); if (qisint(q) || !flag) @@ -765,18 +765,18 @@ qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base) * bit position. Negative bit positions indicate bits to the right of the * binary decimal point. Examples: qdigit(17.1, 0) = 1, qdigit(17.1, -1) = 0. */ -BOOL +bool qisset(NUMBER *q, long n) { NUMBER *qtmp1, *qtmp2; ZVALUE ztmp; - BOOL res; + bool res; /* * Zero number or negative bit position place of integer is trivial. */ if (qiszero(q) || (qisint(q) && (n < 0))) - return FALSE; + return false; /* * For non-negative bit positions, answer is easy. */ @@ -1337,10 +1337,10 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd) ZVALUE tmp1, tmp2, tmp3, tmp4; ZVALUE denbnd; ZVALUE f, g, k; - BOOL esign; + bool esign; int s; - BOOL bnddencase; - BOOL useold = FALSE; + bool bnddencase; + bool useold = false; if (qiszero(epsilon) || qisint(q)) return qlink(q); @@ -1416,7 +1416,7 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd) } if (bnddencase) { if (s > 0) { - useold = TRUE; + useold = true; } else { zsub(zden, denbnd, &tmp1); zquo(tmp1, oldden, &k, 1); @@ -1829,14 +1829,14 @@ qplaces(NUMBER *q, ZVALUE base) /* * Perform a probabilistic primality test (algorithm P in Knuth). - * Returns FALSE if definitely not prime, or TRUE if probably prime. + * Returns false if definitely not prime, or true if probably prime. * * The absolute value of the 2nd arg determines how many times * to check for primality. If 2nd arg < 0, then the trivial * check is omitted. The 3rd arg determines how tests to * initially skip. */ -BOOL +bool qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3) { if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) { diff --git a/qio.c b/qio.c index 1851a80..a79e9af 100644 --- a/qio.c +++ b/qio.c @@ -1,7 +1,7 @@ /* * qio - scanf and printf routines for arbitrary precision rational numbers * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -114,7 +114,7 @@ qprintf(char *fmt, ...) case 'r': case 'R': q = va_arg(ap, NUMBER *); - qprintfr(q, width, (BOOL) (ch == 'R')); + qprintfr(q, width, (bool) (ch == 'R')); break; case 'N': q = va_arg(ap, NUMBER *); @@ -227,7 +227,7 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits) break; case MODE_FRAC: - qprintfr(q, 0L, FALSE); + qprintfr(q, 0L, false); break; case MODE_EXP: @@ -416,7 +416,7 @@ qprintfe(NUMBER *q, long UNUSED(width), long precision) * Example: 397/37 */ void -qprintfr(NUMBER *q, long width, BOOL force) +qprintfr(NUMBER *q, long width, bool force) { zprintval(q->num, 0L, width); if (force || qisfrac(q)) { @@ -526,18 +526,18 @@ str2q(char *s) register char *t; ZVALUE div, newnum, newden, tmp; long decimals, exp; - BOOL hex, negexp; + bool hex, negexp; q = qalloc(); decimals = 0; exp = 0; - negexp = FALSE; - hex = FALSE; + negexp = false; + hex = false; t = s; if ((*t == '+') || (*t == '-')) t++; if ((*t == '0') && ((t[1] == 'x') || (t[1] == 'X'))) { - hex = TRUE; + hex = true; t += 2; } while (((*t >= '0') && (*t <= '9')) || (hex && @@ -562,7 +562,7 @@ str2q(char *s) if (*t == '+') t++; else if (*t == '-') { - negexp = TRUE; + negexp = true; t++; } while ((*t >= '0') && (*t <= '9')) { diff --git a/qmath.c b/qmath.c index 29b7815..46173e4 100644 --- a/qmath.c +++ b/qmath.c @@ -1,7 +1,7 @@ /* * qmath - extended precision rational arithmetic primitive routines * - * Copyright (C) 1999-2007,2014,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2014,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -221,7 +221,7 @@ uutoq(FULL inum, FULL iden) { register NUMBER *q; FULL d; - BOOL sign; + bool sign; if (iden == 0) { math_error("Division by zero"); @@ -253,7 +253,7 @@ iitoq(long inum, long iden) { register NUMBER *q; long d; - BOOL sign; + bool sign; if (iden == 0) { math_error("Division by zero"); @@ -441,7 +441,7 @@ qaddi(NUMBER *q1, long n) { NUMBER addnum; /* temporary number */ HALF addval[2]; /* value of small number */ - BOOL neg; /* TRUE if number is neg */ + bool neg; /* true if number is neg */ #if LONG_BITS > BASEB FULL nf; #endif @@ -1223,16 +1223,16 @@ qprecision(NUMBER *q) /* * Determine whether or not one number exactly divides another one. - * Returns TRUE if the first number is an integer multiple of the second one. + * Returns true if the first number is an integer multiple of the second one. */ -BOOL +bool qdivides(NUMBER *q1, NUMBER *q2) { if (qiszero(q1)) - return TRUE; + return true; if (qisint(q1) && qisint(q2)) { if (qisunit(q2)) - return TRUE; + return true; return zdivides(q1->num, q2->num); } return zdivides(q1->num, q2->num) && zdivides(q2->den, q1->den); @@ -1305,21 +1305,21 @@ qrel(NUMBER *q1, NUMBER *q2) /* * Compare two numbers to see if they are equal. * This differs from qrel in that the numbers are not ordered. - * Returns TRUE if they differ. + * Returns true if they differ. */ -BOOL +bool qcmp(NUMBER *q1, NUMBER *q2) { if (q1 == q2) - return FALSE; + return false; if ((q1->num.sign != q2->num.sign) || (q1->num.len != q2->num.len) || (q1->den.len != q2->den.len) || (*q1->num.v != *q2->num.v) || (*q1->den.v != *q2->den.v)) - return TRUE; + return true; if (zcmp(q1->num, q2->num)) - return TRUE; + return true; if (qisint(q1)) - return FALSE; + return false; return zcmp(q1->den, q2->den); } @@ -1361,9 +1361,9 @@ qreli(NUMBER *q, long n) /* * Compare a number against a small integer to see if they are equal. - * Returns TRUE if they differ. + * Returns true if they differ. */ -BOOL +bool qcmpi(NUMBER *q, long n) { long len; @@ -1373,11 +1373,11 @@ qcmpi(NUMBER *q, long n) len = q->num.len; if (qisfrac(q) || (q->num.sign != (n < 0))) - return TRUE; + return true; if (n < 0) n = -n; if (((HALF)(n)) != q->num.v[0]) - return TRUE; + return true; #if LONG_BITS > BASEB nf = ((FULL) n) >> BASEB; return ((nf != 0 || len > 1) && (len != 2 || nf != q->num.v[1])); diff --git a/qmath.h b/qmath.h index 540b423..565e761 100644 --- a/qmath.h +++ b/qmath.h @@ -68,7 +68,7 @@ E_FUNC void qfreenum(NUMBER *q); E_FUNC void qprintnum(NUMBER *q, int mode, LEN outdigits); E_FUNC void qprintff(NUMBER *q, long width, long precision); E_FUNC void qprintfe(NUMBER *q, long width, long precision); -E_FUNC void qprintfr(NUMBER *q, long width, BOOL force); +E_FUNC void qprintfr(NUMBER *q, long width, bool force); E_FUNC void qprintfd(NUMBER *q, long width); E_FUNC void qprintfx(NUMBER *q, long width); E_FUNC void qprintfb(NUMBER *q, long width); @@ -119,12 +119,12 @@ E_FUNC NUMBER *qround(NUMBER *q, long places, long rnd); E_FUNC NUMBER *qbtrunc(NUMBER *q1, NUMBER *q2); E_FUNC NUMBER *qbround(NUMBER *q, long places, long rnd); E_FUNC NUMBER *qscale(NUMBER *q, long i); -E_FUNC BOOL qdivides(NUMBER *q1, NUMBER *q2); -E_FUNC BOOL qcmp(NUMBER *q1, NUMBER *q2); -E_FUNC BOOL qcmpi(NUMBER *q, long i); +E_FUNC bool qdivides(NUMBER *q1, NUMBER *q2); +E_FUNC bool qcmp(NUMBER *q1, NUMBER *q2); +E_FUNC bool qcmpi(NUMBER *q, long i); E_FUNC FLAG qrel(NUMBER *q1, NUMBER *q2); E_FUNC FLAG qreli(NUMBER *q, long i); -E_FUNC BOOL qisset(NUMBER *q, long i); +E_FUNC bool qisset(NUMBER *q, long i); /* @@ -153,13 +153,13 @@ E_FUNC NUMBER *qredcout(NUMBER *q1, NUMBER *q2); E_FUNC NUMBER *qredcmul(NUMBER *q1, NUMBER *q2, NUMBER *q3); E_FUNC NUMBER *qredcsquare(NUMBER *q1, NUMBER *q2); E_FUNC NUMBER *qredcpower(NUMBER *q1, NUMBER *q2, NUMBER *q3); -E_FUNC BOOL qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3); -E_FUNC BOOL qissquare(NUMBER *q); +E_FUNC bool qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3); +E_FUNC bool qissquare(NUMBER *q); E_FUNC long qilog2(NUMBER *q); E_FUNC long qilog10(NUMBER *q); E_FUNC NUMBER *qilog(NUMBER *q, ZVALUE base); -E_FUNC BOOL qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3); -E_FUNC BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, +E_FUNC bool qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3); +E_FUNC bool qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, long rnd); E_FUNC FLAG qnear(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); E_FUNC NUMBER *qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base); @@ -209,7 +209,7 @@ E_FUNC NUMBER *qatanh(NUMBER *q, NUMBER *epsilon); E_FUNC NUMBER *qasech(NUMBER *q, NUMBER *epsilon); E_FUNC NUMBER *qacsch(NUMBER *q, NUMBER *epsilon); E_FUNC NUMBER *qacoth(NUMBER *q, NUMBER *epsilon); -E_FUNC NUMBER *qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg); +E_FUNC NUMBER *qlegtoleg(NUMBER *q, NUMBER *epsilon, bool wantneg); E_FUNC NUMBER *qpi(NUMBER *epsilon); E_FUNC NUMBER *qpidiv180(NUMBER *epsilon); E_FUNC NUMBER *qpidiv200(NUMBER *epsilon); @@ -229,9 +229,9 @@ E_FUNC NUMBER *pseudo_seed(void); /* * external swap functions */ -E_FUNC NUMBER *swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); -E_FUNC NUMBER *swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); -E_FUNC NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); +E_FUNC NUMBER *swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all); +E_FUNC NUMBER *swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all); +E_FUNC NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all); /* diff --git a/qmod.c b/qmod.c index 6fdf970..045e48a 100644 --- a/qmod.c +++ b/qmod.c @@ -1,7 +1,7 @@ /* * qmod - modular arithmetic routines for normal numbers and REDC numbers * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -110,7 +110,7 @@ qmod(NUMBER *q1, NUMBER *q2, long rnd) * If rnd is zero, the remainder has the sign of q2 * and the quotient is rounded towards zero. * - * The function returns TRUE or FALSE according as the remainder is + * The function returns true or false according as the remainder is * nonzero or zero * * Given: @@ -120,7 +120,7 @@ qmod(NUMBER *q1, NUMBER *q2, long rnd) * mod remainder * rnd rounding-type specifier */ -BOOL +bool qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, long rnd) { NUMBER *qq, *qm; @@ -181,9 +181,9 @@ qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, long rnd) /* * Return whether or not two integers are congruent modulo a third integer. - * Returns TRUE if the numbers are not congruent, and FALSE if they are. + * Returns true if the numbers are not congruent, and false if they are. */ -BOOL +bool qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3) { if (qisneg(q3) || qiszero(q3)) @@ -191,7 +191,7 @@ qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3) if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) math_error("Non-integers for qcmpmod"); if (q1 == q2) - return FALSE; + return false; return zcmpmod(q1->num, q2->num, q3->num); } diff --git a/qtrans.c b/qtrans.c index ca6534c..0e0bc1c 100644 --- a/qtrans.c +++ b/qtrans.c @@ -1,7 +1,7 @@ /* * qtrans - transcendental functions for real numbers * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -427,7 +427,7 @@ qasin(NUMBER *q, NUMBER *epsilon) { NUMBER *qtmp1, *qtmp2, *epsilon1; ZVALUE ztmp; - BOOL neg; + bool neg; FLAG r; if (qiszero(epsilon)) { @@ -523,7 +523,7 @@ qatan(NUMBER *q, NUMBER *epsilon) FULL d; ZVALUE X, D, DD, sum, mul, term, ztmp1, ztmp2; NUMBER *qtmp, *res; - BOOL sign; + bool sign; if (qiszero(epsilon)) { math_error("Zero epsilon value for arctangent"); @@ -1045,7 +1045,7 @@ qln(NUMBER *q, NUMBER *epsilon) long m, n, k, h, d; ZVALUE term, sum, mul, pow, X, D, B, ztmp; NUMBER *qtmp, *res; - BOOL neg; + bool neg; if (qiszero(q) || qiszero(epsilon)) { math_error("logarithm of 0"); @@ -1154,7 +1154,7 @@ qln(NUMBER *q, NUMBER *epsilon) NUMBER * qlog(NUMBER *q, NUMBER *epsilon) { - int need_new_ln_10 = TRUE; /* FALSE => use cached ln_10 value */ + int need_new_ln_10 = true; /* false => use cached ln_10 value */ NUMBER *ln_q; /* ln(x) */ NUMBER *ret; /* base 10 logarithm of x */ @@ -1168,12 +1168,12 @@ qlog(NUMBER *q, NUMBER *epsilon) * shortcut for small integer powers of 10 */ if (qisint(q) && qispos(q) && !zge8192b(q->num) && ziseven(q->num)) { - BOOL is_10_power; /* TRUE ==> q is a power of 10 */ + bool is_10_power; /* true ==> q is a power of 10 */ long ilog_10; /* integer log base 10 */ /* try for a quick small power of 10 log */ ilog_10 = zlog10(q->num, &is_10_power ); - if (is_10_power == TRUE) { + if (is_10_power == true) { /* is small power of 10, return log */ return itoq(ilog_10); } @@ -1195,19 +1195,19 @@ qlog(NUMBER *q, NUMBER *epsilon) if (ln_10_epsilon == NULL) { /* first time call */ ln_10_epsilon = qcopy(epsilon); - } else if (qcmp(ln_10_epsilon, epsilon) == TRUE) { + } else if (qcmp(ln_10_epsilon, epsilon) == true) { /* replaced cached value with epsilon arg */ qfree(ln_10_epsilon); ln_10_epsilon = qcopy(epsilon); } else if (ln_10 != NULL) { /* the previously computed ln(2) is OK to use */ - need_new_ln_10 = FALSE; + need_new_ln_10 = false; } /* * compute ln(10) if needed */ - if (need_new_ln_10 == TRUE) { + if (need_new_ln_10 == true) { if (ln_10 != NULL) { qfree(ln_10); } @@ -1692,7 +1692,7 @@ qasinh(NUMBER *q, NUMBER *epsilon) { NUMBER *tmp1, *tmp2, *epsilon1; long n; - BOOL neg; + bool neg; if (qiszero(epsilon)) { math_error("Zero epsilon value for asinh"); diff --git a/quickhash.c b/quickhash.c index 3d28bd5..5b819e0 100644 --- a/quickhash.c +++ b/quickhash.c @@ -6,7 +6,7 @@ * * http://www.isthe.com/chongo/tech/comp/fnv/index.html * - * Copyright (C) 1999-2007,2014,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2014,2021-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 @@ -470,9 +470,9 @@ config_hash(CONFIG *cfg, QCKHASH val) value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cygwin); value = (((value>>5) | (value<<27)) ^ (USB32)cfg->compile_custom); if (cfg->allow_custom != NULL && *(cfg->allow_custom)) { - value = (((value>>5) | (value<<27)) ^ (USB32)TRUE); + value = (((value>>5) | (value<<27)) ^ (USB32)true); } else { - value = (((value>>5) | (value<<27)) ^ (USB32)FALSE); + value = (((value>>5) | (value<<27)) ^ (USB32)false); } /* version is handled out of order */ diff --git a/sha1.c b/sha1.c index d56dc10..7095b68 100644 --- a/sha1.c +++ b/sha1.c @@ -531,7 +531,7 @@ sha1_init_state(HASH *state) * initialize state */ state->hashtype = SHA1_HASH_TYPE; - state->bytes = TRUE; + state->bytes = true; state->update = sha1Update; state->chkpt = sha1_chkpt; state->note = sha1_note; @@ -622,8 +622,8 @@ sha1_final_state(HASH *state) * b second hash state * * returns: - * TRUE => hash states are different - * FALSE => hash states are the same + * true => hash states are different + * false => hash states are the same */ S_FUNC int sha1_cmp(HASH *a, HASH *b) @@ -633,18 +633,18 @@ sha1_cmp(HASH *a, HASH *b) */ if (a == b) { /* pointers to the same object */ - return FALSE; + return false; } if (a == NULL || b == NULL) { /* one is NULL, so they differ */ - return TRUE; + return true; } /* * compare data-reading modes */ if (a->bytes != b->bytes) - return TRUE; + return true; /* * compare bit counts @@ -652,7 +652,7 @@ sha1_cmp(HASH *a, HASH *b) if (a->h_union.h_sha1.countLo != b->h_union.h_sha1.countLo || a->h_union.h_sha1.countHi != b->h_union.h_sha1.countHi) { /* counts differ */ - return TRUE; + return true; } /* @@ -660,13 +660,13 @@ sha1_cmp(HASH *a, HASH *b) */ if (a->h_union.h_sha1.datalen != b->h_union.h_sha1.datalen) { /* buffer lengths differ */ - return TRUE; + return true; } if (memcmp((USB8*)a->h_union.h_sha1.data, (USB8*)b->h_union.h_sha1.data, a->h_union.h_sha1.datalen) != 0) { /* buffer contents differ */ - return TRUE; + return true; } /* diff --git a/str.c b/str.c index 1d98ef5..2e82265 100644 --- a/str.c +++ b/str.c @@ -1,7 +1,7 @@ /* * str - string list routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -427,7 +427,7 @@ stringmul(NUMBER *q, STRING *str) NUMBER *tmp1, *tmp2; char *c, *c1; STRING *s; - BOOL neg; + bool neg; if (str->s_len == 0) return slink(str); @@ -671,7 +671,7 @@ stringshift(STRING *s1, long n) char *c1, *c; STRING *s; long len, i, j, k; - BOOL right; + bool right; char ch; len = s1->s_len; @@ -866,27 +866,27 @@ stringlowbit(STRING *s) /* * stringcompare compares first len characters of strings starting at c1, c2 - * Returns TRUE if and only if a difference is encountered. + * Returns true if and only if a difference is encountered. * Essentially a local version of memcmp. */ -S_FUNC BOOL +S_FUNC bool stringcompare(char *c1, char *c2, long len) { while (len-- > 0) { if (*c1++ != *c2++) - return TRUE; + return true; } - return FALSE; + return false; } /* - * stringcmp returns TRUE if strings differ, FALSE if strings equal + * stringcmp returns true if strings differ, false if strings equal */ -BOOL +bool stringcmp(STRING *s1, STRING *s2) { if (s1->s_len != s2->s_len) - return TRUE; + return true; return stringcompare(s1->s_str, s2->s_str, s1->s_len); } @@ -988,7 +988,7 @@ stringbit(STRING *s, long index) } -BOOL +bool stringtest(STRING *s) { long i; @@ -998,18 +998,18 @@ stringtest(STRING *s) c = s->s_str; while (i-- > 0) { if (*c++) - return TRUE; + return true; } - return FALSE; + return false; } /* * If index is in acceptable range, stringsetbit sets or resets specified - * bit in string s according as val is TRUE or FALSE, and returns 0. + * bit in string s according as val is true or false, and returns 0. * Returns 1 if index < 0; 2 if index too large. */ int -stringsetbit(STRING *s, long index, BOOL val) +stringsetbit(STRING *s, long index, bool val) { char *c; int bit; @@ -1327,7 +1327,7 @@ addstring(char *str, size_t len) char *c; long index; /* index into constant table */ long first; /* first non-null position found */ - BOOL havefirst; + bool havefirst; if (len < 1) { math_error("addstring length including trailing NUL < 1"); @@ -1354,13 +1354,13 @@ addstring(char *str, size_t len) } len--; first = 0; - havefirst = FALSE; + havefirst = false; sp = stringconsttable; for (index = 0; index < stringconstcount; index++, sp++) { s = *sp; if (s->s_links == 0) { if (!havefirst) { - havefirst = TRUE; + havefirst = true; first = index; } continue; diff --git a/symbol.c b/symbol.c index 9148f83..de9b66e 100644 --- a/symbol.c +++ b/symbol.c @@ -1,7 +1,7 @@ /* * symbol - global and local symbol routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -89,10 +89,10 @@ initglobals(void) * * given: * name name of global variable - * isstatic TRUE if symbol is static + * isstatic true if symbol is static */ GLOBAL * -addglobal(char *name, BOOL isstatic) +addglobal(char *name, bool isstatic) { GLOBAL *sp; /* current symbol pointer */ GLOBAL **hp; /* hash table head address */ @@ -493,7 +493,7 @@ exitfuncscope(void) * variable is at the same file and function level. */ void -endscope(char *name, BOOL isglobal) +endscope(char *name, bool isglobal) { GLOBAL *sp; GLOBAL *prevsp; diff --git a/symbol.h b/symbol.h index 7372e00..ddd2d43 100644 --- a/symbol.h +++ b/symbol.h @@ -62,7 +62,7 @@ struct global { /* * Routines to search for global symbols. */ -E_FUNC GLOBAL *addglobal(char *name, BOOL isstatic); +E_FUNC GLOBAL *addglobal(char *name, bool isstatic); E_FUNC GLOBAL *findglobal(char *name); @@ -82,7 +82,7 @@ E_FUNC void enterfilescope(void); E_FUNC void exitfilescope(void); E_FUNC void enterfuncscope(void); E_FUNC void exitfuncscope(void); -E_FUNC void endscope (char *name, BOOL isglobal); +E_FUNC void endscope (char *name, bool isglobal); /* diff --git a/token.c b/token.c index 00e8e39..cb25f28 100644 --- a/token.c +++ b/token.c @@ -1,7 +1,7 @@ /* * token - read input file characters into tokens * - * Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2017,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -61,9 +61,9 @@ STATIC struct { } curtoken; -STATIC BOOL rescan; /* TRUE to reread current token */ -STATIC BOOL newlines; /* TRUE to return newlines as tokens */ -STATIC BOOL allsyms; /* TRUE if always want a symbol token */ +STATIC bool rescan; /* true to reread current token */ +STATIC bool newlines; /* true to return newlines as tokens */ +STATIC bool allsyms; /* true if always want a symbol token */ STATIC STRINGHEAD strings; /* list of constant strings */ STATIC char *numbuf; /* buffer for numeric tokens */ STATIC long numbufsize; /* current size of numeric buffer */ @@ -127,9 +127,9 @@ void inittokens(void) { initstr(&strings); - newlines = FALSE; - allsyms = FALSE; - rescan = FALSE; + newlines = false; + allsyms = false; + rescan = false; setprompt(conf->prompt1); } @@ -148,12 +148,12 @@ tokenmode(int flag) oldflag |= TM_NEWLINES; if (allsyms) oldflag |= TM_ALLSYMS; - newlines = FALSE; - allsyms = FALSE; + newlines = false; + allsyms = false; if (flag & TM_NEWLINES) - newlines = TRUE; + newlines = true; if (flag & TM_ALLSYMS) - allsyms = TRUE; + allsyms = true; setprompt(newlines ? conf->prompt1 : conf->prompt2); return oldflag; } @@ -171,7 +171,7 @@ gettoken(void) int type; /* token type */ if (rescan) { /* rescanning */ - rescan = FALSE; + rescan = false; return curtoken.t_type; } curtoken.t_sym = NULL; @@ -437,11 +437,11 @@ eatstring(int quotechar) long len; /* length in buffer */ long totlen; /* total length, including '\0' */ char *str; - BOOL done; + bool done; str = buf; totlen = 0; - done = FALSE; + done = false; while (!done) { cp = buf; @@ -457,7 +457,7 @@ eatstring(int quotechar) reread(); scanerror(T_NULL, "Unterminated string constant"); - done = TRUE; + done = true; ch = '\0'; break; @@ -522,7 +522,7 @@ eatstring(int quotechar) continue; } reread(); - done = TRUE; + done = true; ch = '\0'; } break; @@ -702,7 +702,7 @@ tokensymbol(void) void rescantoken(void) { - rescan = TRUE; + rescan = true; } @@ -774,7 +774,7 @@ scanerror(int skip, char *fmt, ...) case T_NULL: return; case T_COMMA: - rescan = TRUE; + rescan = true; for (;;) { switch (gettoken()) { case T_NEWLINE: @@ -783,7 +783,7 @@ scanerror(int skip, char *fmt, ...) case T_RIGHTBRACE: case T_EOF: case T_COMMA: - rescan = TRUE; + rescan = true; return; } } @@ -797,7 +797,7 @@ scanerror(int skip, char *fmt, ...) /* fall into semicolon case */ /*FALLTHRU*/ case T_SEMICOLON: - rescan = TRUE; + rescan = true; for (;;) { switch (gettoken()) { case T_NEWLINE: @@ -805,7 +805,7 @@ scanerror(int skip, char *fmt, ...) case T_LEFTBRACE: case T_RIGHTBRACE: case T_EOF: - rescan = TRUE; + rescan = true; return; } } diff --git a/token.h b/token.h index 0177aa8..aa76fc9 100644 --- a/token.h +++ b/token.h @@ -1,7 +1,7 @@ /* * token - token defines * - * Copyright (C) 1999-2007,2014,2021 David I. Bell + * Copyright (C) 1999-2007,2014,2021,2023 David I. Bell * * 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 @@ -138,7 +138,7 @@ #define T_ABORT 127 /* abort operation */ -#define iskeyword(n) ((n) > 100) /* TRUE if token is a keyword */ +#define iskeyword(n) ((n) > 100) /* true if token is a keyword */ /* @@ -148,13 +148,13 @@ #define EXPR_CONST 0x0002 /* result is constant */ #define EXPR_ASSIGN 0x0004 /* result is an assignment */ -/* TRUE if expression is rvalue */ +/* true if expression is rvalue */ #define isrvalue(n) ((n) & EXPR_RVALUE) -/* TRUE if expr is lvalue */ +/* true if expr is lvalue */ #define islvalue(n) (((n) & EXPR_RVALUE) == 0) -/* TRUE if expr is constant */ +/* true if expr is constant */ #define isconst(n) ((n) & EXPR_CONST) -/* TRUE if expr is an assignment */ +/* true if expr is an assignment */ #define isassign(n) ((n) & EXPR_ASSIGN) diff --git a/value.c b/value.c index 49f1c32..ddb01a1 100644 --- a/value.c +++ b/value.c @@ -1,7 +1,7 @@ /* * value - generic value manipulation routines * - * Copyright (C) 1999-2007,2014,2017,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2014,2017,2021-2023 David I. Bell * * 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 @@ -1723,11 +1723,11 @@ normvalue(VALUE *vp, VALUE *vres) * given: * v1 value to shift * v2 shift amount - * rightshift TRUE if shift right instead of left + * rightshift true if shift right instead of left * vres result */ void -shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres) +shiftvalue(VALUE *v1, VALUE *v2, bool rightshift, VALUE *vres) { COMPLEX *c; long n = 0; @@ -2361,9 +2361,9 @@ modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) * Test an arbitrary value to see if it is equal to "zero". * The definition of zero varies depending on the value type. For example, * the null string is "zero", and a matrix with zero values is "zero". - * Returns TRUE if value is not equal to zero. + * Returns true if value is not equal to zero. */ -BOOL +bool testvalue(VALUE *vp) { VALUE val; @@ -2382,9 +2382,9 @@ testvalue(VALUE *vp) case V_LIST: for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { if (testvalue(&ep->e_value)) - return TRUE; + return true; } - return FALSE; + return false; case V_ASSOC: return (vp->v_assoc->a_count != 0); case V_FILE: @@ -2397,36 +2397,36 @@ testvalue(VALUE *vp) case V_BLOCK: for (i=0; i < vp->v_block->datalen; ++i) { if (vp->v_block->data[i]) { - return TRUE; + return true; } } - return FALSE; + return false; case V_OCTET: return (*vp->v_octet != 0); case V_NBLOCK: if (vp->v_nblock->blk->data == NULL) - return FALSE; + return false; for (i=0; i < vp->v_nblock->blk->datalen; ++i) { if (vp->v_nblock->blk->data[i]) { - return TRUE; + return true; } } - return FALSE; + return false; default: - return TRUE; + return true; } - return FALSE; + return false; } /* * Compare two values for equality. - * Returns TRUE if the two values differ. + * Returns true if the two values differ. */ -BOOL +bool comparevalue(VALUE *v1, VALUE *v2) { - int r = FALSE; + int r = false; VALUE val; if ((v1->v_type == V_OBJ) || (v2->v_type == V_OBJ)) { @@ -2434,7 +2434,7 @@ comparevalue(VALUE *v1, VALUE *v2) return (val.v_int != 0); } if (v1 == v2) - return FALSE; + return false; if (v1->v_type == V_OCTET) { if (v2->v_type == V_OCTET) return (*v1->v_octet != *v2->v_octet); @@ -2443,15 +2443,15 @@ comparevalue(VALUE *v1, VALUE *v2) || (v2->v_str->s_len != 1); if (v2->v_type != V_NUM || qisfrac(v2->v_num) || qisneg(v2->v_num) || v2->v_num->num.len > 1) - return TRUE; + return true; return (*v2->v_num->num.v != *v1->v_octet); } if (v2->v_type == V_OCTET) return comparevalue(v2, v1); if (v1->v_type != v2->v_type) - return TRUE; + return true; if (v1->v_type <= 0) - return FALSE; + return false; switch (v1->v_type) { case V_NUM: r = qcmp(v1->v_num, v2->v_num); @@ -2509,12 +2509,12 @@ comparevalue(VALUE *v1, VALUE *v2) return (r != 0); } -BOOL +bool acceptvalue(VALUE *v1, VALUE *v2) { long index; FUNC *fp; - BOOL ret; + bool ret; index = adduserfunc("accept"); fp = findfunc(index); @@ -2536,14 +2536,14 @@ acceptvalue(VALUE *v1, VALUE *v2) } -BOOL +bool precvalue(VALUE *v1, VALUE *v2) { VALUE val; long index; int r = 0; FUNC *fp; - BOOL ret; + bool ret; index = adduserfunc("precedes"); fp = findfunc(index); @@ -3017,7 +3017,7 @@ config_print(CONFIG *cfg) { NAMETYPE *cp; VALUE tmp; - int tab_over; /* TRUE => OK move over one tab stop */ + int tab_over; /* true => OK move over one tab stop */ size_t len; /* @@ -3032,7 +3032,7 @@ config_print(CONFIG *cfg) /* * print each element */ - tab_over = FALSE; + tab_over = false; for (cp = configs; cp->name; cp++) { /* skip if special all or duplicate maxerr value */ @@ -3044,7 +3044,7 @@ config_print(CONFIG *cfg) if (tab_over) { math_str("\t"); } else if (conf->tab_ok) { - tab_over = TRUE; /* tab next time */ + tab_over = true; /* tab next time */ } /* print name and spaces */ diff --git a/value.h b/value.h index 841382e..5c4959d 100644 --- a/value.h +++ b/value.h @@ -265,22 +265,22 @@ E_FUNC void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); E_FUNC void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); E_FUNC void absvalue(VALUE *v1, VALUE *v2, VALUE *vres); E_FUNC void normvalue(VALUE *vp, VALUE *vres); -E_FUNC void shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres); +E_FUNC void shiftvalue(VALUE *v1, VALUE *v2, bool rightshift, VALUE *vres); E_FUNC void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres); E_FUNC void powvalue(VALUE *v1, VALUE *v2, VALUE *vres); E_FUNC void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); E_FUNC void divvalue(VALUE *v1, VALUE *v2, VALUE *vres); E_FUNC void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); E_FUNC void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); -E_FUNC BOOL testvalue(VALUE *vp); -E_FUNC BOOL comparevalue(VALUE *v1, VALUE *v2); -E_FUNC BOOL acceptvalue(VALUE *v1, VALUE *v2); +E_FUNC bool testvalue(VALUE *vp); +E_FUNC bool comparevalue(VALUE *v1, VALUE *v2); +E_FUNC bool acceptvalue(VALUE *v1, VALUE *v2); E_FUNC void relvalue(VALUE *v1, VALUE *v2, VALUE *vres); E_FUNC void sgnvalue(VALUE *vp, VALUE *vres); E_FUNC QCKHASH hashvalue(VALUE *vp, QCKHASH val); E_FUNC void printvalue(VALUE *vp, int flags); E_FUNC void printestr(VALUE *vp); -E_FUNC BOOL precvalue(VALUE *v1, VALUE *v2); +E_FUNC bool precvalue(VALUE *v1, VALUE *v2); E_FUNC VALUE error_value(int e); E_FUNC int set_errno(int e); E_FUNC int set_errcount(int e); @@ -329,9 +329,9 @@ E_FUNC MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3); E_FUNC VALUE mattrace(MATRIX *m); E_FUNC MATRIX *mattrans(MATRIX *m); E_FUNC MATRIX *matcross(MATRIX *m1, MATRIX *m2); -E_FUNC BOOL mattest(MATRIX *m); +E_FUNC bool mattest(MATRIX *m); E_FUNC void matsum(MATRIX *m, VALUE *vres); -E_FUNC BOOL matcmp(MATRIX *m1, MATRIX *m2); +E_FUNC bool matcmp(MATRIX *m1, MATRIX *m2); E_FUNC int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index); E_FUNC int matrsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index); @@ -340,10 +340,10 @@ E_FUNC VALUE matdot(MATRIX *m1, MATRIX *m2); E_FUNC void matfill(MATRIX *m, VALUE *v1, VALUE *v2); E_FUNC void matfree(MATRIX *m); E_FUNC void matprint(MATRIX *m, long max_print); -E_FUNC VALUE *matindex(MATRIX *mp, BOOL create, long dim, VALUE *indices); +E_FUNC VALUE *matindex(MATRIX *mp, bool create, long dim, VALUE *indices); E_FUNC void matreverse(MATRIX *m); E_FUNC void matsort(MATRIX *m); -E_FUNC BOOL matisident(MATRIX *m); +E_FUNC bool matisident(MATRIX *m); E_FUNC MATRIX *matround(MATRIX *m, VALUE *v2, VALUE *v3); E_FUNC MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3); @@ -383,7 +383,7 @@ E_FUNC void listprint(LIST *lp, long max_print); E_FUNC int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index); E_FUNC int listrsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index); -E_FUNC BOOL listcmp(LIST *lp1, LIST *lp2); +E_FUNC bool listcmp(LIST *lp1, LIST *lp2); E_FUNC VALUE *listfindex(LIST *lp, long index); E_FUNC LIST *listalloc(void); E_FUNC LIST *listcopy(LIST *lp); @@ -394,8 +394,8 @@ E_FUNC LIST *listround(LIST *m, VALUE *v2, VALUE *v3); E_FUNC LIST *listbround(LIST *m, VALUE *v2, VALUE *v3); E_FUNC LIST *listquo(LIST *lp, VALUE *v2, VALUE *v3); E_FUNC LIST *listmod(LIST *lp, VALUE *v2, VALUE *v3); -E_FUNC BOOL evp(LISTELEM *cp, LISTELEM *x, VALUE *vres); -E_FUNC BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *vres); +E_FUNC bool evp(LISTELEM *cp, LISTELEM *x, VALUE *vres); +E_FUNC bool evalpoly(LIST *clist, LISTELEM *x, VALUE *vres); E_FUNC void insertitems(LIST *lp1, LIST *lp2); E_FUNC LISTELEM *listelement(LIST *, long); E_FUNC LIST *listsegment(LIST *, long, long); @@ -431,9 +431,9 @@ E_FUNC int assocsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index); E_FUNC int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index); -E_FUNC BOOL assoccmp(ASSOC *ap1, ASSOC *ap2); +E_FUNC bool assoccmp(ASSOC *ap1, ASSOC *ap2); E_FUNC VALUE *assocfindex(ASSOC *ap, long index); -E_FUNC VALUE *associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices); +E_FUNC VALUE *associndex(ASSOC *ap, bool create, long dim, VALUE *indices); /* @@ -567,12 +567,12 @@ E_FUNC STRING *stringncpy(STRING *, STRING *, size_t); E_FUNC long stringcontent(STRING *s); E_FUNC long stringlowbit(STRING *s); E_FUNC long stringhighbit(STRING *s); -E_FUNC BOOL stringcmp(STRING *, STRING *); +E_FUNC bool stringcmp(STRING *, STRING *); E_FUNC FLAG stringrel(STRING *, STRING *); E_FUNC FLAG stringcaserel(STRING *, STRING *); E_FUNC int stringbit(STRING *, long); -E_FUNC BOOL stringtest(STRING *); -E_FUNC int stringsetbit(STRING *, long, BOOL); +E_FUNC bool stringtest(STRING *); +E_FUNC int stringsetbit(STRING *, long, bool); E_FUNC int stringsearch(STRING *, STRING *, long, long, ZVALUE *); E_FUNC int stringrsearch(STRING *, STRING *, long, long, ZVALUE *); diff --git a/version.h b/version.h index f4d459d..e2f6edd 100644 --- a/version.h +++ b/version.h @@ -3,8 +3,6 @@ * * Copyright (C) 2023 David I. Bell and Landon Curt Noll * - * Primary author: David I. Bell - * * 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. @@ -19,8 +17,8 @@ * 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: 1990/05/22 11:00:58 - * File existed as early as: 1990 + * Under source code control: 2023/08/19 17:32:42 + * File existed as early as: 2023 * * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/zfunc.c b/zfunc.c index b1e8051..ffa38c5 100644 --- a/zfunc.c +++ b/zfunc.c @@ -1,7 +1,7 @@ /* * zfunc - extended precision integral arithmetic non-primitive routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell, Landon Curt Noll and Ernest Bowen * * Primary author: David I. Bell * @@ -478,7 +478,7 @@ zfib(ZVALUE z, ZVALUE *res) sign = z.sign && ((n & 0x1) == 0); if (n <= 2) { *res = _one_; - res->sign = (BOOL)sign; + res->sign = (bool)sign; return; } i = TOPFULL; @@ -512,7 +512,7 @@ zfib(ZVALUE z, ZVALUE *res) zfree(fnm1); zfree(fnp1); *res = fn; - res->sign = (BOOL)sign; + res->sign = (bool)sign; } @@ -539,7 +539,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) } if (zisabsleone(z1)) { /* 0, 1, or -1 raised to a power */ ans = _one_; - ans.sign = (BOOL)sign; + ans.sign = (bool)sign; if (*z1.v == 0) ans = _zero_; *res = ans; @@ -559,7 +559,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) */ if (zistiny(z1) && (*z1.v == 10)) { ztenpow((long) power, res); - res->sign = (BOOL)sign; + res->sign = (bool)sign; return; } /* @@ -571,7 +571,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) ans.len = z1.len; ans.v = alloc(ans.len); zcopyval(z1, ans); - ans.sign = (BOOL)sign; + ans.sign = (bool)sign; *res = ans; return; case 2: @@ -581,7 +581,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) zsquare(z1, &temp); zmul(z1, temp, res); zfree(temp); - res->sign = (BOOL)sign; + res->sign = (bool)sign; return; case 4: zsquare(z1, &temp); @@ -641,7 +641,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) ans = temp; zfree(z1); } - ans.sign = (BOOL)sign; + ans.sign = (bool)sign; *res = ans; } @@ -687,10 +687,10 @@ ztenpow(long power, ZVALUE *res) * Calculate modular inverse suppressing unnecessary divisions. * This is based on the Euclidean algorithm for large numbers. * (Algorithm X from Knuth Vol 2, section 4.5.2. and exercise 17) - * Returns TRUE if there is no solution because the numbers + * Returns true if there is no solution because the numbers * are not relatively prime. */ -BOOL +bool zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res) { FULL q1, q2, ui3, vi3, uh, vh, A, B, C, D, T; @@ -813,7 +813,7 @@ zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res) zfree(v3); zfree(u2); zfree(v2); - return TRUE; + return true; } ui3 = ztofull(u3); vi3 = ztofull(v3); @@ -834,15 +834,15 @@ zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res) zfree(v2); if (ui3 != 1) { zfree(u2); - return TRUE; + return true; } if (zisneg(u2)) { zadd(v, u2, res); zfree(u2); - return FALSE; + return false; } *res = u2; - return FALSE; + return false; } @@ -858,7 +858,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) HALF *a, *a0, *A, *b, *b0, *B, *c, *d; FULL f, g; ZVALUE gcd; - BOOL needw; + bool needw; if (zisunit(z1) || zisunit(z2)) { *res = _one_; @@ -979,7 +979,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) k = (n - 1) * BASEB; while (u >>= 1) k++; - needw = TRUE; + needw = true; w = 0; j = 0; @@ -1019,7 +1019,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) b0 = a; k = j; h = -h; - needw = TRUE; + needw = true; } if (h > 1) { if (needw) { /* find w = minv(*b0, h0) */ @@ -1032,7 +1032,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) if (u & x) { u -= v * x; w |= x;} x <<= 1; } - needw = FALSE; + needw = false; } g = (FULL) (*a0 * w); if (h < BASEB) { @@ -1190,23 +1190,23 @@ zlcm(ZVALUE z1, ZVALUE z2, ZVALUE *res) /* * Return whether or not two numbers are relatively prime to each other. */ -BOOL +bool zrelprime(ZVALUE z1, ZVALUE z2) { FULL rem1, rem2; /* remainders */ ZVALUE rem; - BOOL result; + bool result; z1.sign = 0; z2.sign = 0; if (ziseven(z1) && ziseven(z2)) /* false if both even */ - return FALSE; + return false; if (zisunit(z1) || zisunit(z2)) /* true if either is a unit */ - return TRUE; + return true; if (ziszero(z1) || ziszero(z2)) /* false if either is zero */ - return FALSE; + return false; if (zistwo(z1) || zistwo(z2)) /* true if either is two */ - return TRUE; + return true; /* * Try reducing each number by the product of the first few odd primes * to see if any of them are a common factor. @@ -1214,26 +1214,26 @@ zrelprime(ZVALUE z1, ZVALUE z2) rem1 = zmodi(z1, (FULL)3 * 5 * 7 * 11 * 13); rem2 = zmodi(z2, (FULL)3 * 5 * 7 * 11 * 13); if (((rem1 % 3) == 0) && ((rem2 % 3) == 0)) - return FALSE; + return false; if (((rem1 % 5) == 0) && ((rem2 % 5) == 0)) - return FALSE; + return false; if (((rem1 % 7) == 0) && ((rem2 % 7) == 0)) - return FALSE; + return false; if (((rem1 % 11) == 0) && ((rem2 % 11) == 0)) - return FALSE; + return false; if (((rem1 % 13) == 0) && ((rem2 % 13) == 0)) - return FALSE; + return false; /* * Try a new batch of primes now */ rem1 = zmodi(z1, (FULL)17 * 19 * 23); rem2 = zmodi(z2, (FULL)17 * 19 * 23); if (((rem1 % 17) == 0) && ((rem2 % 17) == 0)) - return FALSE; + return false; if (((rem1 % 19) == 0) && ((rem2 % 19) == 0)) - return FALSE; + return false; if (((rem1 % 23) == 0) && ((rem2 % 23) == 0)) - return FALSE; + return false; /* * Yuk, we must actually compute the gcd to know the answer */ @@ -1322,11 +1322,11 @@ zlog(ZVALUE z, ZVALUE base) /* * Return the integral log base 10 of a number. * - * If was_10_power != NULL, then this flag is set to TRUE if the - * value was a power of 10, FALSE otherwise. + * If was_10_power != NULL, then this flag is set to true if the + * value was a power of 10, false otherwise. */ long -zlog10(ZVALUE z, BOOL *was_10_power) +zlog10(ZVALUE z, bool *was_10_power) { ZVALUE *zp; /* current square */ long power; /* current power */ @@ -1368,7 +1368,7 @@ zlog10(ZVALUE z, BOOL *was_10_power) /* assume not a power of ten unless we find out otherwise */ if (was_10_power != NULL) { - *was_10_power = FALSE; + *was_10_power = false; } /* quick exit for small values */ @@ -1378,7 +1378,7 @@ zlog10(ZVALUE z, BOOL *was_10_power) for (i=0; i <= max_power10_exp; ++i) { if (value == power10[i]) { if (was_10_power != NULL) { - *was_10_power = TRUE; + *was_10_power = true; } return i; } else if (value < power10[i]) { @@ -1413,7 +1413,7 @@ zlog10(ZVALUE z, BOOL *was_10_power) if (rel == 0) { /* quick return - we match a tenpower entry */ if (was_10_power != NULL) { - *was_10_power = TRUE; + *was_10_power = true; } return (1L << (zp - _tenpowers_)); } @@ -1437,7 +1437,7 @@ zlog10(ZVALUE z, BOOL *was_10_power) /* exact power of 10 match */ power += (1L << (zp - _tenpowers_)); if (was_10_power != NULL) { - *was_10_power = TRUE; + *was_10_power = true; } zfree(pow10); zfree(temp); @@ -1750,7 +1750,7 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd) int i, j, j1, j2, k, k1, m, m0, m1, n, n0, o; FULL d, e, f, g, h, s, t, x, topbit; int remsign; - BOOL up, onebit; + bool up, onebit; ZVALUE sqrt; if (z.sign) { @@ -1874,7 +1874,7 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd) k1 = 1; } h = e >> k; - onebit = ((e & ((FULL)1 << (k - 1))) ? TRUE : FALSE); + onebit = ((e & ((FULL)1 << (k - 1))) ? true : false); j2 = BASEB - k1; j1 = BASEB + j2; while (m > n0) { @@ -1980,9 +1980,9 @@ done: if (s == 0) { } else if (rnd & 8) - up = (((rnd ^ *a0) & 1) ? TRUE : FALSE); + up = (((rnd ^ *a0) & 1) ? true : false); else - up = ((rnd & 1) ? TRUE : FALSE); + up = ((rnd & 1) ? true : false); if (up) { remsign = -1; i = n; @@ -2042,14 +2042,14 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest) } if (zge31b(z2)) { /* humongous root */ *dest = _one_; - dest->sign = (BOOL)((HALF)sign); + dest->sign = (bool)((HALF)sign); return; } k = (LEN)ztolong(z2); highbit = zhighbit(z1); if (highbit < k) { /* too high a root */ *dest = _one_; - dest->sign = (BOOL)((HALF)sign); + dest->sign = (bool)((HALF)sign); return; } sival.ivalue = k - 1; @@ -2095,7 +2095,7 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest) if ((i == 0) || (zcmp(old, ztry) == 0)) { zfree(quo); zfree(old); - ztry.sign = (BOOL)((HALF)sign); + ztry.sign = (bool)((HALF)sign); zquicktrim(ztry); *dest = ztry; return; @@ -2118,7 +2118,7 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest) /* * Test to see if a number is an exact square or not. */ -BOOL +bool zissquare(ZVALUE z) { long n; @@ -2126,7 +2126,7 @@ zissquare(ZVALUE z) /* negative values are never perfect squares */ if (zisneg(z)) { - return FALSE; + return false; } /* ignore trailing zero words */ @@ -2137,16 +2137,38 @@ zissquare(ZVALUE z) /* zero or one is a perfect square */ if (zisabsleone(z)) { - return TRUE; + return true; } /* check mod 4096 values */ if (issq_mod4k[(int)(*z.v & 0xfff)] == 0) { - return FALSE; + return false; } /* must do full square root test now */ n = !zsqrt(z, &tmp, 0); zfree(tmp); - return (n ? TRUE : FALSE); + return (n ? true : false); } + + +#if 0 /* XXX - to be added later */ +/* + * test if a number is a power of 2 + * + * given: + * z value to check if it is a power of 2 + * zlog2 set to log base 2 of z if z is a power of 2, 0 otherwise + */ +bool +zispowerof2(ZVALUE z, ZVALUE *zlog2) +{ + + /* zero and negative values are never powers of 2 */ + if (ziszero(z) || zisneg(z)) { + return false; + } + + /* XXX - add code here - XXX */ +} +#endif /* XXX */ diff --git a/zio.c b/zio.c index 339d2af..8a0a34b 100644 --- a/zio.c +++ b/zio.c @@ -1,7 +1,7 @@ /* * zio - scanf and printf routines for arbitrary precision integers * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -58,14 +58,14 @@ struct iostate { char *outbuf; /* output string buffer (if any) */ size_t outbufsize; /* current size of string buffer */ size_t outbufused; /* space used in string buffer */ - BOOL outputisstring; /* TRUE if output is to string buffer */ + bool outputisstring; /* true if output is to string buffer */ }; STATIC IOSTATE *oldiostates = NULL; /* list of saved output states */ STATIC FILE *outfp = NULL; /* file unit for output */ STATIC char *outbuf = NULL; /* current diverted buffer */ -STATIC BOOL outputisstring = FALSE; +STATIC bool outputisstring = false; STATIC size_t outbufsize; STATIC size_t outbufused; @@ -232,7 +232,7 @@ math_divertio(void) not_reached(); } outbufsize = OUTBUFSIZE; - outputisstring = TRUE; + outputisstring = true; oldiostates = sp; } @@ -602,8 +602,8 @@ zprintval(ZVALUE z, long decimals, long width) long leadspaces; /* number of leading spaces to print */ long putpoint; /* digits until print decimal point */ long digits; /* number of digits of raw number */ - BOOL output; /* TRUE if have output something */ - BOOL neg; /* TRUE if negative */ + bool output; /* true if have output something */ + bool neg; /* true if negative */ ZVALUE quo, rem; /* quotient and remainder */ ZVALUE leftnums[32]; /* left parts of the number */ ZVALUE rightnums[32]; /* right parts of the number */ @@ -642,7 +642,7 @@ zprintval(ZVALUE z, long decimals, long width) * we visit left nodes first. We do the needed recursion in line. */ digits = 1; - output = FALSE; + output = false; n = 0; putpoint = 0; rightnums[0].len = 0; @@ -660,7 +660,7 @@ zprintval(ZVALUE z, long decimals, long width) i = (long)(leftnums[n].v[0]); if (output || i || (n == 0)) { if (!output) { - output = TRUE; + output = true; if (decimals < digits) leadspaces -= digits; else @@ -711,15 +711,15 @@ str2z(char *s, ZVALUE *res) { ZVALUE z, ztmp, digit; HALF digval; - BOOL minus; + bool minus; long shift; - minus = FALSE; + minus = false; shift = 0; if (*s == '+') s++; else if (*s == '-') { - minus = TRUE; + minus = true; s++; } if (*s == '0') { /* possibly hex, octal, or binary */ diff --git a/zmath.c b/zmath.c index 08757a7..53bcab2 100644 --- a/zmath.c +++ b/zmath.c @@ -1,7 +1,7 @@ /* * zmath - extended precision integral arithmetic primitives * - * Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell and Ernest Bowen * * Primary author: David I. Bell * @@ -196,7 +196,7 @@ HALF bitmask[(2*BASEB)+1] = { #endif }; /* actual rotation thru 8 cycles */ -BOOL _math_abort_; /* nonzero to abort calculations */ +bool _math_abort_; /* nonzero to abort calculations */ /* @@ -257,8 +257,8 @@ alloc(LEN len) * h pointer to the beginning of the HALF array * * returns: - * TRUE - h is found in the half_tbl array - * FALSE - is is not found in the half_tbl array + * true - h is found in the half_tbl array + * false - is is not found in the half_tbl array */ int is_const(HALF* h) @@ -268,12 +268,12 @@ is_const(HALF* h) /* search the half_tbl for h */ for (h_p = &half_tbl[0]; *h_p != NULL; ++h_p) { if (h == *h_p) { - return TRUE; /* found in the half_tbl array */ + return true; /* found in the half_tbl array */ } } /* not found in the half_tbl array */ - return FALSE; + return false; } @@ -722,7 +722,7 @@ zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *quo, ZVALUE *rem, long rnd) HALF s, u; HALF *A, *B, *a1, *b0; FULL f, g, h, x; - BOOL adjust, onebit; + bool adjust, onebit; LEN m, n, len, i, p, j1, j2, k; long t, val; @@ -782,7 +782,7 @@ zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *quo, ZVALUE *rem, long rnd) j1 = BASEB - k; j2 = BASEB + j1; h = j1 ? ((FULL) B[n - 1] << j1 | B[n - 2] >> k) : B[n-1]; - onebit = (BOOL)((B[n - 2] >> (k - 1)) & 1); + onebit = (bool)((B[n - 2] >> (k - 1)) & 1); m++; while (m > n) { m--; @@ -837,9 +837,9 @@ done: while (m > 0 && A[m - 1] == 0) return val; } if (rnd & 8) - adjust = (((*a1 ^ rnd) & 1) ? TRUE : FALSE); + adjust = (((*a1 ^ rnd) & 1) ? true : false); else - adjust = (((rnd & 1) ^ z1.sign ^ z2.sign) ? TRUE : FALSE); + adjust = (((rnd & 1) ^ z1.sign ^ z2.sign) ? true : false); if (rnd & 2) adjust ^= z1.sign ^ z2.sign; if (rnd & 4) @@ -1243,31 +1243,31 @@ zmodi(ZVALUE z, long n) /* * Return whether or not one number exactly divides another one. - * Returns TRUE if division occurs with no remainder. + * Returns true if division occurs with no remainder. * z1 is the number to be divided by z2. */ -BOOL +bool zdivides(ZVALUE z1, ZVALUE z2) { LEN i, j, k, m, n; HALF u, v, w, x; HALF *a, *a0, *A, *b, *B, *c, *d; FULL f; - BOOL ans; + bool ans; - if (zisunit(z2) || ziszero(z1)) return TRUE; - if (ziszero(z2)) return FALSE; + if (zisunit(z2) || ziszero(z1)) return true; + if (ziszero(z2)) return false; m = z1.len; n = z2.len; - if (m < n) return FALSE; + if (m < n) return false; c = z1.v; d = z2.v; while (!*d) { - if (*c++) return FALSE; + if (*c++) return false; d++; m--; n--; @@ -1277,20 +1277,20 @@ zdivides(ZVALUE z1, ZVALUE z2) u = *c; v = *d; while (!(v & 1)) { /* Counting and checking zero bits */ - if (u & 1) return FALSE; + if (u & 1) return false; u >>= 1; v >>= 1; j++; } - if (n == 1 && v == 1) return TRUE; + if (n == 1 && v == 1) return true; if (!*c) { /* Removing any further zeros */ while(!*++c) m--; c--; } - if (m < n) return FALSE; + if (m < n) return false; if (j) { B = alloc((LEN)n); /* Array for shifted z2 */ @@ -1347,11 +1347,11 @@ zdivides(ZVALUE z1, ZVALUE z2) } a0++; } - ans = FALSE; + ans = false; if (A[m + 1]) { a = A + m; while (--n && !*--a); - if (!n) ans = TRUE; + if (!n) ans = true; } freeh(A); if (j) freeh(B); @@ -1627,37 +1627,37 @@ zhighbit(ZVALUE z) * Return whether or not the specified bit number is set in a number. * Rightmost bit of a number is bit 0. */ -BOOL +bool zisset(ZVALUE z, long n) { if ((n < 0) || ((n / BASEB) >= z.len)) - return FALSE; + return false; return ((z.v[n / BASEB] & (((HALF) 1) << (n % BASEB))) != 0); } /* * Check whether or not a number has exactly one bit set, and - * thus is an exact power of two. Returns TRUE if so. + * thus is an exact power of two. Returns true if so. */ -BOOL +bool zisonebit(ZVALUE z) { register HALF *hp; register LEN len; if (ziszero(z) || zisneg(z)) - return FALSE; + return false; hp = z.v; len = z.len; while (len > 4) { len -= 4; if (*hp++ || *hp++ || *hp++ || *hp++) - return FALSE; + return false; } while (--len > 0) { if (*hp++) - return FALSE; + return false; } return ((*hp & -*hp) == *hp); /* NEEDS 2'S COMPLEMENT */ } @@ -1666,9 +1666,9 @@ zisonebit(ZVALUE z) /* * Check whether or not a number has all of its bits set below some * bit position, and thus is one less than an exact power of two. - * Returns TRUE if so. + * Returns true if so. */ -BOOL +bool zisallbits(ZVALUE z) { register HALF *hp; @@ -1676,18 +1676,18 @@ zisallbits(ZVALUE z) HALF digit; if (ziszero(z) || zisneg(z)) - return FALSE; + return false; hp = z.v; len = z.len; while (len > 4) { len -= 4; if ((*hp++ != BASE1) || (*hp++ != BASE1) || (*hp++ != BASE1) || (*hp++ != BASE1)) - return FALSE; + return false; } while (--len > 0) { if (*hp++ != BASE1) - return FALSE; + return false; } digit = (HALF)(*hp + 1); return ((digit & -digit) == digit); /* NEEDS 2'S COMPLEMENT */ @@ -1802,24 +1802,24 @@ zabsrel(ZVALUE z1, ZVALUE z2) /* * Compare two numbers to see if they are equal or not. - * Returns TRUE if they differ. + * Returns true if they differ. */ -BOOL +bool zcmp(ZVALUE z1, ZVALUE z2) { register HALF *h1, *h2; register long len; if ((z1.sign != z2.sign) || (z1.len != z2.len) || (*z1.v != *z2.v)) - return TRUE; + return true; len = z1.len; h1 = z1.v; h2 = z2.v; while (--len > 0) { if (*++h1 != *++h2) - return TRUE; + return true; } - return FALSE; + return false; } diff --git a/zmath.h b/zmath.h index 9689946..13c410f 100644 --- a/zmath.h +++ b/zmath.h @@ -1,7 +1,7 @@ /* * zmath - declarations for extended precision integer arithmetic * - * Copyright (C) 1999-2007,2014,2021 David I. Bell + * Copyright (C) 1999-2007,2014,2021,2023 David I. Bell * * 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 @@ -36,6 +36,7 @@ #if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "version.h" +# include "bool.h" # include "decl.h" # include "alloc.h" # include "endian_calc.h" @@ -46,6 +47,7 @@ # include "charbit.h" #else # include +# include # include # include # include @@ -83,7 +85,7 @@ typedef SB64 SFULL; /* signed FULL */ #define SWAP_HALF_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) #define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) #define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) -#define SWAP_HALF_IN_BOOL(dest, src) SWAP_B16_IN_BOOL(dest, src) +#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) #define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) #define SWAP_B32_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) #define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B64(dest, src) @@ -104,7 +106,7 @@ typedef SB32 SFULL; /* signed FULL */ #define SWAP_HALF_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) #define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) #define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) -#define SWAP_HALF_IN_BOOL(dest, src) SWAP_B16_IN_BOOL(dest, src) +#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) #define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) #define SWAP_B32_IN_FULL(dest, src) (*(dest) = *(src)) #define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) @@ -122,29 +124,6 @@ typedef SB32 SFULL; /* signed FULL */ #define FULL_LEN (sizeof(FULL)) /* length of FULL in bites */ -/* - * calc historic booleans - */ -#if defined(CALC2_COMPAT) -typedef SB32 BOOL; /* calc v2 compatible TRUE or FALSE value */ -#else /* CALC2_COMPAT */ -typedef bool BOOL; /* TRUE or FALSE value as C boolean */ -#endif /* CALC2_COMPAT */ - -/* - * calc historic booleans - */ -#undef TRUE -#undef FALSE -#if defined(CALC2_COMPAT) -#define TRUE ((BOOL) 1) /* booleans */ -#define FALSE ((BOOL) 0) -#else -#define TRUE ((bool) true) -#define FALSE ((bool) false) -#endif - - /* * ROUNDUP(value, mult) - round up value to the next multiple of mult * @@ -206,9 +185,9 @@ typedef SB32 LEN; /* else assume we can support at least 4 octet pointers */ #define SWAP_B16_IN_FLAG(dest, src) SWAP_B16_IN_B32(dest, src) #define SWAP_B8_IN_FLAG(dest, src) SWAP_B8_IN_B32(dest, src) -#define SWAP_B32_IN_BOOL(dest, src) (*(dest) = *(src)) -#define SWAP_B16_IN_BOOL(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_B8_IN_BOOL(dest, src) SWAP_B8_IN_B32(dest, src) +#define SWAP_B32_IN_bool(dest, src) (*(dest) = *(src)) +#define SWAP_B16_IN_bool(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B8_IN_bool(dest, src) SWAP_B8_IN_B32(dest, src) #define SWAP_B32_IN_LEN(dest, src) (*(dest) = *(src)) #define SWAP_B16_IN_LEN(dest, src) SWAP_B16_IN_B32(dest, src) @@ -329,10 +308,19 @@ typedef union { #endif + +/* + * ZVALUE - multi-prevision integer + */ +#if defined(CALC2_COMPAT) +typedef SB32 SIGN; /* calc v2 compatible sign type */ +#else /* CALC2_COMPAT */ +typedef bool SIGN; /* sign as a C boolean */ +#endif /* CALC2_COMPAT */ typedef struct { HALF *v; /* pointer to array of values */ LEN len; /* number of values in array */ - BOOL sign; /* sign, nonzero is negative */ + SIGN sign; /* sign, nonzero is negative */ } ZVALUE; @@ -378,7 +366,7 @@ E_FUNC long zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *res, ZVALUE *rem, long R); E_FUNC long zquo(ZVALUE z1, ZVALUE z2, ZVALUE *res, long R); E_FUNC long zmod(ZVALUE z1, ZVALUE z2, ZVALUE *rem, long R); E_FUNC void zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res); -E_FUNC BOOL zdivides(ZVALUE z1, ZVALUE z2); +E_FUNC bool zdivides(ZVALUE z1, ZVALUE z2); E_FUNC void zor(ZVALUE z1, ZVALUE z2, ZVALUE *res); E_FUNC void zand(ZVALUE z1, ZVALUE z2, ZVALUE *res); E_FUNC void zxor(ZVALUE z1, ZVALUE z2, ZVALUE *res); @@ -389,13 +377,13 @@ E_FUNC void zsquare(ZVALUE z, ZVALUE *res); E_FUNC long zlowbit(ZVALUE z); E_FUNC LEN zhighbit(ZVALUE z); E_FUNC void zbitvalue(long n, ZVALUE *res); -E_FUNC BOOL zisset(ZVALUE z, long n); -E_FUNC BOOL zisonebit(ZVALUE z); -E_FUNC BOOL zisallbits(ZVALUE z); +E_FUNC bool zisset(ZVALUE z, long n); +E_FUNC bool zisonebit(ZVALUE z); +E_FUNC bool zisallbits(ZVALUE z); E_FUNC FLAG ztest(ZVALUE z); E_FUNC FLAG zrel(ZVALUE z1, ZVALUE z2); E_FUNC FLAG zabsrel(ZVALUE z1, ZVALUE z2); -E_FUNC BOOL zcmp(ZVALUE z1, ZVALUE z2); +E_FUNC bool zcmp(ZVALUE z1, ZVALUE z2); /* @@ -414,10 +402,10 @@ E_FUNC void zfib(ZVALUE z, ZVALUE *res); E_FUNC void zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res); E_FUNC void ztenpow(long power, ZVALUE *res); E_FUNC void zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res); -E_FUNC BOOL zmodinv(ZVALUE z1, ZVALUE z2, ZVALUE *res); -E_FUNC BOOL zrelprime(ZVALUE z1, ZVALUE z2); +E_FUNC bool zmodinv(ZVALUE z1, ZVALUE z2, ZVALUE *res); +E_FUNC bool zrelprime(ZVALUE z1, ZVALUE z2); E_FUNC long zlog(ZVALUE z1, ZVALUE z2); -E_FUNC long zlog10(ZVALUE z, BOOL *was_10_power); +E_FUNC long zlog10(ZVALUE z, bool *was_10_power); E_FUNC long zdivcount(ZVALUE z1, ZVALUE z2); E_FUNC long zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem); E_FUNC long zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res); @@ -425,7 +413,7 @@ E_FUNC long zdigits(ZVALUE z1); E_FUNC long zdigit(ZVALUE z1, long n); E_FUNC FLAG zsqrt(ZVALUE z1, ZVALUE *dest, long R); E_FUNC void zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest); -E_FUNC BOOL zissquare(ZVALUE z); +E_FUNC bool zissquare(ZVALUE z); E_FUNC void zhnrmod(ZVALUE v, ZVALUE h, ZVALUE zn, ZVALUE zr, ZVALUE *res); @@ -437,11 +425,11 @@ E_FUNC FULL znprime(ZVALUE z); E_FUNC FULL next_prime(FULL v); E_FUNC FULL zpprime(ZVALUE z); E_FUNC void zpfact(ZVALUE z, ZVALUE *dest); -E_FUNC BOOL zprimetest(ZVALUE z, long count, ZVALUE skip); -E_FUNC BOOL zredcprimetest(ZVALUE z, long count, ZVALUE skip); -E_FUNC BOOL znextcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, +E_FUNC bool zprimetest(ZVALUE z, long count, ZVALUE skip); +E_FUNC bool zredcprimetest(ZVALUE z, long count, ZVALUE skip); +E_FUNC bool znextcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand); -E_FUNC BOOL zprevcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, +E_FUNC bool zprevcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand); E_FUNC FULL zlowfactor(ZVALUE z, long count); E_FUNC FLAG zfactor(ZVALUE z1, ZVALUE z2, ZVALUE *res); @@ -454,7 +442,7 @@ E_FUNC void zlcmfact(ZVALUE z, ZVALUE *dest); */ E_FUNC void zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res); E_FUNC void zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res); -E_FUNC BOOL zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3); +E_FUNC bool zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3); E_FUNC void zio_init(void); @@ -510,18 +498,18 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); #define zistiny(z) ((z).len == 1) /* - * zgtmaxfull(z) TRUE if abs(z) > MAXFULL + * zgtmaxfull(z) true if abs(z) > MAXFULL */ #define zgtmaxfull(z) (((z).len > 2) || (((z).len == 2) && \ (((SHALF)(z).v[1]) < 0))) /* - * zgtmaxufull(z) TRUE if abs(z) will not fit into a FULL (> MAXUFULL) + * zgtmaxufull(z) true if abs(z) will not fit into a FULL (> MAXUFULL) */ #define zgtmaxufull(z) ((z).len > 2) /* - * zgtmaxulong(z) TRUE if abs(z) > MAXULONG + * zgtmaxulong(z) true if abs(z) > MAXULONG */ #if BASEB >= LONG_BITS #define zgtmaxulong(z) ((z).len > 1) @@ -530,7 +518,7 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); #endif /* - * zgtmaxlong(z) TRUE if abs(z) > MAXLONG + * zgtmaxlong(z) true if abs(z) > MAXLONG */ #if BASEB >= LONG_BITS #define zgtmaxlong(z) (((z).len > 1) || (((z).len == 1) && \ @@ -546,18 +534,18 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); * against a different power of 2 on a 64 bit machine. The macros below * provide a tests against powers of 2 that are independent of the work size. * - * zge16b(z) TRUE if abs(z) >= 2^16 - * zge24b(z) TRUE if abs(z) >= 2^24 - * zge31b(z) TRUE if abs(z) >= 2^31 - * zge32b(z) TRUE if abs(z) >= 2^32 - * zge64b(z) TRUE if abs(z) >= 2^64 - * zge128b(z) TRUE if abs(z) >= 2^128 - * zge256b(z) TRUE if abs(z) >= 2^256 - * zge512b(z) TRUE if abs(z) >= 2^512 - * zge1024b(z) TRUE if abs(z) >= 2^1024 - * zge2048b(z) TRUE if abs(z) >= 2^2048 - * zge4096b(z) TRUE if abs(z) >= 2^4096 - * zge8192b(z) TRUE if abs(z) >= 2^8192 + * zge16b(z) true if abs(z) >= 2^16 + * zge24b(z) true if abs(z) >= 2^24 + * zge31b(z) true if abs(z) >= 2^31 + * zge32b(z) true if abs(z) >= 2^32 + * zge64b(z) true if abs(z) >= 2^64 + * zge128b(z) true if abs(z) >= 2^128 + * zge256b(z) true if abs(z) >= 2^256 + * zge512b(z) true if abs(z) >= 2^512 + * zge1024b(z) true if abs(z) >= 2^1024 + * zge2048b(z) true if abs(z) >= 2^2048 + * zge4096b(z) true if abs(z) >= 2^4096 + * zge8192b(z) true if abs(z) >= 2^8192 */ #if BASEB == 32 @@ -692,11 +680,11 @@ E_FUNC void math_error(char *, ...) \ * external swap functions */ E_FUNC HALF *swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len); -E_FUNC ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); +E_FUNC ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all); E_FUNC HALF *swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len); E_FUNC HALF *swap_HALFs(HALF *dest, HALF *src, LEN len); -E_FUNC ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); -E_FUNC ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); +E_FUNC ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all); +E_FUNC ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all); /* @@ -732,7 +720,7 @@ EXTERN ZVALUE _b64_; EXTERN HALF *half_tbl[]; /* preset HALF constants, NULL terminated list */ -EXTERN BOOL _math_abort_; /* nonzero to abort calculations */ +EXTERN bool _math_abort_; /* nonzero to abort calculations */ EXTERN ZVALUE _tenpowers_[]; /* table of 10^2^n */ /* diff --git a/zmod.c b/zmod.c index 762d188..4497a88 100644 --- a/zmod.c +++ b/zmod.c @@ -1,7 +1,7 @@ /* * zmod - modulo arithmetic routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen + * Copyright (C) 1999-2007,2021-2023 David I. Bell, Landon Curt Noll and Ernest Bowen * * Primary author: David I. Bell * @@ -54,7 +54,7 @@ S_FUNC void zredcmodinv(ZVALUE z1, ZVALUE *res); STATIC REDC *powermodredc = NULL; /* REDC info for raising to power */ -BOOL havelastmod = FALSE; +bool havelastmod = false; STATIC ZVALUE lastmod[1]; STATIC ZVALUE lastmodinv[1]; @@ -177,7 +177,7 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res) } tmp1 = z1; if (cv > 0) { - z1.sign = (BOOL)sign; + z1.sign = (bool)sign; zmod(z1, z2, &tmp1, 0); if (tmp1.len < z2.len - 1) { *res = tmp1; @@ -197,7 +197,7 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res) cv = zrel(tmp1, tmp2); if (cv < 0) { zfree(tmp2); - tmp1.sign = (BOOL)sign; + tmp1.sign = (bool)sign; if (tmp1.v == z1.v) zcopy(tmp1, res); else @@ -215,7 +215,7 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res) /* * Compare two numbers for equality modulo a third number. * The two numbers to be compared can be negative or out of modulo range. - * Returns TRUE if the numbers are not congruent, and FALSE if they are + * Returns true if the numbers are not congruent, and false if they are * congruent. * * given: @@ -223,7 +223,7 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res) * z2 second number to be compared * z3 modulus */ -BOOL +bool zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) { ZVALUE tmp1, tmp2, tmp3; @@ -243,7 +243,7 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) */ if ((z1.sign == z2.sign) && (z1.len == z2.len) && (z1.v[0] == z2.v[0]) && (zcmp(z1, z2) == 0)) - return FALSE; + return false; /* * If both numbers are negative, then we can make them positive. @@ -279,7 +279,7 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) zfree(tmp1); if (tmp2.v != z2.v) zfree(tmp2); - return FALSE; + return false; } /* @@ -293,7 +293,7 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) zfree(tmp1); if (tmp2.v != z2.v) zfree(tmp2); - return TRUE; + return true; } /* @@ -315,11 +315,11 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) cv = zrel(tmp3, z3); if (cv == 0) { zfree(tmp3); - return FALSE; + return false; } if (cv < 0) { zfree(tmp3); - return TRUE; + return true; } /* @@ -330,10 +330,10 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) zfree(tmp3); if (ziszero(tmp1)) { zfree(tmp1); - return FALSE; + return false; } else { zfree(tmp1); - return TRUE; + return true; } } @@ -494,7 +494,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) HALF curhalf; /* current word of power */ unsigned int curpow; /* current low power */ unsigned int curbit; /* current bit of low power */ - BOOL free_z1; /* TRUE => need to free z1 */ + bool free_z1; /* true => need to free z1 */ int i; if (zisneg(z3) || ziszero(z3)) { @@ -537,12 +537,12 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) * within the modulo range. Then check for zero or one specially. */ ztmp.len = 0; - free_z1 = FALSE; + free_z1 = false; if (zisneg(z1) || zrel(z1, z3) >= 0) { zmod(z1, z3, &ztmp, 0); zfree(z1); z1 = ztmp; - free_z1 = TRUE; + free_z1 = true; } if (ziszero(z1)) { zfree(z1); @@ -566,14 +566,14 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) if (havelastmod && zcmp(z3, *lastmod)) { zfree(*lastmod); zfree(*lastmodinv); - havelastmod = FALSE; + havelastmod = false; } if (!havelastmod) { zcopy(z3, lastmod); zbitvalue(2 * z3.len * BASEB, &temp); zquo(temp, z3, lastmodinv, 0); zfree(temp); - havelastmod = TRUE; + havelastmod = true; } /* zzz */ @@ -607,7 +607,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) if (pp->v == NULL) { if (curpow & 0x1) { zcopy(z1, &modpow); - free_z1 = FALSE; + free_z1 = false; } else { modpow = _one_; } @@ -697,7 +697,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) powermodredc = zredcalloc(z3); rp = powermodredc; zredcencode(rp, z1, &temp); - if (free_z1 == TRUE) { + if (free_z1 == true) { zfree(z1); } zredcpower(rp, temp, z2, &z1); @@ -740,7 +740,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) if (pp->v == NULL) { if (curpow & 0x1) { zcopy(z1, &modpow); - free_z1 = FALSE; + free_z1 = false; } else { modpow = _one_; } @@ -807,7 +807,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) *res = ans; if (ztmp.len) zfree(ztmp); - if (free_z1 == TRUE) { + if (free_z1 == true) { zfree(z1); } } @@ -958,14 +958,14 @@ zredcencode(REDC *rp, ZVALUE z1, ZVALUE *res) if (havelastmod && zcmp(rp->mod, *lastmod)) { zfree(*lastmod); zfree(*lastmodinv); - havelastmod = FALSE; + havelastmod = false; } if (!havelastmod) { zcopy(rp->mod, lastmod); zbitvalue(2 * rp->len * BASEB, &tmp1); zquo(tmp1, rp->mod, lastmodinv, 0); zfree(tmp1); - havelastmod = TRUE; + havelastmod = true; } } /* diff --git a/zmul.c b/zmul.c index 5f0afeb..7fa3733 100644 --- a/zmul.c +++ b/zmul.c @@ -1,7 +1,7 @@ /* * zmul - faster than usual multiplying and squaring routines * - * Copyright (C) 1999-2007,2021,2022 David I. Bell + * Copyright (C) 1999-2007,2021-2023 David I. Bell * * 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 @@ -144,7 +144,7 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans) FULL carryACBD; /* carry from addition of A*C and B*D */ FULL digit; /* single digit multiplying by */ HALF *temp; /* base for temporary calculations */ - BOOL neg; /* whether intermediate term is negative */ + bool neg; /* whether intermediate term is negative */ register HALF *hd, *h1=NULL, *h2=NULL; /* for inner loops */ SIUNION sival; /* for addition of digits */ @@ -401,7 +401,7 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans) * location at position 0 of the result. Negate the sign if A is * smaller than B. */ - neg = FALSE; + neg = false; if (sizeA == sizeB) { len = sizeA; h1 = &baseA[len - 1]; diff --git a/zprime.c b/zprime.c index c3a64ea..56af853 100644 --- a/zprime.c +++ b/zprime.c @@ -1,7 +1,7 @@ /* * zprime - rapid small prime routines * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2021-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 @@ -890,16 +890,16 @@ zpfact(ZVALUE z, ZVALUE *dest) /* * Perform a probabilistic primality test (algorithm P in Knuth vol2, 4.5.4). - * Returns FALSE if definitely not prime, or TRUE if probably prime. + * Returns false if definitely not prime, or true if probably prime. * Count determines how many times to check for primality. * The chance of a non-prime passing this test is less than (1/4)^count. * For example, a count of 100 fails for only 1 in 10^60 numbers. * * It is interesting to note that ptest(a,1,x) (for any x >= 0) of this - * test will always return TRUE for a prime, and rarely return TRUE for + * test will always return true for a prime, and rarely return true for * a non-prime. The 1/4 is appears in practice to be a poor upper - * bound. Even so the only result that is EXACT and TRUE is when - * this test returns FALSE for a non-prime. When ptest returns TRUE, + * bound. Even so the only result that is EXACT and true is when + * this test returns false for a non-prime. When ptest returns true, * one cannot determine if the value in question is prime, or the value * is one of those rare non-primes that produces a false positive. * @@ -910,7 +910,7 @@ zpfact(ZVALUE z, ZVALUE *dest) * skip = 1 uses prime bases 2, 3, 5, ... * skip > 1 or < 0 uses bases skip, skip + 1, ... */ -BOOL +bool zprimetest(ZVALUE z, long count, ZVALUE skip) { long limit = 0; /* test odd values from skip up to limit */ @@ -958,7 +958,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) */ if (small_factor(z, PTEST_PRECHECK) != 0) { /* a tiny factor was found */ - return FALSE; + return false; } /* @@ -966,7 +966,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) */ if (count == 0) { /* no test was done, so no test failed! */ - return TRUE; + return true; } } else { @@ -1013,7 +1013,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) if (*pr == 1 || (long)*pr >= limit) { zfree(z1); zfree(zm1); - return TRUE; + return true; } itoz((long) *pr++, &zbase); break; @@ -1035,7 +1035,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) zfree(zm1); zfree(z1); zfree(zbase); - return FALSE; + return false; } break; } @@ -1047,7 +1047,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) zfree(zm1); zfree(z1); zfree(zbase); - return FALSE; + return false; } zsquare(z3, &z2); zfree(z3); @@ -1061,7 +1061,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) zfree(zbase); /* number might be prime */ - return TRUE; + return true; } @@ -1069,7 +1069,7 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) * Called by zprimetest when simple cases have been eliminated * and z.len < conf->redc2. Here count > 0, z is odd and > 3. */ -BOOL +bool zredcprimetest(ZVALUE z, long count, ZVALUE skip) { long limit = 0; /* test odd values from skip up to limit */ @@ -1127,7 +1127,7 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) zredcfree(rp); zfree(zredcm1); } - return TRUE; + return true; } itoz((long) *pr++, &z3); zredcencode(rp, z3, &zbase); @@ -1158,7 +1158,7 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) zfree(zbase); zredcfree(rp); zfree(zredcm1); - return FALSE; + return false; } break; } @@ -1172,7 +1172,7 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) zfree(zbase); zredcfree(rp); zfree(zredcm1); - return FALSE; + return false; } zredcsquare(rp, z3, &z2); zfree(z3); @@ -1187,7 +1187,7 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) zfree(z1); /* number might be prime */ - return TRUE; + return true; } @@ -1205,7 +1205,7 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip) * mod congruent to res modulo abs(mod) * cand candidate found */ -BOOL +bool znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand) { @@ -1217,13 +1217,13 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, if (ziszero(mod)) { if (zrel(res, z) > 0 && zprimetest(res, count, skip)) { zcopy(res, cand); - return TRUE; + return true; } - return FALSE; + return false; } if (ziszero(z) && zisone(mod)) { zcopy(_two_, cand); - return TRUE; + return true; } zsub(res, z, &tmp1); if (zmod(tmp1, mod, &tmp2, 0)) @@ -1238,12 +1238,12 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(tmp1); zfree(tmp2); if (zprimetest(*cand, count, skip)) - return TRUE; + return true; zgcd(*cand, mod, &tmp1); if (!zisone(tmp1)) { zfree(tmp1); zfree(*cand); - return FALSE; + return false; } zfree(tmp1); if (ziseven(*cand)) { @@ -1251,7 +1251,7 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(*cand); *cand = tmp1; if (zprimetest(*cand, count, skip)) - return TRUE; + return true; } /* * *cand is now least odd integer > abs(z) and congruent to @@ -1267,7 +1267,7 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, *cand = tmp2; } while (!zprimetest(*cand, count, skip)); zfree(tmp1); - return TRUE; + return true; } @@ -1285,7 +1285,7 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, * mod congruent to res modulo abs(mod) * cand candidate found */ -BOOL +bool zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand) { @@ -1297,9 +1297,9 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, if (ziszero(mod)) { if (zispos(res)&&zrel(res, z)<0 && zprimetest(res,count,skip)) { zcopy(res, cand); - return TRUE; + return true; } - return FALSE; + return false; } zsub(z, res, &tmp1); if (zmod(tmp1, mod, &tmp2, 0)) @@ -1314,10 +1314,10 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(tmp2); if (zisneg(*cand)) { zfree(*cand); - return FALSE; + return false; } if (zprimetest(*cand, count, skip)) - return TRUE; + return true; zgcd(*cand, mod, &tmp1); if (!zisone(tmp1)) { zfree(tmp1); @@ -1325,18 +1325,18 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(*cand); if (zprimetest(tmp1, count, skip)) { *cand = tmp1; - return TRUE; + return true; } if (ziszero(tmp1)) { zfree(tmp1); if (zprimetest(mod, count, skip)) { zcopy(mod, cand); - return TRUE; + return true; } - return FALSE; + return false; } zfree(tmp1); - return FALSE; + return false; } zfree(tmp1); if (ziseven(*cand)) { @@ -1344,11 +1344,11 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(*cand); if (zisneg(tmp1)) { zfree(tmp1); - return FALSE; + return false; } *cand = tmp1; if (zprimetest(*cand, count, skip)) - return TRUE; + return true; } /* * *cand is now the greatest odd integer < z that is congruent to @@ -1370,11 +1370,11 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, zfree(*cand); *cand = tmp1; if (zistwo(*cand)) - return TRUE; + return true; zfree(*cand); - return FALSE; + return false; } - return TRUE; + return true; } diff --git a/zrand.c b/zrand.c index cc83bf5..9c359e4 100644 --- a/zrand.c +++ b/zrand.c @@ -1,7 +1,7 @@ /* * zrand - subtractive 100 shuffle generator * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2021-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 @@ -2318,9 +2318,9 @@ randfree(RAND *state) * s2 - second state to compare * * return: - * TRUE if states differ + * true if states differ */ -BOOL +bool randcmp(CONST RAND *s1, CONST RAND *s2) { /* @@ -2329,7 +2329,7 @@ randcmp(CONST RAND *s1, CONST RAND *s2) if (!s1->seeded) { if (!s2->seeded) { /* uninitialized == uninitialized */ - return FALSE; + return false; } else { /* uninitialized only equals default state */ return randcmp(s2, &init_s100); @@ -2340,7 +2340,7 @@ randcmp(CONST RAND *s1, CONST RAND *s2) } /* compare states */ - return (BOOL)(memcmp(s1, s2, sizeof(RAND)) != 0); + return (bool)(memcmp(s1, s2, sizeof(RAND)) != 0); } diff --git a/zrand.h b/zrand.h index c382a51..180e6c2 100644 --- a/zrand.h +++ b/zrand.h @@ -214,7 +214,7 @@ E_FUNC void zrandrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res); E_FUNC long irand(long s); E_FUNC RAND *randcopy(CONST RAND *rand); E_FUNC void randfree(RAND *rand); -E_FUNC BOOL randcmp(CONST RAND *s1, CONST RAND *s2); +E_FUNC bool randcmp(CONST RAND *s1, CONST RAND *s2); E_FUNC void randprint(CONST RAND *state, int flags); diff --git a/zrandom.c b/zrandom.c index 3d92510..9621795 100644 --- a/zrandom.c +++ b/zrandom.c @@ -1,7 +1,7 @@ /* * zrandom - Blum-Blum-Shub pseudo-random generator * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2021-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 @@ -2256,13 +2256,13 @@ S_FUNC void zfree_random(ZVALUE z); * * given: * pseed - seed of the generator - * need_ret - TRUE=>malloc return previous Blum state, FALSE=>return NULL + * need_ret - true=>malloc return previous Blum state, false=>return NULL * * returns: * previous Blum state */ RANDOM * -zsrandom1(CONST ZVALUE seed, BOOL need_ret) +zsrandom1(CONST ZVALUE seed, bool need_ret) { RANDOM *ret; /* previous Blum state */ ZVALUE r; /* quadratic residue */ @@ -2291,7 +2291,7 @@ zsrandom1(CONST ZVALUE seed, BOOL need_ret) /* * srandom(seed == 0) * - * If the init arg is TRUE, then restore the initial state and + * If the init arg is true, then restore the initial state and * modulus of the Blum generator. After this call, the Blum * generator is restored to its initial state after calc started. */ @@ -2433,7 +2433,7 @@ zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn) * Otherwise non-zero seeds are processed as 1 arg calls */ } else { - zsrandom1(seed, FALSE); + zsrandom1(seed, false); } /* @@ -2485,13 +2485,13 @@ zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn) * as if this value is given as a 1 arg call */ if (ziszero(seed)) { - (void) zsrandom1(z_rdefault, FALSE); + (void) zsrandom1(z_rdefault, false); /* * Otherwise non-zero seeds are processed as 1 arg calls */ } else { - (void) zsrandom1(seed, FALSE); + (void) zsrandom1(seed, false); } /* @@ -2594,13 +2594,13 @@ zsrandom4(CONST ZVALUE seed, CONST ZVALUE ip, CONST ZVALUE iq, long trials) * as if this value is given as a 1 arg call */ if (ziszero(seed)) { - (void) zsrandom1(z_rdefault, FALSE); + (void) zsrandom1(z_rdefault, false); /* * Otherwise non-zero seeds are processed as 1 arg calls */ } else { - (void) zsrandom1(seed, FALSE); + (void) zsrandom1(seed, false); } /* @@ -3118,9 +3118,9 @@ randomfree(RANDOM *state) * s2 - second state to compare * * return: - * TRUE if states differ + * true if states differ */ -BOOL +bool randomcmp(CONST RANDOM *s1, CONST RANDOM *s2) { /* @@ -3129,7 +3129,7 @@ randomcmp(CONST RANDOM *s1, CONST RANDOM *s2) if (!s1->seeded) { if (!s2->seeded) { /* uninitialized == uninitialized */ - return FALSE; + return false; } else { /* uninitialized only equals default state */ return randomcmp(s2, &init_blum); @@ -3143,14 +3143,14 @@ randomcmp(CONST RANDOM *s1, CONST RANDOM *s2) * compare operating mask parameters */ if ((s1->loglogn != s2->loglogn) || (s1->mask != s2->mask)) { - return TRUE; + return true; } /* * compare bit buffer */ if ((s1->bits != s2->bits) || (s1->buffer != s2->buffer)) { - return TRUE; + return true; } /* diff --git a/zrandom.h b/zrandom.h index 6cfc76d..a13485f 100644 --- a/zrandom.h +++ b/zrandom.h @@ -70,7 +70,7 @@ struct random { /* * Blum generator function declarations */ -E_FUNC RANDOM *zsrandom1(CONST ZVALUE seed, BOOL need_ret); +E_FUNC RANDOM *zsrandom1(CONST ZVALUE seed, bool need_ret); E_FUNC RANDOM *zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn); E_FUNC RANDOM *zsrandom4(CONST ZVALUE seed, CONST ZVALUE ip, CONST ZVALUE iq, long trials); @@ -82,7 +82,7 @@ E_FUNC void zrandomrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res); E_FUNC long irandom(long s); E_FUNC RANDOM *randomcopy(CONST RANDOM *random); E_FUNC void randomfree(RANDOM *random); -E_FUNC BOOL randomcmp(CONST RANDOM *s1, CONST RANDOM *s2); +E_FUNC bool randomcmp(CONST RANDOM *s1, CONST RANDOM *s2); E_FUNC void randomprint(CONST RANDOM *state, int flags); E_FUNC void random_libcalc_cleanup(void);