Compare commits

..

12 Commits

Author SHA1 Message Date
Landon Curt Noll
eaec46982d Release v2.12.9.1
The following are the changes in this release:

    Fixed a typo typo in help/Makefile that caused the build of
    2.12.9.0 to fail in a number of cases.  Thanks to a report by
    <GitHub user balducci>.

    Pass form Makefile variables ${Q}, ${S}, ${E}, ${H} and ${V} down
    to all sub-directory Makefiles from the top level Makefile.
2021-03-26 09:31:36 -07:00
Landon Curt Noll
a86d629982 Fixed a typo in help/Makefile
Fixed a typo typo in help/Makefile that caused the build of
2.12.9.0 to fail in a number of cases.  Thanks to a report by
<GitHub user balducci>.
2021-03-12 11:31:21 -08:00
Landon Curt Noll
bcbc0cb766 Merge pull request #25 from atsampson/doubleassign
Remove redundant assignments when byteswapping
2021-03-11 03:14:14 -08:00
Landon Curt Noll
ac0d84eef8 Release v2.12.9.0
Added notes to help/unexpected about:

    display() will limit the number of digits printed after decimal point

    %d will format after the decimal point for non-integer numeric values

    %x will format as fractions for non-integer numeric values

    fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish

Fixed Makefile dependencies for the args.h rule.

Fixed Makefile cases where echo with -n is used.  On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.

Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.

Sort lists of standard tool Makefile variables and remove duplicates.

Declare the SHELL at the top of Makefiles.

Fixed the depend rule in the custom Makefile.

Improved the messages produced by the depend in the Makefiles.

Changed the UNUSED define in have_unused.h to be a macro with
a parameter.  Changed all use of UNUSED in *.c to be UNUSED(x).

Removed need for HAVE_UNUSED in building the have_unused.h file.

 CCBAN is given to ${CC} in order to control if banned.h is in effect.

 The banned.h attempts to ban the use of certain dangerous functions
 that, if improperly used, could compromise the computational integrity
 if calculations.

 In the case of calc, we are motivated in part by the desire for calc
 to correctly calculate: even during extremely long calculations.

 If UNBAN is NOT defined, then calling certain functions
 will result in a call to a non-existent function (link error).

 While we do NOT encourage defining UNBAN, there may be
 a system / compiler environment where re-defining a
 function may lead to a fatal compiler complication.
 If that happens, consider compiling as:

    make clobber all chk CCBAN=-DUNBAN

 as see if this is a work-a-round.

 If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
 Please send us a bug report.  See the file:

    BUGS

 or the URL:

    http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html

 for how to send us such a bug report.

 Added the building of have_ban_pragma.h, which will determine
 if "#pragma GCC poison func_name" is supported.  If it is not,
 or of HAVE_PRAGMA_GCC_POSION=-DHAVE_NO_PRAGMA_GCC_POSION, then
 banned.h will have no effect.

 Fixed building of the have_getpgid.h file.
 Fixed building of the have_getprid.h file.
 Fixed building of the have_getsid.h file.
 Fixed building of the have_gettime.h file.
 Fixed building of the have_strdup.h file.
 Fixed building of the have_ustat.h file.
 Fixed building of the have_rusage.h file.

 Added HAVE_NO_STRLCPY to control if we want to test if
 the system has a strlcpy() function.  This in turn produces
 the have_strlcpy.h file wherein the symbol HAVE_STRLCPY will
 be defined, or not depending if the system comes with a
 strlcpy() function.

 If the system does not have a strlcpy() function, we
 compile our own strlcpy() function.  See strl.c for details.

 Added HAVE_NO_STRLCAT to control if we want to test if
 the system has a strlcat() function.  This in turn produces
 the have_strlcat.h file wherein the symbol HAVE_STRLCAT will
 be defined, or not depending if the system comes with a
 strlcat() function.

 If the system does not have a strlcat() function, we
 compile our own strlcat() function.  See strl.c for details.

 Fixed places were <string.h>, using #ifdef HAVE_STRING_H
 for legacy systems that do not have that include file.

 Added ${H} Makefile symbol to control the announcement
 of forming and having formed hsrc related files.  By default
 H=@ (announce hsrc file formation) vs. H=@: to silence hsrc
 related file formation.

 Explicitly turn off quiet mode (set Makefile variable ${Q} to
 be empty) when building rpms.

 Improved and fixed the hsrc build process.

 Forming rpms is performed in verbose mode to assist debugging
 to the rpm build process.

 Compile custom code, if needed, after main code is compiled.
2021-03-11 01:54:28 -08:00
Landon Curt Noll
9b4580d861 Fix typo in make depend messages 2021-03-07 02:37:59 -08:00
Landon Curt Noll
2085361df1 Fix make depend plus make depend Makefile changes 2021-03-07 02:03:28 -08:00
Landon Curt Noll
bf4657c138 Cleanup of Makefiles
Fixed Makefile dependenies for the args.h rule.

Fixed Makefile cases where echo with -n is used.  On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.

Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.

Sort lists of standard tool Makefile variables and remove duplicates.

Declare the SHELL at the top of Makefiles.

Fixed the depend rule in the custom Makefile.
2021-03-07 01:26:40 -08:00
Landon Curt Noll
1b5636afed Use ${ECHON} for when /bin/echo -n is needed 2021-03-06 22:21:36 -08:00
Landon Curt Noll
7eba99ac29 Add notes about unexpeded things in using calc 2021-03-06 22:12:14 -08:00
Landon Curt Noll
de6474bf28 Declare SHELL at makefile top, sort and fix standard tool list in Makefiles 2021-03-06 22:09:10 -08:00
Landon Curt Noll
55bc690cd1 Fix dependencies for args.h 2021-03-06 21:00:45 -08:00
Adam Sampson
6dc62c1ab7 Remove redundant assignments when byteswapping.
The SWAP_ macros already write the result to their destination arg, so
there's no need for an extra assignment -- and this is undefined
behaviour because there are two assignments to the same variable without
an intervening sequence point (as GCC 10 correctly warns).
2021-03-06 01:46:04 +00:00
110 changed files with 3770 additions and 1414 deletions

4
.gitignore vendored
View File

@@ -33,6 +33,7 @@ custom/libcustcalc*
endian
endian_calc.h
fposval.h
have_ban_pragma.h
have_const.h
have_fpos.h
have_fpos_pos.h
@@ -49,6 +50,8 @@ have_stdlib.h
have_stdvs
have_strdup.h
have_string.h
have_strlcat.h
have_strlcpy.h
have_times.h
have_uid_t.h
have_unistd.h
@@ -88,6 +91,7 @@ longbits
longbits.h
sample_many
sample_rand
tags
terminal.h
ver_calc

129
CHANGES
View File

@@ -1,4 +1,130 @@
The following are the changes from calc version 2.12.8.1 to date:
The following are the changes from calc version 2.12.9.1 to date:
Fixed a typo typo in help/Makefile that caused the build of
2.12.9.0 to fail in a number of cases. Thanks to a report by
<GitHub user balducci>.
Pass form Makefile variables ${Q}, ${S}, ${E}, ${H} and ${V} down
to all sub-directory Makefiles from the top level Makefile.
The following are the changes from calc version 2.12.8.2 to 2.12.9.0:
Added notes to help/unexpected about:
display() will limit the number of digits printed after decimal point
%d will format after the decimal point for non-integer numeric values
%x will format as fractions for non-integer numeric values
fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish
Fixed Makefile dependencies for the args.h rule.
Fixed Makefile cases where echo with -n is used. On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.
Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.
Sort lists of standard tool Makefile variables and remove duplicates.
Declare the SHELL at the top of Makefiles.
Fixed the depend rule in the custom Makefile.
Improved the messages produced by the depend in the Makefiles.
Changed the UNUSED define in have_unused.h to be a macro with
a parameter. Changed all use of UNUSED in *.c to be UNUSED(x).
Removed the need for HAVE_UNUSED in building the have_unused.h file.
CCBAN is given to ${CC} in order to control if banned.h is in effect.
The banned.h attempts to ban the use of certain dangerous functions
that, if improperly used, could compromise the computational integrity
if calculations.
In the case of calc, we are motivated in part by the desire for calc
to correctly calculate: even during extremely long calculations.
If UNBAN is NOT defined, then calling certain functions
will result in a call to a non-existent function (link error).
While we do NOT encourage defining UNBAN, there may be
a system / compiler environment where re-defining a
function may lead to a fatal compiler complication.
If that happens, consider compiling as:
make clobber all chk CCBAN=-DUNBAN
as see if this is a work-a-round.
If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
Please send us a bug report. See the file:
BUGS
or the URL:
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
for how to send us such a bug report.
Added the building of have_ban_pragma.h, which will determine
if "#pragma GCC poison func_name" is supported. If it is not,
or of HAVE_PRAGMA_GCC_POSION=-DHAVE_NO_PRAGMA_GCC_POSION, then
banned.h will have no effect.
Fixed building of the have_getpgid.h file.
Fixed building of the have_getprid.h file.
Fixed building of the have_getsid.h file.
Fixed building of the have_gettime.h file.
Fixed building of the have_strdup.h file.
Fixed building of the have_ustat.h file.
Fixed building of the have_rusage.h file.
Added HAVE_NO_STRLCPY to control if we want to test if
the system has a strlcpy() function. This in turn produces
the have_strlcpy.h file wherein the symbol HAVE_STRLCPY will
be defined, or not depending if the system comes with a
strlcpy() function.
If the system does not have a strlcpy() function, we
compile our own strlcpy() function. See strl.c for details.
Added HAVE_NO_STRLCAT to control if we want to test if
the system has a strlcat() function. This in turn produces
the have_strlcat.h file wherein the symbol HAVE_STRLCAT will
be defined, or not depending if the system comes with a
strlcat() function.
If the system does not have a strlcat() function, we
compile our own strlcat() function. See strl.c for details.
Fixed places were <string.h>, using #ifdef HAVE_STRING_H
for legacy systems that do not have that include file.
Added ${H} Makefile symbol to control the announcement
of forming and having formed hsrc related files. By default
H=@ (announce hsrc file formation) vs. H=@: to silence hsrc
related file formation.
Explicitly turn off quiet mode (set Makefile variable ${Q} to
be empty) when building rpms.
Improved and fixed the hsrc build process.
Forming rpms is performed in verbose mode to assist debugging
to the rpm build process.
Compile custom code, if needed, after main code is compiled.
The following are the changes from calc version 2.12.8.1 to 2.12.8.2:
Fixed how the *.tar.bz2 are formed. The calc-2.12.8.0.tar.bz2 file
that was formed for calc version 2.12.8.0 was missing most files.
@@ -13,6 +139,7 @@ The following are the changes from calc version 2.12.8.1 to date:
thanks to a report by <GitHub user barsnick>.
The following are the changes from calc version 2.12.7.5 to 2.12.8.0:
Fixed a mistake in "help intro" where some inserted text changed

147
Makefile
View File

@@ -53,6 +53,65 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
#SHELL= /bin/sh
SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
# Try uname -s if the target was not already set on the make command line
#
ifeq ($(target),)
@@ -142,7 +201,6 @@ endif
# standard utilities used during make
#
SHELL= /bin/sh
MAKE= make
SED= sed
GREP= egrep
@@ -160,11 +218,30 @@ CI= ci
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
@@ -180,20 +257,24 @@ XARG=
# that invokes the ${MAKE_FILE}.
#
XVAR= \
target=${target} \
USE_READLINE='${USE_READLINE}' \
READLINE_LIB='${READLINE_LIB}' \
READLINE_INCLUDE='${READLINE_INCLUDE}' \
RPM_TOP='${RPM_TOP}' \
MAKE_FILE='${MAKE_FILE}' \
EXT='${EXT}' \
DARWIN_ARCH='${DARWIN_ARCH}' \
CCBAN='${CCBAN}' \
CCWERR='${CCWERR}' \
NROFF='${NROFF}' \
COMMON_ADD='${COMMON_ADD}' \
DARWIN_ARCH='${DARWIN_ARCH}' \
E='${E}' \
EXT='${EXT}' \
H='${H}' \
MAKE_FILE='${MAKE_FILE}' \
MANDIR='${MANDIR}' \
NROFF='${NROFF}' \
Q='${Q}' \
V='${V}'
READLINE_INCLUDE='${READLINE_INCLUDE}' \
READLINE_LIB='${READLINE_LIB}' \
RPM_TOP='${RPM_TOP}' \
S='${S}' \
USE_READLINE='${USE_READLINE}' \
V='${V}' \
target=${target}
# We update the calc version string in these makefiles
#
@@ -209,7 +290,7 @@ XMKVER= ${MAKE_FILE} custom/Makefile.head
#
###
all: fix_version check_include
all: fix_version
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
@@ -504,6 +585,20 @@ have_unused.h:
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_ban_pragma.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_strlcpy.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
have_strlcat.h:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
@@ -519,34 +614,6 @@ win32_hsrc:
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
# These rules are used in the process of building the BUILD_H_SRC.
#
##
endian.o:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
endian${EXT}:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
longbits.o:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
longbits${EXT}:
${V} echo '=-=-=-=-= private Makefile $@ rule start =-=-=-=-='
${Q} ${MAKE} ${XARG} -f ${MAKE_FILE} $@ ${XVAR}
${V} echo '=-=-=-=-= private Makefile $@ rule end =-=-=-=-='
##
#
# These two .all rules are used to determine of the lower level

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/*
* addop - add opcodes to a function being compiled
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -28,6 +28,7 @@
#include <stdio.h>
#include "calc.h"
#include "alloc.h"
#include "opcodes.h"
#include "str.h"
#include "func.h"
@@ -36,6 +37,9 @@
#include "symbol.h"
#include "banned.h" /* include after system header <> includes */
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */

View File

@@ -1,7 +1,7 @@
/*
* align32 - determine if 32 bit accesses must be aligned
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -34,6 +34,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
static void buserr(void); /* catch alignment errors */

View File

@@ -1,7 +1,7 @@
/*
* assocfunc - association table routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,9 @@
#include "value.h"
#include "banned.h" /* include after system header <> includes */
#define MINHASHSIZE 31 /* minimum size of hash tables */
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */

180
banned.h Normal file
View File

@@ -0,0 +1,180 @@
/*
* banned - optionally ban dqngerious functions
*
* Unless UNBAN is defined, this file will turn the use
* of certain dangerous functions into syntax errors.
*
* In the case of calc, we are motivated in part by the desire for
* calc to correctly calculate: even durings extremely long calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a syntaxc error.
*
* If we define UNBAN, then the effect of this file is disabled.
*
* The banned.h attempts to ban the use of certain dangerous functions
* that, if improperly used, could compromise the computational integrity
* if calculations.
*
* In the case of calc, we are motivated in part by the desire for calc
* to correctly calculate: even durings extremely long calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a call to a non-existent function (link error).
*
* While we do NOT encourage defining UNBAN, there may be
* a system / compiler environment where re-defining a
* function may lead to a fatal compiler complication.
* If that happens, consider compiling as:
*
* make clobber all chk CCBAN=-DUNBAN
*
* as see if this is a work-a-round.
*
* If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
* Please send us a bug report. See the file:
*
* BUGS
*
* or the URL:
*
* http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
*
* for how to send us such a bug report.
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/06 21:07:31
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(PRE_HAVE_BAN_PRAGMA_H)
#include "have_ban_pragma.h"
#endif /* ! PRE_HAVE_BAN_PRAGMA_H */
#if !defined(INCLUDE_BANNED_H)
#define INCLUDE_BANNED_H
/*
* If we define UNBAN, then the effect of this file is disabled.
*/
#if !defined(UNBAN)
/*
* In the spirit of:
*
* https://github.com/git/git/blob/master/banned.h
*
* we will ban the use of certain unsafe functions by turning
* then into function calls that do not exist.
*
* In the case of calc, we are motivated in part by the desire
* for calc to correctly calculate: even durings extremely long
* calculations.
*
* If UNBAN is NOT defined, then calling certain functions
* will result in a syntaxc error.
*
* Unlike the above URL, we suggest an alternative function.
* In many cases, additional logic is required to use the
* alternative function, we cannot simply replace one function
* with another.
*/
/*
* If one is not careful, strcpy() can lead to buffer overflows.
* Use strlcpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strcpy
#pragma GCC poison strcpy
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strcat() can lead to buffer overflows.
* Use strlcat() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strcat
#pragma GCC poison strcat
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strncpy() can lead to buffer overflows.
* Use memccpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strncpy
#pragma GCC poison strncpy
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, strncat() can lead to buffer overflows.
* Use memccpy() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef strncat
#pragma GCC poison strncat
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, sprintf() can lead to buffer overflows.
* Use snprintf() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef sprintf
#pragma GCC poison sprintf
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* If one is not careful, vsprintf() can lead to buffer overflows.
* Use vsnprintf() instead.
*/
#if defined(HAVE_PRAGMA_GCC_POSION)
#undef vsprintf
#pragma GCC poison vsprintf
#endif /* HAVE_PRAGMA_GCC_POSION */
/*
* XXX - As of 2021, functions such as:
*
* gmtime_s
* localtime_s
* ctime_s
* asctime_s
*
* are not universal. We cannot yet ban the following
* functions because we do not have a portable AND
* widely available alternative. Therefore we just
* have to be extra careful when using:
*
* gmtime
* localtime
* ctime
* ctime_r
* asctime
* asctime_r
*/
#endif /* !UNBAN */
#endif /* !INCLUDE_BANNED_H */

View File

@@ -29,12 +29,16 @@
#include <stdio.h>
#include <sys/types.h>
#include "calc.h"
#include "alloc.h"
#include "value.h"
#include "file.h"
#include "blkcpy.h"
#include "str.h"
#include "banned.h" /* include after system header <> includes */
/*
* copystod - copy num indexed items from source value to destination value
*

View File

@@ -28,6 +28,11 @@
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "alloc.h"
#include "value.h"
#include "zmath.h"
#include "config.h"
@@ -36,6 +41,10 @@
#include "str.h"
#include "calcerr.h"
#include "banned.h" /* include after system header <> includes */
#define NBLOCKCHUNK 16
STATIC long nblockcount = 0;

View File

@@ -29,6 +29,9 @@
#include "byteswap.h"
#include "banned.h" /* include after system header <> includes */
/*
* swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs
*
@@ -123,8 +126,8 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_B8_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
SWAP_B8_IN_LEN(&dest->len, &src->len);
SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -189,7 +192,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
SWAP_B8_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -253,7 +256,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
SWAP_B8_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -358,8 +361,8 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_B16_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
SWAP_B16_IN_LEN(&dest->len, &src->len);
SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -424,7 +427,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
SWAP_B16_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -488,7 +491,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
SWAP_B16_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -554,8 +557,8 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_HALF_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
SWAP_HALF_IN_LEN(&dest->len, &src->len);
SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -620,7 +623,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
SWAP_HALF_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -684,7 +687,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
SWAP_HALF_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}

View File

@@ -27,9 +27,28 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide
@@ -157,27 +176,51 @@ T=
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
# standard tools
#
CHMOD= chmod
CMP= cmp
RM= rm
MKDIR= mkdir
RMDIR= rmdir
CP= cp
MV= mv
CO= co
TRUE= true
TOUCH= touch
CP= cp
FMT= fmt
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
FMT= fmt
TOUCH= touch
TRUE= true
# The calc files to install
#
@@ -187,25 +230,24 @@ FMT= fmt
#
# make calc_files_list
#
# to keep this list in nice sorted order and to check that these
# detailed help files are under RCS control.
# to keep this list in nice sorted order.
#
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal \
lucas.cal lucas_chk.cal mersenne.cal mfactor.cal \
mod.cal natnumset.cal pell.cal pi.cal pix.cal pollard.cal poly.cal \
prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
sumtimes.cal surd.cal test1700.cal test2300.cal test2600.cal \
test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal \
test4000.cal test4100.cal test4600.cal test5100.cal test5200.cal \
test8400.cal test8500.cal test8600.cal test8900.cal toomcook.cal \
unitfrac.cal varargs.cal xx_print.cal zeta2.cal
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal intfile.cal \
intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal pell.cal \
pi.cal pix.cal pollard.cal poly.cal prompt.cal psqrt.cal qtime.cal \
quat.cal randbitrun.cal randmprime.cal randombitrun.cal randomrun.cal \
randrun.cal regress.cal repeat.cal screen.cal seedrandom.cal \
set8700.cal set8700.line smallfactors.cal solve.cal \
specialfunctions.cal statistics.cal strings.cal sumsq.cal sumtimes.cal \
surd.cal test1700.cal test2300.cal test2600.cal test2700.cal \
test3100.cal test3300.cal test3400.cal test3500.cal test4000.cal \
test4100.cal test4600.cal test5100.cal test5200.cal test8400.cal \
test8500.cal test8600.cal test8900.cal toomcook.cal unitfrac.cal \
varargs.cal xx_print.cal zeta2.cal
# These calc files are now obsolete and are removed by the install rule.
#
@@ -261,19 +303,13 @@ calcliblist:
#
calc_files_list:
${Q} -(find . -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
while read i; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i,v ]; then \
echo "WARNING: $$i not under RCS control" 1>&2; \
else \
echo $$i; \
fi; \
fi; \
done; \
echo '--first_line--'; \
echo README; \
echo set8700.line; \
echo bindings) | \
while read i; do \
echo $$i; \
done; \
echo '--first_line--'; \
echo README; \
echo set8700.line; \
echo bindings) | \
${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/ /' \
-e 's/$$/ \\/' -e '$$s/ \\$$//'

46
calc.c
View File

@@ -26,7 +26,6 @@
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#include <stdio.h>
#include <signal.h>
@@ -66,6 +65,7 @@
#include "lib_calc.h"
#include "args.h"
#include "zmath.h"
#include "strl.h"
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
@@ -85,6 +85,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* S_FUNC definitions and functions
*/
@@ -373,14 +376,20 @@ main(int argc, char **argv)
havearg = TRUE;
if (cmdlen > 0)
cmdbuf[cmdlen++] = ' ';
strcpy(cmdbuf + cmdlen, "read ");
cmdlen += 5;
if (strncmp(cp, "-once", 5) == 0 &&
(cp[5] == '\0' || cp[5] == ' ')) {
cp += 5;
strlcpy(cmdbuf + cmdlen, "read ",
sizeof("read "));
cmdlen += sizeof("read ")-1;
cmdbuf[cmdlen] = '\0';
if (strncmp(cp, "-once",
sizeof("-once")) == 0 &&
(cp[sizeof("-once")-1] == '\0' ||
cp[sizeof("-once")-1] == ' ')) {
cp += sizeof("-once")-1;
haveendstr = (*cp == '\0');
strcpy(cmdbuf+cmdlen, "-once ");
cmdlen += 6;
strlcpy(cmdbuf+cmdlen, "-once ",
sizeof("-once "));
cmdlen += sizeof("-once ")-1;
cmdbuf[cmdlen] = '\0';
if (nextcp(&cp, &index, argc,
argv, haveendstr)) {
fprintf(stderr, "-f -once"
@@ -406,7 +415,7 @@ main(int argc, char **argv)
}
/* XXX - what if *cp = '\''? */
*bp++ = '\'';
strncpy(bp, cp, len+1);
strlcpy(bp, cp, len+1);
bp += len;
*bp++ = '\'';
cp += len;
@@ -428,6 +437,7 @@ main(int argc, char **argv)
if (*cp == ';')
cp++;
*bp++ = ';';
*bp = '\0';
cmdlen++;
s_flag = TRUE; /* -f implies -s */
break;
@@ -480,21 +490,7 @@ main(int argc, char **argv)
program);
exit(21);
}
/*
* The next statement could be:
*
* strncpy(cmdbuf + cmdlen, cp, cplen);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(cmdbuf + cmdlen, cp, cplen);
strlcpy(cmdbuf + cmdlen, cp, cplen+1);
cmdbuf[newcmdlen] = '\0';
cmdlen = newcmdlen;
index++;
@@ -762,7 +758,7 @@ main(int argc, char **argv)
*/
/*ARGSUSED*/
S_FUNC void
intint(int UNUSED arg)
intint(int UNUSED(arg))
{
(void) signal(SIGINT, intint);
if (inputwait || (++abortlevel >= ABORT_NOW)) {

View File

@@ -28,6 +28,8 @@ BEGIN {
printf("#include <stdio.h>\n");
printf("#include \"calcerr.h\"\n\n");
printf("#include \"have_const.h\"\n\n");
printf("#include \"banned.h\"\t");
printf("/* include after system header <> includes */\n\n");
printf("/*\n");
printf(" * names of calc error values\n");
printf(" */\n");

View File

@@ -34,6 +34,7 @@
#include "lib_calc.h"
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "symbol.h"
#include "label.h"
@@ -41,11 +42,16 @@
#include "str.h"
#include "func.h"
#include "conf.h"
#include "strl.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <direct.h>
#endif
#include "banned.h" /* include after system header <> includes */
STATIC BOOL rdonce; /* TRUE => do not reread this file */
FUNC *curfunc;
@@ -144,11 +150,9 @@ getcommands(BOOL toplevel)
case 1:
case -1:
if(i == 1) {
strncpy(name,
strlcpy(name,
DEFAULTCALCHELP,
MAXCMD);
/* paranoia */
name[MAXCMD] = '\0';
MAXCMD+1);
givehelp(name);
}
break;
@@ -2354,8 +2358,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
/* use the value of the literal string */
s = findstring(tokenstring());
strncpy(name, s->s_str, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, s->s_str, namelen);
sfree(s);
break;
@@ -2392,8 +2395,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
}
/* return symbol name or value of global var string */
strncpy(name, symstr, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, symstr, namelen);
break;
case T_NEWLINE:
@@ -2431,7 +2433,7 @@ getshowstatement(void)
switch (gettoken()) {
case T_SYMBOL:
strncpy(name, tokensymbol(), 4);
strlcpy(name, tokensymbol(), sizeof(name));
name[4] = '\0';
/* Yuck! */
arg = stringindex("buil\000"
@@ -2595,8 +2597,7 @@ getid(char *buf)
*buf = '\0';
return FALSE;
}
strncpy(buf, tokensymbol(), SYMBOLSIZE);
buf[SYMBOLSIZE] = '\0';
strlcpy(buf, tokensymbol(), SYMBOLSIZE+1);
return TRUE;
}

View File

@@ -29,6 +29,10 @@
#include "config.h"
#include "cmath.h"
#include "banned.h" /* include after system header <> includes */
/*
* cache the natural logarithm of 10
*/

View File

@@ -1,7 +1,7 @@
/*
* commath - extended precision complex arithmetic primitive routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -27,6 +27,9 @@
#include "cmath.h"
#include "banned.h" /* include after system header <> includes */
COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 };
COMPLEX _cone_ = { &_qone_, &_qzero_, 1 };
COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };

View File

@@ -1,7 +1,7 @@
/*
* config - configuration routines
*
* Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll
* Copyright (C) 1999-2007,2021 David I. Bell and Landon Curt Noll
*
* Primary author: David I. Bell
*
@@ -46,6 +46,7 @@
#endif
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "zrand.h"
#include "block.h"
@@ -53,12 +54,17 @@
#include "config.h"
#include "str.h"
#include "custom.h"
#include "strl.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "banned.h" /* include after system header <> includes */
/*
* deal with systems that lack a defined CLK_TCK
*/
@@ -757,7 +763,7 @@ setconfig(int type, VALUE *vp)
math_error("Cannot duplicate new prompt");
/*NOTREACHED*/
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt1);
conf->prompt1 = p;
break;
@@ -772,7 +778,7 @@ setconfig(int type, VALUE *vp)
math_error("Cannot duplicate new more prompt");
/*NOTREACHED*/
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt2);
conf->prompt2 = p;
break;

View File

@@ -1,7 +1,7 @@
/*
* const - constant number storage module
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -28,6 +28,10 @@
#include "calc.h"
#include "qmath.h"
#include "banned.h" /* include after system header <> includes */
#define CONSTALLOCSIZE 400 /* number of constants to allocate */
STATIC unsigned long constcount;/* number of constants defined */

View File

@@ -27,9 +27,27 @@
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide
@@ -157,28 +175,59 @@ T=
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
# standard tools
#
CAT= cat
CHMOD= chmod
CMP= cmp
CO= co
CP= cp
FMT= fmt
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
FMT= fmt
CMP= cmp
MKDIR= mkdir
RMDIR= rmdir
RM= rm
TOUCH= touch
MV= mv
CP= cp
CO= co
TRUE= true
# NOTE: On some shells, echo is a builtin that does
# not understand -n, so we call /bin/echo -n
# directly to get around such shells.
#
ECHON= /bin/echo -n
# The ${SCRIPT} list is the list of calc shell script files (without the .calc
# extension) which will be installed.
#
@@ -188,19 +237,17 @@ TRUE= true
# To add a script:
#
# 1) Name the file with a .calc filename extension
# 2) Place that file under RCS control
# 3) Add the name, without the .calc extension to the ${SCRIPT} below
# 4) Write out this Makefile
# 5) Replace the ${SCRIPT} and ${SCRIPT_SRC} lines with the output of:
# 2) Add the name, without the .calc extension to the ${SCRIPT} below
# 3) Write out this Makefile
# 4) Replace the SCRIPT= and SCRIPT_SRC= lines with the output of:
#
# make detaillist
#
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm \
simple square
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm simple \
square
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc \
piforever.calc plus.calc powerterm.calc simple.calc \
square.calc
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc piforever.calc \
plus.calc powerterm.calc simple.calc square.calc
# These files are found (but not built) in the distribution
#
@@ -264,11 +311,7 @@ detaillist:
${Q} -(echo "xxxxxxx"; \
for i in ${SCRIPT} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i.calc,v ]; then \
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
else \
echo $$i; \
fi; \
echo $$i; \
fi; \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxx/SCRIPT=/' -e '2,$$s/^/ /' \
@@ -277,11 +320,7 @@ detaillist:
${Q} -(echo "xxxxxxxxxxx"; \
for i in ${SCRIPT} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i.calc,v ]; then \
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
else \
echo $$i.calc; \
fi; \
echo $$i.calc; \
fi; \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxxxxxx/SCRIPT_SRC=/' -e '2,$$s/^/ /' \
@@ -312,7 +351,7 @@ depend:
if [ X"$$i" != X"/dev/null" ]; then \
echo "$$i: $$i.calc"; \
echo ' @$${RM} -f $$@'; \
echo -n ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
${ECHON} ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
echo 'calc/calc:#!$${BINDIR}/calc:" $$?>$$@'; \
echo ' @$${CHMOD} +x $$@'; \
fi; \
@@ -327,20 +366,13 @@ depend:
${Q} ${CAT} makedep.out >> ${MAKE_FILE}
${Q} ${RM} -f makedep.out
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'sample ${MAKE_FILE} was already up to date'; \
echo 'cscript/${MAKE_FILE} was already up to date'; \
echo 'restoring original cscript/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
${RM} -f ${MAKE_FILE}.tmp; \
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
${CO} -l ${MAKE_FILE}; \
fi; \
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
if [ -d RCS ]; then \
echo '******************************************************'; \
echo 'new cscript ${MAKE_FILE} formed -- need to check it in'; \
echo '******************************************************'; \
fi; \
echo 'old cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
echo 'new cscript/${MAKE_FILE} formed'; \
echo 'try: diff -u cscript/${MAKE_FILE}.bak cscript/${MAKE_FILE}'; \
fi
##

View File

@@ -47,6 +47,10 @@
#endif /* CUSTOM */
#include "banned.h" /* include after system header <> includes */
BOOL allow_custom = FALSE; /* TRUE => custom builtins allowed */

View File

@@ -27,6 +27,65 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
##############################################################################
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
@@ -96,14 +155,38 @@ CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
# Normally, the upper level makefile will set these values. We provide
# a default here just in case you want to build from this directory.
#
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
####
# Normally, the upper level makefile will set these values. We provide
@@ -348,7 +431,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.8.2
VERSION= 2.12.9.1
# Names of shared libraries with versions
#
@@ -357,26 +440,25 @@ LIB_EXT_VERSION= ${LIB_EXT}.${VERSION}
# standard tools
#
SHELL= /bin/sh
SED= sed
MAKEDEPEND= makedepend
GREP= egrep
CHMOD= chmod
FMT= fmt
SORT= sort
CMP= cmp
AR= ar
RM= rm
TOUCH= touch
MKDIR= mkdir
RMDIR= rmdir
MV= mv
CP= cp
CO= co
TRUE= true
MAKE= make
LN= ln
AWK= awk
CHMOD= chmod
CMP= cmp
CO= co
CP= cp
FMT= fmt
GREP= egrep
LN= ln
MAKE= make
MAKEDEPEND= makedepend
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
TOUCH= touch
TRUE= true
# EXTRA_CFLAGS are flags given to ${CC} when compiling C files
# EXTRA_LDFLAGS are flags given to ${CC} when linking progs
@@ -420,9 +502,9 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
@@ -466,12 +548,20 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
# CCOPT are flags given to ${CC} for optimization
# CCWARN are flags given to ${CC} for warning message control
#
# WNO_IMPLICT, WNO_ERROR_LONG_LONG and WNO_LONG_LONG are given to ${CC}
# when compiling special .o files that may need special compile options
# The following are given to ${CC}:
#
# WNO_IMPLICT
# WNO_ERROR_LONG_LONG
# WNO_LONG_LONG
#
# when compiling special .o files that may need special compile options:
#
# NOTE: These flags simply turn off certain compiler warnings,
# which is useful only when CCWERR is set to -Werror.
#
# NOTE: If your compiler does not have these -Wno files, just
# set these variables to nothing as in:
#
# WNO_IMPLICT=
# WNO_ERROR_LONG_LONG=
# WNO_LONG_LONG=
@@ -482,6 +572,9 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
# to abort on warnings, then leave CCWERR blank.
# CCMISC are misc flags given to ${CC}
#
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
# NOTE: See where CCBAN is defined above for details.
#
# LCC is how the C compiler is invoked on locally executed intermediate programs
# CC is how the C compiler is invoked (with an optional Purify)
#
@@ -904,7 +997,7 @@ CC= ${PURIFY} ${LCC} ${CCWERR}
# ILDFLAGS for ${CC} in linking intermediate programs used to help compile calc
# LDFLAGS for ${CC} in linking calc programs other than intermediate programs
#
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
CFLAGS= ${ICFLAGS} ${CCOPT}
#
ILDFLAGS= ${COMMON_LDFLAGS} ${LD_STATIC}
@@ -1031,9 +1124,9 @@ endif
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
@@ -1222,7 +1315,7 @@ Makefile.simple: ${MAKE_FILE}
depend:
${Q} if [ -f ${MAKE_FILE}.bak ]; then \
echo "${MAKE_FILE}.bak exists, remove or move it"; \
echo "custom/${MAKE_FILE}.bak exists, remove or move it"; \
exit 1; \
else \
${TRUE}; \
@@ -1238,9 +1331,7 @@ depend:
fi; \
done
-${Q} for i in ${H_SRC} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if [ "$$i" = "/dev/null" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/custom/$$i"; \
echo "#define $$tag" >> "skel/custom/$$i"; \
@@ -1249,25 +1340,25 @@ depend:
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q} (cd ..; ${MAKE} -f ${TOP_MAKE_FILE} hsrc)
${Q} for i in `cd ..; ${MAKE} -f ${TOP_MAKE_FILE} h_list 2>&1 | \
${SED} -e '/Entering directory/d' \
-e '/Nothing to be done/d' \
-e '/Leaving directory/d'` /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
>> "skel/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
done
${MAKE} -f ../${TOP_MAKE_FILE} h_list 2>/dev/null | \
while read i; do \
if [ ! -f "../$$i" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
>> "skel/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
done
${Q} ${RM} -f skel/custom/makedep.out
${Q} echo custom/skel formed
${Q} echo forming custom dependency list
${Q} :> skel/custom/makedep.out
${Q} cd skel/custom; ${MAKEDEPEND} -I.. -w 1 -f makedep.out ${C_SRC}
${Q} cd skel/custom; ${MAKEDEPEND} \
-I../../.. -w 1 -f makedep.out -- \
${CFLAGS} -- \
${C_SRC} 2>/dev/null
${Q} ${SED} -e 's|: ../../|: |' -E -i '' -l skel/custom/makedep.out
-${Q} for i in ${C_SRC} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo "$$i" | ${SED} 's/^\(.*\)\.c/\1.o: \1.c/'; \
@@ -1282,22 +1373,16 @@ depend:
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
${MAKE_FILE}.bak > ${MAKE_FILE}
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'custom ${MAKE_FILE} was already up to date'; \
echo 'custom/${MAKE_FILE} was already up to date'; \
echo 'restoring original custom/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
${RM} -f ${MAKE_FILE}.tmp; \
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
${CO} -l ${MAKE_FILE}; \
fi ;\
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
if [ -d RCS ]; then \
echo '****************************************************'; \
echo 'new custom ${MAKE_FILE} formed -- you to check it in'; \
echo '****************************************************'; \
fi; \
echo 'old custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'new custom/${MAKE_FILE} formed'; \
echo 'try: diff -u custom/${MAKE_FILE}.bak custom/${MAKE_FILE}'; \
fi
##
@@ -1344,6 +1429,7 @@ clobber: clean
${RM} -f libcustcalc${LIB_EXT}
${RM} -f libcustcalc.a
${RM} -f libcustcalc*
${RM} -rf skel
${V} echo remove files that are obsolete
#if 0 /* start of skip for non-Gnu makefiles */
${RM} -f Makefile.simple
@@ -1590,6 +1676,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
c_argv.o: ../calc.h
@@ -1600,6 +1687,7 @@ c_argv.o: ../custom.h
c_argv.o: ../decl.h
c_argv.o: ../endian_calc.h
c_argv.o: ../hash.h
c_argv.o: ../have_ban_pragma.h
c_argv.o: ../have_const.h
c_argv.o: ../have_memmv.h
c_argv.o: ../have_newstr.h
@@ -1615,6 +1703,7 @@ c_argv.o: ../value.h
c_argv.o: ../zmath.h
c_argv.o: c_argv.c
c_devnull.o: ../alloc.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
c_devnull.o: ../calcerr.h
@@ -1624,6 +1713,7 @@ c_devnull.o: ../custom.h
c_devnull.o: ../decl.h
c_devnull.o: ../endian_calc.h
c_devnull.o: ../hash.h
c_devnull.o: ../have_ban_pragma.h
c_devnull.o: ../have_const.h
c_devnull.o: ../have_memmv.h
c_devnull.o: ../have_newstr.h
@@ -1640,6 +1730,7 @@ c_devnull.o: ../value.h
c_devnull.o: ../zmath.h
c_devnull.o: c_devnull.c
c_help.o: ../alloc.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
c_help.o: ../calcerr.h
@@ -1649,6 +1740,7 @@ c_help.o: ../custom.h
c_help.o: ../decl.h
c_help.o: ../endian_calc.h
c_help.o: ../hash.h
c_help.o: ../have_ban_pragma.h
c_help.o: ../have_const.h
c_help.o: ../have_memmv.h
c_help.o: ../have_newstr.h
@@ -1665,6 +1757,7 @@ c_help.o: ../value.h
c_help.o: ../zmath.h
c_help.o: c_help.c
c_pmodm127.o: ../alloc.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
c_pmodm127.o: ../calcerr.h
@@ -1674,6 +1767,7 @@ c_pmodm127.o: ../custom.h
c_pmodm127.o: ../decl.h
c_pmodm127.o: ../endian_calc.h
c_pmodm127.o: ../hash.h
c_pmodm127.o: ../have_ban_pragma.h
c_pmodm127.o: ../have_const.h
c_pmodm127.o: ../have_memmv.h
c_pmodm127.o: ../have_newstr.h
@@ -1689,6 +1783,7 @@ c_pmodm127.o: ../value.h
c_pmodm127.o: ../zmath.h
c_pmodm127.o: c_pmodm127.c
c_pzasusb8.o: ../alloc.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
c_pzasusb8.o: ../calcerr.h
@@ -1698,6 +1793,7 @@ c_pzasusb8.o: ../custom.h
c_pzasusb8.o: ../decl.h
c_pzasusb8.o: ../endian_calc.h
c_pzasusb8.o: ../hash.h
c_pzasusb8.o: ../have_ban_pragma.h
c_pzasusb8.o: ../have_const.h
c_pzasusb8.o: ../have_memmv.h
c_pzasusb8.o: ../have_newstr.h
@@ -1713,6 +1809,7 @@ c_pzasusb8.o: ../value.h
c_pzasusb8.o: ../zmath.h
c_pzasusb8.o: c_pzasusb8.c
c_register.o: ../alloc.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
c_register.o: ../calc.h
@@ -1723,6 +1820,7 @@ c_register.o: ../custom.h
c_register.o: ../decl.h
c_register.o: ../endian_calc.h
c_register.o: ../hash.h
c_register.o: ../have_ban_pragma.h
c_register.o: ../have_const.h
c_register.o: ../have_memmv.h
c_register.o: ../have_newstr.h
@@ -1738,6 +1836,7 @@ c_register.o: ../value.h
c_register.o: ../zmath.h
c_register.o: c_register.c
c_sysinfo.o: ../alloc.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
c_sysinfo.o: ../calc.h
@@ -1750,6 +1849,7 @@ c_sysinfo.o: ../decl.h
c_sysinfo.o: ../endian_calc.h
c_sysinfo.o: ../fposval.h
c_sysinfo.o: ../hash.h
c_sysinfo.o: ../have_ban_pragma.h
c_sysinfo.o: ../have_const.h
c_sysinfo.o: ../have_memmv.h
c_sysinfo.o: ../have_newstr.h
@@ -1770,6 +1870,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
custtbl.o: ../calcerr.h
@@ -1779,6 +1880,7 @@ custtbl.o: ../custom.h
custtbl.o: ../decl.h
custtbl.o: ../endian_calc.h
custtbl.o: ../hash.h
custtbl.o: ../have_ban_pragma.h
custtbl.o: ../have_const.h
custtbl.o: ../have_memmv.h
custtbl.o: ../have_newstr.h

View File

@@ -27,6 +27,65 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
#
# The banned.h attempts to ban the use of certain dangerous functions
# that, if improperly used, could compromise the computational integrity
# if calculations.
#
# In the case of calc, we are motivated in part by the desire for calc
# to correctly calculate: even durings extremely long calculations.
#
# If UNBAN is NOT defined, then calling certain functions
# will result in a call to a non-existent function (link error).
#
# While we do NOT encourage defining UNBAN, there may be
# a system / compiler environment where re-defining a
# function may lead to a fatal compiler complication.
# If that happens, consider compiling as:
#
# make clobber all chk CCBAN=-DUNBAN
#
# as see if this is a work-a-round.
#
# If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
# Please send us a bug report. See the file:
#
# BUGS
#
# or the URL:
#
# http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
#
# for how to send us such a bug report.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
##############################################################################
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
@@ -96,14 +155,38 @@ CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
# Normally, the upper level makefile will set these values. We provide
# a default here just in case you want to build from this directory.
#
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
####
# Normally, the upper level makefile will set these values. We provide
@@ -348,7 +431,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.8.2
VERSION= 2.12.9.1
# Names of shared libraries with versions
#
@@ -357,26 +440,25 @@ LIB_EXT_VERSION= ${LIB_EXT}.${VERSION}
# standard tools
#
SHELL= /bin/sh
SED= sed
MAKEDEPEND= makedepend
GREP= egrep
CHMOD= chmod
FMT= fmt
SORT= sort
CMP= cmp
AR= ar
RM= rm
TOUCH= touch
MKDIR= mkdir
RMDIR= rmdir
MV= mv
CP= cp
CO= co
TRUE= true
MAKE= make
LN= ln
AWK= awk
CHMOD= chmod
CMP= cmp
CO= co
CP= cp
FMT= fmt
GREP= egrep
LN= ln
MAKE= make
MAKEDEPEND= makedepend
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
TOUCH= touch
TRUE= true
# EXTRA_CFLAGS are flags given to ${CC} when compiling C files
# EXTRA_LDFLAGS are flags given to ${CC} when linking progs
@@ -420,9 +502,9 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CC_STATIC}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CC_SHARE}
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}

View File

@@ -170,7 +170,7 @@ Makefile.simple: ${MAKE_FILE}
depend:
${Q} if [ -f ${MAKE_FILE}.bak ]; then \
echo "${MAKE_FILE}.bak exists, remove or move it"; \
echo "custom/${MAKE_FILE}.bak exists, remove or move it"; \
exit 1; \
else \
${TRUE}; \
@@ -186,9 +186,7 @@ depend:
fi; \
done
-${Q} for i in ${H_SRC} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if [ "$$i" = "/dev/null" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/custom/$$i"; \
echo "#define $$tag" >> "skel/custom/$$i"; \
@@ -197,25 +195,25 @@ depend:
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q} (cd ..; ${MAKE} -f ${TOP_MAKE_FILE} hsrc)
${Q} for i in `cd ..; ${MAKE} -f ${TOP_MAKE_FILE} h_list 2>&1 | \
${SED} -e '/Entering directory/d' \
-e '/Nothing to be done/d' \
-e '/Leaving directory/d'` /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
>> "skel/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
done
${MAKE} -f ../${TOP_MAKE_FILE} h_list 2>/dev/null | \
while read i; do \
if [ ! -f "../$$i" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
>> "skel/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
done
${Q} ${RM} -f skel/custom/makedep.out
${Q} echo custom/skel formed
${Q} echo forming custom dependency list
${Q} :> skel/custom/makedep.out
${Q} cd skel/custom; ${MAKEDEPEND} -I.. -w 1 -f makedep.out ${C_SRC}
${Q} cd skel/custom; ${MAKEDEPEND} \
-I../../.. -w 1 -f makedep.out -- \
${CFLAGS} -- \
${C_SRC} 2>/dev/null
${Q} ${SED} -e 's|: ../../|: |' -E -i '' -l skel/custom/makedep.out
-${Q} for i in ${C_SRC} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo "$$i" | ${SED} 's/^\(.*\)\.c/\1.o: \1.c/'; \
@@ -230,22 +228,16 @@ depend:
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
${MAKE_FILE}.bak > ${MAKE_FILE}
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'custom ${MAKE_FILE} was already up to date'; \
echo 'custom/${MAKE_FILE} was already up to date'; \
echo 'restoring original custom/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
${RM} -f ${MAKE_FILE}.tmp; \
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
${CO} -l ${MAKE_FILE}; \
fi ;\
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
if [ -d RCS ]; then \
echo '****************************************************'; \
echo 'new custom ${MAKE_FILE} formed -- you to check it in'; \
echo '****************************************************'; \
fi; \
echo 'old custom/${MAKE_FILE} is now custom/${MAKE_FILE}.bak'; \
echo 'new custom/${MAKE_FILE} formed'; \
echo 'try: diff -u custom/${MAKE_FILE}.bak custom/${MAKE_FILE}'; \
fi
##
@@ -292,6 +284,7 @@ clobber: clean
${RM} -f libcustcalc${LIB_EXT}
${RM} -f libcustcalc.a
${RM} -f libcustcalc*
${RM} -rf skel
${V} echo remove files that are obsolete
#if 0 /* start of skip for non-Gnu makefiles */
${RM} -f Makefile.simple
@@ -538,6 +531,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
c_argv.o: ../calc.h
@@ -548,6 +542,7 @@ c_argv.o: ../custom.h
c_argv.o: ../decl.h
c_argv.o: ../endian_calc.h
c_argv.o: ../hash.h
c_argv.o: ../have_ban_pragma.h
c_argv.o: ../have_const.h
c_argv.o: ../have_memmv.h
c_argv.o: ../have_newstr.h
@@ -563,6 +558,7 @@ c_argv.o: ../value.h
c_argv.o: ../zmath.h
c_argv.o: c_argv.c
c_devnull.o: ../alloc.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
c_devnull.o: ../calcerr.h
@@ -572,6 +568,7 @@ c_devnull.o: ../custom.h
c_devnull.o: ../decl.h
c_devnull.o: ../endian_calc.h
c_devnull.o: ../hash.h
c_devnull.o: ../have_ban_pragma.h
c_devnull.o: ../have_const.h
c_devnull.o: ../have_memmv.h
c_devnull.o: ../have_newstr.h
@@ -588,6 +585,7 @@ c_devnull.o: ../value.h
c_devnull.o: ../zmath.h
c_devnull.o: c_devnull.c
c_help.o: ../alloc.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
c_help.o: ../calcerr.h
@@ -597,6 +595,7 @@ c_help.o: ../custom.h
c_help.o: ../decl.h
c_help.o: ../endian_calc.h
c_help.o: ../hash.h
c_help.o: ../have_ban_pragma.h
c_help.o: ../have_const.h
c_help.o: ../have_memmv.h
c_help.o: ../have_newstr.h
@@ -613,6 +612,7 @@ c_help.o: ../value.h
c_help.o: ../zmath.h
c_help.o: c_help.c
c_pmodm127.o: ../alloc.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
c_pmodm127.o: ../calcerr.h
@@ -622,6 +622,7 @@ c_pmodm127.o: ../custom.h
c_pmodm127.o: ../decl.h
c_pmodm127.o: ../endian_calc.h
c_pmodm127.o: ../hash.h
c_pmodm127.o: ../have_ban_pragma.h
c_pmodm127.o: ../have_const.h
c_pmodm127.o: ../have_memmv.h
c_pmodm127.o: ../have_newstr.h
@@ -637,6 +638,7 @@ c_pmodm127.o: ../value.h
c_pmodm127.o: ../zmath.h
c_pmodm127.o: c_pmodm127.c
c_pzasusb8.o: ../alloc.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
c_pzasusb8.o: ../calcerr.h
@@ -646,6 +648,7 @@ c_pzasusb8.o: ../custom.h
c_pzasusb8.o: ../decl.h
c_pzasusb8.o: ../endian_calc.h
c_pzasusb8.o: ../hash.h
c_pzasusb8.o: ../have_ban_pragma.h
c_pzasusb8.o: ../have_const.h
c_pzasusb8.o: ../have_memmv.h
c_pzasusb8.o: ../have_newstr.h
@@ -661,6 +664,7 @@ c_pzasusb8.o: ../value.h
c_pzasusb8.o: ../zmath.h
c_pzasusb8.o: c_pzasusb8.c
c_register.o: ../alloc.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
c_register.o: ../calc.h
@@ -671,6 +675,7 @@ c_register.o: ../custom.h
c_register.o: ../decl.h
c_register.o: ../endian_calc.h
c_register.o: ../hash.h
c_register.o: ../have_ban_pragma.h
c_register.o: ../have_const.h
c_register.o: ../have_memmv.h
c_register.o: ../have_newstr.h
@@ -686,6 +691,7 @@ c_register.o: ../value.h
c_register.o: ../zmath.h
c_register.o: c_register.c
c_sysinfo.o: ../alloc.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
c_sysinfo.o: ../calc.h
@@ -698,6 +704,7 @@ c_sysinfo.o: ../decl.h
c_sysinfo.o: ../endian_calc.h
c_sysinfo.o: ../fposval.h
c_sysinfo.o: ../hash.h
c_sysinfo.o: ../have_ban_pragma.h
c_sysinfo.o: ../have_const.h
c_sysinfo.o: ../have_memmv.h
c_sysinfo.o: ../have_newstr.h
@@ -718,6 +725,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
custtbl.o: ../calcerr.h
@@ -727,6 +735,7 @@ custtbl.o: ../custom.h
custtbl.o: ../decl.h
custtbl.o: ../endian_calc.h
custtbl.o: ../hash.h
custtbl.o: ../have_ban_pragma.h
custtbl.o: ../have_const.h
custtbl.o: ../have_memmv.h
custtbl.o: ../have_newstr.h

View File

@@ -1,7 +1,7 @@
/*
* c_argv - a custom function display info about its args
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,6 +38,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_argv - a custom function display info about its args
*
@@ -49,7 +53,7 @@
*/
/*ARGSUSED*/
VALUE
c_argv(char UNUSED *name, int count, VALUE **vals)
c_argv(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE zfilelen; /* length of a file as a ZVALUE */

View File

@@ -1,7 +1,7 @@
/*
* c_devnull - a custom function that does nothing
*
* Copyright (C) 1999-2004 Landon Curt Noll
* Copyright (C) 1999-2004,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_devnull - a custom function that does nothing
*
@@ -47,7 +50,7 @@
*/
/*ARGSUSED*/
VALUE
c_devnull(char UNUSED *name, int UNUSED count, VALUE UNUSED **vals)
c_devnull(char *UNUSED(name), int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE result; /* what we will return */

View File

@@ -1,7 +1,7 @@
/*
* c_help - custom help function
*
* Copyright (C) 1999-2004 Landon Curt Noll
* Copyright (C) 1999-2004,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_help - custom help function
*
@@ -58,7 +61,7 @@
*/
/*ARGSUSED*/
VALUE
c_help(char UNUSED *name, int UNUSED count, VALUE **vals)
c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */

View File

@@ -35,6 +35,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/* 2^255 */
STATIC HALF h255[] = {
#if BASEB == 32
@@ -71,7 +75,7 @@ STATIC ZVALUE lastmodinv[1];
*/
/*ARGSUSED*/
VALUE
c_pmodm127(char UNUSED *name, int UNUSED count, VALUE **vals)
c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE q; /* test factor */

View File

@@ -35,6 +35,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* c_pzasusb8 - print numerator as a string of USB8s
*
@@ -47,7 +51,7 @@
*/
/*ARGSUSED*/
VALUE
c_pzasusb8(char UNUSED *name, int UNUSED count, VALUE **vals)
c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
{
VALUE result; /* what we will return */
ZVALUE z; /* numerator of the value */

View File

@@ -1,7 +1,7 @@
/*
* c_register - set or print a custom register value
*
* Copyright (C) 2007 Landon Curt Noll
* Copyright (C) 2007,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -39,6 +39,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* registers
*/
@@ -76,7 +79,7 @@ init_custreg(void)
*/
/*ARGSUSED*/
VALUE
c_register(char UNUSED *name, int count, VALUE **vals)
c_register(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
long reg; /* register number */

View File

@@ -57,6 +57,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
/*
* sys_info - names and values of selected #defines
*/
@@ -266,7 +269,7 @@ S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
*/
/*ARGSUSED*/
VALUE
c_sysinfo(char UNUSED *name, int count, VALUE **vals)
c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
{
VALUE result; /* what we will return */
struct infoname *p; /* current infoname */

View File

@@ -30,6 +30,10 @@
#include "value.h"
#include "custom.h"
#include "banned.h" /* include after system header <> includes */
/*
* NOTE: See the file CUSTOM for instructions on how to add
* custom functions.

2
decl.h
View File

@@ -1,7 +1,7 @@
/*
* decl - variable and function declaration macros
*
* Copyright (C) 2007,2014 Landon Curt Noll
* Copyright (C) 2007,2014,2021 Landon Curt Noll
*
* Primary author: Landon Curt Noll
*

View File

@@ -42,6 +42,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
/* byte order array */
char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
(char)0x01, (char)0x23, (char)0x45, (char)0x67 };

50
file.c
View File

@@ -37,17 +37,23 @@
#endif /* HAVE_UNISTD_H */
#include <ctype.h>
#include "calc.h"
#include "alloc.h"
#include "longbits.h"
#include "have_fpos.h"
#include "have_fpos_pos.h"
#include "fposval.h"
#include "file.h"
#include "calcerr.h"
#include "strl.h"
#if defined(_WIN32)
# include <io.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define READSIZE 1024 /* buffer size for reading */
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
@@ -141,6 +147,7 @@ file_init(void)
files[idnum].reading = TRUE;
files[idnum].writing = TRUE;
files[idnum].action = 0;
memset(files[idnum].mode, 0, MODE_LEN+1);
/*
* stat the descriptor to see what we have
*/
@@ -148,16 +155,19 @@ file_init(void)
size_t snprintf_len; /* malloced snprintf length */
fp = (FILE *) fdopen(i,"r+"); /*guess mode*/
if (fp) {
strcpy(files[idnum].mode, "r+");
strlcpy(files[idnum].mode, "r+",
sizeof(files[idnum].mode));
} else {
fp = (FILE *) fdopen(i, "r");
if (fp) {
strcpy(files[idnum].mode, "r");
strlcpy(files[idnum].mode, "r",
sizeof(files[idnum].mode));
files[idnum].writing = FALSE;
} else {
fp = (FILE *) fdopen(i, "w");
if (fp) {
strcpy(files[idnum].mode, "w");
strlcpy(files[idnum].mode, "w",
sizeof(files[idnum].mode));
files[idnum].reading = FALSE;
}
else
@@ -208,10 +218,14 @@ S_FUNC void
init_fileio(FILEIO *fiop, char *name, char *mode,
struct stat *sbufp, FILEID id, FILE *fp)
{
char modestr[sizeof(fiop->mode)]; /* mode [rwa]b?\+? */
size_t namelen; /* length of name */
char modestr[MODE_LEN+1]; /* mode [rwa]b?\+? */
size_t namelen; /* length of name */
/* clear modestr */
memset(modestr, 0, sizeof(modestr));
/* allocate filename if requested */
namelen = 0;
if (name != NULL) {
namelen = strlen(name);
fiop->name = (char *)malloc(namelen + 1);
@@ -223,7 +237,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
/* initialize FILEIO structure */
if (name != NULL) {
strncpy(fiop->name, name, namelen+1);
strlcpy(fiop->name, name, namelen+1);
}
fiop->id = id;
fiop->fp = fp;
@@ -234,7 +248,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
fiop->appending = FALSE;
fiop->binary = FALSE;
fiop->action = 0;
fiop->mode[0] = '\0';
memset(fiop->mode, 0, sizeof(fiop->mode));
/*
* determine file open mode
@@ -248,65 +262,65 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
if (mode[0] == 'r') {
/* note read mode */
strcpy(modestr, "r");
strlcpy(modestr, "r", sizeof(modestr));
fiop->reading = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->writing = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize write modes */
} else if (mode[0] == 'w') {
/* note write mode */
strcpy(modestr, "w");
strlcpy(modestr, "w", sizeof(modestr));
fiop->writing = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->reading = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize append modes */
} else if (mode[0] == 'a') {
/* note append mode */
strcpy(modestr, "a");
strlcpy(modestr, "a", sizeof(modestr));
fiop->writing = TRUE;
fiop->appending = TRUE;
/* note binary mode even though mode is not used / ignored */
if (strchr(mode, 'b') != NULL) {
strcat(modestr, "b");
strlcat(modestr, "b", sizeof(modestr));
}
/* note if reading and writing */
if (strchr(mode, '+') != NULL) {
fiop->reading = TRUE;
strcat(modestr, "+");
strlcat(modestr, "+", sizeof(modestr));
}
/* canonicalize no I/O modes */
} else {
modestr[0] = '\0';
}
modestr[sizeof(modestr)-1] = '\0'; /* firewall */
modestr[MODE_LEN] = '\0'; /* firewall */
/* record canonical open mode string */
strncpy(fiop->mode, modestr, sizeof(fiop->mode));
strlcpy(fiop->mode, modestr, sizeof(fiop->mode));
}

3
file.h
View File

@@ -41,6 +41,7 @@
/*
* Definition of opened files.
*/
#define MODE_LEN (sizeof("rb+")-1)
typedef struct {
FILEID id; /* id to identify this file */
FILE *fp; /* real file structure for I/O */
@@ -52,7 +53,7 @@ typedef struct {
BOOL appending; /* TRUE if also opened for appending */
BOOL binary; /* TRUE if binary mode - mode ignored/unused */
char action; /* most recent use for 'r', 'w' or 0 */
char mode[sizeof("rb+")+1];/* open mode */
char mode[MODE_LEN+1]; /* open mode */
} FILEIO;

View File

@@ -64,6 +64,11 @@
#include "have_offscl.h"
#include "have_posscl.h"
#include "have_fpos_pos.h"
#include "alloc.h"
#include "banned.h" /* include after system header <> includes */
char *program; /* our name */

54
fposval.h.def Normal file
View File

@@ -0,0 +1,54 @@
/*
* fposval.h.def - fposval.h default macros
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/10 22;14:26
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* WARNING: For some reason fposval failed to generate values
* so we choose these values that are hopefully OK
*/
/* what are our file position & size types? */
#undef FILEPOS_BITS
#define FILEPOS_BITS 64
#undef FILEPOS_LEN
#define FILEPOS_LEN 8
#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src))
#undef OFF_T_BITS
#define OFF_T_BITS 64
#undef OFF_T_LEN
#define OFF_T_LEN 8
#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src))
#undef DEV_BITS
#define DEV_BITS 32
#undef DEV_LEN
#define DEV_LEN 4
#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4)
#undef INODE_BITS
#define INODE_BITS 64
#undef INODE_LEN
#define INODE_LEN 8
#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 8)

59
func.c
View File

@@ -105,6 +105,7 @@
#include "zrand.h"
#include "zrandom.h"
#include "custom.h"
#include "strl.h"
#if defined(CUSTOM)
# define E_CUSTOM_ERROR E_NO_C_ARG
@@ -113,6 +114,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/
@@ -269,22 +273,7 @@ f_prompt(VALUE *vp)
math_error("Cannot allocate string");
/*NOTREACHED*/
}
/*
* The next statement could be::
*
* strncpy(newcp, cp, len);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(newcp, cp, len);
newcp[len] = '\0';
strlcpy(newcp, cp, len+1);
result.v_str = makestring(newcp);
return result;
}
@@ -317,7 +306,7 @@ f_display(int count, VALUE **vals)
/*ARGSUSED*/
S_FUNC VALUE
f_null(int UNUSED count, VALUE UNUSED **vals)
f_null(int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE res;
@@ -5341,7 +5330,7 @@ f_list(int count, VALUE **vals)
/*ARGSUSED*/
S_FUNC VALUE
f_assoc(int UNUSED count, VALUE UNUSED **vals)
f_assoc(int UNUSED(count), VALUE **UNUSED(vals))
{
VALUE result;
@@ -7466,22 +7455,7 @@ f_cmdbuf(void)
math_error("Cannot allocate string in cmdbuf");
/*NOTREACHED*/
}
/*
* The next statement could be::
*
* strncpy(newcp, cmdbuf, cmdbuf_len);
*
* however compilers like gcc would issue warnings such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(newcp, cmdbuf, cmdbuf_len);
newcp[cmdbuf_len] = '\0';
strlcpy(newcp, cmdbuf, cmdbuf_len+1);
result.v_str = makestring(newcp);
return result;
}
@@ -7666,7 +7640,7 @@ f_putenv(int count, VALUE **vals)
/*NOTREACHED*/
}
/*
* The next statement could be::
* The next statement could be:
*
* snprintf(putenv_str, snprintf_len,
* "%s=%s", vals[0]->v_str->s_str,
@@ -7677,16 +7651,16 @@ f_putenv(int count, VALUE **vals)
* null destination pointer
*
* even though we check that putenv_str is non-NULL
* above before using it. Therefore we call memcpy()
* above before using it. Therefore we call strlcpy()
* twice and make an assignment instead to avoid such warnings.
*/
memcpy(putenv_str,
strlcpy(putenv_str,
vals[0]->v_str->s_str,
vals[0]->v_str->s_len);
vals[0]->v_str->s_len+1);
putenv_str[vals[0]->v_str->s_len] = '=';
memcpy(putenv_str + vals[0]->v_str->s_len + 1,
strlcpy(putenv_str + vals[0]->v_str->s_len + 1,
vals[1]->v_str->s_str,
vals[1]->v_str->s_len);
vals[1]->v_str->s_len+1);
putenv_str[snprintf_len] = '\0';
} else {
@@ -7711,9 +7685,8 @@ f_putenv(int count, VALUE **vals)
math_error("Cannot allocate string in putenv");
/*NOTREACHED*/
}
memcpy(putenv_str, vals[0]->v_str->s_str,
vals[0]->v_str->s_len);
putenv_str[vals[0]->v_str->s_len] = '\0';
strlcpy(putenv_str, vals[0]->v_str->s_str,
vals[0]->v_str->s_len+1);
}
/* return putenv result */

9
hash.c
View File

@@ -26,16 +26,23 @@
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include "calc.h"
#include "alloc.h"
#include "value.h"
#include "zrand.h"
#include "zrandom.h"
#include "hash.h"
#include "banned.h" /* include after system header <> includes */
/*
* external hash_setup functions
*/

71
have_ban_pragma.c Normal file
View File

@@ -0,0 +1,71 @@
/*
* have_ban_pragma.c - Determine if we have #pragma GCC poison func_name
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/08 01:02:34
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_ban_pragma
*
* Not all systems have #pragma GCC poison func_name, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_PRAGMA_GCC_POSION
* defined ==> use #pragma GCC poison func_name
* undefined ==> do not use #pragma GCC poison func_name
*
* NOTE: Modern clang compilers allow for 'pragma GCC poison func_name'.
* This is NOT simply a GCC feature.
*/
#include <stdio.h>
/* undef UNBAN to be undefined to force use of banned.h */
#undef UNBAN
/* prevent banned.h from including have_ban_pragma.h */
#define PRE_HAVE_BAN_PRAGMA_H
#include "banned.h" /* include after system header <> includes */
int
main(void)
{
#if defined(HAVE_NO_PRAGMA_GCC_POSION)
printf("#undef HAVE_PRAGMA_GCC_POSION /* no */\n");
#else /* HAVE_NO_PRAGMA_GCC_POSION */
printf("#define HAVE_PRAGMA_GCC_POSION /* yes */\n");
#endif /* HAVE_NO_PRAGMA_GCC_POSION */
/* exit(0); */
return 0;
}

View File

@@ -41,9 +41,12 @@
* (nothing) ==> const not used
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_fpos - Determine if have fgetpos and fsetpos 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -31,9 +31,12 @@
* appropriate have_fpos.h file body.
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_fpos_pos - Determine if a __pos element in FILEPOS
*
* Copyright (C) 2000 Landon Curt Noll
* Copyright (C) 2000,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -31,11 +31,14 @@
* __pos element in a non-scalar FILEPOS.
*/
#include <stdio.h>
#include "have_fpos.h"
#include "have_posscl.h"
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,12 +38,17 @@
* undefined ==> do not or cannot call getpgid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,13 +38,17 @@
* undefined ==> do not or cannot call getprid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,13 +38,17 @@
* undefined ==> do not call or cannot call getsid()
*/
#include <stdio.h>
#include <sys/types.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_gettime - determine if we have clock_gettime()
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -40,9 +40,13 @@
* CLOCK_SGI_CYCLE and CLOCK_REALTIME
*/
#include <stdio.h>
#include <time.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -38,9 +38,15 @@
* undefined ==> use internal slow memmove() instead
*/
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define MOVELEN 3

View File

@@ -40,9 +40,15 @@
* use index() instead of strchr()
*/
#include <stdio.h>
#include <string.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define MOVELEN 3

View File

@@ -42,7 +42,6 @@
* undefined ==> convert to ZVALUE first
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -51,6 +50,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -41,7 +41,6 @@
* undefined ==> convert to ZVALUE first
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -51,6 +50,10 @@
#endif
#include "have_fpos.h"
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_rusage - Determine if we have getrusage()
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,10 +38,14 @@
* undefined ==> do not call or cannot call getrusage()
*/
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_stdvs - try <stdarg.h> to see if it really works with vsnprintf()
*
* Copyright (C) 1999,2014,2018 Landon Curt Noll
* Copyright (C) 1999,2014,2018,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,7 +38,6 @@
* include file.
*/
#include <stdio.h>
#include "have_unistd.h"
@@ -65,6 +64,10 @@
# define VSNPRINTF_SIZE_T long
#endif
#include "banned.h" /* include after system header <> includes */
char buf[BUFSIZ+1];

View File

@@ -1,7 +1,7 @@
/*
* have_strdup - determine if we have strdup()
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,8 +38,15 @@
* undefined ==> do not call or cannot call strdup()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#include <string.h>
int
main(void)

76
have_strlcat.c Normal file
View File

@@ -0,0 +1,76 @@
/*
* have_strlcat - determine if we have strlcat()
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/08 20:34:13
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_strlcat
*
* Not all systems have the strlcat() function, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_STRLCAT
* defined ==> use strlcat()
* undefined ==> do not or cannot call strlcat()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define BUF_SIZ 5
char src[BUF_SIZ+1] = "abcde";
int
main(void)
{
#if defined(HAVE_NO_STRLCAT)
printf("#undef HAVE_STRLCAT /* no */\n");
#else /* HAVE_NO_STRLCAT */
char dst[BUF_SIZ+1+1];
dst[0] = 'S';
dst[1] = '\0';
(void) strlcat(dst, src, sizeof(dst));
printf("#define HAVE_STRLCAT /* yes */\n");
#endif /* HAVE_NO_STRLCAT */
/* exit(0); */
return 0;
}

74
have_strlcpy.c Normal file
View File

@@ -0,0 +1,74 @@
/*
* have_strlcpy - determine if we have strlcpy()
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/08 20:34:13
* File existed as early as: 2021
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* have_strlcpy
*
* Not all systems have the strlcpy() function, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_STRLCPY
* defined ==> use strlcpy()
* undefined ==> do not or cannot call strlcpy()
*/
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
#define BUF_SIZ (sizeof("abcde")-1)
char src[BUF_SIZ+1] = "abcde";
int
main(void)
{
#if defined(HAVE_NO_STRLCPY)
printf("#undef HAVE_STRLCPY /* no */\n");
#else /* HAVE_NO_STRLCPY */
char dst[BUF_SIZ+1];
(void) strlcpy(dst, src, sizeof(dst));
printf("#define HAVE_STRLCPY /* yes */\n");
#endif /* HAVE_NO_STRLCPY */
/* exit(0); */
return 0;
}

View File

@@ -1,7 +1,7 @@
/*
* have_uid_t - Determine if we want or can support uid_t
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -37,7 +37,6 @@
* undefined ==> do not use uid_t
*/
#include <stdio.h>
#if !defined(HAVE_NO_UID_T)
@@ -49,6 +48,10 @@
#include <sys/types.h>
#endif /* ! HAVE_NO_UID_T */
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_unused - Determine if we want or can support the unused attribute
*
* Copyright (C) 2004 Landon Curt Noll
* Copyright (C) 2004,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -42,22 +42,25 @@
* (nothing) ==> unused not used
*/
#include <stdio.h>
#include "banned.h" /* include after system header <> includes */
#if !defined(HAVE_NO_UNUSED)
/* make sure that we can use the __attribute__((unused)) in #define's */
/* make sure that we can use the __attribute__((x)) in #define's */
#undef UNUSED
#define UNUSED __attribute__((unused))
#define UNUSED(x) UNUSED_ ## x __attribute__((unused))
/*
* unused_str - a function with an unused argument
*/
static char *
unused_str(char UNUSED *str)
unused_str(char *UNUSED(str))
{
return "__attribute__((unused))";
return "UNUSED_ ## x __attribute__((unused))";
}
#endif /* !HAVE_NO_UNUSED */
@@ -68,15 +71,17 @@ main(void)
{
#if defined(HAVE_NO_UNUSED)
printf("#undef HAVE_UNUSED /* no */\n");
printf("#undef UNUSED\n");
printf("#define UNUSED /* no */\n");
printf("#if defined(__LCLINT__)\n");
printf("# define UNUSED(x) /*@unused@*/ x\n");
printf("#else\n");
printf("# define UNUSED(x) x\n");
printf("#endif\n");
#else /* HAVE_NO_UNUSED */
printf("#define HAVE_UNUSED /* yes */\n");
printf("#undef UNUSED\n");
printf("#define UNUSED %s /* yes */\n", unused_str(NULL));
printf("#define UNUSED(x) %s\n", unused_str(NULL));
#endif /* HAVE_NO_UNUSED */

View File

@@ -1,7 +1,7 @@
/*
* have_ustat - Determine if we have ustat()
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,11 +38,15 @@
* undefined ==> do not call or cannot call ustat()
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ustat.h>
#include "banned.h" /* include after system header <> includes */
int
main(void)
{

View File

@@ -1,7 +1,7 @@
/*
* have_varvs - try <varargs.h> to see if it really works with vsnprintf()
*
* Copyright (C) 1999,2018 Landon Curt Noll
* Copyright (C) 1999,2018,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -35,7 +35,6 @@
* include file.
*/
#include <stdio.h>
#include "have_unistd.h"
@@ -56,10 +55,17 @@
# define VSNPRINTF_SIZE_T long
#endif
#if !defined(STDARG) && !defined(SIMULATE_STDARG)
#include <varargs.h>
#endif
#include "banned.h" /* include after system header <> includes */
char buf[BUFSIZ+1];
#if !defined(STDARG) && !defined(SIMULATE_STDARG)
#include <varargs.h>
void
try_nthis(char *fmt, VSNPRINTF_SIZE_T size, ...)

3
help.c
View File

@@ -45,6 +45,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* some help topics are symbols, so we alias them to nice filenames
*/

View File

@@ -27,9 +27,28 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavor.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point wehre is cannot be depended on.
# On such systems, the zsh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/zsh
#
SHELL= /bin/sh
#SHELL= /bin/bash
#SHELL= /bin/zsh
####
# Normally, the upper level makefile will set these values. We provide
@@ -157,31 +176,55 @@ T=
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
# standard tools
#
LCC= cc
ICFLAGS=
ILDFLAGS=
GREP= egrep
CAT= cat
CHMOD= chmod
SED= sed
SORT= sort
FMT= fmt
CMP= cmp
CP= cp
MV= mv
TRUE= true
RM= rm
FMT= fmt
GREP= egrep
ICFLAGS=
ILDFLAGS=
LCC= cc
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
TOUCH= touch
CAT= cat
TRUE= true
# Some out of date operating systems require / want an executable to
# end with a certain file extension. Some compile systems such as
@@ -233,7 +276,7 @@ BLT_HELP_FILES_13= bugs changes
STD_HELP_FILES_14= credit
BLT_HELP_FILES_14= contrib COPYING COPYING-LGPL question
BLT_HELP_FILES_14= contrib COPYING COPYING-LGPL questions
STD_HELP_FILES_15= wishlist todo
@@ -277,8 +320,7 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
#
# make detail_help_list
#
# to keep this list in nice sorted order and to check that these
# non-special help files are under RCS control.
# to keep this list in nice sorted order.
#
DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
append appr arg argv arrow asec asech asin asinh assign atan atan2 \
@@ -301,14 +343,15 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
matsum mattrace mattrans max memsize meq min minv mmin mne mod modify \
name near newerror nextcand nextprime norm null num oldvalue ord param \
perm pfact pi pix places pmod polar poly pop popcnt pound power \
prevcand prevprime printf prompt protect ptest push putenv quo quomod \
rand randbit random randombit randperm rcin rcmul rcout rcpow rcsq re \
remove reverse rewind rm root round rsearch runtime saveval scale scan \
scanf search sec sech seed segment select sgn sha1 sin sinh size \
sizeof sleep sort sqrt srand srandom ssq stoponerror str strcasecmp \
strcat strcmp strcpy strerror strlen strncasecmp strncmp strncpy \
strpos strprintf strscan strscanf strtolower strtoupper substr sum \
swap system systime tail tan tanh test time trunc usertime version xor
prevcand prevprime printf prompt protect ptest push putenv questions \
quo quomod rand randbit random randombit randperm rcin rcmul rcout \
rcpow rcsq re remove reverse rewind rm root round rsearch runtime \
saveval scale scan scanf search sec sech seed segment select sgn sha1 \
sin sinh size sizeof sleep sort sqrt srand srandom ssq stoponerror str \
strcasecmp strcat strcmp strcpy strerror strlen strncasecmp strncmp \
strncpy strpos strprintf strscan strscanf strtolower strtoupper substr \
sum swap system systime tail tan tanh test time trunc usertime version \
xor
# This list is of files that are clones of DETAIL_HELP files. They are
# built from DETAIL_HELP files.
@@ -517,7 +560,7 @@ COPYING-LGPL: ../COPYING-LGPL
${TRUE}; \
fi
question: ../QUESTIONS
questions: ../QUESTIONS
${RM} -f $@
${CP} ../QUESTIONS $@
${CHMOD} 0444 $@
@@ -618,8 +661,8 @@ builtin: builtin.top builtin.end ../func.c funclist.sed
${Q} ${SED} -n -f funclist.sed ../func.c > funclist.c
${Q} ${RM} -f funclist.o funclist${EXT}
${Q} ${LCC} ${ICFLAGS} -DFUNCLIST -I/usr/include \
-I.. funclist.c -c 2>/dev/null
${Q} ${LCC} ${ILDFLAGS} funclist.o -o funclist${EXT}
-I.. funclist.c -c ${S}
${Q} ${LCC} ${ILDFLAGS} funclist.o -o funclist${EXT} ${S}
${Q} ${RM} -f builtin
${Q} ${GREP} -v '^#' builtin.top > builtin
${Q} ./funclist${EXT} | \
@@ -686,15 +729,11 @@ detail_help_list:
! -name mat ! -name obj.file ! -name operator \
! -name overview ! -name script ! -name statement \
! -name todo ! -name types ! -name unexpected \
! -name variable ! -name wishlist ! -name question \
! -name variable ! -name wishlist ! -name questions \
-print | \
while read i; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i,v ]; then \
echo "WARNING: $$i not under RCS control" 1>&2; \
else \
echo $$i; \
fi; \
echo $$i; \
fi; \
done; \
echo '--first_line--') | \
@@ -725,7 +764,7 @@ echo_inst_files:
clean:
${RM} -f obj mkbuiltin funclist.c funclist.o funclist${EXT}
${RM} -f COPYING COPYING-LGPL question
${RM} -f COPYING COPYING-LGPL questions
clobber: clean
${RM} -f ${BLT_HELP_FILES} full .all calc

View File

@@ -106,6 +106,66 @@ DESCRIPTION
affected by the configuration parameters "outround", "tilde",
"fullzero", "leadzero".
IMPORTANT NOTES:
In calc, %d formats in base 10 according to the current
config("mode"). Therefore this will print the entire
"1.2345" value:
; printf("%d\n", 1.2345);
1.2345
assuming printing of 4 or more digits is allowed by the current
value of display().
See also:
; help printf
; help display
; help mode
In calc, %x formats in base 16. A non-integer numeric values such
as 1/3 is represented as a fraction. When fractions are printed
in %x format, both the numerator and denominator are printed
as is mode("fraction"):
; printf("%x\n", 1.2345);
0x9a5/0x7d0
See also:
; help printf
; help display
; help mode
Because calc is capable of of printing very large values, some
people may be surprised when this does not print the entire
value of M(23209):
fprintf(fd, "%d\n", 2^23209-1);
/* the entire value may not be printed yet */
Because I/O is usually buffered to files, the above fprintf()
may print only the initial 4096 characters. One needs to also
flush (or close the stream) to be sure that the entire
value as been printed to the file:
; fflush(fd);
A similar problem an arise when printing many digits after
the decimal point:
; display(10000),;
; fprintf(fd, "%d\n", pi(1e-10000));
; fflush(fd);
The buffer will also be flushed during a call to fclose():
; fclose(fd);
EXAMPLE
; config("epsilon", 1e-6),;
: config("display", 6),;
@@ -117,6 +177,18 @@ EXAMPLE
; printf(fmt,a,a,a,a,a,a);
1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
; fd = fopen("/tmp/test.txt", "w+");
; fprintf(fd, "%d\n", 2^23209-1);
; /* one must flush to be buffered output is written */
; fflush(fd);
; display(10000),;
; fprintf(fd, "%d\n", pi(1e-10000));
; /* closing the file will also flush the buffer */
; fclose(fd);
; printf("%x\n", 1.2345);
0x9a5/0x7d0
; config("display", 5),;
: config("tilde", 0),;
; printf("%f\n", pi());
@@ -229,7 +301,7 @@ LINK LIBRARY
none
SEE ALSO
config, display, epsilon, fprintf, strprintf
config, display, epsilon, fclose, fflush, fopen, fprintf, strprintf
## Copyright (C) 1999-2006,2018,2021 Landon Curt Noll
##

View File

@@ -404,6 +404,131 @@ Unexpected
64
display() will limit the number of digits printed after decimal point
=====================================================================
While calc is able to print many digits after the decimal point,
the value of display() may limit the number of digits printed.
For example, while the following will calculate e to 50 digits:
; e = exp(1,1e-50);
the value of display() (defaults to 20) will limit the number of
digits printed after the decimal point:
; e
~2.71828182845904523536
To print many digits after the decimal point, one needs to change
the value of display():
; display(100),;
; e
2.71828182845904523536028747135266249775724709369996
Printing a leading ~ (unless disabled by config("tilde", 0)) is
your indication that the computed value has been rounded
(rounding mode controlled by config("outround", bitflag)):
For example, if display(49) is used for that value if e,
the output will be rounded:
; display(49);
50
; e
~2.7182818284590452353602874713526624977572470937000
See also:
; help display
; help config
; help epsilon
%d will format after the decimal point for non-integer numeric values
=====================================================================
In calc, %d formats in base 10 according to the current
config("mode"). Therefore this will print the entire
"1.2345" value:
; printf("%d\n", 1.2345);
1.2345
assuming printing of 4 or more digits is allowed by the current
value of display().
See also:
; help printf
; help display
; help mode
%x will format as fractions for non-integer numeric values
==========================================================
In calc, %x formats in base 16. A non-integer numeric values such
as 1/3 is represented as a fraction. When fractions are printed
in %x format, both the numerator and denominator are printed
as is mode("fraction"):
; printf("%x\n", 1.2345);
0x9a5/0x7d0
See also:
; help printf
; help display
; help mode
fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish
=============================================================
When printing a small value such as:
; fd = fopen("/tmp/test.txt", "w+");
; i = 20;
; fprintf(fd, "%d\n", i);
The resulting string will almost always be printed in full.
Because calc is capable of of printing very large values, some
people may be surprised when this does not print the entire
value of M(23209):
fprintf(fd, "%d\n", 2^23209-1);
/* the entire value may not be printed yet */
Because I/O is usually buffered to files, the above fprintf()
may print only the initial 4096 characters. One needs to also
flush (or close the stream) to be sure that the entire
value as been printed to the file:
; fflush(fd);
A similar problem an arise when printing many digits after
the decimal point:
; display(10000),;
; fprintf(fd, "%d\n", pi(1e-10000));
; fflush(fd);
The buffer will also be flushed during a call to fclose():
; fclose(fd);
See also:
; help fprintf
; help fflush
; help fopen
; help fclose
## Copyright (C) 1999-2007,2014,2017,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under

14
hist.c
View File

@@ -52,20 +52,26 @@
#include "calc.h"
#include "lib_calc.h"
#include "alloc.h"
#include "hist.h"
#include "have_string.h"
#include "strl.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#if !defined(USE_READLINE)
E_FUNC FILE *curstream(void);
@@ -1490,7 +1496,7 @@ hist_getline(char *prompt, char *buf, size_t len)
/*NOTREACHED*/
}
}
strncpy(buf, line, len - 1);
strlcpy(buf, line, len);
buf[len - 2] = '\0';
len = strlen(buf);
buf[len] = '\n';
@@ -1518,7 +1524,7 @@ my_stifle_history (void)
int
hist_init(char UNUSED *filename)
hist_init(char *UNUSED(filename))
{
/* used when parsing conditionals in ~/.inputrc */
rl_readline_name = "calc";
@@ -1570,7 +1576,7 @@ hist_saveline(char *line, int len)
/*
* Main routine to test history.
*/
void
int
main(int argc, char **argv)
{
char *filename;

54
input.c
View File

@@ -1,7 +1,7 @@
/*
* input - nested input source file reader
*
* Copyright (C) 1999-2007,2014,2018 David I. Bell
* Copyright (C) 1999-2007,2014,2018,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -53,6 +53,11 @@
#include "calc.h"
#include "conf.h"
#include "hist.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
EXTERN int stdin_tty; /* TRUE if stdin is a tty */
E_FUNC FILE *f_open(char *name, char *mode);
@@ -135,6 +140,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
int i;
char *cp;
char *path; /* name being searched for */
size_t path_alloc; /* length of malloced path */
struct stat statbuf; /* stat of the path */
size_t namelen; /* length of name */
size_t extlen; /* length of the extension if non-NULL or 0 */
@@ -181,11 +187,14 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
extlen = 0;
}
pathlen = strlen(pathlist);
path = malloc(pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1);
path_alloc = pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1;
path = malloc(path_alloc+1);
if (path == NULL) {
math_error("Cannot allocate filename path buffer");
/*NOTREACHED*/
}
path[0] = '\0'; /* paranoia */
path[path_alloc] = '\0'; /* paranoia */
/*
* Don't try the extension if the filename already contains it.
@@ -206,11 +215,11 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
*cp++ = *pathlist++;
if (cp != path)
*cp++ = PATHCHAR;
strncpy(cp, name, namelen+1);
strlcpy(cp, name, namelen+1);
i = openfile(path);
if ((i < 0) &&
(extension != NULL && extension[0] != '\0')) {
strcat(path, extension);
strlcat(path, extension, path_alloc+1);
i = openfile(path);
}
} while ((i < 0) && *pathlist);
@@ -348,7 +357,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
*cp++ = *pathlist++;
if (cp != path)
*cp++ = PATHCHAR;
strncpy(cp, name, namelen+1);
strlcpy(cp, name, namelen+1);
ret = f_open(path, mode);
} while ((ret == NULL) && *pathlist);
@@ -442,23 +451,7 @@ homeexpand(char *name)
if (fullpath == NULL) {
return NULL;
}
/*
* The next statement could be:
*
* strncpy(fullpath, ent->pw_dir, fullpath_len);
*
* however compilers like gcc would issue warnings
* such as:
*
* specified bound depends on the length of the
* source argument
*
* even though we terminate the string by setting a NUL
* byte following the copy. Therefore we call memcpy()
* instead to avoid such warnings.
*/
memcpy(fullpath, ent->pw_dir, fullpath_len);
fullpath[fullpath_len] = '\0';
strlcpy(fullpath, ent->pw_dir, fullpath_len+1);
return fullpath;
}
username = (char *) malloc(after-name + 1 + 1);
@@ -466,8 +459,7 @@ homeexpand(char *name)
/* failed to malloc username */
return NULL;
}
strncpy(username, name+1, after-name-1);
username[after-name-1] = '\0';
strlcpy(username, name+1, after-name+1+1);
/* get that user's home directory */
ent = (struct passwd *)getpwnam(username);
@@ -587,7 +579,7 @@ openfile(char *name)
if (cip->i_name == NULL) {
return -1;
}
strncpy(cip->i_name, name, namelen+1);
strlcpy(cip->i_name, name, namelen+1);
return 0;
}
@@ -623,8 +615,7 @@ openstring(char *str, size_t num)
cp = (char *) malloc(num + 1);
if (cp == NULL)
return -1;
strncpy(cp, str, num);
cp[num] = '\0'; /* firewall */
strlcpy(cp, str, num+1);
cip = inputs + depth++;
cip->i_state = IS_READ;
cip->i_char = '\0';
@@ -946,10 +937,9 @@ runrcfiles(void)
/* load file name into the path */
if (calcrc == NULL) {
strncpy(path, cp, MAX_CALCRC+1);
strlcpy(path, cp, MAX_CALCRC+1);
} else {
strncpy(path, cp, calcrc - cp);
path[calcrc - cp] = '\0';
strlcpy(path, cp, calcrc - cp + 1);
}
/* find the start of the path */
@@ -1129,7 +1119,7 @@ addreadset(char *name, char *path, struct stat *sbuf)
if (readset[ret].name == NULL) {
return -1;
}
strncpy(readset[ret].name, name, name_len+1);
strlcpy(readset[ret].name, name, name_len+1);
#if defined(_WIN32) || defined(__MSDOS__)
/*
* For WIN32, _fullpath expands the path to a fully qualified
@@ -1149,7 +1139,7 @@ addreadset(char *name, char *path, struct stat *sbuf)
if (readset[ret].path == NULL) {
return -1;
}
strncpy(readset[ret].path, path, path_len+1);
strlcpy(readset[ret].path, path, path_len+1);
#endif /* Windoz free systems */
readset[ret].inode = *sbuf;
readset[ret].active = 1;

6
jump.c
View File

@@ -1,7 +1,7 @@
/*
* jump - trivial prime jump table
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -50,6 +50,10 @@
#include "jump.h"
#include "banned.h" /* include after system header <> includes */
/*
* jmpindx - how to find the next value not divisible by a trivial prime
*

View File

@@ -1,7 +1,7 @@
/*
* label - label handling routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -31,6 +31,10 @@
#include "opcodes.h"
#include "func.h"
#include "banned.h" /* include after system header <> includes */
STATIC long labelcount; /* number of user labels defined */
STATIC STRINGHEAD labelnames; /* list of user label names */
STATIC LABEL labels[MAXLABELS]; /* list of user labels */

View File

@@ -41,6 +41,7 @@
#include "token.h"
#include "symbol.h"
#include "func.h"
#include "strl.h"
#if defined(CUSTOM)
#include "custom.h"
@@ -92,6 +93,10 @@ typedef struct {int fd;} ttystruct;
# endif
#endif /* Windoz */
#include "banned.h" /* include after system header <> includes */
/*
* in case we do not have certain .h files
*/
@@ -692,7 +697,7 @@ calc_strdup(CONST char *s1)
* if we have storage, duplicate the string
*/
if (ret != NULL) {
strncpy(ret, s1, s1_len+1);
strlcpy(ret, s1, s1_len+1);
}
/*

View File

@@ -31,9 +31,13 @@
#include "zmath.h"
#include "alloc.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
/*
* lowhex2bin - quick low order ASCII hex to binary conversion
*

View File

@@ -1,7 +1,7 @@
/*
* listfunc - list handling routines
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,10 @@
#include "value.h"
#include "zrand.h"
#include "banned.h" /* include after system header <> includes */
E_FUNC long irand(long s);
S_FUNC LISTELEM *elemalloc(void);

View File

@@ -1,7 +1,7 @@
/*
* longbits - Determine the number if bits in a char, short, int or long
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -92,6 +92,10 @@
# include <stdlib.h>
#endif
#include "banned.h" /* include after system header <> includes */
char *program; /* our name */
int

View File

@@ -28,12 +28,17 @@
* Matrices can contain arbitrary types of elements.
*/
#include "alloc.h"
#include "value.h"
#include "zrand.h"
#include "calcerr.h"
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
E_FUNC long irand(long s);
S_FUNC void matswaprow(MATRIX *m, long r1, long r2);
@@ -851,7 +856,7 @@ matfrac(MATRIX *m)
*/
/*ARGSUSED*/
VALUE *
matindex(MATRIX *mp, BOOL UNUSED create, long dim, VALUE *indices)
matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
{
NUMBER *q; /* index value */
VALUE *vp;

View File

@@ -65,6 +65,9 @@
#include "lib_calc.h"
#include "banned.h" /* include after system header <> includes */
/*
* math_error - print a math error and exit
*/

15
obj.c
View File

@@ -1,7 +1,7 @@
/*
* obj - object handling primitives
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -35,6 +35,10 @@
#include "func.h"
#include "symbol.h"
#include "str.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
/*
@@ -210,6 +214,9 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
char *namestr_ret; /* namestr() return string */
size_t opi_name_len; /* length of the oip name */
/* initilaize name */
memset(name, 0, sizeof(name));
/* initialize VALUEs */
val.v_subtype = V_NOSUBTYPE;
tmp.v_subtype = V_NOSUBTYPE;
@@ -241,9 +248,9 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
/*NOTREACHED*/
}
name[0] = '\0';
strncpy(name, namestr_ret, namestr_len+1);
strcat(name, "_");
strncat(name, oip->name, opi_name_len+1);
strlcpy(name, namestr_ret, namestr_len+1);
strlcat(name, "_", sizeof(name));
strlcat(name, oip->name, sizeof(name));
index = adduserfunc(name);
oap->oa_indices[action] = index;
}

View File

@@ -1,7 +1,7 @@
/*
* opcodes - opcode execution module
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -46,6 +46,10 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#define QUICKLOCALS 20 /* local vars to handle quickly */
@@ -161,7 +165,7 @@ o_localaddr(FUNC *fp, VALUE *locals, long index)
/*ARGSUSED*/
S_FUNC void
o_globaladdr(FUNC UNUSED *fp, GLOBAL *sp)
o_globaladdr(FUNC *UNUSED(fp), GLOBAL *sp)
{
if (sp == NULL) {
math_error("Global variable \"%s\" not initialized",
@@ -177,7 +181,7 @@ o_globaladdr(FUNC UNUSED *fp, GLOBAL *sp)
/*ARGSUSED*/
S_FUNC void
o_paramaddr(FUNC UNUSED *fp, int argcount, VALUE *args, long index)
o_paramaddr(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
@@ -209,7 +213,7 @@ o_localvalue(FUNC *fp, VALUE *locals, long index)
/*ARGSUSED*/
S_FUNC void
o_globalvalue(FUNC UNUSED *fp, GLOBAL *sp)
o_globalvalue(FUNC *UNUSED(fp), GLOBAL *sp)
{
if (sp == NULL) {
math_error("Global variable not defined");
@@ -221,7 +225,7 @@ o_globalvalue(FUNC UNUSED *fp, GLOBAL *sp)
/*ARGSUSED*/
S_FUNC void
o_paramvalue(FUNC UNUSED *fp, int argcount, VALUE *args, long index)
o_paramvalue(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
@@ -266,7 +270,7 @@ o_argvalue(FUNC *fp, int argcount, VALUE *args)
/*ARGSUSED*/
S_FUNC void
o_number(FUNC UNUSED *fp, long arg)
o_number(FUNC *UNUSED(fp), long arg)
{
NUMBER *q;
@@ -284,7 +288,7 @@ o_number(FUNC UNUSED *fp, long arg)
/*ARGSUSED*/
S_FUNC void
o_imaginary(FUNC UNUSED *fp, long arg)
o_imaginary(FUNC *UNUSED(fp), long arg)
{
NUMBER *q;
COMPLEX *c;
@@ -311,7 +315,7 @@ o_imaginary(FUNC UNUSED *fp, long arg)
/*ARGSUSED*/
S_FUNC void
o_string(FUNC UNUSED *fp, long arg)
o_string(FUNC *UNUSED(fp), long arg)
{
stack++;
stack->v_str = slink(findstring(arg));
@@ -331,7 +335,7 @@ o_undef(void)
/*ARGSUSED*/
S_FUNC void
o_matcreate(FUNC UNUSED *fp, long dim)
o_matcreate(FUNC *UNUSED(fp), long dim)
{
register MATRIX *mp; /* matrix being defined */
NUMBER *num1; /* first number from stack */
@@ -399,7 +403,7 @@ o_matcreate(FUNC UNUSED *fp, long dim)
/*ARGSUSED*/
S_FUNC void
o_eleminit(FUNC UNUSED *fp, long index)
o_eleminit(FUNC *UNUSED(fp), long index)
{
VALUE *vp;
STATIC VALUE *oldvp;
@@ -540,7 +544,7 @@ o_eleminit(FUNC UNUSED *fp, long index)
*/
/*ARGSUSED*/
S_FUNC void
o_indexaddr(FUNC UNUSED *fp, long dim, long writeflag)
o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
{
int i;
BOOL flag;
@@ -693,7 +697,7 @@ o_indexaddr(FUNC UNUSED *fp, long dim, long writeflag)
/*ARGSUSED*/
S_FUNC void
o_elemaddr(FUNC UNUSED *fp, long index)
o_elemaddr(FUNC *UNUSED(fp), long index)
{
VALUE *vp;
MATRIX *mp;
@@ -748,7 +752,7 @@ o_elemvalue(FUNC *fp, long index)
/*ARGSUSED*/
S_FUNC void
o_objcreate(FUNC UNUSED *fp, long arg)
o_objcreate(FUNC *UNUSED(fp), long arg)
{
stack++;
stack->v_type = V_OBJ;
@@ -2558,7 +2562,7 @@ o_return(void)
/*ARGSUSED*/
S_FUNC void
o_jumpz(FUNC UNUSED *fp, BOOL *dojump)
o_jumpz(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
int i; /* result of comparison */
@@ -2582,7 +2586,7 @@ o_jumpz(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_jumpnz(FUNC UNUSED *fp, BOOL *dojump)
o_jumpnz(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
int i; /* result of comparison */
@@ -2609,7 +2613,7 @@ o_jumpnz(FUNC UNUSED *fp, BOOL *dojump)
*/
/*ARGSUSED*/
S_FUNC void
o_jumpnn(FUNC UNUSED *fp, BOOL *dojump)
o_jumpnn(FUNC *UNUSED(fp), BOOL *dojump)
{
if (stack->v_addr->v_type) {
*dojump = TRUE;
@@ -2620,7 +2624,7 @@ o_jumpnn(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_condorjump(FUNC UNUSED *fp, BOOL *dojump)
o_condorjump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
@@ -2646,7 +2650,7 @@ o_condorjump(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_condandjump(FUNC UNUSED *fp, BOOL *dojump)
o_condandjump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *vp;
@@ -2677,7 +2681,7 @@ o_condandjump(FUNC UNUSED *fp, BOOL *dojump)
*/
/*ARGSUSED*/
S_FUNC void
o_casejump(FUNC UNUSED *fp, BOOL *dojump)
o_casejump(FUNC *UNUSED(fp), BOOL *dojump)
{
VALUE *v1, *v2;
int r;
@@ -2699,7 +2703,7 @@ o_casejump(FUNC UNUSED *fp, BOOL *dojump)
/*ARGSUSED*/
S_FUNC void
o_jump(FUNC UNUSED *fp, BOOL *dojump)
o_jump(FUNC *UNUSED(fp), BOOL *dojump)
{
*dojump = TRUE;
}
@@ -2719,7 +2723,7 @@ o_usercall(FUNC *fp, long index, long argcount)
/*ARGSUSED*/
S_FUNC void
o_call(FUNC UNUSED *fp, long index, long argcount)
o_call(FUNC *UNUSED(fp), long index, long argcount)
{
VALUE result;
@@ -3101,7 +3105,7 @@ o_rightshift(void)
/*ARGSUSED*/
S_FUNC void
o_debug(FUNC UNUSED *fp, long line)
o_debug(FUNC *UNUSED(fp), long line)
{
funcline = line;
if (abortlevel >= ABORT_STATEMENT) {
@@ -3142,7 +3146,7 @@ o_printresult(void)
/*ARGSUSED*/
S_FUNC void
o_print(FUNC UNUSED *fp, long flags)
o_print(FUNC *UNUSED(fp), long flags)
{
VALUE *vp;
@@ -3176,7 +3180,7 @@ o_printspace(void)
/*ARGSUSED*/
S_FUNC void
o_printstring(FUNC UNUSED *fp, long index)
o_printstring(FUNC *UNUSED(fp), long index)
{
STRING *s;
char *cp;

5
pix.c
View File

@@ -1,7 +1,7 @@
/*
* pix - number of primes less than a small value
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -30,6 +30,9 @@
#include "have_const.h"
#include "banned.h" /* include after system header <> includes */
/*
* pi10b - number of primes <= 2^18 in multiples of 2^10
*

5
poly.c
View File

@@ -1,7 +1,7 @@
/*
* poly - polynomial functions
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -30,6 +30,9 @@
#include "value.h"
#include "banned.h" /* include after system header <> includes */
BOOL
evp(LISTELEM *cp, LISTELEM *x, VALUE *vres)
{

View File

@@ -1,7 +1,7 @@
/*
* prime - quickly determine if a small number is prime
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -31,6 +31,9 @@
#include "have_const.h"
#include "banned.h" /* include after system header <> includes */
/*
* odd prime bitmap for odd values < 2^16
*

View File

@@ -30,6 +30,10 @@
#include "config.h"
#include "prime.h"
#include "banned.h" /* include after system header <> includes */
STATIC NUMBER **B_table;
STATIC long B_num;
STATIC long B_allocnum;

7
qio.c
View File

@@ -1,7 +1,7 @@
/*
* qio - scanf and printf routines for arbitrary precision rational numbers
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -31,6 +31,9 @@
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
#define PUTCHAR(ch) math_chr(ch)
#define PUTSTR(str) math_str(str)
#define PRINTF1(fmt, a1) math_fmt(fmt, a1)
@@ -322,7 +325,7 @@ qprintff(NUMBER *q, long width, long precision)
*/
/*ARGSUSED*/
void
qprintfe(NUMBER *q, long UNUSED width, long precision)
qprintfe(NUMBER *q, long UNUSED(width), long precision)
{
long exponent;
NUMBER q2;

View File

@@ -31,6 +31,9 @@
#include "config.h"
#include "banned.h" /* include after system header <> includes */
NUMBER _qzero_ = { { _zeroval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qone_ = { { _oneval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qtwo_ = { { _twoval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };

5
qmod.c
View File

@@ -1,7 +1,7 @@
/*
* qmod - modular arithmetic routines for normal numbers and REDC numbers
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,9 @@
#include "config.h"
#include "banned.h" /* include after system header <> includes */
/*
* Structure used for caching REDC information.
*/

View File

@@ -33,6 +33,10 @@
#include "qmath.h"
#include "banned.h" /* include after system header <> includes */
HALF _qlgenum_[] = { 36744 };
HALF _qlgeden_[] = { 25469 };
NUMBER _qlge_ = { { _qlgenum_, 1, 0 }, { _qlgeden_, 1, 0 }, 1, NULL };

View File

@@ -39,6 +39,10 @@
#include "zrand.h"
#include "zrandom.h"
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/

30
rpm.mk
View File

@@ -106,11 +106,30 @@ TMPDIR= ${RPM_TOP}/tmp
# Q=@ do not echo internal Makefile actions (quiet mode)
# Q= echo internal Makefile actions (debug / verbose mode)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 slience ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null slience command stderr during hsrc file formation
# E= full command stderr during hsrc file formation
#
# V=@: do not echo debug statements (quiet mode)
# V=@ do echo debug statements (debug / verbose mode)
#
#Q=
Q=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
@@ -121,20 +140,20 @@ all: ver_calc calc.spec
-e '/^Release:/s/^Release: *//p' calc.spec.in`"; \
$(MAKE) -f rpm.mk rpm \
PROJECT_VERSION="$$PROJECT_VERSION" \
PROJECT_RELEASE="$$PROJECT_RELEASE"
PROJECT_RELEASE="$$PROJECT_RELEASE" Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
pkgme: $(PROJECT_NAME)-spec.${TAR}.bz2
ver_calc:
${V} echo '=-=-=-=-= rpm.mk start of $@ rule =-=-=-=-='
$(MAKE) -f Makefile ver_calc
$(MAKE) -f Makefile ver_calc Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
.PHONY: vers
vers:
${V} echo '=-=-=-=-= rpm.mk start of $@ rule =-=-=-=-='
$(MAKE) -f Makefile ver_calc
$(MAKE) -f Makefile ver_calc Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
calc.spec: calc.spec.in ver_calc
@@ -174,7 +193,7 @@ rpm: srcpkg calc.spec
${V} echo RPM_BUILD_ROOT="${RPM_BUILD_ROOT}"
${V} echo PROJECT_VERSION="${PROJECT_VERSION}"
${V} echo PROJECT_RELEASE="${PROJECT_RELEASE}"
$(MAKE) -f Makefile clean
$(MAKE) -f Makefile clean Q= S= E=
${CP} "$(SPECFILE)" "$(RPM_TOP)/SPECS/$(SPECFILE)"
${RM} -f "$(RPM_TOP)/RPMS/$(TARCH)/$(RPMx86_64)"
${RM} -f "$(RPM_TOP)/RPMS/$(TARCH)/$(DRPMx86_64)"
@@ -270,7 +289,8 @@ test: ver_calc
echo "test needs to install, must be root to test" 1>&2; \
exit 6; \
fi
$(MAKE) -f rpm.mk PROJECT_VERSION="`./ver_calc`" installrpm chksys
$(MAKE) -f rpm.mk PROJECT_VERSION="`./ver_calc`" installrpm \
chksys Q= S= E=
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
.PHONY: installrpm

View File

@@ -1,7 +1,7 @@
/*
* sample_many - generate many random values via random number generator
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -40,6 +40,10 @@
#include "have_const.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
#define DEF_CNT 128 /* default number of bits to generate */
#define RESEED 1000 /* number of random numbers to generate */
#define MANY 100 /* number of random numbers to generate */

View File

@@ -1,7 +1,7 @@
/*
* sample_rand - test the libcalc random number generator
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -40,6 +40,10 @@
#include "have_const.h"
#include "lib_util.h"
#include "banned.h" /* include after system header <> includes */
#define DEF_CNT 128 /* default number of bits to generate */
extern char *program; /* our name */

4
seed.c
View File

@@ -79,6 +79,7 @@
# include <sys/resource.h>
#endif
#include <setjmp.h>
#include "alloc.h"
#include "qmath.h"
#include "longbits.h"
#include "have_ustat.h"
@@ -99,6 +100,9 @@
#endif
#include "banned.h" /* include after system header <> includes */
/*
* 64 bit hash value
*/

4
sha1.c
View File

@@ -27,6 +27,7 @@
#include <stdio.h>
#include "alloc.h"
#include "longbits.h"
#include "align32.h"
#include "endian_calc.h"
@@ -35,6 +36,9 @@
#include "sha1.h"
#include "banned.h" /* include after system header <> includes */
/*
* The SHA1 f()-functions. The f1 and f3 functions can be optimized
* to save one boolean operation each - thanks to Rich Schroeppel,

5
size.c
View File

@@ -1,7 +1,7 @@
/*
* size - size and sizeof functions are implemented here
*
* Copyright (C) 1999-2007 David I. Bell
* Copyright (C) 1999-2007,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -30,6 +30,9 @@
#include "block.h"
#include "banned.h" /* include after system header <> includes */
/*
* forward declarations
*/

28
str.c
View File

@@ -1,7 +1,7 @@
/*
* str - string list routines
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -28,12 +28,22 @@
#include <stdio.h>
#include <ctype.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "calc.h"
#include "alloc.h"
#include "str.h"
#include "strl.h"
#include "banned.h" /* include after system header <> includes */
#define STR_TABLECHUNK 100 /* how often to reallocate string table */
#define STR_CHUNK 2000 /* size of string storage allocation */
#define STR_UNIQUE 100 /* size of string to allocate separately */
#define STR_CHUNK (1<<11) /* size of string storage allocation */
#define STR_UNIQUE (1<<7) /* size of string to allocate separately */
STRING _nullstring_ = {"", 0, 1, NULL};
@@ -107,7 +117,7 @@ addstr(STRINGHEAD *hp, char *str)
hp->h_used += len;
hp->h_avail -= len;
hp->h_count++;
strcpy(retstr, str);
strlcpy(retstr, str, len);
retstr[len] = '\0';
return retstr;
}
@@ -279,15 +289,19 @@ addliteral(char *str)
table = literals.l_table;
/*
* If the new string is very long, allocate it manually.
*
* Add room for trailing NUL and then round up to a
* memory chunk (in this case we pick the size of a FULL
* just because that is a nice size) for extra padded room.
*/
len = (len + 2) & ~1; /* add room for null and round up to word */
len = ROUNDUP(len+1, FULL_LEN);
if (len >= STR_UNIQUE) {
newstr = (char *)malloc(len);
if (newstr == NULL) {
math_error("Cannot allocate large literal string");
/*NOTREACHED*/
}
strcpy(newstr, str);
strlcpy(newstr, str, len);
table[literals.l_count++] = newstr;
return newstr;
}
@@ -311,7 +325,7 @@ addliteral(char *str)
literals.l_avail -= len;
literals.l_alloc += len;
table[literals.l_count++] = newstr;
strcpy(newstr, str);
strlcpy(newstr, str, len);
return newstr;
}

9
str.h
View File

@@ -24,8 +24,8 @@
*/
#if !defined(INCLUDE_CALCSTRING_H)
#define INCLUDE_CALCSTRING_H
#if !defined(INCLUDE_STR_H)
#define INCLUDE_STR_H
#if defined(CALC_SRC) /* if we are building from the calc source tree */
@@ -35,6 +35,7 @@
#endif
struct string {
char *s_str;
size_t s_len;
@@ -52,6 +53,7 @@ typedef struct {
long h_count; /* number of strings */
} STRINGHEAD;
EXTERN STRING _nullstring_;
E_FUNC void initstr(STRINGHEAD *hp);
E_FUNC char *addstr(STRINGHEAD *hp, char *str);
@@ -72,7 +74,6 @@ E_FUNC void fitstring(char *, long, long);
E_FUNC void strprint(STRING *);
E_FUNC void showstrings(void);
E_FUNC void showliterals(void);
EXTERN STRING _nullstring_;
#endif /* !INCLUDE_CALCSTRING_H */
#endif /* !INCLUDE_STR_H */

301
strl.c Normal file
View File

@@ -0,0 +1,301 @@
/*
* strl - size-bounded string copying and concatenation
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/08 21;58:10
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "strl.h"
#include "alloc.h"
#if defined(STRL_TEST)
#include <stdio.h>
#include <stdlib.h>
#endif /* STRL_TEST */
#include "banned.h" /* include after system header <> includes */
#if !defined(HAVE_STRLCPY) || defined(STRL_TEST)
/*
* calc_strlcpy - calc STRL_TEST test version of strlcpy
* strlcpy - size-bounded string copying
*
* The strlcpy() functions copies up to dstsize-1 characters from the
* string src to dst, NUL-terminating the result if dstsize > 0.
*
* This function attempts to simulate strlcpy() on systems that
* do not have this function in their C library.
*
* given:
* dst destination string
* src source string
* dstsize size of the destination string buffer including NUL
*
* returns:
* total length of source string excluding NUL,
* 0 ==> invalid arguments
*
* NOTE: If return value is >= dstsize, the result was truncated.
* I.e., there was not enough room in dst and so the copy
* was stopped before it would have overflowed and was NUL terminated.
*/
#if defined(STRL_TEST)
size_t
calc_strlcpy(char * dst, const char * src, size_t dstsize)
#else /* STRL_TEST */
size_t
strlcpy(char * dst, const char * src, size_t dstsize)
#endif /* STRL_TEST */
{
size_t srclen; /* src string length not including NUL */
/*
* firewall
*/
if (dst == NULL || src == NULL || dstsize <= 0) {
/* nothing can be copied */
#if defined(STRL_TEST)
printf("in %s: return 0\n", __FUNCTION__);
#endif /* STRL_TEST */
return 0;
}
/*
* determine how much string we could copy
*/
srclen = strlen(src);
/*
* perform the size limited copy and NUL terminate
*/
if (srclen > dstsize-1) {
memcpy(dst, src, dstsize-1);
dst[dstsize-1] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, dstsize-1);
#endif /* STRL_TEST */
} else {
memcpy(dst, src, srclen);
dst[srclen] = '\0';
#if defined(STRL_TEST)
printf("in %s: else memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, srclen);
#endif /* STRL_TEST */
}
/*
* return the length we tried to copy, not including NUL
*/
#if defined(STRL_TEST)
printf("in %s: return %zu\n", __FUNCTION__, srclen);
#endif /* STRL_TEST */
return srclen;
}
#endif /* !HAVE_STRLCPY || STRL_TEST */
#if !defined(HAVE_STRLCAT) || defined(STRL_TEST)
/*
* calc_strlcat - calc STRL_TEST test version of strlcat
* strlcat - size-bounded string cat
*
* The strlcat() appends string src to the end of dst.
* At most, dstsize - strlen(dst) - 1 characters will of appended.
*
* This function attempts to simulate strlcat() on systems that
* do not have this function in their C library.
*
* given:
* dst destination string
* src source string
* dstsize size of the destination string buffer including NUL
*
* returns:
* total length of string could have been copied excluding NUL,
* 0 ==> invalid arguments
*
* NOTE: If return value is >= dstsize, the output string was truncated.
* I.e., there was not enough room and so the result was truncated
* and NUL terminated.
*/
#if defined(STRL_TEST)
size_t
calc_strlcat(char * dst, const char * src, size_t dstsize)
#else /* STRL_TEST */
size_t
strlcat(char * dst, const char * src, size_t dstsize)
#endif /* STRL_TEST */
{
size_t srclen; /* src string length not including NUL */
size_t dstlen; /* dst string length not including NUL */
size_t catlen; /* amount from src we can copy */
/*
* firewall
*/
if (dst == NULL || src == NULL || dstsize <= 0) {
/* nothing can be concatinated */
#if defined(STRL_TEST)
printf("in %s: return 0\n", __FUNCTION__);
#endif /* STRL_TEST */
return 0;
}
/*
* prep to determine the room we have
*/
dstlen = strlen(dst);
srclen = strlen(src);
#if defined(STRL_TEST)
printf("in %s: dst = ((%s)) src = ((%s)) dstsize = %zu\n",
__FUNCTION__, dst, src, dstsize);
printf("in %s: dstlen = %zu srclen = %zu\n",
__FUNCTION__, dstlen, srclen);
#endif /* STRL_TEST */
if (dstsize <= dstlen+1) {
/* dst is already full */
#if defined(STRL_TEST)
printf("in %s: dstsize: %zu <= dstlen+1: %zu\n",
__FUNCTION__, dstsize, dstlen+1);
printf("in %s: already full return %zu\n",
__FUNCTION__, srclen+dstlen);
#endif /* STRL_TEST */
return srclen+dstlen;
}
/*
* determine the amount data we can copy
*/
catlen = dstsize - dstlen;
/*
* perform the cancatimation
*/
dst += dstlen;
#if defined(STRL_TEST)
printf("in %s: catlen = %zu\n", __FUNCTION__, catlen);
#endif /* STRL_TEST */
if (catlen > srclen+1) {
memcpy(dst, src, srclen);
dst[srclen] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, srclen);
#endif /* STRL_TEST */
} else {
memcpy(dst, src, catlen);
dst[catlen] = '\0';
#if defined(STRL_TEST)
printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n",
__FUNCTION__, dst, src, catlen);
#endif /* STRL_TEST */
}
/*
* return the length, not including NUL, of what could have been formed
*/
#if defined(STRL_TEST)
printf("in %s: return %zu\n", __FUNCTION__, srclen+dstlen);
#endif /* STRL_TEST */
return srclen+dstlen;
}
#endif /* !HAVE_STRLCAT || STRL_TEST */
#if defined(STRL_TEST)
static char src[] = "abcde"; /* test source string */
/*
* Main routine to test the strlcpy() and strlcat() functions.
*/
int
main(int argc, char **argv)
{
char dst[sizeof(src)]; /* test destination string */
size_t ret; /* strlcpy() or strlcat() return */
/*
* normal copy
*/
memset(dst, 0, sizeof(dst));
printf("src: %s\n", src);
ret = calc_strlcpy(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* truncated copy
*/
memset(dst, 0, sizeof(dst));
printf("src: %s\n", src);
ret = calc_strlcpy(dst, src, sizeof(dst)-3);
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* overcat
*/
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* fullcat
*/
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* nilcat
*/
dst[0] = '\0';
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst));
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* shortcat
*/
dst[1] = '\0';
printf("src: %s\n", src);
ret = calc_strlcat(dst, src, sizeof(dst)-3);
printf("ret: %zu\n", ret);
printf("dst: %s\n\n", dst);
/*
* all done
*/
exit(0);
}
#endif /* STRL_TEST */

59
strl.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* strl - size-bounded string copying and concatenation
*
* Copyright (C) 2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2021/03/08 21;58:10
* File existed as early as: 2021
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(INCLUDE_STRL_H)
#define INCLUDE_STRL_H
#if defined(CALC_SRC) /* if we are building from the calc source tree */
#include "have_string.h"
#else
#include <calc/have_string.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#if defined(CALC_SRC) /* if we are building from the calc source tree */
# include "have_strlcpy.h"
# include "have_strlcat.h"
# include "decl.h"
#else
# include <calc/have_strlcpy.h>
# include <calc/have_strlcat.h>
# include <calc/decl.h>
#endif
#if !defined(HAVE_STRLCPY)
E_FUNC size_t strlcpy(char * dst, const char * src, size_t dstsize);
#endif /* !HAVE_STRLCPY */
#if !defined(HAVE_STRLCAT)
E_FUNC size_t strlcat(char * dst, const char * src, size_t dstsize);
#endif /* !HAVE_STRLCAT */
#endif /* !INCLUDE_STRL_H */

View File

@@ -1,7 +1,7 @@
/*
* symbol - global and local symbol routines
*
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -34,6 +34,10 @@
#include "opcodes.h"
#include "func.h"
#include "banned.h" /* include after system header <> includes */
#define HASHSIZE 37 /* size of hash table */
E_FUNC FILE *f_open(char *name, char *mode);

View File

@@ -1,7 +1,7 @@
/*
* token - read input file characters into tokens
*
* Copyright (C) 1999-2007,2017 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -30,12 +30,16 @@
#include <setjmp.h>
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "str.h"
#include "args.h"
#include "lib_calc.h"
#include "banned.h" /* include after system header <> includes */
#define isletter(ch) ((((ch) >= 'a') && ((ch) <= 'z')) || \
(((ch) >= 'A') && ((ch) <= 'Z')))
#define isdigit(ch) (((ch) >= '0') && ((ch) <= '9'))

View File

@@ -1,7 +1,7 @@
/*
* value - generic value manipulation routines
*
* Copyright (C) 1999-2007,2014,2017 David I. Bell
* Copyright (C) 1999-2007,2014,2017,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -38,6 +38,10 @@
#include "file.h"
#include "config.h"
#include "banned.h" /* include after system header <> includes */
#define LINELEN 80 /* length of a typical tty line */
/*

View File

@@ -1,7 +1,7 @@
/*
* value - definitions of general values and related routines used by calc
*
* Copyright (C) 1999-2007,2014 David I. Bell
* Copyright (C) 1999-2007,2014,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License

Some files were not shown because too many files have changed in this diff Show More