Compare commits

...

15 Commits

Author SHA1 Message Date
Landon Curt Noll
4bec694df3 Release calc version 2.12.7.0
The following are the changes from calc version 2.12.7.0 to date:

    Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.

    Fixed a problem where gcc complains about E_FUNC not being defined
    for Linux systems as reported by Martin Buck (m at rtin-buck dor de).

    Updated the help files help/config, help/display, help/epsilon,
    help/fprint, help/printf, and help/strprintf to give more
    examples of how display digits and epsilon precision interact
    with displaying values.

    Added more information about %g in the help file help/printf.

    The '\a' is now recognized in a printf format string as the
    single byte audible bell character (byte 0x07 in ASCII encoding).

    The following is a partial list of escape sequences recognized
    in strings and in printf formats:

        \a      audible bell    byte 0x07 in ASCII encoding
        \b      backspace       byte 0x08 in ASCII encoding
        \f      form feed       byte 0x0c in ASCII encoding
        \n      newline         byte 0x0b in ASCII encoding
        \r      return          byte 0x0a in ASCII encoding
        \t      tab             byte 0x0d in ASCII encoding
        \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:11:31 -08:00
Landon Curt Noll
4870a7a164 Sync check_include rule with Makefile.ship 2018-11-04 17:10:46 -08:00
Landon Curt Noll
84ccb37bc3 Regualrize escape characters
Regularized the case statements in qio.c, str.c, and token.c
that relate to escape characters.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:08:11 -08:00
Landon Curt Noll
29c6e9325f Fix issue with E_FUNC under linux
Fixed a problem where gcc complains about E_FUNC not being defined
for Linux systems as reported by Martin Buck (m at rtin-buck dor de).
2018-11-04 17:01:24 -08:00
Landon Curt Noll
81a4a4f828 Improve string and printing documentation
Updated the help files help/config, help/display, help/epsilon,
help/fprint, help/printf, and help/strprintf to give more
examples of how display digits and epsilon precision interact
with displaying values.

Added more information about %g in the help file help/printf.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:00:15 -08:00
Landon Curt Noll
1cdb5172d8 Fix Makefile lines that picky complains about 2018-10-19 19:41:58 -07:00
Landon Curt Noll
54a7a3f7bc Release 2.12.6.10
Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne <helmut at subdivi dot de> who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.
2018-10-19 19:33:57 -07:00
Landon Curt Noll
2ea77e6151 Release 2.12.6.9
Experimental changes for macOS builds.
2018-10-15 19:37:48 -07:00
Landon Curt Noll
5cfa6199e5 Merge branch '10110111-master' 2018-09-30 16:11:23 -07:00
Landon Curt Noll
da6ccc146f Improvements to %g pull request
This code %g is preliminary.

Fixed some code style issues to match the current code style.

Added regression tests and help file updates to printf and strprintf.

Fixed use of magic number -4: using -P instead.

Noted two problem areas with XXX comments in qio.c:

    1) need a qprintfg function
    2) re-write to not modify conf->outdigits
2018-09-30 16:06:28 -07:00
Landon Curt Noll
fcfe237375 Merge branch 'master' of https://github.com/10110111/calc into 10110111-master 2018-09-30 14:22:41 -07:00
Landon Curt Noll
5fb3db4558 Fixed trigonometric and hyperbolic core dumps 2018-09-30 14:08:20 -07:00
Landon Curt Noll
c8705c1198 Release calc 2.12.6.8
The following are the changes in this release:

    For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4.

    Fixed some compiler warnings, thanks to a report by Mike
    <michael dot d dot ince at gmail dot com>.

    Added work around for a gcc warning bug, thanks to a report by Mike
    <michael dot d dot ince at gmail dot com>.

    Fixed errors in various help files such as:

	mat randbit seed srandom types

    Removed the MAXSTRING symbol because it was no longer used by calc.

    Increased HIST_SIZE (depth of the history stack) from 10k to 32k.

    Increased TTYSIZE (reallocation size for terminal buffers) from 100 to 8191.

    Increased MAXDEPTH (maximum depth of input stack) from 10 to 255.

    Increased interactive input buffer size from 1024 to 256k.  This has the
    effect of increasing the maximum length of an input line from a tty.
    This helps with an interactive bug that was reported by Ruslan Kabatsayev
    (b7 dot 10110111 at gmail dot com).

    The calc man page indicates that -d also disables the printing of the
    leading tilde.

    Added information to "help command" about how to silence messages
    while reading calc resource files.

    Fixed an error message buffer overflow thanks to a report by
    Frank Peters <nlp at northernlightsphoto dot biz>.

    Replaced all use of the C funcion sprintf() with snprintf().
    Replaced all use of the C funcion vsprintf() with vsnprintf().
    Replaced all DONT_HAVE_VSPRINTF with DONT_HAVE_VSNPRINTF.
    Replaced all Makefile var ${HAVE_VSPRINTF} with ${HAVE_VSNPRINTF}.
2018-09-30 10:25:18 -07:00
Ruslan Kabatsayev
0558bafcb6 Use MODE_REAL_AUTO by default instead of MODE_REAL
This will save the user from embarrassment due to getting
~0.00000000000000000000 as the result instead of e.g. 1.23e-53.
2018-06-30 18:44:14 +03:00
Ruslan Kabatsayev
f58277f53d Implement %g format for printf 2018-06-30 18:35:35 +03:00
40 changed files with 903 additions and 399 deletions

96
CHANGES
View File

@@ -1,4 +1,84 @@
The following are the changes from calc version 2.12.6.6 to date: The following are the changes from calc version 2.12.7.0 to date:
Added a patch to replaces the manual search for include files
in $(INCDIR) in the have_*.h targets with compiler invocations.
Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
implemented the patch and posted it to the Debian bug tracker
and Martin Buck (m at rtin-buck dor de) for forwarding it to us.
The check_include make rule was fixed to not assume /usr/include.
The qprintnum() function now takes outdigits as a 3rd argument.
Most of the time, this 3rd argument is just conf->outdigits.
But when it comes to the experimental '%g', this value can
change. This avoids having to modify conf->outdigits.
Fixed a problem where gcc complains about E_FUNC not being defined
for Linux systems as reported by Martin Buck (m at rtin-buck dor de).
Updated the help files help/config, help/display, help/epsilon,
help/fprint, help/printf, and help/strprintf to give more
examples of how display digits and epsilon precision interact
with displaying values.
Added more information about %g in the help file help/printf.
The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).
The following is a partial list of escape sequences recognized
in strings and in printf formats:
\a audible bell byte 0x07 in ASCII encoding
\b backspace byte 0x08 in ASCII encoding
\f form feed byte 0x0c in ASCII encoding
\n newline byte 0x0b in ASCII encoding
\r return byte 0x0a in ASCII encoding
\t tab byte 0x0d in ASCII encoding
\v vertical tab byte 0x09 in ASCII encoding
The following are the changes from calc version 2.12.6.9 to 2.12.6.9:
Fixed a number of core dump bugs related to the calculation of
tan(), cot(), sec(), csc(), tanh(), coth(), sech(), and csch(),
asin(), acos(), asinh(), acosh(), where when a call to an
underlying function produced an invalid value. Thanks goes to
github user wuxiuheng for reporting this problem.
A number of trigonometric and hyperbolic functions that incorrectly
returned E_LOGINF, now return a new error code that is more
specific to the trigonometric or hyperbolic function. The
following is a list of these new error codes: E_TAN3 E_TAN4
E_COT3 E_COT4 E_SEC3 E_CSC3 E_TANH3 E_TANH4 E_COTH3 E_COTH4
E_SECH3 E_CSCH3 E_ASIN3 E_ACOS3 E_ASINH3 E_ACOSH3 E_ATAN3 E_ACOT3
E_ASEC3 E_ACSC3 E_ATANH3 E_ACOTH3 E_ASECH3 E_ACSCH3.
Added regression tests 3729 thru 3732 to test E_TAN3, E_COT3,
E_SEC3 and E_CSC3 respectively.
Added experimential %g printf (and strprintf) format implementation
based on pull request from github user 10110111.
Made exterimental changes to macOS builds to not require use of
/usr/include. The INCDIR for macOS uses:
INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include
to determine the upper path of the /usr/include directory for macOS.
In some rare cases, the Darwin target seems to not automatically detected.
If you are running under macOS, and that happens, you can force
the target to be Darwin:
# for macOS users only, force the target to be darwin
#
make target=Darwin clobber
make target=Darwin all
make target=Darwin chk
make target=Darwin install
The following are the changes from calc version 2.12.6.6 to 2.12.6.8:
For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4. For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4.
@@ -25,6 +105,20 @@ The following are the changes from calc version 2.12.6.6 to date:
This helps with an interactive bug that was reported by Ruslan Kabatsayev This helps with an interactive bug that was reported by Ruslan Kabatsayev
(b7 dot 10110111 at gmail dot com). (b7 dot 10110111 at gmail dot com).
The calc man page indicates that -d also disables the printing of the
leading tilde.
Added information to "help command" about how to silence messages
while reading calc resource files.
Fixed an error message buffer overflow thanks to a report by
Frank Peters <nlp at northernlightsphoto dot biz>.
Replaced all use of the C funcion sprintf() with snprintf().
Replaced all use of the C funcion vsprintf() with vsnprintf().
Replaced all DONT_HAVE_VSPRINTF with DONT_HAVE_VSNPRINTF.
Replaced all Makefile var ${HAVE_VSPRINTF} with ${HAVE_VSNPRINTF}.
The following are the changes from calc version 2.12.6.4 to 2.12.6.5: The following are the changes from calc version 2.12.6.4 to 2.12.6.5:

View File

@@ -32,6 +32,16 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
targets, the default make is sufficent. On FreeBSD for example, targets, the default make is sufficent. On FreeBSD for example,
one must use gmake instead of make. one must use gmake instead of make.
Some report that under macOS, one has to declare the target
to be darwin. So for macOS, one might have to do:
# for macOS users only, force the target to be darwin
#
make target=Darwin clobber
make target=Darwin all
make target=Darwin chk
make target=Darwin install
If your target system does not have GNU Make (or equivalent), then If your target system does not have GNU Make (or equivalent), then
you should try using the Makefile.simple and custom/Makefile.simple you should try using the Makefile.simple and custom/Makefile.simple
files: files:

View File

@@ -207,30 +207,9 @@ all: fix_version check_include
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-=' ${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
check_include: check_include:
$(Q) if [ ! -d /usr/include ]; then \ ${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
echo "ERROR: critical directory missing: /usr/include" 1>&2; \ ${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
echo "Without this critical directory, we cannot compile." 1>&2; \ ${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo 1>&2; \
exit 1; \
fi
$(Q) if [ ! -f /usr/include/stdio.h ]; then \
echo "ERROR: critical include files are missing" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \
echo " xcode-select --install" 1>&2; \
echo 1>&2; \
exit 1; \
fi
calc-dynamic-only: calc-dynamic-only:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-=' ${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='

View File

@@ -90,29 +90,29 @@ TERMCONTROL=
#TERMCONTROL= -DUSE_SGTTY #TERMCONTROL= -DUSE_SGTTY
#TERMCONTROL= -DUSE_WIN32 #TERMCONTROL= -DUSE_WIN32
# If your system does not have a vsprintf() function, you could be in trouble. # If your system does not have a vsnprintf() function, you could be in trouble.
# #
# vsprintf(string, format, ap) # vsnprintf(string, size, format, ap)
# #
# This function works like sprintf except that the 3rd arg is a va_list # This function works like spnrintf except that the 4th arg is a va_list
# strarg (or varargs) list. Some old systems do not have vsprintf(). # strarg (or varargs) list. Some old systems do not have vsnprintf().
# If you do not have vsprintf(), then calc will try sprintf() and hope # If you do not have vsnprintf(), then calc will try snprintf() and hope
# for the best. # for the best.
# #
# A similar problem occurs if your system does not have a vsnprintf() # A similar problem occurs if your system does not have a vsnprintf()
# function. This function is like the vsprintf() function except that # function. This function is like the vsnprintf() function except that
# there is an extra second argument that controls the maximum size # there is an extra second argument that controls the maximum size
# string that is produced. # string that is produced.
# #
# If HAVE_VSPRINTF is empty, this Makefile will run the have_stdvs.c and/or # If HAVE_VSNPRINTF is empty, this Makefile will run the have_stdvs.c and/or
# have_varvs.c program to determine if vsprintf() is supported. If # have_varvs.c program to determine if vsnprintf() is supported. If
# HAVE_VSPRINTF is set to -DDONT_HAVE_VSPRINTF then calc will hope that # HAVE_VSNPRINTF is set to -DDONT_HAVE_VSNPRINTF then calc will hope that
# sprintf() will work. # snprintf() will work.
# #
# If in doubt, leave HAVE_VSPRINTF empty. # If in doubt, leave HAVE_VSNPRINTF empty.
# #
HAVE_VSPRINTF= HAVE_VSNPRINTF=
#HAVE_VSPRINTF= -DDONT_HAVE_VSPRINTF #HAVE_VSNPRINTF= -DDONT_HAVE_VSNPRINTF
# Determine the byte order of your machine # Determine the byte order of your machine
# #
@@ -575,7 +575,7 @@ HAVE_UNUSED=
ifeq ($(target),Darwin) ifeq ($(target),Darwin)
# default INCDIR for macOS # default INCDIR for macOS
INCDIR= /usr/local/include INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include
else else
#endif /* end of skip for non-Gnu makefiles */ #endif /* end of skip for non-Gnu makefiles */
@@ -1054,7 +1054,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.7 VERSION= 2.12.7.0
# Names of shared libraries with versions # Names of shared libraries with versions
# #
@@ -2179,25 +2179,15 @@ TARGETS= ${EARLY_TARGETS} ${BLD_TYPE} ${LATE_TARGETS}
all: check_include ${BLD_TYPE} CHANGES all: check_include ${BLD_TYPE} CHANGES
check_include: check_include:
$(Q) if [ ! -d /usr/include ]; then \ $(Q) if ! echo '#include <stdio.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo "ERROR: critical directory missing: /usr/include" 1>&2; \ echo "ERROR: Missing critical <stdio.h> include file." 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \ echo "Without critical include files, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \ echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \ echo 1>&2; \
echo " xcode-select --install" 1>&2; \ echo "For example, Apple macOS / Darwin requres that XCode" 1>&2; \
echo "must be installed." 1>&2; \
echo 1>&2; \ echo 1>&2; \
exit 1; \ echo "Also macOS users might later to run this command:" 1>&2; \
fi
$(Q) if [ ! -f /usr/include/stdio.h ]; then \
echo "ERROR: critical include files are missing" 1>&2; \
echo "Without this critical directory, we cannot compile." 1>&2; \
echo 1>&2; \
echo "Perhaps your system isn't setup to compile C source?" 1>&2; \
echo "For example, Apple OS X / darwin requres that XCode" 1>&2; \
echo "must be installed and that you run the command:" 1>&2; \
echo 1>&2; \ echo 1>&2; \
echo " xcode-select --install" 1>&2; \ echo " xcode-select --install" 1>&2; \
echo 1>&2; \ echo 1>&2; \
@@ -2477,22 +2467,15 @@ endian_calc.h: endian${EXT} ${MAKE_FILE}
${Q} echo '' >> endian_calc.h ${Q} echo '' >> endian_calc.h
${Q} echo '/* what byte order are we? */' >> endian_calc.h ${Q} echo '/* what byte order are we? */' >> endian_calc.h
-${Q} if [ X"${CALC_BYTE_ORDER}" = X ]; then \ -${Q} if [ X"${CALC_BYTE_ORDER}" = X ]; then \
if [ -f ${INCDIR}/endian.h ]; then \ if echo '#include <endian.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#include <endian.h>' >> endian_calc.h; \ echo '#include <endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \ echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f ${INCDIR}/machine/endian.h ]; then \ elif echo '#include <machine/endian.h>' | \
${CC} -E - >/dev/null 2>&1; then \
echo '#include <machine/endian.h>' >> endian_calc.h; \ echo '#include <machine/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \ echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f ${INCDIR}/sys/endian.h ]; then \ elif echo '#include <sys/endian.h>' | \
echo '#include <sys/endian.h>' >> endian_calc.h; \ ${CC} -E- >/dev/null 2>&1; then \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/endian.h ]; then \
echo '#include <endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/machine/endian.h ]; then \
echo '#include <machine/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
elif [ -f /usr/include/sys/endian.h ]; then \
echo '#include <sys/endian.h>' >> endian_calc.h; \ echo '#include <sys/endian.h>' >> endian_calc.h; \
echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \ echo '#define CALC_BYTE_ORDER BYTE_ORDER' >> endian_calc.h; \
else \ else \
@@ -2559,9 +2542,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \ echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_TIMES_H}" = X"NO" ]; then \ elif [ X"${HAVE_TIMES_H}" = X"NO" ]; then \
echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \ echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/times.h ]; then \ elif echo '#include <times.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/times.h ]; then \
echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \ echo '#define HAVE_TIMES_H /* yes */' >> have_times.h; \
else \ else \
echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \ echo '#undef HAVE_TIMES_H /* no */' >> have_times.h; \
@@ -2570,9 +2551,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \ echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_SYS_TIMES_H}" = X"NO" ]; then \ elif [ X"${HAVE_SYS_TIMES_H}" = X"NO" ]; then \
echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \ echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/sys/times.h ]; then \ elif echo '#include <sys/times.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/sys/times.h ]; then \
echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \ echo '#define HAVE_SYS_TIMES_H /* yes */' >> have_times.h; \
else \ else \
echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \ echo '#undef HAVE_SYS_TIMES_H /* no */' >> have_times.h; \
@@ -2581,9 +2560,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \ echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_TIME_H}" = X"NO" ]; then \ elif [ X"${HAVE_TIME_H}" = X"NO" ]; then \
echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \ echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/time.h ]; then \ elif echo '#include <time.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/time.h ]; then \
echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \ echo '#define HAVE_TIME_H /* yes */' >> have_times.h; \
else \ else \
echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \ echo '#undef HAVE_TIME_H /* no */' >> have_times.h; \
@@ -2592,9 +2569,7 @@ have_times.h: ${MAKE_FILE}
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \ echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
elif [ X"${HAVE_SYS_TIME_H}" = X"NO" ]; then \ elif [ X"${HAVE_SYS_TIME_H}" = X"NO" ]; then \
echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \ echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \
elif [ -f ${INCDIR}/sys/time.h ]; then \ elif echo '#include <sys/time.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
elif [ -f /usr/include/sys/time.h ]; then \
echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \ echo '#define HAVE_SYS_TIME_H /* yes */' >> have_times.h; \
else \ else \
echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \ echo '#undef HAVE_SYS_TIME_H /* no */' >> have_times.h; \
@@ -2630,9 +2605,7 @@ have_stdlib.h: ${MAKE_FILE}
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \ echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
elif [ X"${HAVE_STDLIB_H}" = X"NO" ]; then \ elif [ X"${HAVE_STDLIB_H}" = X"NO" ]; then \
echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \ echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \
elif [ -f ${INCDIR}/stdlib.h ]; then \ elif echo '#include <stdlib.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
elif [ -f /usr/include/stdlib.h ]; then \
echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \ echo '#define HAVE_STDLIB_H /* yes */' >> have_stdlib.h; \
else \ else \
echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \ echo '#undef HAVE_STDLIB_H /* no */' >> have_stdlib.h; \
@@ -2668,9 +2641,7 @@ have_unistd.h: ${MAKE_FILE}
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \ echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
elif [ X"${HAVE_UNISTD_H}" = X"NO" ]; then \ elif [ X"${HAVE_UNISTD_H}" = X"NO" ]; then \
echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \ echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \
elif [ -f ${INCDIR}/unistd.h ]; then \ elif echo '#include <unistd.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
elif [ -f /usr/include/unistd.h ]; then \
echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \ echo '#define HAVE_UNISTD_H /* yes */' >> have_unistd.h; \
else \ else \
echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \ echo '#undef HAVE_UNISTD_H /* no */' >> have_unistd.h; \
@@ -2706,9 +2677,7 @@ have_string.h: ${MAKE_FILE}
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \ echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
elif [ X"${HAVE_STRING_H}" = X"NO" ]; then \ elif [ X"${HAVE_STRING_H}" = X"NO" ]; then \
echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \ echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \
elif [ -f ${INCDIR}/string.h ]; then \ elif echo '#include <string.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
elif [ -f /usr/include/string.h ]; then \
echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \ echo '#define HAVE_STRING_H /* yes */' >> have_string.h; \
else \ else \
echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \ echo '#undef HAVE_STRING_H /* no */' >> have_string.h; \
@@ -2748,22 +2717,12 @@ terminal.h: ${MAKE_FILE}
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \ echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \ echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \ echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f ${INCDIR}/termios.h ]; then \ elif echo '#include <termios.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '/* use termios */' >> terminal.h; \ echo '/* use termios */' >> terminal.h; \
echo '#define USE_TERMIOS /* <termios.h> */' >> terminal.h; \ echo '#define USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \ echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \ echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f ${INCDIR}/termio.h ]; then \ elif echo '#include <termio.h>' | ${CC} -E - >/dev/null 2>&1; then \
echo '/* use termio */' >> terminal.h; \
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#define USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f /usr/include/termios.h ]; then \
echo '/* use termios */' >> terminal.h; \
echo '#define USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#undef USE_TERMIO /* <termio.h> */' >> terminal.h; \
echo '#undef USE_SGTTY /* <sys/ioctl.h> */' >> terminal.h; \
elif [ -f /usr/include/termio.h ]; then \
echo '/* use termio */' >> terminal.h; \ echo '/* use termio */' >> terminal.h; \
echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \ echo '#undef USE_TERMIOS /* <termios.h> */' >> terminal.h; \
echo '#define USE_TERMIO /* <termio.h> */' >> terminal.h; \ echo '#define USE_TERMIO /* <termio.h> */' >> terminal.h; \
@@ -3545,7 +3504,7 @@ args.h: have_stdvs.c have_varvs.c have_string.h have_unistd.h have_string.h
${Q} echo '' >> args.h ${Q} echo '' >> args.h
${Q} echo '' >> args.h ${Q} echo '' >> args.h
${Q} ${RM} -f have_stdvs.o have_stdvs${EXT} ${Q} ${RM} -f have_stdvs.o have_stdvs${EXT}
-${Q} ${LCC} ${ICFLAGS} ${HAVE_VSPRINTF} have_stdvs.c -c \ -${Q} ${LCC} ${ICFLAGS} ${HAVE_VSNPRINTF} have_stdvs.c -c \
>/dev/null 2>&1; ${TRUE} >/dev/null 2>&1; ${TRUE}
-${Q} ${LCC} ${ILDFLAGS} have_stdvs.o -o have_stdvs${EXT} \ -${Q} ${LCC} ${ILDFLAGS} have_stdvs.o -o have_stdvs${EXT} \
>/dev/null 2>&1; ${TRUE} >/dev/null 2>&1; ${TRUE}
@@ -3554,10 +3513,10 @@ args.h: have_stdvs.c have_varvs.c have_string.h have_unistd.h have_string.h
else \ else \
${TRUE}; \ ${TRUE}; \
fi fi
-${Q} if [ ! -f have_args.sh ] && [ X"${HAVE_VSPRINTF}" = X ]; then \ -${Q} if [ ! -f have_args.sh ] && [ X"${HAVE_VSNPRINTF}" = X ]; then \
${RM} -f have_stdvs.o have_stdvs${EXT} have_varvs.o; \ ${RM} -f have_stdvs.o have_stdvs${EXT} have_varvs.o; \
${RM} -f have_varvs${EXT}; \ ${RM} -f have_varvs${EXT}; \
${LCC} ${ICFLAGS} ${HAVE_VSPRINTF} have_varvs.c -c \ ${LCC} ${ICFLAGS} ${HAVE_VSNPRINTF} have_varvs.c -c \
2>/dev/null; \ 2>/dev/null; \
${LCC} ${ILDFLAGS} have_varvs.o -o have_varvs${EXT} 2>/dev/null; \ ${LCC} ${ILDFLAGS} have_varvs.o -o have_varvs${EXT} 2>/dev/null; \
if ./have_varvs${EXT} >>args.h 2>/dev/null; then \ if ./have_varvs${EXT} >>args.h 2>/dev/null; then \
@@ -3573,8 +3532,8 @@ args.h: have_stdvs.c have_varvs.c have_string.h have_unistd.h have_string.h
else \ else \
echo 'exit 1' > have_args.sh; \ echo 'exit 1' > have_args.sh; \
echo "Unable to determine what type of variable args and"; \ echo "Unable to determine what type of variable args and"; \
echo "what type of vsprintf() should be used. Set or change"; \ echo "what type of vsnprintf() should be used. Set or change"; \
echo "the Makefile variable HAVE_VSPRINTF."; \ echo "the Makefile variable HAVE_VSNPRINTF."; \
fi fi
${Q} sh ./have_args.sh ${Q} sh ./have_args.sh
${Q} echo '' >> args.h ${Q} echo '' >> args.h
@@ -4160,7 +4119,7 @@ env:
@echo 'HAVE_UNUSED=${HAVE_UNUSED}'; echo '' @echo 'HAVE_UNUSED=${HAVE_UNUSED}'; echo ''
@echo 'HAVE_URANDOM_H=${HAVE_URANDOM_H}'; echo '' @echo 'HAVE_URANDOM_H=${HAVE_URANDOM_H}'; echo ''
@echo 'HAVE_USTAT=${HAVE_USTAT}'; echo '' @echo 'HAVE_USTAT=${HAVE_USTAT}'; echo ''
@echo 'HAVE_VSPRINTF=${HAVE_VSPRINTF}'; echo '' @echo 'HAVE_VSNPRINTF=${HAVE_VSNPRINTF}'; echo ''
@echo 'HELPDIR=${HELPDIR}'; echo '' @echo 'HELPDIR=${HELPDIR}'; echo ''
@echo 'HELP_PASSDOWN=${HELP_PASSDOWN}'; echo '' @echo 'HELP_PASSDOWN=${HELP_PASSDOWN}'; echo ''
@echo 'H_SRC=${H_SRC}'; echo '' @echo 'H_SRC=${H_SRC}'; echo ''

View File

@@ -3227,9 +3227,9 @@ define test_error()
print '3600: Beginning test_error'; print '3600: Beginning test_error';
/* bump ecnt up by 148 */ /* bump ecnt up by 156 */
ecnt += 148; ecnt += 156;
print '3601: ecnt += 148'; print '3601: ecnt += 156';
strx = "x"; strx = "x";
print '3602: strx = "x"'; print '3602: strx = "x"';
@@ -3418,11 +3418,15 @@ define test_error()
n = 8191; n = 8191;
print '3727: n = 8191'; print '3727: n = 8191';
/* test 3728 removed due to non-portable strerror() output */ /* test 3728 removed due to non-portable strerror() output */
vrfy(tan(2e9i) == error(10435), '3729: tan(2e9i) == error(10435)');
vrfy(cot(2e9i) == error(10437), '3730: cot(2e9i) == error(10437)');
vrfy(sec(2e9i) == error(10439), '3731: sec(2e9i) == error(10439)');
vrfy(csc(2e9i) == error(10440), '3732: csc(2e9i) == error(10440)');
/* errmax and errcount should be bumped up the 148 errors above */ /* errmax and errcount should be bumped up the 148 errors above */
vrfy(errcount() == ecnt, '3729: errcount() == ecnt'); vrfy(errcount() == ecnt, '3733: errcount() == ecnt');
print '3730: Ending test_error'; print '3734: Ending test_error';
} }
print '054: parsed test_error()'; print '054: parsed test_error()';
@@ -4102,38 +4106,46 @@ define test_strprintf()
'4821: strprintf("%b", 27/29) == "0b11011/0b11101"'); '4821: strprintf("%b", 27/29) == "0b11011/0b11101"');
vrfy(strprintf("%e", 12345) == "~1.23e4", vrfy(strprintf("%e", 12345) == "~1.23e4",
'4822: strprintf("%e", 12345) == "~1.23e4"'); '4822: strprintf("%e", 12345) == "~1.23e4"');
vrfy(strprintf("%g", .385) == "~.38",
'4823: strprintf("%g", .385) == "~.38"');
vrfy(strprintf("%g", 385) == "~3.8e2",
'4824: strprintf("%g", 385) == "~3.8e2"');
/* mode tests with tilde == 0 */ /* mode tests with tilde == 0 */
c = config("tilde", 0); c = config("tilde", 0);
print '4823: c = config("tilde", 0)'; print '4825: c = config("tilde", 0)';
vrfy(strprintf("%e", 12345) == "1.23e4", vrfy(strprintf("%e", 12345) == "1.23e4",
'4824: strprintf("%e", 12345) == "1.23e4"'); '4826: strprintf("%e", 12345) == "1.23e4"');
vrfy(strprintf("%.3e", 12345) == "1.234e4", vrfy(strprintf("%.3e", 12345) == "1.234e4",
'4825: strprintf("%.3e", 12345) == "1.234e4"'); '4827: strprintf("%.3e", 12345) == "1.234e4"');
vrfy(strprintf("%e", .00012345) == "1.23e-4", vrfy(strprintf("%e", .00012345) == "1.23e-4",
'4826: strprintf("%e", .00012345) == "1.23e-4"'); '4828: strprintf("%e", .00012345) == "1.23e-4"');
vrfy(strprintf("%d %d", 27) == "27 ", vrfy(strprintf("%d %d", 27) == "27 ",
'4827: strprintf("%d %d", 27) == "27 "'); '4829: strprintf("%d %d", 27) == "27 "');
vrfy(strprintf("%d", 27, 29) == "27", vrfy(strprintf("%d", 27, 29) == "27",
'4828: strprintf("%d", 27, 29) == "27"'); '4830: strprintf("%d", 27, 29) == "27"');
vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93", vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93",
'4829: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"'); '4831: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"');
vrfy(strprintf("%s", "abc") == "abc", vrfy(strprintf("%s", "abc") == "abc",
'4830: strprintf("%s", "abc") == "abc"'); '4832: strprintf("%s", "abc") == "abc"');
vrfy(strprintf("%f", "abc") == "abc", vrfy(strprintf("%f", "abc") == "abc",
'4831: strprintf("%f", "abc") == "abc"'); '4833: strprintf("%f", "abc") == "abc"');
vrfy(strprintf("%e", "abc") == "abc", vrfy(strprintf("%e", "abc") == "abc",
'4832: strprintf("%e", "abc") == "abc"'); '4834: strprintf("%e", "abc") == "abc"');
vrfy(strprintf("%5s", "abc") == " abc", vrfy(strprintf("%5s", "abc") == " abc",
'4833: strprintf("%5s", "abc") == " abc"'); '4835: strprintf("%5s", "abc") == " abc"');
vrfy(strprintf("%-5s", "abc") == "abc ", vrfy(strprintf("%-5s", "abc") == "abc ",
'4834: strprintf("%-5s", "abc") == "abc "'); '4836: strprintf("%-5s", "abc") == "abc "');
vrfy(strprintf("%g", .385) == ".38",
'4837: strprintf("%g", .385) == ".38"');
vrfy(strprintf("%g", 385) == "3.8e2",
'4838: strprintf("%g", 385) == "3.8e2"');
/* restore config */ /* restore config */
c = config("all", callcfg); c = config("all", callcfg);
print '4835: c = config("all", callcfg)'; print '4839: c = config("all", callcfg)';
print '4836: Ending test_strprintf'; print '4840: Ending test_strprintf';
} }
print '088: parsed test_fileop()'; print '088: parsed test_fileop()';
@@ -7932,8 +7944,8 @@ print '8901: read -once "test8900"';
read -once "test8900"; read -once "test8900";
print '8902: about to run test8900(1,,8903)'; print '8902: about to run test8900(1,,8903)';
testnum = test8900(1,,8903); testnum = test8900(1,,8903);
print '8999: ecnt = 203;' print '8999: ecnt = 211;'
ecnt = 203; ecnt = 211;
/* 89xx: test calc resource functions by Christoph Zurnieden */ /* 89xx: test calc resource functions by Christoph Zurnieden */

2
calc.c
View File

@@ -775,7 +775,7 @@ calc_interrupt(char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(calc_err_msg, MAXERROR, fmt, ap); vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
va_end(ap); va_end(ap);
calc_err_msg[MAXERROR] = '\0'; calc_err_msg[MAXERROR] = '\0'; /* paranoia */
fprintf(stderr, "%s\n\n", calc_err_msg); fprintf(stderr, "%s\n\n", calc_err_msg);
funcname = NULL; funcname = NULL;
if (calc_use_scanerr_jmpbuf != 0) { if (calc_use_scanerr_jmpbuf != 0) {

View File

@@ -1,5 +1,5 @@
.\" .\"
.\" Copyright (C) 1999-2007,2014 Landon Curt Noll .\" Copyright (C) 1999-2007,2014,2018 Landon Curt Noll
.\" .\"
.\" Calc is open software; you can redistribute it and/or modify it under .\" Calc is open software; you can redistribute it and/or modify it under
.\" the terms of the version 2.1 of the GNU Lesser General Public License .\" the terms of the version 2.1 of the GNU Lesser General Public License
@@ -138,7 +138,7 @@ calc -d "read qtime; qtime(2)"
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
will just say: will just print:
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
@@ -148,6 +148,41 @@ It's nearly ten past six.
.sp 1 .sp 1
This flag disables the reporting of missing calc This flag disables the reporting of missing calc
startup resource files. startup resource files.
.sp 1
This flag also disables the printing the leading tilde. For example:
.sp 1
.in +5n
.nf
calc 2/3
.fi
.in -5n
.sp 1
will print:
.sp 1
.in +5n
.nf
~0.66666666666666666667
.fi
.in -5n
.sp 1
.sp 1
whereas:
.sp 1
.in +5n
.nf
calc -d 2/3
.fi
.in -5n
.sp 1
will just print:
.sp 1
.in +5n
.nf
0.66666666666666666667
.fi
.in -5n
.sp 1
.TP .TP
.BR -D " calc_debug[:resource_debug[:user_debug]]" .BR -D " calc_debug[:resource_debug[:user_debug]]"

View File

@@ -451,6 +451,7 @@ E_FPATHOPEN1 Non-string arguments for fpathopen
E_FPATHOPEN2 Unrecognized mode for fpathopen E_FPATHOPEN2 Unrecognized mode for fpathopen
E_LOG1 Bad epsilon argument for log E_LOG1 Bad epsilon argument for log
E_LOG2 Non-numeric first argument for log E_LOG2 Non-numeric first argument for log
E_LOG3 Cannot calculate log for this value
E_FGETFILE1 Non-file argument for fgetfile E_FGETFILE1 Non-file argument for fgetfile
E_FGETFILE2 File argument for fgetfile not open for reading E_FGETFILE2 File argument for fgetfile not open for reading
E_FGETFILE3 Unable to set file position in fgetfile E_FGETFILE3 Unable to set file position in fgetfile
@@ -471,3 +472,27 @@ E_ISSPACE Bad argument for isspace
E_ISXDIGIT Bad argument for isxdigit E_ISXDIGIT Bad argument for isxdigit
E_STRTOUPPER Bad argument type for strtoupper E_STRTOUPPER Bad argument type for strtoupper
E_STRTOLOWER Bad argument type for strtolower E_STRTOLOWER Bad argument type for strtolower
E_TAN3 Invalid value for calculating the sin numerator for tan
E_TAN4 Invalid value for calculating the cos denominator for tan
E_COT3 Invalid value for calculating the sin numerator for cot
E_COT4 Invalid value for calculating the cos denominator for cot
E_SEC3 Invalid value for calculating the cos reciprocal for sec
E_CSC3 Invalid value for calculating the sin reciprocal for csc
E_TANH3 Invalid value for calculating the sinh numerator for tanh
E_TANH4 Invalid value for calculating the cosh denominator for tanh
E_COTH3 Invalid value for calculating the sinh numerator for coth
E_COTH4 Invalid value for calculating the cosh denominator for coth
E_SECH3 Invalid value for calculating the cosh reciprocal for sech
E_CSCH3 Invalid value for calculating the sinh reciprocal for csch
E_ASIN3 Invalid value for calculating asin
E_ACOS3 Invalid value for calculating acos
E_ASINH3 Invalid value for calculating asinh
E_ACOSH3 Invalid value for calculating acosn
E_ATAN3 Invalid value for calculating atan
E_ACOT3 Invalid value for calculating acot
E_ASEC3 Invalid value for calculating asec
E_ACSC3 Invalid value for calculating acsc
E_ATANH3 Invalid value for calculating atan
E_ACOTH3 Invalid value for calculating acot
E_ASECH3 Invalid value for calculating asec
E_ACSCH3 Invalid value for calculating acsc

View File

@@ -1182,7 +1182,7 @@ comprint(COMPLEX *c)
return; return;
} }
if (!qiszero(c->real) || qiszero(c->imag)) if (!qiszero(c->real) || qiszero(c->imag))
qprintnum(c->real, MODE_DEFAULT); qprintnum(c->real, MODE_DEFAULT, conf->outdigits);
qtmp = c->imag[0]; qtmp = c->imag[0];
if (qiszero(&qtmp)) if (qiszero(&qtmp))
return; return;
@@ -1192,7 +1192,7 @@ comprint(COMPLEX *c)
math_chr('-'); math_chr('-');
qtmp.num.sign = 0; qtmp.num.sign = 0;
} }
qprintnum(&qtmp, MODE_DEFAULT); qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
math_chr('i'); math_chr('i');
} }

View File

@@ -274,6 +274,7 @@ STATIC NAMETYPE modes[] = {
{"oct", MODE_OCTAL}, {"oct", MODE_OCTAL},
{"binary", MODE_BINARY}, {"binary", MODE_BINARY},
{"bin", MODE_BINARY}, {"bin", MODE_BINARY},
{"float-auto", MODE_REAL_AUTO},
{"off", MODE2_OFF}, {"off", MODE2_OFF},
{NULL, 0} {NULL, 0}
}; };

View File

@@ -1,7 +1,7 @@
/* /*
* custom - interface for custom software and hardware interfaces * custom - interface for custom software and hardware interfaces
* *
* Copyright (C) 1999-2006 Landon Curt Noll * Copyright (C) 1999-2006,2018 Landon Curt Noll
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -180,6 +180,7 @@ customhelp(char *name)
#if defined(CUSTOM) #if defined(CUSTOM)
char *customname; /* a string of the form: custom/name */ char *customname; /* a string of the form: custom/name */
size_t snprintf_len; /* malloced snprintf buffer length */
/* /*
* firewall * firewall
@@ -191,12 +192,14 @@ customhelp(char *name)
/* /*
* form the custom help name * form the custom help name
*/ */
customname = (char *)malloc(sizeof("custhelp")+1+strlen(name)+1); snprintf_len = sizeof("custhelp")+1+strlen(name)+1;
customname = (char *)malloc(snprintf_len+1);
if (customname == NULL) { if (customname == NULL) {
math_error("bad malloc of customname"); math_error("bad malloc of customname");
/*NOTREACHED*/ /*NOTREACHED*/
} }
sprintf(customname, "custhelp/%s", name); snprintf(customname, snprintf_len, "custhelp/%s", name);
customname[snprintf_len] = '\0'; /* paranoia */
/* /*
* give help directly to the custom file * give help directly to the custom file

View File

@@ -2,7 +2,7 @@
# #
# custom - makefile for calc custom routines # custom - makefile for calc custom routines
# #
# Copyright (C) 1999-2006,2014,2017 Landon Curt Noll # Copyright (C) 1999-2006,2014,2017-2018 Landon Curt Noll
# #
# Calc is open software; you can redistribute it and/or modify it under # Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License # the terms of the version 2.1 of the GNU Lesser General Public License
@@ -348,7 +348,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.7 VERSION= 2.12.7.0
# Names of shared libraries with versions # Names of shared libraries with versions
# #

View File

@@ -2,7 +2,7 @@
# #
# custom - makefile for calc custom routines # custom - makefile for calc custom routines
# #
# Copyright (C) 1999-2006,2014,2017 Landon Curt Noll # Copyright (C) 1999-2006,2014,2017-2018 Landon Curt Noll
# #
# Calc is open software; you can redistribute it and/or modify it under # Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License # the terms of the version 2.1 of the GNU Lesser General Public License
@@ -348,7 +348,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.7 VERSION= 2.12.7.0
# Names of shared libraries with versions # Names of shared libraries with versions
# #

13
file.c
View File

@@ -1,7 +1,7 @@
/* /*
* file - file I/O routines callable by users * file - file I/O routines callable by users
* *
* Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll * Copyright (C) 1999-2007,2018 David I. Bell and Landon Curt Noll
* *
* Primary author: David I. Bell * Primary author: David I. Bell
* *
@@ -143,6 +143,7 @@ file_init(void)
* stat the descriptor to see what we have * stat the descriptor to see what we have
*/ */
if (fstat(i, &sbuf) >= 0) { if (fstat(i, &sbuf) >= 0) {
size_t snprintf_len; /* malloced snprintf length */
fp = (FILE *) fdopen(i,"r+"); /*guess mode*/ fp = (FILE *) fdopen(i,"r+"); /*guess mode*/
if (fp) { if (fp) {
strcpy(files[idnum].mode, "r+"); strcpy(files[idnum].mode, "r+");
@@ -161,12 +162,15 @@ file_init(void)
continue; continue;
} }
} }
tname = (char *)malloc(sizeof("descriptor[19]")); snprintf_len =
sizeof("descriptor[12345678901234567890]") + 1;
tname = (char *)malloc(snprintf_len+1);
if (tname == NULL) { if (tname == NULL) {
math_error("Out of memory for init_file"); math_error("Out of memory for init_file");
/*NOTREACHED*/ /*NOTREACHED*/
} }
sprintf(tname, "descriptor[%d]", i); snprintf(tname, snprintf_len, "descriptor[%d]", i);
tname[snprintf_len] = '\0'; /* paranoia */
files[idnum].name = tname; files[idnum].name = tname;
files[idnum].id = idnum; files[idnum].id = idnum;
files[idnum].fp = fp; files[idnum].fp = fp;
@@ -1027,6 +1031,9 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
case 'e': case 'e':
newmode = MODE_EXP; newmode = MODE_EXP;
break; break;
case 'g':
newmode = MODE_REAL_AUTO;
break;
case 'r': case 'r':
newmode = MODE_FRAC; newmode = MODE_FRAC;
break; break;

121
func.c
View File

@@ -1,7 +1,7 @@
/* /*
* func - built-in functions implemented here * func - built-in functions implemented here
* *
* Copyright (C) 1999-2007 David I. Bell, Landon Curt Noll and Ernest Bowen * Copyright (C) 1999-2007,2018 David I. Bell, Landon Curt Noll & Ernest Bowen
* *
* Primary author: David I. Bell * Primary author: David I. Bell
* *
@@ -335,7 +335,7 @@ f_str(VALUE *vp)
break; break;
case V_NUM: case V_NUM:
math_divertio(); math_divertio();
qprintnum(vp->v_num, MODE_DEFAULT); qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits);
cp = math_getdivertedio(); cp = math_getdivertedio();
result.v_str = makestring(cp); result.v_str = makestring(cp);
break; break;
@@ -2122,6 +2122,9 @@ f_log(int count, VALUE **vals)
default: default:
return error_value(E_LOG2); return error_value(E_LOG2);
} }
if (c == NULL) {
return error_value(E_LOG3);
}
result.v_type = V_COM; result.v_type = V_COM;
result.v_com = c; result.v_com = c;
if (cisreal(c)) { if (cisreal(c)) {
@@ -2239,8 +2242,15 @@ f_tan(int count, VALUE **vals)
case V_COM: case V_COM:
tmp1.v_type = V_COM; tmp1.v_type = V_COM;
tmp1.v_com = c_sin(vals[0]->v_com, err); tmp1.v_com = c_sin(vals[0]->v_com, err);
if (tmp1.v_com == NULL) {
return error_value(E_TAN3);
}
tmp2.v_type = V_COM; tmp2.v_type = V_COM;
tmp2.v_com = c_cos(vals[0]->v_com, err); tmp2.v_com = c_cos(vals[0]->v_com, err);
if (tmp2.v_com == NULL) {
comfree(tmp1.v_com);
return error_value(E_TAN4);
}
divvalue(&tmp1, &tmp2, &result); divvalue(&tmp1, &tmp2, &result);
comfree(tmp1.v_com); comfree(tmp1.v_com);
comfree(tmp2.v_com); comfree(tmp2.v_com);
@@ -2276,6 +2286,9 @@ f_sec(int count, VALUE **vals)
case V_COM: case V_COM:
tmp.v_type = V_COM; tmp.v_type = V_COM;
tmp.v_com = c_cos(vals[0]->v_com, err); tmp.v_com = c_cos(vals[0]->v_com, err);
if (tmp.v_com == NULL) {
return error_value(E_SEC3);
}
invertvalue(&tmp, &result); invertvalue(&tmp, &result);
comfree(tmp.v_com); comfree(tmp.v_com);
break; break;
@@ -2314,8 +2327,15 @@ f_cot(int count, VALUE **vals)
case V_COM: case V_COM:
tmp1.v_type = V_COM; tmp1.v_type = V_COM;
tmp1.v_com = c_cos(vals[0]->v_com, err); tmp1.v_com = c_cos(vals[0]->v_com, err);
if (tmp1.v_com == NULL) {
return error_value(E_COT3);
}
tmp2.v_type = V_COM; tmp2.v_type = V_COM;
tmp2.v_com = c_sin(vals[0]->v_com, err); tmp2.v_com = c_sin(vals[0]->v_com, err);
if (tmp2.v_com == NULL) {
comfree(tmp1.v_com);
return error_value(E_COT4);
}
divvalue(&tmp1, &tmp2, &result); divvalue(&tmp1, &tmp2, &result);
comfree(tmp1.v_com); comfree(tmp1.v_com);
comfree(tmp2.v_com); comfree(tmp2.v_com);
@@ -2354,6 +2374,9 @@ f_csc(int count, VALUE **vals)
case V_COM: case V_COM:
tmp.v_type = V_COM; tmp.v_type = V_COM;
tmp.v_com = c_sin(vals[0]->v_com, err); tmp.v_com = c_sin(vals[0]->v_com, err);
if (tmp.v_com == NULL) {
return error_value(E_CSC3);
}
invertvalue(&tmp, &result); invertvalue(&tmp, &result);
comfree(tmp.v_com); comfree(tmp.v_com);
break; break;
@@ -2476,8 +2499,15 @@ f_tanh(int count, VALUE **vals)
case V_COM: case V_COM:
tmp1.v_type = V_COM; tmp1.v_type = V_COM;
tmp1.v_com = c_sinh(vals[0]->v_com, err); tmp1.v_com = c_sinh(vals[0]->v_com, err);
if (tmp1.v_com == NULL) {
return error_value(E_TANH3);
}
tmp2.v_type = V_COM; tmp2.v_type = V_COM;
tmp2.v_com = c_cosh(vals[0]->v_com, err); tmp2.v_com = c_cosh(vals[0]->v_com, err);
if (tmp2.v_com == NULL) {
comfree(tmp1.v_com);
return error_value(E_TANH4);
}
divvalue(&tmp1, &tmp2, &result); divvalue(&tmp1, &tmp2, &result);
comfree(tmp1.v_com); comfree(tmp1.v_com);
comfree(tmp2.v_com); comfree(tmp2.v_com);
@@ -2517,8 +2547,15 @@ f_coth(int count, VALUE **vals)
case V_COM: case V_COM:
tmp1.v_type = V_COM; tmp1.v_type = V_COM;
tmp1.v_com = c_cosh(vals[0]->v_com, err); tmp1.v_com = c_cosh(vals[0]->v_com, err);
if (tmp1.v_com == NULL) {
return error_value(E_COTH3);
}
tmp2.v_type = V_COM; tmp2.v_type = V_COM;
tmp2.v_com = c_sinh(vals[0]->v_com, err); tmp2.v_com = c_sinh(vals[0]->v_com, err);
if (tmp2.v_com == NULL) {
comfree(tmp1.v_com);
return error_value(E_COTH4);
}
divvalue(&tmp1, &tmp2, &result); divvalue(&tmp1, &tmp2, &result);
comfree(tmp1.v_com); comfree(tmp1.v_com);
comfree(tmp2.v_com); comfree(tmp2.v_com);
@@ -2555,6 +2592,9 @@ f_sech(int count, VALUE **vals)
case V_COM: case V_COM:
tmp.v_type = V_COM; tmp.v_type = V_COM;
tmp.v_com = c_cosh(vals[0]->v_com, err); tmp.v_com = c_cosh(vals[0]->v_com, err);
if (tmp.v_com == NULL) {
return error_value(E_SECH3);
}
invertvalue(&tmp, &result); invertvalue(&tmp, &result);
comfree(tmp.v_com); comfree(tmp.v_com);
break; break;
@@ -2592,6 +2632,9 @@ f_csch(int count, VALUE **vals)
case V_COM: case V_COM:
tmp.v_type = V_COM; tmp.v_type = V_COM;
tmp.v_com = c_sinh(vals[0]->v_com, err); tmp.v_com = c_sinh(vals[0]->v_com, err);
if (tmp.v_com == NULL) {
return error_value(E_CSCH3);
}
invertvalue(&tmp, &result); invertvalue(&tmp, &result);
comfree(tmp.v_com); comfree(tmp.v_com);
break; break;
@@ -2626,7 +2669,7 @@ f_atan(int count, VALUE **vals)
case V_COM: case V_COM:
tmp = c_atan(vals[0]->v_com, err); tmp = c_atan(vals[0]->v_com, err);
if (tmp == NULL) if (tmp == NULL)
return error_value(E_LOGINF); return error_value(E_ATAN3);
result.v_type = V_COM; result.v_type = V_COM;
result.v_com = tmp; result.v_com = tmp;
if (cisreal(tmp)) { if (cisreal(tmp)) {
@@ -2666,7 +2709,7 @@ f_acot(int count, VALUE **vals)
case V_COM: case V_COM:
tmp = c_acot(vals[0]->v_com, err); tmp = c_acot(vals[0]->v_com, err);
if (tmp == NULL) if (tmp == NULL)
return error_value(E_LOGINF); return error_value(E_ACOT3);
result.v_type = V_COM; result.v_type = V_COM;
result.v_com = tmp; result.v_com = tmp;
if (cisreal(tmp)) { if (cisreal(tmp)) {
@@ -2718,6 +2761,9 @@ f_asin(int count, VALUE **vals)
default: default:
return error_value(E_ASIN2); return error_value(E_ASIN2);
} }
if (result.v_com == NULL) {
return error_value(E_ASIN3);
}
if (result.v_type == V_COM && cisreal(result.v_com)) { if (result.v_type == V_COM && cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -2764,6 +2810,9 @@ f_acos(int count, VALUE **vals)
default: default:
return error_value(E_ACOS2); return error_value(E_ACOS2);
} }
if (result.v_com == NULL) {
return error_value(E_ACOS3);
}
if (result.v_type == V_COM && cisreal(result.v_com)) { if (result.v_type == V_COM && cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -2794,7 +2843,7 @@ f_asec(int count, VALUE **vals)
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: case V_NUM:
if (qiszero(vals[0]->v_num)) if (qiszero(vals[0]->v_num))
return error_value(E_LOGINF); return error_value(E_ASEC3);
result.v_num = qasec(vals[0]->v_num, err); result.v_num = qasec(vals[0]->v_num, err);
result.v_type = V_NUM; result.v_type = V_NUM;
if (result.v_num == NULL) { if (result.v_num == NULL) {
@@ -2813,9 +2862,10 @@ f_asec(int count, VALUE **vals)
default: default:
return error_value(E_ASEC2); return error_value(E_ASEC2);
} }
if (result.v_com == NULL) {
return error_value(E_ASEC3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -2847,7 +2897,7 @@ f_acsc(int count, VALUE **vals)
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: case V_NUM:
if (qiszero(vals[0]->v_num)) if (qiszero(vals[0]->v_num))
return error_value(E_LOGINF); return error_value(E_ACSC3);
result.v_num = qacsc(vals[0]->v_num, err); result.v_num = qacsc(vals[0]->v_num, err);
result.v_type = V_NUM; result.v_type = V_NUM;
if (result.v_num == NULL) { if (result.v_num == NULL) {
@@ -2866,9 +2916,10 @@ f_acsc(int count, VALUE **vals)
default: default:
return error_value(E_ACSC2); return error_value(E_ACSC2);
} }
if (result.v_com == NULL) {
return error_value(E_ACSC3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -2903,6 +2954,9 @@ f_asinh(int count, VALUE **vals)
break; break;
case V_COM: case V_COM:
tmp = c_asinh(vals[0]->v_com, err); tmp = c_asinh(vals[0]->v_com, err);
if (tmp == NULL) {
return error_value(E_ASINH3);
}
result.v_type = V_COM; result.v_type = V_COM;
result.v_com = tmp; result.v_com = tmp;
if (cisreal(tmp)) { if (cisreal(tmp)) {
@@ -2955,6 +3009,9 @@ f_acosh(int count, VALUE **vals)
default: default:
return error_value(E_ACOSH2); return error_value(E_ACOSH2);
} }
if (result.v_com == NULL) {
return error_value(E_ACOSH3);
}
if (result.v_type == V_COM && cisreal(result.v_com)) { if (result.v_type == V_COM && cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -3002,9 +3059,10 @@ f_atanh(int count, VALUE **vals)
default: default:
return error_value(E_ATANH2); return error_value(E_ATANH2);
} }
if (result.v_com == NULL) {
return error_value(E_ATANH3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -3053,9 +3111,10 @@ f_acoth(int count, VALUE **vals)
default: default:
return error_value(E_ACOTH2); return error_value(E_ACOTH2);
} }
if (result.v_com == NULL) {
return error_value(E_ACOTH3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -3087,7 +3146,7 @@ f_asech(int count, VALUE **vals)
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: case V_NUM:
if (qiszero(vals[0]->v_num)) if (qiszero(vals[0]->v_num))
return error_value(E_LOGINF); return error_value(E_ASECH3);
result.v_num = qasech(vals[0]->v_num, err); result.v_num = qasech(vals[0]->v_num, err);
result.v_type = V_NUM; result.v_type = V_NUM;
if (result.v_num == NULL) { if (result.v_num == NULL) {
@@ -3106,9 +3165,10 @@ f_asech(int count, VALUE **vals)
default: default:
return error_value(E_ASECH2); return error_value(E_ASECH2);
} }
if (result.v_com == NULL) {
return error_value(E_ASECH3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -3140,7 +3200,7 @@ f_acsch(int count, VALUE **vals)
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: case V_NUM:
if (qiszero(vals[0]->v_num)) if (qiszero(vals[0]->v_num))
return error_value(E_LOGINF); return error_value(E_ACSCH3);
result.v_num = qacsch(vals[0]->v_num, err); result.v_num = qacsch(vals[0]->v_num, err);
result.v_type = V_NUM; result.v_type = V_NUM;
if (result.v_num == NULL) { if (result.v_num == NULL) {
@@ -3159,9 +3219,10 @@ f_acsch(int count, VALUE **vals)
default: default:
return error_value(E_ACSCH2); return error_value(E_ACSCH2);
} }
if (result.v_com == NULL) {
return error_value(E_ACSCH3);
}
if (result.v_type == V_COM) { if (result.v_type == V_COM) {
if (result.v_com == NULL)
return error_value(E_LOGINF);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -3260,7 +3321,7 @@ f_agd(int count, VALUE **vals)
return error_value(E_AGD2); return error_value(E_AGD2);
} }
if (result.v_com == NULL) if (result.v_com == NULL)
return error_value(E_AGD3); return error_value(E_AGD3);
if (cisreal(result.v_com)) { if (cisreal(result.v_com)) {
q = qlink(result.v_com->real); q = qlink(result.v_com->real);
comfree(result.v_com); comfree(result.v_com);
@@ -6022,12 +6083,15 @@ f_strerror(int count, VALUE **vals)
/* firewall - return generic error string if it is not assigned */ /* firewall - return generic error string if it is not assigned */
if (i >= nexterrnum || (i > E__HIGHEST && i < E_USERDEF) if (i >= nexterrnum || (i > E__HIGHEST && i < E_USERDEF)
|| (i < E__BASE && strerror(i) == NULL)) { || (i < E__BASE && strerror(i) == NULL)) {
cp = (char *) malloc(sizeof("Error 1234567890")+1); size_t snprintf_len; /* malloced snprintf buffer length */
snprintf_len = sizeof("Unknown error 12345678901234567890")+1;
cp = (char *) malloc(snprintf_len+1);
if (cp == NULL) { if (cp == NULL) {
math_error("Out of memory for strerror"); math_error("Out of memory for strerror");
/*NOTREACHED*/ /*NOTREACHED*/
} }
sprintf(cp, "Unknown error %ld", i); snprintf(cp, snprintf_len, "Unknown error %ld", i);
cp[snprintf_len] = '\0'; /* paranoia */
result.v_str = makestring(cp); result.v_str = makestring(cp);
return result; return result;
} }
@@ -7550,6 +7614,8 @@ f_putenv(int count, VALUE **vals)
* parse args * parse args
*/ */
if (count == 2) { if (count == 2) {
size_t snprintf_len; /* malloced snprintf buffer length */
/* firewall */ /* firewall */
if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) {
math_error("Non-string argument for putenv"); math_error("Non-string argument for putenv");
@@ -7557,14 +7623,17 @@ f_putenv(int count, VALUE **vals)
} }
/* convert putenv("foo","bar") into putenv("foo=bar") */ /* convert putenv("foo","bar") into putenv("foo=bar") */
putenv_str = (char *)malloc(vals[0]->v_str->s_len + 1 + snprintf_len = vals[0]->v_str->s_len + 1 +
vals[1]->v_str->s_len + 1); vals[1]->v_str->s_len + 1;
putenv_str = (char *)malloc(snprintf_len+1);
if (putenv_str == NULL) { if (putenv_str == NULL) {
math_error("Cannot allocate string in putenv"); math_error("Cannot allocate string in putenv");
/*NOTREACHED*/ /*NOTREACHED*/
} }
sprintf(putenv_str, "%s=%s", vals[0]->v_str->s_str, snprintf(putenv_str, snprintf_len,
"%s=%s", vals[0]->v_str->s_str,
vals[1]->v_str->s_str); vals[1]->v_str->s_str);
putenv_str[snprintf_len] = '\0'; /* paranoia */
} else { } else {

View File

@@ -1,7 +1,7 @@
/* /*
* have_stdvs - try <stdarg.h> to see if it really works with vsprintf() * have_stdvs - try <stdarg.h> to see if it really works with vsnprintf()
* *
* Copyright (C) 1999,2014 Landon Curt Noll * Copyright (C) 1999,2014,2018 Landon Curt Noll
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -25,16 +25,16 @@
*/ */
/* /*
* On some systems that have both <stdarg.h> and <varargs.h>, vsprintf() * On some systems that have both <stdarg.h> and <varargs.h>, vsnprintf()
* does not work well under one type of include file. * does not work well under one type of include file.
* *
* Some systems (such as UMIPS) have bugs in the <stdarg.h> implementation * Some systems (such as UMIPS) have bugs in the <stdarg.h> implementation
* that show up in vsprintf(), so we may have to try to use sprintf() * that show up in vsnprintf(), so we may have to try to use snprintf()
* as if it were vsprintf() and hope for the best. * as if it were vsnprintf() and hope for the best.
* *
* This program will output #defines and exits 0 if vsprintf() (or sprintf()) * This program will output #defines and exits 0 if vsnprintf() (or snprintf())
* produces the results that we expect. This program exits 1 if vsprintf() * produces the results that we expect. This program exits 1 if vsnprintf()
* (or sprintf()) produces unexpected results while using the <stdarg.h> * (or snprintf()) produces unexpected results while using the <stdarg.h>
* include file. * include file.
*/ */
@@ -57,39 +57,24 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#undef VSPRINTF_SIZE_T #undef VSNPRINTF_SIZE_T
#if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \ #if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \
defined(__cplusplus) defined(__cplusplus)
# define VSPRINTF_SIZE_T size_t # define VSNPRINTF_SIZE_T size_t
#else #else
# define VSPRINTF_SIZE_T long # define VSNPRINTF_SIZE_T long
#endif #endif
char buf[BUFSIZ]; char buf[BUFSIZ+1];
void void
try_this(char *fmt, ...) try_nthis(char *fmt, VSNPRINTF_SIZE_T size, ...)
{
va_list ap;
va_start(ap, fmt);
#if !defined(DONT_HAVE_VSPRINTF)
vsprintf(buf, fmt, ap);
#else
sprintf(buf, fmt, ap);
#endif
va_end(ap);
}
void
try_nthis(char *fmt, VSPRINTF_SIZE_T size, ...)
{ {
va_list ap; va_list ap;
va_start(ap, size); va_start(ap, size);
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
vsnprintf(buf, size, fmt, ap); vsnprintf(buf, size, fmt, ap);
#else #else
snprintf(buf, size, fmt, ap); snprintf(buf, size, fmt, ap);
@@ -106,36 +91,12 @@ main(void)
*/ */
buf[0] = '\0'; buf[0] = '\0';
/*
* test variable args and vsprintf/sprintf
*/
try_this("@%d:%s:%d@", 1, "hi", 2);
if (strcmp(buf, "@1:hi:2@") != 0) {
#if !defined(DONT_HAVE_VSPRINTF)
/* <stdarg.h> with vsprintf() didn't work */
#else
/* <stdarg.h> with sprintf() simulating vsprintf() didn't work */
#endif
exit(1);
}
try_this("%s %d%s%d%d %s",
"Landon Noll 1st coproved that", 2, "^", 21701, -1, "was prime");
if (strcmp(buf,
"Landon Noll 1st coproved that 2^21701-1 was prime") != 0) {
#if !defined(DONT_HAVE_VSPRINTF)
/* <stdarg.h> with vsprintf() didn't work */
#else
/* <stdarg.h> with sprintf() simulating vsprintf() didn't work */
#endif
exit(1);
}
/* /*
* test variable args and vsnprintf/snprintf * test variable args and vsnprintf/snprintf
*/ */
try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5);
if (strcmp(buf, "@1:hello:5@") != 0) { if (strcmp(buf, "@1:hello:5@") != 0) {
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
/* <stdarg.h> with vsnprintf() didn't work */ /* <stdarg.h> with vsnprintf() didn't work */
#else #else
/* <stdarg.h> with snprintf() simulating vsnprintf() didn't work */ /* <stdarg.h> with snprintf() simulating vsnprintf() didn't work */
@@ -146,7 +107,7 @@ main(void)
"Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime");
if (strcmp(buf, if (strcmp(buf,
"Landon Noll 1st proved that 2^23209-1 was prime") != 0) { "Landon Noll 1st proved that 2^23209-1 was prime") != 0) {
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
/* <stdarg.h> with vsnprintf() didn't work */ /* <stdarg.h> with vsnprintf() didn't work */
#else #else
/* <stdarg.h> with snprintf() simulating vsnprintf() didn't work */ /* <stdarg.h> with snprintf() simulating vsnprintf() didn't work */
@@ -158,7 +119,7 @@ main(void)
* report the result * report the result
*/ */
puts("/* what type of variable args do we have? */"); puts("/* what type of variable args do we have? */");
#if defined(DONT_HAVE_VSPRINTF) #if defined(DONT_HAVE_VSNPRINTF)
puts("/*"); puts("/*");
puts(" * SIMULATE_STDARG"); puts(" * SIMULATE_STDARG");
puts(" *"); puts(" *");
@@ -179,22 +140,21 @@ main(void)
puts("#define STDARG /* use <stdarg.h> */"); puts("#define STDARG /* use <stdarg.h> */");
puts("#include <stdarg.h>"); puts("#include <stdarg.h>");
#endif #endif
puts("\n/* should we use vsprintf() and vsnprintf()? */"); puts("\n/* should we use vsnprintf() and vsnprintf()? */");
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
puts("#define HAVE_VSPRINTF /* yes */"); puts("#define HAVE_VSNPRINTF /* yes */");
#else #else
puts("/*"); puts("/*");
puts(" * Hack aleart!!!"); puts(" * Hack aleart!!!");
puts(" *"); puts(" *");
puts(" * Systems that do not have vsprintf() need something. In some"); puts(" * Systems that do not have vsnprintf() need something. In some");
puts(" * cases the sprintf function will deal correctly with the"); puts(" * cases the snprintf function will deal correctly with the");
puts(" * va_alist 3rd arg. Same gors for a lack of an vsnprintf()"); puts(" * va_alist 4th arg. Same gors for a lack of an vsnprintf()");
puts(" * function. In either case we use the #defines below and"); puts(" * function. In either case we use the #defines below and");
puts(" * hope for the best!"); puts(" * hope for the best!");
puts(" */"); puts(" */");
puts("#define vsprintf sprintf");
puts("#define vsnprintf snprintf"); puts("#define vsnprintf snprintf");
puts("#undef HAVE_VSPRINTF"); puts("#undef HAVE_VSNPRINTF");
#endif #endif
/* exit(0); */ /* exit(0); */
return 0; return 0;

View File

@@ -1,7 +1,7 @@
/* /*
* have_varvs - try <varargs.h> to see if it really works with vsprintf() * have_varvs - try <varargs.h> to see if it really works with vsnprintf()
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2018 Landon Curt Noll
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -26,12 +26,12 @@
/* /*
* Some systems have bugs in the <varargs.h> implementation that show up in * Some systems have bugs in the <varargs.h> implementation that show up in
* vsprintf(), so we may have to try to use sprintf() as if it were vsprintf() * vsnprintf(), so we may have to try to use snprintf() as if it were
* and hope for the best. * vsnprintf() and hope for the best.
* *
* This program will output #defines and exits 0 if vsprintf() (or sprintf()) * This program will output #defines and exits 0 if vsnprintf() (or snprintf())
* produces the results that we expect. This program exits 1 if vsprintf() * produces the results that we expect. This program exits 1 if vsnprintf()
* (or sprintf()) produces unexpected results while using the <stdarg.h> * (or snprintf()) produces unexpected results while using the <stdarg.h>
* include file. * include file.
*/ */
@@ -48,43 +48,27 @@
# include <string.h> # include <string.h>
#endif #endif
#undef VSPRINTF_SIZE_T #undef VSNPRINTF_SIZE_T
#if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \ #if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \
defined(__cplusplus) defined(__cplusplus)
# define VSPRINTF_SIZE_T size_t # define VSNPRINTF_SIZE_T size_t
#else #else
# define VSPRINTF_SIZE_T long # define VSNPRINTF_SIZE_T long
#endif #endif
char buf[BUFSIZ]; char buf[BUFSIZ+1];
#if !defined(STDARG) && !defined(SIMULATE_STDARG) #if !defined(STDARG) && !defined(SIMULATE_STDARG)
#include <varargs.h> #include <varargs.h>
void void
try_this(char *fmt, ...) try_nthis(char *fmt, VSNPRINTF_SIZE_T size, ...)
{ {
va_list ap; va_list ap;
va_start(ap); va_start(ap);
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
vsprintf(buf, fmt, ap);
#else
sprintf(buf, fmt, ap);
#endif
va_end(ap);
}
void
try_nthis(char *fmt, VSPRINTF_SIZE_T size, ...)
{
va_list ap;
va_start(ap);
#if !defined(DONT_HAVE_VSPRINTF)
vsnprintf(buf, size, fmt, ap); vsnprintf(buf, size, fmt, ap);
#else #else
snprintf(buf, size, fmt, ap); snprintf(buf, size, fmt, ap);
@@ -96,13 +80,7 @@ try_nthis(char *fmt, VSPRINTF_SIZE_T size, ...)
#else #else
void void
try_this(char *a, int b, char *c, int d) try_nthis(char *a, VSNPRINTF_SIZE_T size, int b, char *c, int d)
{
return;
}
void
try_nthis(char *a, VSPRINTF_SIZE_T size, int b, char *c, int d)
{ {
return; return;
} }
@@ -118,36 +96,12 @@ main(void)
*/ */
buf[0] = '\0'; buf[0] = '\0';
/*
* test variable args and vsprintf/sprintf
*/
try_this("@%d:%s:%d@", 1, "hi", 2);
if (strcmp(buf, "@1:hi:2@") != 0) {
#if !defined(DONT_HAVE_VSPRINTF)
/* <varargs.h> with vsprintf() didn't work */
#else
/* <varargs.h> with sprintf() simulating vsprintf() didn't work */
#endif
exit(1);
}
try_this("%s %d%s%d%d %s",
"Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime");
if (strcmp(buf,
"Landon Noll 1st proved that 2^23209-1 was prime") != 0) {
#if !defined(DONT_HAVE_VSPRINTF)
/* <varargs.h> with vsprintf() didn't work */
#else
/* <varargs.h> with sprintf() simulating vsprintf() didn't work */
#endif
exit(1);
}
/* /*
* test variable args and vsnprintf/snprintf * test variable args and vsnprintf/snprintf
*/ */
try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5);
if (strcmp(buf, "@1:hello:5@") != 0) { if (strcmp(buf, "@1:hello:5@") != 0) {
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
/* <varargs.h> with vsnprintf() didn't work */ /* <varargs.h> with vsnprintf() didn't work */
#else #else
/* <varargs.h> with snprintf() simulating vsnprintf() didn't work */ /* <varargs.h> with snprintf() simulating vsnprintf() didn't work */
@@ -158,7 +112,7 @@ main(void)
"Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime");
if (strcmp(buf, if (strcmp(buf,
"Landon Noll 1st proved that 2^23209-1 was prime") != 0) { "Landon Noll 1st proved that 2^23209-1 was prime") != 0) {
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
/* <varargs.h> with vsnprintf() didn't work */ /* <varargs.h> with vsnprintf() didn't work */
#else #else
/* <varargs.h> with snprintf() simulating vsnprintf() didn't work */ /* <varargs.h> with snprintf() simulating vsnprintf() didn't work */
@@ -172,22 +126,21 @@ main(void)
puts("/* what type of variable args do we have? */"); puts("/* what type of variable args do we have? */");
puts("#define VARARGS /* use <varargs.h> */"); puts("#define VARARGS /* use <varargs.h> */");
puts("#include <varargs.h>"); puts("#include <varargs.h>");
puts("\n/* should we use vsprintf() and vsnprintf()? */"); puts("\n/* should we use vsnprintf() and vsnprintf()? */");
#if !defined(DONT_HAVE_VSPRINTF) #if !defined(DONT_HAVE_VSNPRINTF)
puts("#define HAVE_VSPRINTF /* yes */"); puts("#define HAVE_VSNPRINTF /* yes */");
#else #else
puts("/*"); puts("/*");
puts(" * Hack aleart!!!"); puts(" * Hack aleart!!!");
puts(" *"); puts(" *");
puts(" * Systems that do not have vsprintf() need something. In some"); puts(" * Systems that do not have vsnprintf() need something. In some");
puts(" * cases the sprintf function will deal correctly with the"); puts(" * cases the snprintf() function will deal correctly with the");
puts(" * va_alist 3rd arg. Same gors for a lack of an vsnprintf()"); puts(" * va_alist 4th arg. Same gors for a lack of an vsnprintf()");
puts(" * function. In either case we use the #defines below and"); puts(" * function. In either case we use the #defines below and");
puts(" * hope for the best!"); puts(" * hope for the best!");
puts(" */"); puts(" */");
puts("#define vsprintf sprintf");
puts("#define vsnprintf snprintf"); puts("#define vsnprintf snprintf");
puts("#undef HAVE_VSPRINTF"); puts("#undef HAVE_VSNPRINTF");
#endif #endif
/* exit(0); */ /* exit(0); */
return 0; return 0;

17
help.c
View File

@@ -1,7 +1,7 @@
/* /*
* help - display help for calc * help - display help for calc
* *
* Copyright (C) 1999-2007,2014 Landon Curt Noll * Copyright (C) 1999-2007,2014,2018 Landon Curt Noll
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -183,6 +183,7 @@ givehelp(char *type)
FILE *stream; /* help file stream */ FILE *stream; /* help file stream */
char *helppath; /* path to the help file */ char *helppath; /* path to the help file */
char *c; char *c;
size_t snprintf_len; /* malloced snprintf buffer length */
/* /*
* check permissions to see if we are allowed to help * check permissions to see if we are allowed to help
@@ -247,18 +248,21 @@ givehelp(char *type)
*/ */
#if defined(CUSTOM) #if defined(CUSTOM)
if (sizeof(CUSTOMHELPDIR) > sizeof(HELPDIR)) { if (sizeof(CUSTOMHELPDIR) > sizeof(HELPDIR)) {
helppath = (char *)malloc(sizeof(CUSTOMHELPDIR)+1+strlen(type)); snprintf_len = sizeof(CUSTOMHELPDIR)+1+strlen(type) + 1;
} else { } else {
helppath = (char *)malloc(sizeof(HELPDIR)+1+strlen(type)); snprintf_len = sizeof(HELPDIR)+1+strlen(type) + 1;
} }
helppath = (char *)malloc(snprintf_len+1);
#else /* CUSTOM */ #else /* CUSTOM */
helppath = (char *)malloc(sizeof(HELPDIR)+1+strlen(type)); snprintf_len = sizeof(HELPDIR)+1+strlen(type) + 1;
helppath = (char *)malloc(snprintf_len+1);
#endif /* CUSTOM */ #endif /* CUSTOM */
if (helppath == NULL) { if (helppath == NULL) {
fprintf(stderr, "malloc failure in givehelp()\n"); fprintf(stderr, "malloc failure in givehelp()\n");
return; return;
} }
sprintf(helppath, "%s/%s", HELPDIR, type); snprintf(helppath, snprintf_len, "%s/%s", HELPDIR, type);
helppath[snprintf_len] = '\0'; /* paranoia */
stream = fopen(helppath, "r"); stream = fopen(helppath, "r");
if (stream != NULL) { if (stream != NULL) {
@@ -274,7 +278,8 @@ givehelp(char *type)
*/ */
} else { } else {
sprintf(helppath, "%s/%s", CUSTOMHELPDIR, type); snprintf(helppath, snprintf_len, "%s/%s", CUSTOMHELPDIR, type);
helppath[snprintf_len] = '\0'; /* paranoia */
stream = fopen(helppath, "r"); stream = fopen(helppath, "r");
if (stream == NULL) { if (stream == NULL) {

View File

@@ -88,6 +88,31 @@ Command sequence
If the -m mode disallows opening of files for reading, If the -m mode disallows opening of files for reading,
this command will be disabled. this command will be disabled.
To read a calc resource file without printing various
messages about defined functions, the "resource_debug"
config should be set to zero. For example:
read lucas;
will, by default, print messages such as:
lucas(h,n) defined
gen_u2(h,n,v1) defined
gen_u0(h,n,v1) defined
rodseth_xhn(x,h,n) defined
gen_v1(h,n) defined
ldebug(funct,str) defined
legacy_gen_v1(h,n) defined
When "resource_debug" is zero, such messages are silenced.
config("resource_debug", 0),;
read lucas;
To silence such messages on the calc command line, try:
calc -p -D :0 'read -once lucas; lucas(1, 23209);'
write calc commands write calc commands
------------------- -------------------
@@ -350,7 +375,7 @@ Command sequence
statement flow control and declaration statements statement flow control and declaration statements
usage how to invoke the calc command and calc -options usage how to invoke the calc command and calc -options
## Copyright (C) 1999-2006 Landon Curt Noll ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -949,6 +949,48 @@ EXAMPLE
; display() ; display()
50 50
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; config("display", 12),; /* or display(12),; */
; printf("%f\n", pi(1e-10));
3.1415926536
; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; config("display", 12),; /* or display(12),; */
; printf("%f\n", pi(1e-72));
~3.141592653590
; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; config("display", 72),; /* or display(72),; */
; printf("%f\n", pi(1e-10));
3.1415926536
; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; config("display", 72),; /* or display(72),; */
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS LIMITS
none none
@@ -956,9 +998,9 @@ LINK LIBRARY
n/a n/a
SEE ALSO SEE ALSO
usage, custom, custom_cal, usage, epsilon, display custom, custom_cal, display, epsilon, fprintf, printf, strprintf, usage
## Copyright (C) 1999-2007 Landon Curt Noll ## Copyright (C) 1999-2007,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -45,6 +45,48 @@ EXAMPLE
; print display(5), 2/3 ; print display(5), 2/3
40 ~0.66667 40 ~0.66667
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS LIMITS
d >= 0 d >= 0
@@ -52,9 +94,9 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
config config, epsilon, fprintf, printf, strprintf
## Copyright (C) 2004 Landon Curt Noll ## Copyright (C) 2004,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -16,13 +16,57 @@ DESCRIPTION
and sets the stored epsilon value to eps. and sets the stored epsilon value to eps.
The stored epsilon value is used as default value for eps in The stored epsilon value is used as default value for eps in
the functions appr(x, eps, rnd), sqrt(x, eps, rnd), etc. many functions such as appr(x, eps, rnd), sqrt(x, eps, rnd),
pi(eps), sin(x, eps), tanh(x, eps), etc.
EXAMPLE EXAMPLE
; epsilon(1e-20),;
; oldeps = epsilon(1e-6) ; oldeps = epsilon(1e-6)
; print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps) ; print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps)
; .000001 1.414214 .000001 1.4142 .0001 ; .000001 1.414214 .000001 1.4142 .0001
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS LIMITS
none none
@@ -31,9 +75,9 @@ LINK LIBRARY
NUMBER *_epsilon_ NUMBER *_epsilon_
SEE ALSO SEE ALSO
config config, display, fprintf, printf, strprintf
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -45,6 +45,48 @@ EXAMPLE
[2] = "undefined" [2] = "undefined"
[3] = NULL [3] = NULL
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; fprintf(files(1), "%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; fprintf(files(1), "%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; fprintf(files(1), "%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; fprintf(files(1), "%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; fprintf(files(1), "%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; fprintf(files(1), "%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; fprintf(files(1), "%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; fprintf(files(1), "%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS LIMITS
The number of arguments of fprintf() is not to exceed 1024. The number of arguments of fprintf() is not to exceed 1024.
@@ -52,9 +94,9 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
printf, strprintf, print config, display, epsilon, printf, strprintf
## Copyright (C) 1999-2006 Landon Curt Noll ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -28,7 +28,7 @@ DESCRIPTION
zero or more decimal digits zero or more decimal digits
an optional '. followed by zero or more decimal deigits an optional '. followed by zero or more decimal deigits
an optional 'l' an optional 'l'
one of the letters: d, s, c, f, e, r, o, x, b, one of the letters: d, s, c, f, e, g, r, o, x, b,
If any other character is read, the '%' and any characters If any other character is read, the '%' and any characters
between '%' and the character are ignored and no specifier is between '%' and the character are ignored and no specifier is
@@ -51,26 +51,39 @@ DESCRIPTION
d, s, c current config("mode") d, s, c current config("mode")
f real (decimal, floating point) f real (decimal, floating point)
e exponential e exponential
g general format (real or exponential)
r fractional r fractional
o octal o octal
x hexadecimal x hexadecimal
b binary b binary
If the number of arguments after fmt is less than the If the number of arguments after fmt is less than the number
number of format specifiers in fmt, the "missing" arguments of format specifiers in fmt, the "missing" arguments may be
may be taken to be null values - these contribute nothing to the taken to be null values - these contribute nothing to the output;
output; if a positive width w has been specified, the effect is if a positive width w has been specified, the effect is to
to produce w spaces, e.g. printf("abc%6dxyz") prints "abc xyz". produce w spaces, e.g., printf("abc%6dxyz") prints "abc xyz".
If i <= the number of specifiers in fmt, the value of argument x_i Control charters may be given in fmt by escaping them with
is printed in the format specified by the i-th specifier. the \ character. The following control charter escape
If a positive width w has been specified and normal printing of x_i sequences are recognized:
does not include a '\n' character, what is printed will if necessary
be padded with spaces so that the length of the printed output \a audible bell byte 0x07 in ASCII encoding
is at least the w. Note that control \b backspace byte 0x08 in ASCII encoding
characters like '\t', '\b' each count as one character. If \f form feed byte 0x0c in ASCII encoding
the 'right-pad' flag has been set, the padding is on the right; \n newline byte 0x0b in ASCII encoding
otherwise it is on the left. \r return byte 0x0a in ASCII encoding
\t tab byte 0x0d in ASCII encoding
\v vertical tab byte 0x09 in ASCII encoding
If i <= the number of specifiers in fmt, the value of argument
x_i is printed in the format specified by the i-th specifier.
If a positive width w has been specified and normal printing
of x_i does not include a '\n' character, what is printed will
if necessary be padded with spaces so that the length of the
printed output is at least the w. Note that control characters
(e.g., '\a', '\b', '\f', '\n', '\r', '\t', '\n') count as one
character. If the 'right-pad' flag has been set, the padding
is on the right; otherwise it is on the left.
If i > the number of specifiers in fmt, the value of argument x_i If i > the number of specifiers in fmt, the value of argument x_i
does not contribute to the printing. However, as all arguments does not contribute to the printing. However, as all arguments
@@ -83,22 +96,38 @@ DESCRIPTION
specified precision will be ignored except for floating-point specified precision will be ignored except for floating-point
mode. mode.
In the case of floating-point (f) format the precision determines The (g) general format will print the as real (f) (decimal or
the maximum number of decimal places to be floating point) or as an exponential (e) depending on the
displayed. Other aspects of this printing may be affected by the configuration parameter "display".
configuration parameters "outround", "tilde", "fullzero", "leadzero".
In the case of floating-point (f) format, and the (g) general
format, the precision determines the maximum number of decimal
places to be displayed. Other aspects of this printing may be
affected by the configuration parameters "outround", "tilde",
"fullzero", "leadzero".
EXAMPLE EXAMPLE
; c = config("epsilon", 1e-6); c = config("display", 6); ; config("epsilon", 1e-6),;
; c = config("tilde", 1); c = config("outround", 0); : config("display", 6),;
; c = config("fullzero", 0); ; config("tilde", 1),;
; config("outround", 0),;
; config("fullzero", 0),;
; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
; a = sqrt(3); ; a = sqrt(3);
; printf(fmt,a,a,a,a,a,a); ; printf(fmt,a,a,a,a,a,a);
1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
; c = config("tilde", 0); c = config("outround",24); ; config("display", 5),;
; c = config("fullzero", 1); : config("tilde", 0),;
; printf("%f\n", pi());
3.1416
; config("display", 10),;
; printf("%f\n", pi());
3.141592654
; config("tilde", 0),;
: config("outround",24),;
; config("fullzero", 1),;
; printf(fmt,a,a,a,a,a,a); ; printf(fmt,a,a,a,a,a,a);
1.732051, 1.732051,1.732051 , 1.7321,1.7321,2. 1.732051, 1.732051,1.732051 , 1.7321,1.7321,2.
@@ -116,6 +145,82 @@ EXAMPLE
[2] = "undefined" [2] = "undefined"
[3] = NULL [3] = NULL
; config("display", 50),;
; printf("%g %g\n%g %g\n", 1e5, 1e49, 1e50, 1e500);
100000 100000000000000000000000000000000000000000000000000
1e50 1e500
; config("display", 10),;
: config("tilde", 0),;
; printf("%f %f %f\n%f %f %f\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.7182818285 7.3890560989 20.0855369232
54.5981500331 148.4131591026 403.4287934927
; printf("%e %e %e\n%e %e %e\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.7182818285 7.3890560989 2.0085536923e1
5.4598150033e1 1.4841315910e2 4.0342879349e2
; printf("%g %g %g\n%g %g %g\n",
exp(1), exp(2), exp(3), exp(4), exp(5), exp(6));
2.718281828 7.389056099 20.08553692
54.59815003 148.4131591 403.4287935
; config("display", 10),;
; config("tilde", 0),;
; printf("%f %f %f\n%f %f %f\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
485165195.4097902780 1318815734.4832146972 3584912846.1315915617
9744803446.2489026000 26489122129.8434722941 72004899337.3858725242`
; printf("%e %e %e\n%e %e %e\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
4.8516519541e8 1.3188157345e9 3.5849128461e9
9.7448034462e9 2.6489122130e10 7.2004899337e10
; printf("%g %g %g\n%g %g %g\n",
exp(20), exp(21), exp(22), exp(23), exp(24), exp(25));
485165195.4 1318815734 3584912846
9744803446 2.648912213e10 7.200489934e10
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; printf("%f\n", pi(1e-72));
~3.141592653590
; epsilon(1e-72),;
; printf("%f\n", pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; printf("%f\n", pi(1e-10));
3.1415926536
; epsilon(1e-10),;
; printf("%f\n", pi());
3.1415926536
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; printf("%f\n", pi(1e-72));
3.141592653589793238462643383279502884197169399375105820974944592307816406
; epsilon(1e-72),;
; printf("%f\n", pi());
3.141592653589793238462643383279502884197169399375105820974944592307816406
LIMITS LIMITS
The number of arguments of printf() is not to exceed 1024. The number of arguments of printf() is not to exceed 1024.
@@ -124,9 +229,9 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
fprintf, strprintf, print config, display, epsilon, fprintf, strprintf
## Copyright (C) 1999-2006 Landon Curt Noll ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -37,7 +37,7 @@ LIMITS
LINK LIBRARY LINK LIBRARY
void math_divertio(); void math_divertio();
qprintnum(NUMBER *x, int outmode); qprintnum(NUMBER *x, int outmode, LEN outdigits);
char *math_getdivertedio(); char *math_getdivertedio();
math_divertio(); math_divertio();
@@ -47,7 +47,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
base, base2, config base, base2, config
## Copyright (C) 1999-2006 Landon Curt Noll ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -18,15 +18,68 @@ EXAMPLE
; strprintf("h=%d, i=%d", 2, 3); ; strprintf("h=%d, i=%d", 2, 3);
"h=2, i=3" "h=2, i=3"
; c = config("epsilon", 1e-6); c = config("display", 6); ; config("epsilon", 1e-6),;
; c = config("tilde", 1); c = config("outround", 0); ; config("display", 6),;
; c = config("fullzero", 0); ; config("tilde", 1),;
; config("outround", 0),;
; config("fullzero", 0),;
; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
; a = sqrt(3); ; a = sqrt(3);
; strprintf(fmt,a,a,a,a,a,a); ; strprintf(fmt,a,a,a,a,a,a);
"1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. "1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
" "
; config("display", 50),;
; fmt2 = "%g %g\n%g %g\n"
; strprintf(fmt2, 1e5, 1e49, 1e50, 1e500);
"100000 100000000000000000000000000000000000000000000000000
1e50 1e500
"
; /*
* NOTE: When displaying many digits after the decimal point
* be sure to set display(digits) (see 'help display') to
* large enough AND to set epsilon(eps) (see 'help epsilon')
* small enough (or if the function has a esp argument,
* give a eps argument that is small enough) to display
* the value correctly.
*/
; config("tilde", 1),;
; config("tab", 0),;
; fmt1 = "%f";
; /* NOTE: display has too few digits and epsilon is not small enough */
; display(12),;
; strprintf(fmt1, pi(1e-10));
"3.1415926536"
; epsilon(1e-10),;
; strprintf(fmt1, pi());
"3.1415926536"
; /* NOTE: display has too few digits yet epsilon is small enough */
; display(12),;
; strprintf(fmt1, pi(1e-72));
"~3.141592653590"
; epsilon(1e-72),;
; strprintf(fmt1, pi());
~3.141592653590
; /* NOTE: display has enough digits but epsilon is not small enough */
; display(72),;
; strprintf(fmt1, pi(1e-10));
"3.1415926536"
; epsilon(1e-10),;
; strprintf(fmt1, pi());
"3.1415926536"
/* NOTE: display has enough digits and epsilon is small enough */
; display(72),;
; strprintf(fmt1, pi(1e-72));
"3.141592653589793238462643383279502884197169399375105820974944592307816406"
; epsilon(1e-72),;
; strprintf(fmt1, pi());
"3.141592653589793238462643383279502884197169399375105820974944592307816406"
LIMITS LIMITS
The number of arguments of strprintf() is not to exceed 1024. The number of arguments of strprintf() is not to exceed 1024.
@@ -34,12 +87,11 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos, config, display, epsilon, fprintf, strcat, strcpy, strerror,
strscan, strscanf, substr, strlen, strncmp, strncpy, strpos, strscan, strscanf, substr,
printf
printf, fprintf, print ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,7 +1,7 @@
/* /*
* input - nested input source file reader * input - nested input source file reader
* *
* Copyright (C) 1999-2007,2014 David I. Bell * Copyright (C) 1999-2007,2014,2018 David I. Bell
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -410,6 +410,7 @@ homeexpand(char *name)
char *after; /* after the ~user or ~ */ char *after; /* after the ~user or ~ */
char *username; /* extracted username */ char *username; /* extracted username */
size_t fullpath_len; /* length of fullpath */ size_t fullpath_len; /* length of fullpath */
size_t snprintf_len; /* malloced snprintf buffer length */
/* firewall */ /* firewall */
if (name[0] != HOMECHAR) if (name[0] != HOMECHAR)
@@ -466,11 +467,13 @@ homeexpand(char *name)
/* /*
* build the fullpath given the home directory * build the fullpath given the home directory
*/ */
fullpath = (char *)malloc(strlen(home2)+strlen(after)+1); snprintf_len = strlen(home2)+strlen(after) + 1;
fullpath = (char *)malloc(snprintf_len+1);
if (fullpath == NULL) { if (fullpath == NULL) {
return NULL; return NULL;
} }
sprintf(fullpath, "%s%s", home2, after); snprintf(fullpath, snprintf_len, "%s%s", home2, after);
fullpath[snprintf_len] = '\0'; /* paranoia */
return fullpath; return fullpath;
#endif /* Windoz free systems */ #endif /* Windoz free systems */
} }

View File

@@ -92,12 +92,6 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#if defined(__linux)
# if !defined(isascii)
E_FUNC int isascii(int c);
# endif /* !isascii */
#endif /* __linux */
char *program; /* our name */ char *program; /* our name */
int int

View File

@@ -83,7 +83,7 @@ math_error(char *fmt, ...)
#endif #endif
vsnprintf(calc_err_msg, MAXERROR, fmt, ap); vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
va_end(ap); va_end(ap);
calc_err_msg[MAXERROR] = '\0'; calc_err_msg[MAXERROR] = '\0'; /* paranoia */
/* /*
* if we should longjmp, so do * if we should longjmp, so do

42
qio.c
View File

@@ -62,12 +62,13 @@ qprintf(char *fmt, ...)
if (ch == '\\') { if (ch == '\\') {
ch = *fmt++; ch = *fmt++;
switch (ch) { switch (ch) {
case 'a': ch = '\a'; break;
case 'b': ch = '\b'; break;
case 'f': ch = '\f'; break;
case 'n': ch = '\n'; break; case 'n': ch = '\n'; break;
case 'r': ch = '\r'; break; case 'r': ch = '\r'; break;
case 't': ch = '\t'; break; case 't': ch = '\t'; break;
case 'f': ch = '\f'; break;
case 'v': ch = '\v'; break; case 'v': ch = '\v'; break;
case 'b': ch = '\b'; break;
case 0: case 0:
va_end(ap); va_end(ap);
return; return;
@@ -97,6 +98,15 @@ qprintf(char *fmt, ...)
q = va_arg(ap, NUMBER *); q = va_arg(ap, NUMBER *);
qprintfe(q, width, precision); qprintfe(q, width, precision);
break; break;
case 'g':
q = va_arg(ap, NUMBER *);
/* XXX - we need a qprintfg function */
#if 0 /* XXX - we need a qprintfg() function */
qprintfg(q, width, precision);
#else /* XXX - use qprintfe until we have a qprintfg() function */
qprintfe(q, width, precision);
#endif /* XXX - we need a qprintfg() function */
break;
case 'r': case 'r':
case 'R': case 'R':
q = va_arg(ap, NUMBER *); q = va_arg(ap, NUMBER *);
@@ -174,7 +184,7 @@ qprintf(char *fmt, ...)
* Integers are always printed as themselves. * Integers are always printed as themselves.
*/ */
void void
qprintnum(NUMBER *q, int outmode) qprintnum(NUMBER *q, int outmode, LEN outdigits)
{ {
NUMBER tmpval; NUMBER tmpval;
long prec, exp; long prec, exp;
@@ -193,13 +203,13 @@ qprintnum(NUMBER *q, int outmode)
case MODE_REAL: case MODE_REAL:
prec = qdecplaces(q); prec = qdecplaces(q);
if ((prec < 0) || (prec > conf->outdigits)) { if ((prec < 0) || (prec > outdigits)) {
if (conf->tilde_ok) if (conf->tilde_ok)
PUTCHAR('~'); PUTCHAR('~');
} }
if (conf->fullzero || (prec < 0) || if (conf->fullzero || (prec < 0) ||
(prec > conf->outdigits)) (prec > outdigits))
prec = conf->outdigits; prec = outdigits;
qprintff(q, 0L, prec); qprintff(q, 0L, prec);
break; break;
@@ -216,7 +226,7 @@ qprintnum(NUMBER *q, int outmode)
tmpval.num.sign = 0; tmpval.num.sign = 0;
exp = qilog10(&tmpval); exp = qilog10(&tmpval);
if (exp == 0) { /* in range to output as real */ if (exp == 0) { /* in range to output as real */
qprintnum(q, MODE_REAL); qprintnum(q, MODE_REAL, outdigits);
return; return;
} }
tmpval.num = _one_; tmpval.num = _one_;
@@ -228,11 +238,25 @@ qprintnum(NUMBER *q, int outmode)
q = qmul(q, &tmpval); q = qmul(q, &tmpval);
zfree(tmpval.num); zfree(tmpval.num);
zfree(tmpval.den); zfree(tmpval.den);
qprintnum(q, MODE_REAL); qprintnum(q, MODE_REAL, outdigits);
qfree(q); qfree(q);
PRINTF1("e%ld", exp); PRINTF1("e%ld", exp);
break; break;
case MODE_REAL_AUTO:
{
const int P = conf->outdigits ? conf->outdigits : 1;
tmpval = *q;
tmpval.num.sign = 0;
exp = qilog10(&tmpval);
if (P > exp && exp >= -P) {
qprintnum(q, MODE_REAL, P - 1 - exp);
} else {
qprintnum(q, MODE_EXP, P - 1);
}
break;
}
case MODE_HEX: case MODE_HEX:
qprintfx(q, 0L); qprintfx(q, 0L);
break; break;
@@ -252,7 +276,7 @@ qprintnum(NUMBER *q, int outmode)
if (outmode2 != MODE2_OFF) { if (outmode2 != MODE2_OFF) {
PUTSTR(" /* "); PUTSTR(" /* ");
qprintnum(q, outmode2); qprintnum(q, outmode2, outdigits);
PUTSTR(" */"); PUTSTR(" */");
} }
} }

View File

@@ -67,7 +67,7 @@ E_FUNC FULL qtou(NUMBER *q);
E_FUNC SFULL qtos(NUMBER *q); E_FUNC SFULL qtos(NUMBER *q);
E_FUNC long qparse(char *str, int flags); E_FUNC long qparse(char *str, int flags);
E_FUNC void qfreenum(NUMBER *q); E_FUNC void qfreenum(NUMBER *q);
E_FUNC void qprintnum(NUMBER *q, int mode); E_FUNC void qprintnum(NUMBER *q, int mode, LEN outdigits);
E_FUNC void qprintff(NUMBER *q, long width, long precision); E_FUNC void qprintff(NUMBER *q, long width, long precision);
E_FUNC void qprintfe(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);

2
qmod.c
View File

@@ -404,7 +404,7 @@ showredcdata(void)
for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) { for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) {
if (rcp->age > 0) { if (rcp->age > 0) {
printf("%-8ld%-8ld", i, rcp->age); printf("%-8ld%-8ld", i, rcp->age);
qprintnum(rcp->rnum, 0); qprintnum(rcp->rnum, 0, conf->outdigits);
printf("\n"); printf("\n");
} }
} }

3
sha1.c
View File

@@ -684,7 +684,7 @@ sha1_print(HASH *state)
* the last full update or finalization. Thus it * the last full update or finalization. Thus it
* may NOT be the actual hash value. * may NOT be the actual hash value.
*/ */
sprintf(buf, snprintf(buf, DEBUG_SIZE,
"sha1: 0x%08x%08x%08x%08x%08x data: %d octets", "sha1: 0x%08x%08x%08x%08x%08x data: %d octets",
(int)state->h_union.h_sha1.digest[0], (int)state->h_union.h_sha1.digest[0],
(int)state->h_union.h_sha1.digest[1], (int)state->h_union.h_sha1.digest[1],
@@ -692,6 +692,7 @@ sha1_print(HASH *state)
(int)state->h_union.h_sha1.digest[3], (int)state->h_union.h_sha1.digest[3],
(int)state->h_union.h_sha1.digest[4], (int)state->h_union.h_sha1.digest[4],
(int)state->h_union.h_sha1.datalen); (int)state->h_union.h_sha1.datalen);
buf[DEBUG_SIZE] = '\0'; /* paranoia */
math_str(buf); math_str(buf);
} else { } else {
math_str("sha1 hash state"); math_str("sha1 hash state");

19
str.c
View File

@@ -1380,17 +1380,17 @@ printechar(char *c)
math_chr('\\'); math_chr('\\');
ech = 0; ech = 0;
switch (ch) { switch (ch) {
case '\a': ech = 'a'; break;
case '\b': ech = 'b'; break;
case '\f': ech = 'f'; break;
case '\n': ech = 'n'; break; case '\n': ech = 'n'; break;
case '\r': ech = 'r'; break; case '\r': ech = 'r'; break;
case '\t': ech = 't'; break; case '\t': ech = 't'; break;
case '\b': ech = 'b'; break;
case '\f': ech = 'f'; break;
case '\v': ech = 'v'; break; case '\v': ech = 'v'; break;
case '\\': ech = '\\'; break; case '\\': ech = '\\'; break;
case '\"': ech = '\"'; break; case '\"': ech = '\"'; break;
case '\'': ech = '\''; break; case '\'': ech = '\''; break;
case 0: ech = '0'; break; case 0: ech = '0'; break;
case 7: ech = 'a'; break;
case 27: ech = 'e'; break; case 27: ech = 'e'; break;
} }
if (ech == '0') { if (ech == '0') {
@@ -1438,8 +1438,17 @@ fitstring(char *str, long len, long width)
continue; continue;
n++; n++;
switch (ch) { switch (ch) {
case '\n': case '\r': case '\t': case '\b': case '\f': case '\a':
case '\v': case '\\': case '\"': case 7: case 27: case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
case '\v':
case '\\':
case '\"':
case '\'':
case 27:
continue; continue;
} }
if (ch >= 64 || (nch >= '0' && nch <= '7')) { if (ch >= 64 || (nch >= '0' && nch <= '7')) {

18
token.c
View File

@@ -183,10 +183,12 @@ gettoken(void)
} }
switch (ch) { switch (ch) {
case ' ': case ' ':
case '\t': case '\a':
case '\r': case '\b':
case '\v':
case '\f': case '\f':
case '\r':
case '\t':
case '\v':
case '\0': case '\0':
break; break;
case '\n': case '\n':
@@ -718,7 +720,7 @@ scanerror(int skip, char *fmt, ...)
if (name) { if (name) {
snprintf(calc_err_msg, MAXERROR, "\"%s\", line %ld: ", snprintf(calc_err_msg, MAXERROR, "\"%s\", line %ld: ",
name, linenumber()); name, linenumber());
calc_err_msg[MAXERROR] = '\0'; /* firewall */ calc_err_msg[MAXERROR] = '\0'; /* paranoia */
len = strlen(calc_err_msg); len = strlen(calc_err_msg);
if (len < MAXERROR) { if (len < MAXERROR) {
vsnprintf(calc_err_msg+len, MAXERROR-len, fmt, ap); vsnprintf(calc_err_msg+len, MAXERROR-len, fmt, ap);
@@ -727,7 +729,7 @@ scanerror(int skip, char *fmt, ...)
vsnprintf(calc_err_msg, MAXERROR, fmt, ap); vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
} }
va_end(ap); va_end(ap);
calc_err_msg[MAXERROR] = '\0'; calc_err_msg[MAXERROR] = '\0'; /* paranoia */
/* print error message if allowed */ /* print error message if allowed */
if (calc_print_scanerr_msg != 0) { if (calc_print_scanerr_msg != 0) {
@@ -782,7 +784,7 @@ scanerror(int skip, char *fmt, ...)
default: default:
snprintf(calc_err_msg, MAXERROR, snprintf(calc_err_msg, MAXERROR,
"Unknown skip token for scanerror\n"); "Unknown skip token for scanerror\n");
calc_err_msg[MAXERROR] = '\0'; calc_err_msg[MAXERROR] = '\0'; /* paranoia */
if (calc_print_scanerr_msg != 0) { if (calc_print_scanerr_msg != 0) {
fprintf(stderr, "%s\n\n", calc_err_msg); fprintf(stderr, "%s\n\n", calc_err_msg);
} }
@@ -823,7 +825,7 @@ warning(char *fmt, ...)
if (name) { if (name) {
snprintf(calc_warn_msg, MAXERROR, "\"%s\", line %ld: ", snprintf(calc_warn_msg, MAXERROR, "\"%s\", line %ld: ",
name, linenumber()); name, linenumber());
calc_warn_msg[MAXERROR] = '\0'; /* firewall */ calc_warn_msg[MAXERROR] = '\0'; /* paranoia */
len = strlen(calc_warn_msg); len = strlen(calc_warn_msg);
if (len < MAXERROR) { if (len < MAXERROR) {
vsnprintf(calc_warn_msg+len, MAXERROR-len, fmt, ap); vsnprintf(calc_warn_msg+len, MAXERROR-len, fmt, ap);
@@ -832,7 +834,7 @@ warning(char *fmt, ...)
vsnprintf(calc_warn_msg, MAXERROR, fmt, ap); vsnprintf(calc_warn_msg, MAXERROR, fmt, ap);
} }
va_end(ap); va_end(ap);
calc_warn_msg[MAXERROR] = '\0'; calc_warn_msg[MAXERROR] = '\0'; /* paranoia */
/* print the warning if allowed */ /* print the warning if allowed */
if (calc_print_scanwarn_msg != 0) { if (calc_print_scanwarn_msg != 0) {

View File

@@ -2774,7 +2774,7 @@ printvalue(VALUE *vp, int flags)
} }
switch (type) { switch (type) {
case V_NUM: case V_NUM:
qprintnum(vp->v_num, MODE_DEFAULT); qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits);
if (conf->traceflags & TRACE_LINKS) if (conf->traceflags & TRACE_LINKS)
math_fmt("#%ld", vp->v_num->links); math_fmt("#%ld", vp->v_num->links);
break; break;
@@ -2835,7 +2835,7 @@ printvalue(VALUE *vp, int flags)
if (userfunc("octet_print", vp)) if (userfunc("octet_print", vp))
break; break;
qtemp = itoq((long) *vp->v_octet); qtemp = itoq((long) *vp->v_octet);
qprintnum(qtemp, MODE_DEFAULT); qprintnum(qtemp, MODE_DEFAULT, conf->outdigits);
qfree(qtemp); qfree(qtemp);
break; break;
case V_OPTR: case V_OPTR:
@@ -2888,7 +2888,7 @@ printestr(VALUE *vp)
math_chr('"'); math_chr('"');
return; return;
case V_NUM: case V_NUM:
qprintnum(vp->v_num, MODE_FRAC); qprintnum(vp->v_num, MODE_FRAC, conf->outdigits);
return; return;
case V_COM: case V_COM:
mode = math_setmode(MODE_FRAC); mode = math_setmode(MODE_FRAC);

View File

@@ -1,7 +1,7 @@
/* /*
* version - determine the version of calc * version - determine the version of calc
* *
* Copyright (C) 1999-2017 David I. Bell and Landon Curt Noll * Copyright (C) 1999-2018 David I. Bell and Landon Curt Noll
* *
* Primary author: David I. Bell * Primary author: David I. Bell
* *
@@ -44,8 +44,8 @@ static char *program;
#define MAJOR_VER 2 /* major library version */ #define MAJOR_VER 2 /* major library version */
#define MINOR_VER 12 /* minor library version */ #define MINOR_VER 12 /* minor library version */
#define MAJOR_PATCH 6 /* major software level under library version */ #define MAJOR_PATCH 7 /* major software level under library version */
#define MINOR_PATCH 7 /* minor software level or 0 if not patched */ #define MINOR_PATCH 0 /* minor software level or 0 if not patched */
/* /*
@@ -120,6 +120,7 @@ version(void)
snprintf(verbuf, BUFSIZ, snprintf(verbuf, BUFSIZ,
"%d.%d.%d.%d", calc_major_ver, calc_minor_ver, "%d.%d.%d.%d", calc_major_ver, calc_minor_ver,
calc_major_patch, calc_minor_patch); calc_major_patch, calc_minor_patch);
verbuf[BUFSIZ] = '\0'; /* paranoia */
/* /*
* save the versions string into a newly malloced buffer * save the versions string into a newly malloced buffer

View File

@@ -1,5 +1,5 @@
TERMCONTROL=-DUSE_WIN32 TERMCONTROL=-DUSE_WIN32
HAVE_VSPRINTF=-UDONT_HAVE_VSPRINTF HAVE_VSNPRINTF=-UDONT_HAVE_VSNPRINTF
BYTE_ORDER=-DLITTLE_ENDIAN BYTE_ORDER=-DLITTLE_ENDIAN
LONG_BITS=32 LONG_BITS=32
HAVE_FPOS=-DHAVE_NO_FPOS HAVE_FPOS=-DHAVE_NO_FPOS

2
zio.c
View File

@@ -177,7 +177,7 @@ math_fmt(char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buf, BUFSIZ, fmt, ap); vsnprintf(buf, BUFSIZ, fmt, ap);
va_end(ap); va_end(ap);
buf[BUFSIZ] = '\0'; buf[BUFSIZ] = '\0'; /* paranoia */
math_str(buf); math_str(buf);
} }

View File

@@ -579,10 +579,16 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res);
#define MODE_HEX 5 #define MODE_HEX 5
#define MODE_OCTAL 6 #define MODE_OCTAL 6
#define MODE_BINARY 7 #define MODE_BINARY 7
#define MODE_MAX 7 #define MODE_REAL_AUTO 8
#define MODE_MAX 8
#define MODE2_OFF (MODE_MAX+1) #define MODE2_OFF (MODE_MAX+1)
/* XXX - perhaps we need the MODE_REAL_AUTO vs MODE_REAL as a config mode? */
#if 0 /* XXX - can we safely set MODE_INITIAL to MODE_REAL_AUTO ?? */
#define MODE_INITIAL MODE_REAL_AUTO
#else
#define MODE_INITIAL MODE_REAL #define MODE_INITIAL MODE_REAL
#endif
#define MODE2_INITIAL MODE2_OFF #define MODE2_INITIAL MODE2_OFF