Compare commits

..

29 Commits

Author SHA1 Message Date
Landon Curt Noll
229345ade8 Release 2.12.7.6
The following are the changes in this release:

    The missing cscript/square.calc file has been restored.
2021-02-03 13:03:50 -08:00
Landon Curt Noll
0f902b95cf Clarify when factor() builtin returns 1
Clarify that the factor() builtin return 1
if it does not find a factor below the limit.
2021-02-03 12:45:10 -08:00
Landon Curt Noll
8684e1be9c Fix for missing cscript/simple.calc in tarball 2021-02-03 12:44:11 -08:00
Landon Curt Noll
ae3a6129b2 Release 2.12.7.5
Final cleanup for the calc version 2.12.7.5 release.
2021-02-03 03:24:47 -08:00
Landon Curt Noll
2c72570b8d Fixed 0^(0) and 0^(6-6) to return 1
Calc as defined 0^0 as 1.  However in the past, 0 raised to
an expression that evaluted to zero returned 1.  The result
was that 0^0 was different than 0^(6-6) or even 0^(0).
Now, calc will return 1 for 0^(0) and 0^zero when zero == 0.
2021-02-03 01:44:17 -08:00
Landon Curt Noll
41803b878e Added use of $CALCHISTFILE and start of 2.12.7.5
By default, the calc history file is located in ~/.calc_history.
Now, if the environment variable $CALCHISTFILE is defined
and is non-empty, then calc history file will be defined
by the $CALCHISTFILE environment variable.
2021-02-03 00:51:56 -08:00
Landon Curt Noll
a8be58becb Merge pull request #8 from jcul/master
Fix compilation with GCC 7+
2021-02-02 23:45:34 -08:00
Landon Curt Noll
067afc140a Merge pull request #7 from thegithubr/patch-1
Little fix
2021-02-02 23:42:05 -08:00
Landon Curt Noll
41128fada9 Merge pull request #12 from guilhermgonzaga/master
Fix typos; Insert missing lines in README.md
2021-02-02 23:41:22 -08:00
Landon Curt Noll
f5fae012f9 Release 2.12.7.4 2021-02-02 23:03:37 -08:00
Landon Curt Noll
3d25fb30cb Release 2.12.7.4 2021-02-02 23:03:10 -08:00
Landon Curt Noll
8374586275 Merge branch 'master' of https://github.com/lcn2/calc 2021-02-02 23:02:24 -08:00
Landon Curt Noll
68c2edf610 Release 2.12.7.4
These changes are per calc version 2.12.7.3:

Requiring calc shell scripts to use -s -f at the end of the
initial #! line.

Fixed /tmp/mersenne example in calc(1) man page.

Added make variable ${ARCH_CFLAGS}.  The ${ARCH_CFLAGS} is
added after ${CCMISC} and before ${EXTRA_CFLAGS} when building
the ${CFLAGS} for compiling C code.  are ${CC} when compiling
C files.  The default value is:

ARCH_CFLAGS= -march=native

which directs C compiler to compile for the native machine.
To disable use of '-march=native', set ARCH_CFLAGS to the empty
string as in:

make all ARCH_CFLAGS=

To make calc RPMs more portable, they are compiled with an
empty ARCH_CFLAGS.

These changes are per calc version 2.12.7.4:

Fixed issues relating to compiling on macOS.  Fixed issues
where <unistd.h> is needed.
2021-02-02 23:01:11 -08:00
Landon Curt Noll
d58a55a1ed Release 2.12.7.3
Requiring calc shell scripts to use -s -f at the end of the
initial #! line.

Fixed /tmp/mersenne example in calc(1) man page.

Added make variable ${ARCH_CFLAGS}.  The ${ARCH_CFLAGS} is
added after ${CCMISC} and before ${EXTRA_CFLAGS} when building
the ${CFLAGS} for compiling C code.  are ${CC} when compiling
C files.  The default value is:

ARCH_CFLAGS= -march=native

which directs C compiler to compile for the native machine.
To disable use of '-march=native', set ARCH_CFLAGS to the empty
string as in:

make all ARCH_CFLAGS=

To make calc RPMs more portable, they are compiled with an
empty ARCH_CFLAGS.

Fixed issues relating to compiling on macOS.  Fixed issues
where <unistd.h> is needed.
2021-02-02 22:54:51 -08:00
Landon Curt Noll
ccfa797b68 Changes as per calc 2.12.7.3 2021-02-02 20:33:59 -08:00
Guilherme Gonzaga de Andrade
0f030f0759 Fix typos; Insert missing lines in README.md
Fixed typos in help/intro and README.md;
Copied missing description lines from help/intro to README.md "What is calc?"
section.
2020-03-03 11:27:23 -04:00
Jack Culhane
af59b9dab2 One FALLTHRU comment was inconsistent with others 2019-05-17 17:31:02 +01:00
Jack Culhane
fa173cd9aa Fix spaces vs tabs and use FALLTHRU as it's used elsewhere 2019-05-17 17:18:07 +01:00
Jack Culhane
1f8269c0e2 Comment fallthrough case statements so compilation succeeds with GCC 7.
GCC 7 Added a warning for implicit fallthroughs in switch cases.
It's enabled by -Wextra, and treated as an error due to -Werror so
compilation fails on GCC 7 and higher.
See -Wimplicit-fallthrough in the GCC manual.
2019-05-17 17:00:48 +01:00
thegithubr
51462b8612 Little fix
A little fix
2019-02-22 13:49:25 +01:00
Landon Curt Noll
9b69648921 Fix long lines in lib_calc.c 2018-11-28 12:33:10 -08:00
Landon Curt Noll
c5e416c41f Release calc 2.12.7.2
Fixed a segfault when getpwuid() returned NULL during initialization.
Thanks goes to baratharon GitHub user for reporting this issue.
2018-11-28 12:27:04 -08:00
Landon Curt Noll
37ad43c7fd Release calc 2.12.7.1
Corrected CHANGES notes that were mixed up for TAB, VT, CR &
NL.  The code in 2.12.7.0 is correct.  The CHANGE notes should
have read:

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 0x0a in ASCII encoding
    \r	return		byte 0x0d in ASCII encoding
    \t	tab		byte 0x09 in ASCII encoding
    \v	vertical tab	byte 0x0b in ASCII encoding

Sorry!
2018-11-05 08:02:09 -08:00
Landon Curt Noll
a877cb52c0 Corrected CHANGES notes
Corrected CHANGES notes that were mixed up for TAB, VT, CR & NL.
The core in 2.12.7.0 is correct.  The CHANGE notes were mixed up.
Sorry!
2018-11-05 07:33:40 -08:00
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
53 changed files with 810 additions and 208 deletions

48
BUGS
View File

@@ -80,6 +80,54 @@ Known bugs:
The output of the alg_config.cal resource file is bogus. The output of the alg_config.cal resource file is bogus.
We would welcome a replacement for this code. We would welcome a replacement for this code.
Calc shell scripts do not read from stdin properly,
we all as a number of the cscript examples.
The argv() function is behaving differently
when run in calc shell script mode:
When calc is run as:
calc -s a bb ccc
and given this input on the command prompt:
print "config(\"program\")=", config("program");
print "argv()=", argv();
argc = argv();
for (i=0; i < argc; ++i) {
print "argv(":i:")=", argv(i);
}
calc prints:
config("program")= calc
argv()= 3
argv(0)= a
argv(1)= bb
argv(2)= ccc
but when it is run as a script called ./simple:
#!/usr/local/bin/calc -q -s -f
print "config(\"program\")=", config("program");
print "argv()=", argv();
argc = argv();
for (i=0; i < argc; ++i) {
print "argv(":i:")=", argv(i);
}
under Linux prints:
config("program")= /usr/bin/calc
argv()= 4
argv(0)= ./simple
argv(1)= a
argv(2)= bb
argv(3)= ccc
and under macOS simply enters into interactive mode.
We are sure some more bugs exist. When you find them, please let We are sure some more bugs exist. When you find them, please let
us know! See the above for details on how to report and were to us know! See the above for details on how to report and were to
EMail your bug reports and hopefully patches to fix them. EMail your bug reports and hopefully patches to fix them.

106
CHANGES
View File

@@ -1,8 +1,81 @@
The following are the changes from calc version 2.12.6.10 to date: The following are the changes from calc version 2.12.7.1 to date:
Corrected CHANGES notes that were mixed up for TAB, VT, CR &
NL. The code in 2.12.7.0 is correct. The CHANGE notes should
have read:
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 0x0a in ASCII encoding
\r return byte 0x0d in ASCII encoding
\t tab byte 0x09 in ASCII encoding
\v vertical tab byte 0x0b in ASCII encoding
Fixed a segfault when getpwuid() returned NULL during initialization.
Thanks goes to baratharon GitHub user for reporting this issue.
Requiring calc shell scripts to use -s -f at the end of the
initial #! line.
Fixed /tmp/mersenne example in calc(1) man page.
Added make variable ${ARCH_CFLAGS}. The ${ARCH_CFLAGS} is
added after ${CCMISC} and before ${EXTRA_CFLAGS} when building
the ${CFLAGS} for compiling C code. are ${CC} when compiling
C files. The default value is:
ARCH_CFLAGS= -march=native
which directs C compiler to compile for the native machine.
To disable use of '-march=native', set ARCH_CFLAGS to the empty
string as in:
make all ARCH_CFLAGS=
To make calc RPMs more portable, they are compiled with an
empty ARCH_CFLAGS.
Fixed issues relating to compiling on macOS. Fixed issues
where <unistd.h> is needed.
Fixed typos in help/intro and README.md. <<GitHub guilhermgonzaga>>
Copied missing description lines from help/intro to README.md
"What is calc?" section. <<GitHub guilhermgonzaga>>
GCC 7 added a warning on fall throughs in case statements. It's
enabled by -Wextra and treated as an error due to -Wall so it
breaks compilation. See -Wimplicit-fallthrough in the GCC
manual. The default value is 3, which means a comment matching
some specific regexes is enough to disable the warning.
Fixed spaces vs tabs and use FALLTHRU as it's used elsewhere.
Fixed one FALLTHRU comment that was inconsistent with others.
<<thanks jcul>>
Fixed minor typo on help/power. <<GitHub thegithubr>>
By default, the calc history file is located in ~/.calc_history.
Now, if the environment variable $CALCHISTFILE is defined
and is non-empty, then calc history file will be defined
by the $CALCHISTFILE environment variable.
Calc as defined 0^0 as 1. However in the past, 0 raised to
an expression that evaluted to zero returned 1. The result
was that 0^0 was different than 0^(6-6) or even 0^(0).
Now, calc will return 1 for 0^(0) and 0^zero when zero == 0.
The missing cscript/square.calc file has been restored.
The following are the changes from calc version 2.12.6.10: to 2.12.7.0:
Added a patch to replaces the manual search for include files Added a patch to replaces the manual search for include files
in $(INCDIR) in the have_*.h targets with compiler invocations. in $(INCDIR) in the have_*.h targets with compiler invocations.
Thanks goes to Helmut Grohne <helmut at subdivi dot de> who Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
implemented the patch and posted it to the Debian bug tracker 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. and Martin Buck (m at rtin-buck dor de) for forwarding it to us.
@@ -13,6 +86,30 @@ The following are the changes from calc version 2.12.6.10 to date:
But when it comes to the experimental '%g', this value can But when it comes to the experimental '%g', this value can
change. This avoids having to modify conf->outdigits. 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 0x0a in ASCII encoding
\r return byte 0x0d in ASCII encoding
\t tab byte 0x09 in ASCII encoding
\v vertical tab byte 0x0b in ASCII encoding
The following are the changes from calc version 2.12.6.9 to 2.12.6.9: The following are the changes from calc version 2.12.6.9 to 2.12.6.9:
@@ -42,8 +139,9 @@ The following are the changes from calc version 2.12.6.9 to 2.12.6.9:
INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include
to determine the upper path of the /usr/include directory for macOS. to determine the upper path of the /usr/include directory for macOS.
The Darwin target seems to not automatically detected. For now, In some rare cases, the Darwin target seems to not automatically detected.
under macOS, declare the target as darwin: 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 # for macOS users only, force the target to be darwin
# #

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

@@ -1054,7 +1054,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.10 VERSION= 2.12.7.6
# Names of shared libraries with versions # Names of shared libraries with versions
# #
@@ -1116,16 +1116,26 @@ STRIP= strip
EXTRA_CFLAGS= EXTRA_CFLAGS=
EXTRA_LDFLAGS= EXTRA_LDFLAGS=
# Architecture compile flags
#
# The ARCH_CFLAGS are ${CC} when compiling C files. They follow
# CCMISC and preceed EXTRA_CFLAGS.
#
ARCH_CFLAGS= -march=native
#ARCH_CFLAGS=
# COMMON_CFLAGS are the common ${CC} flags used for all programs, both # COMMON_CFLAGS are the common ${CC} flags used for all programs, both
# intermediate and final calc and calc related programs # intermediate and final calc and calc related programs
# #
#if 0 /* start of skip for non-Gnu makefiles */ #if 0 /* start of skip for non-Gnu makefiles */
ifdef ALLOW_CUSTOM ifdef ALLOW_CUSTOM
#endif /* end of skip for non-Gnu makefiles */ #endif /* end of skip for non-Gnu makefiles */
COMMON_CFLAGS= -DCALC_SRC ${ALLOW_CUSTOM} ${CCWARN} ${CCMISC} ${EXTRA_CFLAGS} COMMON_CFLAGS= -DCALC_SRC ${ALLOW_CUSTOM} ${CCWARN} \
${CCMISC} ${ARCH_CFLAGS} ${EXTRA_CFLAGS}
#if 0 /* start of skip for non-Gnu makefiles */ #if 0 /* start of skip for non-Gnu makefiles */
else else
COMMON_CFLAGS= -DCALC_SRC -UCUSTOM ${CCWARN} ${CCMISC} ${EXTRA_CFLAGS} COMMON_CFLAGS= -DCALC_SRC -UCUSTOM ${CCWARN} \
${CCMISC} ${ARCH_CFLAGS} ${EXTRA_CFLAGS}
endif endif
#endif /* end of skip for non-Gnu makefiles */ #endif /* end of skip for non-Gnu makefiles */
@@ -1900,6 +1910,7 @@ SAMPLE_OBJ= sample_many.o sample_rand.o
CUSTOM_PASSDOWN= \ CUSTOM_PASSDOWN= \
ALLOW_CUSTOM="${ALLOW_CUSTOM}" \ ALLOW_CUSTOM="${ALLOW_CUSTOM}" \
AR=${AR} \ AR=${AR} \
ARCH_CFLAGS=${ARCH_CFLAGS} \
AWK=${AWK} \ AWK=${AWK} \
BINDIR="${BINDIR}" \ BINDIR="${BINDIR}" \
BLD_TYPE="${BLD_TYPE}" \ BLD_TYPE="${BLD_TYPE}" \
@@ -2914,7 +2925,7 @@ have_const.h: have_const.c ${MAKE_FILE}
${TRUE}; \ ${TRUE}; \
fi fi
have_offscl.h: have_offscl.c ${MAKE_FILE} have_offscl.h: have_offscl.c have_unistd.h ${MAKE_FILE}
${Q} ${RM} -f offscl_tmp have_offscl.h ${Q} ${RM} -f offscl_tmp have_offscl.h
${Q} echo 'forming have_offscl.h' ${Q} echo 'forming have_offscl.h'
${Q} echo '/*' > have_offscl.h ${Q} echo '/*' > have_offscl.h
@@ -2954,7 +2965,7 @@ have_offscl.h: have_offscl.c ${MAKE_FILE}
${TRUE}; \ ${TRUE}; \
fi fi
have_posscl.h: have_posscl.c have_fpos.h ${MAKE_FILE} have_posscl.h: have_posscl.c have_fpos.h have_unistd.h ${MAKE_FILE}
${Q} ${RM} -f have_posscl have_posscl.o posscl_tmp have_posscl.h ${Q} ${RM} -f have_posscl have_posscl.o posscl_tmp have_posscl.h
${Q} echo 'forming have_posscl.h' ${Q} echo 'forming have_posscl.h'
${Q} echo '/*' > have_posscl.h ${Q} echo '/*' > have_posscl.h
@@ -3210,7 +3221,7 @@ have_ustat.h: have_ustat.c ${MAKE_FILE}
${TRUE}; \ ${TRUE}; \
fi fi
have_getsid.h: have_getsid.c ${MAKE_FILE} have_getsid.h: have_getsid.c have_unistd.h ${MAKE_FILE}
${Q} ${RM} -f getsid_tmp have_getsid.h ${Q} ${RM} -f getsid_tmp have_getsid.h
${Q} echo 'forming have_getsid.h' ${Q} echo 'forming have_getsid.h'
${Q} echo '/*' > have_getsid.h ${Q} echo '/*' > have_getsid.h
@@ -3250,7 +3261,7 @@ have_getsid.h: have_getsid.c ${MAKE_FILE}
${TRUE}; \ ${TRUE}; \
fi fi
have_getpgid.h: have_getpgid.c ${MAKE_FILE} have_getpgid.h: have_getpgid.c have_unistd.h ${MAKE_FILE}
${Q} ${RM} -f getpgid_tmp have_getpgid.h ${Q} ${RM} -f getpgid_tmp have_getpgid.h
${Q} echo 'forming have_getpgid.h' ${Q} echo 'forming have_getpgid.h'
${Q} echo '/*' > have_getpgid.h ${Q} echo '/*' > have_getpgid.h
@@ -3332,7 +3343,7 @@ have_gettime.h: have_gettime.c ${MAKE_FILE}
${TRUE}; \ ${TRUE}; \
fi fi
have_getprid.h: have_getprid.c ${MAKE_FILE} have_getprid.h: have_getprid.c have_unistd.h ${MAKE_FILE}
${Q} ${RM} -f getprid_tmp have_getprid.h ${Q} ${RM} -f getprid_tmp have_getprid.h
${Q} echo 'forming have_getprid.h' ${Q} echo 'forming have_getprid.h'
${Q} echo '/*' > have_getprid.h ${Q} echo '/*' > have_getprid.h
@@ -4041,6 +4052,7 @@ env:
@echo 'ALIGN32=${ALIGN32}'; echo '' @echo 'ALIGN32=${ALIGN32}'; echo ''
@echo 'ALLOW_CUSTOM=${ALLOW_CUSTOM}'; echo '' @echo 'ALLOW_CUSTOM=${ALLOW_CUSTOM}'; echo ''
@echo 'AR=${AR}'; echo '' @echo 'AR=${AR}'; echo ''
@echo 'ARCH_CFLAGS=${ARCH_CFLAGS}'; echo ''
@echo 'AWK=${AWK}'; echo '' @echo 'AWK=${AWK}'; echo ''
@echo 'BINDIR=${BINDIR}'; echo '' @echo 'BINDIR=${BINDIR}'; echo ''
@echo 'BLD_TYPE=${BLD_TYPE}'; echo '' @echo 'BLD_TYPE=${BLD_TYPE}'; echo ''
@@ -5463,6 +5475,7 @@ hist.o: have_unistd.h
hist.o: have_unused.h hist.o: have_unused.h
hist.o: hist.c hist.o: hist.c
hist.o: hist.h hist.o: hist.h
hist.o: lib_calc.h
hist.o: longbits.h hist.o: longbits.h
hist.o: nametype.h hist.o: nametype.h
hist.o: qmath.h hist.o: qmath.h

View File

@@ -1,6 +1,9 @@
# What is calc? # What is calc?
Calc is an interactive calculator which provides for easy large Calc is an interactive calculator which provides for easy large
numeric calculations, but which also can be easily programmed
for difficult or long calculations. It can accept a command line
argument, in which case it executes that single command and exits.
Otherwise, it enters interactive mode. In this mode, it accepts Otherwise, it enters interactive mode. In this mode, it accepts
commands one at a time, processes them, and displays the answers. commands one at a time, processes them, and displays the answers.
In the simplest case, commands are simply expressions which are In the simplest case, commands are simply expressions which are
@@ -16,7 +19,7 @@ and the calculator will print:
15 15
``` ```
Calc as the usual collection of arithmetic operators +, -, /, * as Calc has the usual collection of arithmetic operators +, -, /, * as
well as ^ (exponentiation), % (modulus) and // (integer divide). well as ^ (exponentiation), % (modulus) and // (integer divide).
For example: For example:

View File

@@ -2057,7 +2057,12 @@ define t010()
epsilon(eps); epsilon(eps);
return 5; return 5;
} }
if ((stirling2(10, 5) - (42525)) != 0) { /*
* Once, when an expression such as 0^(6-6) returned 0,
* then stirling2(10, 5) == 42525. However when we made9
* 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120.
*/
if ((stirling2(10, 5) - (5102999/120)) != 0) {
epsilon(eps); epsilon(eps);
return 6; return 6;
} }

2
calc.c
View File

@@ -449,7 +449,7 @@ main(int argc, char **argv)
"\t[-O] [-p] [-q] [-s] [-u] [-v] " "\t[-O] [-p] [-q] [-s] [-u] [-v] "
"[--] [calc_cmd ...]\n" "[--] [calc_cmd ...]\n"
"usage: %s ... -f filename\n" "usage: %s ... -f filename\n"
"1st cscript line: #/path/to/calc ... -f\n", "1st cscript line: #/path/to/calc ... -s -f\n",
program, program); program, program);
exit(20); exit(20);
} }

1
calc.h
View File

@@ -48,6 +48,7 @@
#define HOME "HOME" /* environment variable for home dir */ #define HOME "HOME" /* environment variable for home dir */
#define PAGER "PAGER" /* environment variable for help */ #define PAGER "PAGER" /* environment variable for help */
#define SHELL "SHELL" /* environment variable for shell */ #define SHELL "SHELL" /* environment variable for shell */
#define CALCHISTFILE "CALCHISTFILE" /* history file environment variable */
#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */ #define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */
#define DEFAULTCALCHELP "help" /* help file that -h prints */ #define DEFAULTCALCHELP "help" /* help file that -h prints */
#define DEFAULTSHELL "sh" /* default shell to use */ #define DEFAULTSHELL "sh" /* default shell to use */

View File

@@ -1,5 +1,5 @@
.\" .\"
.\" Copyright (C) 1999-2007,2014,2018 Landon Curt Noll .\" Copyright (C) 1999-2007,2014,2018,2021 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
@@ -50,7 +50,7 @@ calc \- arbitrary precision calculator
.RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ] .RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ]
.in -5n .in -5n
.sp .sp
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
.SH DESCRIPTION .SH DESCRIPTION
\& \&
.br .br
@@ -219,24 +219,29 @@ The getenv() builtin will still return values, however.
.TP .TP
.B \-f .B \-f
This flag is normally only with calc shell scripts.
.sp 1
This flag is required when using calc in This flag is required when using calc in
.BR "shell script mode" . .BR "shell script mode" .
It must be at the end of the initial It must be at the end of the initial
.B #! .B #!
line of the script. line of the script
and must be immedately preceeded by the
.B \-s
flag.
.sp 1 .sp 1
This flag is normally only at the end of a calc shell script.
If the first line of an executable file begins If the first line of an executable file begins
.B #! .B #!
followed by the absolute pathname of the followed by the absolute pathname of the
.B calc .B calc
program and the flag program and if the first line ends with the two flags
.B \-s
.B \-f .B \-f
as in: as in:
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
@@ -270,7 +275,7 @@ on the command line:
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
\fIcalc\fP\ [other_flags\ \&...] \fB\-f\fP filename \fIcalc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP filename
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
@@ -283,6 +288,16 @@ Use of
.B \-f .B \-f
implies implies
.BR \-s . .BR \-s .
However in a calc shell script,
one must include
.B \-f
before
.B \-s
on the initial
.B #!
line.
.sp 1
In addition, In addition,
.B \-d .B \-d
and and
@@ -753,25 +768,28 @@ If the first line of an executable file begins
.B #! .B #!
followed by the absolute pathname of the followed by the absolute pathname of the
.B calc .B calc
program and the flag program and the first line ends with the two flags
.B \-s
.B \-f .B \-f
as in: as in:
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP \fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
the rest of the file will be processed in the rest of the file will be processed in
.BR "shell script mode" . .BR "shell script mode" .
Note that Note that
.B \-s
.B \-f .B \-f
must at the end of the initial ``#!'' line. must at the end of the initial ``#!'' line.
Any other optional Any other optional
.B "other_flags" .B "other_flags"
must come before must come before
the the
.B \-s
.BR \-f . .BR \-f .
.sp 1 .sp 1
In In
@@ -803,18 +821,26 @@ the file
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
\fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \fB\-f\fP \fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \&\fB\-s\fP \fB\-f\fP
#
# mersenne - an example of a calc \fBshell script file\fP /* setup */
argc = argv();
program = argv(0);
stderr = files(2);
/* parse args */ /* parse args */
if (argv() != 1) { if (argc != 2) {
fprintf(files(2), "usage: %s exp\\n", config("program")); fprintf(stderr, "usage: %s exp\n", program);
abort "must give one exponent arg";
}
exp = eval(argv(1));
if (!isint(exp) || exp < 0) {
fprintf(stderr, "%s: exp must be non-negative integer\n", program);
abort "must give one exponent arg"; abort "must give one exponent arg";
} }
/* print the mersenne number */ /* print the mersenne number */
print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1; print "2^": exp : "-1 =", 2^exp-1;
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
@@ -844,9 +870,9 @@ will print:
.sp 1 .sp 1
Note that because Note that because
.B \-s .B \-s
is assumed in is required in
.B "shell script mode" .B "shell script mode"
and non-dashed args are made available as non-dashed args are made available as
strings via the strings via the
.BR argv () .BR argv ()
builtin function. builtin function.
@@ -854,16 +880,16 @@ Therefore:
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
2^eval(argv(0))-1 2^eval(argv(1))-1
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
will print the decimal value of 2^n-1 will print the decimal value of 2^n-1
but whereas
.sp 1 .sp 1
.in +5n .in +5n
.nf .nf
2^argv(0)-1 2^argv(1)-1
.fi .fi
.in -5n .in -5n
.sp 1 .sp 1
@@ -1077,6 +1103,14 @@ Default value: binding
This variable is not used if calc was compiled with GNU-readline support. This variable is not used if calc was compiled with GNU-readline support.
In that case, the standard readline mechanisms (see readline(3)) are used. In that case, the standard readline mechanisms (see readline(3)) are used.
.sp .sp
.TP 5
CALCHISTFILE
Location of the calc history file.
.sp
Default value: ~/.calc_history
.sp
This variable is not used if calc was compiled with GNU-readline support.
.sp
.SH CREDIT .SH CREDIT
\& \&
.br .br

View File

@@ -32,7 +32,7 @@
Summary: Arbitrary precision calculator. Summary: Arbitrary precision calculator.
Name: calc Name: calc
Version: <<<PROJECT_VERSION>>> Version: <<<PROJECT_VERSION>>>
Release: 12 Release: 13
License: LGPL License: LGPL
Group: Applications/Engineering Group: Applications/Engineering
Source: http://www.isthe.com/chongo/src/calc/%{name}-%{version}.tar.bz2 Source: http://www.isthe.com/chongo/src/calc/%{name}-%{version}.tar.bz2
@@ -76,48 +76,48 @@ For the latest calc release, see the project home page:
%build %build
echo '-=- calc.spec beginning make clobber -=-' echo '-=- calc.spec beginning make clobber -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ clobber MANDIR=%{_mandir}/man1 EXT= V=@ clobber
echo '-=- calc.spec ending make clobber -=-' echo '-=- calc.spec ending make clobber -=-'
echo '-=- calc.spec beginning make calc-static-only -=-' echo '-=- calc.spec beginning make calc-static-only -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ calc-static-only BLD_TYPE=calc-static-only MANDIR=%{_mandir}/man1 EXT= V=@ calc-static-only BLD_TYPE=calc-static-only
echo '-=- calc.spec ending make calc-static-only -=-' echo '-=- calc.spec ending make calc-static-only -=-'
echo '-=- calc.spec beginning make rpm-hide-static -=-' echo '-=- calc.spec beginning make rpm-hide-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-hide-static MANDIR=%{_mandir}/man1 EXT= V=@ rpm-hide-static
echo '-=- calc.spec ending make rpm-hide-static -=-' echo '-=- calc.spec ending make rpm-hide-static -=-'
echo '-=- calc.spec beginning make clobber (again) -=-' echo '-=- calc.spec beginning make clobber (again) -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ clobber MANDIR=%{_mandir}/man1 EXT= V=@ clobber
echo '-=- calc.spec ending make clobber (again) -=-' echo '-=- calc.spec ending make clobber (again) -=-'
echo '-=- calc.spec beginning make calc-dynamic-only -=-' echo '-=- calc.spec beginning make calc-dynamic-only -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ calc-dynamic-only \ MANDIR=%{_mandir}/man1 EXT= V=@ calc-dynamic-only \
BLD_TYPE=calc-dynamic-only LD_SHARE= BLD_TYPE=calc-dynamic-only LD_SHARE=
echo '-=- calc.spec ending make calc-dynamic-only -=-' echo '-=- calc.spec ending make calc-dynamic-only -=-'
echo '-=- calc.spec beginning make chk -=-' echo '-=- calc.spec beginning make chk -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ chk MANDIR=%{_mandir}/man1 EXT= V=@ chk
echo '-=- calc.spec ending make chk -=-' echo '-=- calc.spec ending make chk -=-'
echo '-=- calc.spec beginning make rpm-unhide-static -=-' echo '-=- calc.spec beginning make rpm-unhide-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-unhide-static MANDIR=%{_mandir}/man1 EXT= V=@ rpm-unhide-static
echo '-=- calc.spec ending make rpm-unhide-static -=-' echo '-=- calc.spec ending make rpm-unhide-static -=-'
echo '-=- calc.spec beginning make rpm-clean-static -=-' echo '-=- calc.spec beginning make rpm-clean-static -=-'
make -j1 BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-clean-static MANDIR=%{_mandir}/man1 EXT= V=@ rpm-clean-static
echo '-=- calc.spec ending make rpm-clean-static -=-' echo '-=- calc.spec ending make rpm-clean-static -=-'
echo '-=- calc.spec beginning make rpm-chk-static -=-' echo '-=- calc.spec beginning make rpm-chk-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-chk-static MANDIR=%{_mandir}/man1 EXT= V=@ rpm-chk-static
echo '-=- calc.spec ending make rpm-chk-static -=-' echo '-=- calc.spec ending make rpm-chk-static -=-'
@@ -125,7 +125,7 @@ echo '-=- calc.spec ending make rpm-chk-static -=-'
%install %install
echo '-=- calc.spec beginning make install -=-' echo '-=- calc.spec beginning make install -=-'
mkdir -p %{_buildroot} mkdir -p %{_buildroot}
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \ make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \ CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ install MANDIR=%{_mandir}/man1 EXT= V=@ install
echo '-=- calc.spec ending make install -=-' echo '-=- calc.spec ending make install -=-'
@@ -165,6 +165,12 @@ echo '-=- calc.spec beginning make clean -=-'
%attr(644, root, root) %{_libdir}/libcustcalc.a %attr(644, root, root) %{_libdir}/libcustcalc.a
%changelog %changelog
* Sun Mar 24 2019 cLandon Curt Noll http://www.isthe.com/chongo
- Release: 13
- Disable compiling with the default ARCH_CFLAGS= -march=native
by clearking the ARCH_CFLAGS value in order to maximize
the RPM binary protability.
* Mon Sep 01 2014 Landon Curt Noll http://www.isthe.com/chongo * Mon Sep 01 2014 Landon Curt Noll http://www.isthe.com/chongo
- Release: 12 - Release: 12
- Removed use of %{?_smp_mflags}. On Ubuntu 14.04, the -j2 - Removed use of %{?_smp_mflags}. On Ubuntu 14.04, the -j2

View File

@@ -1021,7 +1021,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel,
return; return;
} }
reread(); reread();
/* fall into default case */ /*FALLTHRU*/
default: default:
rescantoken(); rescantoken();
@@ -1384,6 +1384,7 @@ creatematrix(void)
switch (gettoken()) { switch (gettoken()) {
case T_RIGHTBRACKET: case T_RIGHTBRACKET:
rescantoken(); rescantoken();
/*FALLTHRU*/
case T_COMMA: case T_COMMA:
addop(OP_ONE); addop(OP_ONE);
addop(OP_SUB); addop(OP_SUB);
@@ -1394,6 +1395,7 @@ creatematrix(void)
switch(gettoken()) { switch(gettoken()) {
case T_RIGHTBRACKET: case T_RIGHTBRACKET:
rescantoken(); rescantoken();
/*FALLTHRU*/
case T_COMMA: case T_COMMA:
continue; continue;
} }
@@ -2211,6 +2213,7 @@ getterm(void)
scanerror(T_NULL, scanerror(T_NULL,
"Function calls not allowed " "Function calls not allowed "
"as expressions"); "as expressions");
/*FALLTHRU*/
default: default:
rescantoken(); rescantoken();
return type; return type;
@@ -2248,7 +2251,7 @@ getidexpr(BOOL okmat, int autodef)
if (autodef != T_GLOBAL && autodef != T_LOCAL && if (autodef != T_GLOBAL && autodef != T_LOCAL &&
autodef != T_STATIC) autodef != T_STATIC)
autodef = 1; autodef = 1;
/* fall into default case */ /*FALLTHRU*/
default: default:
rescantoken(); rescantoken();
usesymbol(name, autodef); usesymbol(name, autodef);
@@ -2277,6 +2280,7 @@ getidexpr(BOOL okmat, int autodef)
scanerror(T_NULL, scanerror(T_NULL,
"Function calls not allowed " "Function calls not allowed "
"as expressions"); "as expressions");
/*FALLTHRU*/
default: default:
rescantoken(); rescantoken();
return type; return type;

View File

@@ -909,34 +909,42 @@ setconfig(int type, VALUE *vp)
case CONFIG_PROGRAM: case CONFIG_PROGRAM:
math_error("The program config parameter is read-only"); math_error("The program config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_BASENAME: case CONFIG_BASENAME:
math_error("The basename config parameter is read-only"); math_error("The basename config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_WINDOWS: case CONFIG_WINDOWS:
math_error("The windows config parameter is read-only"); math_error("The windows config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_CYGWIN: case CONFIG_CYGWIN:
math_error("The cygwin config parameter is read-only"); math_error("The cygwin config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_COMPILE_CUSTOM: case CONFIG_COMPILE_CUSTOM:
math_error("The custom config parameter is read-only"); math_error("The custom config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_ALLOW_CUSTOM: case CONFIG_ALLOW_CUSTOM:
math_error("The allow_custom config parameter is read-only"); math_error("The allow_custom config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_VERSION: case CONFIG_VERSION:
math_error("The version config parameter is read-only"); math_error("The version config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_BASEB: case CONFIG_BASEB:
math_error("The baseb config parameter is read-only"); math_error("The baseb config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
case CONFIG_REDECL_WARN: case CONFIG_REDECL_WARN:
if (vp->v_type == V_NUM) { if (vp->v_type == V_NUM) {
@@ -971,10 +979,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_HZ: case CONFIG_HZ:
math_error("The clock tick rate config parameter is read-only"); math_error("The clock tick rate config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
default: default:
math_error("Setting illegal config parameter"); math_error("Setting illegal config parameter");
/*NOTREACHED*/ /*NOTREACHED*/
abort();
} }
} }

View File

@@ -10,7 +10,7 @@
* ... ... * ... ...
* x5 y5 z5 w5 point 5 in R^4 * x5 y5 z5 w5 point 5 in R^4
* *
* Copyright (C) 2001,2014 Landon Curt Noll * Copyright (C) 2001,2014,2019 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
@@ -37,9 +37,11 @@
* parse args * parse args
*/ */
argc = argv(); argc = argv();
if (argc != 25) { stderr = files(2);
fprintf(files(2), "usage: %s x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5\n", program = argv(0);
argv(0)); if (argc != 24) {
fprintf(stderr, "usage: %s x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5\n",
program);
exit; exit;
} }
x0 = eval(argv(1)); x0 = eval(argv(1));

View File

@@ -1,7 +1,7 @@
# #
# cscript - makefile for calc shell script files # cscript - makefile for calc shell script files
# #
# Copyright (C) 1999-2006,2014,2017 Landon Curt Noll # Copyright (C) 1999-2006,2014,2017,2021 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
@@ -199,7 +199,8 @@ SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm \
simple square simple square
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc \ SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc \
piforever.calc plus.calc powerterm.calc simple.calc square.calc piforever.calc plus.calc powerterm.calc simple.calc \
square.calc
# These files are found (but not built) in the distribution # These files are found (but not built) in the distribution
# #

View File

@@ -8,7 +8,7 @@
* filename where to write the product, use - for stdout * filename where to write the product, use - for stdout
* term ... terms to multiply * term ... terms to multiply
* *
* Copyright (C) 2001,2014 Landon Curt Noll * Copyright (C) 2001,2014,2019 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
@@ -35,8 +35,10 @@
* parse args * parse args
*/ */
argc = argv(); argc = argv();
stderr = files(2);
program = argv(0);
if (argc < 2) { if (argc < 2) {
fprintf(files(2), "usage: %s term [term ...]\n", argv(0)); fprintf(stderr, "usage: %s term [term ...]\n", program);
exit; exit;
} }
filename = argv(1); filename = argv(1);

View File

@@ -2,7 +2,7 @@
/* /*
* mersenne - print the value of a mersenne number * mersenne - print the value of a mersenne number
* *
* Copyright (C) 1999-2007,2014 Landon Curt Noll * Copyright (C) 1999-2007,2014,2019 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
@@ -32,13 +32,16 @@
/* /*
* parse args * parse args
*/ */
if (argv() != 2) { argc = argv();
stderr = files(2);
program = argv(0);
if (argc != 2) {
/* we include the name of this script in the error message */ /* we include the name of this script in the error message */
fprintf(files(2), "usage: %s exp\n", config("program")); fprintf(stderr, "usage: %s exp\n", program);
abort "wrong number of args"; abort "wrong number of args";
} }
global n = eval(argv(1)); n = eval(argv(1));
if (!isint(n) || n <= 0) { if (!isint(n) || n <= 0) {
quit "Argument to be a positive integer"; quit "Argument to be a positive integer";

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f #!/usr/local/src/bin/calc/calc -q -s -f
/* /*
* piforever - print digits of pi forever (or as long as your mem/cpu allow) * piforever - print digits of pi forever (or as long as your mem/cpu allow)
* *
* Copyright (C) 1999-2007,2014 Landon Curt Noll * Copyright (C) 1999-2007,2014,2019 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,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f #!/usr/local/src/bin/calc/calc -q -s -f
/* /*
* plus - add two or more arguments together * plus - add two or more arguments together
* *
* Copyright (C) 1999-2007,2014 Landon Curt Noll * Copyright (C) 1999-2007,2014,2019 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
@@ -32,9 +32,12 @@
/* /*
* parse args * parse args
*/ */
if (argv() < 2) { argc = argv();
stderr = files(2);
program = argv(0);
if (argc < 2) {
/* we include the name of this script in the error message */ /* we include the name of this script in the error message */
fprintf(files(2), "usage: %s value ...\n", config("program")); fprintf(stderr, "usage: %s value ...\n", program);
abort "not enough args"; abort "not enough args";
} }

View File

@@ -8,7 +8,7 @@
* base_limit largest base we will consider (def: 10000) * base_limit largest base we will consider (def: 10000)
* value value to convert into sums of powers of integers * value value to convert into sums of powers of integers
* *
* Copyright (C) 2001,2014 Landon Curt Noll * Copyright (C) 2001,2014,2019 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 powerterm of the version 2.1 of the GNU Lesser General Public License * the powerterm of the version 2.1 of the GNU Lesser General Public License
@@ -35,28 +35,31 @@
/* /*
* parse args * parse args
*/ */
argc = argv();
stderr = files(2);
program = argv(0);
config("verbose_quit", 0),; config("verbose_quit", 0),;
base_lim = 10000; /* default: highest base we will consider */ base_lim = 10000; /* default: highest base we will consider */
if (argv() < 2 || argv() > 3) { if (argc < 2 || argc > 3) {
fprintf(files(2), "usage: %s [base_limit] value\n", argv(0)); fprintf(stderr, "usage: %s [base_limit] value\n", program);
exit; exit;
} }
if (argv() == 3) { if (argc == 3) {
x = eval(argv(2)); x = eval(argv(2));
base_lim = eval(argv(1)); base_lim = eval(argv(1));
} else { } else {
x = eval(argv(1)); x = eval(argv(1));
} }
if (! isint(x)) { if (! isint(x)) {
fprintf(files(2), "%s: value must be an integer\n"); fprintf(stderr, "%s: value must be an integer\n", program);
exit; exit;
} }
if (! isint(base_lim)) { if (! isint(base_lim)) {
fprintf(files(2), "%s: base limit must be an integer\n"); fprintf(stderr, "%s: base limit must be an integer\n", program);
exit; exit;
} }
if (base_lim <= 1) { if (base_lim <= 1) {
fprintf(files(2), "%s: base limit is too small\n"); fprintf(stderr, "%s: base limit is too small\n", program);
exit; exit;
} }
++base_lim; ++base_lim;

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f #!/usr/local/src/bin/calc/calc -q -s -f
/* /*
* simple - an example of a simple calc shell script * simple - an example of a simple calc shell script
* *
* Copyright (C) 1999-2007,2014 Landon Curt Noll * Copyright (C) 1999-2007,2014,2019 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
@@ -30,3 +30,9 @@
* This is an example of a simple calc shell script. * This is an example of a simple calc shell script.
*/ */
print "This simple calc shell script works!" print "This simple calc shell script works!"
print "config(\"program\")=", config("program");
print "argv()=", argv();
argc = argv();
for (i=0; i < argc; ++i) {
print "argv(":i:")=", argv(i);
}

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f #!/usr/local/src/bin/calc/calc -q -s -f
/* /*
* sqaure - print the squares of input values * sqaure - print the squares of input values
* *
* Copyright (C) 2000-2007,2014 Ernest Bowen * Copyright (C) 2000-2007,2014,2019 Ernest Bowen
* *
* 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
@@ -33,10 +33,6 @@
* cat file | ./square * cat file | ./square
* echo "123" | ./square * echo "123" | ./square
* *
* Within calc:
*
* > read square
*
* With input from a terminal, there is no prompt but each non-empty * With input from a terminal, there is no prompt but each non-empty
* line of input is evaluated as a calc expression and if it can be * line of input is evaluated as a calc expression and if it can be
* calculated, the square of the value of that expression is displayed. * calculated, the square of the value of that expression is displayed.
@@ -59,6 +55,6 @@
*/ */
global s; while (s = fgetline(files(0))) {
while ((s = prompt("")))
print "\t":eval(s)^2; print "\t":eval(s)^2;
}

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.10 VERSION= 2.12.7.6
# Names of shared libraries with versions # Names of shared libraries with versions
# #

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions # The default calc versions
# #
VERSION= 2.12.6.10 VERSION= 2.12.7.6
# Names of shared libraries with versions # Names of shared libraries with versions
# #

1
file.c
View File

@@ -1021,6 +1021,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
switch (ch) { switch (ch) {
case 's': case 's':
printstring = TRUE; printstring = TRUE;
/*FALLTHRU*/
case 'c': case 'c':
printchar = TRUE; printchar = TRUE;
case 'd': case 'd':

View File

@@ -125,7 +125,8 @@ main(int argc, char **argv)
* systems a FILEPOS is not a scalar hince we must memcpy. * systems a FILEPOS is not a scalar hince we must memcpy.
*/ */
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s\n", printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(FPOS_POS_LEN))"); "\\\n\tmemcpy((void *)(dest), (void *)(src), "
"sizeof(FPOS_POS_LEN))");
#endif /* HAVE_FILEPOS_SCALAR */ #endif /* HAVE_FILEPOS_SCALAR */
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */ #endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
putchar('\n'); putchar('\n');

View File

@@ -1,7 +1,7 @@
/* /*
* have_getpgid - determine if we have getpgid() * have_getpgid - determine if we have getpgid()
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -39,7 +39,10 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h> #include <unistd.h>
#endif
int int
main(void) main(void)

View File

@@ -1,7 +1,7 @@
/* /*
* have_getprid - determine if we have getprid() * have_getprid - determine if we have getprid()
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -40,7 +40,10 @@
#include <sys/types.h> #include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h> #include <unistd.h>
#endif
int int
main(void) main(void)

View File

@@ -1,7 +1,7 @@
/* /*
* have_getsid - determine if we have getsid() * have_getsid - determine if we have getsid()
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -40,6 +40,10 @@
#include <sys/types.h> #include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
int int
main(void) main(void)

View File

@@ -1,7 +1,7 @@
/* /*
* have_memmv - Determine if we have memmove() * have_memmv - Determine if we have memmove()
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -40,6 +40,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define MOVELEN 3 #define MOVELEN 3

View File

@@ -1,7 +1,7 @@
/* /*
* have_newstr - Determine if we have a system without ANSI C string functions * have_newstr - Determine if we have a system without ANSI C string functions
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -42,6 +42,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define MOVELEN 3 #define MOVELEN 3

View File

@@ -1,7 +1,7 @@
/* /*
* have_offscl - determine if we have a scalar off_t element * have_offscl - determine if we have a scalar off_t element
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -46,6 +46,10 @@
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
int int
main(void) main(void)

View File

@@ -1,7 +1,7 @@
/* /*
* have_posscl - determine if we have a scalar FILEPOS element * have_posscl - determine if we have a scalar FILEPOS element
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2021 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
@@ -45,6 +45,10 @@
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "have_fpos.h" #include "have_fpos.h"
int int

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

@@ -7,7 +7,8 @@ Environment variables
/ ./ ../ ~ / ./ ../ ~
If this variable does not exist, a compiled value If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is: is used. Typically compiled in value is:
.:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR} .:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR}
@@ -27,7 +28,8 @@ Environment variables
line), calc searches for files along the :-separated line), calc searches for files along the :-separated
$CALCRC environment variable. $CALCRC environment variable.
If this variable does not exist, a compiled value If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is: is used. Typically compiled in value is:
${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit
@@ -66,7 +68,8 @@ Environment variables
This value is taken to be the home directory of the This value is taken to be the home directory of the
current user. It is used when files begin with '~/'. current user. It is used when files begin with '~/'.
If this variable does not exist, the home directory password If this variable does not exist, or if this
variable is an empty string, the home directory password
entry of the current user is used. If that information entry of the current user is used. If that information
is not available, '.' is used. is not available, '.' is used.
@@ -75,7 +78,8 @@ Environment variables
When invoking help, this environment variable is used When invoking help, this environment variable is used
to display a help file. to display a help file.
If this variable does not exist, a compiled value If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is something is used. Typically compiled in value is something
such as 'more', 'less', 'pg' or 'cat'. such as 'more', 'less', 'pg' or 'cat'.
@@ -84,11 +88,20 @@ Environment variables
When a !-command is used, the program indicated by When a !-command is used, the program indicated by
this environment variable is used. this environment variable is used.
If this variable does not exist, a compiled value If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is something is used. Typically compiled in value is something
such as 'sh' is used. such as 'sh' is used.
## Copyright (C) 1999 Landon Curt Noll CALCHISTFILE
This value is taken to be the calc history file.
If this variable does not exist, or if this
variable is an empty string, then ~/.calc_history
is used.
## Copyright (C) 1999,2021 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

@@ -16,7 +16,8 @@ DESCRIPTION
assume n and limit are both nonnegative. assume n and limit are both nonnegative.
If n has a prime proper factor less than or equal to limit, then If n has a prime proper factor less than or equal to limit, then
factor(n, limit) returns the smallest such factor. factor(n, limit) returns the smallest such factor, or 1 if no
factor was found below the limit.
NOTE: A proper factor of n>1 is a factor < n. In other words, NOTE: A proper factor of n>1 is a factor < n. In other words,
for n>1 is not a proper factor of itself. The value 1 for n>1 is not a proper factor of itself. The value 1
@@ -50,7 +51,7 @@ SEE ALSO
isprime, lfactor, nextcand, nextprime, prevcand, prevprime, isprime, lfactor, nextcand, nextprime, prevcand, prevprime,
pfact, pix, ptest pfact, pix, ptest
## Copyright (C) 1999-2006 Landon Curt Noll ## Copyright (C) 1999-2006,2021 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

@@ -15,7 +15,7 @@ What is calc?
15 15
Calc as the usual collection of arithmetic operators +, -, /, * Calc has the usual collection of arithmetic operators +, -, /, *
as well as ^ (exponentiation), % (modulus) and // (integer divide). as well as ^ (exponentiation), % (modulus) and // (integer divide).
For example: For example:
@@ -137,7 +137,7 @@ What is calc?
f2(79) f2(79)
will produce; will produce:
1009847364737869270905302433221592504062302663202724609375 1009847364737869270905302433221592504062302663202724609375
@@ -150,7 +150,7 @@ What is calc?
sc(31, 61) sc(31, 61)
will produce; will produce:
256772 256772

View File

@@ -6,7 +6,7 @@ SYNOPSIS
TYPES TYPES
x number x number
x number y number
eps nonzero real, defaults to epsilon() eps nonzero real, defaults to epsilon()
return number return number

View File

@@ -51,7 +51,7 @@ 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 real or exponential depending on config("display") g general format (real or exponential)
r fractional r fractional
o octal o octal
x hexadecimal x hexadecimal
@@ -63,15 +63,27 @@ DESCRIPTION
if a positive width w has been specified, the effect is to if a positive width w has been specified, the effect is to
produce w spaces, e.g., printf("abc%6dxyz") prints "abc xyz". produce w spaces, e.g., printf("abc%6dxyz") prints "abc xyz".
Control charters may be given in fmt by escaping them with
the \ character. The following control charter escape
sequences are recognized:
\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
If i <= the number of specifiers in fmt, the value of argument 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. x_i is printed in the format specified by the i-th specifier.
If a positive width w has been specified and normal printing If a positive width w has been specified and normal printing
of x_i does not include a '\n' character, what is printed will 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 if necessary be padded with spaces so that the length of the
printed output is at least the w. Note that control characters printed output is at least the w. Note that control characters
like '\t', '\b' each count as one character. If the 'right-pad' (e.g., '\a', '\b', '\f', '\n', '\r', '\t', '\n') count as one
flag has been set, the padding is on the right; otherwise it character. If the 'right-pad' flag has been set, the padding
is on the left. 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
@@ -84,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 displayed. Other floating point) or as an exponential (e) depending on the
aspects of this printing may be affected by the configuration configuration parameter "display".
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.
@@ -117,11 +145,82 @@ EXAMPLE
[2] = "undefined" [2] = "undefined"
[3] = NULL [3] = NULL
; c = config("display", 50); ; config("display", 50),;
; printf("%g %g\n%g %g\n", 1e5, 1e49, 1e50, 1e500); ; printf("%g %g\n%g %g\n", 1e5, 1e49, 1e50, 1e500);
100000 100000000000000000000000000000000000000000000000000 100000 100000000000000000000000000000000000000000000000000
1e50 1e500 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.
@@ -130,7 +229,7 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
fprintf, strprintf, print config, display, epsilon, fprintf, strprintf
## Copyright (C) 1999-2006,2018 Landon Curt Noll ## Copyright (C) 1999-2006,2018 Landon Curt Noll
## ##

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,22 +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.
" "
; c = config("display", 50); ; config("display", 50),;
; fmt2 = "%g %g\n%g %g\n" ; fmt2 = "%g %g\n%g %g\n"
; strprintf(fmt2, 1e5, 1e49, 1e50, 1e500); ; strprintf(fmt2, 1e5, 1e49, 1e50, 1e500);
"100000 100000000000000000000000000000000000000000000000000 "100000 100000000000000000000000000000000000000000000000000
1e50 1e500 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.
@@ -41,10 +87,9 @@ 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,2018 Landon Curt Noll
## ##

14
hist.c
View File

@@ -51,6 +51,7 @@
#endif #endif
#include "calc.h" #include "calc.h"
#include "lib_calc.h"
#include "hist.h" #include "hist.h"
#include "have_string.h" #include "have_string.h"
@@ -1461,9 +1462,6 @@ quit_calc(void)
*/ */
/* name of history file */
char *my_calc_history = NULL;
size_t size_t
hist_getline(char *prompt, char *buf, size_t len) hist_getline(char *prompt, char *buf, size_t len)
{ {
@@ -1504,8 +1502,8 @@ my_stifle_history (void)
/* only save last number of entries */ /* only save last number of entries */
stifle_history(HISTORY_LEN); stifle_history(HISTORY_LEN);
if (my_calc_history) if (calc_history)
write_history(my_calc_history); write_history(calc_history);
} }
@@ -1519,10 +1517,12 @@ hist_init(char UNUSED *filename)
using_history(); using_history();
/* name of history file */ /* name of history file */
my_calc_history = tilde_expand("~/.calc_history"); if (calc_history == NULL) {
calc_history = tilde_expand("~/.calc_history");
}
/* read previous history */ /* read previous history */
read_history(my_calc_history); read_history(calc_history);
atexit(my_stifle_history); atexit(my_stifle_history);

View File

@@ -1,7 +1,7 @@
/* /*
* lib_calc - calc link library initialization and shutdown routines * lib_calc - calc link library initialization and shutdown routines
* *
* 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
@@ -145,6 +145,7 @@ char *calcbindings = NULL; /* $CALCBINDINGS or default */
char *home = NULL; /* $HOME or default */ char *home = NULL; /* $HOME or default */
char *pager = NULL; /* $PAGER or default */ char *pager = NULL; /* $PAGER or default */
char *shell = NULL; /* $SHELL or default */ char *shell = NULL; /* $SHELL or default */
char *calc_history = NULL; /* $CALCHISTFILE or ~/.calc_history */
int stdin_tty = FALSE; /* TRUE if stdin is a tty */ int stdin_tty = FALSE; /* TRUE if stdin is a tty */
int havecommands = FALSE; /* TRUE if have one or more cmd args */ int havecommands = FALSE; /* TRUE if have one or more cmd args */
long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */ long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */
@@ -504,22 +505,36 @@ initenv(void)
home = (c ? strdup(c) : NULL); home = (c ? strdup(c) : NULL);
#if defined(_WIN32) #if defined(_WIN32)
if (home == NULL || home[0] == '\0') { if (home == NULL || home[0] == '\0') {
/* free home if it was previously allocated, but empty */
if (home != NULL) {
free(home);
}
/* just assume . is home if all else fails */ /* just assume . is home if all else fails */
home = "."; home = strdup(".");
} }
#else /* Windoz free systems */ #else /* Windoz free systems */
if (home == NULL || home[0] == '\0') { if (home == NULL || home[0] == '\0') {
size_t pw_dir_len; /* free home if it was previously allocated, but empty */
ent = (struct passwd *)getpwuid(geteuid()); if (home != NULL) {
if (ent == NULL) { free(home);
/* just assume . is home if all else fails */ }
home = "."; /* try using the home directory of current effective UID */
ent = (struct passwd *)getpwuid(geteuid());
if (ent == NULL || ent->pw_dir == NULL ||
ent->pw_dir[0] == '\0') {
/* just assume . is home if all else fails */
home = strdup(".");
} else {
/* use home directory of current effective UID */
home = strdup(ent->pw_dir);
} }
pw_dir_len = strlen(ent->pw_dir);
home = (char *)malloc(pw_dir_len+1);
strncpy(home, ent->pw_dir, pw_dir_len+1);
} }
#endif /* Windoz free systems */ #endif /* Windoz free systems */
/* paranoia */
if (home == NULL) {
math_error("Unable to allocate string for $HOME");
/*NOTREACHED*/
}
/* determine the $PAGER value */ /* determine the $PAGER value */
c = (no_env ? NULL : getenv(PAGER)); c = (no_env ? NULL : getenv(PAGER));
@@ -532,6 +547,12 @@ initenv(void)
shell = (c ? strdup(c) : NULL); shell = (c ? strdup(c) : NULL);
if (shell == NULL || *shell == '\0') if (shell == NULL || *shell == '\0')
shell = DEFAULTSHELL; shell = DEFAULTSHELL;
/* determine the $CALCHISTFILE value */
c = (no_env ? NULL : getenv(CALCHISTFILE));
calc_history = (c ? strdup(c) : NULL);
if (calc_history == NULL || *calc_history == '\0')
calc_history = NULL; /* will use ~/.calc_history */
} }

View File

@@ -74,4 +74,9 @@ EXTERN int calc_print_scanwarn_msg;
/* number of parse/scan warnings found */ /* number of parse/scan warnings found */
EXTERN unsigned long calc_warn_cnt; EXTERN unsigned long calc_warn_cnt;
/*
* calc history file
*/
EXTERN char *calc_history;
#endif /* !INCLUDE_MATH_ERROR_H */ #endif /* !INCLUDE_MATH_ERROR_H */

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

@@ -4104,6 +4104,7 @@ freenumbers(FUNC *fp)
case OP_QUIT: case OP_QUIT:
freestringconstant( freestringconstant(
(long)fp->f_opcodes[pc]); (long)fp->f_opcodes[pc]);
break;
} }
/*FALLTHRU*/ /*FALLTHRU*/
case OPLOC: case OPLOC:

6
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;
@@ -143,6 +144,7 @@ qprintf(char *fmt, ...)
case '-': case '-':
sign = -1; sign = -1;
ch = *fmt++; ch = *fmt++;
/*FALLTHRU*/
default: default:
if (('0' <= ch && ch <= '9') || if (('0' <= ch && ch <= '9') ||
ch == '.' || ch == '*') { ch == '.' || ch == '*') {

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')) {

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':
@@ -445,6 +447,7 @@ eatstring(int quotechar)
case '\n': case '\n':
if (!newlines) if (!newlines)
break; break;
/*FALLTHRU*/
case EOF: case EOF:
reread(); reread();
scanerror(T_NULL, scanerror(T_NULL,

View File

@@ -1879,9 +1879,9 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres)
*vres = error_value(E_1OVER0); *vres = error_value(E_1OVER0);
break; break;
} }
/* 0 ^ non-neg is zero, including 0^0 */ /* 0 ^ non-neg is 1, including 0^0 */
vres->v_type = V_NUM; vres->v_type = V_NUM;
vres->v_num = qlink(&_qzero_); vres->v_num = qlink(&_qone_);
} else if (qisint(real_v2)) { } else if (qisint(real_v2)) {
vres->v_num = qpowi(v1->v_num, real_v2); vres->v_num = qpowi(v1->v_num, real_v2);
} else { } else {

View File

@@ -1,7 +1,7 @@
/* /*
* version - determine the version of calc * version - determine the version of calc
* *
* Copyright (C) 1999-2018 David I. Bell and Landon Curt Noll * Copyright (C) 1999-2021 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 10 /* minor software level or 0 if not patched */ #define MINOR_PATCH 6 /* minor software level or 0 if not patched */
/* /*
@@ -69,7 +69,7 @@ STATIC char *stored_version = NULL; /* version formed if != NULL */
char *Copyright = "\n" char *Copyright = "\n"
"calc - arbitrary precision calculator\n" "calc - arbitrary precision calculator\n"
"\n" "\n"
"Copyright (C) 1999-2017 David I. Bell, Landon Curt Noll " "Copyright (C) 1999-2021 David I. Bell, Landon Curt Noll "
"and Ernest Bowen\n" "and Ernest Bowen\n"
"\n" "\n"
"Initial author: David I. Bell\n" "Initial author: David I. Bell\n"