Compare commits

..

86 Commits

Author SHA1 Message Date
Landon Curt Noll
11ddc30528 Release v2.14.1.3
The following are the changes in this release:

    Fixed missing <string.h include in have_fpos_pos.c.

    Change calc version from 2.14.1.2 to 2.14.2.3 as part of a test to
    build calc RPMs on a reference RHEL8.7 platform (formerly a RHEL7.9
    platform).
2023-02-14 15:49:05 -08:00
Landon Curt Noll
f5fc06fbd4 update make depend 2023-02-14 15:42:57 -08:00
Landon Curt Noll
8a4c12d2be add missing have_fpos_pos.c fix to CHANGES 2023-02-14 15:41:11 -08:00
Landon Curt Noll
d2139064cb Merge branch 'master' of github.com:lcn2/calc 2023-02-14 15:39:53 -08:00
Landon Curt Noll
774060944b prep for calc version 2.14.1.3
Change calc version from 2.14.1.2 to 2.14.2.3 as part of a test to
build calc RPMs on a reference RHEL8.7 platform (formerly a RHEL7.9
platform).
2023-02-14 15:39:11 -08:00
Landon Curt Noll
61c268f1c2 Merge pull request #68 from fweimer-rh/c99
Avoid implicit declaration memset in have_fpos_pos.c probe
2023-01-21 19:36:01 -08:00
Florian Weimer
dcf360d688 Avoid implicit declaration memset in have_fpos_pos.c probe
Otherwise, the probe result changes with compilers which do not
support implicit function declarations, a language feature that
was removed from C in 1999.
2023-01-18 10:54:55 +01:00
Landon Curt Noll
fddd24d6c6 Update CodeQL Action to v2
See: https://github.blog/changelog/2022-04-27-code-scanning-deprecation-of-codeql-action-v1/
2022-12-08 14:40:03 -08:00
Landon Curt Noll
bcae90959e Enable Dependabot version updateo
See also: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabots
2022-12-08 14:36:15 -08:00
Landon Curt Noll
5b42c557b0 Add missing copyright example to COPYING 2022-12-08 14:29:01 -08:00
Landon Curt Noll
1b0e6c4462 Improve README.WINDOWS
Expand on the notes made by GitHub user @Leoongithub.

Re-order a few README.WINDOWS sections.

Add a number of 'NOTE:" notes to README.WINDOWS.
2022-12-08 14:11:04 -08:00
Landon Curt Noll
f0396fccde Merge pull request #67 from Leoongithub/patch-1
Update latest information about compile under Windows
2022-12-08 13:21:17 -08:00
Leoongithub
21be7adb82 Fix Cygwin compile error 2022-12-07 18:14:11 +08:00
Leoongithub
6317991f2b Update README.WINDOWS 2022-12-07 18:08:44 +08:00
Landon Curt Noll
f4f19f21dc Add config("complex_space") to control spaces around + or - in complex values
Added config("fraction_space", boolean) to help/config, along with
a few few minor text improvements.  Updated cal/regress to test
config("tilde_space").

Added config("complex_space", boolean).  The "complex_space" controls
whether or not a space (' ') is printed before and after the + or -
in complex values.

By default, config("complex_space") is false.

For example, with the default, config("complex_space", 0):

    ; asin(2)
	    1.57079632679489661923-1.31695789692481670863i

With config("complex_space", 1):

    ; asin(2)
	    1.57079632679489661923 - 1.31695789692481670863i

NOTE: Use of config("complex_space", 1) can break printing and scanning
      of fractional values via "%r".

NOTE: Use of config("complex_space", 1) can break printing and scanning
      of complex values via "%c".

Added config("complex_space", boolean) to help/config, along with
a few few minor text improvements.  Updated cal/regress to test
config("complex_space").
2022-12-04 00:53:15 -08:00
Landon Curt Noll
348f3ed427 Clarified -a and -f in calc man page
Clarify in the calc man page, the relationship between -q and
calc start scripts such as the ~/.calcrc file.

Fixed in the calc man page, the issue of -f not implying -q.
2022-12-03 16:36:46 -08:00
Landon Curt Noll
542a263de6 Improve show config and help config order 2022-12-03 16:09:03 -08:00
Landon Curt Noll
17702a4799 Add config("fraction_space") to control spaces around printing fractions
Added config("tilde_space", boolean) to help/config, along with
a few few minor text improvements.  Updated cal/regress to test
config("tilde_space").

Added config("fraction_space", boolean).  The "fraction_space" controls
whether or not a space (' ') is printed before and after fractions.
By default, config("fraction_space") is false.

For example, with the default, config("fraction_space", 0):

    ; base(1/3),
    ; 1/7
            1/7

With config("fraction_space", 1):

    ; base(1/3),
    ; 1/7
            1 / 7

NOTE: Use of config("fraction_space", 1) can break printing and scanning
      of fractional values via "%r".

NOTE: Use of config("fraction_space", 1) can break printing and scanning
      of complex values via "%c".

Added config("fraction_space", boolean) to help/config, along with
a few few minor text improvements.  Updated cal/regress to test
config("tilde_space").
2022-12-03 14:39:25 -08:00
Landon Curt Noll
7c6723db88 Change tilde_space to be 0 by default 2022-12-03 14:02:49 -08:00
Landon Curt Noll
0d99ba54d8 Change default to print space after the approximation tilde
Added config("tilde_space", boolean).  The "tilde_space" controls
whether or not a space (' ') is printed after leading tilde ('~').
By default, config("tilde_space") is true, which is a change
from past behavior.  For example, now:

    ; 1/3
	    ~ 0.33333333333333333333

With config("tilde_space", 0):

    ; 1/3
	    ~0.33333333333333333333

To disable "tilde_space", use config("tilde_space", 0) on the
command line and/or use config("tilde_space", 0),; in your ~/.calcrc.
Thanks goes to <GitHub use ljramalho> for this suggestion.

Added config("tilde_space", boolean) to help/config, along with
a few few minor text improvements.  Updated cal/regress to test
config("tilde_space") and to account for the new default.
2022-12-03 12:22:55 -08:00
Landon Curt Noll
83adfaa720 Removed compiler confusing setjmp() call
In pseudo_seed(), we removed a call to setjmp() that was only
there to add more information to mix into the seed.  For compilers
such as gcc that used -Wclobbered, the call to setjmp() gave the
impression that the hash_val might be clobbered by a longjmp().
Where there is no longjmp() that would use the previous setjmp(),
the gcc compiler has nil ways to notice that. So to avoid confusion
we removed the setjmp() call.  Thanks to <GitHub user mattdm> for
raising this potential concern.
2022-12-03 10:47:05 -08:00
Landon Curt Noll
ef6a30c9c9 Fixed how the original TTY state is preserved
In find_tty_state(), we changed how we expand fd_orig as an original
pre-modified copy of fd_setup.  We realloc the fd_orig array and copy
the fd_setup into it first, before touching the fd_setup array.
2022-12-03 10:25:43 -08:00
Landon Curt Noll
3aaad95443 Fixed a use after free bug
Fixed a -Wuse-after-free warning that identified a call to realloc() in
find_tty_state() could move the fd_setup array.  Thanks goes to <GitHub
user mattdm> for reporting this bug!
2022-12-03 10:10:21 -08:00
Landon Curt Noll
74b833977b Use calloc in swap_HALF_in_ZVALUE() to help with compiler paranoia 2022-12-03 09:34:32 -08:00
Landon Curt Noll
333f0c4332 Add a Makefile comment about how to turn on all messages 2022-12-03 09:33:15 -08:00
Landon Curt Noll
d91ace6091 Release v2.14.1.2
The following are the changes in this release:

    Restored use of the #define FPOS_POS_LEN symbol.  This refers to
    the length of the __pos element (if the __pos element exists),
    the fpos_t type (if that type exists).

    Changed SWAP_HALF_IN_FILEPOS(dest, src) mato to use FILEPOS_LEN Little
    Endian when FILEPOS is a simple scalar type (i.e., HAVE_FILEPOS_SCALAR
    is defined).

    Changed #define HAVE_FPOS to HAVE_FGETSETPOS.

    Corrected comment in have_fpos_pos.h.  The HAVE_FPOS_POS symbol was
    NOT related to fgetpos & fsetpos but rather if we we have an __pos
    element in FILEPOS.

    Changed #define HAVE_NO_FPOS to HAVE_NO_FGETSETPOS.

    Improved comments in have_fpos_pos.h to show why and how
    HAVE_FPOS_POS, FPOS_POS_BITS, and FPOS_POS_LEN were defined or undefed.

    Changed showfiles builtin to print sizes cast to (long int) with
    the "%ld" printf format to avoid implementations that do not support
    the "%lld" printf format specifier.

    Renamed have_fpos.h to have_fgetsetpos.h.  Renamed CALC_HAVE_FPOS_H
    to CALC_HAVE_FGETSETPOS_H.  The make install and the olduninstall
    rules remove the any old have_fpos.h that was previously installed.

    Added swap_HALFs(dest, src, len) function to byteswap.c.

    Calc can now handle Big Engian file position sizes that are a
    multiple of BASEB bits in length.  Before handle Big Engian file
    positions could only be 32 and 64 bits in length.  This will allow,
    for example, a Big Engian file position size of 128 (assuming that
    128/BASEB is is an integer).

    Temporary workaround for musl libc systems such as gentoo Linux that
    allows them to compile calc and successfully run the regression test.
2022-11-29 13:10:33 -08:00
Landon Curt Noll
49c6a8218c Release calc v2.14.1.2
Restored use of the #define FPOS_POS_LEN symbol.  This refers to
the length of the __pos element (if the __pos element exists),
the fpos_t type (if that type exists).

Changed SWAP_HALF_IN_FILEPOS(dest, src) mato to use FILEPOS_LEN Little
Endian when FILEPOS is a simple scalar type (i.e., HAVE_FILEPOS_SCALAR
is defined).

Changed #define HAVE_FPOS to HAVE_FGETSETPOS.

Corrected comment in have_fpos_pos.h.  The HAVE_FPOS_POS symbol was
NOT related to fgetpos & fsetpos but rather if we we have an __pos
element in FILEPOS.

Changed #define HAVE_NO_FPOS to HAVE_NO_FGETSETPOS.

Improved comments in have_fpos_pos.h to show why and how
HAVE_FPOS_POS, FPOS_POS_BITS, and FPOS_POS_LEN were defined or
undefed.

Changed showfiles builtin to print sizes cast to (long int) with
the "%ld" printf format to avoid implementations that do not support
the "%lld" printf format specifier.

Renamed have_fpos.h to have_fgetsetpos.h.  Renamed CALC_HAVE_FPOS_H
to CALC_HAVE_FGETSETPOS_H.  The make install and the olduninstall
rules remove the any old have_fpos.h that was previously installed.

Added swap_HALFs(dest, src, len) function to byteswap.c.

Calc can now handle Big Engian file position sizes that are a
multiple of BASEB bits in length.  Before handle Big Engian file
positions could only be 32 and 64 bits in length.  This will allow,
for example, a Big Engian file position size of 128 (assuming that
128/BASEB is is an integer).

Temporary workaround for musl libc systems such as gentoo Linux that
allows them to compile calc and successfully run the regression
test.
2022-11-29 13:04:00 -08:00
Landon Curt Noll
def203f273 Release calc v2.14.1.2 2022-11-29 12:59:36 -08:00
Landon Curt Noll
5b2983f421 Improve format of SWAP_HALF_IN_FILEPOS in fposval.h 2022-11-28 15:24:31 -08:00
Landon Curt Noll
e6fc1a92a9 Improve file position handling on Big Engian machines
Added swap_HALFs(dest, src, len) function to byteswap.c.

Calc can now handle Big Engian file position sizes that are a
multiple of BASEB bits in length.  Before handle Big Engian file
positions could only be 32 and 64 bits in length.  This will allow,
for example, a Big Engian file position size of 128 (assuming that
128/BASEB is is an integer).
2022-11-28 15:13:16 -08:00
Landon Curt Noll
3e084d9fb9 Rename have_fpos.h to have_fgetsetpos.h
Renamed have_fpos.h to have_fgetsetpos.h.

Renamed CALC_HAVE_FPOS_H to CALC_HAVE_FGETSETPOS_H.
2022-11-28 14:07:47 -08:00
Landon Curt Noll
340c1990ce Checkpoint on fixing compiling with musl gentoo
Restored use of the #define FPOS_POS_LEN symbol.  This refers to the
length of the __pos element (if the __pos element exists), the fpos_t type
(if that type exists).

Changed SWAP_HALF_IN_FILEPOS(dest, src) mato to use FILEPOS_LEN Little
Endian when FILEPOS is a simple scalar type (i.e., HAVE_FILEPOS_SCALAR
is defined).

Changed #define HAVE_FPOS to HAVE_FGETSETPOS.

Corrected comment in have_fpos_pos.h.  The HAVE_FPOS_POS symbol was NOT
related to fgetpos & fsetpos but rather if we we have an __pos element
in FILEPOS.

Changed #define HAVE_NO_FPOS to HAVE_NO_FGETSETPOS.

Improved comments in have_fpos_pos.h to show why and how HAVE_FPOS_POS,
FPOS_POS_BITS, and FPOS_POS_LEN were defined or undefed.

Changed showfiles builtin to print sizes cast to (long int) with the
"%ld" printf format to avoid implementations that do not support the
"%lld" printf format specifier.
2022-11-28 12:55:29 -08:00
Landon Curt Noll
5acd67c704 Updated calc bug report template version: 1.3 2022-11-27 2022-11-27 19:07:54 -08:00
Landon Curt Noll
083011c9e3 Changed full_debug rule to not stop on sub-task error 2022-11-27 19:01:15 -08:00
Landon Curt Noll
dce2c6f0ee Improve the make debug rule
Added full_debug rule to Makefile.  This does the work of the
old debug rule in a more verbose mode by using Q= H=@ S= E= V=@.

The debug rule in the Makefile now pre-removes debug.out and then
runs make full_debug sending stdout and stderr to debug.out.  It then
prints a few instructions about filing a GitHub issue bug report.
2022-11-27 18:45:58 -08:00
Landon Curt Noll
827988c553 Fixed FILEPOS_LEN symbol and macro problems 2022-11-27 17:05:49 -08:00
Landon Curt Noll
25dcd8cb80 Release v2.14.1.1
The following are the changes in this release:

    Added a few remarks on calc version numbers to version.c.

    Fixed how fposval.h is built.  On a number of systems, the fposval.c
    file failed to compile incorrectly.  This caused problems for systems in
    which fposval.h.def was not correct.

    Fixed how have_memmv.h is built.  On a number of systems, the have_memmv.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_memmv.h file for such systems.

    Fixed how align32.h is built.  On a number of systems, the align32.c
    file failed to compile incorrectly, producing a potentially incorrect
    align32.h file for such systems.

    Fixed how have_newstr.h is built.  On a number of systems, the have_newstr.c
    failed to compile incorrectly, producing a potentially incorrect
    have_newstr.h file for such systems.

    Fixed how have_strdup.h is built.  On a number of systems, the have_strdup.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strdup.h file for such systems.

    Fixed how have_strlcat.h is built.  On a number of systems, the have_strlcat.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strlcat.h file for such systems.

    Fixed how have_strlcpy.h is built.  On a number of systems, the have_strlcpy.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_strlcpy.h file for such systems.

    Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_uid_t.h file for such systems.

    Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
    file failed to compile incorrectly, producing a potentially incorrect
    have_uid_t.h file for such systems.
2022-11-27 13:41:32 -08:00
Landon Curt Noll
3b3bfb3f74 Proposed changes for v2.14.1.1
Added a few remarks on calc version numbers to version.c.

Fixed how fposval.h is built.  On a number of systems, the fposval.c
file failed to compile incorrectly.  This caused problems for systems in
which fposval.h.def was not correct.

Fixed how have_memmv.h is built.  On a number of systems, the have_memmv.c
file failed to compile incorrectly, producing a potentially incorrect
have_memmv.h file for such systems.

Fixed how align32.h is built.  On a number of systems, the align32.c
file failed to compile incorrectly, producing a potentially incorrect
align32.h file for such systems.

Fixed how have_newstr.h is built.  On a number of systems, the have_newstr.c
failed to compile incorrectly, producing a potentially incorrect
have_newstr.h file for such systems.

Fixed how have_strdup.h is built.  On a number of systems, the have_strdup.c
file failed to compile incorrectly, producing a potentially incorrect
have_strdup.h file for such systems.

Fixed how have_strlcat.h is built.  On a number of systems, the have_strlcat.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcat.h file for such systems.

Fixed how have_strlcpy.h is built.  On a number of systems, the have_strlcpy.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcpy.h file for such systems.

Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.

Fixed how have_uid_t.h is built.  On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
2022-11-27 13:28:32 -08:00
Landon Curt Noll
3e4391e2af Fix another comment in comma.cal 2022-06-20 19:39:11 -07:00
Landon Curt Noll
cfc6a6669c Improve comments in comma.cal 2022-06-20 19:36:54 -07:00
Landon Curt Noll
fa457db3cd Fix more comments in cal/comma.cal 2022-06-20 19:30:45 -07:00
Landon Curt Noll
d08b958a15 Fix typo in comma.cal comment 2022-06-20 19:28:16 -07:00
Landon Curt Noll
5f28e5b851 Removed training newline from fprint_comma in comma.cal 2022-06-20 19:26:35 -07:00
Landon Curt Noll
8dc52a532a Fix comma.cal to avoid leading 0's and tilde's 2022-06-20 19:20:34 -07:00
Landon Curt Noll
6fc14730c0 Fix the forming of fraction part in comma.cal 2022-06-20 19:10:20 -07:00
Landon Curt Noll
b97093e58c Fix calc man page \-escape, add cal/comma.cal
Fixed a \-escape bug in calc(1) man page.

Added cal/comma.cal:

    Convert numbers into strings with 3-digit group and integer-fraction
    separators.

    If the value is an integer, the integer-fraction separator is not used.

    str_comma(x, [group, [decimal]])

	Convert x into a string.

	If group is given and is a string, group will be used as
	the 3-digit group separator, otherwise the default 3-digit
	group separator will be used.

	If decimal is given and is a string, group will be used as
	the integer-fraction separator, otherwise the default
	integer-fraction separator will be used.

	The decimal and group arguments are optional.

    set_default_group_separator(group)

	Change the default 3-digit group separator if group is a string,
	otherwise the default 3-digit group separator will not be
	changed.  Return the old 3-digit group separator.

    set_default_decimal_separator(decimal)

	Change the default 3-digit group separator if decimal is a
	string, otherwise the default integer-fraction separator
	will not be changed.  Return the old integer-fraction separator.

    print_comma(x, [group, [decimal]])

	Print the value produced by str_comma(x, [group, [decimal]])
	followed by a newline.

	If the str_comma() does not return a string, nothing is printed.

	The decimal and group arguments are optional.

	The value produced by str_comma() is returned.

    fprint_comma(fd, x, [group, [decimal]])

	Print the value produced by str_comma(x, [group, [decimal]]),
	without a trailing newline, on file fd.

	If the str_comma() does not return a string, nothing is printed.

	If fd is not an open file, nothing is printed.

	The decimal and group arguments are optional.

	The value produced by str_comma() is returned.
2022-06-20 18:25:12 -07:00
Landon Curt Noll
923c36e475 Remove excess whitespace under SECURITY.md 2022-04-08 00:24:42 -07:00
Landon Curt Noll
741ea46853 Release v2.14.1.0
The following are the changes from calc version 2.14.1.0 to date:

    Fixed alignment of show item section of help command.

    Bug fix: While 0^0 == 1, now for y > 0, 0^y == 0.
    Adjusted cal/test8900.cal to reflect this bug fix.
    Added tests to cal/regress.cal to help verify bug fix is fixed.
2022-04-08 00:02:44 -07:00
Landon Curt Noll
56b6613da8 Fixed 0^y for y > 0
While 0^0 == 1, now for y > 0, 0^y == 0.

Adjusted cal/test8900.cal to reflect the this bug fix.

Added tests to cal/regress.cal to help verify bug fix is fixed.
2022-04-07 23:54:06 -07:00
Landon Curt Noll
e9eef2dfa2 Merge branch 'master' of github.com:lcn2/calc 2022-04-07 23:44:38 -07:00
Landon Curt Noll
0dbf258696 Fixed alignment of show item section of help command 2022-04-07 23:44:05 -07:00
Landon Curt Noll
f6d558783a Improved security issue template
create a calc GitHub repo issue for a security issue
2022-02-24 13:58:56 -08:00
Landon Curt Noll
6f27a32f79 Calc bug report template version: 1.2 2022-02-24
Added template version and made a minor edit
2022-02-24 12:42:32 -08:00
Landon Curt Noll
d58f605866 Update issue templates
Updated calc Bug report
2022-02-24 12:30:36 -08:00
Landon Curt Noll
b83c5be515 Update issue templates
Add default GitHub Bug and Feature templates
2022-02-15 13:35:46 -08:00
Landon Curt Noll
561928a45c Checkpint disbale use of gettime() under _WIN32 or _WIN64 2022-02-12 13:52:06 -08:00
Landon Curt Noll
7f89af37f5 Checkpoint more Windows 11 Cygwin MINGW64 changes 2022-02-12 13:41:16 -08:00
Landon Curt Noll
4470f1f62e Checkpoint - Windows 11 with Cygwin and MinGW64 packages. 2022-02-12 12:44:32 -08:00
Landon Curt Noll
8217c49b94 Fix lack of quotes in PASSDOWN variables 2022-02-12 11:37:53 -08:00
Landon Curt Noll
d2cb03b4cc Add ${MSYS} to Makefile for Windows 11 MINGW64_NT users 2022-02-12 11:18:49 -08:00
Landon Curt Noll
80f13a4e45 Changed Makefiles as per make depend 2022-01-22 02:52:02 -08:00
Landon Curt Noll
1658343227 Changes to use attributes for noreturn and printf-like functions 2022-01-22 02:48:50 -08:00
Landon Curt Noll
3f177f2d81 Improved source code flow
Changed /*NOTREACHED*/ to not_reached(); and use "attribute.h".

Added .PHONY rule, just after all rule, to Makefiles.

Fixed an improper indentation issue.
2022-01-22 01:16:07 -08:00
Landon Curt Noll
dcd5a987af Added better examples of asan debugging use with gcc and clang 2022-01-13 11:11:32 -08:00
Landon Curt Noll
cb77888045 Expand certain table sizes, add comments to Makefile.local
Expanded the globalsymbol string table size: from 1024 to 65536.

    Expanded the how often to reallocate string table is performed:
    from 100 to 1024.

    Expanded the number env_pool elements to allocate at a time:
    from 10 to 256.

    Improve comments on Makefile.local and add a few more examples
    of how it might be used.
2022-01-02 18:01:21 -08:00
Landon Curt Noll
ce17b267be Minor changes to Makefile, HOWTO.INSTALL, CONTRIBUTING.md
Changed Makefile to set shell before setting the SHELL Makefile
    variable.

    Added text to HOWTO.INSTALL to help people with systems that
    lack the readline package.

    Trimmed long line in the CONTRIBUTING.md file.
2021-12-29 15:16:40 -08:00
Landon Curt Noll
738dd0334e Create CONTRIBUTING.md
Create initial CONTRIBUTING.md file.
2021-12-27 20:01:26 -08:00
Landon Curt Noll
7ba1dbdc65 Create CODE_OF_CONDUCT.md
Initial release of CODE_OF_CONDUCT.md
2021-12-27 19:56:02 -08:00
Landon Curt Noll
ee70c12481 Release v2.14.0.14
The following are the changes in this release:

    Fixed typo in Makefile.local comment.

    Established a tagging procedure for a production release.
    Production git tags will be of the form:

	prod-2.x.y.z
2021-12-27 19:10:56 -08:00
Landon Curt Noll
d4970d66ce Merge branch 'master' of github.com:lcn2/calc 2021-12-27 19:04:53 -08:00
Landon Curt Noll
c3ea3d28a4 Added 2.14.0.14 CHANGES 2021-12-27 19:04:08 -08:00
Landon Curt Noll
3fa34dabfe Fixed typo in comment for Makefile.local 2021-12-13 22:12:03 -08:00
Landon Curt Noll
ffd4422870 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the
"v2.14.0.12 source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

Removed constructed help file that incorrectly added as a src file.

=-=

The following are the changes in this release:

    Made major changes to our release process in order to avoid
    missing critical files that happened in calc v2.4.0.12.

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive, BUGS, HOWTO.INSTALL to reflect GitHub use.
2021-12-13 17:41:35 -08:00
Landon Curt Noll
b5b2c3f812 Updated CHANGES to reflect recent commits 2021-12-13 17:00:01 -08:00
Landon Curt Noll
f7dadbf1f8 Improve how Makefiles are formed, updated related doc 2021-12-13 16:54:45 -08:00
Landon Curt Noll
22e123140c Fix to add missing Makefiles to distlist
The output of the distlist rule was used to form the source tarball.
2021-12-13 16:27:37 -08:00
Landon Curt Noll
1242700601 Fix how Makefile.simple and custom/Makefile.simple are formed 2021-12-13 16:11:38 -08:00
Landon Curt Noll
5b7dfeaf11 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

Removed constructed help file that incorrectly added as a src file.

=-=

The following are the changes in this release:

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive to reflect GitHub use.
2021-12-13 14:43:37 -08:00
Landon Curt Noll
b3c015d338 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

=-=

The following are the changes in this release:

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive to reflect GitHub use.
2021-12-13 14:23:47 -08:00
Landon Curt Noll
5985ad2f33 Updated Makefile.simple due to recent changes in Makefile 2021-12-13 14:16:02 -08:00
Landon Curt Noll
e401c9abf1 Added code to handle HomeBrew macOS libs, added a few #'s 2021-12-13 14:07:51 -08:00
Landon Curt Noll
ad79b6384d Remove leading spaces before a tab in CHANGES 2021-12-13 12:33:35 -08:00
Landon Curt Noll
862dbd6777 Improve the calc build and release process
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

We made several changes to the Makefiles.  We also added a new
README.RELEASE document (see "help release") that is a work in
progress. Along the way we discovered a few things that needed to be
updated in documentation.

See the CHANGES file for details.
2021-12-13 12:17:51 -08:00
Landon Curt Noll
0d31eb6828 Recommend calling srand() or srandom() with seed() 2021-12-09 01:34:58 -08:00
Landon Curt Noll
c0be37d4e3 Added paranoia size limited code for seed() builtin.
Just to be padanticly sure, we prevent seed() from
ever returning a value >= 2^64.
2021-12-09 01:12:44 -08:00
Landon Curt Noll
4344532c28 Improve how a seed is loaded into ZVALUE 2021-12-09 00:49:16 -08:00
102 changed files with 10440 additions and 11028 deletions

View File

@@ -0,0 +1,70 @@
---
name: Calc bug report
about: Create a report to help us improve
title: 'Bug: XXX-change-this-part-XXX'
labels: bug
assignees: ''
---
Calc bug report template version: 1.3 2022-11-27
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
0. How you started calc
I.e., provide the command line you used to launch calc
1. Calc commands and their output
Please provide any calc commands you entered on the terminal.
Please provide the calc command line output inline as well.
If the above is long, please attach a file.
Or if you cannot compile calc: The make command you used try and compile calc
and all error and warning messages produced during that action. If long, consider
attaching a file.
2. Indicate where the problem is
Referring to the information for step 1 above, indicate where the problem is to be found
**Expected behavior**
A clear and concise description of what you expected to happen.
**Attach debug.out**
IMPORTANT: Please run `make debug` and then attach the `debug.out` file.
**Screen shots**
If applicable, attach screen shots to help explain your problem.
**Execution environment (please complete the following information):**
- OS:
E.g., macOS, FreeBSD, Linux, Windows 11, etc.
- OS version:
E.g., Preferred: give the output of `uname -a`
or if no uname command, a description of the OS version/release you are using
- OS distribution:
E.g., macOS 13.0.1, contents of /etc/redhat-release, or /etc/os-release, etc.
- Calc Version
E.g., output of calc -v
or if you cannot compile calc, the version you downloaded and from where it came from
- Shell and shell version
E.g., bash, zsh, power shell, etc.
and the version of the shell you are using, if known
**Calc mods**
If you have modified the calc source for some reason, please description what you modified.
Please consider attaching a patch (diff -u) between an official calc release and the source
you are using.
**Patch**
If you have a recommended code patch to address the problem, please attach your file
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View File

@@ -43,7 +43,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@@ -68,4 +68,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

12
.github/workflows/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# Set update schedule for GitHub Actions
#
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"

5
.gitignore vendored
View File

@@ -29,6 +29,7 @@ cscript/simple
cscript/square
custom/.all
custom/libcustcalc*
debug.out
endian
endian_calc.h
fposval.h
@@ -36,7 +37,7 @@ have_arc4random.h
have_ban_pragma.h
have_const.h
have_environ.h
have_fpos.h
have_fgetsetpos.h
have_fpos_pos.h
have_getpgid.h
have_getprid.h
@@ -84,6 +85,7 @@ help/man
help/new_custom
help/question
help/questions
help/releases
help/resource
help/type
help/usage
@@ -91,6 +93,7 @@ libcalc*
libcustcalc*
longbits
longbits.h
Makefile.our
sample_many
sample_rand
tags

15
BUGS
View File

@@ -15,12 +15,21 @@ Look at the end of the output, it should say something like:
If it does not, then something is really broken!
To be sure that your version of calc is up to date, check out:
To be sure that your version of calc is up to date.
Look for the latest release on GitHub:
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
https://github.com/lcn2/calc/releases
Just below latest GitHub release sectiop is something called:
> Assets
Click in the triangle to open up the Assets then click on
the approptiate package to download.
If you made and modifications to calc beyond the simple Makefile
configuration, try backing them out and see if things get better.
configuration, try backing those changges out and see if things get
better.
If you have tried all of the above and things still are not right,
then it may be time to send in a bug report.

427
CHANGES
View File

@@ -1,4 +1,427 @@
The following are the changes from calc version 2.14.0.11 to date:
The following are the changes from calc version 2.14.2.3 to date:
Fixed missing <string.h include in have_fpos_pos.c.
Change calc version from 2.14.1.2 to 2.14.2.3 as part of a test to
build calc RPMs on a reference RHEL8.7 platform (formerly a RHEL7.9
platform).
The following are the changes from calc version 2.14.2.0 to 2.14.1.2:
Attempted to address a paranoid compiler warning -Wmaybe-uninitialized
in swap_HALF_in_ZVALUE() where the gcc compiler seems to ignore the
fact that calling not_reached() above the call to zcopyval()
should prevent dest from being NULL to the 1st zcopyval() call.
Thanks to <GitHub user mattdm> for raising this potential concern.
Fixed a -Wuse-after-free warning that identified a call to realloc()
in find_tty_state() could move the fd_setup array. Thanks goes to
<GitHub user mattdm> for reporting this bug!
In find_tty_state(), we changed how we expand fd_orig as an original
pre-modified copy of fd_setup. We realloc the fd_orig array and copy
the fd_setup into it first, before touching the fd_setup array.
In pseudo_seed(), we removed a call to setjmp() that was only
there to add more information to mix into the seed. For compilers
such as gcc that used -Wclobbered, the call to setjmp() gave the
impression that the hash_val might be clobbered by a longjmp().
Where there is no longjmp() that would use the previous setjmp(),
the gcc compiler has nil ways to notice that. So to avoid confusion
we removed the setjmp() call. Thanks to <GitHub user mattdm> for
raising this potential concern.
Added config("tilde_space", boolean). The "tilde_space" controls
whether or not a space (' ') is printed after leading tilde ('~').
By default, config("tilde_space") is false.
For example, with the default, config("tilde_space", 0):
; 1/3
~0.33333333333333333333
; sqrt(7 + 5i,1e-100)
~2.79305614578749801863+~0.89507688693280053094i
With config("tilde_space", 1):
; 1/3
~ 0.33333333333333333333
; sqrt(7 + 5i,1e-100)
~ 2.79305614578749801863+~ 0.89507688693280053094i
NOTE: Use of config("tilde_space", 1) can break printing and scanning
of complex values via "%c".
To enable "tilde_space", use config("tilde_space", 1) on the
command line and/or use config("tilde_space", 1),; in your ~/.calcrc.
Thanks goes to <GitHub use ljramalho> for this suggestion.
Added config("tilde_space", boolean) to help/config, along with
a few few minor text improvements. Updated cal/regress to test
config("tilde_space").
For example, with the default, config("tilde_space", 0):
; pi(1e-50)
~3.14159265358979323846
With config("tilde_space", 1):
; pi(1e-50)
~ 3.14159265358979323846
Added config("fraction_space", boolean). The "fraction_space" controls
whether or not a space (' ') is printed before and after fractions.
By default, config("fraction_space") is false.
For example, with the default, config("fraction_space", 0):
; base(1/3),
; 1/7
1/7
With config("fraction_space", 1):
; base(1/3),
; 1/7
1 / 7
NOTE: Use of config("fraction_space", 1) can break printing and scanning
of fractional values via "%r".
NOTE: Use of config("fraction_space", 1) can break printing and scanning
of complex values via "%c".
Added config("fraction_space", boolean) to help/config, along with
a few few minor text improvements. Updated cal/regress to test
config("tilde_space").
Added config("complex_space", boolean). The "complex_space" controls
whether or not a space (' ') is printed before and after the + or -
in complex values.
By default, config("complex_space") is false.
For example, with the default, config("complex_space", 0):
; asin(2)
1.57079632679489661923-1.31695789692481670863i
With config("complex_space", 1):
; asin(2)
1.57079632679489661923 - 1.31695789692481670863i
NOTE: Use of config("complex_space", 1) can break printing and scanning
of fractional values via "%r".
NOTE: Use of config("complex_space", 1) can break printing and scanning
of complex values via "%c".
Added config("complex_space", boolean) to help/config, along with
a few few minor text improvements. Updated cal/regress to test
config("complex_space").
Clarify in the calc man page, the relationship between -q and
calc start scripts such as the ~/.calcrc file.
Fixed in the calc man page, the issue of -f not implying -q.
The following are the changes from calc version 2.14.1.2 to date:
Restored use of the #define FPOS_POS_LEN symbol. This refers to
the length of the __pos element (if the __pos element exists),
the fpos_t type (if that type exists).
Changed SWAP_HALF_IN_FILEPOS(dest, src) mato to use FILEPOS_LEN Little
Endian when FILEPOS is a simple scalar type (i.e., HAVE_FILEPOS_SCALAR
is defined).
Changed #define HAVE_FPOS to HAVE_FGETSETPOS.
Corrected comment in have_fpos_pos.h. The HAVE_FPOS_POS symbol was
NOT related to fgetpos & fsetpos but rather if we we have an __pos
element in FILEPOS.
Changed #define HAVE_NO_FPOS to HAVE_NO_FGETSETPOS.
Improved comments in have_fpos_pos.h to show why and how
HAVE_FPOS_POS, FPOS_POS_BITS, and FPOS_POS_LEN were defined or undefed.
Changed showfiles builtin to print sizes cast to (long int) with
the "%ld" printf format to avoid implementations that do not support
the "%lld" printf format specifier.
Renamed have_fpos.h to have_fgetsetpos.h. Renamed CALC_HAVE_FPOS_H
to CALC_HAVE_FGETSETPOS_H. The make install and the olduninstall
rules remove the any old have_fpos.h that was previously installed.
Added swap_HALFs(dest, src, len) function to byteswap.c.
Calc can now handle Big Engian file position sizes that are a
multiple of BASEB bits in length. Before handle Big Engian file
positions could only be 32 and 64 bits in length. This will allow,
for example, a Big Engian file position size of 128 (assuming that
128/BASEB is is an integer).
Temporary workaround for musl libc systems such as gentoo Linux that
allows them to compile calc and successfully run the regression test.
The following are the changes from calc version 2.14.1.1 to 2.14.1.1:
Added a few remarks on calc version numbers to version.c.
Fixed how fposval.h is built. On a number of systems, the fposval.c
file failed to compile incorrectly. This caused problems for systems in
which fposval.h.def was not correct.
Fixed how have_memmv.h is built. On a number of systems, the have_memmv.c
file failed to compile incorrectly, producing a potentially incorrect
have_memmv.h file for such systems.
Fixed how align32.h is built. On a number of systems, the align32.c
file failed to compile incorrectly, producing a potentially incorrect
align32.h file for such systems.
Fixed how have_newstr.h is built. On a number of systems, the have_newstr.c
failed to compile incorrectly, producing a potentially incorrect
have_newstr.h file for such systems.
Fixed how have_strdup.h is built. On a number of systems, the have_strdup.c
file failed to compile incorrectly, producing a potentially incorrect
have_strdup.h file for such systems.
Fixed how have_strlcat.h is built. On a number of systems, the have_strlcat.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcat.h file for such systems.
Fixed how have_strlcpy.h is built. On a number of systems, the have_strlcpy.c
file failed to compile incorrectly, producing a potentially incorrect
have_strlcpy.h file for such systems.
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
file failed to compile incorrectly, producing a potentially incorrect
have_uid_t.h file for such systems.
Added full_debug rule to Makefile. This does the work of the
old debug rule in a more verbose mode by using Q= H=@ S= E= V=@.
The debug rule in the Makefile now pre-removes debug.out and then
runs make full_debug sending stdout and stderr to debug.out. It then
prints a few instructions about filing a GitHub issue bug report.
The full_debug rule will no longer stop when one of the sub-tasks
failed (exit non-zero).
The following are the changes from calc version 2.14.1.0 to 2.14.1.0:
Fixed alignment of show item section of help command.
Bug fix: While 0^0 == 1, now for y > 0, 0^y == 0.
Adjusted cal/test8900.cal to reflect this bug fix.
Added tests to cal/regress.cal to help verify bug fix is fixed.
Fixed a \-escape bug in calc(1) man page.
Added cal/comma.cal:
Convert numbers into strings with 3-digit group and integer-fraction
separators.
If the value is an integer, the integer-fraction separator is not used.
str_comma(x, [group, [decimal]])
Convert x into a string.
If group is given and is a string, group will be used as
the 3-digit group separator, otherwise the default 3-digit
group separator will be used.
If decimal is given and is a string, group will be used as
the integer-fraction separator, otherwise the default
integer-fraction separator will be used.
The decimal and group arguments are optional.
set_default_group_separator(group)
Change the default 3-digit group separator if group is a string,
otherwise the default 3-digit group separator will not be
changed. Return the old 3-digit group separator.
set_default_decimal_separator(decimal)
Change the default 3-digit group separator if decimal is a
string, otherwise the default integer-fraction separator
will not be changed. Return the old integer-fraction separator.
print_comma(x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]])
followed by a newline.
If the str_comma() does not return a string, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
fprint_comma(fd, x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]]),
without a trailing newline, on file fd.
If the str_comma() does not return a string, nothing is printed.
If fd is not an open file, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
The following are the changes from calc version 2.14.0.15 to 2.14.0.15:
Changed Makefile to set shell before setting the SHELL Makefile
variable.
Added text to HOWTO.INSTALL to help people with systems that
lack the readline package.
Trimmed long line in the CONTRIBUTING.md file.
Expanded the globalsymbol string table size: from 1024 to 65536.
Expanded the how often to reallocate string table is performed:
from 100 to 1024.
Expanded the number env_pool elements to allocate at a time:
from 10 to 256.
Improve comments on Makefile.local and add a few more examples
of how it might be used.
Changed /*NOTREACHED*/ to not_reached(); and use "attribute.h".
Added .PHONY rule, just after all rule, to Makefiles.
Made minor format update on help/commands.
Added ${WINGM} Makefile variable for users under Windows 11 who
use Cygwin and the MinGW64 packages.
Updated README.WINDOWS for Windows 11 users based on advice
form a Microsoft 11 developer.
Fixed missing quotes in the PASSDOWN makefile variables.
Disable use of gettime() under _WIN32 or _WIN64.
The following are the changes from calc version 2.14.0.14 to 2.14.0.14:
Fixed typo in Makefile.local comment.
Established a tagging procedure for a production release.
Production git tags will be of the form:
prod-2.x.y.z
The following are the changes from calc version 2.14.0.13 to 2.14.0.13:
Made major changes to our release process in order to avoid
missing critical files that happened in calc v2.4.0.12.
Minor tweak to seed() builtin. Updated help/srand and help/srandom.
Moved Makefile.ship into Makefile.
Removed custom/Makefile.head and custom/Makefile.tail.
The custom/Makefile is now part of source and includes Makefile.
In particular, custom/Makefile makes use of the 'middle' of
the new top level Makefile where calc's top level Makefile
variables are defined.
Makefile.simple and custom/Makefile.simple are now part of the source
and are constructed from Makefile and custom/Makefile respectively.
The Makefile.simple and custom/Makefile.simple avoid using GNU
conditionals. They may be used with older/classic make commands.
Makefile.local will include comments about how to better use
it. Between releases, Makefile.local at the top of the master branch
will contain how we typically build calc and test calc (FYI: we
normally enable things such as -Werror -Wextra -pedantic). When we
push out a release, Makefile.local will be stripped of non-comment
lines. Thus, releases of calc, and, released "calc*.src.rpm"
files and the source tarballs, will have a Makefile.local with
only comments.
The "README.*" files and "HOWTO.INSTALL" file have been updated.
By default, compiler warnings have been turned up. The Makefile
variable ${CCWARN} now defaults to:
CCWARN= -Wall -Wextra -pedantic
The previous level of compiler warnings can be easily restored by
adding to Makefile.local:
CCWARN:= -Wall
The readline, history and ncurses libraries are now default.
The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
${READLINE_EXTRAS} now default to:
USE_READLINE= -DUSE_READLINE
READLINE_LIB= -lreadline
READLINE_EXTRAS= -lhistory -lncurses
The previous mode where readline, history and ncurses libraries
were not compiled in by default can be easily restored by
adding to Makefile.local:
USE_READLINE:=
READLINE_LIB:=
READLINE_EXTRAS:=
We have renamed "stable" as "production".
We have renamed "unstable" as "tested".
On the web site:
http://www.isthe.com/chongo/src/calc/
these files has been renamed:
2.x.y.z_IS_LATEST_STABLE ==> 2.x.y.z_IS_LATEST_PRODUCTION
2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED
The terms 'stable' and 'unstable' were both misleading and
inaccurate. For details see the new documention file:
README.RELEASE
See also the help command:
; help release
Fixed bug impacting how have_ustat.h was formed.
Updated help/archive, BUGS, HOWTO.INSTALL to reflect GitHub use.
The following are the changes from calc version 2.14.0.11 to 2.14.0.12:
Fixed a number of typos.
@@ -8103,7 +8526,7 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
A small bug in the library file regress.cal was fixed.
## Copyright (C) 2001-2017,2021 Landon Curt Noll
## Copyright (C) 2001-2017,2021,2022 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

128
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
https://github.com/lcn2/calc/blob/master/QUESTIONS.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

7
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,7 @@
# How to contribue code to calc
## CONTRIB-CODE
See the file
<A HREF="https://github.com/lcn2/calc/blob/master/CONTRIB-CODE">CONTRIB-CODE</A>
for how to contribue code to calc.

View File

@@ -6,7 +6,7 @@ This file is Copyrighted
This file is covered under the following Copyright:
Copyright (C) 1999-2021 Landon Curt Noll
Copyright (C) 1999-2022 Landon Curt Noll
All rights reserved.
Everyone is permitted to copy and distribute verbatim copies
@@ -120,6 +120,7 @@ Calc copyrights and exception files
Copyright (C) year Ernest Bowen
Copyright (C) year Petteri Kettunen and Landon Curt Noll
Copyright (C) year Christoph Zurnieden
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
These files are not covered under one of the Copyrights listed above:

View File

@@ -47,22 +47,114 @@ or from:
4 steps:
(1) Look at the makefile, and adjust it to suit your needs.
(1) Look at the makefile, and adjust it to suit your needs.
The top level Makefile and the custom/Makefile require a modern
Make (such as gmake) or an equivalently advanced make. On many
targets, the default make is sufficient. On FreeBSD for example,
probably want to use gmake instead of make.
Some report that under macOS, one has to declare the target
to be Darwin. So for macOS, one might have to do:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! By default, calc assumes you have the readline package installed !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! macOS does not have readline, so mac users need to make a choice !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# for macOS users only, force the target to be Darwin
#
make target=Darwin clobber
make target=Darwin all
make target=Darwin chk
make target=Darwin install
The readline package (-lreadline, -lhistory, -lncurses) used by and
linked into calc by default. If your system does NOT have those
libaraies, then you have two options:
(1-with readline) Install the readline package <- Recommended
Install the readline package first, then compile calc.
For information on the readline package, see:
https://tiswww.case.edu/php/chet/readline/rltop.html
MacOS users can use MacPorts or HomeBrew to install readline:
https://www.macports.org
https://brew.sh
Or compile from the readline.git repo:
http://git.savannah.gnu.org/cgit/readline.git/
(1-w/o readline) Compile calc without readline (not recommended)
Why do we not recommend (1b)? Because using calc with readline
provides a beter user experience.
If you feel you must use calc without the readline package, then you
will need to change your calc Makefile with this patch:
--- Makefile.old 2021-12-29 14:57:56.000000000 -0800
+++ Makefile 2021-12-29 14:59:13.000000000 -0800
@@ -1140,14 +1140,14 @@
#
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
#
-#USE_READLINE=
-USE_READLINE= -DUSE_READLINE
+USE_READLINE=
+#USE_READLINE= -DUSE_READLINE
#
-#READLINE_LIB=
-#READLINE_EXTRAS=
+READLINE_LIB=
+READLINE_EXTRAS=
#
-READLINE_LIB= -lreadline
-READLINE_EXTRAS= -lhistory -lncurses
+#READLINE_LIB= -lreadline
+#READLINE_EXTRAS= -lhistory -lncurses
#
#READLINE_LIB= -L/usr/gnu/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
@@ -1181,8 +1181,8 @@
# # and using the readline, history, and ncurses libraries.
# #
ifneq ($(HOMEBREW_PREFIX),)
-READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
-READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
+#READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
+#READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
endif
#
#endif /* end of skip for non-Gnu makefiles */
If your target system does not have a modern Makefile
(such as gmake), then you will need to change your
Makefile.simple with this patch:
--- Makefile.simple.orig 2021-12-29 15:00:53.000000000 -0800
+++ Makefile.simple 2021-12-29 15:01:00.000000000 -0800
@@ -1005,14 +1005,14 @@
#
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
#
-#USE_READLINE=
-USE_READLINE= -DUSE_READLINE
+USE_READLINE=
+#USE_READLINE= -DUSE_READLINE
#
-#READLINE_LIB=
-#READLINE_EXTRAS=
+READLINE_LIB=
+READLINE_EXTRAS=
#
-READLINE_LIB= -lreadline
-READLINE_EXTRAS= -lhistory -lncurses
+#READLINE_LIB= -lreadline
+#READLINE_EXTRAS= -lhistory -lncurses
#
#READLINE_LIB= -L/usr/gnu/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! By default, calc assumes you are using a modern gnu-like make tool !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If your target system does not have a modern Makefile (such as gmake),
then you should try using the Makefile.simple and custom/Makefile.simple
@@ -212,15 +304,15 @@ or from:
(3) test calc:
make check
make check
NOTE: For a quiet check which only prints if something goes wrong:
make chk
make chk
(4) install calc:
make install
make install
We suggest that you might want to read the README.FIRST file and look at
the calc help subsystem. See also the README.md file.
@@ -256,45 +348,33 @@ SHELL= ...
SHELL= /bin/sh
Makefile
Makefile.local
# SRC: Makefile - Our calc build environment
# SRC: Makefile.local - tweaks to the top level Makefile
This is our internal Makefile that drives how we build calc.
For critical rules in Makefile.ship, there is a corresponding
rule, Makefile, that calls ${MAKE} -f Makefile.ship with,
additional commands, args and Makefile variables. The ${XVAR}
Makefile variable, for example, is passed on each call to
${MAKE} -f Makefile.ship so that the environment and parameters of
Makefile.ship may be managed for our build environment.
Between releases, Makefile.local at the top of the master branch
will contain how we typically build calc and test calc (FYI: we
normally enable things such as -Werror -Wextra -pedantic). When we
push out a release, Makefile.local will be stripped of non-comment
lines. Thus, releases of calc, and, released "calc*.src.rpm"
files and the source tarballs, will have a Makefile.local with
only comments.
This Makefile is used to make the calc rpm. In addition to these
comments, this Makefile differs from the non-rpm bzip2-ed tarball
source Makefile in at least the the following ways:
If the Makefile is not suitable for you (say because you fetch it
from the top of the master branch between releases), then you may
wish to remove all non-comment lines. I.e., lines that do not start
with the # character.
CCWERR= -Werror
USE_READLINE= -DUSE_READLINE
READLINE_LIB= -lreadline -lhistory -lncurses
If the Makefile is not suitable for you, then
you may wish to replace it with Makefile.ship:
mv -f -v Makefile.ship Makefile
This Makefile assumes you have a modern make command such as
This Makefile.local assumes you have a modern make command such as
the GNU make. See Makefile.simple comment below if you do not
have such a modern make command.
In packages such as RPMs, and the tar.bz2 source tarball,
Makefile contains the contents of Makefile.ship. If Makefile.ship
is missing it has likely moved to replace Makefile.
In the calc GitHub repo, Makefile is the calc build environment
and Makefile.ship is the top level Makefile:
https://github.com/lcn2/calc
Makefile.ship
Makefile
# SRC: Makefile.ship - top level Makefile
@@ -334,16 +414,9 @@ Makefile.ship
...
#endif /* DO NOT DO THIS */
The custom/Makefile rule of Makefile.ship is used to form
the custom/Makefile. In particular the Makefile.ship lines:
# start of host target cut
... these go between custom/Makefile.head and custom/Makefile.tail
# end of host target cut
Makefile.simple
# SRC: non-GNU Makefile via make -f Makefile.ship Makefile.simple
# SRC: Makefile.simple - non-GNU version
This is a non-GNU or simple Makefile designed for environments
that do not have a modern make command.
@@ -370,36 +443,15 @@ Makefile.simple
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
custom/Makefile.head
# SRC: custom/Makefile.head
This file forms the top part of the custom/Makefile.
custom/Makefile.tail
# SRC: custom/Makefile.tail
This file forms the bottom part of the custom/Makefile.
custom/Makefile
# SRC: Makefile via make -f Makefile custom/Makefile
This is the custom directory Makefile.
The custom/Makefile rule of Makefile.ship is used to form
the custom/Makefile. In particular the Makefile.ship lines:
# start of host target cut
... these go in between custom/Makefile.head and custom/Makefile.tail
# end of host target cut
NOTE: The clobber rule does not remove this file. - XXX
custom/Makefile.simple
# SRC: non-GNU Makefile via make -f Makefile custom/Makefile.simple
# SRC: custom/Makefile.simple - non-GNU version
This is a non-GNU or simple Makefile for the custom directory
that is designed for environments that do not have a modern make

7516
Makefile

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1,39 @@
# Add below to override Makefile values (using :=) as in: HAVE_STRING_H:= YES
#
# Makefile.local - local Makefile variables
#
# This file is included by Makefile after the last Makefile is set and
# before the first make rule. This makes this file suitable to override
# Makefile variables.
#
# To replace a Makefile variable, use := symbols. For example:
#
# CCWERR:= -Werror
###################################################################
# NOTE: For this and other commended out examples in this file, #
# you need to remove the leading '#<whitespaces>' to take effect. #
# #
# Comments start with a #-character. #
###################################################################
# You can append to an existing Makefile variable using '+=' symbols.
# For example:
#
# CFLAGS+= -Ofast
# For example, a AddressSanitizer. You do NOT want to do this by
# by default! Do this only if you are debugging with libasan:
#
# For Linux gcc version 4.8.5 with libasan-4.8.5-4 you might try:
#
# CDEBUG:= -O0 -g
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
#
# For macOS 12.1 with clang version 13.0.0 (clang-1300.0.29.30) you might try:
#
# CDEBUG:= -O0 -g
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

117
README.RELEASE Normal file
View File

@@ -0,0 +1,117 @@
On calc versions and releases
Calc version numbers have 4 levels. For example:
++=== top 2 levels: calc builtin functions compatibility
||
vvvv
2.14.0.8
\\\\\\
^ \\\\----> top 3 levels: calc important code base change
|
+--- top version level: internal representation compatibility
The top version level (e.g., 2) refers to the internal representation
of values. Any library or hardware linked/built for calc 2 will be able
to use values from other 2.x.y.z versions.
The top 2 levels (e.g., 2.14) refers to a specific compatible set of
builtin functions. Calc interpreted code (such as calc resource files)
written for, say calc 2.14, will be able to use the same set of builtin
functions for any other 2.14.y.z version. Any new builtin functions or
significant changes to existing builtin functions would be introduced in
a later release such as version 2.15.y.z. While calc scripts written for
2.14.y.z will highly likely be able to run under version 2.15.y.z, any
new builtin functions added in calc 2.15 may collide with an identically
named used defined function.
The top 3 levels (e.g., 2.14.0) change to reflect an important change to
the code base such as a bug fix or performance improvement. There was
neither a change to the internal representation format (a top level
version change), nor were there new calc builtins introduced in such
a top 3 level release.
There are 3 classes of changes to the calc source tree:
alpha => untagged GitHub commit
Any untagged commit to the GitHub master branch should be
considered as alpha code that may make calc unstable.
While we try to avoid breaking the calc code with commits,
there is a risk that picking up such a change could
negatively impact the code.
tested => tagged GitHub pre-release commit
A new version of calc has been released and has recently passed
regression testing on at least to different platforms and chip
architectures.
The "tested" class was historically called "untested",
however this term was misleading as such releases ARE tested.
Since 2.14.0.13 we have used the term "tested".
All tested releases are tagged with a new version number.
Such releases have GitHub assets such as a source tarball,
zip file, source rpm, development rpm and binary rpm. See the
orange "Pre-release" GitHub releases under:
https://github.com/lcn2/calc/releases
At the bottom of a given release is a "> Assets" that may
be opened to reveal down-loadable files.
production => tagged GitHub release commit
A new version of calc has been released and has undergone
extensive testing over time over a number of platforms.
Sometimes a "tested" release that is found work well over
a period of time will be re-released with a new version
number as a "production" release.
The latest production GitHub release is marked with green
"Latest" label under:
https://github.com/lcn2/calc/releases
A release that has neither an orange "Pre-release" nor
a green "Latest" label is a prior production class release.
At the bottom of a given release is a "> Assets" that may
be opened to reveal down-loadable files.
Production class code where stability is critical should use a
"production" release.
A historical note and apology:
In the past, some version number changes were made that did not fully
reflect the above version number or change class. Moreover older terms
such as "stable" and "unstable" were misleading and did not properly
reflect the nature of the change. Sorry! The purpose of this document
is to try and bring a better level of conformity to source code updates,
tagged releases and version numbers.
## 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/12/12 19:36:26
## 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/

View File

@@ -3,16 +3,8 @@ Dear calc user on a Windows based system,
See the HOWTO.INSTALL file for information on how to build and install calc.
See also the README file.
BTW: While we are unable to use Windows 11, we welcome
Windows 11 developers to try compiling calc natively
(instead of via a Linux virtual machine). If you are
able to compile Windows 11 natively, we would welcome
GitHub pull requests showing any needed modifications:
https://github.com/lcn2/calc/pulls
Please also add notes to the 'Compiling calc under Windows 11'
section in README.WINDOWS file.
and 'Compiling with Cygwin' section in README.WINDOWS file.
NOTE: The main developers do not have access to a Windows based platform.
While we will make an effort to not break calc Windows based system,
@@ -21,81 +13,99 @@ NOTE: The main developers do not have access to a Windows based platform.
Of course you are welcome to send us any patches that fix your
Windows build environment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= Compiling calc under Windows 11 =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BTW: While we are unable to use Windows 11, we welcome Windows 11
developers to try compiling calc natively (instead of via a Linux
virtual machine). If you are able to compile Windows 11 natively,
we would welcome GitHub pull requests showing any needed modifications:
https://github.com/lcn2/calc/pulls
We were given this advice from a Windows 11 developer:
Windows 11 users should try:
Windows 11 users could use Cygwin:
https://git-scm.com/downloads
https://cygwin.com/install.html
When you run the installer wizard, make sure you choose/check
the git bash installer option.
IMPORTANT: While installing Cygwin, and during Cygwin Setup, be sure to
select all the MinGW64 packages relating to gcc.
https://www.mingw-w64.org/
See the "Compiling with Cygwin" section below.
Runtime environment for GCC & LLVM for 32 and 64 bit Windows
NOTE: Compiling calc under Windows 11 is work in progress. If you run into
problems, consider the "Compiling with Cygwin" section below.
We suggest Windows 11 users consider using MINGW64.
We would prefer a Windows 11 solution that does not require a Windows 11
developer to install a Linux virtual machine. Nevertheless, a Windows 11
user might want to use the Microsoft Windows Subsystem (WSL) for Linux:
https://docs.microsoft.com/en-us/windows/wsl/
We have been told that you will need to turn on virtualization
to use this WSL subsystem.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= Compiling calc under Windows 10 via Windows Subsystem for Linux (WSL) =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
It has been reported that calc version 2.12.6.4 has been successfully
compiled, installed and running on Windows 10 on 2018 Jan 21.
We were told:
"The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that
enables you to run native Linux command-line tools directly on Windows"
https://docs.microsoft.com/cs-cz/windows/wsl/about
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling with Cygwin =-=
=-= Compiling with Cygwin =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
An effort is being made to allow windows users to compile calc using the
Cygwin project (http://sources.redhat.com/cygwin/) with the GCC compiler
and Un*x tools for Windows.
and Unix tools for Windows.
The major porting work for Cygwin was performed by Thomas Jones-Low
(tjoneslo at softstart dot com).
In March 2009, Michael Penk (mpenk at wuska dot com) reported success in
installs under Cygwin:
In December 2022, GitHub user @Leoongithub successfully compiled
calc-2.14.1.2 under cygwin 2.924 (64 bit). The following are the
compilation steps that GitHub user @Leoongithub recommends:
On my fairly complete Cygwin installs, everything compiles,
checks, and installs correctly. My Cygwin is configured
in a very standard way (out of the box, using all of Cygwin's
defaults). The install worked on 5 different machines with
Cygwin on them: one XP home, one XP professional, and three
Vista professionals.
0. Install the latest version of cygwin (https://cygwin.com/install.html).
Using the calc Makefile, he did the following:
NOTE: In addition to the default packages, you also need to check these
three packages: gcc-core, make, and libreadline-devel. The version
of these packages does not matter. Just choose the latest version.
make all target=Cygwin
make check
make install
NOTE: The addition of "target=Cygwin" to make commands below
is done just in case the target is not set properly by make.
He also reports:
1. Change (cd) into the top of the source code directory of calc.
Of course, one should be logged in as an Administrator when
one builds and installs calc.
NOTE: The make command assume you are at the top of the calc source directory.
2. make clobber target=Cygwin
NOTE: This helps ensure that you are starting from a so-called "clean slate",
and that you have nothing hanging around from previous attempts to compile.
3. make all target=Cygwin
NOTE: If successful, you should have a calc executable. However that executable
may not be working properly. Advance to step (4) to test.
4. make chk target=Cygwin
NOTE: If you want this command be be verbose, try:
make check target=Cygwin
NOTE: This will run calc with the regress.cal regression suite. This step could take
for a while to run, depending on the speed/performance of your machine.
If all is well (all regression tests pass), you will see at the end:
chk OK
Otherwise you may see calc exit non-zero after it prints some lines with '****'
error messages followed by a line including a final error count of the form:
**** 2 error(s) found \/++\/
If you see some errors that may relate to files and I/O, all may not be lost.
It could simply mean that your Windows environment is not conforming to standard
I/O and file operations. The calc mathematical engine may be just fine. On the
other hand if you see mathematical related regression test failures, this is
bad sign that your calc executable under Windows is not usable.
5. make install target=Cygwin
NOTE: This step is optional. While calc is usable at the top of the source code directory
of calc, installing calc may be of benefit so you can use calc elsewhere on your system.
He was compiling calc 2.12.4.0 with Cygwin version 1.5.25-15.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= If all else fails, for Cygwin =-=
@@ -120,6 +130,10 @@ In particular:
source directory, edit them (if needed) and build using the
Cygwin GCC compiler and Cygwin build environment.
NOTE: The use of win32_hsrc and this method has been deprecated.
It may go away once the Windows 11 methods are stable.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling under DJGPP =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -180,8 +194,43 @@ Look for Makefile comments of the form:
Follow those recommendations. In cases where they conflict with
the above Makefile list, follow the recommendation in the Makefile.
NOTE: The use of DJGPP and this method has been deprecated.
It may go away once the Windows 11 methods are stable.
## Copyright (C) 2002-2009,2021 Landon Curt Noll and Thomas Jones-Low
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= Compiling calc via virtual machine under Windows 11 =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
We would prefer a Windows 11 solution that does not require a Windows 11
developer to install a Linux virtual machine. Nevertheless, a Windows 11
user might want to use the Microsoft Windows Subsystem (WSL) for Linux:
https://docs.microsoft.com/en-us/windows/wsl/
We have been told that you will need to turn on virtualization
to use this WSL subsystem.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= Compiling calc under Windows 10 via Windows Subsystem for Linux (WSL) =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
It has been reported that calc version 2.12.6.4 has been successfully
compiled, installed and running on Windows 10 on 2018 Jan 21.
We were told:
"The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that
enables you to run native Linux command-line tools directly on Windows"
https://docs.microsoft.com/cs-cz/windows/wsl/about
NOTE: The use of calc under Windows 10 has been deprecated in favor of one
of the Windows 11 methods above.
## Copyright (C) 2002-2009,2021,2022 Landon Curt Noll and Thomas Jones-Low
##
## 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

View File

@@ -6,9 +6,14 @@ The most recent version of calc is supported with security updates.
If the most recent stable of calc is also supported with security updates.
## Reporting a Vulnerability
To report a vulnerability, please review the BUGS file, or enter
the calc command:
FYI: please review the BUGS file, or enter the calc command:
; help BUGS
## Reporting a Vulnerability
Please create a calc GitHub repo issue:
https://github.com/lcn2/calc/issues
Click on ((New issue)) and follow the issue template.

21
addop.c
View File

@@ -1,7 +1,7 @@
/*
* addop - add opcodes to a function being compiled
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -37,6 +37,7 @@
#include "symbol.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -68,12 +69,12 @@ initfunctions(void)
functemplate = (FUNC *) malloc(funcsize(maxopcodes));
if (functemplate == NULL) {
math_error("Cannot allocate function template");
/*NOTREACHED*/
not_reached();
}
functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
if (functions == NULL) {
math_error("Cannot allocate function table");
/*NOTREACHED*/
not_reached();
}
funccount = 0;
funcavail = FUNCALLOCSIZE;
@@ -155,7 +156,7 @@ beginfunc(char *name, BOOL newflag)
fp = (FUNC *) malloc(funcsize(maxopcodes));
if (fp == NULL) {
math_error("Cannot allocate temporary function");
/*NOTREACHED*/
not_reached();
}
}
fp->f_next = NULL;
@@ -203,7 +204,7 @@ endfunc(void)
fp = (FUNC *) malloc(size);
if (fp == NULL) {
math_error("Cannot commit function");
/*NOTREACHED*/
not_reached();
}
memcpy((char *) fp, (char *) curfunc, size);
if (curfunc != functemplate)
@@ -257,13 +258,13 @@ adduserfunc(char *name)
sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE));
if (functions == NULL) {
math_error("Failed to reallocate function table");
/*NOTREACHED*/
not_reached();
}
funcavail += FUNCALLOCSIZE;
}
if (addstr(&funcnames, name) == NULL) {
math_error("Cannot save function name");
/*NOTREACHED*/
not_reached();
}
index = funccount++;
functions[index] = NULL;
@@ -316,7 +317,7 @@ freefunc(FUNC *fp)
}
if (index == funccount) {
math_error("Bad call to freefunc!!!");
/*NOTREACHED*/
not_reached();
}
}
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
@@ -386,7 +387,7 @@ findfunc(long index)
{
if (index >= funccount) {
math_error("Undefined function");
/*NOTREACHED*/
not_reached();
}
return functions[index];
}
@@ -438,7 +439,7 @@ addop(long op)
fp = (FUNC *) malloc(funcsize(maxopcodes));
if (fp == NULL) {
math_error("cannot malloc function");
/*NOTREACHED*/
not_reached();
}
memcpy((char *) fp, (char *) curfunc,
funcsize(curfunc->f_opcodecount));

View File

@@ -27,6 +27,11 @@
#include <stdio.h>
#include <signal.h>
#include "have_stdlib.h"
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif
#include "longbits.h"
#include "have_unistd.h"
@@ -34,11 +39,13 @@
#include <unistd.h>
#endif
#include "have_unused.h"
#include "banned.h" /* include after system header <> includes */
static void buserr(void); /* catch alignment errors */
static void buserr(int arg); /* catch alignment errors */
int
@@ -46,7 +53,7 @@ main(void)
{
char byte[2*sizeof(USB32)]; /* mis-alignment buffer */
USB32 *p; /* mis-alignment pointer */
int i;
unsigned long i;
#if defined(MUST_ALIGN32)
/* force alignment */
@@ -82,7 +89,7 @@ main(void)
*/
/*ARGSUSED*/
static void
buserr(int arg)
buserr(int UNUSED(arg))
{
/* alignment is required */
printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",

View File

@@ -1,7 +1,7 @@
/*
* assocfunc - association table routines
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,7 @@
#include "value.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -74,7 +75,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
if (dim < 0) {
math_error("Negative dimension for indexing association");
/*NOTREACHED*/
not_reached();
}
/*
@@ -112,7 +113,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
ep = (ASSOCELEM *) malloc(ELEMSIZE(dim));
if (ep == NULL) {
math_error("Cannot allocate association element");
/*NOTREACHED*/
not_reached();
}
ep->e_dim = dim;
ep->e_hash = hash;
@@ -142,13 +143,13 @@ assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > ap->a_count) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
while (i < j) {
ep = elemindex(ap, i);
if (ep == NULL) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
utoz(i, index);
@@ -172,14 +173,14 @@ assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > ap->a_count) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
j--;
while (j >= i) {
ep = elemindex(ap, j);
if (ep == NULL) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
utoz(j, index);
@@ -333,7 +334,7 @@ assoccopy(ASSOC *oldap)
if (ep == NULL) {
math_error("Cannot allocate "
"association element");
/*NOTREACHED*/
not_reached();
}
ep->e_dim = oldep->e_dim;
ep->e_hash = oldep->e_hash;
@@ -374,7 +375,7 @@ resize(ASSOC *ap, long newsize)
newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize);
if (newtable == NULL) {
math_error("No memory to grow association");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < newsize; i++)
newtable[i] = NULL;
@@ -430,7 +431,7 @@ assocalloc(long initsize)
ap = (ASSOC *) malloc(sizeof(ASSOC));
if (ap == NULL) {
math_error("No memory for association");
/*NOTREACHED*/
not_reached();
}
ap->a_count = 0;
ap->a_size = initsize;
@@ -438,7 +439,7 @@ assocalloc(long initsize)
if (ap->a_table == NULL) {
free((char *) ap);
math_error("No memory for association");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < initsize; i++)
ap->a_table[i] = NULL;

69
attribute.h Normal file
View File

@@ -0,0 +1,69 @@
/*
* attribute - control use of attributes in a backward compatible way
*
* Copyright (C) 2022 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: 2022/01/21 22:51:25
* File existed as early as: 2022
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(INCLUDE_ATTRIBUTE_H)
#define INCLUDE_ATTRIBUTE_H
/*
* backward compatibility
*
* Not all compilers support __attribute__ nor do they suuport __has_builtin.
* For example, MSVC, TenDRAm and Little C Compiler doesn't support __attribute__.
* Early gcc does not support __attribute__.
*
* Not all compiles have __has_builtin
*/
#if !defined(__attribute__) && \
(defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
# define __attribute__(A)
#endif
#if !defined __has_builtin
# define __has_builtin(x) 0
#endif
/*
* not_reached
*
* In the old days of lint, one could give lint and friends a hint by
* placing the token NOTREACHED immediately between opening and closing
* comments. Modern compilers do not honor such commented tokens
* and instead rely on features such as __builtin_unreachable
* and __attribute__((noreturn)).
*
* The not_reached will either yield a __builtin_unreachable() feature call,
* or it will call abort from stdlib.
*/
#if __has_builtin(__builtin_unreachable)
# define not_reached() __builtin_unreachable()
#else
# define not_reached() abort()
#endif /* __has_builtin(__builtin_unreachable) */
#endif /* !INCLUDE_ATTRIBUTE_H */

View File

@@ -1,7 +1,7 @@
/*
* blkcpy - general values and related routines used by the calculator
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
*
* Primary author: Landon Curt Noll
*
@@ -36,6 +36,7 @@
#include "str.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -298,7 +299,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for mat-to-mat copy");
/*NOTREACHED*/
not_reached();
}
vp = smat->m_table + ssi;
vq = vtemp;
@@ -347,7 +348,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for block-to-matrix copy");
/*NOTREACHED*/
not_reached();
}
vp = vtemp;
i = num;
@@ -404,7 +405,7 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for matrix-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -447,7 +448,7 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for matrix-to-list copy");
/*NOTREACHED*/
not_reached();
}
vp = smat->m_table + ssi;
vq = vtemp;
@@ -497,7 +498,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for list-to-matrix copy");
/*NOTREACHED*/
not_reached();
}
ep = listelement(lp, (long) ssi);
vp = vtemp;
@@ -547,7 +548,7 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for list-to-list copy");
/*NOTREACHED*/
not_reached();
}
sep = listelement(slp, (long) ssi);
vp = vtemp;
@@ -662,7 +663,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for block-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -748,7 +749,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for block-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -792,7 +793,7 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for string-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -913,7 +914,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for string-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -945,7 +946,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
*/
if (s1 == NULL || s2 == NULL) {
math_error("bogus memmove NULL ptr");
/*NOTREACHED*/
not_reached();
}
if (n <= 0) {
/* neg or 0 count does nothing */
@@ -1015,7 +1016,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for num-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -1086,7 +1087,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
swapped = (HALF *)malloc(halflen * sizeof(HALF));
if (swapped == NULL) {
math_error("Out of memory for block-to-num copy");
/*NOTREACHED*/
not_reached();
}
/* ensure that any trailing octets will be zero filled */
swapped[halflen-1] = 0;

39
block.c
View File

@@ -1,7 +1,7 @@
/*
* block - fixed, dynamic, fifo and circular memory blocks
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
*
* Primary author: Landon Curt Noll
*
@@ -42,6 +42,7 @@
#include "calcerr.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -87,7 +88,7 @@ blkalloc(int len, int chunk)
nblk = (BLOCK *)malloc(sizeof(BLOCK));
if (nblk == NULL) {
math_error("cannot allocate block");
/*NOTREACHED*/
not_reached();
}
/*
@@ -98,7 +99,7 @@ blkalloc(int len, int chunk)
nblk->data = (USB8*)malloc(nblk->maxsize);
if (nblk->data == NULL) {
math_error("cannot allocate block data storage");
/*NOTREACHED*/
not_reached();
}
memset(nblk->data, 0, nblk->maxsize);
nblk->datalen = len;
@@ -172,7 +173,7 @@ blkchk(BLOCK *blk)
}
if (blk == NULL) {
math_error("internal: blk ptr is NULL");
/*NOTREACHED*/
not_reached();
}
/*
@@ -180,7 +181,7 @@ blkchk(BLOCK *blk)
*/
if (blk->data == NULL) {
math_error("internal: blk->data ptr is NULL");
/*NOTREACHED*/
not_reached();
}
/*
@@ -188,7 +189,7 @@ blkchk(BLOCK *blk)
*/
if (blk->datalen < 0) {
math_error("internal: blk->datalen < 0");
/*NOTREACHED*/
not_reached();
}
/*
@@ -196,7 +197,7 @@ blkchk(BLOCK *blk)
*/
if (blk->datalen < 0) {
math_error("internal: blk->datalen < 0");
/*NOTREACHED*/
not_reached();
}
return;
}
@@ -259,7 +260,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
nblk = (USB8*)realloc(blk->data, newmax);
if (nblk == NULL) {
math_error("cannot reallocate block storage");
/*NOTREACHED*/
not_reached();
}
/* clear any new storage */
@@ -367,7 +368,7 @@ blktrunc(BLOCK *blk)
blk->data = (USB8*)malloc(1);
if (blk->data == NULL) {
math_error("cannot allocate truncated block storage");
/*NOTREACHED*/
not_reached();
}
blk->data[0] = (USB8)0;
if (conf->calc_debug & CALCDBG_BLOCK) {
@@ -397,7 +398,7 @@ blk_copy(BLOCK *blk)
nblk = (BLOCK *)malloc(sizeof(BLOCK));
if (nblk == NULL) {
math_error("blk_copy: cannot malloc BLOCK");
/*NOTREACHED*/
not_reached();
}
/*
@@ -411,7 +412,7 @@ blk_copy(BLOCK *blk)
nblk->data = (USB8 *)malloc(blk->maxsize);
if (nblk->data == NULL) {
math_error("blk_copy: cannot duplicate block data");
/*NOTREACHED*/
not_reached();
}
memcpy(nblk->data, blk->data, blk->maxsize);
return nblk;
@@ -539,7 +540,7 @@ reallocnblock(int id, int len, int chunk)
/* Fire wall */
if (id < 0 || id >= nblockcount) {
math_error("Bad id in call to reallocnblock");
/*NOTREACHED*/
not_reached();
}
blk = nblocks[id]->blk;
@@ -556,13 +557,13 @@ reallocnblock(int id, int len, int chunk)
newdata = malloc(newsize);
if (newdata == NULL) {
math_error("Allocation failed");
/*NOTREACHED*/
not_reached();
}
} else if (newsize != oldsize) {
newdata = realloc(blk->data, newsize);
if (newdata == NULL) {
math_error("Reallocation failed");
/*NOTREACHED*/
not_reached();
}
}
memset(newdata + len, 0, newsize - len);
@@ -593,7 +594,7 @@ createnblock(char *name, int len, int chunk)
if (nblocks == NULL) {
maxnblockcount = 0;
math_error("unable to malloc new named blocks");
/*NOTREACHED*/
not_reached();
}
} else {
maxnblockcount += NBLOCKCHUNK;
@@ -602,7 +603,7 @@ createnblock(char *name, int len, int chunk)
if (nblocks == NULL) {
maxnblockcount = 0;
math_error("cannot malloc more named blocks");
/*NOTREACHED*/
not_reached();
}
}
}
@@ -610,18 +611,18 @@ createnblock(char *name, int len, int chunk)
initstr(&nblocknames);
if (findstr(&nblocknames, name) >= 0) {
math_error("Named block already exists!!!");
/*NOTREACHED*/
not_reached();
}
newname = addstr(&nblocknames, name);
if (newname == NULL) {
math_error("Block name allocation failed");
/*NOTREACHED*/
not_reached();
}
res = (NBLOCK *) malloc(sizeof(NBLOCK));
if (res == NULL) {
math_error("Named block allocation failed");
/*NOTREACHED*/
not_reached();
}
nblocks[nblockcount] = res;

View File

@@ -1,7 +1,7 @@
/*
* byteswap - byte swapping routines
*
* Copyright (C) 1999,2021 Landon Curt Noll
* Copyright (C) 1999,2021,2022 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
@@ -29,6 +29,7 @@
#include "byteswap.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -39,7 +40,7 @@
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
@@ -103,7 +104,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
if (dest == NULL) {
math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: "
"Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -170,7 +171,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_b8_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -234,7 +235,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_b8_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -275,7 +276,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
@@ -308,6 +309,50 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
}
/*
* swap_HALFs - swap HALFs in an array of HALFs
*
* given:
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
*/
HALF *
swap_HALFs(HALF *dest, HALF *src, LEN len)
{
HALF *s; /* src swap pointer */
HALF *d; /* dest swap pointer */
HALF *ret;
LEN i;
/*
* allocate storage if needed
*/
if (dest == NULL) {
dest = alloc(len);
}
ret = dest;
/*
* swap HALFs in the array
*/
s = src;
d = &dest[len-1];
for (i=0; i < len; ++i, --d, ++s) {
*d = *s;
}
/*
* return the result
*/
return ret;
}
/*
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
*
@@ -338,7 +383,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
dest = malloc(sizeof(ZVALUE));
if (dest == NULL) {
math_error("swap_b16_in_ZVALUE: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -405,7 +450,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_b16_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -469,7 +514,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_b16_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -530,10 +575,10 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
/*
* allocate the storage
*/
dest = malloc(sizeof(ZVALUE));
dest = calloc(1, sizeof(ZVALUE));
if (dest == NULL) {
math_error("swap_HALF_in_ZVALUE: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -601,7 +646,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_HALF_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -665,7 +710,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_HALF_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -2,7 +2,7 @@
#
# cal - makefile for calc standard resource files
#
# Copyright (C) 1999-2006,2017,2021 Landon Curt Noll
# Copyright (C) 1999-2006,2017,2021,2022 Landon Curt Noll
#
# SRC: cal/Makefile
#
@@ -106,15 +106,6 @@ PREFIX= /usr/local
#
MAKE_FILE= Makefile
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# Where the system include (.h) files are kept
#
# For DJGPP, select:
@@ -276,9 +267,9 @@ TRUE= true
#
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 \
comma.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 \
palindrome.cal pell.cal pi.cal pix.cal pollard.cal poly.cal prompt.cal \
psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
@@ -302,6 +293,10 @@ DISTLIST= ${CALC_FILES} ${MAKE_FILE}
# These files are used to make (but not built) a calc .a link library
#
CALCLIBLIST=
#
# rules that are not also names of files
#
PHONY= all clobber distlist install
all: ${CALC_FILES} ${MAKE_FILE} .all
@@ -311,6 +306,8 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
${RM} -f .all
${TOUCH} .all
.PHONY: ${PHONY}
##
#
# File list generation. You can ignore this section.

View File

@@ -263,6 +263,64 @@ chrem.cal
Chinese remainder theorem/problem solver.
comma.cal
Convert numbers into strings with 3-digit group and integer-fraction
separators.
If the value is an integer, the integer-fraction separator is not used.
str_comma(x, [group, [decimal]])
Convert x into a string.
If group is given and is a string, group will be used as
the 3-digit group separator, otherwise the default 3-digit
group separator will be used.
If decimal is given and is a string, group will be used as
the integer-fraction separator, otherwise the default
integer-fraction separator will be used.
The decimal and group arguments are optional.
set_default_group_separator(group)
Change the default 3-digit group separator if group is a string,
otherwise the default 3-digit group separator will not be
changed. Return the old 3-digit group separator.
set_default_decimal_separator(decimal)
Change the default 3-digit group separator if decimal is a
string, otherwise the default integer-fraction separator
will not be changed. Return the old integer-fraction separator.
print_comma(x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]])
followed by a newline.
If the str_comma() does not return a string, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
fprint_comma(fd, x, [group, [decimal]])
Print the value produced by str_comma(x, [group, [decimal]]),
without a trailing newline, on file fd.
If the str_comma() does not return a string, nothing is printed.
If fd is not an open file, nothing is printed.
The decimal and group arguments are optional.
The value produced by str_comma() is returned.
deg.cal
deg(deg, min, sec)

437
cal/comma.cal Normal file
View File

@@ -0,0 +1,437 @@
/*
* comma - convert numbers into strings with 3-digit group and integer-fraction separators
*
* Convert numbers into strings with 3-digit group and integer-fraction separators.
*
* If the value is an integer, the integer-fraction separator is not used.
*
* str_comma(x, [group, [decimal]])
*
* Convert x into a string.
*
* If group is given and is a string, group will be used as
* the 3-digit group separator, otherwise the default 3-digit
* group separator will be used.
*
* If decimal is given and is a string, group will be used as
* the integer-fraction separator, otherwise the default
* integer-fraction separator will be used.
*
* The decimal and group arguments are optional.
*
* set_default_group_separator(group)
*
* Change the default 3-digit group separator if group is a string,
* otherwise the default 3-digit group separator will not be
* changed. Return the old 3-digit group separator.
*
* set_default_decimal_separator(decimal)
*
* Change the default 3-digit group separator if decimal is a
* string, otherwise the default integer-fraction separator
* will not be changed. Return the old integer-fraction separator.
*
* print_comma(x, [group, [decimal]])
*
* Print the value produced by str_comma(x, [group, [decimal]])
* followed by a newline.
*
* If the str_comma() does not return a string, nothing is printed.
*
* The decimal and group arguments are optional.
*
* The value produced by str_comma() is returned.
*
* fprint_comma(fd, x, [group, [decimal]])
*
* Print the value produced by str_comma(x, [group, [decimal]]),
* without a trailing newline, on file fd.
*
* If the str_comma() does not return a string, nothing is printed.
*
* If fd is not an open file, nothing is printed.
*
* The decimal and group arguments are optional.
*
* The value produced by str_comma() is returned.
*
* Copyright (C) 2022 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: 2022/06/20 15:51:49
* File existed as early as: 2022
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
static default_group_separator = ","; /* default 3-digit group separator */
static default_decimal_separator = "."; /* default integer-fraction separator */
/*
* str_comma - convert number into base 10 string with 3-digit groups and integer-fraction separator
*
*
* This function converts a real number into a base 10 string, where
* groups of 3 digits are separated by a 3-digit group separator and
* a integer-fraction separator is printed between integer and decimal fraction.
*
* For example:
*
* string = str_comma(x);
* string = str_comma(x), " ", ".");
* string = str_comma(x), ".", ",");
*
* Internally the function calls:
*
* strprintf("%f", x);
*
* and thus the number of decimal fraction digits is subject to
* the display() or config("display") value. See:
*
* man display
*
* for details.
*
* given:
*
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and decimal separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define str_comma(x, group, decimal)
{
local group_separator; /* 3-digit group separator */
local decimal_separator; /* separator between decimal integer and decimal fraction */
local sign_str; /* leading - if x < 0 or empty if x >= 0 */
local integer; /* integer part of absolute value of x */
local int_str; /* integer as a string */
local int_len; /* number of digits in int_str */
local first_group_len; /* length of 1st group before the 1st 3-digit group separator */
local fraction; /* factional part of absolute value of x */
local frac_str; /* fraction as a string */
local frac_len; /* number of digits in frac_str including leading 0. */
local ret; /* string to return */
local config_leadzero; /* config("leadzero") to restore */
local config_tilde; /* config("tilde") to restore */
local i;
/*
* parse args - return null if args are bogus
*
* Return null() if args or conditions are bogus.
*/
if (!isreal(x)) {
return null();
}
group_separator = isnull(group) ? default_group_separator : group;
decimal_separator = isnull(decimal) ? default_decimal_separator : decimal;
if (!isstr(group_separator)) {
return null();
}
if (!isstr(decimal_separator)) {
return null();
}
/*
* split number
*/
if (x < 0) {
sign_str = "-";
integer = int(-x);
fraction = frac(-x);
} else {
sign_str = "";
integer = int(x);
fraction = frac(x);
}
ret = sign_str;
/*
* convert digits
*
* Avoid printing ~ and leading zeros for factional part.
*/
int_str = strprintf("%d", integer);
config_leadzero = config("leadzero", 0);
config_tilde = config("tilde", 0);
frac_str = strprintf("%d", fraction);
config("leadzero", config_leadzero),;
config("tilde", config_tilde),;
/*
* determine number of digits in the integer part
*/
int_len = strlen(int_str);
frac_len = strlen(frac_str);
/*
* form integer part with group separators as needed
*/
/*
* case: integer is 3 or fewer digits
*/
if (integer < 1000) {
ret += int_str;
/*
* case: integer is 4 or more digits
*/
} else {
/*
* form a decimal string using group separators
*/
/*
* form the initial leading digits before 1st group separator
*/
first_group_len = int_len % 3;
if (first_group_len == 0) {
first_group_len = 3;
}
ret += substr(int_str, 1, first_group_len);
/*
* until end of digits, print group separator followed by 3 more digits
*/
for (i = first_group_len+1; i < int_len; i += 3) {
ret += group_separator + substr(int_str, i, 3);
}
}
/*
* form fractional part using decimal separator as needed
*/
/*
* case: x is an integer
*/
if (fraction == 0) {
/* no fraction, nothing more to do */
/*
* case: x is not an integer
*/
} else {
/*
* add integer-fraction separator
*/
ret += decimal_separator;
/*
* add remaining digits
*
* Skip over the leading 0. in frac_str
*/
ret += substr(frac_str, 2, frac_len-1);
}
/*
* All Done!!! -- Jessica Noll, Age 2
*/
return ret;
}
/*
* set_default_group_separator - change the default 3-digit group separator
*
* If group is not a string, then the default 3-digit group separator
* is not changed. Thus, this will only return the default 3-digit group separator:
*
* set_default_group_separator(null());
*
* given:
*
* group 3-digit group separator
*
* returns:
*
* previous 3-digit group separator value
*/
define set_default_group_separator(group)
{
local old_default_group_separator; /* previous default 3-digit group separator to return */
/*
* save current 3-digit group separator
*/
old_default_group_separator = default_group_separator;
/*
* change 3-digit group separator if group is a string
*/
if (isstr(group)) {
default_group_separator = group;
}
return old_default_group_separator;
}
/*
* set_default_decimal_separator - change the default integer-fraction separator
*
* If decimal is not a string, then the default integer-fraction separator
* is not changed. Thus, this will only return the integer-fraction separator:
*
* set_default_decimal_separator(null());
*
* given:
*
* decimal separator between decimal integer and decimal fraction (def: ".")
*
* returns:
*
* previous integer-fraction separator value
*/
define set_default_decimal_separator(decimal)
{
local old_default_decimal_separator; /* previous default integer-fraction separator */
/*
* save current integer-fraction separator
*/
old_default_decimal_separator = default_decimal_separator;
/*
* change 3-digit decimal integer-fraction if decimal is a string
*/
if (isstr(decimal)) {
default_decimal_separator = decimal;
}
return old_default_decimal_separator;
}
/*
* print_comma - print base 10 string with 3-digit group separators & integer-fraction separator + newline
*
* This function prints the result of str_comma(x, group, decimal) followed by a newline.
* For example:
*
* print_comma(x);
* print_comma(x), " ", ".");
* print_comma(x), ".", ",");
*
* If str_comma() does not return a string, this function prints nothing.
*
* NOTE: To print without a newline, use fprint_comma(fd, x, group, decimal).
*
* given:
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and decimal separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define print_comma(x, group, decimal)
{
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
/*
* convert to string
*/
ret = str_comma(x, group, decimal);
/*
* print converted string
*/
if (isstr(ret)) {
printf("%s\n", ret);
}
return ret;
}
/*
* fprint_comma - print base 10 string with 3-digit group separators & integer-fraction separator w/o newline
*
* This function prints the result of str_comma(x, group, decimal) on an open file, without a trailing newline.
* For example:
*
* fprint_comma(files(1), x);
* fprint_comma(fd, x), " ", ".");
* fprint_comma(files(2), x), ".", ",");
*
* If str_comma() does not return a string, this function prints nothing.
*
* This function flushes output to the open file before returning.
*
* NOTE: To print with a newline, use print_comma(x, group, decimal).
*
* given:
* fd open file
* x number to convert
*
* optional args:
*
* group use this 3-digit group separator
* decimal use this integer-fraction separator
*
* returns:
*
* string containing the base 10 digits with group and integer-fraction separators, OR
* null() if x is not a number, OR
* null() if group is neither null() (not given) nor a string, OR
* null() if group is null() (not given) AND default_group_separator is not a string, OR
* null() if decimal is neither null() (not given) nor a string, OR
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
*/
define fprint_comma(fd, x, group, decimal)
{
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
/*
* convert to string
*/
ret = str_comma(x, group, decimal);
/*
* print converted string
*/
if (isstr(ret) && isfile(fd)) {
fprintf(fd, "%s", ret);
fflush(fd);
}
return ret;
}

View File

@@ -305,6 +305,8 @@ print '008: parsed test_variables()';
*/
define test_arithmetic()
{
local x;
print '400: Beginning test_arithmetic';
vrfy(3+4==7, '401: 3 + 4 == 7');
@@ -366,8 +368,18 @@ define test_arithmetic()
vrfy((2^23209-1)^(2-2) == 1, '457: (2^23209-1)^(2-2) == 1');
vrfy((2^23209-1)^((2^23209-1)-(2^23209-1)) == 1,
'458: (2^23209-1)^((2^23209-1)-(2^23209-1)) == 1');
vrfy(0^2 == 0, '459: 0^2 == 0');
vrfy(0^3 == 0, '460: 0^3 == 0');
vrfy(0^12 == 0, '461: 0^12 == 0');
vrfy(0^13 == 0, '462: 0^13 == 0');
x = 0;
vrfy(x == 0, '463: x == 0');
vrfy(0^2 == 0, '464: 0^2 == 0');
vrfy(0^3 == 0, '465: 0^3 == 0');
vrfy(0^12 == 0, '466: 0^12 == 0');
vrfy(x^13 == 0, '467: x^13 == 0');
print '459: Ending test_arithmetic';
print '462: Ending test_arithmetic';
}
print '009: parsed test_arithmetic()';
@@ -529,7 +541,16 @@ define test_config()
vrfy(issimple(config("dupvar_warn")),
'562: issimple(config("rdupvar_warn"))');
print '563: Ending test_config';
/* test new space modes */
vrfy(config("tilde_space") == 0,
'563: config("tilde_space") == 0');
vrfy(config("fraction_space") == 0,
'564: config("fraction_space") == 0');
vrfy(config("complex_space") == 0,
'565: config("complex_space") == 0');
print '566: Ending test_config';
}
print '010: parsed test_config()';
@@ -3912,7 +3933,7 @@ define test_fileops()
vrfy(!iserror(p=fopen("tmp4200","r")),
'4274: !iserror(p=fopen("tmp4200","r"))');
vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))');
vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0');
vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0');
vrfy(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))');
vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0,
'4278: strcmp(s,"w\0a\0s\nhere\n") == 0');
@@ -4284,84 +4305,119 @@ define test_strprintf()
print '4804: c = config("display", 2)';
c = config("tilde", 0);
print '4805: c = config("tilde", 0)';
c = config("tilde_space", 1);
print '4806: c = config("tilde_space", 1)';
c = config("leadzero", 0);
print '4806: c = config("leadzero", 0)';
print '4807: c = config("leadzero", 0)';
c = config("fullzero", 0);
print '4807: c = config("fullzero", 0)';
print '4808: c = config("fullzero", 0)';
/* tests with tilde == 0 */
vrfy(strprintf("%d%d", 27, 29) == "2729",
'4808: strprintf("%d%d", 27, 29) == "2729"');
'4809: strprintf("%d%d", 27, 29) == "2729"');
vrfy(strprintf("%5d%3d", 27, 29) == " 27 29",
'4809: strprintf("%5d%3d", 27, 29) == " 27 29"; ');
'4810: strprintf("%5d%3d", 27, 29) == " 27 29"; ');
vrfy(strprintf("%-5d%-3d", 27, 29) == "27 29 ",
'4810: strprintf("%-5d%-3d", 27, 29) == "27 29 "');
'4811: strprintf("%-5d%-3d", 27, 29) == "27 29 "');
vrfy(strprintf("%f", 1.375) == "1.38",
'4811: strprintf("%f", 1.375) == "1.38"');
'4812: strprintf("%f", 1.375) == "1.38"');
vrfy(strprintf("%f", 1.385) == "1.38",
'4812: strprintf("%f", 1.385) == "1.38"');
'4813: strprintf("%f", 1.385) == "1.38"');
vrfy(strprintf("%f", .375) == ".38",
'4813: strprintf("%f", .375) == ".38"');
'4814: strprintf("%f", .375) == ".38"');
vrfy(strprintf("%f", .385) == ".38",
'4814: strprintf("%f", .385) == ".38"');
'4815: strprintf("%f", .385) == ".38"');
/* tests with tilde == 1 */
c = config("tilde", 1);
print '4815: c = config("tilde", 1)';
vrfy(strprintf("%f", 1.375) == "~1.38",
'4816: strprintf("%f", 1.375) == "~1.38"');
vrfy(strprintf("%f", 27/29) == "~.93",
'4817: strprintf("%f", 27/29) == "~.93"');
print '4816: c = config("tilde", 1)';
vrfy(strprintf("%f", 1.375) == "~ 1.38",
'4817: strprintf("%f", 1.375) == "~ 1.38"');
vrfy(strprintf("%f", 27/29) == "~ .93",
'4818: strprintf("%f", 27/29) == "~ .93"');
vrfy(strprintf("%r", 27/29) == "27/29",
'4818: strprintf("%r", 27/29) == "27/29"');
'4819: strprintf("%r", 27/29) == "27/29"');
vrfy(strprintf("%o", 27/29) == "033/035",
'4819: strprintf("%o", 27/29) == "033/035"');
'4820: strprintf("%o", 27/29) == "033/035"');
vrfy(strprintf("%x", 27/29) == "0x1b/0x1d",
'4820: strprintf("%x", 27/29) == "0x1b/0x1d"');
'4821: strprintf("%x", 27/29) == "0x1b/0x1d"');
vrfy(strprintf("%b", 27/29) == "0b11011/0b11101",
'4821: strprintf("%b", 27/29) == "0b11011/0b11101"');
'4822: strprintf("%b", 27/29) == "0b11011/0b11101"');
vrfy(strprintf("%e", 12345) == "~ 1.23e4",
'4823: strprintf("%e", 12345) == "~ 1.23e4"');
vrfy(strprintf("%g", .385) == "~ .38",
'4824: strprintf("%g", .385) == "~ .38"');
vrfy(strprintf("%g", 385) == "~ 3.8e2",
'4825: strprintf("%g", 385) == "~ 3.8e2"');
/* tests with tilde == 1 and tilde_space == 0 */
c = config("tilde_space", 0);
print '4826: c = config("tilde_space", 0)';
vrfy(strprintf("%f", 1.375) == "~1.38",
'4827: strprintf("%f", 1.375) == "~1.38"');
vrfy(strprintf("%f", 27/29) == "~.93",
'4828: strprintf("%f", 27/29) == "~.93"');
vrfy(strprintf("%e", 12345) == "~1.23e4",
'4822: strprintf("%e", 12345) == "~1.23e4"');
'4829: strprintf("%e", 12345) == "~1.23e4"');
vrfy(strprintf("%g", .385) == "~.38",
'4823: strprintf("%g", .385) == "~.38"');
'4830: strprintf("%g", .385) == "~.38"');
vrfy(strprintf("%g", 385) == "~3.8e2",
'4824: strprintf("%g", 385) == "~3.8e2"');
'4831: strprintf("%g", 385) == "~3.8e2"');
/* tests with tilde_space == 0 */
c = config("tilde_space", 1);
print '4832: c = config("tilde_space", 1)';
vrfy(strprintf("%f", 1.375) == "~ 1.38",
'4833: strprintf("%f", 1.375) == "~ 1.38"');
vrfy(strprintf("%f", 27/29) == "~ .93",
'4834: strprintf("%f", 27/29) == "~ .93"');
vrfy(strprintf("%e", 12345) == "~ 1.23e4",
'4835: strprintf("%e", 12345) == "~ 1.23e4"');
vrfy(strprintf("%g", .385) == "~ .38",
'4836: strprintf("%g", .385) == "~ .38"');
vrfy(strprintf("%g", 385) == "~ 3.8e2",
'4837: strprintf("%g", 385) == "~ 3.8e2"');
/* mode tests with tilde == 0 */
c = config("tilde", 0);
print '4825: c = config("tilde", 0)';
print '4838: c = config("tilde", 0)';
vrfy(strprintf("%e", 12345) == "1.23e4",
'4826: strprintf("%e", 12345) == "1.23e4"');
'4839: strprintf("%e", 12345) == "1.23e4"');
vrfy(strprintf("%.3e", 12345) == "1.234e4",
'4827: strprintf("%.3e", 12345) == "1.234e4"');
'4840: strprintf("%.3e", 12345) == "1.234e4"');
vrfy(strprintf("%e", .00012345) == "1.23e-4",
'4828: strprintf("%e", .00012345) == "1.23e-4"');
'4841: strprintf("%e", .00012345) == "1.23e-4"');
vrfy(strprintf("%d %d", 27) == "27 ",
'4829: strprintf("%d %d", 27) == "27 "');
'4842: strprintf("%d %d", 27) == "27 "');
vrfy(strprintf("%d", 27, 29) == "27",
'4830: strprintf("%d", 27, 29) == "27"');
'4843: strprintf("%d", 27, 29) == "27"');
vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93",
'4831: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"');
'4844: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"');
vrfy(strprintf("%s", "abc") == "abc",
'4832: strprintf("%s", "abc") == "abc"');
'4845: strprintf("%s", "abc") == "abc"');
vrfy(strprintf("%f", "abc") == "abc",
'4833: strprintf("%f", "abc") == "abc"');
'4846: strprintf("%f", "abc") == "abc"');
vrfy(strprintf("%e", "abc") == "abc",
'4834: strprintf("%e", "abc") == "abc"');
'4847: strprintf("%e", "abc") == "abc"');
vrfy(strprintf("%5s", "abc") == " abc",
'4835: strprintf("%5s", "abc") == " abc"');
'4848: strprintf("%5s", "abc") == " abc"');
vrfy(strprintf("%-5s", "abc") == "abc ",
'4836: strprintf("%-5s", "abc") == "abc "');
'4849: strprintf("%-5s", "abc") == "abc "');
vrfy(strprintf("%g", .385) == ".38",
'4837: strprintf("%g", .385) == ".38"');
'4850: strprintf("%g", .385) == ".38"');
vrfy(strprintf("%g", 385) == "3.8e2",
'4838: strprintf("%g", 385) == "3.8e2"');
'4851: strprintf("%g", 385) == "3.8e2"');
c = config("fraction_space", 1);
print '4852: c = config("fraction_space", 1)';
vrfy(strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93",
'4853: strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93"');
/* restore config */
c = config("all", callcfg);
print '4839: c = config("all", callcfg)';
print '4854: c = config("all", callcfg)';
print '4840: Ending test_strprintf';
print '4855: Ending test_strprintf';
}
print '088: parsed test_fileop()';
@@ -8117,7 +8173,7 @@ vrfy(config("redecl_warn",0), '8651: config("redecl_warn",0)');
vrfy(config("dupvar_warn",0), '8652: config("dupvar_warn",0)');
vrfy(u_glob == 6, '8653: u_glob == 6');
global u_glob = 555;
print '8654: declare u_glob';
print '8654: declare u_glob';
vrfy(u_glob == 555, '8655: u_glob == 555');
define func_8650(u_glob) { local u_glob; return u_glob; }
print '8656: u_glob as both local and parameter';

View File

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

6
calc.c
View File

@@ -1,8 +1,7 @@
/*
* calc - arbitrary precision calculator
*
* Copyright (C) 1999-2013,2021 David I. Bell, Landon Curt Noll
* and Ernest Bowen
* Copyright (C) 1999-2013,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -85,6 +84,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -786,7 +786,7 @@ intint(int UNUSED(arg))
(void) signal(SIGINT, intint);
if (inputwait || (++abortlevel >= ABORT_NOW)) {
calc_interrupt("\nABORT");
/*NOTREACHED*/
not_reached();
}
if (abortlevel >= ABORT_MATH)
_math_abort_ = TRUE;

View File

@@ -251,9 +251,6 @@ For example:
\fI#!${BINDIR}/calc\fP \fB\-q\fP \fB\-f\fP
.fi
.in -5n
.sp 1
This allows the script to run independently of
startup scripts.
.sp 1
See
@@ -294,6 +291,24 @@ This will cause calc to process lines in
in
.BR "shell script mode" .
.sp 1
.B NOTE:
The use of
.BR \-f
does
.B NOT
imply
.BR \-q
and thus one would need to use
.sp 1
.in +5n
.nf
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
.fi
.in -5n
.sp 1
to disable the use of calc startup files as well.
.sp 1
The use of
.B \-f
@@ -458,6 +473,13 @@ flag overrides
.TP
.B \-q
Disable the reading of the startup scripts.
.sp 1
This allows the script to run independently of
startup scripts such those managed by the
.B $CALCRC
environment variable.
For example, this will disable the use of the common calcrc file
(usually ~/.calcrc).
.TP
.B \-s
@@ -596,7 +618,7 @@ may have to be replaced by:
.sp 1
.in +5n
.nf
print 27! ^2 or print 27\!^2
print 27! ^2 or print 27\\!^2
.fi
.in -5n
@@ -813,6 +835,23 @@ are automatically set if
.B \-i
is not given.
.sp 1
.B NOTE:
The use of
.BR \-f
does
.B NOT
imply
.BR \-q
and thus one would need to use
.sp 1
.in +5n
.nf
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
.fi
.in -5n
.sp 1
to disable the use of calc startup files as well.
.sp 1
For example, if
the file
.BR /tmp/mersenne :

View File

@@ -1,7 +1,7 @@
/*
* codegen - module to generate opcodes from the input tokens
*
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -51,6 +51,7 @@
#endif
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -2383,16 +2384,16 @@ getfilename(char *name, size_t namelen, BOOL *once)
if (symstr == NULL) {
math_error(
"string value pointer is NULL!!");
/*NOTREACHED*/
not_reached();
}
} else {
math_error(
"a filename variable must be a string");
/*NOTREACHED*/
not_reached();
}
} else {
math_error("no such global variable");
/*NOTREACHED*/
not_reached();
}
}

View File

@@ -1,7 +1,7 @@
/*
* comfunc - extended precision complex arithmetic non-primitive routines
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -30,6 +30,7 @@
#include "cmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -60,16 +61,16 @@ c_powi(COMPLEX *c, NUMBER *q)
if (qisfrac(q)) {
math_error("Raising number to non-integral power");
/*NOTREACHED*/
not_reached();
}
if (zge31b(q->num)) {
math_error("Raising number to very large power");
/*NOTREACHED*/
not_reached();
}
power = ztolong(q->num);
if (ciszero(c) && (power == 0)) {
math_error("Raising zero to zeroth power");
/*NOTREACHED*/
not_reached();
}
sign = 1;
if (qisneg(q))
@@ -381,7 +382,7 @@ c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon)
if (qisneg(q) || qiszero(q) || qisfrac(q)) {
math_error("Taking bad root of complex number");
/*NOTREACHED*/
not_reached();
}
if (cisone(c) || qisone(q))
return clink(c);
@@ -446,7 +447,7 @@ c_exp(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cexp");
/*NOTREACHED*/
not_reached();
}
if (cisreal(c)) {
tmp1 = qexp(c->real, epsilon);
@@ -502,7 +503,7 @@ c_ln(COMPLEX *c, NUMBER *epsilon)
if (ciszero(c)) {
math_error("logarithm of zero");
/*NOTREACHED*/
not_reached();
}
if (cisone(c))
return clink(&_czero_);
@@ -599,7 +600,7 @@ c_cos(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for ccos");
/*NOTREACHED*/
not_reached();
}
n = qilog2(epsilon);
ctmp1 = comalloc();
@@ -649,7 +650,7 @@ c_sin(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for csin");
/*NOTREACHED*/
not_reached();
}
if (ciszero(c))
return clink(&_czero_);
@@ -1072,7 +1073,7 @@ c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cpolar");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1))
return clink(&_czero_);
@@ -1114,12 +1115,12 @@ c_power(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cpower");
/*NOTREACHED*/
not_reached();
}
if (ciszero(c1)) {
if (cisreal(c2) && qisneg(c2->real)) {
math_error ("Non-positive real exponent of zero");
/*NOTREACHED*/
not_reached();
}
return clink(&_czero_);
}
@@ -1190,12 +1191,18 @@ comprint(COMPLEX *c)
qtmp = c->imag[0];
if (qiszero(&qtmp))
return;
if (conf->complex_space) {
math_chr(' ');
}
if (!qiszero(c->real) && !qisneg(&qtmp))
math_chr('+');
if (qisneg(&qtmp)) {
math_chr('-');
qtmp.num.sign = 0;
}
if (conf->complex_space) {
math_chr(' ');
}
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
math_chr('i');
}
@@ -1222,7 +1229,13 @@ cprintfr(COMPLEX *c)
zprintval(i->num, 0L, 0L);
math_chr('i');
if (qisfrac(i)) {
if (conf->fraction_space) {
math_chr(' ');
}
math_chr('/');
if (conf->fraction_space) {
math_chr(' ');
}
zprintval(i->den, 0L, 0L);
}
}

View File

@@ -1,7 +1,7 @@
/*
* commath - extended precision complex arithmetic primitive routines
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "cmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -189,7 +190,7 @@ c_div(COMPLEX *c1, COMPLEX *c2)
if (ciszero(c2)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if ((c1->real == c2->real) && (c1->imag == c2->imag))
return clink(&_cone_);
@@ -260,7 +261,7 @@ c_inv(COMPLEX *c)
if (ciszero(c)) {
math_error("Inverting zero");
/*NOTREACHED*/
not_reached();
}
r = comalloc();
if (cisreal(c)) {
@@ -522,7 +523,7 @@ c_divq(COMPLEX *c, NUMBER *q)
if (qiszero(q)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (qisone(q))
return clink(c);
@@ -605,7 +606,7 @@ comalloc(void)
r = (COMPLEX *) malloc(sizeof(COMPLEX));
if (r == NULL) {
math_error("Cannot allocate complex number");
/*NOTREACHED*/
not_reached();
}
r->links = 1;
r->real = qlink(&_qzero_);

289
config.c
View File

@@ -1,7 +1,7 @@
/*
* config - configuration routines
*
* Copyright (C) 1999-2007,2021 David I. Bell and Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Landon Curt Noll
*
* Primary author: David I. Bell
*
@@ -62,6 +62,7 @@
#endif /* HAVE_STRDUP */
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -92,6 +93,9 @@ NAMETYPE configs[] = {
{"pow2", CONFIG_POW2},
{"redc2", CONFIG_REDC2},
{"tilde", CONFIG_TILDE},
{"tilde_space", CONFIG_TILDE_SPACE},
{"fraction_space", CONFIG_FRACTION_SPACE},
{"complex_space", CONFIG_COMPLEX_SPACE},
{"tab", CONFIG_TAB},
{"quomod", CONFIG_QUOMOD},
{"quo", CONFIG_QUO},
@@ -149,8 +153,11 @@ CONFIG oldstd = { /* backward compatible standard configuration */
SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* OK to print a tilde on approximations */
TRUE, /* OK to print tab before numeric values */
TRUE, /* TRUE ==> print a tilde on approximations */
FALSE, /* TRUE ==> print a space after tilde on approximations */
FALSE, /* TRUE ==> print spaces around / in fractions */
FALSE, /* TRUE ==> print spaces around + or - in complex values */
TRUE, /* TRUE ==> print tab before numeric values */
0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
@@ -160,8 +167,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
8, /* cfsim() default rounding mode */
2, /* output default rounding mode */
24, /* round()/bround() default rounding mode */
FALSE, /* OK to print leading 0 before decimal pt */
0, /* OK to print trailing 0's */
FALSE, /* TRUE ==> print leading 0 before decimal pt */
0, /* TRUE ==> print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */
PROMPT1, /* normal prompt */
PROMPT2, /* prompt when inside multi-line input */
@@ -172,30 +179,30 @@ CONFIG oldstd = { /* backward compatible standard configuration */
0, /* internal calc debug level */
3, /* calc resource file debug level */
0, /* user defined debug level */
FALSE, /* print Quit or abort executed messages */
FALSE, /* TRUE ==> print Quit or abort executed messages */
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */
NULL, /* basename of our name */
#if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */
TRUE, /* TRUE ==> running under windows */
#else
FALSE, /* not using windows */
FALSE, /* FALSE ==> not using windows */
#endif
#if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */
TRUE, /* TRUE ==> compiled under cygwin */
#else
FALSE, /* not compiled with cygwin */
FALSE, /* FALSE ==> not compiled with cygwin */
#endif
#if defined(CUSTOM)
TRUE, /* compiled with -DCUSTOM */
TRUE, /* TRUE ==> compiled with -DCUSTOM */
#else
FALSE, /* compiled without -DCUSTOM */
FALSE, /* FALSE ==> compiled without -DCUSTOM */
#endif
&allow_custom, /* *TRUE=> custom functions are enabled */
NULL, /* version */
BASEB, /* base for calculations */
TRUE, /* warn when redeclaring */
TRUE, /* warn when variable names collide */
TRUE, /* TRUE ==> warn when redeclaring */
TRUE, /* TRUE ==> warn when variable names collide */
};
CONFIG newstd = { /* new non-backward compatible configuration */
MODE_INITIAL, /* current output mode */
@@ -209,8 +216,11 @@ CONFIG newstd = { /* new non-backward compatible configuration */
SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* OK to print a tilde on approximations */
TRUE, /* OK to print tab before numeric values */
TRUE, /* TRUE ==> print a tilde on approximations */
FALSE, /* TRUE ==> print spaces around / in fractions */
FALSE, /* TRUE ==> print a space after tilde on approximations */
FALSE, /* TRUE ==> print spaces around + or - in complex values */
TRUE, /* TRUE ==> print tab before numeric values */
0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
@@ -220,8 +230,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
8, /* cfsim() default rounding mode */
24, /* output default rounding mode */
24, /* round()/bround() default rounding mode */
TRUE, /* OK to print leading 0 before decimal pt */
0, /* OK to print trailing 0's */
TRUE, /* TRUE ==> print leading 0 before decimal pt */
0, /* TRUE ==> print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */
"; ", /* normal prompt */
";; ", /* prompt when inside multi-line input */
@@ -232,30 +242,30 @@ CONFIG newstd = { /* new non-backward compatible configuration */
0, /* internal calc debug level */
3, /* calc resource file debug level */
0, /* user defined debug level */
FALSE, /* print Quit or abort executed messages */
FALSE, /* TRUE ==> print Quit or abort executed messages */
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */
NULL, /* basename of our name */
#if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */
TRUE, /* TRUE ==> running under windows */
#else
FALSE, /* not using windows */
FALSE, /* FALSE ==> not using windows */
#endif
#if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */
TRUE, /* TRUE ==> compiled under cygwin */
#else
FALSE, /* not compiled with cygwin */
FALSE, /* FALSE ==> not compiled with cygwin */
#endif
#if defined(CUSTOM)
TRUE, /* compiled with -DCUSTOM */
TRUE, /* TRUE ==> compiled with -DCUSTOM */
#else
FALSE, /* compiled without -DCUSTOM */
FALSE, /* FALSE ==> compiled without -DCUSTOM */
#endif
&allow_custom, /* *TRUE=> custom functions are enabled */
&allow_custom, /* *TRUE ==> custom functions are enabled */
NULL, /* version */
BASEB, /* base for calculations */
TRUE, /* warn when redeclaring */
TRUE, /* warn when variable names collide */
TRUE, /* TRUE ==> warn when redeclaring */
TRUE, /* TRUE ==> warn when variable names collide */
};
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
@@ -488,11 +498,11 @@ setconfig(int type, VALUE *vp)
newconf = &newstd;
} else {
math_error("CONFIG alias not oldstd or newstd");
/*NOTREACHED*/
not_reached();
}
} else if (vp->v_type != V_CONFIG) {
math_error("non-CONFIG for all");
/*NOTREACHED*/
not_reached();
} else {
newconf = vp->v_config;
}
@@ -507,14 +517,14 @@ setconfig(int type, VALUE *vp)
case CONFIG_TRACE:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for trace");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num) ||
((unsigned long) temp > TRACE_MAX)) {
math_error("Bad trace value");
/*NOTREACHED*/
not_reached();
}
conf->traceflags = (FLAG)temp;
break;
@@ -522,7 +532,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_DISPLAY:
if (getlen(vp, &len)) {
math_error("Bad value for display");
/*NOTREACHED*/
not_reached();
}
math_setdigits(len);
break;
@@ -530,12 +540,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_MODE:
if (vp->v_type != V_STR) {
math_error("Non-string for mode");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(modes, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
math_setmode((int) temp);
break;
@@ -543,12 +553,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_MODE2:
if (vp->v_type != V_STR) {
math_error("Non-string for mode");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(modes, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
math_setmode2((int) temp);
break;
@@ -556,7 +566,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_EPSILON:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for epsilon");
/*NOTREACHED*/
not_reached();
}
setepsilon(vp->v_num);
break;
@@ -564,7 +574,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MAXPRINT:
if (getlen(vp, &len)) {
math_error("Bad value for maxprint");
/*NOTREACHED*/
not_reached();
}
conf->maxprint = len;
break;
@@ -572,7 +582,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MUL2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for mul2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = MUL_ALG2;
@@ -582,7 +592,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_SQ2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for sq2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = SQ_ALG2;
@@ -592,7 +602,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_POW2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for pow2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = POW_ALG2;
@@ -602,7 +612,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_REDC2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for redc2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = REDC_ALG2;
@@ -617,12 +627,54 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for tilde");
/*NOTREACHED*/
not_reached();
}
conf->tilde_ok = (int)temp;
}
break;
case CONFIG_TILDE_SPACE:
if (vp->v_type == V_NUM) {
q = vp->v_num;
conf->tilde_space = !qiszero(q);
} else if (vp->v_type == V_STR) {
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for tilde_space");
not_reached();
}
conf->tilde_space = (int)temp;
}
break;
case CONFIG_FRACTION_SPACE:
if (vp->v_type == V_NUM) {
q = vp->v_num;
conf->fraction_space = !qiszero(q);
} else if (vp->v_type == V_STR) {
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for fraction_space");
not_reached();
}
conf->fraction_space = (int)temp;
}
break;
case CONFIG_COMPLEX_SPACE:
if (vp->v_type == V_NUM) {
q = vp->v_num;
conf->complex_space = !qiszero(q);
} else if (vp->v_type == V_STR) {
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for complex_space");
not_reached();
}
conf->complex_space = (int)temp;
}
break;
case CONFIG_TAB:
if (vp->v_type == V_NUM) {
q = vp->v_num;
@@ -631,7 +683,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for tab");
/*NOTREACHED*/
not_reached();
}
conf->tab_ok = (int)temp;
}
@@ -640,7 +692,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_QUOMOD:
if (getlen(vp, &len)) {
math_error("Illegal value for quomod");
/*NOTREACHED*/
not_reached();
}
conf->quomod = len;
break;
@@ -648,7 +700,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_QUO:
if (getlen(vp, &len)) {
math_error("Illegal value for quo");
/*NOTREACHED*/
not_reached();
}
conf->quo = len;
break;
@@ -656,7 +708,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MOD:
if (getlen(vp, &len)) {
math_error("Illegal value for mod");
/*NOTREACHED*/
not_reached();
}
conf->mod = len;
break;
@@ -664,7 +716,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_SQRT:
if (getlen(vp, &len)) {
math_error("Illegal value for sqrt");
/*NOTREACHED*/
not_reached();
}
conf->sqrt = len;
break;
@@ -672,7 +724,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_APPR:
if (getlen(vp, &len)) {
math_error("Illegal value for appr");
/*NOTREACHED*/
not_reached();
}
conf->appr = len;
break;
@@ -680,7 +732,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_CFAPPR:
if (getlen(vp, &len)) {
math_error("Illegal value for cfappr");
/*NOTREACHED*/
not_reached();
}
conf->cfappr = len;
break;
@@ -688,7 +740,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_CFSIM:
if (getlen(vp, &len)) {
math_error("Illegal value for cfsim");
/*NOTREACHED*/
not_reached();
}
conf->cfsim = len;
break;
@@ -696,7 +748,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_OUTROUND:
if (getlen(vp, &len)) {
math_error("Illegal value for outround");
/*NOTREACHED*/
not_reached();
}
conf->outround = len;
break;
@@ -704,7 +756,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_ROUND:
if (getlen(vp, &len)) {
math_error("Illegal value for round");
/*NOTREACHED*/
not_reached();
}
conf->round = len;
break;
@@ -715,10 +767,9 @@ setconfig(int type, VALUE *vp)
conf->leadzero = !qiszero(q);
} else if (vp->v_type == V_STR) {
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) { {
if (temp < 0) {
math_error("Illegal truth value for leadzero");
/*NOTREACHED*/
}
not_reached();
}
conf->leadzero = (int)temp;
}
@@ -732,7 +783,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) { {
math_error("Illegal truth value for fullzero");
/*NOTREACHED*/
not_reached();
}
}
conf->fullzero = (int)temp;
@@ -742,7 +793,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MAXSCAN:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for maxscancount");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
@@ -750,7 +801,7 @@ setconfig(int type, VALUE *vp)
temp = -1;
if (temp < 0) {
math_error("Maxscan value is out of range");
/*NOTREACHED*/
not_reached();
}
conf->maxscancount = temp;
break;
@@ -758,12 +809,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_PROMPT:
if (vp->v_type != V_STR) {
math_error("Non-string for prompt");
/*NOTREACHED*/
not_reached();
}
p = (char *)malloc(vp->v_str->s_len + 1);
if (p == NULL) {
math_error("Cannot duplicate new prompt");
/*NOTREACHED*/
not_reached();
}
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt1);
@@ -773,12 +824,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_MORE:
if (vp->v_type != V_STR) {
math_error("Non-string for more prompt");
/*NOTREACHED*/
not_reached();
}
p = (char *)malloc(vp->v_str->s_len + 1);
if (p == NULL) {
math_error("Cannot duplicate new more prompt");
/*NOTREACHED*/
not_reached();
}
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt2);
@@ -788,7 +839,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKMAXPRINT:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for blkmaxprint");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
@@ -796,7 +847,7 @@ setconfig(int type, VALUE *vp)
temp = -1;
if (temp < 0) {
math_error("Blkmaxprint value is out of range");
/*NOTREACHED*/
not_reached();
}
conf->blkmaxprint = temp;
break;
@@ -809,7 +860,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for blkverbose");
/*NOTREACHED*/
not_reached();
}
conf->blkverbose = (int)temp;
}
@@ -818,13 +869,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKBASE:
if (vp->v_type != V_STR) {
math_error("Non-string for blkbase");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(blk_base, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for blkbase",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->blkbase = temp;
break;
@@ -832,13 +883,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKFMT:
if (vp->v_type != V_STR) {
math_error("Non-string for blkfmt");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(blk_fmt, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for blkfmt",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->blkfmt = temp;
break;
@@ -846,13 +897,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_CALC_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for calc_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal calc_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->calc_debug = temp;
break;
@@ -860,13 +911,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_RESOURCE_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for resource_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal resource_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->resource_debug = temp;
break;
@@ -874,13 +925,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_USER_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for user_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal user_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->user_debug = temp;
break;
@@ -894,7 +945,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value "
"for verbose_quit");
/*NOTREACHED*/
not_reached();
}
conf->verbose_quit = (int)temp;
}
@@ -903,56 +954,56 @@ setconfig(int type, VALUE *vp)
case CONFIG_CTRL_D:
if (vp->v_type != V_STR) {
math_error("Non-string for ctrl_d");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(ctrl_d, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for ctrl_d",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->ctrl_d = temp;
break;
case CONFIG_PROGRAM:
math_error("The program config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_BASENAME:
math_error("The basename config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_WINDOWS:
math_error("The windows config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_CYGWIN:
math_error("The cygwin config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_COMPILE_CUSTOM:
math_error("The custom config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_ALLOW_CUSTOM:
math_error("The allow_custom config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_VERSION:
math_error("The version config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_BASEB:
math_error("The baseb config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
case CONFIG_REDECL_WARN:
if (vp->v_type == V_NUM) {
@@ -963,7 +1014,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value for "
"redecl_warn");
/*NOTREACHED*/
not_reached();
}
conf->redecl_warn = (int)temp;
}
@@ -978,7 +1029,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value for "
"dupvar_warn");
/*NOTREACHED*/
not_reached();
}
conf->dupvar_warn = (int)temp;
}
@@ -986,13 +1037,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_HZ:
math_error("The clock tick rate config parameter is read-only");
/*NOTREACHED*/
abort();
not_reached();
break;
default:
math_error("Setting illegal config parameter");
/*NOTREACHED*/
abort();
not_reached();
break;
}
}
@@ -1017,7 +1068,7 @@ config_copy(CONFIG *src)
if (src == NULL || src->epsilon == NULL || src->prompt1 == NULL ||
src->prompt2 == NULL) {
math_error("bad CONFIG value");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1026,7 +1077,7 @@ config_copy(CONFIG *src)
dest = (CONFIG *)malloc(sizeof(CONFIG));
if (dest == NULL) {
math_error("malloc of CONFIG failed");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1134,7 +1185,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
cfg->prompt2 == NULL) {
math_error("bad CONFIG value");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1161,7 +1212,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(modes, cfg->outmode);
if (p == NULL) {
math_error("invalid output mode: %d", cfg->outmode);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1172,7 +1223,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
if (p == NULL) {
math_error("invalid secondary output mode: %d",
cfg->outmode2);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1205,6 +1256,18 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
i = (cfg->tilde_ok ? 1 : 0);
break;
case CONFIG_TILDE_SPACE:
i = (cfg->tilde_space ? 1 : 0);
break;
case CONFIG_FRACTION_SPACE:
i = (cfg->fraction_space ? 1 : 0);
break;
case CONFIG_COMPLEX_SPACE:
i = (cfg->complex_space ? 1 : 0);
break;
case CONFIG_TAB:
i = (cfg->tab_ok ? 1 : 0);
break;
@@ -1280,7 +1343,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(blk_base, cfg->blkbase);
if (p == NULL) {
math_error("invalid block base: %d", cfg->blkbase);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1290,7 +1353,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(blk_fmt, cfg->blkfmt);
if (p == NULL) {
math_error("invalid block format: %d", cfg->blkfmt);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1316,7 +1379,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(ctrl_d, cfg->ctrl_d);
if (p == NULL) {
math_error("invalid Control-D: %d", cfg->ctrl_d);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1386,7 +1449,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
default:
math_error("Getting illegal CONFIG element");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1416,12 +1479,12 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL ||
cfg1->prompt2 == NULL) {
math_error("CONFIG #1 value is invalid");
/*NOTREACHED*/
not_reached();
}
if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL ||
cfg2->prompt2 == NULL) {
math_error("CONFIG #2 value is invalid");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -94,6 +94,9 @@
#define CONFIG_REDECL_WARN 44
#define CONFIG_DUPVAR_WARN 45
#define CONFIG_HZ 46
#define CONFIG_TILDE_SPACE 47
#define CONFIG_FRACTION_SPACE 48
#define CONFIG_COMPLEX_SPACE 49
/*
@@ -123,7 +126,7 @@ struct config {
int outmode2; /* current secondary output mode */
LEN outdigits; /* current output digits for float or exp */
NUMBER *epsilon; /* default error for real functions */
long epsilonprec; /* epsilon binary precision (tied to epsilon) */
long epsilonprec; /* epsilon binary precision (tied to epsilon) */
FLAG traceflags; /* tracing flags */
LEN maxprint; /* number of elements to print */
LEN mul2; /* size of number to use multiply algorithm 2 */
@@ -131,6 +134,9 @@ struct config {
LEN pow2; /* size of modulus to use REDC for powers */
LEN redc2; /* size of modulus to use REDC algorithm 2 */
BOOL tilde_ok; /* OK to print a tilde on approximations */
BOOL tilde_space; /* print space after tilde on approximations */
BOOL fraction_space; /* TRUE => print spaces around / in fractions */
BOOL complex_space; /* TRUE => print spaces around + or - in complex values */
BOOL tab_ok; /* OK to print tab before numeric values */
LEN quomod; /* quomod() default rounding mode */
LEN quo; /* quotient // default rounding mode */

15
const.c
View File

@@ -1,7 +1,7 @@
/*
* const - constant number storage module
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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
@@ -29,6 +29,7 @@
#include "qmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -47,7 +48,7 @@ initconstants(void)
consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE);
if (consttable == NULL) {
math_error("Unable to allocate constant table");
/*NOTREACHED*/
not_reached();
}
for (i = 0; initnumbs[i] != NULL; i++) {
consttable[i] = initnumbs[i];
@@ -108,7 +109,7 @@ addqconstant(NUMBER *q)
sizeof(NUMBER *) * (constcount + CONSTALLOCSIZE));
if (tp == NULL) {
math_error("Unable to reallocate const table");
/*NOTREACHED*/
not_reached();
}
consttable = tp;
constavail = CONSTALLOCSIZE;
@@ -179,11 +180,11 @@ constvalue(unsigned long index)
{
if (index >= constcount) {
math_error("Bad index value for constvalue");
/*NOTREACHED*/
not_reached();
}
if (consttable[index]->links == 0) {
math_error("Constvalue has been freed!!!");
/*NOTREACHED*/
not_reached();
}
return consttable[index];
}
@@ -196,12 +197,12 @@ freeconstant(unsigned long index)
if (index >= constcount) {
math_error("Bad index value for freeconst");
/*NOTREACHED*/
not_reached();
}
q = consttable[index];
if (q->links == 0) {
math_error("Attempting to free freed const location");
/*NOTREACHED*/
not_reached();
}
qfree(q);
if (index == constcount - 1) {

View File

@@ -1,7 +1,7 @@
#
# cscript - makefile for calc shell script files
#
# Copyright (C) 1999-2006,2014,2017,2021 Landon Curt Noll
# Copyright (C) 1999-2006,2014,2017,2021,2022 Landon Curt Noll
#
# SRC: cscript/Makefile
#
@@ -105,15 +105,6 @@ PREFIX= /usr/local
#
MAKE_FILE= Makefile
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# Where the system include (.h) files are kept
#
# For DJGPP, select:
@@ -306,11 +297,17 @@ CALCLIBLIST=
#
CSCRIPT_TARGETS= ${SCRIPT}
TARGETS= ${CSCRIPT_TARGETS} README
#
# rules that are not also names of files
#
PHONY= all clobber distlist install
# The reason for this Makefile
#
all: ${TARGETS} .all
.PHONY: ${PHONY}
README: README.src
@${RM} -f $@
@${SED} -e "s:#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@

View File

@@ -1,7 +1,7 @@
/*
* custom - interface for custom software and hardware interfaces
*
* Copyright (C) 1999-2006,2018,2021 Landon Curt Noll
* Copyright (C) 1999-2006,2018,2021,2022 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
@@ -48,6 +48,7 @@
#endif /* CUSTOM */
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -77,12 +78,12 @@ custom(char *name, int count, VALUE **vals)
if (count < p->minargs) {
math_error("Too few arguments for custom "
"function \"%s\"", p->name);
/*NOTREACHED*/
not_reached();
}
if (count > p->maxargs) {
math_error("Too many arguments for custom "
"function \"%s\"", p->name);
/*NOTREACHED*/
not_reached();
}
/* call the custom function */
@@ -200,7 +201,7 @@ customhelp(char *name)
customname = (char *)malloc(snprintf_len+1);
if (customname == NULL) {
math_error("bad malloc of customname");
/*NOTREACHED*/
not_reached();
}
snprintf(customname, snprintf_len, "custhelp/%s", name);
customname[snprintf_len] = '\0'; /* paranoia */

View File

@@ -4,7 +4,7 @@
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: Makefile via make -f Makefile.ship custom/Makefile
# SRC: custom/Makefile
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
@@ -35,25 +35,6 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
####################################################
# NOTE: Start of section from custom/Makefile.head #
####################################################
#.###############################################################.#
#.# #.#
#.# WARNING: This Makefile is generated from a combination of #.#
#.# custom/Makefile.head, Makefile.ship, and #.#
#.# custom/Makefile.tail. We recommend that you NOT #.#
#.# edit this file, but instead edit the proper source #.#
#.# file and then make custom/Makefile: #.#
#.# #.#
#.# make custom/Makefile #.#
#.# #.#
#.# See the '# NOTE .. section from ..' lines for #.#
#.# where the source file for the lines are from. #.#
#.# #.#
#.###############################################################.#
# The shell used by this Makefile
#
@@ -151,8 +132,10 @@ CCBAN= -UUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
# Unfortunately due to the complex dependency issues between
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
# is NOT recommended. Sorry.
# Makefile, and custom/Makefile, parallel GNU make
# is NOT recommended.
#
# XXX - fix this - XXX
#
.NOTPARALLEL:
@@ -171,10 +154,6 @@ target=$(shell uname -s 2>/dev/null)
endif
#endif /* end of skip for non-Gnu makefiles */
##############################################################################
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
##############################################################################
# The custom calc resource files to install
#
# Put your custom calc resource files here.
@@ -218,6 +197,10 @@ CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c c_pzasusb8.c \
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
c_pmodm127.o c_register.o
##############################################################################
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
##############################################################################
##############################################################################
#-=-=-=-=-=-=- Defaults in case you want to build from this dir -=-=-=-=-=-=-#
##############################################################################
@@ -422,15 +405,6 @@ RANLIB=ranlib
MAKE_FILE= Makefile
#MAKE_FILE=
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# If you do not wish to use purify, set PURIFY to an empty string.
#
# If in doubt, use PURIFY=
@@ -500,7 +474,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.0.12
VERSION= 2.14.1.3
# Names of shared libraries with versions
#
@@ -515,9 +489,11 @@ CHMOD= chmod
CMP= cmp
CO= co
CP= cp
DIFF= diff
FMT= fmt
GREP= egrep
LN= ln
LS= ls
MAKE= make
MAKEDEPEND= makedepend
MKDIR= mkdir
@@ -588,548 +564,21 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
#endif /* end of skip for non-Gnu makefiles */
##################################################
# NOTE: End of section from custom/Makefile.head #
##################################################
# start of host target cut - Do not remove this line
###########################################################
# NOTE: Start of section from the middle of Makefile.ship #
###########################################################
##############################################################################
#-=-=-=-=-=- host target section - targets that override defaults -=-=-=-=-=-#
##############################################################################
# Common values set in targets
#
# BLD_TYPE determines if calc is built with static and/or dynamic libs.
# Set this value to one of:
#
# BLD_TYPE= calc-dynamic-only
# BLD_TYPE= calc-static-only
#
# CC_SHARE are flags given to ${CC} to build .o files suitable for shared libs
# DEFAULT_LIB_INSTALL_PATH is where calc programs look for calc shared libs
# LD_SHARE are common flags given to ${CC} to link with shared libraries
# LIBCALC_SHLIB are flags given to ${CC} to build libcalc shared libraries
# LIBCUSTCALC_SHLIB are flags given to ${CC} to build libcustcalc shared lib
#
# NOTE: The above 5 values are unused if BLD_TYPE= calc-static-only
#
# CC_STATIC are flags given to ${CC} to build .o files suitable for static libs
# LD_STATIC are common flags given to ${CC} to link with static libraries
# LIBCALC_STATIC are flags given to ${CC} to build libcalc static libraries
# LIBCUSTCALC_STATIC are flags given to ${CC} to build libcustcalc static lib
#
# NOTE: The above 4 values are unused if BLD_TYPE= calc-dynamic-only
#
# CCOPT are flags given to ${CC} for optimization
# CCWARN are flags given to ${CC} for warning message control
#
# 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=
#
# CCWERR are flags given to ${CC} to make warnings fatal errors
# NOTE: CCWERR is only set in development Makefiles and must only be
# used with ${CC}, not ${LCC}. If you do not want the compiler
# 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)
#
# Specific target overrides or modifications to default values
##########################################################################
# NOTE: If your target is not supported below and the default target #
# is not suitable for your needs, please send to the: #
# #
# calc-contrib at asthe dot com #
# #
# Email address an "ifeq ($(target),YOUR_TARGET_NAME)" ... "endif" #
# set of lines so that we can consider them for the next release. #
#=-=-=-=-=- Be careful if you change something below this line -=-=-=-=-=#
##########################################################################
# include start from top Makefile - keep this line
#if 0 /* start of skip for non-Gnu makefiles */
################
# Linux target #
################
ifeq ($(target),Linux)
###
#
BLD_TYPE= calc-dynamic-only
# Allow Makefile.local to override any of the above settings
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
ifdef ALLOW_CUSTOM
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LD_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use gcc's -Werror to force warnings
# to become errors, call make with:
#
# make .. COMMON_ADD='-Werror'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= gcc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
endif
###############################
# Apple macOS / Darwin target #
###############################
ifeq ($(target),Darwin)
#
BLD_TYPE= calc-dynamic-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:${LIBDIR}:${PREFIX}/lib
LD_SHARE= ${DARWIN_ARCH}
#SET_INSTALL_NAME= no
SET_INSTALL_NAME= yes
ifeq ($(SET_INSTALL_NAME),yes)
LIBCALC_SHLIB= -single_module -undefined dynamic_lookup -dynamiclib \
-install_name ${LIBDIR}/libcalc${LIB_EXT_VERSION} ${DARWIN_ARCH}
else
LIBCALC_SHLIB= -single_module -undefined dynamic_lookup -dynamiclib \
${DARWIN_ARCH}
endif
ifdef ALLOW_CUSTOM
ifeq ($(SET_INSTALL_NAME),yes)
LIBCUSTCALC_SHLIB= -single_module -undefined dynamic_lookup -dynamiclib \
-install_name ${LIBDIR}/libcustcalc${LIB_EXT_VERSION} ${DARWIN_ARCH}
else
LIBCUSTCALC_SHLIB= -single_module -undefined dynamic_lookup -dynamiclib \
${DARWIN_ARCH}
endif
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LD_STATIC= ${DARWIN_ARCH}
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use clang's -fsanitize for calc testing,
# which requires a common set of flags to be passed to
# every compile and link, then call make with:
#
# make .. COMMON_ADD='-fsanitize=undefined -fsanitize=address'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC= ${DARWIN_ARCH}
#
LCC= clang
CC= ${PURIFY} ${LCC} ${CCWERR}
#
# Darwin dynamic shared lib filenames
LIB_EXT:= .dylib
LIB_EXT_VERSION:= .${VERSION}${LIB_EXT}
# LDCONFIG not required on this platform, so we redefine it to an empty string
LDCONFIG:=
# DARWIN_ARCH= -arch i386 -arch ppc # Universal binary
# DARWIN_ARCH= -arch i386 # Intel binary
# DARWIN_ARCH= -arch ppc # PPC binary
# DARWIN_ARCH= -arch x86_64 # native 64-bit binary
DARWIN_ARCH= # native binary
endif
##################
# FreeBSD target #
##################
########################################################################
# NOTE: You MUST either use gmake (GNU Make) or you must try your luck #
# with Makefile.simple and custom/Makefile.simple versions. #
# See HOWTO.INSTALL for more information. #
########################################################################
ifeq ($(target),FreeBSD)
#
BLD_TYPE= calc-dynamic-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
ifdef ALLOW_CUSTOM
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LD_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use gcc's -Werror to force warnings
# to become errors, call make with:
#
# make .. COMMON_ADD='-Werror'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= gcc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
MAKE= gmake
#
endif
##################
# OpenBSD target #
##################
########################################################################
# NOTE: You MUST either use gmake (GNU Make) or you must try your luck #
# with Makefile.simple and custom/Makefile.simple versions. #
# See HOWTO.INSTALL for more information. #
########################################################################
ifeq ($(target),OpenBSD)
#
BLD_TYPE= calc-dynamic-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
ifdef ALLOW_CUSTOM
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LD_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use gcc's -Werror to force warnings
# to become errors, call make with:
#
# make .. COMMON_ADD='-Werror'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= gcc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
MAKE= gmake
#
endif
#################
# Cygwin target #
#################
ifeq ($(target),Cygwin)
#
BLD_TYPE= calc-static-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
ifdef ALLOW_CUSTOM
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
LD_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use gcc's -Werror to force warnings
# to become errors, call make with:
#
# make .. COMMON_ADD='-Werror'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= gcc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
endif
#######################################################
# simple target - values used to form Makefile.simple #
#######################################################
# NOTE: This is not a real host target. The simple target
# exists only to form the Makefile.simple file.
ifeq ($(target),simple)
###
EXCLUDE_FROM_CUSTOM_MAKEFILE=true # include only middle of ../Makefile
include ../Makefile
#endif /* end of skip for non-Gnu makefiles */
#
BLD_TYPE= calc-static-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
#
CC_STATIC=
LD_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= cc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
# The simple makefile forces the use of static ${CC} flags
#
# ICFLAGS are given to ${CC} for intermediate programs used to help compile calc
# CFLAGS are given to ${CC} for calc programs other than intermediate programs
# 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} ${CCBAN} ${CC_STATIC}
CFLAGS= ${ICFLAGS} ${CCOPT}
#
ILDFLAGS= ${COMMON_LDFLAGS} ${LD_STATIC}
LDFLAGS= ${LD_DEBUG} ${ILDFLAGS} ${LIBCALC_STATIC} ${LIBCUSTCALC_STATIC}
#
#if 0 /* start of skip for non-Gnu makefiles */
endif
###################################################
# default target - when no specific target exists #
###################################################
# NOTE: This is the default generic host target. Used when no other
# host target matches.
ifeq ($(target),)
#
BLD_TYPE= calc-static-only
#
CC_SHARE= -fPIC
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
ifdef ALLOW_CUSTOM
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
else
LIBCUSTCALC_SHLIB=
endif
#
CC_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
LD_STATIC=
#
# If you want to add flags to all compiler and linker
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
# set ${COMMON_ADD}.
#
# For example to use gcc's -Werror to force warnings
# to become errors, call make with:
#
# make .. COMMON_ADD='-Werror'
#
# This facility requires a Gnu Makefile, or a make command
# that understands the += make operand.
#
COMMON_CFLAGS+= ${COMMON_ADD}
COMMON_LDFLAGS+= ${COMMON_ADD}
#
CCWARN= -Wall
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
CCWERR=
CCOPT= ${DEBUG}
CCMISC=
#
LCC= gcc
CC= ${PURIFY} ${LCC} ${CCWERR}
#
endif
###########################################
# Set the default compile flags for ${CC} #
###########################################
# Required flags to compile C files for calc
#
# ICFLAGS are given to ${CC} for intermediate programs used to help compile calc
# CFLAGS are given to ${CC} for calc programs other than intermediate programs
#
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
# Required flags to link files for calc
#
# ILDFLAGS for ${CC} in linking intermediate programs used to help compile calc
# LDFLAGS for ${CC} in linking calc programs other than intermediate programs
#
ILDFLAGS= ${COMMON_LDFLAGS}
LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
#endif /* end of skip for non-Gnu makefiles */
#######################################################################
#-=-=-=-=-=- end of target section - only make rules below -=-=-=-=-=-#
#######################################################################
#########################################################
# NOTE: End of section from the middle of Makefile.ship #
#########################################################
# end of host target cut - Do not remove this line
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: Makefile via make -f Makefile.ship custom/Makefile
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
####################################################
# NOTE: Start of section from custom/Makefile.tail #
####################################################
##############################################################################
#-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-#
##############################################################################
# include end from top Makefile - keep this line
# These .c files are required for the main custom interface and
# for the custom support functions for libcustcalc${LIB_EXT_VERSION}.
@@ -1171,8 +620,7 @@ H_SRC= ${CUSTOM_H_SRC}
# directory but are installed as help files from the help/Makefile.
#
DISTLIST= ${CUSTCALC_SRC} ${CUSTOM_CALC_FILES} ${CUSTOM_HELP} \
${INSTALL_H_SRC} CUSTOM_CAL HOW_TO_ADD ${MAKE_FILE}.head \
${MAKE_FILE}.tail
${INSTALL_H_SRC} CUSTOM_CAL HOW_TO_ADD Makefile Makefile.simple
# These files are used to make (but not built) a calc .a link library
#
@@ -1192,7 +640,7 @@ TARGETS= ${BLD_TYPE} Makefile.simple
###
#
# The reason for this Makefile :-)
# The main reason for this Makefile :-)
#
###
@@ -1273,7 +721,7 @@ calcliblist: ${CALCLIBLIST}
done
#if 0 /* start of skip for non-Gnu makefiles */
Makefile.simple: Makefile ../Makefile ../Makefile.ship
Makefile.simple: Makefile ../Makefile
${V} echo '=-=-=-=-= custom/${MAKE_FILE} start of $@ rule =-=-=-=-='
${Q} if [ -f $@.bak ]; then \
echo "custom/$@.bak exists, remove or move it"; \
@@ -1285,14 +733,41 @@ Makefile.simple: Makefile ../Makefile ../Makefile.ship
${MV} -f $@ $@.bak; \
fi
${Q} ${AWK} '/^#if 0/{skp=1} {if(!skp){print $$0}} /^#endif/{skp=0}' \
Makefile | \
${GREP} -v '#\.#' | \
${SED} -e 's;^# SRC:.*;# SRC: non-GNU Makefile via;' \
-e 's;via$$;via ${MAKE} -f ${MAKE_FILE} custom/$@;' > $@
${Q} echo >> $@
${Q} echo 'Makefile.simple:' >> $@
${Q} echo ' $${Q} if [ ! -f Makefile.simple ]; then '"\\" >> $@
${Q} echo ' $${CP} -f $${MAKE_FILE} $$@; fi' >> $@
Makefile | \
${SED} -e '/^# include start from top Makefile - keep /,$$d' \
-e 's;^# SRC:.*;# SRC: custom/$@ - non-GNU version;' \
-e '/^ifeq /d' \
-e '/^ifneq /d' \
-e '/^ifdef /d' \
-e '/^ifndef /d' \
-e '/^else/d' \
-e '/^endif/d' \
> $@
${Q} echo '# include start from top Makefile - keep this line' \
>> $@
${Q} ${AWK} '/^#if 0/{skp=1} {if(!skp){print $$0}} /^#endif/{skp=0}' \
../Makefile | \
${SED} -e '1,/^# include start from top Makefile - keep /d' \
-e '/^# include end from top Makefile - keep /,$$d' \
-e '/^ifeq /d' \
-e '/^ifneq /d' \
-e '/^ifdef /d' \
-e '/^ifndef /d' \
-e '/^else/d' \
-e '/^endif/d' \
>> $@
${Q} echo '# include end from top Makefile - keep this line' \
>> $@
${Q} ${AWK} '/^#if 0/{skp=1} {if(!skp){print $$0}} /^#endif/{skp=0}' \
Makefile | \
${SED} -e '1,/^# include end from top Makefile - keep /d' \
-e '/^ifeq /d' \
-e '/^ifneq /d' \
-e '/^ifdef /d' \
-e '/^ifndef /d' \
-e '/^else/d' \
-e '/^endif/d' \
>> $@
-${Q} if [ -s $@.bak ]; then \
if ${CMP} -s $@.bak $@; then \
echo 'custom/$@ was already up to date'; \
@@ -1301,10 +776,13 @@ Makefile.simple: Makefile ../Makefile ../Makefile.ship
else \
echo 'old custom/$@ is now custom/$@.bak'; \
echo 'updated custom/$@ formed'; \
echo 'try: diff -u custom/$@.bak custom/$@'; \
(cd .. ; ${DIFF} -u custom/$@.bak custom/$@); \
fi; \
else \
echo 'new custom/$@ formed'; \
echo; \
(cd .. ; ${LS} -l custom/$@); \
echo; \
fi
${V} echo '=-=-=-=-= custom/${MAKE_FILE} end of $@ rule =-=-=-=-='
#endif /* end of skip for non-Gnu makefiles */
@@ -1347,8 +825,8 @@ depend:
>> "skel/custom/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q} (cd ..; ${MAKE} -f ${TOP_MAKE_FILE} hsrc)
${MAKE} -f ../${TOP_MAKE_FILE} h_list 2>/dev/null | \
${Q} (cd ..; ${MAKE} -f ${MAKE_FILE} hsrc)
${MAKE} -f ../${MAKE_FILE} h_list 2>/dev/null | \
while read i; do \
if [ ! -f "../$$i" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
@@ -1383,7 +861,6 @@ 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} ${TAIL} -4 ${MAKE_FILE}.tail >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
@@ -1684,6 +1161,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../attribute.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
@@ -1711,6 +1189,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: ../attribute.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
@@ -1738,6 +1217,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: ../attribute.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
@@ -1765,6 +1245,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: ../attribute.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
@@ -1791,6 +1272,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: ../attribute.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
@@ -1817,6 +1299,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: ../attribute.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
@@ -1844,6 +1327,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: ../attribute.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
@@ -1878,6 +1362,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../attribute.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
@@ -1902,7 +1387,3 @@ custtbl.o: ../str.h
custtbl.o: ../value.h
custtbl.o: ../zmath.h
custtbl.o: custtbl.c
##################################################
# NOTE: End of section from custom/Makefile.tail #
##################################################

View File

@@ -1,593 +0,0 @@
#!/bin/make
#
# custom - makefile for calc custom routines
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: custom/Makefile.head
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
#
# 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: 1997/03/09 02:28:54
# File existed as early as: 1997
#
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
#
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
####################################################
# NOTE: Start of section from custom/Makefile.head #
####################################################
#.###############################################################.#
#.# #.#
#.# WARNING: This Makefile is generated from a combination of #.#
#.# custom/Makefile.head, Makefile.ship, and #.#
#.# custom/Makefile.tail. We recommend that you NOT #.#
#.# edit this file, but instead edit the proper source #.#
#.# file and then make custom/Makefile: #.#
#.# #.#
#.# make custom/Makefile #.#
#.# #.#
#.# See the '# NOTE .. section from ..' lines for #.#
#.# where the source file for the lines are from. #.#
#.# #.#
#.###############################################################.#
# The shell used by this Makefile
#
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavior.
#
# 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 where 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/bash
#SHELL= /bin/sh
#if 0 /* start of skip for non-Gnu makefiles */
ifeq ($(target),Darwin)
SHELL:= /bin/zsh
endif
#endif /* end of skip for non-Gnu makefiles */
# PREFIX - Top level location for calc
#
# The PREFIX is often prepended to paths within calc and calc Makefiles.
#
# Starting with calc v2.13.0.1, nearly all Makefile places that used
# /usr/local now use ${PREFIX}. An exception is the olduninstall rule
# and, of course, this section. :-)
#
# NOTE: The ${PREFIX} is not the same as ${T}. The ${T} specifies
# a top level directory under which calc installs things.
# While usually ${T} is empty, it can be specific path
# as if calc where "chrooted" during an install.
# The ${PREFIX} value, during install, is a path between
# the top level ${T} install directory and the object
# such as an include file.
#
# NOTE: See also, ${T}, below.
#
# There are some paths that do NOT call under ${PREFIX}, such as
# ${CALCPATH}, that include paths not under ${PREFIX}, but those
# too are exceptions to this general rule.
#
# When in doubt, try:
#
# PREFIX= /usr/local
#
PREFIX= /usr/local
#PREFIX= /usr
#PREFIX= /usr/global
# 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.
#
CCBAN= -UUNBAN
#CCBAN= -DUNBAN
#if 0 /* start of skip for non-Gnu makefiles */
# Unfortunately due to the complex dependency issues between
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
# is NOT recommended. Sorry.
#
.NOTPARALLEL:
##############################################################################
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
##############################################################################
# NOTE: You can force a target value by defining target as in:
#
# make ...__optional_arguments_... target=value
# Try uname -s if the target was not already set on the make command line
#
ifeq ($(target),)
target=$(shell uname -s 2>/dev/null)
endif
#endif /* end of skip for non-Gnu makefiles */
##############################################################################
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
##############################################################################
# The custom calc resource files to install
#
# Put your custom calc resource files here.
#
CUSTOM_CALC_FILES= argv.cal halflen.cal pzasusb8.cal pmodm127.cal register.cal
# The custom help files to install
#
# Put your custom help files here.
#
CUSTOM_HELP= argv devnull help sysinfo pzasusb8 pmodm127 register
# Any .h files that are needed by programs that use
# libcustcalc${LIB_EXT_VERSION}
#
# Put any .h files that you add which might be useful to other
# programs here.
#
CUSTOM_H_SRC=
# Any .c files that are needed to build libcustcalc${LIB_EXT_VERSION}.
#
# Don't put ${REQUIRED_SRC} files in this list.
#
# There MUST be a .c in CUSTOM_SRC for every .o in CUSTOM_OBJ.
#
# Put your custom .c files here.
#
CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c c_pzasusb8.c \
c_pmodm127.c c_register.c
# Any .o files that are needed by program that use
# libcustcalc${LIB_EXT_VERSION}.
#
# Don't put ${REQUIRED_OBJ} files in this list.
#
# There MUST be a .c in CUSTOM_SRC for every .o in CUSTOM_OBJ.
#
# Put your custom .o files here.
#
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
c_pmodm127.o c_register.o
##############################################################################
#-=-=-=-=-=-=- Defaults in case you want to build from this dir -=-=-=-=-=-=-#
##############################################################################
# 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)
#
# H=@: do not report hsrc file formation progress
# H=@ do echo hsrc file formation progress
#
# S= >/dev/null 2>&1 silence ${CC} output during hsrc file formation
# S= full ${CC} output during hsrc file formation
#
# E= 2>/dev/null silence 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
# a default here just in case you want to build from this directory.
####
# Where the system include (.h) files are kept
#
# For DJGPP, select:
#
# INCDIR= /dev/env/DJDIR/include
#
# If in doubt, set:
#
# INCDIR= /usr/include
#
#INCDIR= ${PREFIX}/include
#INCDIR= /dev/env/DJDIR/include
INCDIR= /usr/include
# where to install calc related things
#
# ${BINDIR} where to install calc binary files
# ${LIBDIR} where calc link library (*.a) files are installed
# ${CALC_SHAREDIR} where to install calc help, .cal, startup, config files
#
# NOTE: The install rule prepends installation paths with ${T}, which
# by default is empty. If ${T} is non-empty, then installation
# locations will be relative to the ${T} directory.
#
# For DJGPP, select:
#
# BINDIR= /dev/env/DJDIR/bin
# LIBDIR= /dev/env/DJDIR/lib
# CALC_SHAREDIR= /dev/env/DJDIR/share/calc
#
# If in doubt, set:
#
# BINDIR= /usr/bin
# LIBDIR= /usr/lib
# CALC_SHAREDIR= /usr/share/calc
#
#BINDIR= ${PREFIX}/bin
#BINDIR= /dev/env/DJDIR/bin
BINDIR= /usr/bin
#LIBDIR= ${PREFIX}/lib
#LIBDIR= /dev/env/DJDIR/lib
LIBDIR= /usr/lib
#CALC_SHAREDIR= ${PREFIX}/lib/calc
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
CALC_SHAREDIR= /usr/share/calc
# By default, these values are based CALC_SHAREDIR, INCDIR, BINDIR
# ---------------------------------------------------------------
# ${HELPDIR} where the help directory is installed
# ${CALC_INCDIR} where the calc include files are installed
# ${CUSTOMCALDIR} where custom *.cal files are installed
# ${CUSTOMHELPDIR} where custom help files are installed
# ${CUSTOMINCDIR} where custom .h files are installed
# ${SCRIPTDIR} where calc shell scripts are installed
#
# NOTE: The install rule prepends installation paths with ${T}, which
# by default is empty. If ${T} is non-empty, then installation
# locations will be relative to the ${T} directory.
#
# If in doubt, set:
#
# HELPDIR= ${CALC_SHAREDIR}/help
# CALC_INCDIR= ${INCDIR}/calc
# CUSTOMCALDIR= ${CALC_SHAREDIR}/custom
# CUSTOMHELPDIR= ${CALC_SHAREDIR}/custhelp
# CUSTOMINCDIR= ${CALC_INCDIR}/custom
# SCRIPTDIR= ${BINDIR}/cscript
#
HELPDIR= ${CALC_SHAREDIR}/help
CALC_INCDIR= ${INCDIR}/calc
CUSTOMCALDIR= ${CALC_SHAREDIR}/custom
CUSTOMHELPDIR= ${CALC_SHAREDIR}/custhelp
CUSTOMINCDIR= ${CALC_INCDIR}/custom
SCRIPTDIR= ${BINDIR}/cscript
# T - top level directory under which calc will be installed
#
# The calc install is performed under ${T}, the calc build is
# performed under /. The purpose for ${T} is to allow someone
# to install calc somewhere other than into the system area.
#
# For example, if:
#
# BINDIR= /usr/bin
# LIBDIR= /usr/lib
# CALC_SHAREDIR= /usr/share/calc
#
# and if:
#
# T= /var/tmp/testing
#
# Then the installation locations will be:
#
# calc binary files: /var/tmp/testing/usr/bin
# calc link library: /var/tmp/testing/usr/lib
# calc help, .cal ...: /var/tmp/testing/usr/share/calc
# ... etc ... /var/tmp/testing/...
#
# If ${T} is empty, calc is installed under /, which is the same
# top of tree for which it was built. If ${T} is non-empty, then
# calc is installed under ${T}, as if one had to chroot under
# ${T} for calc to operate.
#
# If in doubt, use T=
#
T=
# Debug/Optimize options for ${CC} and ${LCC}
#
# Select DEBUG= -O2 -gstabs+ -D_WIN32 for DJGPP.
#
#DEBUG=
#
#DEBUG= -O
#DEBUG= -O -g
#DEBUG= -O -g3
#
#DEBUG= -O1
#DEBUG= -O1 -g
#DEBUG= -O1 -g3
#
#DEBUG= -O2
#DEBUG= -O2 -g
#DEBUG= -O2 -g3
#DEBUG= -O2 -ipa
#DEBUG= -O2 -g3 -ipa
#
#DEBUG= -O3
#DEBUG= -O3 -g
DEBUG= -O3 -g3
#DEBUG= -O3 -ipa
#DEBUG= -O3 -g3 -ipa
#
#DEBUG= -g
#DEBUG= -g3
#DEBUG= -gx
#DEBUG= -WM,-g
#
#DEBUG= -O2 -gstabs+ -D_WIN32
# Some systems require one to use ranlib to add a symbol table to
# a *.a link library. Set RANLIB to the utility that performs this
# action. Set RANLIB to : if your system does not need such a utility.
#
RANLIB=ranlib
#RANLIB=:
# Normally certain files depend on the Makefile. If the Makefile is
# changed, then certain steps should be redone. If MAKE_FILE is
# set to Makefile, then these files will depend on Makefile. If
# MAKE_FILE is empty, then they wont.
#
# If in doubt, set MAKE_FILE to Makefile
#
MAKE_FILE= Makefile
#MAKE_FILE=
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# If you do not wish to use purify, set PURIFY to an empty string.
#
# If in doubt, use PURIFY=
#
#PURIFY= purify
#PURIFY= purify -m71-engine
#PURIFY= purify -logfile=pure.out
#PURIFY= purify -m71-engine -logfile=pure.out
PURIFY=
# If you want to use a debugging link library such as a malloc debug link
# library, or need to add special ld flags after the calc link libraries
# are included, set ${LD_DEBUG} below.
#
# If in doubt, set LD_DEBUG to empty.
#
#LD_DEBUG= -lmalloc_cv
LD_DEBUG=
# When doing a:
#
# make check
# make chk
# make debug
#
# the ${CALC_ENV} is used to supply the proper environment variables
# to calc. Most people will simply need 'CALCPATH=./cal' to ensure
# that these debug rules will only use calc resource files under the
# local source directory. The longer lines (with MALLOC_VERBOSE=1 ...)
# are useful for SGI IRIX people who have 'WorkShop Performance Tools'
# and who also set 'LD_DEBUG= -lmalloc_cv' above.
#
# If in doubt, use CALC_ENV= CALCPATH=./cal.
#
CALC_ENV= CALCPATH=./cal
#CALC_ENV= CALCPATH=./cal MALLOC_VERBOSE=1 MALLOC_TRACING=1 \
# MALLOC_FASTCHK=1 MALLOC_FULLWARN=1
#CALC_ENV= CALCPATH=./cal MALLOC_VERBOSE=1 MALLOC_TRACING=1 \
# MALLOC_FASTCHK=1 MALLOC_FULLWARN=1 MALLOC_CLEAR_FREE=1 \
# MALLOC_CLEAR_MALLOC=1
# By default, custom builtin functions may only be executed if calc
# is given the -C option. This is because custom builtin functions
# may invoke non-standard or non-portable code. One may completely
# disable custom builtin functions by not compiling any of code
#
# ALLOW_CUSTOM= -DCUSTOM # allow custom only if -C is given
# ALLOW_CUSTOM= # disable custom even if -C is given
#
# If in doubt, use ALLOW_CUSTOM= -DCUSTOM
#
ALLOW_CUSTOM= -DCUSTOM
#ALLOW_CUSTOM=
# Some out of date operating systems require / want an executable to
# end with a certain file extension. Some compile systems such as
# Cygwin build calc as calc.exe. The EXT variable is used to denote
# the extension required by such.
#
# EXT= # normal Un*x / Linux / GNU/Linux systems
# EXT=.exe # Windows / Cygwin
#
# If in doubt, use EXT=
#
EXT=
#EXT=.exe
# The default calc versions
#
VERSION= 2.14.0.12
# Names of shared libraries with versions
#
LIB_EXT= .so
LIB_EXT_VERSION= ${LIB_EXT}.${VERSION}
# standard tools
#
AR= ar
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
TAIL= tail
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
#
# Both CFLAGS and LDFLAGS are left blank in this Makefile by
# default so that users may use them on the make command line
# to always the way that C is compiled and files are linked
# respectively. For example:
#
# make all EXTRA_CFLAGS="-DMAGIC" EXTRA_LDFLAGS="-lmagic"
#
# NOTE: These should be left blank in this Makefile to make it
# easier to add stuff on the command line. If you want to
# to change the way calc is compiled by this Makefile, change
# the appropriate host target section below or a flag above.
#
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
# COMMON_CFLAGS are the common ${CC} flags used for all progs, both
# intermediate and final calc and calc related progs
#
COMMON_CFLAGS= -DCALC_SRC ${ALLOW_CUSTOM} ${CCWARN} ${CCMISC} ${EXTRA_CFLAGS}
# COMMON_LDFLAGS are the common flags used for linking all progs, both
# intermediate and final calc and calc related progs
#
COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
###########################################
# Set the default compile flags for ${CC} #
###########################################
#if 0 /* start of skip for non-Gnu makefiles */
# Required flags to compile C files for calc
#
# ICFLAGS are given to ${CC} for intermediate progs used to help compile calc
# CFLAGS are given to ${CC} for calc progs other than intermediate progs
#
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
#
ifeq ($(BLD_TYPE),calc-static-only)
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
else
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
endif
CFLAGS= ${ICFLAGS} ${CCOPT}
# Required flags to link files for calc
#
# ILDFLAGS for ${CC} in linking intermediate progs used to help compile calc
# LDFLAGS for ${CC} in linking calc progs other than intermediate progs
#
ILDFLAGS= ${COMMON_LDFLAGS}
LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
#endif /* end of skip for non-Gnu makefiles */
##################################################
# NOTE: End of section from custom/Makefile.head #
##################################################

View File

@@ -4,7 +4,7 @@
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: non-GNU Makefile via make -f Makefile custom/Makefile.simple
# SRC: custom/Makefile.simple - non-GNU version
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
@@ -35,11 +35,6 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
####################################################
# NOTE: Start of section from custom/Makefile.head #
####################################################
# The shell used by this Makefile
#
@@ -130,10 +125,6 @@ CCBAN= -UUNBAN
##############################################################################
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
##############################################################################
# The custom calc resource files to install
#
# Put your custom calc resource files here.
@@ -177,6 +168,10 @@ CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c c_pzasusb8.c \
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
c_pmodm127.o c_register.o
##############################################################################
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
##############################################################################
##############################################################################
#-=-=-=-=-=-=- Defaults in case you want to build from this dir -=-=-=-=-=-=-#
##############################################################################
@@ -381,15 +376,6 @@ RANLIB=ranlib
MAKE_FILE= Makefile
#MAKE_FILE=
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# If you do not wish to use purify, set PURIFY to an empty string.
#
# If in doubt, use PURIFY=
@@ -459,7 +445,7 @@ EXT=
# The default calc versions
#
VERSION= 2.14.0.12
VERSION= 2.14.1.3
# Names of shared libraries with versions
#
@@ -474,9 +460,11 @@ CHMOD= chmod
CMP= cmp
CO= co
CP= cp
DIFF= diff
FMT= fmt
GREP= egrep
LN= ln
LS= ls
MAKE= make
MAKEDEPEND= makedepend
MKDIR= mkdir
@@ -522,14 +510,19 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
###########################################
##################################################
# NOTE: End of section from custom/Makefile.head #
##################################################
# start of host target cut - Do not remove this line
##########################################################################
#=-=-=-=-=- Be careful if you change something below this line -=-=-=-=-=#
##########################################################################
###########################################################
# NOTE: Start of section from the middle of Makefile.ship #
###########################################################
# include start from top Makefile - keep this line
######################################################
# NOTE: Start of section from the middle of Makefile #
# #
# These lines are shared in common with the lower #
# custom/Makefile. That is, until the comment line #
# that starts with '# NOTE: End of section ..' line, #
# these Makefile lines are used in BOTH Makefiles. #
######################################################
##############################################################################
#-=-=-=-=-=- host target section - targets that override defaults -=-=-=-=-=-#
@@ -618,7 +611,8 @@ LD_STATIC=
LIBCALC_STATIC=
LIBCUSTCALC_STATIC=
#
CCWARN= -Wall
#CCWARN= -Wall
CCWARN= -Wall -Wextra -pedantic
WNO_IMPLICT= -Wno-implicit
WNO_ERROR_LONG_LONG= -Wno-error=long-long
WNO_LONG_LONG= -Wno-long-long
@@ -647,29 +641,15 @@ LDFLAGS= ${LD_DEBUG} ${ILDFLAGS} ${LIBCALC_STATIC} ${LIBCUSTCALC_STATIC}
#-=-=-=-=-=- end of target section - only make rules below -=-=-=-=-=-#
#######################################################################
#########################################################
# NOTE: End of section from the middle of Makefile.ship #
#########################################################
# end of host target cut - Do not remove this line
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: non-GNU Makefile via make -f Makefile custom/Makefile.simple
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
####################################################
# NOTE: Start of section from custom/Makefile.tail #
####################################################
##############################################################################
#-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-#
##############################################################################
######################################################
# NOTE: End of section from the middle of Makefile #
# #
# These lines are shared in common with the lower #
# custom/Makefile. That is, starting with the line #
# that starts with '# NOTE: End of section ..' line, #
# these Makefile lines are used in BOTH Makefiles. #
######################################################
# include end from top Makefile - keep this line
# These .c files are required for the main custom interface and
# for the custom support functions for libcustcalc${LIB_EXT_VERSION}.
@@ -711,8 +691,7 @@ H_SRC= ${CUSTOM_H_SRC}
# directory but are installed as help files from the help/Makefile.
#
DISTLIST= ${CUSTCALC_SRC} ${CUSTOM_CALC_FILES} ${CUSTOM_HELP} \
${INSTALL_H_SRC} CUSTOM_CAL HOW_TO_ADD ${MAKE_FILE}.head \
${MAKE_FILE}.tail
${INSTALL_H_SRC} CUSTOM_CAL HOW_TO_ADD Makefile Makefile.simple
# These files are used to make (but not built) a calc .a link library
#
@@ -732,7 +711,7 @@ TARGETS= ${BLD_TYPE} Makefile.simple
###
#
# The reason for this Makefile :-)
# The main reason for this Makefile :-)
#
###
@@ -851,8 +830,8 @@ depend:
>> "skel/custom/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q} (cd ..; ${MAKE} -f ${TOP_MAKE_FILE} hsrc)
${MAKE} -f ../${TOP_MAKE_FILE} h_list 2>/dev/null | \
${Q} (cd ..; ${MAKE} -f ${MAKE_FILE} hsrc)
${MAKE} -f ../${MAKE_FILE} h_list 2>/dev/null | \
while read i; do \
if [ ! -f "../$$i" ]; then continue; fi; \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
@@ -887,7 +866,6 @@ 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} ${TAIL} -4 ${MAKE_FILE}.tail >> ${MAKE_FILE}
${Q} echo removing skel
${Q} ${RM} -rf skel
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
@@ -1188,6 +1166,7 @@ uninstall:
# DO NOT DELETE THIS LINE -- make depend depends on it.
c_argv.o: ../alloc.h
c_argv.o: ../attribute.h
c_argv.o: ../banned.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
@@ -1215,6 +1194,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: ../attribute.h
c_devnull.o: ../banned.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
@@ -1242,6 +1222,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: ../attribute.h
c_help.o: ../banned.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
@@ -1269,6 +1250,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: ../attribute.h
c_pmodm127.o: ../banned.h
c_pmodm127.o: ../block.h
c_pmodm127.o: ../byteswap.h
@@ -1295,6 +1277,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: ../attribute.h
c_pzasusb8.o: ../banned.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
@@ -1321,6 +1304,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: ../attribute.h
c_register.o: ../banned.h
c_register.o: ../block.h
c_register.o: ../byteswap.h
@@ -1348,6 +1332,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: ../attribute.h
c_sysinfo.o: ../banned.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
@@ -1382,6 +1367,7 @@ c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../attribute.h
custtbl.o: ../banned.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
@@ -1406,11 +1392,3 @@ custtbl.o: ../str.h
custtbl.o: ../value.h
custtbl.o: ../zmath.h
custtbl.o: custtbl.c
##################################################
# NOTE: End of section from custom/Makefile.tail #
##################################################
Makefile.simple:
${Q} if [ ! -f Makefile.simple ]; then \
${CP} -f ${MAKE_FILE} $@; fi

View File

@@ -1,794 +0,0 @@
#
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
#
# SRC: custom/Makefile.tail
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
####################################################
# NOTE: Start of section from custom/Makefile.tail #
####################################################
##############################################################################
#-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-#
##############################################################################
# These .c files are required for the main custom interface and
# for the custom support functions for libcustcalc${LIB_EXT_VERSION}.
#
# There MUST be a .c for every .o in REQUIRED_OBJ.
#
REQUIRED_SRC= custtbl.c
# These .o files correspond to the .c files in REQUIRED_SRC
# for libcustcalc${LIB_EXT_VERSION}.
#
# There MUST be a .o for every .c in REQUIRED_SRC.
#
REQUIRED_OBJ= custtbl.o
# These .h files are installed under ${CUSTOMCALDIR} by the install rule.
#
INSTALL_H_SRC= ${CUSTOM_H_SRC}
# These .c files are used to form libcustcalc${LIB_EXT_VERSION}.
#
CUSTCALC_SRC= ${REQUIRED_SRC} ${CUSTOM_SRC}
# These .o files are used to form libcustcalc${LIB_EXT_VERSION}.
#
CUSTCALC_OBJ= ${REQUIRED_OBJ} ${CUSTOM_OBJ}
# These .c files are used to build the dependency list
#
C_SRC= ${REQUIRED_SRC} ${CUSTOM_SRC}
# These .h files are used to build the dependency list
#
H_SRC= ${CUSTOM_H_SRC}
# These files are found (but not built) in the distribution
#
# The CUSTOM_CAL and HOW_TO_ADD are files distributed from this
# directory but are installed as help files from the help/Makefile.
#
DISTLIST= ${CUSTCALC_SRC} ${CUSTOM_CALC_FILES} ${CUSTOM_HELP} \
${INSTALL_H_SRC} CUSTOM_CAL HOW_TO_ADD ${MAKE_FILE}.head \
${MAKE_FILE}.tail
# These files are used to make (but not built) a calc .a link library
#
CALCLIBLIST= ${CUSTCALC_SRC} ${INSTALL_H_SRC} ${MAKE_FILE} HOW_TO_ADD
# This is the custom dynamic shared library that is build
#
CALC_DYNAMIC_LIBCUSTCALC= libcustcalc${LIB_EXT_VERSION}
# This is the custom static library that is build
#
CALC_STATIC_LIBCUSTCALC= libcustcalc.a
# complete list of targets
#
TARGETS= ${BLD_TYPE} Makefile.simple
###
#
# The reason for this Makefile :-)
#
###
all: ${TARGETS} ${INSTALL_H_SRC} ${CUSTOM_CALC_FILES} \
${CUSTOM_HELP} ${MAKE_FILE} .all
calc-dynamic-only: ${CUSTCALC_OBJ} ${CALC_DYNAMIC_LIBCUSTCALC}
calc-static-only: ${CUSTCALC_OBJ} ${CALC_STATIC_LIBCUSTCALC}
custom/libcustcalc${LIB_EXT_VERSION}: libcustcalc${LIB_EXT_VERSION} \
${CALC_STATIC_LIBCUSTCALC}
libcustcalc${LIB_EXT_VERSION}: ${CUSTCALC_OBJ} ${MAKE_FILE}
${CC} ${LIBCUSTCALC_SHLIB} ${CUSTCALC_OBJ} -o $@
##
#
# Special .o files
#
##
c_sysinfo.o: c_sysinfo.c ${MAKE_FILE}
${CC} ${CFLAGS} c_sysinfo.c -c
##
#
# used by the upper level Makefile
#
##
# to determine of we have done all
#
.all:
${RM} -f .all
${TOUCH} .all
###
#
# building calc-static and static lib*.a libraries
#
###
libcustcalc.a: ${CUSTCALC_OBJ} ${MAKE_FILE}
${RM} -f libcustcalc.a
${AR} qc libcustcalc.a ${CUSTCALC_OBJ}
${RANLIB} libcustcalc.a
${CHMOD} 0644 libcustcalc.a
##
#
# File list generation. You can ignore this section.
#
#
# We will form the names of source files as if they were in a
# sub-directory called calc/lib.
#
# NOTE: Due to bogus shells found on one common system we must have
# an non-empty else clause for every if condition. *sigh*
#
##
distlist: ${DISTLIST}
${Q} for i in ${DISTLIST} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo custom/$$i; \
fi; \
done
distdir:
${Q} echo custom
calcliblist: ${CALCLIBLIST}
${Q} for i in ${CALCLIBLIST} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo custom/$$i; \
fi; \
done
#if 0 /* start of skip for non-Gnu makefiles */
Makefile.simple: Makefile ../Makefile ../Makefile.ship
${V} echo '=-=-=-=-= custom/${MAKE_FILE} start of $@ rule =-=-=-=-='
${Q} if [ -f $@.bak ]; then \
echo "custom/$@.bak exists, remove or move it"; \
exit 1; \
else \
${TRUE}; \
fi
-${Q} if [ -f $@ ]; then \
${MV} -f $@ $@.bak; \
fi
${Q} ${AWK} '/^#if 0/{skp=1} {if(!skp){print $$0}} /^#endif/{skp=0}' \
Makefile | \
${GREP} -v '#\.#' | \
${SED} -e 's;^# SRC:.*;# SRC: non-GNU Makefile via;' \
-e 's;via$$;via ${MAKE} -f ${MAKE_FILE} custom/$@;' > $@
${Q} echo >> $@
${Q} echo 'Makefile.simple:' >> $@
${Q} echo ' $${Q} if [ ! -f Makefile.simple ]; then '"\\" >> $@
${Q} echo ' $${CP} -f $${MAKE_FILE} $$@; fi' >> $@
-${Q} if [ -s $@.bak ]; then \
if ${CMP} -s $@.bak $@; then \
echo 'custom/$@ was already up to date'; \
echo 'restoring original custom/$@'; \
${MV} -f $@.bak $@; \
else \
echo 'old custom/$@ is now custom/$@.bak'; \
echo 'updated custom/$@ formed'; \
echo 'try: diff -u custom/$@.bak custom/$@'; \
fi; \
else \
echo 'new custom/$@ formed'; \
fi
${V} echo '=-=-=-=-= custom/${MAKE_FILE} end of $@ rule =-=-=-=-='
#endif /* end of skip for non-Gnu makefiles */
##
#
# Home grown make dependency rules. Your system make not support
# or have the needed tools. You can ignore this section.
#
# We will form a skeleton tree of *.c files containing only #include "foo.h"
# lines and .h files containing the same lines surrounded by multiple include
# prevention lines. This allows us to build a static depend list that will
# satisfy all possible cpp symbol definition combinations.
#
##
depend:
${Q} if [ -f ${MAKE_FILE}.bak ]; then \
echo "custom/${MAKE_FILE}.bak exists, remove or move it"; \
exit 1; \
else \
${TRUE}; \
fi
${Q} echo forming custom/skel
${Q} ${RM} -rf skel
${Q} ${MKDIR} -p skel
${Q} ${MKDIR} -p skel/custom
-${Q} for i in ${C_SRC} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
${SED} -n '/^#[ ]*include[ ]*"/p' \
"$$i" > "skel/custom/$$i"; \
fi; \
done
-${Q} for i in ${H_SRC} /dev/null; do \
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"; \
${SED} -n '/^#[ ]*include[ ]*"/p' "$$i" \
>> "skel/custom/$$i"; \
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q} (cd ..; ${MAKE} -f ${TOP_MAKE_FILE} hsrc)
${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 skel/custom/makedep.in
${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 -- \
${CFLAGS} -- \
${C_SRC} 2>/dev/null
${Q} ${CP} -f skel/custom/makedep.out skel/custom/makedep.in
${Q} ${SED} -e 's|: ../../|: |' -E < skel/custom/makedep.in | \
${GREP} -v /usr/include > 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/'; \
fi; \
done >> skel/custom/makedep.out
${Q} LANG=C ${SORT} -u skel/custom/makedep.out \
-o skel/custom/makedep.out
${Q} echo custom dependency list formed
${Q} echo forming new custom/${MAKE_FILE}
${Q} ${RM} -f ${MAKE_FILE}.bak
${Q} ${MV} ${MAKE_FILE} ${MAKE_FILE}.bak
${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} ${TAIL} -4 ${MAKE_FILE}.tail >> ${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 'restoring original custom/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
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
##
#
# rpm rules
#
##
echo_inst_files:
${Q} for i in ${INSTALL_H_SRC} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo __file__ ${CUSTOMINCDIR}/$$i; \
fi; \
done
${Q} for i in ${CUSTOM_HELP} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo __file__ ${CUSTOMHELPDIR}/$$i; \
fi; \
done
${Q} for i in ${CUSTOM_CALC_FILES} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo __file__ ${CUSTOMCALDIR}/$$i; \
fi; \
done
${Q} for i in ${CALC_DYNAMIC_LIBCUSTCALC} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
echo __file__ ${CUSTOMCALDIR}/$$i; \
fi; \
done
##
#
# Utility rules
#
##
clean:
${RM} -f ${CUSTCALC_OBJ}
clobber: clean
${RM} -f ${BLD_TYPE}
${RM} -f .all ${MAKE_FILE}.tmp ${MAKE_FILE}.bak
${RM} -f libcustcalc${LIB_EXT_VERSION}
${RM} -f libcustcalc${LIB_EXT}
${RM} -f libcustcalc.a
${RM} -f libcustcalc*
${RM} -rf skel
${V} echo remove files that are obsolete
-${Q} if [ -e .DS_Store ]; then \
echo ${RM} -rf .DS_Store; \
${RM} -rf .DS_Store; \
fi
# install everything
#
# NOTE: Keep the uninstall rule in reverse order to the install rule
#
install: all
-${Q} if [ ! -d ${T}${LIBDIR} ]; then \
echo ${MKDIR} -p ${T}${LIBDIR}; \
${MKDIR} -p ${T}${LIBDIR}; \
if [ ! -d "${T}${LIBDIR}" ]; then \
echo ${MKDIR} -p "${T}${LIBDIR}"; \
${MKDIR} -p "${T}${LIBDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${LIBDIR}; \
${CHMOD} 0755 ${T}${LIBDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${INCDIR} ]; then \
echo ${MKDIR} -p ${T}${INCDIR}; \
${MKDIR} -p ${T}${INCDIR}; \
if [ ! -d "${T}${INCDIR}" ]; then \
echo ${MKDIR} -p "${T}${INCDIR}"; \
${MKDIR} -p "${T}${INCDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${INCDIR}; \
${CHMOD} 0755 ${T}${INCDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${CALC_SHAREDIR} ]; then \
echo ${MKDIR} -p ${T}${CALC_SHAREDIR}; \
${MKDIR} -p ${T}${CALC_SHAREDIR}; \
if [ ! -d "${T}${CALC_SHAREDIR}" ]; then \
echo ${MKDIR} -p "${T}${CALC_SHAREDIR}"; \
${MKDIR} -p "${T}${CALC_SHAREDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${CALC_SHAREDIR}; \
${CHMOD} 0755 ${T}${CALC_SHAREDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${CALC_INCDIR} ]; then \
echo ${MKDIR} -p ${T}${CALC_INCDIR}; \
${MKDIR} -p ${T}${CALC_INCDIR}; \
if [ ! -d "${T}${CALC_INCDIR}" ]; then \
echo ${MKDIR} -p "${T}${CALC_INCDIR}"; \
${MKDIR} -p "${T}${CALC_INCDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${CALC_INCDIR}; \
${CHMOD} 0755 ${T}${CALC_INCDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${HELPDIR} ]; then \
echo ${MKDIR} -p ${T}${HELPDIR}; \
${MKDIR} -p ${T}${HELPDIR}; \
if [ ! -d "${T}${HELPDIR}" ]; then \
echo ${MKDIR} -p "${T}${HELPDIR}"; \
${MKDIR} -p "${T}${HELPDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${HELPDIR}; \
${CHMOD} 0755 ${T}${HELPDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${CUSTOMCALDIR} ]; then \
echo ${MKDIR} -p ${T}${CUSTOMCALDIR}; \
${MKDIR} -p ${T}${CUSTOMCALDIR}; \
if [ ! -d "${T}${CUSTOMCALDIR}" ]; then \
echo ${MKDIR} -p "${T}${CUSTOMCALDIR}"; \
${MKDIR} -p "${T}${CUSTOMCALDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${CUSTOMCALDIR}; \
${CHMOD} 0755 ${T}${CUSTOMCALDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${CUSTOMHELPDIR} ]; then \
echo ${MKDIR} -p ${T}${CUSTOMHELPDIR}; \
${MKDIR} -p ${T}${CUSTOMHELPDIR}; \
if [ ! -d "${T}${CUSTOMHELPDIR}" ]; then \
echo ${MKDIR} -p "${T}${CUSTOMHELPDIR}"; \
${MKDIR} -p "${T}${CUSTOMHELPDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${CUSTOMHELPDIR}; \
${CHMOD} 0755 ${T}${CUSTOMHELPDIR}; \
else \
${TRUE}; \
fi
-${Q} if [ ! -d ${T}${CUSTOMINCDIR} ]; then \
echo ${MKDIR} -p ${T}${CUSTOMINCDIR}; \
${MKDIR} -p ${T}${CUSTOMINCDIR}; \
if [ ! -d "${T}${CUSTOMINCDIR}" ]; then \
echo ${MKDIR} -p "${T}${CUSTOMINCDIR}"; \
${MKDIR} -p "${T}${CUSTOMINCDIR}"; \
fi; \
echo ${CHMOD} 0755 ${T}${CUSTOMINCDIR}; \
${CHMOD} 0755 ${T}${CUSTOMINCDIR}; \
else \
${TRUE}; \
fi
-${Q} for i in ${INSTALL_H_SRC} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if ${CMP} -s "$$i" ${T}${CUSTOMINCDIR}/$$i; then \
${TRUE}; \
else \
${RM} -f ${T}${CUSTOMINCDIR}/$$i.new; \
${CP} -f $$i ${T}${CUSTOMINCDIR}/$$i.new; \
${CHMOD} 0444 ${T}${CUSTOMINCDIR}/$$i.new; \
${MV} -f ${T}${CUSTOMINCDIR}/$$i.new ${T}${CUSTOMINCDIR}/$$i; \
echo "installed ${T}${CUSTOMINCDIR}/$$i"; \
fi; \
done
-${Q} for i in ${CUSTOM_CALC_FILES} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if ${CMP} -s $$i ${T}${CUSTOMCALDIR}/$$i; then \
${TRUE}; \
else \
${RM} -f ${T}${CUSTOMCALDIR}/$$i.new; \
${CP} -f $$i ${T}${CUSTOMCALDIR}/$$i.new; \
${CHMOD} 0444 ${T}${CUSTOMCALDIR}/$$i.new; \
${MV} -f ${T}${CUSTOMCALDIR}/$$i.new ${T}${CUSTOMCALDIR}/$$i; \
echo "installed ${T}${CUSTOMCALDIR}/$$i"; \
fi; \
done
-${Q} for i in ${CUSTOM_HELP} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if ${CMP} -s $$i ${T}${CUSTOMHELPDIR}/$$i; then \
${TRUE}; \
else \
${RM} -f ${T}${CUSTOMHELPDIR}/$$i.new; \
${CP} -f $$i ${T}${CUSTOMHELPDIR}/$$i.new; \
${CHMOD} 0444 ${T}${CUSTOMHELPDIR}/$$i.new; \
${MV} -f ${T}${CUSTOMHELPDIR}/$$i.new \
${T}${CUSTOMHELPDIR}/$$i; \
echo "installed ${T}${CUSTOMHELPDIR}/$$i"; \
fi; \
done
-${Q} if [ -f "${T}${CUSTOMCALDIR}/libcustcalc.a" ]; then \
${RM} -f ${T}${CUSTOMCALDIR}/libcustcalc.a; \
echo "removed old ${T}${CUSTOMCALDIR}/libcustcalc.a"; \
fi
-${Q} if [ ! -z ${ALLOW_CUSTOM} ]; then \
if [ -f libcustcalc.a ]; then \
if ${CMP} -s libcustcalc.a ${T}${LIBDIR}/libcustcalc.a; then \
${TRUE}; \
else \
${RM} -f ${T}${LIBDIR}/libcustcalc.a.new; \
${CP} -f libcustcalc.a ${T}${LIBDIR}/libcustcalc.a.new; \
${CHMOD} 0644 ${T}${LIBDIR}/libcustcalc.a.new; \
${MV} -f ${T}${LIBDIR}/libcustcalc.a.new \
${T}${LIBDIR}/libcustcalc.a; \
${RANLIB} ${T}${LIBDIR}/libcustcalc.a; \
echo "installed ${T}${LIBDIR}/libcustcalc.a"; \
fi; \
fi; \
fi
${Q}# NOTE: The upper level makefile installs the file
${Q}# libcustcalc${LIB_EXT_VERSION} because we only want to
${Q}# perform one ${LDCONFIG} for both libcalc${LIB_EXT_VERSION}
${Q}# and libcustcalc${LIB_EXT_VERSION}.
# Try to remove everything that was installed
#
# NOTE: Keep the uninstall rule in reverse order to the install rule
#
uninstall:
-${Q} if [ -f "${T}${CUSTOMCALDIR}/libcustcalc.a" ]; then \
${RM} -f "${T}${CUSTOMCALDIR}/libcustcalc.a"; \
if [ -f "${T}${CUSTOMCALDIR}/libcustcalc.a" ]; then \
echo "cannot uninstall ${T}${CUSTOMCALDIR}/libcustcalc.a"; \
else \
echo "un-installed ${T}${CUSTOMCALDIR}/libcustcalc.a"; \
fi; \
fi
-${Q} for i in ${CUSTOM_HELP} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if [ -f "${T}${CUSTOMHELPDIR}/$$i" ]; then \
${RM} -f "${T}${CUSTOMHELPDIR}/$$i"; \
if [ -f "${T}${CUSTOMHELPDIR}/$$i" ]; then \
echo "cannot uninstall ${T}${CUSTOMHELPDIR}/$$i"; \
else \
echo "un-installed ${T}${CUSTOMHELPDIR}/$$i"; \
fi; \
fi; \
done
-${Q} for i in ${CUSTOM_CALC_FILES} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if [ -f "${T}${CUSTOMCALDIR}/$$i" ]; then \
${RM} -f "${T}${CUSTOMCALDIR}/$$i"; \
if [ -f "${T}${CUSTOMCALDIR}/$$i" ]; then \
echo "cannot uninstall ${T}${CUSTOMCALDIR}/$$i"; \
else \
echo "un-installed ${T}${CUSTOMCALDIR}/$$i"; \
fi; \
fi; \
done
-${Q} for i in ${INSTALL_H_SRC} /dev/null; do \
if [ "$$i" = "/dev/null" ]; then \
continue; \
fi; \
if [ -f "${T}${CUSTOMINCDIR}/$$i" ]; then \
${RM} -f "${T}${CUSTOMINCDIR}/$$i"; \
if [ -f "${T}${CUSTOMINCDIR}/$$i" ]; then \
echo "cannot uninstall ${T}${CUSTOMINCDIR}/$$i"; \
else \
echo "un-installed ${T}${CUSTOMINCDIR}/$$i"; \
fi; \
fi; \
done
-${Q} for i in ${CUSTOMINCDIR} ${CUSTOMHELPDIR} ${CUSTOMCALDIR} \
${HELPDIR} ${CALC_INCDIR} ${CALC_SHAREDIR} ${INCDIR}; do \
if [ -d "${T}$$i" ]; then \
${RMDIR} "${T}$$i" 2>/dev/null; \
echo "cleaned up ${T}$$i"; \
fi; \
done
##
#
# make depend stuff
#
##
# 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
c_argv.o: ../calcerr.h
c_argv.o: ../cmath.h
c_argv.o: ../config.h
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
c_argv.o: ../have_stdlib.h
c_argv.o: ../have_string.h
c_argv.o: ../have_unused.h
c_argv.o: ../longbits.h
c_argv.o: ../nametype.h
c_argv.o: ../qmath.h
c_argv.o: ../sha1.h
c_argv.o: ../str.h
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
c_devnull.o: ../cmath.h
c_devnull.o: ../config.h
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
c_devnull.o: ../have_stdlib.h
c_devnull.o: ../have_string.h
c_devnull.o: ../have_unistd.h
c_devnull.o: ../have_unused.h
c_devnull.o: ../longbits.h
c_devnull.o: ../nametype.h
c_devnull.o: ../qmath.h
c_devnull.o: ../sha1.h
c_devnull.o: ../str.h
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
c_help.o: ../cmath.h
c_help.o: ../config.h
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
c_help.o: ../have_stdlib.h
c_help.o: ../have_string.h
c_help.o: ../have_unistd.h
c_help.o: ../have_unused.h
c_help.o: ../longbits.h
c_help.o: ../nametype.h
c_help.o: ../qmath.h
c_help.o: ../sha1.h
c_help.o: ../str.h
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
c_pmodm127.o: ../cmath.h
c_pmodm127.o: ../config.h
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
c_pmodm127.o: ../have_stdlib.h
c_pmodm127.o: ../have_string.h
c_pmodm127.o: ../have_unused.h
c_pmodm127.o: ../longbits.h
c_pmodm127.o: ../nametype.h
c_pmodm127.o: ../qmath.h
c_pmodm127.o: ../sha1.h
c_pmodm127.o: ../str.h
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
c_pzasusb8.o: ../cmath.h
c_pzasusb8.o: ../config.h
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
c_pzasusb8.o: ../have_stdlib.h
c_pzasusb8.o: ../have_string.h
c_pzasusb8.o: ../have_unused.h
c_pzasusb8.o: ../longbits.h
c_pzasusb8.o: ../nametype.h
c_pzasusb8.o: ../qmath.h
c_pzasusb8.o: ../sha1.h
c_pzasusb8.o: ../str.h
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
c_register.o: ../calcerr.h
c_register.o: ../cmath.h
c_register.o: ../config.h
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
c_register.o: ../have_stdlib.h
c_register.o: ../have_string.h
c_register.o: ../have_unused.h
c_register.o: ../longbits.h
c_register.o: ../nametype.h
c_register.o: ../qmath.h
c_register.o: ../sha1.h
c_register.o: ../str.h
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
c_sysinfo.o: ../calcerr.h
c_sysinfo.o: ../cmath.h
c_sysinfo.o: ../conf.h
c_sysinfo.o: ../config.h
c_sysinfo.o: ../custom.h
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
c_sysinfo.o: ../have_stdlib.h
c_sysinfo.o: ../have_string.h
c_sysinfo.o: ../have_unused.h
c_sysinfo.o: ../hist.h
c_sysinfo.o: ../lib_calc.h
c_sysinfo.o: ../longbits.h
c_sysinfo.o: ../nametype.h
c_sysinfo.o: ../prime.h
c_sysinfo.o: ../qmath.h
c_sysinfo.o: ../sha1.h
c_sysinfo.o: ../str.h
c_sysinfo.o: ../value.h
c_sysinfo.o: ../zmath.h
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
custtbl.o: ../cmath.h
custtbl.o: ../config.h
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
custtbl.o: ../have_stdlib.h
custtbl.o: ../have_string.h
custtbl.o: ../longbits.h
custtbl.o: ../nametype.h
custtbl.o: ../qmath.h
custtbl.o: ../sha1.h
custtbl.o: ../str.h
custtbl.o: ../value.h
custtbl.o: ../zmath.h
custtbl.o: custtbl.c
##################################################
# NOTE: End of section from custom/Makefile.tail #
##################################################

View File

@@ -1,7 +1,7 @@
/*
* c_help - custom help function
*
* Copyright (C) 1999-2004,2021 Landon Curt Noll
* Copyright (C) 1999-2004,2021,2022 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,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -70,7 +71,7 @@ c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
*/
if (vals[0]->v_type != V_STR) {
math_error("custom help arg 1 must be a string");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -1,7 +1,7 @@
/*
* c_pmodm127 - calculate q mod 2^(2^127-1)
*
* Copyright (C) 2004-2007,2021 Landon Curt Noll
* Copyright (C) 2004-2007,2021,2022 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
@@ -36,6 +36,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -88,15 +89,15 @@ c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric argument for pmodm127");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer argument for pmodm127");
/*NOTREACHED*/
not_reached();
}
if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) {
math_error("argument for pmodm127 <= 0");
/*NOTREACHED*/
not_reached();
}
/*
@@ -250,7 +251,7 @@ zmod5_or_zmod(ZVALUE *zp)
subcount++;
if (subcount > 2) {
math_error("Too many subtractions in zmod5_or_zmod");
/*NOTREACHED*/
not_reached();
}
j = modlen;
a = zp->v;

View File

@@ -1,7 +1,7 @@
/*
* c_pzasusb8 - print numerator as a string of USB8s
*
* Copyright (C) 1999-2004,2021 Ernest Bowen
* Copyright (C) 1999-2004,2021,2022 Ernest Bowen
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -67,7 +68,7 @@ c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-real argument for pzasusb8");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -1,7 +1,7 @@
/*
* c_register - set or print a custom register value
*
* Copyright (C) 2007,2021 Landon Curt Noll
* Copyright (C) 2007,2021,2022 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,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -90,24 +91,24 @@ c_register(char *UNUSED(name), int count, VALUE **vals)
result.v_type = V_NULL;
if (vals[0]->v_type != V_NUM) {
math_error("Non-numeric register number");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(vals[0]->v_num)) {
math_error("Non-integer register number");
/*NOTREACHED*/
not_reached();
}
if (qisneg(vals[0]->v_num)) {
math_error("register number < 0");
/*NOTREACHED*/
not_reached();
}
if (! qistiny(vals[0]->v_num)) {
math_error("register is huge");
/*NOTREACHED*/
not_reached();
}
reg = qtoi(vals[0]->v_num);
if (reg > CUSTOM_REG_MAX) {
math_error("register is larger than CUSTOM_REG_MAX");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -1,7 +1,7 @@
/*
* c_sysinfo - names and values of selected #defines
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 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
@@ -57,6 +57,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -301,7 +302,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
qisfrac(vals[0]->v_num) ||
zge31b(vals[0]->v_num->num)) {
math_error("sysinfo: arg must be string, 0, 1 or 2");
/*NOTREACHED*/
not_reached();
}
/*
@@ -319,7 +320,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
break;
default:
math_error("sysinfo: arg must be string, 0, 1 or 2");
/*NOTREACHED*/
not_reached();
}
/*
@@ -368,7 +369,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
*/
} else {
math_error("sysinfo: arg must be string, 0, 1 or 2");
/*NOTREACHED*/
not_reached();
}
/*

7
decl.h
View File

@@ -94,12 +94,5 @@
#endif
/* Perform printf-style argument type checking for known compilers */
#ifdef __GNUC__
# define PRINTF_FORMAT(fmt_idx, arg_idx) __attribute__ \
((format (printf, fmt_idx, arg_idx)))
#else
# define PRINTF_FORMAT(fmt_idx, arg_idx)
#endif
#endif /* !INCLUDE_DECL_H */

43
file.c
View File

@@ -1,7 +1,7 @@
/*
* file - file I/O routines callable by users
*
* Copyright (C) 1999-2007,2018,2021 David I. Bell and Landon Curt Noll
* Copyright (C) 1999-2007,2018,2021,2022 David I. Bell and Landon Curt Noll
*
* Primary author: David I. Bell
*
@@ -39,7 +39,7 @@
#include "calc.h"
#include "alloc.h"
#include "longbits.h"
#include "have_fpos.h"
#include "have_fgetsetpos.h"
#include "have_fpos_pos.h"
#include "fposval.h"
#include "file.h"
@@ -51,6 +51,7 @@
#endif
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -179,7 +180,7 @@ file_init(void)
tname = (char *)malloc(snprintf_len+1);
if (tname == NULL) {
math_error("Out of memory for init_file");
/*NOTREACHED*/
not_reached();
}
snprintf(tname, snprintf_len, "descriptor[%d]", i);
tname[snprintf_len] = '\0'; /* paranoia */
@@ -231,7 +232,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
fiop->name = (char *)malloc(namelen + 1);
if (fiop->name == NULL) {
math_error("No memory for filename");
/*NOTREACHED*/
not_reached();
}
}
@@ -367,7 +368,7 @@ openid(char *name, char *mode)
}
if (fstat(fileno(fp), &sbuf) < 0) {
math_error("bad fstat");
/*NOTREACHED*/
not_reached();
}
/* get a new FILEID */
@@ -436,12 +437,12 @@ openpathid(char *name, char *mode, char *pathlist)
free(openpath);
}
math_error("bad fstat");
/*NOTREACHED*/
not_reached();
}
if (openpath == NULL) {
fclose(fp);
math_error("bad openpath");
/*NOTREACHED*/
not_reached();
}
/* get a new FILEID */
@@ -482,7 +483,7 @@ reopenid(FILEID id, char *mode, char *name)
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
(id == FILEID_STDERR)) {
math_error("Cannot freopen stdin, stdout, or stderr");
/*NOTREACHED*/
not_reached();
}
/* reopen the file */
@@ -507,7 +508,7 @@ reopenid(FILEID id, char *mode, char *name)
}
if (i >= MAXFILES) {
math_error("This should not happen in reopenid");
/*NOTREACHED*/
not_reached();
}
fp = f_open(name, mode);
if (fp == NULL) {
@@ -532,7 +533,7 @@ reopenid(FILEID id, char *mode, char *name)
}
if (fstat(fileno(fp), &sbuf) < 0) {
math_error("bad fstat");
/*NOTREACHED*/
not_reached();
}
/* initialize FILEIO structure */
@@ -632,7 +633,7 @@ closeid(FILEID id)
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
(id == FILEID_STDERR)) {
math_error("Cannot close stdin, stdout, or stderr");
/*NOTREACHED*/
not_reached();
}
/* get file structure */
@@ -832,7 +833,7 @@ readid(FILEID id, int flags, STRING **retstr)
str = (char *)malloc(n + 1);
if (str == NULL) {
math_error("Out of memory for readid");
/*NOTREACHED*/
not_reached();
}
if (n > 0)
memcpy(&str[totlen], buf, n);
@@ -1458,7 +1459,7 @@ z2filepos(ZVALUE zpos)
if (zpos.len >= FILEPOS_BITS/BASEB) {
/* copy the lower FILEPOS_BITS of the ZVALUE */
memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN);
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN));
} else {
/* copy what bits we can into the temp value */
memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */
@@ -1536,7 +1537,7 @@ getloc(FILEID id, ZVALUE *res)
fp = fiop->fp;
if (fp == NULL) {
math_error("Bogus internal file pointer!");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1695,7 +1696,7 @@ setloc(FILEID id, ZVALUE zpos)
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
(id == FILEID_STDERR)) {
math_error("Cannot fseek stdin, stdout, or stderr");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1709,7 +1710,7 @@ setloc(FILEID id, ZVALUE zpos)
fp = fiop->fp;
if (fp == NULL) {
math_error("Bogus internal file pointer!");
/*NOTREACHED*/
not_reached();
}
fiop->action = 0;
@@ -1960,7 +1961,7 @@ filesize(FILEIO *fiop)
/* return length */
if (fstat(fileno(fiop->fp), &sbuf) < 0) {
math_error("bad fstat");
/*NOTREACHED*/
not_reached();
}
return sbuf.st_size;
}
@@ -2021,7 +2022,7 @@ showfiles(void)
math_chr('\n');
continue;
}
printf(" size = %lld\n", (long long int)sizes[i]);
printf(" size = %ld\n", (long int)sizes[i]);
for (j = i + 1; j < idnum; j++) {
if (listed[j] || sizes[j] == -1)
continue;
@@ -2099,7 +2100,7 @@ getscanfield(FILE *fp, BOOL skip, unsigned int width, int scannum,
str = (char *) malloc(len + 1);
if (str == NULL) {
math_error("Out of memory for scanning");
/*NOTREACHED*/
not_reached();
}
if (len)
memcpy(&str[totlen], buf, len);
@@ -2177,7 +2178,7 @@ getscanwhite(FILE *fp, BOOL skip, unsigned int width, int scannum,
str = (char *) malloc(len + 1);
if (str == NULL) {
math_error("Out of memory for scanning");
/*NOTREACHED*/
not_reached();
}
if (len)
memcpy(&str[totlen], buf, len);
@@ -2721,7 +2722,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res)
while (k < tmp.len && tmp.v[k] == 0);
if (k == tmp.len) {
math_error("This should not happen");
/*NOTREACHED*/
not_reached();
}
tmp.v[k]--;
if (tmp.v[tmp.len - 1] == 0)

6
file.h
View File

@@ -32,9 +32,9 @@
#if defined(CALC_SRC) /* if we are building from the calc source tree */
# include "have_fpos.h"
# include "have_fgetsetpos.h"
#else
# include <calc/have_fpos.h>
# include <calc/have_fgetsetpos.h>
#endif
@@ -71,7 +71,7 @@ typedef struct {
* Some obscure systems without fgetpos/fsetpos may not have a simple
* scalar type. In these cases the f_tell macro below will fail.
*/
#if defined(HAVE_FPOS)
#if defined(HAVE_FGETSETPOS)
#define f_seek_set(stream, loc) fsetpos((FILE*)(stream), (FILEPOS*)(loc))
#define f_tell(stream, loc) fgetpos((FILE*)(stream), (FILEPOS*)(loc))

View File

@@ -59,12 +59,19 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "have_fpos.h"
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "decl.h"
#include "have_fgetsetpos.h"
#include "endian_calc.h"
#include "have_offscl.h"
#include "have_posscl.h"
#include "have_fpos_pos.h"
#include "alloc.h"
#include "have_unused.h"
#include "have_memmv.h"
#include "banned.h" /* include after system header <> includes */
@@ -73,7 +80,7 @@
char *program; /* our name */
int
main(int argc, char **argv)
main(int UNUSED(argc), char **argv)
{
int stsizelen; /* bit length of st_size in buf */
int fileposlen; /* bit length of FILEPOS */
@@ -89,7 +96,7 @@ main(int argc, char **argv)
/*
* print the file position information
*/
#if defined(HAVE_FPOS_POS)
#if defined(HAVE_FPOS_POS) && defined(FPOS_POS_BITS)
fileposlen = FPOS_POS_BITS;
#else /* ! HAVE_FPOS_POS */
# if defined(FPOS_BITS)
@@ -107,13 +114,17 @@ main(int argc, char **argv)
* Big Endian
*/
if (fileposlen == 64) {
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
"SWAP_HALF_IN_B64(dest, src)");
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\tSWAP_HALF_IN_B64(dest, src)\n");
} else if (fileposlen == 32) {
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
"SWAP_HALF_IN_B32(dest, src)");
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\tSWAP_HALF_IN_B32(dest, src)\n");
} else if (fileposlen%BASEB == 0) {
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\tswap_HALFs(dest, src, %d)\n",
fileposlen/BASEB);
} else {
fprintf(stderr, "%s: unexpected FILEPOS bit size: %d\n",
fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n",
program, fileposlen);
exit(1);
}
@@ -122,16 +133,15 @@ main(int argc, char **argv)
* Little Endian
*/
#if defined(HAVE_FILEPOS_SCALAR)
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
"(*(dest) = *(src))");
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\t(*(dest) = *(src))\n");
#else /* HAVE_FILEPOS_SCALAR */
/*
* Normally a "(*(dest) = *(src))" would do, but on some
* systems a FILEPOS is not a scalar hence we must memcpy.
*/
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s\n",
"\\\n\tmemcpy((void *)(dest), (void *)(src), "
"sizeof(FPOS_POS_LEN))");
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\tmemcpy((void *)(dest), (void *)(src), FILEPOS_LEN)\n");
#endif /* HAVE_FILEPOS_SCALAR */
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
putchar('\n');

224
func.c
View File

@@ -1,8 +1,7 @@
/*
* func - built-in functions implemented here
*
* Copyright (C) 1999-2007,2018,2021 David I. Bell, Landon Curt Noll
* and Ernest Bowen
* Copyright (C) 1999-2007,2018,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -114,6 +113,7 @@
#endif
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -144,7 +144,7 @@ E_FUNC LIST* matindices(MATRIX *mp, long index);
/*
* malloced environment storage
*/
#define ENV_POOL_CHUNK 10 /* env_pool elements to allocate at a time */
#define ENV_POOL_CHUNK (1<8) /* env_pool elements to allocate at a time */
struct env_pool {
char *getenv; /* what getenv() would return, NULL => unused */
char *putenv; /* pointer given to putenv() */
@@ -290,7 +290,7 @@ f_prompt(VALUE *vp)
newcp = (char *) malloc(len + 1);
if (newcp == NULL) {
math_error("Cannot allocate string");
/*NOTREACHED*/
not_reached();
}
strlcpy(newcp, cp, len+1);
result.v_str = makestring(newcp);
@@ -486,7 +486,7 @@ f_isrel(NUMBER *val1, NUMBER *val2)
{
if (qisfrac(val1) || qisfrac(val2)) {
math_error("Non-integer for isrel");
/*NOTREACHED*/
not_reached();
}
return itoq((long) zrelprime(val1->num, val2->num));
}
@@ -508,7 +508,7 @@ f_isprime(int count, NUMBER **vals)
if (count == 2) {
if (qisfrac(vals[1])) {
math_error("2nd isprime arg must be an integer");
/*NOTREACHED*/
not_reached();
}
err = vals[1];
} else {
@@ -521,7 +521,7 @@ f_isprime(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg for builtin function isprime");
/*NOTREACHED*/
not_reached();
}
/* test the integer */
@@ -533,7 +533,7 @@ f_isprime(int count, NUMBER **vals)
/* error return */
if (!err) {
math_error("isprime argument is an odd value > 2^32");
/*NOTREACHED*/
not_reached();
}
return qlink(err);
}
@@ -549,7 +549,7 @@ f_nprime(int count, NUMBER **vals)
if (count == 2) {
if (qisfrac(vals[1])) {
math_error("2nd nextprime arg must be an integer");
/*NOTREACHED*/
not_reached();
}
err = vals[1];
} else {
@@ -562,7 +562,7 @@ f_nprime(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg 1 for builtin function nextprime");
/*NOTREACHED*/
not_reached();
}
/* test the integer */
@@ -577,7 +577,7 @@ f_nprime(int count, NUMBER **vals)
/* error return */
if (!err) {
math_error("nextprime arg 1 is >= 2^32");
/*NOTREACHED*/
not_reached();
}
return qlink(err);
}
@@ -593,7 +593,7 @@ f_pprime(int count, NUMBER **vals)
if (count == 2) {
if (qisfrac(vals[1])) {
math_error("2nd prevprime arg must be an integer");
/*NOTREACHED*/
not_reached();
}
err = vals[1];
} else {
@@ -606,7 +606,7 @@ f_pprime(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg 1 for builtin function prevprime");
/*NOTREACHED*/
not_reached();
}
/* test the integer */
@@ -621,10 +621,10 @@ f_pprime(int count, NUMBER **vals)
if (!err) {
if (prev_prime == 0) {
math_error("prevprime arg 1 is <= 2");
/*NOTREACHED*/
not_reached();
} else {
math_error("prevprime arg 1 is >= 2^32");
/*NOTREACHED*/
not_reached();
}
}
return qlink(err);
@@ -646,7 +646,7 @@ f_factor(int count, NUMBER **vals)
if (count == 3) {
if (qisfrac(vals[2])) {
math_error("3rd factor arg must be an integer");
/*NOTREACHED*/
not_reached();
}
err = vals[2];
} else {
@@ -658,7 +658,7 @@ f_factor(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg 2 for builtin factor");
/*NOTREACHED*/
not_reached();
}
limit = vals[1]->num;
} else {
@@ -672,7 +672,7 @@ f_factor(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg 1 for builtin pfactor");
/*NOTREACHED*/
not_reached();
}
n = vals[0]->num;
@@ -687,7 +687,7 @@ f_factor(int count, NUMBER **vals)
return qlink(err);
}
math_error("limit >= 2^32 for builtin factor");
/*NOTREACHED*/
not_reached();
} else if (res == 0) {
if (count < 2)
zfree(limit);
@@ -714,7 +714,7 @@ f_pix(int count, NUMBER **vals)
if (count == 2) {
if (qisfrac(vals[1])) {
math_error("2nd pix arg must be an integer");
/*NOTREACHED*/
not_reached();
}
err = vals[1];
} else {
@@ -727,7 +727,7 @@ f_pix(int count, NUMBER **vals)
return qlink(err);
}
math_error("non-integral arg 1 for builtin function pix");
/*NOTREACHED*/
not_reached();
}
/* determine the number of primes <= x */
@@ -739,7 +739,7 @@ f_pix(int count, NUMBER **vals)
/* error return */
if (!err) {
math_error("pix arg 1 is >= 2^32");
/*NOTREACHED*/
not_reached();
}
return qlink(err);
}
@@ -765,14 +765,14 @@ f_prevcand(int count, NUMBER **vals)
case 5:
if (!qisint(vals[4])) {
math_error( "prevcand 5th arg must both be integer");
/*NOTREACHED*/
not_reached();
}
zmodulus = vals[4]->num;
/*FALLTHRU*/
case 4:
if (!qisint(vals[3])) {
math_error( "prevcand 4th arg must both be integer");
/*NOTREACHED*/
not_reached();
}
zresidue = vals[3]->num;
/*FALLTHRU*/
@@ -780,7 +780,7 @@ f_prevcand(int count, NUMBER **vals)
if (!qisint(vals[2])) {
math_error(
"prevcand skip arg (3rd) must be an integer or omitted");
/*NOTREACHED*/
not_reached();
}
zskip = vals[2]->num;
/*FALLTHRU*/
@@ -788,7 +788,7 @@ f_prevcand(int count, NUMBER **vals)
if (!qisint(vals[1])) {
math_error(
"prevcand count arg (2nd) must be an integer or omitted");
/*NOTREACHED*/
not_reached();
}
zcount = &vals[1]->num;
/*FALLTHRU*/
@@ -796,12 +796,13 @@ f_prevcand(int count, NUMBER **vals)
if (!qisint(vals[0])) {
math_error(
"prevcand search arg (1st) must be an integer");
/*NOTREACHED*/
not_reached();
}
break;
default:
math_error("invalid number of args passed to prevcand");
/*NOTREACHED*/
not_reached();
break;
}
if (zcount == NULL) {
@@ -809,7 +810,7 @@ f_prevcand(int count, NUMBER **vals)
} else {
if (zge24b(*zcount)) {
math_error("prevcand count arg (2nd) must be < 2^24");
/*NOTREACHED*/
not_reached();
}
count = ztoi(*zcount);
}
@@ -847,7 +848,7 @@ f_nextcand(int count, NUMBER **vals)
if (!qisint(vals[4])) {
math_error(
"nextcand 5th args must be integer");
/*NOTREACHED*/
not_reached();
}
zmodulus = vals[4]->num;
/*FALLTHRU*/
@@ -855,7 +856,7 @@ f_nextcand(int count, NUMBER **vals)
if (!qisint(vals[3])) {
math_error(
"nextcand 5th args must be integer");
/*NOTREACHED*/
not_reached();
}
zresidue = vals[3]->num;
/*FALLTHRU*/
@@ -863,7 +864,7 @@ f_nextcand(int count, NUMBER **vals)
if (!qisint(vals[2])) {
math_error(
"nextcand skip arg (3rd) must be an integer or omitted");
/*NOTREACHED*/
not_reached();
}
zskip = vals[2]->num;
/*FALLTHRU*/
@@ -871,7 +872,7 @@ f_nextcand(int count, NUMBER **vals)
if (!qisint(vals[1])) {
math_error(
"nextcand count arg (2nd) must be an integer or omitted");
/*NOTREACHED*/
not_reached();
}
zcount = &vals[1]->num;
/*FALLTHRU*/
@@ -879,12 +880,12 @@ f_nextcand(int count, NUMBER **vals)
if (!qisint(vals[0])) {
math_error(
"nextcand search arg (1st) must be an integer");
/*NOTREACHED*/
not_reached();
}
break;
default:
math_error("invalid number of args passed to nextcand");
/*NOTREACHED*/
not_reached();
}
/*
@@ -895,7 +896,7 @@ f_nextcand(int count, NUMBER **vals)
} else {
if (zge24b(*zcount)) {
math_error("prevcand count arg (2nd) must be < 2^24");
/*NOTREACHED*/
not_reached();
}
count = ztoi(*zcount);
}
@@ -935,11 +936,11 @@ f_rand(int count, NUMBER **vals)
case 1: /* rand(limit) */
if (!qisint(vals[0])) {
math_error("rand limit must be an integer");
/*NOTREACHED*/
not_reached();
}
if (zislezero(vals[0]->num)) {
math_error("rand limit must > 0");
/*NOTREACHED*/
not_reached();
}
ans = qalloc();
zrandrange(_zero_, vals[0]->num, &ans->num);
@@ -949,7 +950,7 @@ f_rand(int count, NUMBER **vals)
/* firewall */
if (!qisint(vals[0]) || !qisint(vals[1])) {
math_error("rand range must be integers");
/*NOTREACHED*/
not_reached();
}
ans = qalloc();
zrandrange(vals[0]->num, vals[1]->num, &ans->num);
@@ -957,7 +958,7 @@ f_rand(int count, NUMBER **vals)
default:
math_error("invalid number of args passed to rand");
/*NOTREACHED*/
not_reached();
return NULL;
}
@@ -986,11 +987,11 @@ f_randbit(int count, NUMBER **vals)
*/
if (!qisint(vals[0])) {
math_error("rand bit count must be an integer");
/*NOTREACHED*/
not_reached();
}
if (zge31b(vals[0]->num)) {
math_error("huge rand bit count");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1037,7 +1038,7 @@ f_srand(int count, VALUE **vals)
if (!qisint(vals[0]->v_num)) {
math_error(
"srand number seed must be an integer");
/*NOTREACHED*/
not_reached();
}
result.v_rand = zsrand(&vals[0]->v_num->num, NULL);
break;
@@ -1054,14 +1055,14 @@ f_srand(int count, VALUE **vals)
default:
math_error("illegal type of arg passed to srand()");
/*NOTREACHED*/
not_reached();
break;
}
break;
default:
math_error("bad arg count to srand()");
/*NOTREACHED*/
not_reached();
break;
}
@@ -1086,11 +1087,11 @@ f_random(int count, NUMBER **vals)
case 1: /* random(limit) */
if (!qisint(vals[0])) {
math_error("random limit must be an integer");
/*NOTREACHED*/
not_reached();
}
if (zislezero(vals[0]->num)) {
math_error("random limit must > 0");
/*NOTREACHED*/
not_reached();
}
ans = qalloc();
zrandomrange(_zero_, vals[0]->num, &ans->num);
@@ -1100,7 +1101,7 @@ f_random(int count, NUMBER **vals)
/* firewall */
if (!qisint(vals[0]) || !qisint(vals[1])) {
math_error("random range must be integers");
/*NOTREACHED*/
not_reached();
}
ans = qalloc();
zrandomrange(vals[0]->num, vals[1]->num, &ans->num);
@@ -1108,7 +1109,7 @@ f_random(int count, NUMBER **vals)
default:
math_error("invalid number of args passed to random");
/*NOTREACHED*/
not_reached();
return NULL;
}
@@ -1140,11 +1141,11 @@ f_randombit(int count, NUMBER **vals)
*/
if (!qisint(vals[0])) {
math_error("random bit count must be an integer");
/*NOTREACHED*/
not_reached();
}
if (zge31b(vals[0]->num)) {
math_error("huge random bit count");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1191,7 +1192,7 @@ f_srandom(int count, VALUE **vals)
if (!qisint(vals[0]->v_num)) {
math_error(
"srandom number seed must be an integer");
/*NOTREACHED*/
not_reached();
}
result.v_random = zsrandom1(vals[0]->v_num->num, TRUE);
break;
@@ -1203,7 +1204,7 @@ f_srandom(int count, VALUE **vals)
default:
math_error("illegal type of arg passed to srandom()");
/*NOTREACHED*/
not_reached();
break;
}
break;
@@ -1211,11 +1212,11 @@ f_srandom(int count, VALUE **vals)
case 2: /* srandom(seed, newn) */
if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) {
math_error("srandom seed must be an integer");
/*NOTREACHED*/
not_reached();
}
if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) {
math_error("srandom Blum modulus must be an integer");
/*NOTREACHED*/
not_reached();
}
result.v_random = zsrandom2(vals[0]->v_num->num,
vals[1]->v_num->num);
@@ -1224,23 +1225,23 @@ f_srandom(int count, VALUE **vals)
case 4: /* srandom(seed, ip, iq, trials) */
if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) {
math_error("srandom seed must be an integer");
/*NOTREACHED*/
not_reached();
}
if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) {
math_error("srandom 2nd arg must be an integer");
/*NOTREACHED*/
not_reached();
}
if (vals[2]->v_type != V_NUM || !qisint(vals[2]->v_num)) {
math_error("srandom 3rd arg must be an integer");
/*NOTREACHED*/
not_reached();
}
if (vals[3]->v_type != V_NUM || !qisint(vals[3]->v_num)) {
math_error("srandom 4th arg must be an integer");
/*NOTREACHED*/
not_reached();
}
if (zge24b(vals[3]->v_num->num)) {
math_error("srandom trials count is excessive");
/*NOTREACHED*/
not_reached();
}
result.v_random = zsrandom4(vals[0]->v_num->num,
vals[1]->v_num->num,
@@ -1250,7 +1251,7 @@ f_srandom(int count, VALUE **vals)
default:
math_error("bad arg count to srandom()");
/*NOTREACHED*/
not_reached();
break;
}
@@ -1856,7 +1857,7 @@ f_fact(VALUE *vp)
}
if (vp->v_type != V_NUM) {
math_error("Non-real argument for fact()");
/*NOTREACHED*/
not_reached();
}
res.v_num = qfact(vp->v_num);
return res;
@@ -1913,19 +1914,19 @@ f_hnrmod(NUMBER *val1, NUMBER *val2, NUMBER *val3, NUMBER *val4)
*/
if (qisfrac(val1)) {
math_error("1st arg of hnrmod (v) must be an integer");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(val2) || qisneg(val2) || qiszero(val2)) {
math_error("2nd arg of hnrmod (h) must be an integer > 0");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(val3) || qisneg(val3) || qiszero(val3)) {
math_error("3rd arg of hnrmod (n) must be an integer > 0");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(val4) || !zisabsleone(val4->num)) {
math_error("4th arg of hnrmod (r) must be -1, 0 or 1");
/*NOTREACHED*/
not_reached();
}
/*
@@ -5686,7 +5687,7 @@ f_strcat(int count, VALUE **vals)
c = (char *) malloc(len + 1) ;
if (c == NULL) {
math_error("No memory for strcat");
/*NOTREACHED*/
not_reached();
}
result.v_str = stralloc();
result.v_str->s_str = c;
@@ -5774,7 +5775,7 @@ f_substr(VALUE *v1, VALUE *v2, VALUE *v3)
ccp = (char *) malloc(len + 1);
if (ccp == NULL) {
math_error("No memory for substr");
/*NOTREACHED*/
not_reached();
}
result.v_str = stralloc();
result.v_str->s_len = len;
@@ -7144,7 +7145,7 @@ f_errno(int count, VALUE **vals)
if (vp->v_type != V_NUM || qisfrac(vp->v_num) ||
qisneg(vp->v_num) || zge16b(vp->v_num->num)) {
math_error("errno argument out of range");
/*NOTREACHED*/
not_reached();
}
newerr = (int) ztoi(vp->v_num->num);
}
@@ -7174,7 +7175,7 @@ f_errcount(int count, VALUE **vals)
if (vp->v_type != V_NUM || qisfrac(vp->v_num) ||
qisneg(vp->v_num) || zge31b(vp->v_num->num)) {
math_error("errcount argument out of range");
/*NOTREACHED*/
not_reached();
}
newcount = (int) ztoi(vp->v_num->num);
}
@@ -7395,7 +7396,7 @@ f_strerror(int count, VALUE **vals)
cp = (char *) malloc(snprintf_len+1);
if (cp == NULL) {
math_error("Out of memory for strerror");
/*NOTREACHED*/
not_reached();
}
snprintf(cp, snprintf_len, "Unknown error %ld", i);
cp[snprintf_len] = '\0'; /* paranoia */
@@ -8297,7 +8298,7 @@ f_reverse(VALUE *val)
break;
default:
math_error("Bad argument type for reverse");
/*NOTREACHED*/
not_reached();
}
return res;
}
@@ -8321,7 +8322,7 @@ f_sort(VALUE *val)
break;
default:
math_error("Bad argument type for sort");
/*NOTREACHED*/
not_reached();
}
return res;
}
@@ -8562,12 +8563,12 @@ f_forall(VALUE *v1, VALUE *v2)
if (v2->v_type != V_STR) {
math_error("Non-string second argument for forall");
/*NOTREACHED*/
not_reached();
}
fp = findfunc(adduserfunc(v2->v_str->s_str));
if (!fp) {
math_error("Undefined function for forall");
/*NOTREACHED*/
not_reached();
}
switch (v1->v_type) {
case V_LIST:
@@ -8588,7 +8589,7 @@ f_forall(VALUE *v1, VALUE *v2)
break;
default:
math_error("Non list or matrix first argument for forall");
/*NOTREACHED*/
not_reached();
}
return res;
}
@@ -8608,16 +8609,16 @@ f_select(VALUE *v1, VALUE *v2)
if (v1->v_type != V_LIST) {
math_error("Non-list first argument for select");
/*NOTREACHED*/
not_reached();
}
if (v2->v_type != V_STR) {
math_error("Non-string second argument for select");
/*NOTREACHED*/
not_reached();
}
fp = findfunc(adduserfunc(v2->v_str->s_str));
if (!fp) {
math_error("Undefined function for select");
/*NOTREACHED*/
not_reached();
}
lp = listalloc();
for (ep = v1->v_list->l_first; ep; ep = ep->e_next) {
@@ -8648,12 +8649,12 @@ f_count(VALUE *v1, VALUE *v2)
if (v2->v_type != V_STR) {
math_error("Non-string second argument for select");
/*NOTREACHED*/
not_reached();
}
fp = findfunc(adduserfunc(v2->v_str->s_str));
if (!fp) {
math_error("Undefined function for select");
/*NOTREACHED*/
not_reached();
}
switch (v1->v_type) {
case V_LIST:
@@ -8678,7 +8679,8 @@ f_count(VALUE *v1, VALUE *v2)
break;
default:
math_error("Bad argument type for count");
/*NOTREACHED*/
not_reached();
break;
}
res.v_num = itoq(n);
return res;
@@ -8698,11 +8700,11 @@ f_makelist(VALUE *v1)
if (v1->v_type != V_NUM || qisfrac(v1->v_num) || qisneg(v1->v_num)) {
math_error("Bad argument for makelist");
/*NOTREACHED*/
not_reached();
}
if (zge31b(v1->v_num->num)) {
math_error("makelist count >= 2^31");
/*NOTREACHED*/
not_reached();
}
n = qtoi(v1->v_num);
lp = listalloc();
@@ -8734,7 +8736,7 @@ f_randperm(VALUE *val)
break;
default:
math_error("Bad argument type for randperm");
/*NOTREACHED*/
not_reached();
}
return res;
}
@@ -8755,7 +8757,7 @@ f_cmdbuf(void)
newcp = (char *)malloc(cmdbuf_len+1);
if (newcp == NULL) {
math_error("Cannot allocate string in cmdbuf");
/*NOTREACHED*/
not_reached();
}
strlcpy(newcp, cmdbuf, cmdbuf_len+1);
result.v_str = makestring(newcp);
@@ -8774,7 +8776,7 @@ f_getenv(VALUE *v1)
if (v1->v_type != V_STR) {
math_error("Non-string argument for getenv");
/*NOTREACHED*/
not_reached();
}
result.v_type = V_STR;
str = getenv(v1->v_str->s_str);
@@ -8930,7 +8932,7 @@ f_putenv(int count, VALUE **vals)
/* firewall */
if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) {
math_error("Non-string argument for putenv");
/*NOTREACHED*/
not_reached();
}
/* convert putenv("foo","bar") into putenv("foo=bar") */
@@ -8939,7 +8941,7 @@ f_putenv(int count, VALUE **vals)
putenv_str = (char *)malloc(snprintf_len+1);
if (putenv_str == NULL) {
math_error("Cannot allocate string in putenv");
/*NOTREACHED*/
not_reached();
}
/*
* The next statement could be:
@@ -8969,13 +8971,13 @@ f_putenv(int count, VALUE **vals)
/* firewall */
if (vals[0]->v_type != V_STR) {
math_error("Non-string argument for putenv");
/*NOTREACHED*/
not_reached();
}
/* putenv(arg) must be of the form "foo=bar" */
if ((char *)strchr(vals[0]->v_str->s_str, '=') == NULL) {
math_error("putenv single arg string missing =");
/*NOTREACHED*/
not_reached();
}
/*
@@ -8985,7 +8987,7 @@ f_putenv(int count, VALUE **vals)
putenv_str = (char *)malloc(vals[0]->v_str->s_len + 1);
if (putenv_str == NULL) {
math_error("Cannot allocate string in putenv");
/*NOTREACHED*/
not_reached();
}
strlcpy(putenv_str, vals[0]->v_str->s_str,
vals[0]->v_str->s_len+1);
@@ -9010,7 +9012,7 @@ f_strpos(VALUE *haystack, VALUE *needle)
if (haystack->v_type != V_STR || needle->v_type != V_STR) {
math_error("Non-string argument for index");
/*NOTREACHED*/
not_reached();
}
cpointer = strstr(haystack->v_str->s_str,
needle->v_str->s_str);
@@ -9034,11 +9036,11 @@ f_system(VALUE *vp)
if (vp->v_type != V_STR) {
math_error("Non-string argument for system");
/*NOTREACHED*/
not_reached();
}
if (!allow_exec) {
math_error("execution disallowed by -m");
/*NOTREACHED*/
not_reached();
}
if (conf->calc_debug & CALCDBG_SYSTEM) {
printf("%s\n", vp->v_str->s_str);
@@ -9147,7 +9149,7 @@ f_base(int count, NUMBER **vals)
break;
default:
math_error("Unsupported base");
/*NOTREACHED*/
not_reached();
break;
}
@@ -9204,7 +9206,7 @@ f_base2(int count, NUMBER **vals)
break;
default:
math_error("Unsupported base");
/*NOTREACHED*/
not_reached();
break;
}
@@ -9333,7 +9335,7 @@ f_custom(int count, VALUE **vals)
/* firewall */
if (vals[0]->v_type != V_STR) {
math_error("custom: 1st arg not a string name");
/*NOTREACHED*/
not_reached();
}
/* perform the custom function */
@@ -9776,7 +9778,7 @@ f_argv(int count, VALUE **vals)
qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) {
math_error("argv argument must be a integer [0,2^31)");
/*NOTREACHED*/
not_reached();
}
/* determine the arg value of the argv() function */
@@ -10609,18 +10611,18 @@ builtinfunc(long index, int argcount, VALUE *stck)
if ((unsigned long)index >=
(sizeof(builtins) / sizeof(builtins[0])) - 1) {
math_error("Bad built-in function index");
/*NOTREACHED*/
not_reached();
}
bp = &builtins[index];
if (argcount < bp->b_minargs) {
math_error("Too few arguments for builtin function \"%s\"",
bp->b_name);
/*NOTREACHED*/
not_reached();
}
if ((argcount > bp->b_maxargs) || (argcount > IN)) {
math_error("Too many arguments for builtin function \"%s\"",
bp->b_name);
/*NOTREACHED*/
not_reached();
}
/*
* If an address was passed, then point at the real variable,
@@ -10662,7 +10664,7 @@ builtinfunc(long index, int argcount, VALUE *stck)
if ((*vpp)->v_type != V_NUM) {
math_error("Non-real argument for builtin function %s",
bp->b_name);
/*NOTREACHED*/
not_reached();
}
numargs[i] = (*vpp)->v_num;
vpp++;
@@ -10696,7 +10698,7 @@ builtinfunc(long index, int argcount, VALUE *stck)
break;
default:
math_error("Bad builtin function call");
/*NOTREACHED*/
not_reached();
}
return result;
}
@@ -10745,7 +10747,7 @@ builtincheck(long index, int count)
if ((unsigned long)index >=
(sizeof(builtins) / sizeof(builtins[0])) - 1) {
math_error("Unknown built in index");
/*NOTREACHED*/
not_reached();
}
bp = &builtins[index];
if (count < bp->b_minargs)
@@ -10813,11 +10815,11 @@ malloced_putenv(char *str)
*/
if (str == NULL) {
math_error("malloced_putenv given a NULL pointer!!");
/*NOTREACHED*/
not_reached();
}
if (str[0] == '=') {
math_error("malloced_putenv = is first character in string!!");
/*NOTREACHED*/
not_reached();
}
/*
@@ -10826,7 +10828,7 @@ malloced_putenv(char *str)
value = strchr(str, '=');
if (value == NULL) {
math_error("malloced_putenv = not found in string!!");
/*NOTREACHED*/
not_reached();
}
++value;
@@ -10876,7 +10878,7 @@ malloced_putenv(char *str)
sizeof(struct env_pool));
if (new == NULL) {
math_error("malloced_putenv malloc failed");
/*NOTREACHED*/
not_reached();
}
e_pool = new;
env_pool_max = ENV_POOL_CHUNK;
@@ -10892,7 +10894,7 @@ malloced_putenv(char *str)
sizeof(struct env_pool));
if (new == NULL) {
math_error("malloced_putenv realloc failed");
/*NOTREACHED*/
not_reached();
}
e_pool = new;
for (i=env_pool_max; i <= env_pool_max + ENV_POOL_CHUNK; ++i) {
@@ -10919,7 +10921,7 @@ malloced_putenv(char *str)
}
if (i >= env_pool_max) {
math_error("malloced_putenv missed unused entry!!");
/*NOTREACHED*/
not_reached();
}
/*

13
hash.c
View File

@@ -1,7 +1,7 @@
/*
* hash - one-way hash routines
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "hash.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -94,7 +95,7 @@ hash_init(int type, HASH *state)
state = (HASH *)malloc(sizeof(HASH));
if (state == NULL) {
math_error("hash_init: cannot malloc HASH");
/*NOTREACHED*/
not_reached();
}
}
@@ -119,7 +120,7 @@ hash_init(int type, HASH *state)
if (state->chunksize > MAX_CHUNKSIZE) {
math_error(
"internal error: MAX_CHUNKSIZE is too small");
/*NOTREACHED*/
not_reached();
}
return state;
}
@@ -174,7 +175,7 @@ hash_copy(HASH *state)
hnew = (HASH *)malloc(sizeof(HASH));
if (hnew == NULL) {
math_error("hash_init: cannot malloc HASH");
/*NOTREACHED*/
not_reached();
}
/*
@@ -955,6 +956,7 @@ hash_value(int type, void *v, HASH *state)
state = hash_len(type, value->v_config->pow2, state);
state = hash_len(type, value->v_config->redc2, state);
state = hash_bool(type, value->v_config->tilde_ok, state);
state = hash_bool(type, value->v_config->tilde_space, state);
state = hash_bool(type, value->v_config->tab_ok, state);
state = hash_long(type, (long)value->v_config->quomod, state);
state = hash_long(type, (long)value->v_config->quo, state);
@@ -1000,6 +1002,7 @@ hash_value(int type, void *v, HASH *state)
state = hash_int(type, value->v_config->baseb, state);
state = hash_bool(type, value->v_config->redecl_warn, state);
state = hash_bool(type, value->v_config->dupvar_warn, state);
state = hash_bool(type, value->v_config->fraction_space, state);
break;
case V_HASH:
@@ -1048,7 +1051,7 @@ hash_value(int type, void *v, HASH *state)
default:
math_error("hashing an unknown value");
/*NOTREACHED*/
not_reached();
}
return state;
}

View File

@@ -1,7 +1,7 @@
/*
* have_fpos - Determine if have fgetpos and fsetpos functions
*
* Copyright (C) 1999,2021 Landon Curt Noll
* Copyright (C) 1999,2021,2022 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
@@ -25,10 +25,10 @@
*/
/*
* If the symbol HAVE_NO_FPOS is defined, we will output nothing.
* If the symbol HAVE_NO_FGETSETPOS is defined, we will output nothing.
* If we are able to compile this program, then we must have the
* fgetpos and fsetpos functions and we will output the
* appropriate have_fpos.h file body.
* appropriate have_fgetsetpos.h file body.
*/
#include <stdio.h>
@@ -40,7 +40,7 @@
int
main(void)
{
#if !defined(HAVE_NO_FPOS)
#if !defined(HAVE_NO_FGETSETPOS)
fpos_t pos; /* file position */
/* get the current position */
@@ -49,9 +49,9 @@ main(void)
/* set the current position */
(void) fsetpos(stdin, &pos);
/* print a have_fpos.h body that says we have the functions */
printf("#undef HAVE_FPOS\n");
printf("#define HAVE_FPOS 1 /* yes */\n\n");
/* print a have_fgetsetpos.h body that says we have the functions */
printf("#undef HAVE_FGETSETPOS\n");
printf("#define HAVE_FGETSETPOS 1 /* yes */\n\n");
printf("typedef fpos_t FILEPOS;\n");
#endif
/* exit(0); */

View File

@@ -24,16 +24,14 @@
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* If the symbol HAVE_NO_FPOS is defined, we will output nothing.
* If the HAVE_FILEPOS_SCALAR is defined, we will output nothing.
* If we are able to compile this program, then we must have the
* __pos element in a non-scalar FILEPOS.
*/
#include <stdio.h>
#include "have_fpos.h"
#include "have_fgetsetpos.h"
#include "have_posscl.h"
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "banned.h" /* include after system header <> includes */
@@ -42,29 +40,43 @@
int
main(void)
{
#if !defined(HAVE_NO_FPOS) && !defined(HAVE_FILEPOS_SCALAR)
fpos_t pos; /* file position */
#if defined(HAVE_FILEPOS_SCALAR)
/* print a __pos element in fpos_t */
printf("#undef HAVE_FPOS_POS\n");
printf("#define HAVE_FPOS_POS 1 /* yes */\n\n");
/* determine __pos element size */
printf("#undef FPOS_POS_BITS\n");
printf("#undef FPOS_POS_LEN\n");
# if defined(FPOS_POS_BITS)
printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS);
printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8));
# else
printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8);
printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos));
# endif
#else
/* we have no __pos element */
printf("/* HAVE_FILEPOS_SCALAR is defined, we assume FILEPOS is scalar */\n");
printf("/* we assume we have no __pos in FILEPOS */\n");
printf("#undef HAVE_FPOS_POS\t/* no */\n");
printf("#undef FPOS_POS_BITS\n");
printf("#undef FPOS_POS_LEN\n");
#else
printf("/* HAVE_FILEPOS_SCALAR is undefined, we assume FILEPOS is not scalar */\n");
# if defined(HAVE_NO_FPOS_POS)
printf("/* HAVE_NO_FPOS_POS defiled, we assume we have no __pos in FILEPOS */\n");
printf("#undef HAVE_FPOS_POS\t/* no */\n");
printf("#undef FPOS_POS_BITS\n");
printf("#undef FPOS_POS_LEN\n");
# elif defined(FPOS_POS_BITS)
printf("/* FPOS_POS_BITS defiled, assume we have __pos in FILEPOS */\n");
printf("#undef HAVE_FPOS_POS\n");
printf("#define HAVE_FPOS_POS 1 /* yes */\n");
printf("#undef FPOS_POS_BITS\n");
printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS);
printf("#undef FPOS_POS_LEN\n");
printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8));
# else
fpos_t pos; /* file position */
memset(&pos, 0, sizeof(pos)); /* zeroize pos to "set it" */
printf("/* we successfully compiled with a fpos_t type wit an __pos element */\n");
printf("#undef HAVE_FPOS_POS\n");
printf("#define HAVE_FPOS_POS 1 /* yes */\n");
printf("#undef FPOS_POS_BITS\n");
printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8);
printf("#undef FPOS_POS_LEN\n");
printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos));
# endif
#endif
/* exit(0); */
return 0;

View File

@@ -49,7 +49,7 @@
int
main(void)
{
#if defined(HAVE_NO_GETTIME)
#if defined(HAVE_NO_GETTIME) || defined(_WIN32) || defined(_WIN64)
printf("#undef HAVE_GETTIME /* no */\n");

View File

@@ -48,7 +48,7 @@
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include "have_fpos.h"
#include "have_fgetsetpos.h"
#include "banned.h" /* include after system header <> includes */

View File

@@ -65,6 +65,8 @@ main(void)
extern uid_t geteuid();
curds = geteuid();
/* force curds to be used, but do not print much info about our UID */
printf("/* geteuid() mod 2 == %ld */\n", ((long)curds) & 0x1);
printf("#define HAVE_UID_T /* yes */\n");

1
help.c
View File

@@ -87,6 +87,7 @@ STATIC struct help_alias {
{"dm2d", "dms2d"},
{"gm2g", "gms2g"},
{"hm2d", "hms2d"},
{"release", "releases"},
{NULL, NULL}
};

View File

@@ -2,7 +2,7 @@
#
# help - makefile for calc help files
#
# Copyright (C) 1999-2006,2017,2021 Landon Curt Noll
# Copyright (C) 1999-2006,2017,2021,2022 Landon Curt Noll
#
# SRC: help/Makefile
#
@@ -106,15 +106,6 @@ PREFIX= /usr/local
#
MAKE_FILE= Makefile
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# Where the system include (.h) files are kept
#
# For DJGPP, select:
@@ -318,7 +309,7 @@ BLT_HELP_FILES_13= bugs changes
STD_HELP_FILES_14= credit
BLT_HELP_FILES_14= contrib COPYING COPYING-LGPL questions
BLT_HELP_FILES_14= contrib COPYING COPYING-LGPL questions releases
STD_HELP_FILES_15= wishlist todo
@@ -417,6 +408,10 @@ DISTLIST= ${STD_HELP_FILES} ${DETAIL_HELP} ${MAKE_FILE} \
# These files are used to make (but not built) a calc .a link library
#
CALCLIBLIST=
#
# rules that are not also names of files
#
PHONY= all clobber distlist install
all: ${FULL_HELP_FILES} full ${DETAIL_HELP} ${DETAIL_CLONE} \
${SINGULAR_FILES} .all
@@ -430,6 +425,8 @@ all: ${FULL_HELP_FILES} full ${DETAIL_HELP} ${DETAIL_CLONE} \
${RM} -f .all
${TOUCH} .all
.PHONY: ${PHONY}
bindings: ../cal/bindings
${RM} -f $@
${CP} ../cal/bindings $@
@@ -529,7 +526,7 @@ usage: ../calc.usage
fi
../calc.usage:
(cd ..; ${MAKE} -f ${TOP_MAKE_FILE} calc.usage)
(cd ..; ${MAKE} -f ${MAKE_FILE} calc.usage)
custom_cal: ../custom/CUSTOM_CAL
${RM} -f $@
@@ -632,6 +629,18 @@ cscript: ../cscript/README
${Q} ${RM} -f $@
(cd ../cscript; ${MAKE} -f Makefile README)
releases: ../README.RELEASE
${RM} -f $@
${CP} ../README.RELEASE $@
${CHMOD} 0444 $@
-@if [ -z "${Q}" ]; then \
echo ''; \
echo '=-=-= skipping the ${CAT} of help/$@ =-=-='; \
echo ''; \
else \
${TRUE}; \
fi
full: ${FULL_HELP_FILES} ${MAKE_FILE}
${Q} echo "forming full"
${Q} ${RM} -f $@
@@ -747,14 +756,6 @@ calcliblist:
fi; \
done
# The BSDI cdrom makefile expects all help files to be pre-built. This rule
# creates these files so that the release can be shipped off to BSDI. You can
# ignore this rule.
#
bsdi: all
${RM} -f obj
${CP} obj.file obj
# These next rule help form the ${DETAIL_HELP} makefile variables above.
#
# NOTE: The ${DETAIL_HELP} list does not include special help files.

View File

@@ -1,21 +1,27 @@
Where to get the latest versions of calc
Landon Noll maintains the official calc home page at:
Official calc source is maintained on GitHub:
https://github.com/lcn2/calc
Calc releases may be found as GitHub tagged releases:
https://github.com/lcn2/calc/releases?page=2
At the bottom of a given release is a "> Assets" that may
be opened to reveal down-loadable files such as source
tarballs, source zip files and RPMs.
Landon Noll also maintains a calc home page at:
http://www.isthe.com/chongo/tech/comp/calc/
See:
http://www.isthe.com/chongo/tech/comp/calc/calc-download.html
for information on how to obtain up a recent version of calc.
Landon Curt Noll
http://www.isthe.com/chongo/
chongo <was here> /\../\
## 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

View File

@@ -215,22 +215,22 @@ Command sequence
blocks unfreed named blocks
builtin built in functions
config config parameters and values
constants cache of numeric constants
constants cache of numeric constants
custom custom functions if calc -C was used
errors new error-values created
files open files, file position and sizes
function user-defined functions
globaltypes global variables
function user-defined functions
globaltypes global variables
objfunctions possible object functions
objtypes defined objects
opcodes func internal opcodes for function `func'
objtypes defined objects
opcodes internal opcodes for function `func'
sizes size in octets of calc value types
realglobals numeric global variables
realglobals numeric global variables
statics un-scoped static variables
numbers calc number cache
redcdata REDC data defined
redcdata REDC data defined
strings calc string cache
literals calc literal cache
literals calc literal cache
Only the first 4 characters of item are examined, so:

View File

@@ -34,6 +34,7 @@ DESCRIPTION
"pow2" sets size for alternate powering.
"redc2" sets size for alternate REDC.
"tilde" enable/disable printing of the roundoff '~'
"tilde_space" enable/disable printing space after roundoff tilde '~ '
"tab" enable/disable printing of leading tabs
"quomod" sets rounding mode for quomod
"quo" sets rounding mode for //, default for quo
@@ -134,6 +135,7 @@ DESCRIPTION
config("display", 50); 50 digits of output
epsilon(epsilon() / 8); 3 bits more accuracy
config("tilde", 0) disable roundoff tilde printing
config("tilde_space", 1) enable printing space after roundoff tilde
config("tab", "off") disable leading tab printing
=-=
@@ -264,7 +266,7 @@ DESCRIPTION
config("mul2", int)
config("sq2", int)
Mul2 and sq2 specify the sizes of numbers at which calc switches
Both "mul2" and "sq2" specify the sizes of numbers at which calc switches
from its first to its second algorithm for multiplying and squaring.
The first algorithm is the usual method of cross multiplying, which
runs in a time of O(N^2). The second method is a recursive and
@@ -305,7 +307,7 @@ DESCRIPTION
config("pow2", int)
Pow2 specifies the sizes of numbers at which calc switches from
The "pow2" specifies the sizes of numbers at which calc switches from
its first to its second algorithm for calculating powers modulo
another number. The first algorithm for calculating modular powers
is by repeated squaring and multiplying and dividing by the modulus.
@@ -334,7 +336,7 @@ DESCRIPTION
config("redc2", int)
Redc2 specifies the sizes of numbers at which calc switches from
The "redc2" specifies the sizes of numbers at which calc switches from
its first to its second algorithm when using the REDC algorithm.
The first algorithm performs a multiply and a modular reduction
together in one loop which runs in O(N^2). The second algorithm
@@ -363,16 +365,48 @@ DESCRIPTION
config("tilde", boolean)
Config("tilde") controls whether or not a leading tilde ('~') is
The "tilde" controls whether or not a leading tilde ('~') is
printed to indicate that a number has not been printed exactly
because the number of decimal digits required would exceed the
specified maximum number. The initial "tilde" value is 1.
specified maximum number.
If config("tilde") is false, then config("tilde_space") has no effect.
The initial "tilde" value is 1 (on).
=-=
config("tilde_space", boolean)
The "tilde_space" controls whether or not a space (' ') is
printed after leading tilde ('~'). See config("tilde") above.
If config("tilde") is false, then config("tilde_space") has no effect.
NOTE: Use of config("tilde_space", 1) can break printing and scanning
of complex values via "%c".
The initial "tilde_space" value is 0 (off)
=-=
config("fraction_space", boolean)
The "fraction_space" controls whether or not a space (' ') is
printed both before and after '/' when printing a fraction.
NOTE: Use of config("fraction_space", 1) can break printing and scanning
of fractional values via "%r".
NOTE: Use of config("fraction_space", 1) can break printing and scanning
of complex values via "%c".
The initial "fraction_space" value is 0 (off).
=-=
config("tab", boolean)
Config ("tab") controls the printing of a tab before results
config("tab") controls the printing of a tab before results
automatically displayed when working interactively. It does not
affect the printing by the functions print, printf, etc. The initial
"tab" value is 1.
@@ -908,6 +942,7 @@ EXAMPLE
pow2 40
redc2 50
tilde 1
tilde_space 0
tab 1
quomod 0
quo 2
@@ -944,6 +979,7 @@ EXAMPLE
redecl_warn 1
dupvar_warn 1
hz 100
fraction_space 0
; display()
20

View File

@@ -48,6 +48,8 @@ following topics:
copyright calc copyright and the GNU LGPL
copying details on the Calc GNU Lesser General Public License
copying-lgpl calc GNU Lesser General Public License text
questions how to ask simple general question about calc
release on calc versions and releases
full all of the above (in the above order)
@@ -123,7 +125,7 @@ Any help file that the help command is able to display may be
displayed by the man command. The man command may only display
calc help files.
## Copyright (C) 1999-2007,2017 Landon Curt Noll
## Copyright (C) 1999-2007,2017,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

View File

@@ -12,6 +12,11 @@ TYPES
DESCRIPTION
Seed the pseudo-random number using an subtractive 100 shuffle generator.
It you want a quick and effective way to seed the generator,
we recommended that you call srand() with the seed() value:
srand(seed())
For integer seed != 0:
Any buffered rand generator bits are flushed. The subtractive table
@@ -150,7 +155,7 @@ LINK LIBRARY
SEE ALSO
seed, srandom, randbit, isrand, random, srandom, israndom
## 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

View File

@@ -20,6 +20,11 @@ TYPES
DESCRIPTION
Seed the pseudo-random number using the Blum-Blum-Shub generator.
It you want a quick and effective way to seed the generator,
we recommended that you call srandom() with the seed() value:
srandom(seed())
There are two primary values contained inside generator state:
Blum modulus:
@@ -58,7 +63,7 @@ DESCRIPTION
call of srandom(0) will restore the generator to the state
found when calc starts.
1 arg (seed >= 2^32): srandom(21609139158123209^9+17)
1 arg (seed >= 2^32): srandom(seed())
The seed value is used to compute the new quadratic residue.
The seed passed will be successively squared mod the Blum

7
hist.c
View File

@@ -1,7 +1,7 @@
/*
* hist - interactive readline module
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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
@@ -69,6 +69,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -136,7 +137,7 @@ S_FUNC void uppercase_word(void);
S_FUNC void lowercase_word(void);
S_FUNC void ignore_char(void);
S_FUNC void arrow_key(void);
S_FUNC void quit_calc(void);
S_FUNC void quit_calc(void) __attribute__((noreturn));
STATIC FUNC funcs[] =
@@ -1493,7 +1494,7 @@ hist_getline(char *prompt, char *buf, size_t len)
case CTRL_D_EMPTY_EOF:
default:
quit_calc();
/*NOTREACHED*/
not_reached();
}
}
strlcpy(buf, line, len);

19
input.c
View File

@@ -1,7 +1,7 @@
/*
* input - nested input source file reader
*
* Copyright (C) 1999-2007,2014,2018,2021 David I. Bell
* Copyright (C) 1999-2007,2014,2018,2021,2022 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
@@ -55,6 +55,7 @@
#include "strl.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -148,7 +149,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
/* firewall */
if (name == NULL) {
math_error("NULL name given to opensearchfile");
/*NOTREACHED*/
not_reached();
}
/*
@@ -190,7 +191,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
path = malloc(path_alloc+1);
if (path == NULL) {
math_error("Cannot allocate filename path buffer");
/*NOTREACHED*/
not_reached();
}
path[0] = '\0'; /* paranoia */
path[path_alloc] = '\0'; /* paranoia */
@@ -304,11 +305,11 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
/* firewall */
if (name == NULL) {
math_error("NULL name given to f_pathopen");
/*NOTREACHED*/
not_reached();
}
if (mode == NULL) {
math_error("NULL mode given to f_pathopen");
/*NOTREACHED*/
not_reached();
}
/*
@@ -342,7 +343,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
path = malloc(pathlen+1 + 1 + namelen+1 + 1 + 1);
if (path == NULL) {
math_error("Cannot allocate f_pathopen buffer");
/*NOTREACHED*/
not_reached();
}
/*
@@ -375,7 +376,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
}
fclose(ret);
math_error("cannot malloc return openpath buffer");
/*NOTREACHED*/
not_reached();
}
}
free(path);
@@ -756,7 +757,7 @@ nextline(void)
cp = (char *)malloc(TTYSIZE + 1);
if (cp == NULL) {
math_error("Cannot allocate line buffer");
/*NOTREACHED*/
not_reached();
}
linebuf = cp;
linesize = TTYSIZE;
@@ -776,7 +777,7 @@ nextline(void)
cp = (char *)realloc(cp, linesize + TTYSIZE + 1);
if (cp == NULL) {
math_error("Cannot realloc line buffer");
/*NOTREACHED*/
not_reached();
}
linebuf = cp;
linesize += TTYSIZE;

View File

@@ -1,7 +1,7 @@
/*
* lib_calc - calc link library initialization and shutdown routines
*
* Copyright (C) 1999-2007,2018,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2018,2021,2022 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
@@ -94,6 +94,7 @@ typedef struct {int fd;} ttystruct;
#endif /* Windows */
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -320,6 +321,7 @@ libcalc_call_me_first(void)
if (d_flag) {
conf->resource_debug = 0;
conf->tilde_ok = 0;
conf->tilde_space = 0;
}
/*
@@ -500,7 +502,7 @@ initenv(void)
if (strlen(calcrc) > MAX_CALCRC) {
math_error("The $CALCRC variable is longer than %d chars",
MAX_CALCRC);
/*NOTREACHED*/
not_reached();
}
/* determine the $CALCBINDINGS value */
@@ -542,7 +544,7 @@ initenv(void)
/* paranoia */
if (home == NULL) {
math_error("Unable to allocate string for $HOME");
/*NOTREACHED*/
not_reached();
}
/* determine the $PAGER value */
@@ -692,7 +694,7 @@ calc_strdup(CONST char *s1)
#else /* HAVE_STRDUP */
char *ret; /* return string */
size_t s1_len; /* length of string to duplicate */
size_t s1_len; /* length of string to duplicate */
/*
* firewall
@@ -736,7 +738,7 @@ S_FUNC int
find_tty_state(int fd)
{
int *new_fd_setup; /* new fd_setup array */
ttystruct *new_fd_orig; /* new fd_orig array */
ttystruct *new_fd_orig; /* new fd_orig array */
ttystruct *new_fd_cur; /* new fd_cur array */
int i;
@@ -763,7 +765,7 @@ find_tty_state(int fd)
if (fd_orig == NULL) {
return -1;
}
fd_cur = (ttystruct *)malloc(sizeof(fd_orig[0]));
fd_cur = (ttystruct *)malloc(sizeof(fd_cur[0]));
if (fd_cur == NULL) {
return -1;
}
@@ -795,26 +797,35 @@ find_tty_state(int fd)
/*
* no empty slots exist, realloc another slot
*/
/* expand fd_orig as an original pre-modified copy of fd_setup */
new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) *
(fd_setup_len+1));
if (new_fd_orig == NULL) {
return -1;
}
fd_orig = new_fd_orig;
memcpy(fd_orig, fd_setup, sizeof(fd_orig[0]) * (fd_setup_len+1));
/* expand fd_setup */
new_fd_setup = (int *)realloc(fd_setup, sizeof(fd_setup[0]) *
(fd_setup_len+1));
if (new_fd_setup == NULL) {
return -1;
}
fd_setup = new_fd_setup;
new_fd_setup[fd_setup_len] = -1;
new_fd_orig = (ttystruct *)realloc(fd_setup, sizeof(fd_orig[0]) *
(fd_setup_len+1));
if (new_fd_orig == NULL) {
return -1;
}
/* expand fd_cur */
new_fd_cur = (ttystruct *)realloc(fd_cur, sizeof(fd_cur[0]) *
(fd_setup_len+1));
if (new_fd_cur == NULL) {
return -1;
}
fd_setup = new_fd_setup;
fd_orig = new_fd_orig;
fd_cur = new_fd_cur;
/* expand fd setup length */
++fd_setup_len;
/* return the new slot */
return fd_setup_len-1;
}

View File

@@ -1,7 +1,7 @@
/*
* lib_util - calc library utility routines
*
* Copyright (C) 1999-2006,2021 Landon Curt Noll
* Copyright (C) 1999-2006,2021,2022 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,6 +35,7 @@
#include "lib_util.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -151,7 +152,7 @@ convstr2z(char *str)
v = (HALF *)malloc(len * sizeof(HALF));
if (v == NULL) {
math_error("convstr2z bad malloc");
/*NOTREACHED*/
not_reached();
}
v[len-1] = 0; /* deal with possible partial end of string HALF */
@@ -222,7 +223,7 @@ convhex2z(char *hex)
v = (HALF *)malloc(len * sizeof(HALF));
if (v == NULL) {
math_error("convhex2z bad malloc");
/*NOTREACHED*/
not_reached();
}
v[len-1] = 0; /* deal with possible partial end of string HALF */
@@ -313,7 +314,7 @@ convz2hex(ZVALUE z)
ret = (char *)malloc(sizeof("0"));
if (ret == NULL) {
math_error("convz2hex bad malloc of 0 value");
/*NOTREACHED*/
not_reached();
}
ret[0] = '0';
ret[1] = '\0';
@@ -327,7 +328,7 @@ convz2hex(ZVALUE z)
ret = (char *)calloc(slen+1+1, sizeof(char));
if (ret == NULL) {
math_error("convz2hex bad malloc of string");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -1,7 +1,7 @@
/*
* listfunc - list handling routines
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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
@@ -37,6 +37,7 @@
#include "zrand.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -129,7 +130,7 @@ insertlistmiddle(LIST *lp, long index, VALUE *vp)
oldep = listelement(lp, index);
if (oldep == NULL) {
math_error("Index out of bounds for list insertion");
/*NOTREACHED*/
not_reached();
}
ep = elemalloc();
copyvalue(vp, &ep->e_value);
@@ -207,7 +208,7 @@ removelistmiddle(LIST *lp, long index, VALUE *vp)
ep = listelement(lp, index);
if (ep == NULL) {
math_error("Index out of bounds for list deletion");
/*NOTREACHED*/
not_reached();
}
*vp = ep->e_value;
ep->e_value.v_type = V_NULL;
@@ -297,14 +298,14 @@ listsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > lp->l_count) {
math_error("This should not happen in call to listsearch");
/*NOTREACHED*/
not_reached();
}
ep = listelement(lp, i);
while (i < j) {
if (!ep) {
math_error("This should not happen in listsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
lp->l_cache = ep;
@@ -331,14 +332,14 @@ listrsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > lp->l_count) {
math_error("This should not happen in call to listrsearch");
/*NOTREACHED*/
not_reached();
}
ep = listelement(lp, --j);
while (j >= i) {
if (!ep) {
math_error("This should not happen in listsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
lp->l_cache = ep;
@@ -771,7 +772,7 @@ listsort(LIST *lp)
if (k >= LONG_BITS) {
/* this should never happen */
math_error("impossible k overflow in listsort!");
/*NOTREACHED*/
not_reached();
}
lp->l_first = start->e_next;
lp->l_first->e_prev = NULL;
@@ -812,7 +813,7 @@ elemalloc(void)
ep = (LISTELEM *) malloc(sizeof(LISTELEM));
if (ep == NULL) {
math_error("Cannot allocate list element");
/*NOTREACHED*/
not_reached();
}
ep->e_next = NULL;
ep->e_prev = NULL;
@@ -845,7 +846,7 @@ listalloc(void)
lp = (LIST *) malloc(sizeof(LIST));
if (lp == NULL) {
math_error("Cannot allocate list header");
/*NOTREACHED*/
not_reached();
}
lp->l_first = NULL;
lp->l_last = NULL;

View File

@@ -1,7 +1,7 @@
/*
* matfunc - extended precision rational arithmetic matrix functions
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -63,7 +64,7 @@ matadd(MATRIX *m1, MATRIX *m2)
if (m1->m_dim != m2->m_dim) {
math_error("Incompatible matrix dimensions for add");
/*NOTREACHED*/
not_reached();
}
tmp.m_dim = m1->m_dim;
tmp.m_size = m1->m_size;
@@ -75,7 +76,7 @@ matadd(MATRIX *m1, MATRIX *m2)
if ((min1 && min2 && (min1 != min2)) ||
((max1-min1) != (max2-min2))) {
math_error("Incompatible matrix bounds for add");
/*NOTREACHED*/
not_reached();
}
tmp.m_min[dim] = (min1 ? min1 : min2);
tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1);
@@ -105,7 +106,7 @@ matsub(MATRIX *m1, MATRIX *m2)
if (m1->m_dim != m2->m_dim) {
math_error("Incompatible matrix dimensions for sub");
/*NOTREACHED*/
not_reached();
}
tmp.m_dim = m1->m_dim;
tmp.m_size = m1->m_size;
@@ -117,7 +118,7 @@ matsub(MATRIX *m1, MATRIX *m2)
if ((min1 && min2 && (min1 != min2)) ||
((max1-min1) != (max2-min2))) {
math_error("Incompatible matrix bounds for sub");
/*NOTREACHED*/
not_reached();
}
tmp.m_min[dim] = (min1 ? min1 : min2);
tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1);
@@ -187,7 +188,7 @@ matmul(MATRIX *m1, MATRIX *m2)
if (m1->m_dim == 1 && m2->m_dim == 1) {
if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) {
math_error("Incompatible bounds for 1D * 1D matmul");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m1->m_size);
*res = *m1;
@@ -201,7 +202,7 @@ matmul(MATRIX *m1, MATRIX *m2)
if (m1->m_dim == 1 && m2->m_dim == 2) {
if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) {
math_error("Incompatible bounds for 1D * 2D matmul");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m2->m_size);
*res = *m2;
@@ -221,7 +222,7 @@ matmul(MATRIX *m1, MATRIX *m2)
if (m1->m_dim == 2 && m2->m_dim == 1) {
if (m1->m_max[1]-m1->m_min[1] != m2->m_max[0]-m2->m_min[0]) {
math_error("Incompatible bounds for 2D * 1D matmul");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m1->m_size);
*res = *m1;
@@ -240,11 +241,11 @@ matmul(MATRIX *m1, MATRIX *m2)
if ((m1->m_dim != 2) || (m2->m_dim != 2)) {
math_error("Matrix dimensions not compatible for mul");
/*NOTREACHED*/
not_reached();
}
if ((m1->m_max[1]-m1->m_min[1]) != (m2->m_max[0]-m2->m_min[0])) {
math_error("Incompatible bounds for 2D * 2D matrix mul");
/*NOTREACHED*/
not_reached();
}
max1 = (m1->m_max[0] - m1->m_min[0] + 1);
max2 = (m2->m_max[1] - m2->m_min[1] + 1);
@@ -301,11 +302,11 @@ matsquare(MATRIX *m)
}
if (m->m_dim != 2) {
math_error("Matrix dimension exceeds two for square");
/*NOTREACHED*/
not_reached();
}
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
math_error("Squaring non-square matrix");
/*NOTREACHED*/
not_reached();
}
max = (m->m_max[0] - m->m_min[0] + 1);
res = matalloc(max * max);
@@ -357,20 +358,20 @@ matpowi(MATRIX *m, NUMBER *q)
if (m->m_dim > 2) {
math_error("Matrix dimension greater than 2 for power");
/*NOTREACHED*/
not_reached();
}
if (m->m_dim == 2 && (m->m_max[0] - m->m_min[0] !=
m->m_max[1] - m->m_min[1])) {
math_error("Raising non-square 2D matrix to a power");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(q)) {
math_error("Raising matrix to non-integral power");
/*NOTREACHED*/
not_reached();
}
if (zge31b(q->num)) {
math_error("Raising matrix to very large power");
/*NOTREACHED*/
not_reached();
}
power = ztolong(q->num);
if (qisneg(q))
@@ -610,7 +611,7 @@ matquoval(MATRIX *m, VALUE *vp, VALUE *v3)
if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m->m_size);
*res = *m;
@@ -640,7 +641,7 @@ matmodval(MATRIX *m, VALUE *vp, VALUE *v3)
if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m->m_size);
*res = *m;
@@ -866,31 +867,31 @@ matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
if (dim < 0) {
math_error("Negative dimension %ld for matrix", dim);
/*NOTREACHED*/
not_reached();
}
for (;;) {
if (dim < mp->m_dim) {
math_error(
"Indexing a %ldd matrix as a %ldd matrix",
mp->m_dim, dim);
/*NOTREACHED*/
not_reached();
}
offset = 0;
for (i = 0; i < mp->m_dim; i++) {
if (indices->v_type != V_NUM) {
math_error("Non-numeric index for matrix");
/*NOTREACHED*/
not_reached();
}
q = indices->v_num;
if (qisfrac(q)) {
math_error("Non-integral index for matrix");
/*NOTREACHED*/
not_reached();
}
index = qtoi(q);
if (zge31b(q->num) || (index < mp->m_min[i]) ||
(index > mp->m_max[i])) {
math_error("Index out of bounds for matrix");
/*NOTREACHED*/
not_reached();
}
offset *= (mp->m_max[i] - mp->m_min[i] + 1);
offset += (index - mp->m_min[i]);
@@ -902,7 +903,7 @@ matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
break;
if (vp->v_type != V_MAT) {
math_error("Non-matrix argument for matindex");
/*NOTREACHED*/
not_reached();
}
mp = vp->v_mat;
}
@@ -953,7 +954,7 @@ matsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index)
val = &m->m_table[i];
if (i < 0 || j > m->m_size) {
math_error("This should not happen in call to matsearch");
/*NOTREACHED*/
not_reached();
}
while (i < j) {
if (acceptvalue(val++, vp)) {
@@ -978,7 +979,7 @@ matrsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > m->m_size) {
math_error("This should not happen in call to matrsearch");
/*NOTREACHED*/
not_reached();
}
val = &m->m_table[--j];
while (j >= i) {
@@ -1056,11 +1057,11 @@ matident(MATRIX *m)
if (m->m_dim != 2) {
math_error(
"Matrix dimension must be two for setting to identity");
/*NOTREACHED*/
not_reached();
}
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
math_error("Matrix must be square for setting to identity");
/*NOTREACHED*/
not_reached();
}
res = matalloc(m->m_size);
*res = *m;
@@ -1108,11 +1109,11 @@ matinv(MATRIX *m)
}
if (m->m_dim != 2) {
math_error("Matrix dimension exceeds two for inverse");
/*NOTREACHED*/
not_reached();
}
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
math_error("Inverting non-square matrix");
/*NOTREACHED*/
not_reached();
}
/*
* Begin by creating the identity matrix with the same attributes.
@@ -1154,7 +1155,7 @@ matinv(MATRIX *m)
matfree(m);
matfree(res);
math_error("Matrix is not invertible");
/*NOTREACHED*/
not_reached();
}
val += rows;
}
@@ -1447,7 +1448,7 @@ matinit(MATRIX *m, VALUE *v1, VALUE *v2)
((res->m_max[0] - res->m_min[0]) !=
(res->m_max[1] - res->m_min[1])))) {
math_error("Filling diagonals of non-square matrix");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1489,7 +1490,7 @@ matalloc(long size)
if (m == NULL) {
math_error("Cannot get memory to allocate matrix of size %ld",
size);
/*NOTREACHED*/
not_reached();
}
m->m_size = size;
for (i = size, vp = m->m_table; i > 0; i--, vp++)
@@ -1617,7 +1618,7 @@ matsort(MATRIX *m)
buf = (VALUE *) malloc(m->m_size * sizeof(VALUE));
if (buf == NULL) {
math_error("Not enough memory for matsort");
/*NOTREACHED*/
not_reached();
}
next = m->m_table;
end = next + m->m_size;
@@ -1672,7 +1673,7 @@ matsort(MATRIX *m)
if (k >= LONG_BITS) {
/* this should never happen */
math_error("impossible k overflow in matsort!");
/*NOTREACHED*/
not_reached();
}
}

41
obj.c
View File

@@ -1,7 +1,7 @@
/*
* obj - object handling primitives
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "strl.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -223,7 +224,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
if ((unsigned)action > OBJ_MAXFUNC) {
math_error("Illegal action for object call");
/*NOTREACHED*/
not_reached();
}
oip = &objectinfo[action];
if (v1->v_type == V_OBJ) {
@@ -232,20 +233,20 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
oap = v2->v_obj->o_actions;
} else {
math_error("Object routine called with non-object");
/*NOTREACHED*/
not_reached();
}
index = oap->oa_indices[action];
if (index < 0) {
namestr_ret = namestr(&objectnames, oap->oa_index);
if (namestr_ret == NULL) {
math_error("namestr returned NULL!!!");
/*NOTREACHED*/
not_reached();
}
namestr_len = strlen(namestr_ret);
opi_name_len = strlen(oip->name);
if (namestr_len > (size_t)SYMBOLSIZE-1-opi_name_len) {
math_error("namestr returned a strong too long!!!");
/*NOTREACHED*/
not_reached();
}
name[0] = '\0';
strlcpy(name, namestr_ret, namestr_len+1);
@@ -278,7 +279,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
case ERR_POW:
if (v2->v_type != V_NUM) {
math_error("Non-real power");
/*NOTREACHED*/
not_reached();
}
val = objpowi(v1, v2->v_num);
break;
@@ -312,7 +313,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
default:
math_error("Function \"%s\" is undefined",
namefunc(index));
/*NOTREACHED*/
not_reached();
}
return val;
}
@@ -345,7 +346,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
break;
default:
math_error("Bad number of args to calculate");
/*NOTREACHED*/
not_reached();
}
calculate(fp, oip->args);
switch (oip->retval) {
@@ -358,7 +359,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
case A_INT:
if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) {
math_error("Integer return value required");
/*NOTREACHED*/
not_reached();
}
index = qtoi(stack->v_num);
qfree(stack->v_num);
@@ -368,7 +369,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
break;
default:
math_error("Bad object return");
/*NOTREACHED*/
not_reached();
}
return val;
}
@@ -457,11 +458,11 @@ objpowi(VALUE *vp, NUMBER *q)
if (qisfrac(q)) {
math_error("Raising object to non-integral power");
/*NOTREACHED*/
not_reached();
}
if (zge31b(q->num)) {
math_error("Raising object to very large power");
/*NOTREACHED*/
not_reached();
}
power = ztolong(q->num);
if (qisneg(q))
@@ -572,7 +573,7 @@ defineobject(char *name, int indices[], int count)
}
if (newobjects == NULL) {
math_error("Allocation failure for new object type");
/*NOTREACHED*/
not_reached();
}
objects = newobjects;
}
@@ -580,12 +581,12 @@ defineobject(char *name, int indices[], int count)
oap = (OBJECTACTIONS *) malloc(objectactionsize(count));
if (oap == NULL) {
math_error("Cannot allocate object type #0");
/*NOTREACHED*/
not_reached();
}
name = addstr(hp, name);
if (name == NULL) {
math_error("Cannot allocate object type #1");
/*NOTREACHED*/
not_reached();
}
oap->oa_count = count;
for (index = OBJ_MAXFUNC; index >= 0; index--)
@@ -634,7 +635,7 @@ addelement(char *name)
return index;
if (addstr(hp, name) == NULL) {
math_error("Cannot allocate element name");
/*NOTREACHED*/
not_reached();
}
return findstr(hp, name);
}
@@ -699,12 +700,12 @@ objalloc(long index)
if (index < 0 || index > maxobjcount) {
math_error("Allocating bad object index");
/*NOTREACHED*/
not_reached();
}
oap = objects[index];
if (oap == NULL) {
math_error("Object type not defined");
/*NOTREACHED*/
not_reached();
}
i = oap->oa_count;
if (i < USUAL_ELEMENTS)
@@ -715,7 +716,7 @@ objalloc(long index)
op = (OBJECT *) malloc(objectsize(i));
if (op == NULL) {
math_error("Cannot allocate object");
/*NOTREACHED*/
not_reached();
}
op->o_actions = oap;
vp = op->o_table;
@@ -771,7 +772,7 @@ objcopy(OBJECT *op)
np = (OBJECT *) malloc(objectsize(i));
if (np == NULL) {
math_error("Cannot allocate object");
/*NOTREACHED*/
not_reached();
}
np->o_actions = op->o_actions;
v1 = op->o_table;

149
opcodes.c
View File

@@ -1,7 +1,7 @@
/*
* opcodes - opcode execution module
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -38,7 +38,7 @@
#include "file.h"
#include "zrand.h"
#include "zrandom.h"
#include "have_fpos.h"
#include "have_fgetsetpos.h"
#include "custom.h"
#include "lib_calc.h"
#include "block.h"
@@ -47,6 +47,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -153,7 +154,7 @@ o_localaddr(FUNC *fp, VALUE *locals, long index)
{
if ((unsigned long)index >= fp->f_localcount) {
math_error("Bad local variable index");
/*NOTREACHED*/
not_reached();
}
locals += index;
stack++;
@@ -170,7 +171,7 @@ o_globaladdr(FUNC *UNUSED(fp), GLOBAL *sp)
if (sp == NULL) {
math_error("Global variable \"%s\" not initialized",
sp->g_name);
/*NOTREACHED*/
not_reached();
}
stack++;
stack->v_addr = &sp->g_value;
@@ -185,7 +186,7 @@ o_paramaddr(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
/*NOTREACHED*/
not_reached();
}
args += index;
stack++;
@@ -204,7 +205,7 @@ o_localvalue(FUNC *fp, VALUE *locals, long index)
{
if ((unsigned long)index >= fp->f_localcount) {
math_error("Bad local variable index");
/*NOTREACHED*/
not_reached();
}
locals += index;
copyvalue(locals, ++stack);
@@ -217,7 +218,7 @@ o_globalvalue(FUNC *UNUSED(fp), GLOBAL *sp)
{
if (sp == NULL) {
math_error("Global variable not defined");
/*NOTREACHED*/
not_reached();
}
copyvalue(&sp->g_value, ++stack);
}
@@ -229,7 +230,7 @@ o_paramvalue(FUNC *UNUSED(fp), int argcount, VALUE *args, long index)
{
if ((long)index >= argcount) {
math_error("Bad parameter index");
/*NOTREACHED*/
not_reached();
}
args += index;
if (args->v_type == V_ADDR)
@@ -250,7 +251,7 @@ o_argvalue(FUNC *fp, int argcount, VALUE *args)
if ((vp->v_type != V_NUM) || qisneg(vp->v_num) ||
qisfrac(vp->v_num)) {
math_error("Illegal argument for arg function");
/*NOTREACHED*/
not_reached();
}
if (qiszero(vp->v_num)) {
if (stack->v_type == V_NUM)
@@ -277,7 +278,7 @@ o_number(FUNC *UNUSED(fp), long arg)
q = constvalue(arg);
if (q == NULL) {
math_error("Numeric constant value not found");
/*NOTREACHED*/
not_reached();
}
stack++;
stack->v_num = qlink(q);
@@ -296,7 +297,7 @@ o_imaginary(FUNC *UNUSED(fp), long arg)
q = constvalue(arg);
if (q == NULL) {
math_error("Numeric constant value not found");
/*NOTREACHED*/
not_reached();
}
stack++;
stack->v_subtype = V_NOSUBTYPE;
@@ -349,7 +350,7 @@ o_matcreate(FUNC *UNUSED(fp), long dim)
if ((dim < 0) || (dim > MAXDIM)) {
math_error("Bad dimension %ld for matrix", dim);
/*NOTREACHED*/
not_reached();
}
size = 1;
for (i = dim - 1; i >= 0; i--) {
@@ -361,17 +362,17 @@ o_matcreate(FUNC *UNUSED(fp), long dim)
v2 = v2->v_addr;
if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM)) {
math_error("Non-numeric bounds for matrix");
/*NOTREACHED*/
not_reached();
}
num1 = v1->v_num;
num2 = v2->v_num;
if (qisfrac(num1) || qisfrac(num2)) {
math_error("Non-integral bounds for matrix");
/*NOTREACHED*/
not_reached();
}
if (zge31b(num1->num) || zge31b(num2->num)) {
math_error("Very large bounds for matrix");
/*NOTREACHED*/
not_reached();
}
min[i] = qtoi(num1);
max[i] = qtoi(num2);
@@ -383,7 +384,7 @@ o_matcreate(FUNC *UNUSED(fp), long dim)
size *= (max[i] - min[i] + 1);
if (size > 10000000) {
math_error("Very large size for matrix");
/*NOTREACHED*/
not_reached();
}
freevalue(stack--);
freevalue(stack--);
@@ -558,13 +559,13 @@ o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
flag = (writeflag != 0);
if (dim < 0) {
math_error("Negative dimension for indexing");
/*NOTREACHED*/
not_reached();
}
val = &stack[-dim];
if (val->v_type != V_NBLOCK && val->v_type != V_FILE) {
if (val->v_type != V_ADDR) {
math_error("Non-pointer for indexaddr");
/*NOTREACHED*/
not_reached();
}
val = val->v_addr;
}
@@ -593,7 +594,7 @@ o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
blk = val->v_nblock->blk;
if (blk->data == NULL) {
math_error("Freed block");
/*NOTREACHED*/
not_reached();
}
/*
@@ -601,26 +602,26 @@ o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
*/
if (dim != 1) {
math_error("block has only one dimension");
/*NOTREACHED*/
not_reached();
}
if (indices[0].v_type != V_NUM) {
math_error("Non-numeric index for block");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(indices[0].v_num)) {
math_error("Non-integral index for block");
/*NOTREACHED*/
not_reached();
}
if (zge31b(indices[0].v_num->num) ||
zisneg(indices[0].v_num->num)) {
math_error("Index out of bounds for block");
/*NOTREACHED*/
not_reached();
}
index = ztoi(indices[0].v_num->num);
if (index >= blk->maxsize) {
math_error("Index out of bounds for block");
/*NOTREACHED*/
not_reached();
}
if (index >= blk->datalen)
blk->datalen = index + 1;
@@ -633,25 +634,25 @@ o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
case V_STR:
if (dim != 1) {
math_error("string has only one dimension");
/*NOTREACHED*/
not_reached();
}
if (indices[0].v_type != V_NUM) {
math_error("Non-numeric index for string");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(indices[0].v_num)) {
math_error("Non-integral index for string");
/*NOTREACHED*/
not_reached();
}
if (zge31b(indices[0].v_num->num) ||
zisneg(indices[0].v_num->num)) {
math_error("Index out of bounds for string");
/*NOTREACHED*/
not_reached();
}
index = ztoi(indices[0].v_num->num);
if (index < 0 || (size_t)index >= val->v_str->s_len) {
math_error("Index out of bounds for string");
/*NOTREACHED*/
not_reached();
}
ret.v_type = V_OCTET;
ret.v_subtype = val->v_subtype;
@@ -662,31 +663,31 @@ o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag)
case V_LIST:
if (dim != 1) {
math_error("list has only one dimension");
/*NOTREACHED*/
not_reached();
}
if (indices[0].v_type != V_NUM) {
math_error("Non-numeric index for list");
/*NOTREACHED*/
not_reached();
}
if (qisfrac(indices[0].v_num)) {
math_error("Non-integral index for list");
/*NOTREACHED*/
not_reached();
}
if (zge31b(indices[0].v_num->num) ||
zisneg(indices[0].v_num->num)) {
math_error("Index out of bounds for list");
/*NOTREACHED*/
not_reached();
}
index = ztoi(indices[0].v_num->num);
vp = listfindex(val->v_list, index);
if (vp == NULL) {
math_error("Index out of bounds for list");
/*NOTREACHED*/
not_reached();
}
break;
default:
math_error("Illegal value for indexing");
/*NOTREACHED*/
not_reached();
}
while (dim-- > 0)
freevalue(stack--);
@@ -712,7 +713,7 @@ o_elemaddr(FUNC *UNUSED(fp), long index)
mp = vp->v_mat;
if ((index < 0) || (index >= mp->m_size)) {
math_error("Non-existent element for matrix");
/*NOTREACHED*/
not_reached();
}
vp = &mp->m_table[index];
break;
@@ -721,7 +722,7 @@ o_elemaddr(FUNC *UNUSED(fp), long index)
offset = objoffset(op, index);
if (offset < 0) {
math_error("Non-existent element for object");
/*NOTREACHED*/
not_reached();
}
vp = &op->o_table[offset];
break;
@@ -729,12 +730,12 @@ o_elemaddr(FUNC *UNUSED(fp), long index)
vp = listfindex(vp->v_list, index);
if (vp == NULL) {
math_error("Index out of bounds for list");
/*NOTREACHED*/
not_reached();
}
break;
default:
math_error("Not initializing matrix, object or list");
/*NOTREACHED*/
not_reached();
}
stack->v_type = V_ADDR;
stack->v_addr = vp;
@@ -917,7 +918,7 @@ o_ptr(void)
break;
default:
math_error("Addressing non-addressable type");
/*NOTREACHED*/
not_reached();
}
}
@@ -957,7 +958,7 @@ o_deref(void)
}
if (stack->v_type != V_ADDR) {
math_error("Dereferencing a non-variable");
/*NOTREACHED*/
not_reached();
}
vp = vp->v_addr;
switch (vp->v_type) {
@@ -1578,7 +1579,7 @@ o_links(void)
}
if (links <= 0) {
math_error("Non-positive links!!!");
/*NOTREACHED*/
not_reached();
}
freevalue(stack);
if (!haveaddress)
@@ -2138,7 +2139,7 @@ o_isdefined(void)
vp = vp->v_addr;
if (vp->v_type != V_STR) {
math_error("Non-string argument for isdefined");
/*NOTREACHED*/
not_reached();
}
r = 0;
index = getbuiltinfunc(vp->v_str->s_str);
@@ -2167,7 +2168,7 @@ o_isobjtype(void)
vp = vp->v_addr;
if (vp->v_type != V_STR) {
math_error("Non-string argument for isobjtype");
/*NOTREACHED*/
not_reached();
}
index = checkobject(vp->v_str->s_str);
freevalue(stack);
@@ -2311,7 +2312,7 @@ o_re(void)
}
if (vp->v_type != V_COM) {
math_error("Taking real part of non-number");
/*NOTREACHED*/
not_reached();
}
q = qlink(vp->v_com->real);
if (stack->v_type == V_COM)
@@ -2341,7 +2342,7 @@ o_im(void)
}
if (vp->v_type != V_COM) {
math_error("Taking imaginary part of non-number");
/*NOTREACHED*/
not_reached();
}
q = qlink(vp->v_com->imag);
if (stack->v_type == V_COM)
@@ -2391,12 +2392,12 @@ o_fiaddr(void)
vp = vp->v_addr;
if (vp->v_type != V_NUM || qisfrac(vp->v_num)) {
math_error("Fast indexing by non-integer");
/*NOTREACHED*/
not_reached();
}
index = qtoi(vp->v_num);
if (zge31b(vp->v_num->num) || (index < 0)) {
math_error("Index out of range for fast indexing");
/*NOTREACHED*/
not_reached();
}
if (stack->v_type == V_NUM)
qfree(stack->v_num);
@@ -2404,14 +2405,14 @@ o_fiaddr(void)
vp = stack;
if (vp->v_type != V_ADDR) {
math_error("Non-pointer for fast indexing");
/*NOTREACHED*/
not_reached();
}
vp = vp->v_addr;
switch (vp->v_type) {
case V_OBJ:
if (index >= vp->v_obj->o_actions->oa_count) {
math_error("Index out of bounds for object");
/*NOTREACHED*/
not_reached();
}
res = vp->v_obj->o_table + index;
break;
@@ -2419,7 +2420,7 @@ o_fiaddr(void)
m = vp->v_mat;
if (index >= m->m_size) {
math_error("Index out of bounds for matrix");
/*NOTREACHED*/
not_reached();
}
res = m->m_table + index;
break;
@@ -2428,7 +2429,7 @@ o_fiaddr(void)
res = listfindex(lp, index);
if (res == NULL) {
math_error("Index out of bounds for list");
/*NOTREACHED*/
not_reached();
}
break;
case V_ASSOC:
@@ -2436,12 +2437,12 @@ o_fiaddr(void)
res = assocfindex(ap, index);
if (res == NULL) {
math_error("Index out of bounds for association");
/*NOTREACHED*/
not_reached();
}
break;
default:
math_error("Bad variable type for fast indexing");
/*NOTREACHED*/
not_reached();
}
stack->v_addr = res;
}
@@ -2491,7 +2492,7 @@ o_numerator(void)
vp = vp->v_addr;
if (vp->v_type != V_NUM) {
math_error("Numerator of non-number");
/*NOTREACHED*/
not_reached();
}
if ((stack->v_type == V_NUM) && qisint(vp->v_num))
return;
@@ -2515,7 +2516,7 @@ o_denominator(void)
vp = vp->v_addr;
if (vp->v_type != V_NUM) {
math_error("Denominator of non-number");
/*NOTREACHED*/
not_reached();
}
q = qden(vp->v_num);
if (stack->v_type == V_NUM)
@@ -2715,7 +2716,7 @@ o_usercall(FUNC *fp, long index, long argcount)
fp = findfunc(index);
if (fp == NULL) {
math_error("Function \"%s\" is undefined", namefunc(index));
/*NOTREACHED*/
not_reached();
}
calculate(fp, (int) argcount);
}
@@ -3110,7 +3111,7 @@ o_debug(FUNC *UNUSED(fp), long line)
funcline = line;
if (abortlevel >= ABORT_STATEMENT) {
math_error("Calculation aborted at statement boundary");
/*NOTREACHED*/
not_reached();
}
}
@@ -3319,7 +3320,7 @@ o_setepsilon(void)
vp = vp->v_addr;
if (vp->v_type != V_NUM) {
math_error("Non-numeric for epsilon");
/*NOTREACHED*/
not_reached();
}
newep = vp->v_num;
stack->v_num = qlink(conf->epsilon);
@@ -3346,13 +3347,13 @@ o_setconfig(void)
v2 = v2->v_addr;
if (v1->v_type != V_STR) {
math_error("Non-string for config");
/*NOTREACHED*/
not_reached();
}
type = configtype(v1->v_str->s_str);
if (type < 0) {
math_error("Unknown config name \"%s\"",
v1->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
config_value(conf, type, &tmp);
setconfig(type, v2);
@@ -3373,13 +3374,13 @@ o_getconfig(void)
vp = vp->v_addr;
if (vp->v_type != V_STR) {
math_error("Non-string for config");
/*NOTREACHED*/
not_reached();
}
type = configtype(vp->v_str->s_str);
if (type < 0) {
math_error("Unknown config name \"%s\"",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
freevalue(stack);
config_value(conf, type, stack);
@@ -3416,7 +3417,7 @@ error_value(int e)
errcount++;
if (errmax >= 0 && errcount > errmax) {
math_error("Error %d caused errcount to exceed errmax", e);
/*NOTREACHED*/
not_reached();
}
res.v_type = (short) -e;
res.v_subtype = V_NOSUBTYPE;
@@ -3472,7 +3473,7 @@ o_initfill(void)
v2 = v2->v_addr;
if (v1->v_type != V_MAT) {
math_error("Non-matrix argument for o_initfill");
/*NOTREACHED*/
not_reached();
}
s = v1->v_mat->m_size;
vp = v1->v_mat->m_table;
@@ -3868,7 +3869,7 @@ calculate(FUNC *fp, int argcount)
locals = (VALUE *) malloc(sizeof(VALUE) * fp->f_localcount);
if (locals == NULL) {
math_error("No memory for local variables");
/*NOTREACHED*/
not_reached();
}
}
for (i = 0; i < fp->f_localcount; i++) {
@@ -3882,20 +3883,20 @@ calculate(FUNC *fp, int argcount)
while (go) {
if (abortlevel >= ABORT_OPCODE) {
math_error("Calculation aborted in opcode");
/*NOTREACHED*/
not_reached();
}
if (pc >= fp->f_opcodecount) {
math_error("Function pc out of range");
/*NOTREACHED*/
not_reached();
}
if (stack > &stackarray[MAXSTACK-3]) {
math_error("Evaluation stack depth exceeded");
/*NOTREACHED*/
not_reached();
}
opnum = fp->f_opcodes[pc];
if (opnum > MAX_OPCODE) {
math_error("Function opcode out of range");
/*NOTREACHED*/
not_reached();
}
op = &opcodes[opnum];
if (conf->traceflags & TRACE_OPCODES) {
@@ -3961,7 +3962,7 @@ calculate(FUNC *fp, int argcount)
free(locals);
if (stack != &beginstack[1]) {
math_error("Misaligned stack");
/*NOTREACHED*/
not_reached();
}
if (argcount > 0) {
retval = *stack--;
@@ -3980,7 +3981,7 @@ calculate(FUNC *fp, int argcount)
default:
math_error("Unknown opcode type: %d", op->o_type);
/*NOTREACHED*/
not_reached();
}
}
for (i = 0; i < fp->f_localcount; i++)
@@ -4125,12 +4126,12 @@ freenumbers(FUNC *fp)
continue;
default:
math_error("Unknown opcode type for freeing");
/*NOTREACHED*/
not_reached();
}
}
if (pc != fp->f_opcodecount) {
math_error("Incorrect opcodecount ???");
/*NOTREACHED*/
not_reached();
}
trimconstants();
}

65
qfunc.c
View File

@@ -1,7 +1,7 @@
/*
* qfunc - extended precision rational arithmetic non-primitive functions
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,7 @@
#include "prime.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -56,7 +57,7 @@ setepsilon(NUMBER *q)
if (qisneg(q) || qiszero(q)) {
math_error("Epsilon value must be greater than zero");
/*NOTREACHED*/
not_reached();
}
old = conf->epsilon;
conf->epsilonprec = qprecision(q);
@@ -82,7 +83,7 @@ qminv(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for minv");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q2)) {
if (qisunit(q1))
@@ -135,11 +136,11 @@ qpowermod(NUMBER *q1, NUMBER *q2, NUMBER *q3)
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) {
math_error("Non-integers for pmod");
/*NOTREACHED*/
not_reached();
}
if (qisneg(q2)) {
math_error("Negative power for pmod");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q3))
return qpowi(q1, q2);
@@ -191,7 +192,7 @@ qpowi(NUMBER *q1, NUMBER *q2)
if (qisfrac(q2)) {
math_error("Raising number to fractional power");
/*NOTREACHED*/
not_reached();
}
num = q1->num;
zden = q1->den;
@@ -206,7 +207,7 @@ qpowi(NUMBER *q1, NUMBER *q2)
if (ziszero(num) && !ziszero(z2)) { /* zero raised to a power */
if (invert) {
math_error("Zero raised to negative power");
/*NOTREACHED*/
not_reached();
}
return qlink(&_qzero_);
}
@@ -251,7 +252,7 @@ qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for hypot");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1))
return qqabs(q2);
@@ -281,7 +282,7 @@ qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for legtoleg");
/*NOTREACHED*/
not_reached();
}
if (qisunit(q))
return qlink(&_qzero_);
@@ -294,7 +295,7 @@ qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg)
num.sign = 0;
if (zrel(num, q->den) >= 0) {
math_error("Leg too large in legtoleg");
/*NOTREACHED*/
not_reached();
}
qtmp1 = qsquare(q);
qtmp2 = qsub(&_qone_, qtmp1);
@@ -329,14 +330,14 @@ qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd)
if (qisneg(q1)) {
math_error("Square root of negative number");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1))
return qlink(&_qzero_);
sign = (rnd & 64) != 0;
if (qiszero(epsilon)) {
math_error("Zero epsilon for qsqrt");
/*NOTREACHED*/
not_reached();
}
etemp = *epsilon;
@@ -435,7 +436,7 @@ qisqrt(NUMBER *q)
if (qisneg(q)) {
math_error("Square root of negative number");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qzero_);
@@ -477,7 +478,7 @@ qiroot(NUMBER *q1, NUMBER *q2)
if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) {
math_error("Taking number to bad root value");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1))
return qlink(&_qzero_);
@@ -514,7 +515,7 @@ qilog2(NUMBER *q)
if (qiszero(q)) {
math_error("Zero argument for ilog2");
/*NOTREACHED*/
not_reached();
}
if (qisint(q))
return zhighbit(q->num);
@@ -554,7 +555,7 @@ qilog10(NUMBER *q)
if (qiszero(q)) {
math_error("Zero argument for ilog10");
/*NOTREACHED*/
not_reached();
}
tmp1 = q->num;
tmp1.sign = 0;
@@ -810,7 +811,7 @@ qfact(NUMBER *q)
if (qisfrac(q)) {
math_error("Non-integral factorial");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q) || zisone(q->num))
return qlink(&_qone_);
@@ -831,7 +832,7 @@ qpfact(NUMBER *q)
if (qisfrac(q)) {
math_error("Non-integral factorial");
/*NOTREACHED*/
not_reached();
}
r = qalloc();
zpfact(q->num, &r->num);
@@ -850,7 +851,7 @@ qlcmfact(NUMBER *q)
if (qisfrac(q)) {
math_error("Non-integral lcmfact");
/*NOTREACHED*/
not_reached();
}
r = qalloc();
zlcmfact(q->num, &r->num);
@@ -870,7 +871,7 @@ qperm(NUMBER *q1, NUMBER *q2)
if (qisfrac(q2)) {
math_error("Non-integral second arg for permutation");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q2))
return qlink(&_qone_);
@@ -887,7 +888,7 @@ qperm(NUMBER *q1, NUMBER *q2)
}
if (zge31b(q2->num)) {
math_error("Too large arg2 for permutation");
/*NOTREACHED*/
not_reached();
}
i = qtoi(q2);
if (i > 0) {
@@ -934,7 +935,7 @@ qcomb(NUMBER *q, NUMBER *n)
if (!qisint(n) || qisneg(n)) {
math_error("Bad second arg in call to qcomb!");
/*NOTREACHED*/
not_reached();
}
if (qisint(q)) {
switch (zcomb(q->num, n->num, &z)) {
@@ -1181,7 +1182,7 @@ qjacobi(NUMBER *q1, NUMBER *q2)
{
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integral arguments for jacobi");
/*NOTREACHED*/
not_reached();
}
return itoq((long) zjacobi(q1->num, q2->num));
}
@@ -1197,7 +1198,7 @@ qfib(NUMBER *q)
if (qisfrac(q)) {
math_error("Non-integral Fibonacci number");
/*NOTREACHED*/
not_reached();
}
r = qalloc();
zfib(q->num, &r->num);
@@ -1216,7 +1217,7 @@ qtrunc(NUMBER *q1, NUMBER *q2)
if (qisfrac(q2) || !zistiny(q2->num)) {
math_error("Bad number of places for qtrunc");
/*NOTREACHED*/
not_reached();
}
places = qtoi(q2);
e = qtenpow(-places);
@@ -1240,7 +1241,7 @@ qbtrunc(NUMBER *q1, NUMBER *q2)
if (qisfrac(q2) || !zistiny(q2->num)) {
math_error("Bad number of places for qtrunc");
/*NOTREACHED*/
not_reached();
}
places = qtoi(q2);
e = qbitvalue(-places);
@@ -1678,7 +1679,7 @@ qfacrem(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for factor removal");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q2))
return qqabs(q1);
@@ -1711,7 +1712,7 @@ qgcdrem(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for gcdrem");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q2))
return qlink(&_qone_);
@@ -1745,12 +1746,12 @@ qlowfactor(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for lowfactor");
/*NOTREACHED*/
not_reached();
}
count = ztoi(q2->num);
if (count > PIX_32B) {
math_error("lowfactor count is too large");
/*NOTREACHED*/
not_reached();
}
return utoq(zlowfactor(q1->num, count));
}
@@ -1840,11 +1841,11 @@ qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3)
{
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) {
math_error("Bad arguments for ptest");
/*NOTREACHED*/
not_reached();
}
if (zge24b(q2->num)) {
math_error("ptest count >= 2^24");
/*NOTREACHED*/
not_reached();
}
return zprimetest(q1->num, ztoi(q2->num), q3->num);
}

49
qio.c
View File

@@ -1,7 +1,7 @@
/*
* qio - scanf and printf routines for arbitrary precision rational numbers
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -200,16 +201,24 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits)
}
switch (outmode) {
case MODE_INT:
if (conf->tilde_ok && qisfrac(q))
if (conf->tilde_ok && qisfrac(q)) {
PUTCHAR('~');
if (conf->tilde_space && qisfrac(q)) {
PUTCHAR(' ');
}
}
qprintfd(q, 0L);
break;
case MODE_REAL:
prec = qdecplaces(q);
if ((prec < 0) || (prec > outdigits)) {
if (conf->tilde_ok)
if (conf->tilde_ok) {
PUTCHAR('~');
if (conf->tilde_space) {
PUTCHAR(' ');
}
}
}
if (conf->fullzero || (prec < 0) ||
(prec > outdigits))
@@ -306,7 +315,7 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits)
default:
math_error("Bad mode for print");
/*NOTREACHED*/
not_reached();
}
if (outmode2 != MODE2_OFF) {
@@ -411,7 +420,13 @@ qprintfr(NUMBER *q, long width, BOOL force)
{
zprintval(q->num, 0L, width);
if (force || qisfrac(q)) {
if (conf->fraction_space) {
PUTCHAR(' ');
}
PUTCHAR('/');
if (conf->fraction_space) {
PUTCHAR(' ');
}
zprintval(q->den, 0L, width);
}
}
@@ -445,7 +460,13 @@ qprintfx(NUMBER *q, long width)
{
zprintx(q->num, width);
if (qisfrac(q)) {
if (conf->fraction_space) {
PUTCHAR(' ');
}
PUTCHAR('/');
if (conf->fraction_space) {
PUTCHAR(' ');
}
zprintx(q->den, 0L);
}
}
@@ -460,7 +481,13 @@ qprintfb(NUMBER *q, long width)
{
zprintb(q->num, width);
if (qisfrac(q)) {
if (conf->fraction_space) {
PUTCHAR(' ');
}
PUTCHAR('/');
if (conf->fraction_space) {
PUTCHAR(' ');
}
zprintb(q->den, 0L);
}
}
@@ -475,7 +502,13 @@ qprintfo(NUMBER *q, long width)
{
zprinto(q->num, width);
if (qisfrac(q)) {
if (conf->fraction_space) {
PUTCHAR(' ');
}
PUTCHAR('/');
if (conf->fraction_space) {
PUTCHAR(' ');
}
zprinto(q->den, 0L);
}
}
@@ -536,7 +569,7 @@ str2q(char *s)
exp = (exp * 10) + *t++ - '0';
if (exp > (MAXLONG/10L)) {
math_error("Exponent too large");
/*NOTREACHED*/
not_reached();
}
}
}
@@ -748,6 +781,12 @@ fitprint(NUMBER *q, long width)
width1 = width - width2;
}
fitzprint(q->num, numdigits, width1);
if (conf->fraction_space) {
PUTCHAR(' ');
}
PUTCHAR('/');
if (conf->fraction_space) {
PUTCHAR(' ');
}
fitzprint(q->den, dendigits, width2);
}

35
qmath.c
View File

@@ -1,7 +1,7 @@
/*
* qmath - extended precision rational arithmetic primitive routines
*
* Copyright (C) 1999-2007,2014,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2014,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,7 @@
#include "config.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -224,7 +225,7 @@ uutoq(FULL inum, FULL iden)
if (iden == 0) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (inum == 0)
return qlink(&_qzero_);
@@ -256,7 +257,7 @@ iitoq(long inum, long iden)
if (iden == 0) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (inum == 0)
return qlink(&_qzero_);
@@ -504,7 +505,7 @@ qmul(NUMBER *q1, NUMBER *q2)
d2 = q2->den;
if (ziszero(d1) || ziszero(d2)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (ziszero(n1) || ziszero(n2))
return qlink(&_qzero_);
@@ -583,7 +584,7 @@ qqdiv(NUMBER *q1, NUMBER *q2)
if (qiszero(q2)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if ((q1 == q2) || !qcmp(q1, q2))
return qlink(&_qone_);
@@ -611,7 +612,7 @@ qdivi(NUMBER *q, long n)
if (n == 0) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if ((n == 1) || qiszero(q))
return qlink(q);
@@ -734,7 +735,7 @@ qinv(NUMBER *q)
}
if (qiszero(q)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
r = qalloc();
if (!zisunit(q->num))
@@ -861,7 +862,7 @@ qshift(NUMBER *q, long n)
if (qisfrac(q)) {
math_error("Shift of non-integer");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q) || (n == 0))
return qlink(q);
@@ -954,7 +955,7 @@ qor(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for bitwise or");
/*NOTREACHED*/
not_reached();
}
if (qcmp(q1,q2) == 0 || qiszero(q2))
return qlink(q1);
@@ -1003,7 +1004,7 @@ qand(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for bitwise and");
/*NOTREACHED*/
not_reached();
}
if (qcmp(q1, q2) == 0)
return qlink(q1);
@@ -1053,7 +1054,7 @@ qxor(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for bitwise xor");
/*NOTREACHED*/
not_reached();
}
if (qcmp(q1,q2) == 0)
return qlink(&_qzero_);
@@ -1106,7 +1107,7 @@ qandnot(NUMBER *q1, NUMBER *q2)
if (qisfrac(q1) || qisfrac(q2)) {
math_error("Non-integers for bitwise xor");
/*NOTREACHED*/
not_reached();
}
if (qcmp(q1,q2) == 0 || qiszero(q1))
return qlink(&_qzero_);
@@ -1213,7 +1214,7 @@ qprecision(NUMBER *q)
if (qiszero(q) || qisneg(q)) {
math_error("Non-positive number for precision");
/*NOTREACHED*/
not_reached();
}
r = - qilog2(q);
return (r < 0 ? 0 : r);
@@ -1408,7 +1409,7 @@ qalloc(void)
freeNum = (NUMBER *) malloc(sizeof (NUMBER) * NNALLOC);
if (freeNum == NULL) {
math_error("Not enough memory");
/*NOTREACHED*/
not_reached();
}
freeNum[NNALLOC - 1].next = NULL;
freeNum[NNALLOC - 1].links = 0;
@@ -1438,7 +1439,7 @@ qalloc(void)
}
if (newfn == NULL) {
math_error("Cannot allocate new number block");
/*NOTREACHED*/
not_reached();
}
firstNums = newfn;
firstNums[blockcount - 1] = freeNum;
@@ -1457,11 +1458,11 @@ qfreenum(NUMBER *q)
{
if (q == NULL) {
math_error("Calling qfreenum with null argument!!!");
/*NOTREACHED*/
not_reached();
}
if (q->links != 0) {
math_error("Calling qfreenum with non-zero links!!!");
/*NOTREACHED*/
not_reached();
}
zfree(q->num);
zfree(q->den);

5
qmod.c
View File

@@ -1,7 +1,7 @@
/*
* qmod - modular arithmetic routines for normal numbers and REDC numbers
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,7 @@
#include "config.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -371,7 +372,7 @@ qfindredc(NUMBER *q)
*/
if (qisfrac(q) || qisneg(q)) {
math_error("REDC modulus must be positive odd integer");
/*NOTREACHED*/
not_reached();
}
bestrcp = NULL;

View File

@@ -1,7 +1,7 @@
/*
* qtrans - transcendental functions for real numbers
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -34,6 +34,7 @@
#include "qmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -209,7 +210,7 @@ qcos(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for cosine");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qone_);
@@ -236,7 +237,7 @@ qsin(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for sine");
/*NOTREACHED*/
not_reached();
}
n = -qilog2(epsilon);
if (qiszero(q) || n < 0)
@@ -260,7 +261,7 @@ qtan(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for tangent");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(q);
@@ -301,11 +302,11 @@ qcot(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for cotangent");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q)) {
math_error("Zero argument for cotangent");
/*NOTREACHED*/
not_reached();
}
k = -qilog2(q);
n = qilog2(epsilon);
@@ -347,7 +348,7 @@ qsec(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for secant");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qone_);
@@ -386,11 +387,11 @@ qcsc(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for cosecant");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q)) {
math_error("Zero argument for cosecant");
/*NOTREACHED*/
not_reached();
}
k = -qilog2(q);
n = qilog2(epsilon);
@@ -431,7 +432,7 @@ qasin(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for asin");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qzero_);
@@ -480,7 +481,7 @@ qacos(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for acos");
/*NOTREACHED*/
not_reached();
}
if (qisone(q))
return qlink(&_qzero_);
@@ -526,7 +527,7 @@ qatan(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for arctangent");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qzero_);
@@ -569,7 +570,7 @@ qatan(NUMBER *q, NUMBER *epsilon)
for (;;) {
if (d > BASE) {
math_error("Too many terms required for atan");
/*NOTREACHED*/
not_reached();
}
zmul(X, mul, &ztmp1);
zfree(X);
@@ -644,7 +645,7 @@ qacot(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for acot");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q)) {
epsilon1 = qscale(epsilon, 1L);
@@ -687,7 +688,7 @@ qatan2(NUMBER *qy, NUMBER *qx, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for atan2");
/*NOTREACHED*/
not_reached();
}
if (qiszero(qy) && qiszero(qx)) {
/* conform to 4.3BSD ANSI/IEEE 754-1985 math lib */
@@ -761,7 +762,7 @@ qpi(NUMBER *epsilon)
/* firewall */
if (qiszero(epsilon)) {
math_error("zero epsilon value for pi");
/*NOTREACHED*/
not_reached();
}
/* use pi cache if epsilon marches, else flush if needed */
@@ -829,7 +830,7 @@ qpidiv180(NUMBER *epsilon)
/* firewall */
if (qiszero(epsilon)) {
math_error("zero epsilon value for qpidiv180");
/*NOTREACHED*/
not_reached();
}
/* use pi/180 cache if epsilon marches, else flush if needed */
@@ -873,7 +874,7 @@ qpidiv200(NUMBER *epsilon)
/* firewall */
if (qiszero(epsilon)) {
math_error("zero epsilon value for qpidiv200");
/*NOTREACHED*/
not_reached();
}
/* use pi/200 cache if epsilon marches, else flush if needed */
@@ -916,7 +917,7 @@ qexp(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for exp");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qone_);
@@ -1048,7 +1049,7 @@ qln(NUMBER *q, NUMBER *epsilon)
if (qiszero(q) || qiszero(epsilon)) {
math_error("logarithm of 0");
/*NOTREACHED*/
not_reached();
}
if (qisunit(q))
return qlink(&_qzero_);
@@ -1160,7 +1161,7 @@ qlog(NUMBER *q, NUMBER *epsilon)
/* firewall */
if (qiszero(q) || qiszero(epsilon)) {
math_error("logarithm of 0");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1236,11 +1237,11 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for power");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1) && qisneg(q2)) {
math_error("Negative power of zero");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q2) || qisone(q1))
return qlink(&_qone_);
@@ -1248,7 +1249,7 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
return qlink(&_qzero_);
if (qisneg(q1)) {
math_error("Negative base for qpower");
/*NOTREACHED*/
not_reached();
}
if (qisone(q2))
return qmappr(q1, epsilon, 24);
@@ -1353,11 +1354,11 @@ qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for root");
/*NOTREACHED*/
not_reached();
}
if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) {
math_error("Taking bad root of number");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1) || qisone(q1) || qisone(q2))
return qlink(q1);
@@ -1367,7 +1368,7 @@ qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (neg) {
if (ziseven(q2->num)) {
math_error("Taking even root of negative number");
/*NOTREACHED*/
not_reached();
}
q1 = qqabs(q1);
}
@@ -1510,11 +1511,11 @@ qcoth(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for coth");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q)) {
math_error("Zero argument for coth");
/*NOTREACHED*/
not_reached();
}
tmp1 = qscale(q, 1);
tmp2 = qqabs(tmp1);
@@ -1537,7 +1538,7 @@ qcoth(NUMBER *q, NUMBER *epsilon)
qfree(tmp1);
if (qiszero(tmp2)) {
math_error("This should not happen ????");
/*NOTREACHED*/
not_reached();
}
tmp1 = qinv(tmp2);
qfree(tmp2);
@@ -1564,7 +1565,7 @@ qsech(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for sech");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qone_);
@@ -1605,11 +1606,11 @@ qcsch(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for csch");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q)) {
math_error("Zero argument for csch");
/*NOTREACHED*/
not_reached();
}
n = qilog2(epsilon);
@@ -1657,7 +1658,7 @@ qacosh(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for acosh");
/*NOTREACHED*/
not_reached();
}
if (qisone(q))
return qlink(&_qzero_);
@@ -1695,7 +1696,7 @@ qasinh(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for asinh");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qzero_);
@@ -1737,7 +1738,7 @@ qatanh(NUMBER *q, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon value for atanh");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q))
return qlink(&_qzero_);

View File

@@ -6,7 +6,7 @@
*
* http://www.isthe.com/chongo/tech/comp/fnv/index.html
*
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2021,2022 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,7 @@
#include "zrandom.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -231,7 +232,7 @@ hashvalue(VALUE *vp, QCKHASH val)
return blk_hash(vp->v_nblock->blk, val);
default:
math_error("Hashing unknown value");
/*NOTREACHED*/
not_reached();
}
return (QCKHASH)0;
}
@@ -438,6 +439,7 @@ config_hash(CONFIG *cfg, QCKHASH val)
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->pow2);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redc2);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_ok);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_space);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tab_ok);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quomod);
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quo);

View File

@@ -1,7 +1,7 @@
/*
* sample_many - generate many random values via random number generator
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 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
@@ -41,6 +41,7 @@
#include "lib_util.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -106,7 +107,7 @@ main(int argc, char **argv)
prev_state = zsrandom2(seed, _one_);
if (prev_state == NULL) {
math_error("previous random state is NULL");
/*NOTREACHED*/
not_reached();
}
randomfree(prev_state);

View File

@@ -1,7 +1,7 @@
/*
* sample_rand - test the libcalc random number generator
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 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
@@ -41,6 +41,7 @@
#include "lib_util.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -96,7 +97,7 @@ main(int argc, char **argv)
prev_state = zsrandom2(seed, _ten_);
if (prev_state == NULL) {
math_error("previous random state is NULL");
/*NOTREACHED*/
not_reached();
}
/*

21
seed.c
View File

@@ -592,7 +592,6 @@ pseudo_seed(void)
sdata.size = sizeof(sdata);
sdata.prev_hash64_copy = prev_hash64; /* load previous hash */
sdata.call_count_copy = ++call_count; /* update call count */
(void) setjmp(sdata.env);
#if defined(HAVE_ENVIRON)
sdata.environ_copy = environ;
#endif /* HAVE_ENVIRON */
@@ -708,12 +707,26 @@ pseudo_seed(void)
* load the hash data into the ZVALUE
*
* We do not care about byte-order, nor Endian issues, we just
* want to load in data.
* want to load in data. We round up to the next HALF in size
* just in case hash_val is not a HALF multiple in length.
*/
hash.len = sizeof(hash_val) / sizeof(HALF);
hash.len = (sizeof(hash_val)+sizeof(HALF)-1) / sizeof(HALF);
hash.v = alloc(hash.len);
memset(hash.v, 0, hash.len*sizeof(HALF)); /* paranoia */
hash.sign = 0;
memcpy((void *)hash.v, (void *)&hash_val, hash.len*sizeof(HALF));
memcpy((void *)hash.v, (void *)&hash_val, sizeof(hash_val));
/*
* Force the hash as ZVALUE to be at most, 64 bits long.
* It is almost certainly the case that the hash as ZVALUE
* is at most 64 bits in length: this code guarantees it.
*
* BTW: One can safely assume that 64 is an integer multiple of BASEB:
* likely 4, 2, or 1 times BASEB.
*/
if (hash.len > 64/BASEB) {
hash.len = 64/BASEB;
}
ztrim(&hash);
/*

5
sha1.c
View File

@@ -36,6 +36,7 @@
#include "sha1.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -367,7 +368,7 @@ sha1Final(HASH *state)
} else {
if (count % 4) {
math_error("This should not happen in sha1Final");
/*NOTREACHED*/
not_reached();
}
data[count + 3] = 0x80;
}
@@ -563,7 +564,7 @@ sha1_final_state(HASH *state)
state = (HASH *)malloc(sizeof(HASH));
if (state == NULL) {
math_error("cannot malloc HASH");
/*NOTREACHED*/
not_reached();
}
sha1_init_state(state);
}

7
size.c
View File

@@ -1,7 +1,7 @@
/*
* size - size and sizeof functions are implemented here
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "block.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -316,7 +317,7 @@ lsizeof(VALUE *vp)
break;
default:
math_error("sizeof not defined for value type");
/*NOTREACHED*/
not_reached();
}
}
return s;
@@ -436,7 +437,7 @@ memsize(VALUE *vp)
break;
default:
math_error("memsize not defined for value type");
/*NOTREACHED*/
not_reached();
}
}
return s;

39
str.c
View File

@@ -1,7 +1,7 @@
/*
* str - string list routines
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -38,11 +38,12 @@
#include "strl.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
#define STR_TABLECHUNK 100 /* how often to reallocate string table */
#define STR_CHUNK (1<<11) /* size of string storage allocation */
#define STR_TABLECHUNK (1<<10) /* how often to reallocate string table */
#define STR_CHUNK (1<<16) /* size of string storage allocation */
#define OCTET_VALUES 256 /* number of different values in a OCTET */
#define STR_UNIQUE (1<<7) /* size of string to allocate separately */
@@ -73,7 +74,7 @@ initstr(STRINGHEAD *hp)
hp->h_list = (char *)malloc(STR_CHUNK + 1);
if (hp->h_list == NULL) {
math_error("Cannot allocate string header");
/*NOTREACHED*/
not_reached();
}
hp->h_list[STR_CHUNK] = '\0'; /* guard paranoia */
hp->h_avail = STR_CHUNK;
@@ -144,7 +145,7 @@ charstr(int ch)
cp = (char *)malloc((OCTET_VALUES + 1)*2);
if (cp == NULL) {
math_error("Cannot allocate character table");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < OCTET_VALUES; i++) {
*cp++ = (char)i;
@@ -295,7 +296,7 @@ addliteral(char *str)
}
if (table == NULL) {
math_error("Cannot allocate string literal table");
/*NOTREACHED*/
not_reached();
}
literals.l_table = table;
literals.l_maxcount = count;
@@ -314,7 +315,7 @@ addliteral(char *str)
newstr = (char *)malloc(len + 1);
if (newstr == NULL) {
math_error("Cannot allocate large literal string");
/*NOTREACHED*/
not_reached();
}
newstr[len] = '\0'; /* guard paranoia */
strlcpy(newstr, str, len);
@@ -330,7 +331,7 @@ addliteral(char *str)
newstr = (char *)malloc(STR_CHUNK + 1);
if (newstr == NULL) {
math_error("Cannot allocate new literal string");
/*NOTREACHED*/
not_reached();
}
newstr[STR_CHUNK] = '\0'; /* guard paranoia */
literals.l_alloc = newstr;
@@ -1128,7 +1129,7 @@ stralloc(void)
freeStr = (STRING *) malloc(sizeof (STRING) * (STRALLOC + 1));
if (freeStr == NULL) {
math_error("Unable to allocate memory for stralloc");
/*NOTREACHED*/
not_reached();
}
/* guard paranoia */
memset(freeStr+STRALLOC, 0, sizeof(STRING));
@@ -1166,7 +1167,7 @@ stralloc(void)
}
if (newfn == NULL) {
math_error("Cannot allocate new string block");
/*NOTREACHED*/
not_reached();
}
firstStrs = newfn;
firstStrs[blockcount - 1] = freeStr;
@@ -1204,7 +1205,7 @@ charstring(int ch)
c = (char *) malloc(2);
if (c == NULL) {
math_error("Allocation failure for charstring");
/*NOTREACHED*/
not_reached();
}
s = stralloc();
s->s_len = 1;
@@ -1232,7 +1233,7 @@ makenewstring(char *str)
c = (char *) malloc(len + 1);
if (c == NULL) {
math_error("malloc for makenewstring failed");
/*NOTREACHED*/
not_reached();
}
s = stralloc();
s->s_str = c;
@@ -1256,7 +1257,7 @@ stringcopy (STRING *s1)
c = malloc(len + 1);
if (c == NULL) {
math_error("Malloc failed for stringcopy");
/*NOTREACHED*/
not_reached();
}
s = stralloc();
s->s_len = len;
@@ -1272,7 +1273,7 @@ slink(STRING *s)
{
if (s->s_links <= 0) {
math_error("Argument for slink has non-positive links!!!");
/*NOTREACHED*/
not_reached();
}
++s->s_links;
return s;
@@ -1284,7 +1285,7 @@ sfree(STRING *s)
{
if (s->s_links <= 0) {
math_error("Argument for sfree has non-positive links!!!");
/*NOTREACHED*/
not_reached();
}
if (--s->s_links > 0 || s->s_len == 0)
return;
@@ -1306,7 +1307,7 @@ initstrings(void)
malloc(sizeof(STRING *) * (STRCONSTALLOC + 1));
if (stringconsttable == NULL) {
math_error("Unable to allocate constant table");
/*NOTREACHED*/
not_reached();
}
stringconsttable[STRCONSTALLOC] = NULL; /* guard paranoia */
stringconsttable[0] = &_nullstring_;
@@ -1343,7 +1344,7 @@ addstring(char *str, size_t len)
if (sp == NULL) {
math_error("Unable to reallocate string "
"const table");
/*NOTREACHED*/
not_reached();
}
/* guard paranoia */
sp[stringconstcount + STRCONSTALLOC] = NULL;
@@ -1373,7 +1374,7 @@ addstring(char *str, size_t len)
c = (char *) malloc(len + 1);
if (c == NULL) {
math_error("Unable to allocate string constant memory");
/*NOTREACHED*/
not_reached();
}
s->s_str = c;
s->s_len = len;
@@ -1393,7 +1394,7 @@ findstring(long index)
{
if (index < 0 || index >= stringconstcount) {
math_error("Bad index for findstring");
/*NOTREACHED*/
not_reached();
}
return stringconsttable[index];
}

View File

@@ -1,7 +1,7 @@
/*
* symbol - global and local symbol routines
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -35,6 +35,7 @@
#include "func.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -539,7 +540,7 @@ addstatic(GLOBAL *sp)
(20 + staticcount) * sizeof(GLOBAL *));
if (stp == NULL) {
math_error("Cannot allocate static-variable table");
/*NOTREACHED*/
not_reached();
}
statictable = stp;
staticavail = 20;

11
token.c
View File

@@ -1,7 +1,7 @@
/*
* token - read input file characters into tokens
*
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -37,6 +37,7 @@
#include "lib_calc.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -537,7 +538,7 @@ eatstring(int quotechar)
str = (char *) malloc(len);
if (str == NULL) {
math_error("Out of memory for reading tokens");
/*NOTREACHED*/
not_reached();
}
memcpy(str + totlen, buf, len);
totlen += len;
@@ -628,7 +629,7 @@ eatnumber(void)
cp = (char *)realloc(numbuf, numbufsize + 1001);
if (cp == NULL) {
math_error("Cannot reallocate number buffer");
/*NOTREACHED*/
not_reached();
}
numbuf = cp;
numbufsize += 1000;
@@ -745,7 +746,7 @@ scanerror(int skip, char *fmt, ...)
if ((!c_flag && !stoponerror) || stoponerror > 0) {
if (calc_use_scanerr_jmpbuf != 0) {
longjmp(calc_scanerr_jmpbuf, 60);
/*NOTREACHED*/
not_reached();
} else {
fprintf(stderr,
"calc_scanerr_jmpbuf not setup, exiting code 60\n");
@@ -759,7 +760,7 @@ scanerror(int skip, char *fmt, ...)
fprintf(stderr, "Too many scan errors, compilation aborted.\n");
if (calc_use_scanerr_jmpbuf != 0) {
longjmp(calc_scanerr_jmpbuf, 61);
/*NOTREACHED*/
not_reached();
} else {
fprintf(stderr,
"calc_scanerr_jmpbuf not ready: exit 61\n");

View File

@@ -175,8 +175,8 @@ E_FUNC void inittokens(void);
E_FUNC int tokenmode(int flag);
E_FUNC int gettoken(void);
E_FUNC void rescantoken(void);
E_FUNC void scanerror(int, char *, ...) PRINTF_FORMAT(2, 3);
E_FUNC void warning(char *, ...) PRINTF_FORMAT(1, 2);
E_FUNC void scanerror(int, char *, ...) __attribute__((format(printf, 2, 3)));
E_FUNC void warning(char *, ...) __attribute__((format(printf, 1, 2)));
#endif /* !INCLUDE_TOKEN_H */

30
value.c
View File

@@ -1,7 +1,7 @@
/*
* value - generic value manipulation routines
*
* Copyright (C) 1999-2007,2014,2017,2021 David I. Bell
* Copyright (C) 1999-2007,2014,2017,2021,2022 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
@@ -39,6 +39,7 @@
#include "config.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -109,7 +110,7 @@ freevalue(VALUE *vp)
break;
default:
math_error("Freeing unknown value type");
/*NOTREACHED*/
not_reached();
}
}
@@ -242,7 +243,7 @@ copyvalue(VALUE *oldvp, VALUE *newvp)
break;
default:
math_error("Copying unknown value type");
/*NOTREACHED*/
not_reached();
}
}
newvp->v_subtype = oldvp->v_subtype;
@@ -434,7 +435,7 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
q = v2->v_num;
if (qisfrac(q)) {
math_error("Adding non-integer to address");
/*NOTREACHED*/
not_reached();
}
i = qtoi(q);
vres->v_addr = v1->v_addr + i;
@@ -444,7 +445,7 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
q = v2->v_num;
if (qisfrac(q)) {
math_error("Adding non-integer to address");
/*NOTREACHED*/
not_reached();
}
i = qtoi(q);
vres->v_octet = v1->v_octet + i;
@@ -513,7 +514,7 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
q = v2->v_num;
if (qisfrac(q)) {
math_error("Subtracting non-integer from address");
/*NOTREACHED*/
not_reached();
}
i = qtoi(q);
vres->v_addr = v1->v_addr - i;
@@ -523,7 +524,7 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
q = v2->v_num;
if (qisfrac(q)) {
math_error("Adding non-integer to address");
/*NOTREACHED*/
not_reached();
}
i = qtoi(q);
vres->v_octet = v1->v_octet - i;
@@ -1883,9 +1884,14 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres)
*vres = error_value(E_1OVER0);
break;
}
/* 0 ^ non-neg is 1, including 0^0 */
vres->v_type = V_NUM;
vres->v_num = qlink(&_qone_);
if (qiszero(v2->v_num)) {
/* 0 ^ 0 is 1 */
vres->v_num = qlink(&_qone_);
} else {
/* 0 ^ (exp>0) is 0 */
vres->v_num = qlink(&_qzero_);
}
} else if (qisint(real_v2)) {
vres->v_num = qpowi(v1->v_num, real_v2);
} else {
@@ -2474,7 +2480,7 @@ comparevalue(VALUE *v1, VALUE *v2)
return (v1->v_num != v2->v_num);
default:
math_error("Illegal values for comparevalue");
/*NOTREACHED*/
not_reached();
}
return (r != 0);
}
@@ -2859,7 +2865,7 @@ printvalue(VALUE *vp, int flags)
break;
default:
math_error("Printing unrecognized type of value");
/*NOTREACHED*/
not_reached();
}
}
@@ -2996,7 +3002,7 @@ config_print(CONFIG *cfg)
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
cfg->prompt2 == NULL) {
math_error("CONFIG value is invalid");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -51,10 +51,40 @@ static char *program;
#include "banned.h" /* include after system header <> includes */
/*
* MAJOR_VER
*
* The MAJOR_VER remains at 2. That are concepts for version 3 calc,
* but that is a long way off. One of the main reasons why MAJOR_VER
* might incremented is if fundamental calc data objects (such as when ZVALUE
* or NUMBER or COMPLEX need to change) that would cause an incompatibility
* with existing hardware accelerators that are using fundamental calc data objects.
*
* MINOR_VER
*
* The MINOR_VER changes when there are incompatible changes to the calc library
* or calc custom library. The MINOR_VER might change if we need to make a major
* change to the math engine. For example, when the way 0^x was evaluated, we
* changed MINOR_VER from 13 to 14.
*
* MAJOR_PATCH
*
* The MAJOR_PATCH changes when there is an update to the calc library
* or calc custom library. For example, the MAJOR_PATCH might increment when there
* are new builtin functions available, or when there is a change to how existing
* builtin functions process arguments.
*
* MINOR_PATCH
*
* The MINOR_PATCH changes whenever there is any change in the calc release.
* For example, when the documentation changes, the MINOR_PATCH will increment.
* Moreover, when we are working towards a new production release,
* bug fix and improvement updates will cause MINOR_PATCH to increment.
*/
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 14 /* minor library version */
#define MAJOR_PATCH 0 /* major software version level */
#define MINOR_PATCH 12 /* minor software version level */
#define MAJOR_PATCH 1 /* major software version level */
#define MINOR_PATCH 3 /* minor software version level */
/*
@@ -78,7 +108,7 @@ STATIC char *stored_version = NULL; /* version formed if != NULL */
char *Copyright = "\n"
"calc - arbitrary precision calculator\n"
"\n"
"Copyright (C) 1999-2021 David I. Bell, Landon Curt Noll "
"Copyright (C) 1999-2023 David I. Bell, Landon Curt Noll "
"and Ernest Bowen\n"
"\n"
"Initial author: David I. Bell\n"

40
zfunc.c
View File

@@ -1,8 +1,7 @@
/*
* zfunc - extended precision integral arithmetic non-primitive routines
*
* Copyright (C) 1999-2007,2021 David I. Bell, Landon Curt Noll
* and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +30,7 @@
#include "alloc.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -196,11 +196,11 @@ zfact(ZVALUE z, ZVALUE *dest)
if (zisneg(z)) {
math_error("Negative argument for factorial");
/*NOTREACHED*/
not_reached();
}
if (zge31b(z)) {
math_error("Very large factorial");
/*NOTREACHED*/
not_reached();
}
n = ztolong(z);
ptwo = 0;
@@ -249,15 +249,15 @@ zperm(ZVALUE z1, ZVALUE z2, ZVALUE *res)
if (zisneg(z1) || zisneg(z2)) {
math_error("Negative argument for permutation");
/*NOTREACHED*/
not_reached();
}
if (zrel(z1, z2) < 0) {
math_error("Second arg larger than first in permutation");
/*NOTREACHED*/
not_reached();
}
if (zge31b(z2)) {
math_error("Very large permutation");
/*NOTREACHED*/
not_reached();
}
count = ztolong(z2);
zcopy(z1, &ans);
@@ -468,7 +468,7 @@ zfib(ZVALUE z, ZVALUE *res)
if (zge31b(z)) {
math_error("Very large Fibonacci number");
/*NOTREACHED*/
not_reached();
}
n = ztolong(z);
if (n == 0) {
@@ -547,7 +547,7 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res)
}
if (zge31b(z2)) {
math_error("Raising to very large power");
/*NOTREACHED*/
not_reached();
}
power = ztoulong(z2);
if (zistwo(z1)) { /* two raised to a power */
@@ -669,7 +669,7 @@ ztenpow(long power, ZVALUE *res)
zsquare(_tenpowers_[i-1], &_tenpowers_[i]);
} else {
math_error("cannot compute 10^2^(TEN_MAX+1)");
/*NOTREACHED*/
not_reached();
}
}
if (power & 0x1) {
@@ -1267,7 +1267,7 @@ zlog(ZVALUE z, ZVALUE base)
*/
if (ziszero(z) || ziszero(base) || zisone(base)) {
math_error("Zero or too small argument argument for zlog!!!");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1337,7 +1337,7 @@ zlog10(ZVALUE z, BOOL *was_10_power)
if (ziszero(z)) {
math_error("Zero argument argument for zlog10");
/*NOTREACHED*/
not_reached();
}
/* Ignore sign of z */
@@ -1357,7 +1357,7 @@ zlog10(ZVALUE z, BOOL *was_10_power)
power10 = malloc(sizeof(long) * (max_power10_exp+1));
if (power10 == NULL) {
math_error("cannot malloc power10 table");
/*NOTREACHED*/
not_reached();
}
/* load power10 table */
@@ -1396,7 +1396,7 @@ zlog10(ZVALUE z, BOOL *was_10_power)
while (((zp->len * 2) - 1) <= z.len) { /* while square not too large */
if (zp >= &_tenpowers_[TEN_MAX]) {
math_error("Maximum storable power of 10 reached!");
/*NOTREACHED*/
not_reached();
}
if (zp[1].len == 0)
zsquare(*zp, zp + 1);
@@ -1411,7 +1411,7 @@ zlog10(ZVALUE z, BOOL *was_10_power)
do {
rel = zrel(*zp, z);
if (rel == 0) {
/* quick exit - we match a tenpower entry */
/* quick return - we match a tenpower entry */
if (was_10_power != NULL) {
*was_10_power = TRUE;
}
@@ -1420,7 +1420,7 @@ zlog10(ZVALUE z, BOOL *was_10_power)
} while (rel > 0 && --zp >= _tenpowers_);
if (zp < _tenpowers_) {
math_error("fell off bottom of tenpower table!");
/*NOTREACHED*/
not_reached();
}
/* the tenpower value is now our starting comparison value */
@@ -1625,7 +1625,7 @@ zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res)
if (ziszero(z1) || ziszero(z2)) {
math_error("Zero argument in call to zgcdrem!!!");
/*NOTREACHED*/
not_reached();
}
/*
* Begin by taking the gcd for the first time.
@@ -1755,7 +1755,7 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd)
if (z.sign) {
math_error("Square root of negative number");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z)) {
*dest = _zero_;
@@ -2026,11 +2026,11 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest)
sign = z1.sign;
if (sign && ziseven(z2)) {
math_error("Even root of negative number");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z2) || zisneg(z2)) {
math_error("Non-positive root");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z1)) { /* root of zero */
*dest = _zero_;

21
zio.c
View File

@@ -1,7 +1,7 @@
/*
* zio - scanf and printf routines for arbitrary precision integers
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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,7 @@
#include "args.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -105,7 +106,7 @@ math_chr(int ch)
cp = (char *)realloc(outbuf, outbufsize + OUTBUFSIZE + 1);
if (cp == NULL) {
math_error("Cannot realloc output string");
/*NOTREACHED*/
not_reached();
}
outbuf = cp;
outbufsize += OUTBUFSIZE;
@@ -133,7 +134,7 @@ math_str(char *str)
cp = (char *)realloc(outbuf, outbufsize + len + OUTBUFSIZE + 1);
if (cp == NULL) {
math_error("Cannot realloc output string");
/*NOTREACHED*/
not_reached();
}
outbuf = cp;
outbufsize += (len + OUTBUFSIZE);
@@ -211,7 +212,7 @@ math_divertio(void)
sp = (IOSTATE *) malloc(sizeof(IOSTATE));
if (sp == NULL) {
math_error("No memory for diverting output");
/*NOTREACHED*/
not_reached();
}
sp->oldiostates = oldiostates;
sp->outdigits = conf->outdigits;
@@ -228,7 +229,7 @@ math_divertio(void)
outbuf = (char *) malloc(OUTBUFSIZE + 1);
if (outbuf == NULL) {
math_error("Cannot allocate divert string");
/*NOTREACHED*/
not_reached();
}
outbufsize = OUTBUFSIZE;
outputisstring = TRUE;
@@ -250,7 +251,7 @@ math_getdivertedio(void)
sp = oldiostates;
if (sp == NULL) {
math_error("No diverted state to restore");
/*NOTREACHED*/
not_reached();
}
cp = outbuf;
cp[outbufused] = '\0';
@@ -310,7 +311,7 @@ math_setmode(int newmode)
if ((newmode <= MODE_DEFAULT) || (newmode > MODE_MAX)) {
math_error("Setting illegal output mode");
/*NOTREACHED*/
not_reached();
}
oldmode = conf->outmode;
conf->outmode = newmode;
@@ -330,7 +331,7 @@ math_setmode2(int newmode)
if (newmode != MODE2_OFF && ((newmode <= MODE_DEFAULT) ||
(newmode > MODE_MAX))) {
math_error("Setting illegal secondary output mode");
/*NOTREACHED*/
not_reached();
}
oldmode = conf->outmode2;
conf->outmode2 = newmode;
@@ -349,7 +350,7 @@ math_setdigits(LEN newdigits)
if (newdigits < 0) {
math_error("Setting illegal number of digits");
/*NOTREACHED*/
not_reached();
}
olddigits = conf->outdigits;
conf->outdigits = newdigits;
@@ -630,7 +631,7 @@ zprintval(ZVALUE z, long decimals, long width)
&_tenpowers_[depth]);
} else {
math_error("cannot compute 10^2^(TEN_MAX+1)");
/*NOTREACHED*/
not_reached();
}
}
}

19
zmath.c
View File

@@ -1,7 +1,7 @@
/*
* zmath - extended precision integral arithmetic primitives
*
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -31,6 +31,7 @@
#include "zmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -233,12 +234,12 @@ alloc(LEN len)
if (_math_abort_) {
math_error("Calculation aborted");
/*NOTREACHED*/
not_reached();
}
hp = (HALF *) malloc((len+1) * sizeof(HALF));
if (hp == 0) {
math_error("Not enough memory");
/*NOTREACHED*/
not_reached();
}
#ifdef ALLOCTEST
++nalloc;
@@ -725,7 +726,7 @@ zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *quo, ZVALUE *rem, long rnd)
if (ziszero(z2)) {
math_error("Division by zero in zdiv");
/*NOTREACHED*/
not_reached();
}
m = z1.len;
n = z2.len;
@@ -998,7 +999,7 @@ zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res)
}
if (ziszero(z2)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (zisone(z2)) {
zcopy(z1, res);
@@ -1006,7 +1007,7 @@ zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res)
}
if (zhighbit(z1) < zhighbit(z2)) {
math_error("Bad call to zequo");
/*NOTREACHED*/
not_reached();
}
B = z2.v;
o = 0;
@@ -1124,7 +1125,7 @@ zdivi(ZVALUE z, long n, ZVALUE *res)
if (n == 0) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z)) {
*res = _zero_;
@@ -1195,11 +1196,11 @@ zmodi(ZVALUE z, long n)
if (n == 0) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (n < 0) {
math_error("Non-positive modulus");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z) || (n == 1))
return 0;

View File

@@ -41,6 +41,7 @@
# include "longbits.h"
# include "byteswap.h"
# include "have_stdlib.h"
# include "attribute.h"
#else
# include <calc/decl.h>
# include <calc/alloc.h>
@@ -48,6 +49,7 @@
# include <calc/longbits.h>
# include <calc/byteswap.h>
# include <calc/have_stdlib.h>
# include <calc/attribute.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
@@ -625,13 +627,14 @@ E_FUNC char *math_getdivertedio(void);
E_FUNC int math_setmode(int mode);
E_FUNC int math_setmode2(int mode);
E_FUNC LEN math_setdigits(LEN digits);
E_FUNC void math_fmt(char *, ...) PRINTF_FORMAT(1, 2);
E_FUNC void math_fmt(char *, ...) __attribute__((format(printf, 1, 2)));
/*
* The error routine.
*/
E_FUNC void math_error(char *, ...) PRINTF_FORMAT(1, 2);
E_FUNC void math_error(char *, ...) \
__attribute__((format(printf, 1, 2))) __attribute__((noreturn));
/*
@@ -640,6 +643,7 @@ E_FUNC void math_error(char *, ...) PRINTF_FORMAT(1, 2);
E_FUNC HALF *swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len);
E_FUNC ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
E_FUNC HALF *swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len);
E_FUNC HALF *swap_HALFs(HALF *dest, HALF *src, LEN len);
E_FUNC ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);
E_FUNC ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all);

35
zmod.c
View File

@@ -1,8 +1,7 @@
/*
* zmod - modulo arithmetic routines
*
* Copyright (C) 1999-2007,2021 David I. Bell, Landon Curt Noll
* and Ernest Bowen
* Copyright (C) 1999-2007,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -42,6 +41,7 @@
#include "zmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -76,9 +76,10 @@ zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res)
FULL prod;
FULL digit;
if (ziszero(z2) || zisneg(z2))
if (ziszero(z2) || zisneg(z2)) {
math_error("Mod of non-positive integer");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z1) || zisunit(z2)) {
*res = _zero_;
return;
@@ -139,7 +140,7 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res)
if (ziszero(z2) || zisneg(z2)) {
math_error("Mod of non-positive integer");
/*NOTREACHED*/
not_reached();
}
if (ziszero(z1) || zisunit(z2)) {
*res = _zero_;
@@ -232,7 +233,7 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3)
if (zisneg(z3) || ziszero(z3)) {
math_error("Non-positive modulus in zcmpmod");
/*NOTREACHED*/
not_reached();
}
if (zistwo(z3))
return (((z1.v[0] + z2.v[0]) & 0x1) != 0);
@@ -363,7 +364,7 @@ zmod5(ZVALUE *zp)
z1.sign = z2.sign = z3.sign = 0;
if (z1.len > modlen + 1) {
math_error("Bad call to zmod5!!!");
/*NOTREACHED*/
not_reached();
}
z2.v = lastmodinv->v + modlen + 1 - z1.len;
z2.len = lastmodinv->len - modlen - 1 + z1.len;
@@ -400,7 +401,7 @@ zmod5(ZVALUE *zp)
subcount++;
if (subcount > 2) {
math_error("Too many subtractions in zmod5");
/*NOTREACHED*/
not_reached();
}
j = modlen;
a = zp->v;
@@ -498,11 +499,11 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
if (zisneg(z3) || ziszero(z3)) {
math_error("Non-positive modulus in zpowermod");
/*NOTREACHED*/
not_reached();
}
if (zisneg(z2)) {
math_error("Negative power in zpowermod");
/*NOTREACHED*/
not_reached();
}
@@ -884,13 +885,13 @@ zredcalloc(ZVALUE z1)
if (ziseven(z1) || zisneg(z1)) {
math_error("REDC requires positive odd modulus");
/*NOTREACHED*/
not_reached();
}
rp = (REDC *) malloc(sizeof(REDC));
if (rp == NULL) {
math_error("Cannot allocate REDC structure");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1708,7 +1709,7 @@ zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res)
if (zisneg(z2)) {
math_error("Negative power in zredcpower");
/*NOTREACHED*/
not_reached();
}
if (zisunit(rp->mod)) {
@@ -1991,19 +1992,19 @@ zhnrmod(ZVALUE v, ZVALUE zh, ZVALUE zn, ZVALUE zr, ZVALUE *res)
*/
if (zisneg(zh) || ziszero(zh)) {
math_error("h must be > 0");
/*NOTREACHED*/
not_reached();
}
if (zisneg(zn) || ziszero(zn)) {
math_error("n must be > 0");
/*NOTREACHED*/
not_reached();
}
if (zge31b(zn)) {
math_error("n must be < 2^31");
/*NOTREACHED*/
not_reached();
}
if (!zisabsleone(zr)) {
math_error("r must be -1, 0 or 1");
/*NOTREACHED*/
not_reached();
}

5
zmul.c
View File

@@ -1,7 +1,7 @@
/*
* zmul - faster than usual multiplying and squaring routines
*
* Copyright (C) 1999-2007,2021 David I. Bell
* Copyright (C) 1999-2007,2021,2022 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
@@ -37,6 +37,7 @@
#include "zmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -1072,7 +1073,7 @@ zalloctemp(LEN len)
hp = (HALF *) malloc((len+1) * sizeof(HALF));
if (hp == NULL) {
math_error("No memory for temp buffer");
/*NOTREACHED*/
not_reached();
}
bufptr = hp;
buflen = len;

View File

@@ -1,7 +1,7 @@
/*
* zprime - rapid small prime routines
*
* Copyright (C) 1999-2007,2021 Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 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
@@ -33,6 +33,7 @@
#include "have_const.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
@@ -830,11 +831,11 @@ zpfact(ZVALUE z, ZVALUE *dest)
/* firewall */
if (zisneg(z)) {
math_error("Negative argument for factorial");
/*NOTREACHED*/
not_reached();
}
if (zge24b(z)) {
math_error("Very large factorial");
/*NOTREACHED*/
not_reached();
}
n = ztolong(z);
@@ -1534,11 +1535,11 @@ zlcmfact(ZVALUE z, ZVALUE *dest)
if (zisneg(z) || ziszero(z)) {
math_error("Non-positive argument for lcmfact");
/*NOTREACHED*/
not_reached();
}
if (zge24b(z)) {
math_error("Very large lcmfact");
/*NOTREACHED*/
not_reached();
}
n = ztolong(z);
/*

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