mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
193 Commits
2.12.8.2
...
prod-2.14.
Author | SHA1 | Date | |
---|---|---|---|
|
d91ace6091 | ||
|
49c6a8218c | ||
|
def203f273 | ||
|
5b2983f421 | ||
|
e6fc1a92a9 | ||
|
3e084d9fb9 | ||
|
340c1990ce | ||
|
5acd67c704 | ||
|
083011c9e3 | ||
|
dce2c6f0ee | ||
|
827988c553 | ||
|
25dcd8cb80 | ||
|
3b3bfb3f74 | ||
|
3e4391e2af | ||
|
cfc6a6669c | ||
|
fa457db3cd | ||
|
d08b958a15 | ||
|
5f28e5b851 | ||
|
8dc52a532a | ||
|
6fc14730c0 | ||
|
b97093e58c | ||
|
923c36e475 | ||
|
741ea46853 | ||
|
56b6613da8 | ||
|
e9eef2dfa2 | ||
|
0dbf258696 | ||
|
f6d558783a | ||
|
6f27a32f79 | ||
|
d58f605866 | ||
|
b83c5be515 | ||
|
561928a45c | ||
|
7f89af37f5 | ||
|
4470f1f62e | ||
|
8217c49b94 | ||
|
d2cb03b4cc | ||
|
80f13a4e45 | ||
|
1658343227 | ||
|
3f177f2d81 | ||
|
dcd5a987af | ||
|
cb77888045 | ||
|
ce17b267be | ||
|
738dd0334e | ||
|
7ba1dbdc65 | ||
|
ee70c12481 | ||
|
d4970d66ce | ||
|
c3ea3d28a4 | ||
|
3fa34dabfe | ||
|
ffd4422870 | ||
|
b5b2c3f812 | ||
|
f7dadbf1f8 | ||
|
22e123140c | ||
|
1242700601 | ||
|
5b7dfeaf11 | ||
|
b3c015d338 | ||
|
5985ad2f33 | ||
|
e401c9abf1 | ||
|
ad79b6384d | ||
|
862dbd6777 | ||
|
0d31eb6828 | ||
|
c0be37d4e3 | ||
|
4344532c28 | ||
|
0f6efb29bb | ||
|
39c0cba1ca | ||
|
a68e41248f | ||
|
e213cc5072 | ||
|
95ebb60619 | ||
|
e5c8f00adc | ||
|
265713778f | ||
|
4b08a896b0 | ||
|
44f3778af1 | ||
|
8db8f93ae0 | ||
|
e688c22c0e | ||
|
af72992ead | ||
|
9f3a7817d3 | ||
|
dd0610db0a | ||
|
177a5d00d1 | ||
|
a02f8aa9f9 | ||
|
b7d1fb096d | ||
|
48c4f3b948 | ||
|
2023175fcc | ||
|
c54e2648dc | ||
|
faf40b7149 | ||
|
4b2ae40c86 | ||
|
af57104e25 | ||
|
5ae3ca059a | ||
|
cc5fb9a45b | ||
|
5dcadad8b6 | ||
|
9c67ceeed8 | ||
|
7ffbaf922e | ||
|
f9464652fe | ||
|
b30c5c1855 | ||
|
7417f2e776 | ||
|
71138215a9 | ||
|
241f777d07 | ||
|
9d27f0aaa7 | ||
|
a28edba4e9 | ||
|
de47c960d3 | ||
|
c3a51f42e2 | ||
|
f5c5cea8b0 | ||
|
769ac51f8c | ||
|
cdda633369 | ||
|
50f349f4d7 | ||
|
ef00e00328 | ||
|
bb041098bc | ||
|
f794b8d859 | ||
|
bd990cef1f | ||
|
febb9d96b3 | ||
|
13ae9b804e | ||
|
56cc4897d6 | ||
|
eb940e0a21 | ||
|
f3adb35e36 | ||
|
d1d365d7ba | ||
|
af214b166d | ||
|
51b933dfff | ||
|
c4e5007587 | ||
|
c838798f04 | ||
|
23d49a41fe | ||
|
3d300acca1 | ||
|
8f449ba6d2 | ||
|
f4d754b47d | ||
|
fde724aa2d | ||
|
e411a3e6bf | ||
|
7db81649b0 | ||
|
08fe6f13f4 | ||
|
e11d159c81 | ||
|
dfd66be871 | ||
|
27f977b545 | ||
|
2ca6e789ca | ||
|
ff8f921ebc | ||
|
005b78227a | ||
|
b7a42a9d3d | ||
|
3d1e938cb6 | ||
|
8b98a7c1f6 | ||
|
dbf5acf5e8 | ||
|
5fe5ab1c4b | ||
|
e0cd9bb3db | ||
|
f0f6171354 | ||
|
94861cc6d2 | ||
|
286233e28f | ||
|
99ac7836aa | ||
|
6c0c8e0ef6 | ||
|
8aa5f140bf | ||
|
2fcb9a5995 | ||
|
8b018b697d | ||
|
0e269ecd67 | ||
|
a640bc4656 | ||
|
62a95499ef | ||
|
9e92d4a35a | ||
|
459c07b121 | ||
|
ada15fdabc | ||
|
d5de36841a | ||
|
cf419fb329 | ||
|
abf39b34b6 | ||
|
552252371f | ||
|
7570010a04 | ||
|
a9ee753dc6 | ||
|
ca5a81122a | ||
|
554cd97145 | ||
|
806606f284 | ||
|
7c0ebc5887 | ||
|
45665f94a7 | ||
|
cd736fdbd4 | ||
|
f753884008 | ||
|
1d9a4941ce | ||
|
5bde797ba4 | ||
|
ecba35fc26 | ||
|
a4f8f367c3 | ||
|
41b11ab785 | ||
|
3d33c6c6f4 | ||
|
dbd8926022 | ||
|
f7f110b686 | ||
|
ebf065dcb8 | ||
|
6bc0747a71 | ||
|
04861939fc | ||
|
ca0aaa0c3a | ||
|
f5d5319a51 | ||
|
263b8a78ef | ||
|
3c866367c6 | ||
|
09d7080547 | ||
|
f480c8c5df | ||
|
a230431a3b | ||
|
eaec46982d | ||
|
a86d629982 | ||
|
bcbc0cb766 | ||
|
ac0d84eef8 | ||
|
9b4580d861 | ||
|
2085361df1 | ||
|
bf4657c138 | ||
|
1b5636afed | ||
|
7eba99ac29 | ||
|
de6474bf28 | ||
|
55bc690cd1 | ||
|
6dc62c1ab7 |
70
.github/ISSUE_TEMPLATE/calc-bug-report.md
vendored
Normal file
70
.github/ISSUE_TEMPLATE/calc-bug-report.md
vendored
Normal 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.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal 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.
|
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '41 1 * * 6'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# 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
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
16
.gitignore
vendored
16
.gitignore
vendored
@@ -6,7 +6,6 @@
|
||||
#
|
||||
.dynamic
|
||||
.hsrc
|
||||
Makefile.simple
|
||||
NOTES
|
||||
align32.h
|
||||
args.h
|
||||
@@ -16,6 +15,7 @@ calc.1
|
||||
calc.usage
|
||||
calcerr.c
|
||||
calcerr.h
|
||||
charbit.h
|
||||
conf.h
|
||||
cscript/.all
|
||||
cscript/4dsphere
|
||||
@@ -28,18 +28,22 @@ cscript/powerterm
|
||||
cscript/simple
|
||||
cscript/square
|
||||
custom/.all
|
||||
custom/Makefile.simple
|
||||
custom/libcustcalc*
|
||||
debug.out
|
||||
endian
|
||||
endian_calc.h
|
||||
fposval.h
|
||||
have_arc4random.h
|
||||
have_ban_pragma.h
|
||||
have_const.h
|
||||
have_fpos.h
|
||||
have_environ.h
|
||||
have_fgetsetpos.h
|
||||
have_fpos_pos.h
|
||||
have_getpgid.h
|
||||
have_getprid.h
|
||||
have_getsid.h
|
||||
have_gettime.h
|
||||
have_limits.h
|
||||
have_memmv.h
|
||||
have_newstr.h
|
||||
have_offscl.h
|
||||
@@ -49,6 +53,8 @@ have_stdlib.h
|
||||
have_stdvs
|
||||
have_strdup.h
|
||||
have_string.h
|
||||
have_strlcat.h
|
||||
have_strlcpy.h
|
||||
have_times.h
|
||||
have_uid_t.h
|
||||
have_unistd.h
|
||||
@@ -79,6 +85,7 @@ help/man
|
||||
help/new_custom
|
||||
help/question
|
||||
help/questions
|
||||
help/releases
|
||||
help/resource
|
||||
help/type
|
||||
help/usage
|
||||
@@ -86,10 +93,13 @@ libcalc*
|
||||
libcustcalc*
|
||||
longbits
|
||||
longbits.h
|
||||
Makefile.our
|
||||
sample_many
|
||||
sample_rand
|
||||
tags
|
||||
terminal.h
|
||||
ver_calc
|
||||
win32/
|
||||
|
||||
# other commonly excluded patterns
|
||||
#
|
||||
|
76
BUGS
76
BUGS
@@ -15,19 +15,37 @@ 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.
|
||||
|
||||
=-=
|
||||
|
||||
The BEST WAY TO SEND IN A BUG REPORT is via calc GitHub issue URL:
|
||||
If you encounter a warning or error in compiling, or if you
|
||||
find a calc bug and you wish to send is a fix, we recommend
|
||||
that you submit your change using the GitHub pull request:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
=-=
|
||||
|
||||
If you just want to send us a bug report, we recommend
|
||||
doing so via the GitHub issue process:
|
||||
|
||||
https://github.com/lcn2/calc/issues
|
||||
|
||||
@@ -116,58 +134,10 @@ of a context diff patch).
|
||||
|
||||
Known bugs in calc:
|
||||
|
||||
Under macOS, the installation of the calc man page fails.
|
||||
|
||||
The output of the alg_config.cal resource file is bogus.
|
||||
We would welcome a replacement for this code.
|
||||
|
||||
Calc shell scripts do not read from stdin properly,
|
||||
we all as a number of the cscript examples.
|
||||
|
||||
The argv() function is behaving differently
|
||||
when run in calc shell script mode:
|
||||
|
||||
When calc is run as:
|
||||
|
||||
calc -s a bb ccc
|
||||
|
||||
and given this input on the command prompt:
|
||||
|
||||
print "config(\"program\")=", config("program");
|
||||
print "argv()=", argv();
|
||||
argc = argv();
|
||||
for (i=0; i < argc; ++i) {
|
||||
print "argv(":i:")=", argv(i);
|
||||
}
|
||||
|
||||
calc prints:
|
||||
|
||||
config("program")= calc
|
||||
argv()= 3
|
||||
argv(0)= a
|
||||
argv(1)= bb
|
||||
argv(2)= ccc
|
||||
|
||||
but when it is run as a script called ./simple:
|
||||
|
||||
#!/usr/local/bin/calc -q -s -f
|
||||
print "config(\"program\")=", config("program");
|
||||
print "argv()=", argv();
|
||||
argc = argv();
|
||||
for (i=0; i < argc; ++i) {
|
||||
print "argv(":i:")=", argv(i);
|
||||
}
|
||||
|
||||
under Linux prints:
|
||||
|
||||
config("program")= /usr/bin/calc
|
||||
argv()= 4
|
||||
argv(0)= ./simple
|
||||
argv(1)= a
|
||||
argv(2)= bb
|
||||
argv(3)= ccc
|
||||
|
||||
and under macOS simply enters into interactive mode.
|
||||
Calc may not compile natively under Windows 11. See README.WINDOWS.
|
||||
|
||||
We are sure some more bugs exist. When you find them, please let
|
||||
us know! See the above for details on how to report and were to
|
||||
|
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal 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
7
CONTRIBUTING.md
Normal 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.
|
371
HOWTO.INSTALL
371
HOWTO.INSTALL
@@ -1,10 +1,23 @@
|
||||
Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
|
||||
0) If your platform supports i686 RPMs, you may want to go to:
|
||||
IMPORTANT: Please see the section at the bottom of this file for
|
||||
some important information on Makefiles used in calc.
|
||||
|
||||
http://www.isthe.com/chongo/src/calc/
|
||||
###################################################################
|
||||
# IMPORTANT: DO NOT use make in parallel mode!!! #
|
||||
###################################################################
|
||||
# Unfortunately due to the complex dependency issues between #
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel make #
|
||||
# is NOT recommended. Sorry (tm Canada) :) #
|
||||
###################################################################
|
||||
|
||||
and use these RPMs:
|
||||
Installing calc from the bzip2-ed tarball: 4 easy steps:
|
||||
|
||||
(0) If your platform supports i686 RPMs, you may want to go to:
|
||||
|
||||
https://github.com/lcn2/calc/releases
|
||||
|
||||
Open up the 'Assets' tag below a given release and
|
||||
download these RPMs:
|
||||
|
||||
* calc*.i686.rpm
|
||||
- all that is needed if you just want to use calc
|
||||
@@ -13,37 +26,138 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
- calc *.h header and *.a lib files for use in other programs
|
||||
|
||||
* calc.*.src.rpm
|
||||
- calc source in RPM package form
|
||||
- calc source via a SRPM package
|
||||
|
||||
The following 4 steps apply to calc source tree that comes from either:
|
||||
Alternately to the above github link, you might try looking at
|
||||
the RPMs under:
|
||||
|
||||
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
||||
http://www.isthe.com/chongo/src/calc/
|
||||
|
||||
or from:
|
||||
=-=
|
||||
|
||||
rpm -ivh calc-*.src.rpm
|
||||
cd /var/tmp
|
||||
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
|
||||
The following 4 steps apply to calc source tree that comes from either:
|
||||
|
||||
1) Look at the makefile, and adjust it to suit your needs.
|
||||
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
||||
|
||||
The top level Makefile and the custom/Makefile require a GNU
|
||||
or from:
|
||||
|
||||
rpm -ivh calc-*.src.rpm
|
||||
cd /var/tmp
|
||||
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
|
||||
|
||||
4 steps:
|
||||
|
||||
(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,
|
||||
one must use gmake instead of make.
|
||||
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:
|
||||
|
||||
If your target system does not have GNU Make (or equivalent), then
|
||||
you should try using the Makefile.simple and custom/Makefile.simple
|
||||
(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
|
||||
files:
|
||||
|
||||
mv Makefile Makefile.gmake
|
||||
@@ -56,10 +170,18 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
values should work. If in doubt, follow the 'When in doubt'
|
||||
suggestion.
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! If you are building under Windoz or a Windoz-like environment !
|
||||
! (such as Cygwin or DJGPP), read the README.WINDOWS file. !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
If you are using a modern make (such as gmake), you may override
|
||||
any values set in the Makefile by adding them to Makefile.local
|
||||
using the := directive. For example:
|
||||
|
||||
HAVE_STRING_H:= YES
|
||||
HAVE_TIMES_H:= YES
|
||||
SED:= /usr/local/bin/nsed
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! If you are building under Windows or a Windows-like environment !
|
||||
! (such as Cygwin or DJGPP), read the README.WINDOWS file. !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
You should determine if these Makefile variables are reasonable:
|
||||
|
||||
@@ -67,7 +189,7 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
BINDIR Where to install calc binary files.
|
||||
LIBDIR Where to install calc link library (*.a) files.
|
||||
CALC_SHAREDIR Where to install calc help, .cal, startup, and
|
||||
config files.
|
||||
config files.
|
||||
|
||||
You may want to change the default installation locations for
|
||||
these values, which are based on the 4 values listed above:
|
||||
@@ -88,13 +210,13 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
|
||||
For example, if:
|
||||
|
||||
BINDIR= /usr/bin
|
||||
BINDIR= /usr/bin
|
||||
LIBDIR= /usr/lib
|
||||
CALC_SHAREDIR= /usr/share/calc
|
||||
|
||||
and if:
|
||||
|
||||
T= /var/tmp/testing
|
||||
T= /var/tmp/testing
|
||||
|
||||
Then the installation locations will be:
|
||||
|
||||
@@ -148,7 +270,7 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
|
||||
Adjust other Makefile variables as needed.
|
||||
|
||||
2) build calc:
|
||||
(2) build calc:
|
||||
|
||||
The top level Makefile and the custom/Makefile require a GNU
|
||||
Make (such as gmake) or an equivalently advanced make. On many
|
||||
@@ -180,24 +302,193 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
make clobber
|
||||
make calc-dynamic-only BLD_TYPE=calc-dynamic-only
|
||||
|
||||
3) test calc:
|
||||
(3) test calc:
|
||||
|
||||
make check
|
||||
|
||||
==> If you run into problems, read the BUGS file and follow
|
||||
the instructions found in there.
|
||||
make check
|
||||
|
||||
NOTE: For a quiet check which only prints if something goes wrong:
|
||||
|
||||
make chk
|
||||
make chk
|
||||
|
||||
4) install calc:
|
||||
(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.
|
||||
|
||||
In general, if you run into problems, read the BUGS file and follow
|
||||
the instructions.
|
||||
|
||||
=-=
|
||||
|
||||
On calc Makefiles:
|
||||
|
||||
How to tell the origin of of a Makefile:
|
||||
|
||||
The "# SRC: ... - ..." comment line near the top
|
||||
of the file indicates the origin of this file.
|
||||
In each segment below, we indicate what the SRC
|
||||
comment like will read.
|
||||
|
||||
SHELL= ...
|
||||
|
||||
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 edit the Makefile 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 sh may be a much better alternative
|
||||
shell for this Makefile to use:
|
||||
|
||||
SHELL= /bin/sh
|
||||
|
||||
Makefile.local
|
||||
|
||||
# SRC: Makefile.local - tweaks to the top level Makefile
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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 the calc GitHub repo, Makefile is the calc build environment
|
||||
and Makefile.ship is the top level Makefile:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
Makefile
|
||||
|
||||
# SRC: Makefile.ship - top level Makefile
|
||||
|
||||
This is the main top level Makefile.
|
||||
|
||||
In calc packages such as RPMs, and the tar.bz2 source tarball,
|
||||
Makefile.ship has been moved into 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
|
||||
|
||||
The Makefile.simple rule of Makefile.ship, when forming the
|
||||
Makefile.simple file, removes lines from Makefile.ship between
|
||||
pairs of '#if 0' AND '#endif':
|
||||
|
||||
#if 0
|
||||
lines removed when forming Makefile.simple
|
||||
...
|
||||
lines removed when forming Makefile.simple
|
||||
#endif
|
||||
|
||||
The '#if 0' AND '#endif' MUST be at the start of the line.
|
||||
Any text after the '#if 0' OR '#endif' is ignored.
|
||||
|
||||
While they may look like a CPP directives, they are not. The
|
||||
inline awk script of the Makefile.simple rule does NOT allow
|
||||
them to nest:
|
||||
|
||||
#if 0 /* DO NOT DO THIS */
|
||||
lines removed when forming Makefile.simple
|
||||
...
|
||||
#if 0 /* DO NOT DO THIS */
|
||||
...
|
||||
#endif /* DO NOT DO THIS */
|
||||
...
|
||||
#endif /* DO NOT DO THIS */
|
||||
|
||||
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.
|
||||
|
||||
If you have a Makefile.simple file, use these commands to
|
||||
form a Makefile:
|
||||
|
||||
if [ -f Makefile ]; then mv -f Makefile Makefile.orig; fi
|
||||
cp Makefile.simple Makefile
|
||||
|
||||
The Makefile.simple rule from Makefile.ship is used to construct
|
||||
this file from the contents of Makefile.ship.
|
||||
|
||||
In calc packages such as RPMs, and the tar.bz2 source the
|
||||
Makefile.simple exists. In the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
this file does NOT exist and must be made via the Makefile.simple
|
||||
make rule. Therefore, non-GNU and simple make commands are NOT
|
||||
supported by the calc GitHub repo master branch. Instead, you
|
||||
need to extract Makefile.simple from one of the calc tar.bz2
|
||||
source tarball source from a calc source mirror:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
|
||||
|
||||
custom/Makefile
|
||||
|
||||
# SRC: Makefile via make -f Makefile custom/Makefile
|
||||
|
||||
This is the custom directory 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
|
||||
command.
|
||||
|
||||
In calc packages such as RPMs, and the tar.bz2 source the
|
||||
Makefile.simple exists. In the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
this file does NOT exist and must be made via the
|
||||
custom/Makefile.simple make rule. Therefore, non-GNU and simple
|
||||
make commands are NOT supported by the calc GitHub repo master
|
||||
branch. Instead, you need to extract custom/Makefile.simple
|
||||
from one of the calc tar.bz2 source tarball source from a calc
|
||||
source mirror:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
|
||||
|
||||
cal/Makefile
|
||||
|
||||
# SRC: cal/Makefile
|
||||
|
||||
The Makefile for the cal sub-directory.
|
||||
|
||||
cscript/Makefile
|
||||
|
||||
# SRC: cscript/Makefile
|
||||
|
||||
The Makefile for the cscript sub-directory.
|
||||
|
||||
help/Makefile
|
||||
|
||||
# SRC: help/Makefile
|
||||
|
||||
The Makefile for the help sub-directory.
|
||||
|
||||
## Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
|
14
LIBRARY
14
LIBRARY
@@ -216,7 +216,7 @@ Your program must handle parse/scan errors in one of two ways:
|
||||
/* report the parse/scan */
|
||||
if (calc_use_scanerr_jmpbuf == 0) {
|
||||
printf("parse error: %s\n", calc_err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize calc after the longjmp */
|
||||
initialize();
|
||||
@@ -320,10 +320,10 @@ The arbitrary precision integer routines define a structure called a ZVALUE.
|
||||
This is defined in zmath.h. A ZVALUE contains a pointer to an array of
|
||||
integers, the length of the array, and a sign flag. The array is allocated
|
||||
using malloc, so you need to free this array when you are done with a
|
||||
ZVALUE. To do this, you should call zfree with the ZVALUE as an argument
|
||||
(or call freeh with the pointer as an argument) and never try to free the
|
||||
array yourself using free. The reason for this is that sometimes the pointer
|
||||
points to one of two statically allocated arrays which should NOT be freed.
|
||||
ZVALUE. To do this, you should call zfree() with the ZVALUE as an argument
|
||||
and never try to free the array yourself using free(). The reason for this
|
||||
is that sometimes the pointer points to a statically allocated arrays which
|
||||
should NOT be freed.
|
||||
|
||||
The ZVALUE structures are passed to routines by value, and are returned
|
||||
through pointers. For example, to multiply two small integers together,
|
||||
@@ -615,14 +615,14 @@ These have the values 0, 1, and i.
|
||||
LAST THINGS LAST
|
||||
----------------
|
||||
|
||||
If you wish, when you are all doen you can call libcalc_call_me_last()
|
||||
If you wish, when you are all done you can call libcalc_call_me_last()
|
||||
to free a small amount of storage associated with the libcalc_call_me_first()
|
||||
call. This is not required, but is does bring things to a closure.
|
||||
|
||||
The function libcalc_call_me_last() takes no args and returns void. You
|
||||
need call libcalc_call_me_last() only once.
|
||||
|
||||
## Copyright (C) 1999 David I. Bell and Landon Curt Noll
|
||||
## Copyright (C) 1999,2021 David I. Bell and Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
39
Makefile.local
Normal file
39
Makefile.local
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# 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
117
README.RELEASE
Normal file
117
README.RELEASE
Normal 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/
|
@@ -1,19 +1,55 @@
|
||||
Dear calc user on a Windoz based system,
|
||||
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.
|
||||
|
||||
NOTE: The main developers do not have access to a Windoz based platform.
|
||||
While we will make an effort to not break calc Windoz based system,
|
||||
our lack of a Windoz test environment will mean we will make mistakes
|
||||
from time to time. Hopefully Windowz users can overcome these mistakes.
|
||||
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.
|
||||
|
||||
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,
|
||||
our lack of a Windows test environment will mean we will make mistakes
|
||||
from time to time. Hopefully Windows users can overcome these mistakes.
|
||||
Of course you are welcome to send us any patches that fix your
|
||||
Windoz build environment.
|
||||
Windows build environment.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc under Windows 11 =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling with Windows Subsystem for Linux (WSL) =-Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
We were given this advice from a Windows 11 developer:
|
||||
|
||||
Windows 11 users could use Cygwin:
|
||||
|
||||
https://cygwin.com/install.html
|
||||
|
||||
IMPORTANT: While installing Cygwin, and during Cygwin Setup, be sure to
|
||||
select all the MinGW64 packages relating to gcc.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= 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.
|
||||
@@ -78,9 +114,9 @@ needs.
|
||||
|
||||
In particular:
|
||||
|
||||
Just copy the win32/*.[ch] files up into the top level calc
|
||||
source directory, edit them (if needed) and build using the
|
||||
Cygwin GCC compiler and Cygwin build environment.
|
||||
Just copy the win32/*.[ch] files up into the top level calc
|
||||
source directory, edit them (if needed) and build using the
|
||||
Cygwin GCC compiler and Cygwin build environment.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling under DJGPP =-=
|
||||
@@ -126,9 +162,11 @@ recommends the following settings:
|
||||
CATDIR= /dev/env/DJDIR/man/cat1
|
||||
NROFF= groff
|
||||
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
|
||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||
CALCPAGER= less.exe -ci
|
||||
DEBUG= -O2 -gstabs+ -DWINDOZ
|
||||
DEBUG= -O2 -gstabs+ -D_WIN32
|
||||
HAVE_ENVIRON=-DHAVE_NO_ENVIRON
|
||||
HAVE_ARC4RANDOM=-DHAVE_NO_ARC4RANDOM
|
||||
|
||||
The 'Linux set' or 'gcc set' (see the Select your compiler type section)
|
||||
should work for DJGPP systems if you set the above Makefile variables.
|
||||
@@ -141,7 +179,7 @@ Follow those recommendations. In cases where they conflict with
|
||||
the above Makefile list, follow the recommendation in the Makefile.
|
||||
|
||||
|
||||
## Copyright (C) 2002-2009 Landon Curt Noll and Thomas Jones-Low
|
||||
## Copyright (C) 2002-2009,2021 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
|
||||
|
19
SECURITY.md
Normal file
19
SECURITY.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
The most recent version of calc is supported with security updates.
|
||||
|
||||
If the most recent stable of calc is also supported with security updates.
|
||||
|
||||
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.
|
25
addop.c
25
addop.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* addop - add opcodes to a function being compiled
|
||||
*
|
||||
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "opcodes.h"
|
||||
#include "str.h"
|
||||
#include "func.h"
|
||||
@@ -36,6 +37,10 @@
|
||||
#include "symbol.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
|
||||
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */
|
||||
|
||||
@@ -64,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;
|
||||
@@ -151,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;
|
||||
@@ -199,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)
|
||||
@@ -253,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;
|
||||
@@ -312,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)) {
|
||||
@@ -382,7 +387,7 @@ findfunc(long index)
|
||||
{
|
||||
if (index >= funccount) {
|
||||
math_error("Undefined function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return functions[index];
|
||||
}
|
||||
@@ -434,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));
|
||||
|
19
align32.c
19
align32.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* align32 - determine if 32 bit accesses must be aligned
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -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,7 +39,13 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static void buserr(void); /* catch alignment errors */
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
static void buserr(int arg); /* catch alignment errors */
|
||||
|
||||
|
||||
int
|
||||
@@ -42,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 */
|
||||
@@ -78,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",
|
||||
|
2
alloc.h
2
alloc.h
@@ -42,9 +42,7 @@
|
||||
# include <string.h>
|
||||
|
||||
#else
|
||||
#if defined(_WIN32) && defined(NOTCYGWIN)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
# if defined(HAVE_NEWSTR)
|
||||
E_FUNC void *memcpy();
|
||||
|
26
assocfunc.c
26
assocfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* assocfunc - association table routines
|
||||
*
|
||||
* Copyright (C) 1999-2007 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,10 @@
|
||||
#include "value.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define MINHASHSIZE 31 /* minimum size of hash tables */
|
||||
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
|
||||
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */
|
||||
@@ -71,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -109,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;
|
||||
@@ -139,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);
|
||||
@@ -169,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);
|
||||
@@ -330,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;
|
||||
@@ -371,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;
|
||||
@@ -427,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;
|
||||
@@ -435,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
69
attribute.h
Normal 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 */
|
180
banned.h
Normal file
180
banned.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* banned - optionally ban dangerous functions
|
||||
*
|
||||
* Unless UNBAN is defined, this file will turn the use
|
||||
* of certain dangerous functions into syntax errors.
|
||||
*
|
||||
* In the case of calc, we are motivated in part by the desire for
|
||||
* calc to correctly calculate: even during extremely long calculations.
|
||||
*
|
||||
* If UNBAN is NOT defined, then calling certain functions
|
||||
* will result in a syntax error.
|
||||
*
|
||||
* If we define UNBAN, then the effect of this file is disabled.
|
||||
*
|
||||
* The banned.h attempts to ban the use of certain dangerous functions
|
||||
* that, if improperly used, could compromise the computational integrity
|
||||
* if calculations.
|
||||
*
|
||||
* In the case of calc, we are motivated in part by the desire for calc
|
||||
* to correctly calculate: even 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.
|
||||
*
|
||||
* Copyright (C) 2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
* Public License for more details.
|
||||
*
|
||||
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Under source code control: 2021/03/06 21:07:31
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(PRE_HAVE_BAN_PRAGMA_H)
|
||||
#include "have_ban_pragma.h"
|
||||
#endif /* ! PRE_HAVE_BAN_PRAGMA_H */
|
||||
|
||||
|
||||
#if !defined(INCLUDE_BANNED_H)
|
||||
#define INCLUDE_BANNED_H
|
||||
|
||||
/*
|
||||
* If we define UNBAN, then the effect of this file is disabled.
|
||||
*/
|
||||
#if !defined(UNBAN)
|
||||
|
||||
/*
|
||||
* In the spirit of:
|
||||
*
|
||||
* https://github.com/git/git/blob/master/banned.h
|
||||
*
|
||||
* we will ban the use of certain unsafe functions by turning
|
||||
* then into function calls that do not exist.
|
||||
*
|
||||
* In the case of calc, we are motivated in part by the desire
|
||||
* for calc to correctly calculate: even during extremely long
|
||||
* calculations.
|
||||
*
|
||||
* If UNBAN is NOT defined, then calling certain functions
|
||||
* will result in a syntax error.
|
||||
*
|
||||
* Unlike the above URL, we suggest an alternative function.
|
||||
* In many cases, additional logic is required to use the
|
||||
* alternative function, we cannot simply replace one function
|
||||
* with another.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If one is not careful, strcpy() can lead to buffer overflows.
|
||||
* Use strlcpy() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef strcpy
|
||||
#pragma GCC poison strcpy
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* If one is not careful, strcat() can lead to buffer overflows.
|
||||
* Use strlcat() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef strcat
|
||||
#pragma GCC poison strcat
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* If one is not careful, strncpy() can lead to buffer overflows.
|
||||
* Use memccpy() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef strncpy
|
||||
#pragma GCC poison strncpy
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* If one is not careful, strncat() can lead to buffer overflows.
|
||||
* Use memccpy() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef strncat
|
||||
#pragma GCC poison strncat
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* If one is not careful, sprintf() can lead to buffer overflows.
|
||||
* Use snprintf() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef sprintf
|
||||
#pragma GCC poison sprintf
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* If one is not careful, vsprintf() can lead to buffer overflows.
|
||||
* Use vsnprintf() instead.
|
||||
*/
|
||||
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||
#undef vsprintf
|
||||
#pragma GCC poison vsprintf
|
||||
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||
|
||||
/*
|
||||
* XXX - As of 2021, functions such as:
|
||||
*
|
||||
* gmtime_s
|
||||
* localtime_s
|
||||
* ctime_s
|
||||
* asctime_s
|
||||
*
|
||||
* are not universal. We cannot yet ban the following
|
||||
* functions because we do not have a portable AND
|
||||
* widely available alternative. Therefore we just
|
||||
* have to be extra careful when using:
|
||||
*
|
||||
* gmtime
|
||||
* localtime
|
||||
* ctime
|
||||
* ctime_r
|
||||
* asctime
|
||||
* asctime_r
|
||||
*/
|
||||
|
||||
#endif /* !UNBAN */
|
||||
|
||||
#endif /* !INCLUDE_BANNED_H */
|
33
blkcpy.c
33
blkcpy.c
@@ -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
|
||||
*
|
||||
@@ -29,12 +29,17 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "value.h"
|
||||
#include "file.h"
|
||||
#include "blkcpy.h"
|
||||
#include "str.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* copystod - copy num indexed items from source value to destination value
|
||||
*
|
||||
@@ -294,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;
|
||||
@@ -343,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;
|
||||
@@ -400,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;
|
||||
@@ -443,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;
|
||||
@@ -493,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;
|
||||
@@ -543,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;
|
||||
@@ -658,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;
|
||||
@@ -744,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;
|
||||
@@ -788,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;
|
||||
@@ -909,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;
|
||||
@@ -941,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 */
|
||||
@@ -1011,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;
|
||||
@@ -1082,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;
|
||||
|
50
block.c
50
block.c
@@ -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
|
||||
*
|
||||
@@ -28,6 +28,11 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "have_string.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include "alloc.h"
|
||||
#include "value.h"
|
||||
#include "zmath.h"
|
||||
#include "config.h"
|
||||
@@ -36,6 +41,11 @@
|
||||
#include "str.h"
|
||||
#include "calcerr.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define NBLOCKCHUNK 16
|
||||
|
||||
STATIC long nblockcount = 0;
|
||||
@@ -78,7 +88,7 @@ blkalloc(int len, int chunk)
|
||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||
if (nblk == NULL) {
|
||||
math_error("cannot allocate block");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -89,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;
|
||||
@@ -147,7 +157,7 @@ blk_free(BLOCK *blk)
|
||||
* blk - the BLOCK to check
|
||||
*
|
||||
* returns:
|
||||
* if all is ok, otherwise math_error() is called and this
|
||||
* if all is OK, otherwise math_error() is called and this
|
||||
* function does not return
|
||||
*/
|
||||
S_FUNC void
|
||||
@@ -163,7 +173,7 @@ blkchk(BLOCK *blk)
|
||||
}
|
||||
if (blk == NULL) {
|
||||
math_error("internal: blk ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,7 +181,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->data == NULL) {
|
||||
math_error("internal: blk->data ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -179,7 +189,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,7 +197,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -250,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 */
|
||||
@@ -358,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) {
|
||||
@@ -388,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -402,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;
|
||||
@@ -530,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;
|
||||
@@ -547,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);
|
||||
@@ -584,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;
|
||||
@@ -593,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -601,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;
|
||||
|
118
byteswap.c
118
byteswap.c
@@ -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,14 +29,18 @@
|
||||
#include "byteswap.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* 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
|
||||
@@ -73,7 +77,7 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len)
|
||||
* swap_b8_in_ZVALUE - swap 8 and if needed, 16 bits in a ZVALUE
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a ZVALUE to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -100,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -123,8 +127,8 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap or copy the rest of the ZVALUE elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->len = (LEN)SWAP_B8_IN_LEN(&dest->len, &src->len);
|
||||
dest->sign = (BOOL)SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
|
||||
SWAP_B8_IN_LEN(&dest->len, &src->len);
|
||||
SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
|
||||
} else {
|
||||
dest->len = src->len;
|
||||
dest->sign = src->sign;
|
||||
@@ -141,7 +145,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap_b8_in_NUMBER - swap 8 and if needed, 16 bits in a NUMBER
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a NUMBER to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -167,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -189,7 +193,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||
SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
@@ -205,7 +209,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap_b8_in_COMPLEX - swap 8 and if needed, 16 bits in a COMPLEX
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a COMPLEX to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -231,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,7 +257,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||
SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
@@ -269,10 +273,10 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* swap_b16_in_HALFs - swap 16 bits in an array of HALFs
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* 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
|
||||
@@ -305,11 +309,55 @@ 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
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a ZVALUE to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -335,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -358,8 +406,8 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap or copy the rest of the ZVALUE elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->len = (LEN)SWAP_B16_IN_LEN(&dest->len, &src->len);
|
||||
dest->sign = (BOOL)SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
|
||||
SWAP_B16_IN_LEN(&dest->len, &src->len);
|
||||
SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
|
||||
} else {
|
||||
dest->len = src->len;
|
||||
dest->sign = src->sign;
|
||||
@@ -376,7 +424,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap_b16_in_NUMBER - swap 16 bits in a NUMBER
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a NUMBER to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -402,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -424,7 +472,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||
SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
@@ -440,7 +488,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap_b16_in_COMPLEX - swap 16 bits in a COMPLEX
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a COMPLEX to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -466,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -488,7 +536,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||
SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
@@ -504,7 +552,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* swap_HALF_in_ZVALUE - swap HALFs in a ZVALUE
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a ZVALUE to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -530,7 +578,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
dest = malloc(sizeof(ZVALUE));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_HALF_in_ZVALUE: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -554,8 +602,8 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap or copy the rest of the ZVALUE elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->len = (LEN)SWAP_HALF_IN_LEN(&dest->len, &src->len);
|
||||
dest->sign = (BOOL)SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
|
||||
SWAP_HALF_IN_LEN(&dest->len, &src->len);
|
||||
SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
|
||||
} else {
|
||||
dest->len = src->len;
|
||||
dest->sign = src->sign;
|
||||
@@ -572,7 +620,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* swap_HALF_in_NUMBER - swap HALFs in a NUMBER
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a NUMBER to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -598,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -620,7 +668,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
|
||||
SWAP_HALF_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
@@ -636,7 +684,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* swap_HALF_in_COMPLEX - swap HALFs in a COMPLEX
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src wil be put or
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a COMPLEX to swap
|
||||
* all - TRUE => swap every element, FALSE => swap only the
|
||||
@@ -662,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -684,7 +732,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* swap or copy the rest of the NUMBER elements
|
||||
*/
|
||||
if (all) {
|
||||
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
|
||||
SWAP_HALF_IN_LONG(&dest->links, &src->links);
|
||||
} else {
|
||||
dest->links = src->links;
|
||||
}
|
||||
|
20
byteswap.h
20
byteswap.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* byteswap - byte swapping macros
|
||||
*
|
||||
* Copyright (C) 1999,2014 Landon Curt Noll
|
||||
* Copyright (C) 1999,2014,2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -39,7 +39,7 @@
|
||||
/*
|
||||
* SWAP_B8_IN_B16 - swap 8 bits in 16 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 16 bit value to swap
|
||||
*
|
||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||
@@ -53,7 +53,7 @@
|
||||
/*
|
||||
* SWAP_B16_IN_B32 - swap 16 bits in 32 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 32 bit value to swap
|
||||
*/
|
||||
#define SWAP_B16_IN_B32(dest, src) ( \
|
||||
@@ -64,7 +64,7 @@
|
||||
/*
|
||||
* SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 32 bit value to swap
|
||||
*
|
||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||
@@ -82,7 +82,7 @@
|
||||
/*
|
||||
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*/
|
||||
#define SWAP_B32_IN_B64(dest, src) ( \
|
||||
@@ -93,7 +93,7 @@
|
||||
/*
|
||||
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*/
|
||||
#define SWAP_B16_IN_B64(dest, src) ( \
|
||||
@@ -106,7 +106,7 @@
|
||||
/*
|
||||
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*
|
||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||
@@ -124,7 +124,7 @@
|
||||
/*
|
||||
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values)
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*/
|
||||
#define SWAP_B32_IN_B64(dest, src) ( \
|
||||
@@ -135,7 +135,7 @@
|
||||
/*
|
||||
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*/
|
||||
#define SWAP_B16_IN_B64(dest, src) ( \
|
||||
@@ -146,7 +146,7 @@
|
||||
/*
|
||||
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
||||
*
|
||||
* dest - pointer to where the swapped src wil be put
|
||||
* dest - pointer to where the swapped src will be put
|
||||
* src - pointer to a 64 bit value to swap
|
||||
*
|
||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||
|
173
cal/Makefile
173
cal/Makefile
@@ -2,7 +2,15 @@
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
@@ -27,15 +35,68 @@
|
||||
# calculator by David I. Bell with help/mods from others
|
||||
# Makefile by Landon Curt Noll
|
||||
|
||||
# required vars
|
||||
|
||||
# The shell used by this Makefile
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
# 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 sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/sh
|
||||
#
|
||||
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 */
|
||||
|
||||
|
||||
####
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
####
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
@@ -45,15 +106,6 @@ SHELL= /bin/sh
|
||||
#
|
||||
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:
|
||||
@@ -65,11 +117,11 @@ TOP_MAKE_FILE= Makefile
|
||||
# INCDIR= /usr/include
|
||||
#
|
||||
|
||||
#INCDIR= /usr/local/include
|
||||
#INCDIR= ${PREFIX}/include
|
||||
#INCDIR= /dev/env/DJDIR/include
|
||||
INCDIR= /usr/include
|
||||
|
||||
# where to install calc realted things
|
||||
# where to install calc related things
|
||||
#
|
||||
# ${BINDIR} where to install calc binary files
|
||||
# ${LIBDIR} where calc link library (*.a) files are installed
|
||||
@@ -91,15 +143,15 @@ INCDIR= /usr/include
|
||||
# LIBDIR= /usr/lib
|
||||
# CALC_SHAREDIR= /usr/share/calc
|
||||
#
|
||||
#BINDIR= /usr/local/bin
|
||||
#BINDIR= ${PREFIX}/bin
|
||||
#BINDIR= /dev/env/DJDIR/bin
|
||||
BINDIR= /usr/bin
|
||||
|
||||
#LIBDIR= /usr/local/lib
|
||||
#LIBDIR= ${PREFIX}/lib
|
||||
#LIBDIR= /dev/env/DJDIR/lib
|
||||
LIBDIR= /usr/lib
|
||||
|
||||
#CALC_SHAREDIR= /usr/local/lib/calc
|
||||
#CALC_SHAREDIR= ${PREFIX}/lib/calc
|
||||
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
|
||||
CALC_SHAREDIR= /usr/share/calc
|
||||
|
||||
@@ -157,27 +209,51 @@ T=
|
||||
|
||||
# Makefile debug
|
||||
#
|
||||
# Q=@ do not echo internal makefile actions (quiet mode)
|
||||
# Q= echo internal makefile actions (debug / verbose mode)
|
||||
# Q=@ do not echo internal Makefile actions (quiet mode)
|
||||
# Q= echo internal Makefile actions (debug / verbose mode)
|
||||
#
|
||||
# H=@: do not report hsrc file formation progress
|
||||
# H=@ do echo hsrc file formation progress
|
||||
#
|
||||
# S= >/dev/null 2>&1 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=@
|
||||
|
||||
# standard tools
|
||||
#
|
||||
CHMOD= chmod
|
||||
CMP= cmp
|
||||
RM= rm
|
||||
MKDIR= mkdir
|
||||
RMDIR= rmdir
|
||||
CP= cp
|
||||
MV= mv
|
||||
CO= co
|
||||
TRUE= true
|
||||
TOUCH= touch
|
||||
CP= cp
|
||||
FMT= fmt
|
||||
MKDIR= mkdir
|
||||
MV= mv
|
||||
RM= rm
|
||||
RMDIR= rmdir
|
||||
SED= sed
|
||||
SORT= sort
|
||||
FMT= fmt
|
||||
TOUCH= touch
|
||||
TRUE= true
|
||||
|
||||
# The calc files to install
|
||||
#
|
||||
@@ -187,17 +263,16 @@ FMT= fmt
|
||||
#
|
||||
# make calc_files_list
|
||||
#
|
||||
# to keep this list in nice sorted order and to check that these
|
||||
# detailed help files are under RCS control.
|
||||
# to keep this list in nice sorted order.
|
||||
#
|
||||
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
||||
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
|
||||
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
|
||||
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
|
||||
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal \
|
||||
lucas.cal lucas_chk.cal mersenne.cal mfactor.cal \
|
||||
mod.cal natnumset.cal pell.cal pi.cal pix.cal pollard.cal poly.cal \
|
||||
prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
|
||||
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 \
|
||||
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
|
||||
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
|
||||
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
|
||||
@@ -218,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
|
||||
|
||||
@@ -227,6 +306,8 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
|
||||
${RM} -f .all
|
||||
${TOUCH} .all
|
||||
|
||||
.PHONY: ${PHONY}
|
||||
|
||||
##
|
||||
#
|
||||
# File list generation. You can ignore this section.
|
||||
@@ -261,19 +342,13 @@ calcliblist:
|
||||
#
|
||||
calc_files_list:
|
||||
${Q} -(find . -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
|
||||
while read i; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
if [ ! -f RCS/$$i,v ]; then \
|
||||
echo "WARNING: $$i not under RCS control" 1>&2; \
|
||||
else \
|
||||
echo $$i; \
|
||||
fi; \
|
||||
fi; \
|
||||
done; \
|
||||
echo '--first_line--'; \
|
||||
echo README; \
|
||||
echo set8700.line; \
|
||||
echo bindings) | \
|
||||
while read i; do \
|
||||
echo $$i; \
|
||||
done; \
|
||||
echo '--first_line--'; \
|
||||
echo README; \
|
||||
echo set8700.line; \
|
||||
echo bindings) | \
|
||||
${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
|
||||
${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/ /' \
|
||||
-e 's/$$/ \\/' -e '$$s/ \\$$//'
|
||||
@@ -387,7 +462,7 @@ uninstall:
|
||||
continue; \
|
||||
fi; \
|
||||
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
||||
${RM} -f "${T}${CALC_SHAREDIR}/$$i"; \
|
||||
${RM} -f "${T}${CALC_SHAREDIR}/$$i"; \
|
||||
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
||||
echo "cannot uninstall ${T}${CALC_SHAREDIR}/$$i"; \
|
||||
else \
|
||||
|
98
cal/README
98
cal/README
@@ -186,7 +186,7 @@ bernoulli.cal
|
||||
Calculate the nth Bernoulli number.
|
||||
|
||||
NOTE: There is now a bernoulli() builtin function. This file is
|
||||
left here for backward compatibility and now simply returns
|
||||
left here for backward compatibility and now simply returns
|
||||
the builtin function.
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -767,7 +825,7 @@ lucas.cal
|
||||
prove that h*2^n-1 is prime or not prime.
|
||||
|
||||
NOTE: Some call this term u(0). The function gen_u0(h, n, v1)
|
||||
simply calls gen_u2(h, n, v1) for such people. :-)
|
||||
simply calls gen_u2(h, n, v1) for such people. :-)
|
||||
|
||||
gen_v1(h, v)
|
||||
|
||||
@@ -879,6 +937,38 @@ natnumset.cal
|
||||
user-specified bound.
|
||||
|
||||
|
||||
palindrome.cal
|
||||
|
||||
digitof(val,place)
|
||||
copalplace(d,place)
|
||||
upperhalf(val)
|
||||
mkpal(val)
|
||||
mkpalmiddigit(val,digit)
|
||||
ispal(val)
|
||||
nextpal(val)
|
||||
prevpal(val)
|
||||
nextprimepal(val)
|
||||
prevprimepal(val)
|
||||
|
||||
Functions to form and manipulate palindromes in base 10.
|
||||
|
||||
Important functions are:
|
||||
|
||||
Find the next / previous palindrome:
|
||||
|
||||
nextpal(val)
|
||||
prevpal(val)
|
||||
|
||||
Test if a value is a palindrome:
|
||||
|
||||
ispal(val)
|
||||
|
||||
Find the next / previous palindrome that is a (highly probable) prime:
|
||||
|
||||
nextprimepal(val)
|
||||
prevprimepal(val)
|
||||
|
||||
|
||||
pell.cal
|
||||
|
||||
pellx(D)
|
||||
@@ -900,7 +990,7 @@ pi.cal
|
||||
as your free memory space and system up time allows.
|
||||
|
||||
The piforever() function (written by Klaus Alexander Seistrup
|
||||
<klaus@seistrup.dk>) was inspired by an algorithm conceived by
|
||||
<klaus at seistrup dot dk>) was inspired by an algorithm conceived by
|
||||
Lambert Meertens. See also the ABC Programmer's Handbook, by Geurts,
|
||||
Meertens & Pemberton, published by Prentice-Hall (UK) Ltd., 1990.
|
||||
|
||||
@@ -1435,7 +1525,7 @@ sumtimes.cal
|
||||
the list or matrix to use. The doalltimes() function will run
|
||||
all of the sumtimes tests. For example:
|
||||
|
||||
doalltimes(1e6);
|
||||
doalltimes(1e6);
|
||||
|
||||
|
||||
surd.cal
|
||||
|
@@ -474,7 +474,7 @@ define best_mul2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing multiply alg1/alg2 ratio for len = %d\n", mid);
|
||||
@@ -497,7 +497,7 @@ define best_mul2()
|
||||
low = mid;
|
||||
high = mid;
|
||||
if (config("user_debug") > 0) {
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -505,7 +505,7 @@ define best_mul2()
|
||||
/* bump lower range up if we went over */
|
||||
if (ratio > 1.0) {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
low, mid);
|
||||
}
|
||||
low = mid;
|
||||
@@ -513,7 +513,7 @@ define best_mul2()
|
||||
/* drop higher range down if we went under */
|
||||
} else {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
high, mid);
|
||||
}
|
||||
high = mid;
|
||||
@@ -522,7 +522,7 @@ define best_mul2()
|
||||
/* report on test loop progress */
|
||||
if (config("user_debug") > 1) {
|
||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||
low, high, high-low);
|
||||
low, high, high-low);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,7 +884,7 @@ define best_sq2()
|
||||
high *= expand;
|
||||
if (config("user_debug") > 1) {
|
||||
printf(" expand the next test range by a factor of %d\n",
|
||||
expand);
|
||||
expand);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -956,7 +956,7 @@ define best_sq2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing square alg1/alg2 ratio for len = %d\n", mid);
|
||||
@@ -979,7 +979,7 @@ define best_sq2()
|
||||
low = mid;
|
||||
high = mid;
|
||||
if (config("user_debug") > 0) {
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -987,7 +987,7 @@ define best_sq2()
|
||||
/* bump lower range up if we went over */
|
||||
if (ratio > 1.0) {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
low, mid);
|
||||
}
|
||||
low = mid;
|
||||
@@ -995,7 +995,7 @@ define best_sq2()
|
||||
/* drop higher range down if we went under */
|
||||
} else {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
high, mid);
|
||||
}
|
||||
high = mid;
|
||||
@@ -1004,7 +1004,7 @@ define best_sq2()
|
||||
/* report on test loop progress */
|
||||
if (config("user_debug") > 1) {
|
||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||
low, high, high-low);
|
||||
low, high, high-low);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1385,7 +1385,7 @@ define best_pow2()
|
||||
printf(" pmod alg1/alg2 ratio = %.3f\n", ratio);
|
||||
if (ratio > 1.0 && ratio <= 1.02) {
|
||||
printf(" while alg1 is slightly better than alg2, "
|
||||
"it is not clearly better\n");
|
||||
"it is not clearly better\n");
|
||||
}
|
||||
}
|
||||
} while (ratio <= 1.02);
|
||||
@@ -1420,7 +1420,7 @@ define best_pow2()
|
||||
high *= expand;
|
||||
if (config("user_debug") > 1) {
|
||||
printf(" expand the next test range by a factor of %d\n",
|
||||
expand);
|
||||
expand);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1455,7 +1455,7 @@ define best_pow2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid);
|
||||
@@ -1478,7 +1478,7 @@ define best_pow2()
|
||||
low = mid;
|
||||
high = mid;
|
||||
if (config("user_debug") > 0) {
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1486,7 +1486,7 @@ define best_pow2()
|
||||
/* bump lower range up if we went over */
|
||||
if (ratio > 1.0) {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
printf("\tmove low from %d up to %d\n",
|
||||
low, mid);
|
||||
}
|
||||
low = mid;
|
||||
@@ -1494,7 +1494,7 @@ define best_pow2()
|
||||
/* drop higher range down if we went under */
|
||||
} else {
|
||||
if (config("user_debug") > 2) {
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
printf("\tmove high from %d down to %d\n",
|
||||
high, mid);
|
||||
}
|
||||
high = mid;
|
||||
@@ -1503,7 +1503,7 @@ define best_pow2()
|
||||
/* report on test loop progress */
|
||||
if (config("user_debug") > 1) {
|
||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||
low, high, high-low);
|
||||
low, high, high-low);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ define Z(x, eps_term)
|
||||
|
||||
/* obtain the error term */
|
||||
if (isnull(eps_term)) {
|
||||
eps = epsilon();
|
||||
eps = epsilon();
|
||||
} else {
|
||||
eps = eps_term;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ define P(x, eps_term)
|
||||
|
||||
/* obtain the error term */
|
||||
if (isnull(eps_term)) {
|
||||
eps = epsilon();
|
||||
eps = epsilon();
|
||||
} else {
|
||||
eps = eps_term;
|
||||
}
|
||||
|
437
cal/comma.cal
Normal file
437
cal/comma.cal
Normal 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;
|
||||
}
|
22
cal/dms.cal
22
cal/dms.cal
@@ -188,7 +188,7 @@ define dms_abs(a)
|
||||
|
||||
/* firewall - just absolute value non dms objects */
|
||||
if (! istype(a, ans)) {
|
||||
return abs(a);
|
||||
return abs(a);
|
||||
}
|
||||
|
||||
/* compute degrees */
|
||||
@@ -352,24 +352,8 @@ define fixdms(a)
|
||||
quit "attempt to fix a non dms object";
|
||||
}
|
||||
|
||||
/* force minutes to be integral */
|
||||
a.min += frac(a.deg) * 60;
|
||||
a.deg = int(a.deg);
|
||||
|
||||
/* force degrees to be integral */
|
||||
a.sec += frac(a.min) * 60;
|
||||
a.min = int(a.min);
|
||||
|
||||
/* carry excess seconds into minutes */
|
||||
a.min += a.sec // 60;
|
||||
a.sec %= 60;
|
||||
|
||||
/* carry excess minutes into degrees */
|
||||
a.deg += a.min // 60;
|
||||
a.min %= 60;
|
||||
|
||||
/* round degrees :-) */
|
||||
a.deg %= 360;
|
||||
/* use builtin d2dms function */
|
||||
d2dms(a.deg + a.min/60 + a.sec/3600, a.deg, a.min, a.sec),;
|
||||
|
||||
/* return normalized result */
|
||||
return a;
|
||||
|
@@ -157,7 +157,7 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
|
||||
* test the close of the line file
|
||||
*/
|
||||
printf("%d-: detected %d error condition(s), many of which may be OK\n",
|
||||
dotest_code, dotest_old_errcount-dotest_errcnt);
|
||||
dotest_code, dotest_old_errcount-dotest_errcnt);
|
||||
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
|
||||
fclose(dotest_f_file);
|
||||
|
||||
|
@@ -56,7 +56,7 @@ define __CZ__factor_factorial(n,start){
|
||||
if(start){
|
||||
if(!isint(start) && start < 0 && start > n)
|
||||
return newerror("__CZ__factor_factorial(n,start): value of "
|
||||
"parameter 'start' out of range");
|
||||
"parameter 'start' out of range");
|
||||
if(start == n && isprime(n)){
|
||||
prime_list = mat[1 , 2];
|
||||
prime_list[0,0] = n;
|
||||
@@ -64,7 +64,7 @@ define __CZ__factor_factorial(n,start){
|
||||
}
|
||||
else if(!isprime(start) && nextprime(start) >n)
|
||||
return newerror("__CZ__factor_factorial(n,start): value of parameter "
|
||||
"'start' out of range");
|
||||
"'start' out of range");
|
||||
else{
|
||||
if(!isprime(start)) prime = nextprime(start);
|
||||
else prime = start;
|
||||
@@ -225,11 +225,11 @@ define __CZ__multiply_factored_factorial(matrix,stop){
|
||||
|
||||
if(!ismat(matrix))
|
||||
return newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||
"argument matrix not a matrix ");
|
||||
"argument matrix not a matrix ");
|
||||
if(!matrix[0,0])
|
||||
return
|
||||
newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||
"matrix[0,0] is null/0");
|
||||
"matrix[0,0] is null/0");
|
||||
|
||||
if(!isnull(stop))
|
||||
pix = stop;
|
||||
@@ -376,7 +376,7 @@ define bigcatalan(n){
|
||||
|
||||
/*
|
||||
df(-111) = -1/3472059605858239446587523014902616804783337112829102414124928
|
||||
7753332469144201839599609375
|
||||
7753332469144201839599609375
|
||||
|
||||
df(-3+1i) = 0.12532538977287649201-0.0502372106177184607i
|
||||
df(2n + 1) = (2*n)!/(n!*2^n)
|
||||
@@ -427,7 +427,7 @@ define doublefactorial(n){
|
||||
*/
|
||||
eps=epsilon(epsilon()*1e-2);
|
||||
ret = 2^(n/2-1/4 * cos(pi()* n)+1/4) * pi()^(1/4 *
|
||||
cos(pi()* n)-1/4)* gamma(n/2+1);
|
||||
cos(pi()* n)-1/4)* gamma(n/2+1);
|
||||
epsilon(eps);
|
||||
return ret;
|
||||
}
|
||||
|
22
cal/hms.cal
22
cal/hms.cal
@@ -188,7 +188,7 @@ define hms_abs(a)
|
||||
|
||||
/* firewall - just absolute value non hms objects */
|
||||
if (! istype(a, ans)) {
|
||||
return abs(a);
|
||||
return abs(a);
|
||||
}
|
||||
|
||||
/* compute hours */
|
||||
@@ -352,24 +352,8 @@ define fixhms(a)
|
||||
quit "attempt to fix a non hms object";
|
||||
}
|
||||
|
||||
/* force minutes to be integral */
|
||||
a.min += frac(a.hour) * 60;
|
||||
a.hour = int(a.hour);
|
||||
|
||||
/* force hours to be integral */
|
||||
a.sec += frac(a.min) * 60;
|
||||
a.min = int(a.min);
|
||||
|
||||
/* carry excess seconds into minutes */
|
||||
a.min += a.sec // 60;
|
||||
a.sec %= 60;
|
||||
|
||||
/* carry excess minutes into hours */
|
||||
a.hour += a.min // 60;
|
||||
a.min %= 60;
|
||||
|
||||
/* round hours by day */
|
||||
a.hour %= 24;
|
||||
/* use builtin h2hms function */
|
||||
h2hms(a.hour + a.min/60 + a.sec/3600, a.hour, a.min, a.sec),;
|
||||
|
||||
/* return normalized result */
|
||||
return a;
|
||||
|
@@ -156,7 +156,7 @@ define be2file(v, filename)
|
||||
*/
|
||||
octlen = int((highbit(v)+8) / 8);
|
||||
for (i=octlen-1; i >= 0; --i) {
|
||||
fputc(fd, char(v >> (i*8)));
|
||||
fputc(fd, char(v >> (i*8)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -731,7 +731,7 @@ rodseth_xhn(x, h, n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1
|
||||
*/
|
||||
testval = h*2^n-1;
|
||||
@@ -739,7 +739,7 @@ rodseth_xhn(x, h, n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2
|
||||
*/
|
||||
if (jacobi(x+2, testval) != -1) {
|
||||
|
641
cal/palindrome.cal
Normal file
641
cal/palindrome.cal
Normal file
@@ -0,0 +1,641 @@
|
||||
/*
|
||||
* palindrome - palindrome utilities
|
||||
*
|
||||
* 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/11/06 14:35:37
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* digitof - return the a digit of a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val value to find a digit of
|
||||
* place digit place
|
||||
*
|
||||
* returns:
|
||||
* value (>= 0 and < 10) that is the place-th digit of val
|
||||
* or 0 if place is not a digit of val
|
||||
*/
|
||||
define digitof(val, place)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* firewall - return 0 if digit place doesn't exist */
|
||||
if (place < 1 || place > d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return the place-th digit of val as a single digit */
|
||||
return (val // (10^(place-1))) % 10;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* copalplace - determine the other place in a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* d digits of a value
|
||||
* place digit place
|
||||
*
|
||||
* returns:
|
||||
* given palindrome val, the other digit paired with place
|
||||
* or 0 if place is not a digit of val
|
||||
*/
|
||||
define copalplace(d, place)
|
||||
{
|
||||
/* firewall - return 0 if digit place doesn't exist */
|
||||
if (d < 1 || place < 1 || place > d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return digit coplace */
|
||||
return d+1 - place;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upperhalf - return the upper half of a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* NOTE: When the value has an odd number of digits, the upper half
|
||||
* includes the middle digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* the upper half digits of a value
|
||||
*/
|
||||
define upperhalf(val)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local halfd; /* length of upper hand of val */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
halfd = d // 2;
|
||||
|
||||
/* return upper half */
|
||||
return (val // 10^halfd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mkpal - make a value into a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* val as a palindrome with lower half being reverse digits of val
|
||||
*/
|
||||
define mkpal(val)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local i; /* counter */
|
||||
local ret; /* palindrome being formed */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* insert digits in reverse order at the bottom */
|
||||
ret = val;
|
||||
for (i=0; i < d; ++i) {
|
||||
ret = ret*10 + digit(val, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mkpalmiddigit - make a value into a palindrome with a middle digit
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
* digit the digit to put into the middle of the palindrome
|
||||
*
|
||||
* returns:
|
||||
* val as a palindrome with lower half being reverse digits of val
|
||||
* and digit as a middle digit
|
||||
*/
|
||||
define mkpalmiddigit(val, digit)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local i; /* counter */
|
||||
local ret; /* palindrome being formed */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* insert digits in reverse order at the bottom */
|
||||
ret = val*10 + digit;
|
||||
for (i=0; i < d; ++i) {
|
||||
ret = ret*10 + digit(val, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ispal - determine if a value is a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* 1 ==> val is a palindrome
|
||||
* 0 ==> val is NOT a palindrome
|
||||
*/
|
||||
define ispal(val)
|
||||
{
|
||||
local half; /* upper half of digits of val */
|
||||
local digit; /* middle digit */
|
||||
|
||||
/* case: val has an even number of digits */
|
||||
if (iseven(digits(val))) {
|
||||
|
||||
/* test palindrome-ness */
|
||||
return (val == mkpal(upperhalf(val)));
|
||||
|
||||
/* case: val can an odd number of digits */
|
||||
} else {
|
||||
|
||||
/* test palindrome-ness */
|
||||
half = upperhalf(val);
|
||||
digit = half % 10;
|
||||
half //= 10;
|
||||
return (val == mkpalmiddigit(half, digit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* palnextpal - return next palindrome from a known palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* pal a palindrome
|
||||
*
|
||||
* returns:
|
||||
* next palindrome > pal
|
||||
*/
|
||||
define palnextpal(pal)
|
||||
{
|
||||
local paldigits; /* digits in pal */
|
||||
local half; /* upper half of newval */
|
||||
local newhalf; /* half+1 */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative palindrome */
|
||||
if (pal < 0) {
|
||||
return -(palprevpal(-pal));
|
||||
}
|
||||
|
||||
/*
|
||||
* start with upper half
|
||||
*/
|
||||
half = upperhalf(pal);
|
||||
|
||||
/*
|
||||
* prep to find a larger palindrome
|
||||
*/
|
||||
newhalf = half+1;
|
||||
|
||||
/*
|
||||
* form palindrome from new upper half
|
||||
*
|
||||
* We need to watch for the corner case where changing the
|
||||
* half changes the number of digits as this will impact
|
||||
* or even/odd number of digits processing.
|
||||
*/
|
||||
paldigits = digits(pal);
|
||||
if (digits(newhalf) == digits(half)) {
|
||||
/* no change in half digits: process as normal */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpal(newhalf);
|
||||
} else {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
}
|
||||
} else {
|
||||
/* change in half digits: process as opposite */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
} else {
|
||||
newpal = mkpal(newhalf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nextpal - return next palindrome from a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* next palindrome > val
|
||||
*/
|
||||
define nextpal(val)
|
||||
{
|
||||
local newval; /* val+1 */
|
||||
local newvaldigits; /* digits in newval */
|
||||
local half; /* upper half of newval */
|
||||
local pal; /* palindrome test value */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (val < 0) {
|
||||
return -(prevpal(-val));
|
||||
}
|
||||
|
||||
/*
|
||||
* start looking from a larger value
|
||||
*/
|
||||
newval = val+1;
|
||||
newvaldigits = digits(newval);
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (newvaldigits < 2) {
|
||||
return newval;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with next upper half
|
||||
*/
|
||||
half = upperhalf(newval);
|
||||
|
||||
/*
|
||||
* form palindrome from upper half
|
||||
*
|
||||
* We need to deal with even vs. odd digit counts
|
||||
* when forming a palindrome from a half as the
|
||||
* half may not or may include the middle digit.
|
||||
*/
|
||||
if (iseven(newvaldigits)) {
|
||||
pal = mkpal(half);
|
||||
} else {
|
||||
pal = mkpalmiddigit(half // 10, half % 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* case: we found a larger palindrome, we are done
|
||||
*/
|
||||
if (pal > val) {
|
||||
return pal;
|
||||
}
|
||||
|
||||
/*
|
||||
* we need to find an even larger palindrome
|
||||
*/
|
||||
newpal = palnextpal(pal);
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* palprevpal - return previous palindrome from a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* pal a palindrome
|
||||
*
|
||||
* returns:
|
||||
* previous palindrome < pal
|
||||
*/
|
||||
define palprevpal(pal)
|
||||
{
|
||||
local paldigits; /* digits in pal */
|
||||
local half; /* upper half of newval */
|
||||
local newhalf; /* half+1 */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (pal < 0) {
|
||||
return -(palnextpal(-pal));
|
||||
}
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (pal < 10) {
|
||||
newpal = pal-1;
|
||||
return newpal;
|
||||
}
|
||||
|
||||
/* case: 10 or 11 */
|
||||
if (pal < 12) {
|
||||
newpal = 9;
|
||||
return newpal;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with upper half
|
||||
*/
|
||||
half = upperhalf(pal);
|
||||
|
||||
/*
|
||||
* prep to find a smaller palindrome
|
||||
*/
|
||||
newhalf = half-1;
|
||||
|
||||
/*
|
||||
* form palindrome from new upper half
|
||||
*
|
||||
* We need to watch for the corner case where changing the
|
||||
* half changes the number of digits as this will impact
|
||||
* or even/odd number of digits processing.
|
||||
*/
|
||||
paldigits = digits(pal);
|
||||
if (digits(newhalf) == digits(half)) {
|
||||
/* no change in half digits: process as normal */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpal(newhalf);
|
||||
} else {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
}
|
||||
} else {
|
||||
/* change in half digits: process as opposite */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
} else {
|
||||
newpal = mkpal(newhalf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* prevpal - return previous palindrome from a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* previous palindrome < val
|
||||
*/
|
||||
define prevpal(val)
|
||||
{
|
||||
local newval; /* val-1 */
|
||||
local newvaldigits; /* digits in newval */
|
||||
local half; /* upper half of newval */
|
||||
local pal; /* palindrome test value */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (val < 0) {
|
||||
return -(nextpal(-val));
|
||||
}
|
||||
|
||||
/*
|
||||
* start looking from a smaller value
|
||||
*/
|
||||
newval = val-1;
|
||||
newvaldigits = digits(newval);
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (newvaldigits < 2) {
|
||||
return newval;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with previous upper half
|
||||
*/
|
||||
half = upperhalf(newval);
|
||||
|
||||
/*
|
||||
* form palindrome from upper half
|
||||
*
|
||||
* We need to deal with even vs. odd digit counts
|
||||
* when forming a palindrome from a half as the
|
||||
* half may not or may include the middle digit.
|
||||
*/
|
||||
if (iseven(newvaldigits)) {
|
||||
pal = mkpal(half);
|
||||
} else {
|
||||
pal = mkpalmiddigit(half // 10, half % 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* case: we found a smaller palindrome, we are done
|
||||
*/
|
||||
if (pal < val) {
|
||||
return pal;
|
||||
}
|
||||
|
||||
/*
|
||||
* we need to find an even smaller palindrome
|
||||
*/
|
||||
newpal = palprevpal(pal);
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nextprimepal - return next palindrome that is a (highly probable) prime
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* next palindrome (highly probable) prime > val
|
||||
*/
|
||||
define nextprimepal(val)
|
||||
{
|
||||
local pal; /* palindrome test value */
|
||||
local dpal; /* digits in pal */
|
||||
|
||||
/*
|
||||
* pre-start under the next palindrome
|
||||
*/
|
||||
pal = nextpal(val-1);
|
||||
|
||||
/*
|
||||
* loop until we find a (highly probable) prime or 0
|
||||
*/
|
||||
do {
|
||||
|
||||
/* case: negative values and tiny values */
|
||||
if (pal < 2) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* compute the next palindrome
|
||||
*/
|
||||
pal = palnextpal(pal);
|
||||
dpal = digits(pal);
|
||||
|
||||
/* case: 11 is the only prime palindrome with even digit count */
|
||||
if (pal == 11) {
|
||||
return 11;
|
||||
}
|
||||
|
||||
/* case: even number of digits and not 11 */
|
||||
if (iseven(dpal)) {
|
||||
|
||||
/*
|
||||
* Except for 11 (which is handled above already), there are
|
||||
* no prime palindrome with even digits. So we need to
|
||||
* increase the digit count and work with that larger palindrome.
|
||||
*/
|
||||
pal = nextpal(10^dpal);
|
||||
}
|
||||
|
||||
/* case: palindrome is even or ends in 5 */
|
||||
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||
|
||||
/*
|
||||
* we need to increase the bottom and top digits
|
||||
* so that we have a chance to be prime
|
||||
*/
|
||||
pal += (1 + 10^(dpal-1));
|
||||
}
|
||||
if (config("resource_debug") & 0x8) {
|
||||
print "DEBUG: nextprimepal:", pal;
|
||||
}
|
||||
} while (ptest(pal) == 0 && pal > 0);
|
||||
|
||||
/* return palindrome that his (highly probable) prime or 0 */
|
||||
return pal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* prevprimepal - return prev palindrome that is a (highly probable) prime
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* prev palindrome (highly probable) prime < val or 0
|
||||
*/
|
||||
define prevprimepal(val)
|
||||
{
|
||||
local pal; /* palindrome test value */
|
||||
local dpal; /* digits in pal */
|
||||
|
||||
/*
|
||||
* pre-start over the previous palindrome
|
||||
*/
|
||||
pal = prevpal(val+1);
|
||||
|
||||
/*
|
||||
* loop until we find a (highly probable) prime or 0
|
||||
*/
|
||||
do {
|
||||
|
||||
/*
|
||||
* case: single digit values are always palindromes
|
||||
*/
|
||||
if (val < 10) {
|
||||
/*
|
||||
* The prevcand() call will return 0 if there is no previous prime
|
||||
* such as the case when val < 2.
|
||||
*/
|
||||
return prevcand(pal);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute the previous palindrome
|
||||
*/
|
||||
pal = palprevpal(pal);
|
||||
dpal = digits(pal);
|
||||
|
||||
/* case: 11 is the only prime palindrome with even digit count */
|
||||
if (pal == 11) {
|
||||
return 11;
|
||||
}
|
||||
|
||||
/* case: 2 digit palindrome and not 11 */
|
||||
if (dpal == 2) {
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* case: even number of digits */
|
||||
if (iseven(dpal)) {
|
||||
|
||||
/*
|
||||
* Except for 11 (which is handled above already), there are
|
||||
* no prime palindrome with even digits. So we need to
|
||||
* decrease the digit count and work with that smaller palindrome.
|
||||
*/
|
||||
pal = prevpal(10^(dpal-1));
|
||||
}
|
||||
|
||||
/* case: palindrome is even or ends in 5 */
|
||||
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||
|
||||
/*
|
||||
* we need to decrease the bottom and top digits
|
||||
* so that we have a chance to be prime
|
||||
*/
|
||||
pal -= (1 + 10^(dpal-1));
|
||||
}
|
||||
if (config("resource_debug") & 0x8) {
|
||||
print "DEBUG: prevprimepal:", pal;
|
||||
}
|
||||
} while (ptest(pal) == 0 && pal > 0);
|
||||
|
||||
/* return palindrome that his (highly probable) prime or 0 */
|
||||
return pal;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* pi - various routines to calculate pi
|
||||
*
|
||||
* Copyright (C) 1999-2004 David I. Bell
|
||||
* Copyright (C) 1999-2004,2021 David I. Bell
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -74,7 +74,7 @@ define qpi(epsilon)
|
||||
/*
|
||||
* Print digits of PI forever, neatly formatted, using calc.
|
||||
*
|
||||
* Written by Klaus Alexander Seistrup <klaus@seistrup.dk>
|
||||
* Written by Klaus Alexander Seistrup <klaus at seistrup dot dk>
|
||||
* on a dull Friday evening in November 1999.
|
||||
*
|
||||
* Inspired by an algorithm conceived by Lambert Meertens.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* qtime - Display time as English sentence
|
||||
*
|
||||
* Copyright (C) 1999 Klaus Alexander Seistrup and Landon Curt Noll
|
||||
* Copyright (C) 1999,2021 Klaus Alexander Seistrup and Landon Curt Noll
|
||||
*
|
||||
* Written by: Klaus Alexander Seistrup <kseis@magnetic-ink.dk>
|
||||
* Written by: Klaus Alexander Seistrup <kseis at magnetic-ink dot dk>
|
||||
* With mods by: Landon Curt Noll <http://www.isthe.com/chongo/>
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
|
764
cal/regress.cal
764
cal/regress.cal
@@ -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()';
|
||||
|
||||
@@ -775,7 +787,9 @@ print '016: parsed test_bignums()';
|
||||
/*
|
||||
* Test many of the built-in functions.
|
||||
*
|
||||
* See test_functionss() starting at test 9000 for more built-in function tests.
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions()
|
||||
{
|
||||
@@ -1718,7 +1732,7 @@ define test_rand()
|
||||
print '1503: state0 = srand(0)';
|
||||
vrfy(state0 == init, '1504: state0 == init');
|
||||
|
||||
/* test the additive 55 shuffle generator */
|
||||
/* test the subtractive 100 shuffle generator */
|
||||
tmp = srand(0);
|
||||
print '1505: tmp = srand(0)';
|
||||
vrfy(rand() == 0x1fe5b46fba7e069d, \
|
||||
@@ -1881,96 +1895,298 @@ define test_mode()
|
||||
vrfy(tmp == "octal", '1620: tmp == "octal"');
|
||||
vrfy(base() == 2, '1621: base() == 2');
|
||||
|
||||
tmp = config("mode", "real");
|
||||
print '1622: tmp = config("mode", "real")';
|
||||
tmp = config("mode", "eng");
|
||||
print '1622: tmp = config("mode", "eng")';
|
||||
vrfy(tmp == "binary", '1623: tmp == "binary"');
|
||||
vrfy(base() == 1000, '1624: base() == 1000');
|
||||
|
||||
tmp = config("mode", "real");
|
||||
print '1625: tmp = config("mode", "real")';
|
||||
vrfy(tmp == "engineering", '1626: tmp == "engineering"');
|
||||
|
||||
tmp = base(1/3);
|
||||
print '1624: tmp = base(1/3)';
|
||||
print '1627: tmp = base(1/3)';
|
||||
vrfy(config("mode") == "fraction",
|
||||
'1625: config("mode") == "fraction"');
|
||||
'1628: config("mode") == "fraction"');
|
||||
|
||||
tmp = base(-10);
|
||||
print '1626: tmp = base(-10)';
|
||||
print '1629: tmp = base(-10)';
|
||||
vrfy(config("mode") == "integer",
|
||||
'1627: config("mode") == "integer"');
|
||||
'1630: config("mode") == "integer"');
|
||||
|
||||
tmp = base(10);
|
||||
print '1628: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", '1629: config("mode") == "real"');
|
||||
print '1631: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", '1632: config("mode") == "real"');
|
||||
|
||||
tmp = base(1e20);
|
||||
print '1630: tmp = base(1e20)';
|
||||
print '1633: tmp = base(1e20)';
|
||||
vrfy(config("mode") == "scientific",
|
||||
'1631: config("mode") == "scientific"');
|
||||
'1634: config("mode") == "scientific"');
|
||||
|
||||
tmp = base(16);
|
||||
print '1632: tmp = base(16)';
|
||||
print '1635: tmp = base(16)';
|
||||
vrfy(config("mode") == "hexadecimal", \
|
||||
'1633: config("mode") == "hexadecimal"');
|
||||
'1636: config("mode") == "hexadecimal"');
|
||||
|
||||
tmp = base(8);
|
||||
print '1634: tmp = base(8)';
|
||||
vrfy(config("mode") == "octal", '1635: config("mode") == "octal"');
|
||||
print '1637: tmp = base(8)';
|
||||
vrfy(config("mode") == "octal", '1638: config("mode") == "octal"');
|
||||
|
||||
tmp = base(2);
|
||||
print '1636: tmp = base(2)';
|
||||
vrfy(config("mode") == "binary",'1637: config("mode") == "binary"');
|
||||
print '1639: tmp = base(2)';
|
||||
vrfy(config("mode") == "binary",'1640: config("mode") == "binary"');
|
||||
|
||||
tmp = base(1000);
|
||||
print '1641: tmp = base(1000)';
|
||||
vrfy(config("mode") == "engineering",
|
||||
'1642: config("mode") == "engineering"');
|
||||
|
||||
tmp = base(1/3);
|
||||
print '1643: tmp = base(1/3)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1644: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1645: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1646: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1647: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1648: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1649: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1650: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1651: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1652: str(7543) == \"7543"');
|
||||
|
||||
tmp = base(8);
|
||||
print '1638: tmp = base(8)';
|
||||
print '1653: tmp = base(8)';
|
||||
vrfy(str(0x80000000) == "020000000000", \
|
||||
'1639: str(0x8000000) == \"020000000000\"');
|
||||
'1654: str(0x8000000) == \"020000000000\"');
|
||||
vrfy(str(0xffffffff) == "037777777777", \
|
||||
'1640: str(0xffffffff) == \"037777777777\"');
|
||||
'1655: str(0xffffffff) == \"037777777777\"');
|
||||
vrfy(str(3e9) == "026264057000", \
|
||||
'1641: str(3e9) == \"026264057000\"');
|
||||
'1656: str(3e9) == \"026264057000\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1657: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "01372741000", \
|
||||
'1658: str(2e8) == \"01372741000"');
|
||||
vrfy(str(200e6) == "01372741000", \
|
||||
'1659: str(200e6) == \"01372741000"');
|
||||
vrfy(str(0b100111) == "047", \
|
||||
'1660: str(0b100111) == \"047"');
|
||||
vrfy(str(07543) == "07543", \
|
||||
'1661: str(07543) == \"07543"');
|
||||
vrfy(str(7543) == "016567", \
|
||||
'1662: str(7543) == \"016567"');
|
||||
|
||||
tmp = base(16);
|
||||
print '1642: tmp = base(16)';
|
||||
print '1663: tmp = base(16)';
|
||||
vrfy(str(0x80000000) == "0x80000000", \
|
||||
'1643: str(0x8000000) == \"0x80000000\"');
|
||||
'1664: str(0x8000000) == \"0x80000000\"');
|
||||
vrfy(str(0xffffffff) == "0xffffffff", \
|
||||
'1644: str(0xffffffff) == \"0xffffffff\"');
|
||||
'1665: str(0xffffffff) == \"0xffffffff\"');
|
||||
vrfy(str(3e9) == "0xb2d05e00", \
|
||||
'1645: str(3e9) == \"0xb2d05e00\"');
|
||||
'1666: str(3e9) == \"0xb2d05e00\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1667: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "0xbebc200", \
|
||||
'1668: str(2e8) == \"0xbebc200"');
|
||||
vrfy(str(200e6) == "0xbebc200", \
|
||||
'1669: str(200e6) == \"0xbebc200"');
|
||||
vrfy(str(0b100111) == "0x27", \
|
||||
'1670: str(0b100111) == \"0x27"');
|
||||
vrfy(str(07543) == "0xf63", \
|
||||
'1671: str(07543) == \"0xf63"');
|
||||
vrfy(str(7543) == "0x1d77", \
|
||||
'1672: str(7543) == \"0x1d77"');
|
||||
|
||||
tmp = base(2);
|
||||
print '1673: tmp = base(2)';
|
||||
vrfy(str(0x80000000) == "0b10000000000000000000000000000000", \
|
||||
'1674: str(0x8000000) == \"0b10000000000000000000000000000000\"');
|
||||
vrfy(str(0xffffffff) == "0b11111111111111111111111111111111", \
|
||||
'1675: str(0xffffffff) == \"0b11111111111111111111111111111111\"');
|
||||
vrfy(str(3e9) == "0b10110010110100000101111000000000", \
|
||||
'1676: str(3e9) == \"0b10110010110100000101111000000000\"');
|
||||
vrfy(str(1/3) == "1/0b11", \
|
||||
'1677: str(1/3) == \"1/0b11\"');
|
||||
vrfy(str(2e8) == "0b1011111010111100001000000000", \
|
||||
'1678: str(2e8) == \"0b1011111010111100001000000000"');
|
||||
vrfy(str(200e6) == "0b1011111010111100001000000000", \
|
||||
'1679: str(200e6) == \"0b1011111010111100001000000000"');
|
||||
vrfy(str(0b100111) == "0b100111", \
|
||||
'1680: str(0b100111) == \"0b100111"');
|
||||
vrfy(str(07543) == "0b111101100011", \
|
||||
'1681: str(07543) == \"0b111101100011"');
|
||||
vrfy(str(7543) == "0b1110101110111", \
|
||||
'1682: str(7543) == \"0b1110101110111"');
|
||||
|
||||
tmp = base(1e20);
|
||||
print '1683: tmp = base(1e20)';
|
||||
vrfy(str(0x80000000) == "2.147483648e9", \
|
||||
'1684: str(0x8000000) == \"2.147483648e9\"');
|
||||
vrfy(str(0xffffffff) == "4.294967295e9", \
|
||||
'1685: str(0xffffffff) == \"4.294967295e9\"');
|
||||
vrfy(str(3e9) == "3e9", \
|
||||
'1686: str(3e9) == \"3e9\"');
|
||||
vrfy(str(1/3) == "~3.33333333333333333333e-1", \
|
||||
'1687: str(1/3) == \"~3.33333333333333333333e-1\"');
|
||||
vrfy(str(2e8) == "2e8", \
|
||||
'1688: str(2e8) == \"2e8"');
|
||||
vrfy(str(200e6) == "2e8", \
|
||||
'1689: str(200e6) == \"2e8"');
|
||||
vrfy(str(0b100111) == "3.9e1", \
|
||||
'1690: str(0b100111) == \"3.9e1"');
|
||||
vrfy(str(07543) == "3.939e3", \
|
||||
'1691: str(07543) == \"3.939e3"');
|
||||
vrfy(str(7543) == "7.543e3", \
|
||||
'1692: str(7543) == \"7.543e3"');
|
||||
|
||||
tmp = base(1000);
|
||||
print '1693: tmp = base(1000)';
|
||||
vrfy(str(0x80000000) == "2.147483648e9", \
|
||||
'1694: str(0x8000000) == \"2.147483648e9"');
|
||||
vrfy(str(0xffffffff) == "4.294967295e9", \
|
||||
'1695: str(0xffffffff) == \"4.294967295e9\"');
|
||||
vrfy(str(3e9) == "3e9", \
|
||||
'1696: str(3e9) == \"3e9\"');
|
||||
vrfy(str(1/3) == "~333.33333333333333333333e-3", \
|
||||
'1697: str(1/3) == \"~333.33333333333333333333e-3\"');
|
||||
vrfy(str(2e8) == "200e6", \
|
||||
'1698: str(2e8) == \"200e6"');
|
||||
vrfy(str(200e6) == "200e6", \
|
||||
'1699: str(200e6) == \"200e6"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1700: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3.939e3", \
|
||||
'1701: str(07543) == \"3.939e3"');
|
||||
vrfy(str(7543) == "7.543e3", \
|
||||
'1702: str(7543) == \"7.543e3"');
|
||||
|
||||
tmp = base(-10);
|
||||
print '1703: tmp = base(-10)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1704: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1705: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1706: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "~0", \
|
||||
'1707: str(1/3) == \"~0\"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1708: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1709: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1710: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1711: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1712: str(7543) == \"7543"');
|
||||
|
||||
tmp = base(10);
|
||||
print '1646: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", \
|
||||
'1647: config("mode") == "real"');
|
||||
|
||||
print '1713: tmp = base(10)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1648: str(0x80000000) == \"2147483648\"');
|
||||
'1714: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1649: str(0xffffffff) == \"4294967295\"');
|
||||
'1715: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1650: str(3e9) == \"3000000000\"');
|
||||
'1716: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "~0.33333333333333333333", \
|
||||
'1717: str(1/3) == \"~0.33333333333333333333"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1718: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1719: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1720: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1721: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1722: str(7543) == \"7543"');
|
||||
|
||||
/* test base2() functionality */
|
||||
vrfy(base2() == 0, '1651: base2() == 0');
|
||||
vrfy(base2(0) == 0, '1652: base2(0) == 0');
|
||||
vrfy(base2() == 0, '1653: base2() == 0');
|
||||
vrfy(base2(16) == 0, '1654: base2(16) == 0');
|
||||
vrfy(base2() == 16, '1655: base2() == 16');
|
||||
vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */",
|
||||
'1656: str(3e9) == "3000000000 /* 0xb2d05e00 */"');
|
||||
vrfy(base2(1/3) == 16, '1657: base2(16) == 16');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1658: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1659: str(3/2) == "1.5 /* 3/2 */"');
|
||||
vrfy(base() == 10, '1660: base() == 10');
|
||||
vrfy(base2(0) == 1/3, '1661: base2(0) == 1/3');
|
||||
vrfy(base2() == 0, '1723: base2() == 0');
|
||||
vrfy(base2(0) == 0, '1724: base2(0) == 0');
|
||||
vrfy(base2() == 0, '1725: base2() == 0');
|
||||
|
||||
print '1662: Ending mode/base test';
|
||||
vrfy(base2(16) == 0, '1726: base2(16) == 0');
|
||||
vrfy(base2() == 16, '1727: base2() == 16');
|
||||
vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */",
|
||||
'1728: str(3e9) == "3000000000 /* 0xb2d05e00 */"');
|
||||
|
||||
vrfy(base2(1/3) == 16, '1728: base2(16) == 16');
|
||||
vrfy(base2() == 1/3, '1729: base2() == 1/3');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1730: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1731: str(3/2) == "1.5 /* 3/2 */"');
|
||||
|
||||
vrfy(base2(8) == 1/3, '1732: base2(8) == 1/3');
|
||||
vrfy(base2() == 8, '1733: base2() == 8');
|
||||
vrfy(str(23209) == "23209 /* 055251 */",
|
||||
'1734: str(23209) == "23209 /* 055251 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1735: str(3/2) == "1.5 /* 3/2 */"');
|
||||
|
||||
vrfy(base2(2) == 8, '1736: base2(2) == 8');
|
||||
vrfy(base2() == 2, '1737: base2() == 2');
|
||||
vrfy(str(23209) == "23209 /* 0b101101010101001 */",
|
||||
'1738: str(23209) == "23209 /* 0b101101010101001 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 0b11/0b10 */",
|
||||
'1739: str(3/2) == "1.5 /* 0b11/0b10 */"');
|
||||
|
||||
vrfy(base2(1e20) == 2, '1740: base2(1e20) == 2');
|
||||
vrfy(base2() == 1e20, '1741: base2() == 1e20');
|
||||
vrfy(str(23209) == "23209 /* 2.3209e4 */",
|
||||
'1742: str(23209) == "23209 /* 2.3209e4 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1743: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(-10) == 1e20, '1744: base2(-10) == 1e20');
|
||||
vrfy(base2() == -10, '1745: base2() == -10');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1746: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* ~2 */",
|
||||
'1747: str(3/2) == "1.5 /* ~2 */"');
|
||||
|
||||
vrfy(base2(1000) == -10, '1748: base2(1000) == -1000');
|
||||
vrfy(base2() == 1000, '1749: base2() == 1000');
|
||||
vrfy(str(23209) == "23209 /* 23.209e3 */",
|
||||
'1750: str(23209) == "23209 /* 23.209e3 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1751: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(10) == 1000, '1752: base2(10) == 1000');
|
||||
vrfy(base2() == 10, '1753: base2() == 10');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1754: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1755: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(0) == 10, '1756: base2(0) == 10');
|
||||
vrfy(base2() == 0, '1757: base2() == 0');
|
||||
vrfy(str(23209) == "23209",
|
||||
'1758: str(23209) == "23209"');
|
||||
vrfy(str(3/2) == "1.5",
|
||||
'1759: str(3/2) == "1.5"');
|
||||
|
||||
vrfy(base() == 10, '1760: base() == 10');
|
||||
vrfy(base2() == 0, '1761: base2() == 0');
|
||||
|
||||
print '1762: Ending mode/base test';
|
||||
}
|
||||
print '026: parsed test_mode()';
|
||||
|
||||
|
||||
/*
|
||||
* The 1700's contain tests for reading resource files. These tests are
|
||||
* done inline near the bottom.
|
||||
* The 1780's and 1790's contain tests for reading resource files.
|
||||
*
|
||||
* These tests are done inline near the bottom.
|
||||
*/
|
||||
|
||||
|
||||
@@ -3198,9 +3414,11 @@ define test_trig()
|
||||
|
||||
print '3400: Beginning test_trig';
|
||||
|
||||
/* test 3401-3407 */
|
||||
tnum = test3400(1, 3401);
|
||||
vrfy(tnum == 3407, '3407: tnum == 3407');
|
||||
|
||||
print tnum: ': Ending test_trig';
|
||||
print '3438: Ending test_trig';
|
||||
}
|
||||
print '051: parsed test_trig()';
|
||||
|
||||
@@ -4544,7 +4762,7 @@ define test_random()
|
||||
print '5303: state0 = srandom(0)';
|
||||
vrfy(state0 == init, '5304: state0 == init');
|
||||
|
||||
/* test the additive 55 shuffle generator */
|
||||
/* test the subtractive 100 shuffle generator */
|
||||
tmp = srandom(0);
|
||||
print '5305: tmp = srandom(0)';
|
||||
vrfy(random() == 0x7fb838a8a0a95046, \
|
||||
@@ -6895,9 +7113,10 @@ define test_sha1()
|
||||
vrfy(sha1("x", "y", "z") == sha1("xyz"),
|
||||
'7208: sha1("x", "y", "z") == sha1("xyz")');
|
||||
|
||||
vrfy(sha1(sha1("this is",7^19-8,"a composit",3i+4.5,"hash")) ==
|
||||
0xc3e1b562bf45b3bcfc055ac65b5b39cdeb6a6c55,
|
||||
'7209: sha1(sha1("this is",7^19-8,"a composit",3i+4.5,"hash")) == ...');
|
||||
vrfy(sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) ==
|
||||
0x68aa4fe0a9b6d1662f8d2dbdeee8879239185d09,
|
||||
'7209: sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) ' +
|
||||
'== ...');
|
||||
|
||||
|
||||
z = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi(1e-100));
|
||||
@@ -7635,31 +7854,31 @@ print;
|
||||
return test_mode();
|
||||
print;
|
||||
|
||||
print '1700: Beginning read test';
|
||||
print '1780: Beginning read test';
|
||||
value = 0;
|
||||
vrfy(value == 0, '1701: value == 0');
|
||||
vrfy(value == 0, '1781: value == 0');
|
||||
read "test1700";
|
||||
print '1702: read "test1700";';
|
||||
vrfy(value == 1, '1703: value == 1');
|
||||
print '1782: read "test1700";';
|
||||
vrfy(value == 1, '1783: value == 1');
|
||||
read -once "test1700";
|
||||
print '1704: read -once "test1700";';
|
||||
vrfy(value == 1, '1705: value == 1');
|
||||
print '1784: read -once "test1700";';
|
||||
vrfy(value == 1, '1785: value == 1');
|
||||
read "test1700.cal";
|
||||
print '1706: read "test1700.cal";';
|
||||
vrfy(value == 2, '1707: value == 2');
|
||||
read -once "test1700.cal";
|
||||
print '1708: read -once "test1700.cal";';
|
||||
vrfy(value == 2, '1709: value == 2');
|
||||
print '1786: read "test1700.cal";';
|
||||
vrfy(value == 2, '1787: value == 2');
|
||||
read -once "test1700.cal"
|
||||
print '1788: read -once "test1700.cal";';
|
||||
vrfy(value == 2, '1789: value == 2');
|
||||
read "test1700.cal";
|
||||
print '1710: read "test1700.cal";';
|
||||
vrfy(value == 3, '1711: value == 3');
|
||||
print '1790: read "test1700.cal";';
|
||||
vrfy(value == 3, '1791: value == 3');
|
||||
{++value;} read "test1700.cal";
|
||||
print '1712: {++value;} read "test1700.cal";';
|
||||
vrfy(value == 5, '1713: value == 5');
|
||||
print '1792: {++value;} read "test1700.cal";';
|
||||
vrfy(value == 5, '1793: value == 5');
|
||||
{++value;} read -once "test1700.cal";
|
||||
print '1714: {++value;} read -once "test1700.cal";';
|
||||
vrfy(value == 6, '1715: value == 6');
|
||||
print '1716: Ending read test';
|
||||
print '1794: {++value;} read -once "test1700.cal";';
|
||||
vrfy(value == 6, '1795: value == 6');
|
||||
print '1796: Ending read test';
|
||||
|
||||
print;
|
||||
return test_obj();
|
||||
@@ -7963,6 +8182,8 @@ ecnt = 211;
|
||||
* Test more of the built-in functions.
|
||||
*
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions2()
|
||||
{
|
||||
@@ -8076,6 +8297,401 @@ print;
|
||||
return test_functions2();
|
||||
|
||||
|
||||
/*
|
||||
* Test even more of the built-in functions.
|
||||
*
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions3()
|
||||
{
|
||||
local d, m, s, g, h;
|
||||
|
||||
print '9101: Beginning test_functions3';
|
||||
|
||||
/* d2r & r2d */
|
||||
vrfy(d2r(180) == pi(),
|
||||
'9102: d2r(180) == pi()');
|
||||
vrfy(d2r(180, 1e-100) == pi(1e-100),
|
||||
'9103: d2r(180, 1e-100) == pi(1e-100)');
|
||||
vrfy(r2d(pi()/2) == 90,
|
||||
'9104: r2d(pi()/2) == 90');
|
||||
vrfy(r2d(pi(1e-15)/2) == 14137166941154068500000/157079632679489661923,
|
||||
'9105: r2d(pi(1e-15)/2) == ' +
|
||||
'14137166941154068500000/157079632679489661923');
|
||||
vrfy(r2d(d2r(40)) == 40,
|
||||
'9106: r2d(d2r(40)) == 40');
|
||||
vrfy(r2d(d2r(40,1e-90),1e-90) == 40,
|
||||
'9107: r2d(d2r(40,1e-90),1e-90) == 40');
|
||||
vrfy(d2r(180i) == 1i*pi(),
|
||||
'9108: d2r(1808) == 1i*pi()');
|
||||
vrfy(d2r(180i+90) == 1i*pi() + pi()/2,
|
||||
'9109: d2r(180i+90) == 1i*pi() + pi()/2');
|
||||
vrfy(r2d(d2r(40+40i)) == 40+40i,
|
||||
'9110: r2d(d2r(40+40i)) == 40+40i');
|
||||
vrfy(r2d(d2r(40+40i,1e-60),1e-60) == 40+40i,
|
||||
'9111: r2d(d2r(40+40i,1e-60),1e-60) == 40+40i');
|
||||
|
||||
/* g2r & r2g */
|
||||
vrfy(g2r(200) == pi(),
|
||||
'9112: g2r(200) == pi()');
|
||||
vrfy(g2r(200, 1e-100) == pi(1e-100),
|
||||
'9113: g2r(180, 1e-100) == pi(1e-100)');
|
||||
vrfy(r2g(pi()/2) == 100,
|
||||
'9114: r2g(pi()/2) == 100');
|
||||
vrfy(r2g(pi(1e-15)/2) == 15707963267948965000000/157079632679489661923,
|
||||
'9115: r2g(pi(1e-15)/2) == ' +
|
||||
'15707963267948965000000/157079632679489661923');
|
||||
vrfy(r2g(g2r(40)) == 40,
|
||||
'9116: r2g(g2r(40)) == 40');
|
||||
vrfy(r2g(g2r(40,1e-90),1e-90) == 40,
|
||||
'9117: r2g(g2r(40,1e-90),1e-90) == 40');
|
||||
vrfy(g2r(200i) == 1i*pi(),
|
||||
'9118: g2r(200i) == 1i*pi()');
|
||||
vrfy(g2r(200i+150) == pi()*0.75 + 1i*pi(),
|
||||
'9119: g2r(200i+150) == pi()*0.75 + 1i*pi()');
|
||||
vrfy(r2g(g2r(40+40i)) == 40+40i,
|
||||
'9120: r2g(g2r(40+40i)) == 40+40i');
|
||||
vrfy(r2g(g2r(40+40i,1e-60),1e-60) == 40+40i,
|
||||
'9121: r2g(g2r(40+40i,1e-60),1e-60) == 40+40i');
|
||||
|
||||
/* g2d & d2g */
|
||||
vrfy(g2d(200) == 180,
|
||||
'9122: g2d(200) == 180');
|
||||
vrfy(g2d(200, 1e-100) == 180,
|
||||
'9123: g2d(180, 1e-100) == 180');
|
||||
vrfy(d2g(81) == 90,
|
||||
'9124: d2g(81) == 90');
|
||||
vrfy(d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000,
|
||||
'9125: d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000');
|
||||
vrfy(d2g(g2d(40)) == 40,
|
||||
'9126: d2g(g2d(40)) == 40');
|
||||
vrfy(d2g(g2d(40,1e-90),1e-90) == 40,
|
||||
'9127: d2g(g2d(40,1e-90),1e-90) == 40');
|
||||
vrfy(g2d(200i) == 180i,
|
||||
'9128: g2d(200i) == 180i');
|
||||
vrfy(g2d(200i+47) == 42.3 + 180i,
|
||||
'9129: g2d(200i+47) == 42.3 + 180i');
|
||||
vrfy(d2g(g2d(40+40i)) == 40+40i,
|
||||
'9130: d2g(g2d(40+40i)) == 40+40i');
|
||||
vrfy(d2g(g2d(40+40i,1e-90),1e-90) == 40+40i,
|
||||
'9131: d2g(g2d(40+40i,1e-90),1e-90) == 40+40i');
|
||||
|
||||
/* d2dms */
|
||||
vrfy(d2dms(12.3456,d,m,s) == 12.3456,
|
||||
'9132: d2dms(12.3456,d,m,s) == 12.3456');
|
||||
vrfy(d == 12,
|
||||
'9133: d == 12');
|
||||
vrfy(m == 20,
|
||||
'9133: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9134: s == 44.16');
|
||||
|
||||
vrfy(d2dms(1234.5678,d,m,s) == 154.5678,
|
||||
'9135: d2dms(1234.5678,d,m,s) == 154.5678');
|
||||
vrfy(d == 154,
|
||||
'9136: d == 154');
|
||||
vrfy(m == 34,
|
||||
'9137: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9138: s == 4.08');
|
||||
|
||||
vrfy(d2dms(-1234.5678,d,m,s) == 205.4322,
|
||||
'9139: d2dms(-1234.5678,d,m,s) == 205.4322');
|
||||
vrfy(d == 205,
|
||||
'9140: d == 205');
|
||||
vrfy(m == 25,
|
||||
'9141: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9142: s == 55.92');
|
||||
|
||||
vrfy(d2dms(360.321,d,m,s,1) == -359.679,
|
||||
'9143: d2dms(360.321,d,m,s,1) == -359.679');
|
||||
vrfy(d == -359,
|
||||
'9144: d == -359');
|
||||
vrfy(m == -40,
|
||||
'9145: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9146: s == -44.4');
|
||||
|
||||
/* d2dm */
|
||||
vrfy(d2dm(12.3456,d,m) == 12.3456,
|
||||
'9147: d2dm(12.3456,d,m) == 12.3456');
|
||||
vrfy(d == 12,
|
||||
'9148: d == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9149: m == 20.736');
|
||||
|
||||
vrfy(d2dm(1234.5678,d,m) == 154.5678,
|
||||
'9150: d2dm(1234.5678,d,m) == 154.5678');
|
||||
vrfy(d == 154,
|
||||
'9151: d == 154');
|
||||
vrfy(m == 34.068,
|
||||
'9152: m == 34.068');
|
||||
|
||||
vrfy(d2dm(-1234.5678,d,m) == 205.4322,
|
||||
'9153: d2dm(-1234.5678,d,m) == 205.4322');
|
||||
vrfy(d == 205,
|
||||
'9154: d == 205');
|
||||
vrfy(m == 25.932,
|
||||
'9155: m == 25.932');
|
||||
|
||||
vrfy(d2dm(360.321,d,m,1) == -359.679,
|
||||
'9156: d2dm(360.321,d,m,1) == -359.679');
|
||||
vrfy(d == -359,
|
||||
'9167: d == -359');
|
||||
vrfy(m == -40.74,
|
||||
'9158: m == -40.74');
|
||||
|
||||
/* g2gms */
|
||||
vrfy(g2gms(12.3456,g,m,s) == 12.3456,
|
||||
'9159: g2gms(12.3456,g,m,s) == 12.3456');
|
||||
vrfy(g == 12,
|
||||
'9133: g == 12');
|
||||
vrfy(m == 20,
|
||||
'9160: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9161: s == 44.16');
|
||||
|
||||
vrfy(g2gms(1234.5678,g,m,s) == 34.5678,
|
||||
'9162: g2gms(1234.5678,g,m,s) == 34.5678');
|
||||
vrfy(g == 34,
|
||||
'9163: g == 34');
|
||||
vrfy(m == 34,
|
||||
'9164: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9165: s == 4.08');
|
||||
|
||||
vrfy(g2gms(-1234.5678,g,m,s) == 365.4322,
|
||||
'9166: g2gms(-1234.5678,g,m,s) == 365.4322');
|
||||
vrfy(g == 365,
|
||||
'9167: g == 365');
|
||||
vrfy(m == 25,
|
||||
'9168: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9169: s == 55.92');
|
||||
|
||||
vrfy(g2gms(400.321,g,m,s,1) == -399.679,
|
||||
'9170: g2gms(400.321,g,m,s,1) == -399.679');
|
||||
vrfy(g == -399,
|
||||
'9171: g == -399');
|
||||
vrfy(m == -40,
|
||||
'9172: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9173: s == -44.4');
|
||||
|
||||
/* g2gm */
|
||||
vrfy(g2gm(12.3456,g,m) == 12.3456,
|
||||
'9174: g2gm(12.3456,g,m) == 12.3456');
|
||||
vrfy(g == 12,
|
||||
'9175: g == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9176: m == 20.736');
|
||||
|
||||
vrfy(g2gm(1234.5678,g,m) == 34.5678,
|
||||
'9177: g2gm(1234.5678,g,m) == 34.5678');
|
||||
vrfy(g == 34,
|
||||
'9178: g == 34');
|
||||
vrfy(m == 34.068,
|
||||
'9179: m == 34.068');
|
||||
|
||||
vrfy(g2gm(-1234.5678,g,m) == 365.4322,
|
||||
'9180: g2gm(-1234.5678,g,m) == 365.4322');
|
||||
vrfy(g == 365,
|
||||
'9181: g == 365');
|
||||
vrfy(m == 25.932,
|
||||
'9182: m == 25.932');
|
||||
|
||||
vrfy(g2gm(400.321,g,m,1) == -399.679,
|
||||
'9183: g2gm(400.321,g,m,1) == -399.679');
|
||||
vrfy(g == -399,
|
||||
'9184: g == -399');
|
||||
vrfy(m == -40.74,
|
||||
'9185: m == -40.74');
|
||||
|
||||
/* h2hms */
|
||||
vrfy(h2hms(12.3456,h,m,s) == 12.3456,
|
||||
'9186: h2hms(12.3456,h,m,s) == 12.3456');
|
||||
vrfy(h == 12,
|
||||
'9187: h == 12');
|
||||
vrfy(m == 20,
|
||||
'9188: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9189: s == 44.16');
|
||||
|
||||
vrfy(h2hms(1234.5678,h,m,s) == 10.5678,
|
||||
'9190: h2hms(1234.5678,h,m,s) == 10.5678');
|
||||
vrfy(h == 10,
|
||||
'9191: h == 10');
|
||||
vrfy(m == 34,
|
||||
'9192: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9193: s == 4.08');
|
||||
|
||||
vrfy(h2hms(-1234.5678,h,m,s) == 13.4322,
|
||||
'9194: h2hms(-1234.5678,h,m,s) == 13.4322');
|
||||
vrfy(h == 13,
|
||||
'9195: h == 13');
|
||||
vrfy(m == 25,
|
||||
'9196: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9197: s == 55.92');
|
||||
|
||||
vrfy(h2hms(24.321,h,m,s,1) == -23.679,
|
||||
'9198: h2hms(24.321,h,m,s,1) == -23.679');
|
||||
vrfy(h == -23,
|
||||
'9199: h == -23');
|
||||
vrfy(m == -40,
|
||||
'9200: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9201: s == -44.4');
|
||||
|
||||
/* h2hm */
|
||||
vrfy(h2hm(12.3456,h,m) == 12.3456,
|
||||
'9202: h2hm(12.3456,h,m) == 12.3456');
|
||||
vrfy(h == 12,
|
||||
'9203: h == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9204: m == 20.736');
|
||||
|
||||
vrfy(h2hm(1234.5678,h,m) == 10.5678,
|
||||
'9205: h2hm(1234.5678,h,m) == 10.5678');
|
||||
vrfy(h == 10,
|
||||
'9206: h == 10');
|
||||
vrfy(m == 34.068,
|
||||
'9207: m == 34.068');
|
||||
|
||||
vrfy(h2hm(-1234.5678,h,m) == 13.4322,
|
||||
'9208: h2hm(-1234.5678,h,m) == 13.4322');
|
||||
vrfy(h == 13,
|
||||
'9209: h == 13');
|
||||
vrfy(m == 25.932,
|
||||
'9210: m == 25.932');
|
||||
|
||||
vrfy(h2hm(24.321,h,m,1) == -23.679,
|
||||
'9211: h2hm(24.321,h,m,1) == -23.679');
|
||||
vrfy(h == -23,
|
||||
'9212: h == -23');
|
||||
vrfy(m == -40.74,
|
||||
'9213: m == -40.74');
|
||||
|
||||
/* dm2d */
|
||||
vrfy(dm2d(203, 325.5594) == 208.42599,
|
||||
'9214: dm2d(203, 325.5594) == 208.42599');
|
||||
vrfy(dm2d(3601, -25.5594) == 0.57401,
|
||||
'9215: dm2d(3601, -25.5594) == 0.57401');
|
||||
vrfy(dm2d(-923, -25.5594) == 156.57401,
|
||||
'9216: dm2d(-923, -25.5594) == 156.57401');
|
||||
vrfy(dm2d(203, 325.5594, 1) == -151.57401,
|
||||
'9217: dm2d(203, 325.5594, 1) == -151.57401');
|
||||
|
||||
vrfy(d2dm(dm2d(12, 20.16),d,m) == 12.336,
|
||||
'9218: d2dm(dm2d(12, 20.16),d,m) == 12.336');
|
||||
vrfy(d == 12,
|
||||
'9219: d == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9220: m == 20.16');
|
||||
|
||||
/* dms2d */
|
||||
vrfy(dms2d(12, 20, 44.16) == 12.3456,
|
||||
'9221: dms2d(12, 20, 44.16) == 12.3456');
|
||||
vrfy(dms2d(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9222: dms2d(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(dms2d(-65, -40, -44.4) == 294.321,
|
||||
'9223: dms2d(-65, -40, -44.4) == 294.321');
|
||||
vrfy(dms2d(12, 20, 44.16, 1) == -347.6544,
|
||||
'9224: dms2d(12, 20, 44.16, 1) == -347.6544');
|
||||
|
||||
vrfy(d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456,
|
||||
'9225: d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456');
|
||||
vrfy(d == 13,
|
||||
'9226: d == 13');
|
||||
vrfy(m == 20,
|
||||
'9227: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9228: s == 44.16');
|
||||
|
||||
/* gm2g */
|
||||
vrfy(gm2g(203, 325.5594) == 208.42599,
|
||||
'9229: gm2g(203, 325.5594) == 208.42599');
|
||||
vrfy(gm2g(3601, -25.5594) == 0.57401,
|
||||
'9230: gm2g(3601, -25.5594) == 0.57401');
|
||||
vrfy(gm2g(-923, -25.5594) == 276.57401,
|
||||
'9231: gm2g(-923, -25.5594) == 276.57401');
|
||||
vrfy(gm2g(203, 325.5594, 1) == -191.57401,
|
||||
'9232: gm2g(203, 325.5594, 1) == -191.57401');
|
||||
|
||||
vrfy(g2gm(gm2g(12, 20.16),g,m) == 12.336,
|
||||
'9233: g2gm(gm2g(12, 20.16),g,m) == 12.336');
|
||||
vrfy(g == 12,
|
||||
'9234: g == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9235: m == 20.16');
|
||||
|
||||
/* gms2g */
|
||||
vrfy(gms2g(12, 20, 44.16) == 12.3456,
|
||||
'9236: gms2g(12, 20, 44.16) == 12.3456');
|
||||
vrfy(gms2g(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9237: gms2g(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(gms2g(-65, -40, -44.4) == 334.321,
|
||||
'9238: gms2g(-65, -40, -44.4) == 334.321');
|
||||
vrfy(gms2g(12, 20, 44.16, 1) == -387.6544,
|
||||
'9239: gms2g(12, 20, 44.16, 1) == -387.6544');
|
||||
|
||||
vrfy(g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456,
|
||||
'9240: g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456');
|
||||
vrfy(g == 14,
|
||||
'9241: g == 14');
|
||||
vrfy(m == 20,
|
||||
'9242: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9243: s == 44.16');
|
||||
|
||||
/* hm2h */
|
||||
vrfy(hm2h(203, 325.5594) == 16.42599,
|
||||
'9244: hm2h(203, 325.5594) == 16.42599');
|
||||
vrfy(hm2h(241, -25.5594) == 0.57401,
|
||||
'9245: hm2h(241, -25.5594) == 0.57401');
|
||||
vrfy(hm2h(-923, -25.5594) == 12.57401,
|
||||
'9246: hm2h(-923, -25.5594) == 12.57401');
|
||||
vrfy(hm2h(203, 325.5594, 1) == -7.57401,
|
||||
'9247: hm2h(203, 325.5594, 1) == -7.57401');
|
||||
|
||||
vrfy(h2hm(hm2h(12, 20.16),h,m) == 12.336,
|
||||
'9248: h2hm(hm2h(12, 20.16),h,m) == 12.336');
|
||||
vrfy(h == 12,
|
||||
'9249: h == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9250: m == 20.16');
|
||||
|
||||
/* hms2h */
|
||||
vrfy(hms2h(12, 20, 44.16) == 12.3456,
|
||||
'9251: hms2h(12, 20, 44.16) == 12.3456');
|
||||
vrfy(hms2h(123.456, -345.68, 4.08) == 21.6958,
|
||||
'9252: hms2h(123.456, -345.68, 4.08) == 21.6958');
|
||||
vrfy(hms2h(-65, -40, -44.4) == 6.321,
|
||||
'9253: hms2h(-65, -40, -44.4) == 6.321');
|
||||
vrfy(hms2h(12, 20, 44.16, 1) == -11.6544,
|
||||
'9254: hms2h(12, 20, 44.16, 1) == -11.6544');
|
||||
|
||||
vrfy(h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456,
|
||||
'9255: h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456');
|
||||
vrfy(h == 15,
|
||||
'9256: h == 15');
|
||||
vrfy(m == 20,
|
||||
'9257: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9258: s == 44.16');
|
||||
|
||||
print '9259: Ending test_functions3';
|
||||
}
|
||||
print;
|
||||
print '9100: parsed test_functions3()';
|
||||
print;
|
||||
return test_functions3();
|
||||
|
||||
|
||||
/*
|
||||
* read various calc resource files
|
||||
*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
##
|
||||
## set8700 - dotest line tests for the 8700 set of regress.cal
|
||||
##
|
||||
## Copyright (C) 2006 Ernest Bowen and Landon Curt Noll
|
||||
## Copyright (C) 2006,2021 Ernest Bowen and Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -159,7 +159,7 @@ set8700_A = 42, protect(set8700_A,1024), set8700_B = set8700_A, protect(set8700_
|
||||
set8700_A = 6 * 7, protect(set8700_A) == 1024
|
||||
set8700_A == set8700_B
|
||||
|
||||
## Testing matrix protectioon
|
||||
## Testing matrix protection
|
||||
set8700_A = mat [3] = {1, 2, list(3,4)}; 1
|
||||
protect(set8700_A, 65, 1), protect(set8700_A) == 1089
|
||||
protect(set8700_A[0]) == 65
|
||||
@@ -261,7 +261,7 @@ protect(set8700_L[0]) == 0
|
||||
protect(set8700_L[1]) == 512 ## protect(set8700_A) copied
|
||||
protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied
|
||||
|
||||
## Testing list with "intialization"
|
||||
## Testing list with "initialization"
|
||||
set8700_L = list(1,2,3), protect(set8700_L) == 0
|
||||
protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero
|
||||
set8700_L = {1,set8700_A}, set8700_L[1] == set8700_A
|
||||
|
@@ -371,7 +371,7 @@ define normalcdf(x,mu,sigma){
|
||||
|
||||
define probit(p){
|
||||
if(p<0 || p > 1) return newerror("probit: p out of domain 0<=p<=1");
|
||||
return sqrt(2)*ervinv(2*p-1);
|
||||
return sqrt(2)*erfinv(2*p-1);
|
||||
}
|
||||
|
||||
define normalcdfinv(p,mu,sigma){
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* sumtimes - runtimes evaluating sums & squares of large lists and mats
|
||||
* sumtimes - runtime evaluating sums & squares of large lists and mats
|
||||
*
|
||||
* Copyright (C) 2006 Ernest Bowen
|
||||
* Copyright (C) 2006,2021 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
|
||||
@@ -160,7 +160,7 @@ define timehmean(N, M = 10) {
|
||||
v2 = hmean(sumtimes_A);
|
||||
sumtimes_t2 = usertime();
|
||||
print v1, v2;
|
||||
print "List harmonic meanruntimes";
|
||||
print "List harmonic mean runtimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
printf('\tUsing builtin "hmean":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
@@ -2867,7 +2873,7 @@ define t035()
|
||||
epsilon(eps);
|
||||
return 6;
|
||||
}
|
||||
/* Percentiles. Numbers shamlessly stolen from a question at stackoverflow*/
|
||||
/* Percentiles. Numbers shamelessly stolen from a question at stackoverflow */
|
||||
if (abs
|
||||
(invbetainc(0.025, 10008, 151744) -
|
||||
0.060703546312525377697082321820950758320207425674954679415395) >
|
||||
@@ -3081,7 +3087,7 @@ define test8900(verbose = 0, tnum, testnum = 8903)
|
||||
return tnum;
|
||||
}
|
||||
|
||||
/* We will cause erors intentionally. A lot of them. */
|
||||
/* We will cause errors intentionally. A lot of them. */
|
||||
old_errmax = errmax(-1);
|
||||
|
||||
/*
|
||||
|
@@ -336,7 +336,7 @@ define __CZ__produce_long_random_number(n)
|
||||
ret = 1;
|
||||
if(!isint(n) || n<1)
|
||||
return newerror("__CZ__produce_long_random_number(n): "
|
||||
"n is not an integer >=1");
|
||||
"n is not an integer >=1");
|
||||
for(k=0;k<n;k++){
|
||||
ret += random();
|
||||
ret = toomcook4square(ret);
|
||||
|
@@ -72,7 +72,7 @@ define hurwitzzeta(s,a){
|
||||
limit=(precision*ln(10)-re((s-.5)*result)+(1.*realpart_a)*ln(2.*pi()))/2;
|
||||
limit=max(2,ceil(max(limit,abs(s*1.)/2)));
|
||||
limit_function=ceil(sqrt((limit+realpart_a/2-.25)^2+(imagpart_s*1.)^2/4)/
|
||||
pi());
|
||||
pi());
|
||||
if (config("user_debug") > 0) {
|
||||
print "limit_function = " limit_function;
|
||||
print "limit = " limit;
|
||||
|
141
calc.c
141
calc.c
@@ -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
|
||||
*
|
||||
@@ -26,18 +25,17 @@
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined (_WIN32)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# include <io.h>
|
||||
# if !defined(NOTCYGWIN)
|
||||
/*
|
||||
@@ -50,7 +48,7 @@
|
||||
# endif
|
||||
# define strdup _strdup
|
||||
# define isatty _isatty
|
||||
#endif /* Windoz */
|
||||
#endif /* Windows */
|
||||
|
||||
#define CALC_C
|
||||
#include "calc.h"
|
||||
@@ -66,6 +64,7 @@
|
||||
#include "lib_calc.h"
|
||||
#include "args.h"
|
||||
#include "zmath.h"
|
||||
#include "strl.h"
|
||||
|
||||
#include "have_unistd.h"
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
@@ -85,6 +84,10 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* S_FUNC definitions and functions
|
||||
*/
|
||||
@@ -120,6 +123,11 @@ main(int argc, char **argv)
|
||||
* parse args
|
||||
*/
|
||||
program = argv[0];
|
||||
script_name = strdup(argv[0]);
|
||||
if (script_name == NULL) {
|
||||
fprintf(stderr, "%s: failed to strdup(argv[0])\n", program);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cmdbuf[0] = '\0';
|
||||
cmdlen = 0;
|
||||
@@ -269,14 +277,14 @@ main(int argc, char **argv)
|
||||
if (nextcp(&cp, &index, argc, argv,
|
||||
FALSE)) {
|
||||
fprintf(stderr,
|
||||
"-D expects argument\n");
|
||||
"-D expects argument\n");
|
||||
exit(5);
|
||||
}
|
||||
havearg = TRUE;
|
||||
if (*cp != ':') {
|
||||
if (*cp < '0' || *cp > '9') {
|
||||
fprintf(stderr,
|
||||
"-D expects"
|
||||
"-D expects"
|
||||
" integer\n");
|
||||
exit(6);
|
||||
}
|
||||
@@ -288,13 +296,13 @@ main(int argc, char **argv)
|
||||
if (*cp != '\0' &&
|
||||
*cp != ' ' && *cp != ':') {
|
||||
fprintf(stderr,
|
||||
"Bad syntax im -D"
|
||||
"Bad syntax im -D"
|
||||
" arg\n");
|
||||
exit(7);
|
||||
}
|
||||
if (*cp != ':') {
|
||||
if (nextcp(&cp, &index,
|
||||
argc, argv,
|
||||
argc, argv,
|
||||
FALSE)
|
||||
|| *cp != ':')
|
||||
break;
|
||||
@@ -310,7 +318,7 @@ main(int argc, char **argv)
|
||||
if (*cp != ':') {
|
||||
if (*cp < '0' || *cp > '9') {
|
||||
fprintf(stderr,
|
||||
"-D : expects"
|
||||
"-D : expects"
|
||||
" integer\n");
|
||||
exit(9);
|
||||
}
|
||||
@@ -322,13 +330,13 @@ main(int argc, char **argv)
|
||||
if (*cp != '\0' &&
|
||||
*cp != ' ' && *cp != ':') {
|
||||
fprintf(stderr,
|
||||
"Bad syntax im -D"
|
||||
"Bad syntax im -D"
|
||||
" : arg\n");
|
||||
exit(10);
|
||||
}
|
||||
if (*cp != ':') {
|
||||
if (nextcp(&cp, &index,
|
||||
argc, argv,
|
||||
argc, argv,
|
||||
FALSE)
|
||||
|| *cp != ':') {
|
||||
break;
|
||||
@@ -338,12 +346,12 @@ main(int argc, char **argv)
|
||||
if (nextcp(&cp, &index, argc, argv,
|
||||
FALSE)) {
|
||||
fprintf(stderr, "-D : : expects"
|
||||
" argument\n");
|
||||
" argument\n");
|
||||
exit(11);
|
||||
}
|
||||
if (*cp < '0' || *cp > '9') {
|
||||
fprintf(stderr, "-D :: expects"
|
||||
" integer\n");
|
||||
" integer\n");
|
||||
exit(12);
|
||||
}
|
||||
user_debug = cp;
|
||||
@@ -373,40 +381,62 @@ main(int argc, char **argv)
|
||||
havearg = TRUE;
|
||||
if (cmdlen > 0)
|
||||
cmdbuf[cmdlen++] = ' ';
|
||||
strcpy(cmdbuf + cmdlen, "read ");
|
||||
cmdlen += 5;
|
||||
if (strncmp(cp, "-once", 5) == 0 &&
|
||||
(cp[5] == '\0' || cp[5] == ' ')) {
|
||||
cp += 5;
|
||||
strlcpy(cmdbuf + cmdlen, "read ",
|
||||
sizeof("read "));
|
||||
cmdlen += sizeof("read ")-1;
|
||||
cmdbuf[cmdlen] = '\0';
|
||||
if (strncmp(cp, "-once",
|
||||
sizeof("-once")) == 0 &&
|
||||
(cp[sizeof("-once")-1] == '\0' ||
|
||||
cp[sizeof("-once")-1] == ' ')) {
|
||||
cp += sizeof("-once")-1;
|
||||
haveendstr = (*cp == '\0');
|
||||
strcpy(cmdbuf+cmdlen, "-once ");
|
||||
cmdlen += 6;
|
||||
strlcpy(cmdbuf+cmdlen, "-once ",
|
||||
sizeof("-once "));
|
||||
cmdlen += sizeof("-once ")-1;
|
||||
cmdbuf[cmdlen] = '\0';
|
||||
if (nextcp(&cp, &index, argc,
|
||||
argv, haveendstr)) {
|
||||
fprintf(stderr, "-f -once"
|
||||
" expects"
|
||||
" expects"
|
||||
" filename\n");
|
||||
exit(16);
|
||||
}
|
||||
}
|
||||
bp = cmdbuf + cmdlen;
|
||||
/*
|
||||
* duplicate -f filename arg
|
||||
* as a new script_name value
|
||||
*/
|
||||
if (script_name != NULL) {
|
||||
free(script_name);
|
||||
}
|
||||
script_name = NULL;
|
||||
script_name = strdup(cp);
|
||||
if (script_name == NULL) {
|
||||
fprintf(stderr,
|
||||
"strdup(-f argument)"
|
||||
"failed\n");
|
||||
exit(17);
|
||||
}
|
||||
/* process -f filename arg */
|
||||
if (haveendstr) {
|
||||
len = strlen(cp);
|
||||
if (len == 0) {
|
||||
fprintf(stderr,
|
||||
"Null"
|
||||
" filename!");
|
||||
exit(17);
|
||||
" filename!\n");
|
||||
exit(18);
|
||||
}
|
||||
if (cmdlen + len + 2 > MAXCMD) {
|
||||
fprintf(stderr,
|
||||
"Commands too"
|
||||
" long");
|
||||
exit(18);
|
||||
" long\n");
|
||||
exit(19);
|
||||
}
|
||||
/* XXX - what if *cp = '\''? */
|
||||
*bp++ = '\'';
|
||||
strncpy(bp, cp, len+1);
|
||||
strlcpy(bp, cp, len+1);
|
||||
bp += len;
|
||||
*bp++ = '\'';
|
||||
cp += len;
|
||||
@@ -414,10 +444,10 @@ main(int argc, char **argv)
|
||||
} else {
|
||||
do {
|
||||
if (cmdlen > MAXCMD) {
|
||||
fprintf(stderr,
|
||||
"Commands"
|
||||
" too long");
|
||||
exit(19);
|
||||
fprintf(stderr,
|
||||
"Commands"
|
||||
" too long\n");
|
||||
exit(20);
|
||||
}
|
||||
*bp++ = *cp++;
|
||||
cmdlen++;
|
||||
@@ -428,8 +458,12 @@ main(int argc, char **argv)
|
||||
if (*cp == ';')
|
||||
cp++;
|
||||
*bp++ = ';';
|
||||
*bp = '\0';
|
||||
cmdlen++;
|
||||
s_flag = TRUE; /* -f implies -s */
|
||||
|
||||
/* -f implies -s */
|
||||
s_flag = TRUE;
|
||||
maxindex = index + 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
@@ -452,7 +486,7 @@ main(int argc, char **argv)
|
||||
"usage: %s ... -f filename\n"
|
||||
"1st cscript line: #/path/to/calc ... -s -f\n",
|
||||
program, program);
|
||||
exit(20);
|
||||
exit(21);
|
||||
}
|
||||
if (havearg)
|
||||
break;
|
||||
@@ -478,23 +512,9 @@ main(int argc, char **argv)
|
||||
fprintf(stderr,
|
||||
"%s: commands too long\n",
|
||||
program);
|
||||
exit(21);
|
||||
exit(22);
|
||||
}
|
||||
/*
|
||||
* The next statement could be:
|
||||
*
|
||||
* strncpy(cmdbuf + cmdlen, cp, cplen);
|
||||
*
|
||||
* however compilers like gcc would issue warnings such as:
|
||||
*
|
||||
* specified bound depends on the length of the
|
||||
* source argument
|
||||
*
|
||||
* even though we terminate the string by setting a NUL
|
||||
* byte following the copy. Therefore we call memcpy()
|
||||
* instead to avoid such warnings.
|
||||
*/
|
||||
memcpy(cmdbuf + cmdlen, cp, cplen);
|
||||
strlcpy(cmdbuf + cmdlen, cp, cplen+1);
|
||||
cmdbuf[newcmdlen] = '\0';
|
||||
cmdlen = newcmdlen;
|
||||
index++;
|
||||
@@ -515,7 +535,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
argc_value = argc - maxindex;
|
||||
argc_value = argc - maxindex + 1;
|
||||
argv_value = argv + maxindex;
|
||||
|
||||
/*
|
||||
@@ -528,7 +548,6 @@ main(int argc, char **argv)
|
||||
setbuf(stdout, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* initialize
|
||||
*/
|
||||
@@ -685,18 +704,18 @@ main(int argc, char **argv)
|
||||
if (!p_flag && i_flag && !stdin_tty) {
|
||||
closeinput();
|
||||
if(!freopen("/dev/tty", "r", stdin)) {
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
fprintf(stderr,
|
||||
"/dev/tty does not exist on "
|
||||
"this operating system. "
|
||||
"Change operating systems\n"
|
||||
"or don't use this calc mode "
|
||||
"in the future, sorry!\n");
|
||||
#else /* Windoz free systems */
|
||||
#else /* Windows free systems */
|
||||
fprintf(stderr,
|
||||
"Unable to associate stdin"
|
||||
" with /dev/tty");
|
||||
#endif /* Windoz free systems */
|
||||
#endif /* Windows free systems */
|
||||
set_run_state(RUN_EXIT_WITH_ERROR);
|
||||
break;
|
||||
}
|
||||
@@ -715,18 +734,18 @@ main(int argc, char **argv)
|
||||
!p_flag && (!havecommands||i_flag)) {
|
||||
closeinput();
|
||||
if(!freopen("/dev/tty", "r", stdin)) {
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
fprintf(stderr,
|
||||
"/dev/tty does not exist on "
|
||||
"this operating system. "
|
||||
"Change operating systems\n"
|
||||
"or don't use this calc mode "
|
||||
"in the future, sorry!\n");
|
||||
#else /* Windoz free systems */
|
||||
#else /* Windows free systems */
|
||||
fprintf(stderr,
|
||||
"Unable to associate stdin"
|
||||
" with /dev/tty");
|
||||
#endif /* Windoz free systems */
|
||||
#endif /* Windows free systems */
|
||||
set_run_state(RUN_EXIT_WITH_ERROR);
|
||||
break;
|
||||
}
|
||||
@@ -762,12 +781,12 @@ main(int argc, char **argv)
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
S_FUNC void
|
||||
intint(int UNUSED arg)
|
||||
intint(int UNUSED(arg))
|
||||
{
|
||||
(void) signal(SIGINT, intint);
|
||||
if (inputwait || (++abortlevel >= ABORT_NOW)) {
|
||||
calc_interrupt("\nABORT");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (abortlevel >= ABORT_MATH)
|
||||
_math_abort_ = TRUE;
|
||||
@@ -803,7 +822,7 @@ calc_interrupt(char *fmt, ...)
|
||||
* don't call libcalc_call_me_last() -- we might loop
|
||||
* and besides ... this is an unusual internal error case
|
||||
*/
|
||||
exit(22);
|
||||
exit(24);
|
||||
}
|
||||
}
|
||||
|
||||
|
7
calc.h
7
calc.h
@@ -59,7 +59,7 @@
|
||||
#define HOMECHAR '~' /* char which indicates home directory */
|
||||
#define DOTCHAR '.' /* char which indicates current directory */
|
||||
#define PATHCHAR '/' /* char which separates path components */
|
||||
#if defined(__MSDOS__) || defined(__WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define LISTCHAR ';' /* char which separates paths in a list */
|
||||
#else
|
||||
#define LISTCHAR ':' /* char which separates paths in a list */
|
||||
@@ -123,7 +123,7 @@ E_FUNC int get_inode(FILEID id, ZVALUE *ino);
|
||||
E_FUNC FILEID reopenid(FILEID id, char *mode, char *name);
|
||||
E_FUNC int closeall(void);
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
E_FUNC int flushall(void);
|
||||
#endif
|
||||
|
||||
@@ -186,7 +186,7 @@ E_FUNC char *calc_strdup(CONST char *);
|
||||
*/
|
||||
E_FUNC void initialize(void);
|
||||
E_FUNC void reinitialize(void);
|
||||
#if !defined (_WIN32)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
E_FUNC int isatty(int tty); /* TRUE if fd is a tty */
|
||||
#endif
|
||||
E_FUNC char *version(void); /* return version string */
|
||||
@@ -216,6 +216,7 @@ EXTERN int havecommands; /* TRUE if have cmd args) */
|
||||
EXTERN char *program; /* our name */
|
||||
EXTERN char *base_name; /* basename of our name */
|
||||
EXTERN char cmdbuf[]; /* command line expression */
|
||||
EXTERN char *script_name; /* program name or -f filename arg or NULL */
|
||||
|
||||
EXTERN int abortlevel; /* current level of aborts */
|
||||
EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */
|
||||
|
230
calc.man
230
calc.man
@@ -37,6 +37,7 @@ calc \- arbitrary precision calculator
|
||||
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
|
||||
.br
|
||||
.RB [ \-e ]
|
||||
.RB [ \-f\ \&filename ]
|
||||
.RB [ \-h ]
|
||||
.RB [ \-i ]
|
||||
.RB [ \-m\ \&mode ]
|
||||
@@ -50,11 +51,12 @@ calc \- arbitrary precision calculator
|
||||
.RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ]
|
||||
.in -5n
|
||||
.sp
|
||||
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
|
||||
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
|
||||
|
||||
.PP
|
||||
|
||||
.SH DESCRIPTION
|
||||
\&
|
||||
.br
|
||||
CALC OPTIONS
|
||||
|
||||
.PP
|
||||
|
||||
.TP
|
||||
@@ -218,48 +220,55 @@ Ignore any environment variables on startup.
|
||||
The getenv() builtin will still return values, however.
|
||||
|
||||
.TP
|
||||
.B \-f
|
||||
.BR \-f " filename"
|
||||
This flag is normally only with calc shell scripts.
|
||||
.sp 1
|
||||
This flag is required when using calc in
|
||||
.BR "shell script mode" .
|
||||
It must be at the end of the initial
|
||||
.B #!
|
||||
line of the script
|
||||
and must be immediately preceded by the
|
||||
.B \-s
|
||||
flag.
|
||||
.sp 1
|
||||
If the first line of an executable file begins
|
||||
.B #!
|
||||
followed by the absolute pathname of the
|
||||
.B calc
|
||||
program and if the first line ends with the two flags
|
||||
.B \-s
|
||||
.B \-f
|
||||
as in:
|
||||
line of the script, as in:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
|
||||
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
the rest of the file will be processed in
|
||||
.BR "shell script mode" .
|
||||
|
||||
.sp 1
|
||||
A common flag to use, prior to the
|
||||
.B \-f
|
||||
on the #! line is the
|
||||
.B \-q
|
||||
flag.
|
||||
For example:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\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
|
||||
.B "SHELL SCRIPT MODE"
|
||||
section of this man page
|
||||
below for details.
|
||||
.sp 1
|
||||
The actual form of this flag is:
|
||||
While the actual form of this flag is:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.B \-f
|
||||
.BR \-f
|
||||
filename
|
||||
.in -5n
|
||||
.sp 1
|
||||
On systems that treat an executable that begins with
|
||||
for systems that treat an executable that begins with
|
||||
.B #!
|
||||
as a script, the path of the executable is appended by the kernel
|
||||
as the final argument to the exec() system call.
|
||||
@@ -270,12 +279,13 @@ flag at the very end of the
|
||||
line.
|
||||
.sp 1
|
||||
It is possible use
|
||||
.B \-f\ filename
|
||||
.B \-f
|
||||
filename
|
||||
on the command line:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fIcalc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP filename
|
||||
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-f\fP filename
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
@@ -283,28 +293,14 @@ This will cause calc to process lines in
|
||||
.B filename
|
||||
in
|
||||
.BR "shell script mode" .
|
||||
.sp 1
|
||||
Use of
|
||||
.B \-f
|
||||
implies
|
||||
.BR \-s .
|
||||
However in a calc shell script,
|
||||
one must include
|
||||
.B \-f
|
||||
before
|
||||
.B \-s
|
||||
on the initial
|
||||
.B #!
|
||||
line.
|
||||
|
||||
.sp 1
|
||||
In addition,
|
||||
.B \-d
|
||||
and
|
||||
.B \-p
|
||||
are implied if
|
||||
.B \-i
|
||||
is not given.
|
||||
The use of
|
||||
.B \-f
|
||||
filename
|
||||
implies the
|
||||
.B \-s
|
||||
flag.
|
||||
|
||||
.TP
|
||||
.B \-h
|
||||
@@ -491,16 +487,16 @@ This is useful when entering negative values on the command line as in:
|
||||
.in +5n
|
||||
.nf
|
||||
calc \-p \-\- \-1 - -7
|
||||
.sp 1
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
CALC COMMAND LINE
|
||||
.SH CALC COMMAND LINE
|
||||
|
||||
.PP
|
||||
|
||||
With no
|
||||
.I calc_cmd
|
||||
arguments,
|
||||
@@ -600,7 +596,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
|
||||
|
||||
@@ -638,10 +634,10 @@ to parse interactive commands, flushes data on standard input.
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
CALC STARTUP FILES
|
||||
.SH CALC STARTUP FILES
|
||||
|
||||
.PP
|
||||
|
||||
Normally on startup,
|
||||
if the environment variable
|
||||
.B $CALCRC
|
||||
@@ -678,10 +674,12 @@ files is also disabled as if
|
||||
.B \-q
|
||||
was given.
|
||||
|
||||
\&
|
||||
.br
|
||||
CALC FILE SEARCH PATH
|
||||
.PP
|
||||
|
||||
.SH CALC FILE SEARCH PATH
|
||||
|
||||
.PP
|
||||
|
||||
If the environment variable
|
||||
.B $CALCPATH
|
||||
is undefined, or if it
|
||||
@@ -758,24 +756,24 @@ help config
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
SHELL SCRIPT MODE
|
||||
.SH SHELL SCRIPT MODE
|
||||
|
||||
.PP
|
||||
|
||||
If the first line of an executable file begins
|
||||
.B #!
|
||||
followed by the absolute pathname of the
|
||||
.B calc
|
||||
program and the first line ends with the two flags
|
||||
.B \-s
|
||||
program and the first line ends with the flag
|
||||
.B \-f
|
||||
as in:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-s\fP \fB\-f\fP
|
||||
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
@@ -786,11 +784,11 @@ Note that
|
||||
.B \-f
|
||||
must at the end of the initial ``#!'' line.
|
||||
Any other optional
|
||||
.B "other_flags"
|
||||
.B "optional_other_flags"
|
||||
must come before
|
||||
the
|
||||
.B \-s
|
||||
.BR \-f .
|
||||
.B \-f
|
||||
flag.
|
||||
.sp 1
|
||||
In
|
||||
.B "shell script mode"
|
||||
@@ -799,7 +797,7 @@ executed as if they were in a file being processed by a read
|
||||
command, except that a "command" beginning with '#' followed by
|
||||
whitespace and ending at the next newline is treated as a comment.
|
||||
Any optional
|
||||
.B "other_flags"
|
||||
.B "optional_other_flags"
|
||||
will be parsed first followed by
|
||||
the later lines within the script itself.
|
||||
.sp 1
|
||||
@@ -821,7 +819,7 @@ the file
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \&\fB\-s\fP \fB\-f\fP
|
||||
\fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \fB\-f\fP
|
||||
|
||||
/* setup */
|
||||
argc = argv();
|
||||
@@ -894,12 +892,13 @@ whereas
|
||||
.in -5n
|
||||
.sp 1
|
||||
will not.
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
DATA TYPES
|
||||
.SH DATA TYPES
|
||||
|
||||
.PP
|
||||
|
||||
Fundamental builtin data types include integers, real numbers,
|
||||
rational numbers, complex numbers and strings.
|
||||
.PP
|
||||
@@ -922,12 +921,13 @@ help obj
|
||||
.br
|
||||
show objfuncs
|
||||
.in -1.0i
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
VARIABLES
|
||||
.SH VARIABLES
|
||||
|
||||
.PP
|
||||
|
||||
Variables in \fIcalc\fP are typeless.
|
||||
In other words, the fundamental type of a variable is determined by its content.
|
||||
Before a variable is assigned a value it has the value of zero.
|
||||
@@ -950,12 +950,13 @@ help list
|
||||
.br
|
||||
show globals
|
||||
.in -1.0i
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
INPUT/OUTPUT
|
||||
.SH INPUT/OUTPUT
|
||||
|
||||
.PP
|
||||
|
||||
A leading ``0x'' implies a hexadecimal value,
|
||||
a leading ``0b'' implies a binary value,
|
||||
and a ``0'' followed by a digit implies an octal value.
|
||||
@@ -985,12 +986,13 @@ command:
|
||||
.in 1.0i
|
||||
help file
|
||||
.in -1.0i
|
||||
|
||||
.PP
|
||||
|
||||
\&
|
||||
.br
|
||||
CALC LANGUAGE
|
||||
.SH CALC LANGUAGE
|
||||
|
||||
.PP
|
||||
|
||||
The \fIcalc\fP language is a C-like language.
|
||||
The language includes commands such as variable declarations,
|
||||
expressions, tests, labels, loops, file operations, function calls.
|
||||
@@ -1017,10 +1019,13 @@ help operator
|
||||
.br
|
||||
help config
|
||||
.in -1.0i
|
||||
|
||||
.PP
|
||||
|
||||
.SH FILES
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
.PD 0
|
||||
.TP 5
|
||||
${BINDIR}/calc
|
||||
@@ -1062,9 +1067,13 @@ custom resource files
|
||||
${CUSTOMHELPDIR}/*
|
||||
custom help files
|
||||
.sp 1
|
||||
|
||||
.PP
|
||||
|
||||
.SH ENVIRONMENT
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
.PD 0
|
||||
.TP 5
|
||||
CALCPATH
|
||||
@@ -1123,9 +1132,13 @@ Location of the calc custom help directory.
|
||||
.sp
|
||||
Default value: ${CUSTOMHELPDIR}
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH CREDIT
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
The main chunk of
|
||||
.B calc
|
||||
was written by David I. Bell.
|
||||
@@ -1154,10 +1167,13 @@ public domain arbitrarily precision routines which was posted
|
||||
to the net around 1984.
|
||||
By now, there is almost no recognizable
|
||||
code left from that original source.
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSE"
|
||||
\&
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
Calc is open software, and is
|
||||
covered under version 2.1 of the GNU Lesser General Public License.
|
||||
You are
|
||||
@@ -1217,10 +1233,13 @@ Copyright (C) 1999-2021 Landon Curt Noll
|
||||
.sp
|
||||
and is covered under version 2.1 GNU Lesser General
|
||||
Public License.
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CALC QUESTIONS"
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
If you have a simple general question about calc, send Email to:
|
||||
.sp
|
||||
.in +0.5i
|
||||
@@ -1276,11 +1295,13 @@ nor can we do your homework, nor can
|
||||
we do much more than answer short general questions about calc.
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "BUG REPORTS / BUG FIXES"
|
||||
\&
|
||||
.br
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
Send bug reports and bug fixes to:
|
||||
.sp
|
||||
.in +0.5i
|
||||
@@ -1346,11 +1367,13 @@ help bugs
|
||||
for more information about bug reporting.
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CONTRIBUTING CODE TO CALC"
|
||||
\&
|
||||
.br
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.I Calc
|
||||
is open source.
|
||||
Contributions of code are welcome.
|
||||
@@ -1422,7 +1445,7 @@ Your code needs to be contributed under either the 2.1 of the
|
||||
.B GNU Lesser General Public License (LGPL 2.1)
|
||||
or be in the public domain.
|
||||
.sp
|
||||
If you do not want to use calc GitHub, then send EMail to:
|
||||
If you do not want to use calc GitHub, then send Email to:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
@@ -1473,10 +1496,13 @@ you have that
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CALC WEB SITE"
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
Landon Noll maintains the
|
||||
.B calc
|
||||
web site is located at:
|
||||
|
12
calc.spec.in
12
calc.spec.in
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# calc.spec.in - template specfile for calc
|
||||
#
|
||||
# Copyright (C) 2003-2014 Petteri Kettunen and Landon Curt Noll
|
||||
# Copyright (C) 2003-2014,2021 Petteri Kettunen and Landon Curt Noll
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -49,7 +49,7 @@ BuildRoot: %{_tmppath}/build-root
|
||||
Calc is arbitrary precision C-like arithmetic system that is a
|
||||
calculator, an algorithm prototype and mathematical research
|
||||
tool. Calc comes with a rich set of builtin mathematical and
|
||||
programmatic functions.
|
||||
programming functions.
|
||||
|
||||
For the latest calc release, see the calc project home page:
|
||||
|
||||
@@ -165,11 +165,11 @@ echo '-=- calc.spec beginning make clean -=-'
|
||||
%attr(644, root, root) %{_libdir}/libcustcalc.a
|
||||
|
||||
%changelog
|
||||
* Sun Mar 24 2019 cLandon Curt Noll http://www.isthe.com/chongo
|
||||
* Sun Mar 24 2019 Landon Curt Noll http://www.isthe.com/chongo
|
||||
- Release: 13
|
||||
- Disable compiling with the default ARCH_CFLAGS= -march=native
|
||||
by clearking the ARCH_CFLAGS value in order to maximize
|
||||
the RPM binary protability.
|
||||
by clearing the ARCH_CFLAGS value in order to maximize
|
||||
the RPM binary portability.
|
||||
|
||||
* Mon Sep 01 2014 Landon Curt Noll http://www.isthe.com/chongo
|
||||
- Release: 12
|
||||
@@ -178,7 +178,7 @@ echo '-=- calc.spec beginning make clean -=-'
|
||||
use -j1 while building these RPMs to avoid this make bug.
|
||||
This only impacts the speed of building the rpms.
|
||||
- Stopped removing %{_buildroot} at the beginning of install
|
||||
as this, acording to a number of sources, was asking for trouble.
|
||||
as this, according to a number of sources, was asking for trouble.
|
||||
- Clean removes tmp, BUILD, SPEC, and BUILDROOT dirs under topdir.
|
||||
- Fixed the building of the calc-debuginfo rpm.
|
||||
- Eliminated rpmbuild "bogus date" warnings due to inconsistent weekday,
|
||||
|
50
calcerr.tbl
50
calcerr.tbl
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# calcerr - error codes and messages
|
||||
#
|
||||
# Copyright (C) 1999-2006 Ernest Bowen
|
||||
# Copyright (C) 1999-2006,2021 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
|
||||
@@ -259,7 +259,7 @@ E_COPY6 Non-integer or negative destination index for copy
|
||||
E_COPY7 Destination index too large for copy
|
||||
E_COPY8 Freed block source for copy
|
||||
E_COPY9 Unsuitable source type for copy
|
||||
E_COPY10 Freed block destinction for copy
|
||||
E_COPY10 Freed block destination for copy
|
||||
E_COPY11 Unsuitable destination type for copy
|
||||
E_COPY12 Incompatible source and destination for copy
|
||||
E_COPY13 No-copy-from source variable
|
||||
@@ -496,3 +496,49 @@ E_ATANH3 Invalid value for calculating atan
|
||||
E_ACOTH3 Invalid value for calculating acot
|
||||
E_ASECH3 Invalid value for calculating asec
|
||||
E_ACSCH3 Invalid value for calculating acsc
|
||||
E_D2R1 Bad epsilon for converting degrees to radians
|
||||
E_D2R2 Bad first argument converting degrees to radians
|
||||
E_R2D1 Bad epsilon for converting radians to degrees
|
||||
E_R2D2 Bad first argument converting radians to degrees
|
||||
E_G2R1 Bad epsilon for converting gradians to radians
|
||||
E_G2R2 Bad first argument converting gradians to radians
|
||||
E_R2G1 Bad epsilon for converting radians to gradians
|
||||
E_R2G2 Bad first argument converting radians to gradians
|
||||
E_D2G1 Bad first argument converting degrees to gradians
|
||||
E_G2D1 Bad first argument converting gradians to degrees
|
||||
E_D2DMS1 Non-lvalue arguments 2, 3 or 4 for d2dms
|
||||
E_D2DMS2 Non-real-number arg 1 for d2dms
|
||||
E_D2DMS3 No-assign-to argument 2, 3 or 4 for d2dms
|
||||
E_D2DMS4 Invalid rounding arg 5 for d2dms
|
||||
E_D2DM1 Non-lvalue arguments 2 or 3 for d2dm
|
||||
E_D2DM2 Non-real-number arg 1 for d2dm
|
||||
E_D2DM3 No-assign-to argument 2 or 3 for d2dm
|
||||
E_D2DM4 Invalid rounding arg 4 for d2dm
|
||||
E_G2GMS1 Non-lvalue arguments 2, 3 or 4 for g2gms
|
||||
E_G2GMS2 Non-real-number arg 1 for g2gms
|
||||
E_G2GMS3 No-assign-to argument 2 or 3 for g2gms
|
||||
E_G2GMS4 Invalid rounding arg 5 for g2gms
|
||||
E_G2GM1 Non-lvalue arguments 2 or 3 for g2gm
|
||||
E_G2GM2 Non-real-number arg 1 for g2gm
|
||||
E_G2GM3 No-assign-to argument 2, 3 or 4 for g2gm
|
||||
E_G2GM4 Invalid rounding arg 4 for g2gm
|
||||
E_H2HMS1 Non-lvalue arguments 2, 3 or 4 for h2hms
|
||||
E_H2HMS2 Non-real-number arg 1 for h2hms
|
||||
E_H2HMS3 No-assign-to argument 2, 3 or 4 for h2hms
|
||||
E_H2HMS4 Invalid rounding arg 5 for h2hms
|
||||
E_H2HM1 Non-lvalue arguments 2 or 3 for h2hm
|
||||
E_H2HM2 Non-real-number arg 1 for h2hm
|
||||
E_H2HM3 No-assign-to argument 2 or 3 for h2hm
|
||||
E_H2HM4 Invalid rounding arg 4 for h2hm
|
||||
E_DMS2D1 Non-real-number arguments 1, 2 or 3 for dms2d
|
||||
E_DMS2D2 Invalid rounding arg 4 for dms2d
|
||||
E_DM2D1 Non-real-number arguments 1 or 2 for dm2d
|
||||
E_DM2D2 Invalid rounding arg 4 for dm2d
|
||||
E_GMS2G1 Non-real-number arguments 1, 2 or 3 for gms2g
|
||||
E_GMS2G2 Invalid rounding arg 4 for gms2g
|
||||
E_GM2G1 Non-real-number arguments 1 or 2 for gm2g
|
||||
E_GM2G2 Invalid rounding arg 4 for gm2g
|
||||
E_HMS2H1 Non-real-number arguments 1, 2 or 3 for hms2h
|
||||
E_HMS2H2 Invalid rounding arg 4 for hms2h
|
||||
E_HM2H1 Non-real-number arguments 1 or 2 for hm2h
|
||||
E_HM2H2 Invalid rounding arg 4 for hm2h
|
||||
|
@@ -28,6 +28,8 @@ BEGIN {
|
||||
printf("#include <stdio.h>\n");
|
||||
printf("#include \"calcerr.h\"\n\n");
|
||||
printf("#include \"have_const.h\"\n\n");
|
||||
printf("#include \"banned.h\"\t");
|
||||
printf("/* include after system header <> includes */\n\n");
|
||||
printf("/*\n");
|
||||
printf(" * names of calc error values\n");
|
||||
printf(" */\n");
|
||||
|
67
charbit.c
Normal file
67
charbit.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* charbit - determine what CHAR_BIT is and define CALC_CHARBIT
|
||||
*
|
||||
* 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/07 20:57:50
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage:
|
||||
* charbit
|
||||
*
|
||||
* This prog outputs several defines:
|
||||
*
|
||||
* CALC_CHARBIT
|
||||
* after including have_limits.h and perhaps <limits.h>,
|
||||
* output CALC_CHARBIT as CHAR_BIT (from <limits.h>, or as 8.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "have_limits.h"
|
||||
#if defined(HAVE_LIMITS_H)
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("#include \"have_limits.h\"\n");
|
||||
printf("#if defined(HAVE_LIMITS_H)\n");
|
||||
printf("#include <limits.h>\n");
|
||||
printf("#endif\n\n");
|
||||
#if defined(CHAR_BIT)
|
||||
|
||||
printf("#define CALC_CHARBIT (CHAR_BIT) /* from <limits.h> */\n");
|
||||
|
||||
#else /* CHAR_BIT */
|
||||
|
||||
printf("#define CALC_CHARBIT (8) /* no CHAR_BIT, assume 8 */\n");
|
||||
|
||||
#endif /* CHAR_BIT */
|
||||
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
}
|
40
codegen.c
40
codegen.c
@@ -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
|
||||
*
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "lib_calc.h"
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "token.h"
|
||||
#include "symbol.h"
|
||||
#include "label.h"
|
||||
@@ -41,10 +42,18 @@
|
||||
#include "str.h"
|
||||
#include "func.h"
|
||||
#include "conf.h"
|
||||
#include "strl.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if !defined(__CYGWIN__)
|
||||
# include <direct.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
STATIC BOOL rdonce; /* TRUE => do not reread this file */
|
||||
|
||||
@@ -144,11 +153,9 @@ getcommands(BOOL toplevel)
|
||||
case 1:
|
||||
case -1:
|
||||
if(i == 1) {
|
||||
strncpy(name,
|
||||
strlcpy(name,
|
||||
DEFAULTCALCHELP,
|
||||
MAXCMD);
|
||||
/* paranoia */
|
||||
name[MAXCMD] = '\0';
|
||||
MAXCMD+1);
|
||||
givehelp(name);
|
||||
}
|
||||
break;
|
||||
@@ -447,7 +454,7 @@ getsimplebody(void)
|
||||
|
||||
|
||||
/*
|
||||
* Get the body of a function, or a subbody of a function.
|
||||
* Get the body of a function, or a sub-body of a function.
|
||||
* body = '{' [ declarations ] ... [ statement ] ... '}'
|
||||
* | [ declarations ] ... [statement ] ... '\n'
|
||||
*/
|
||||
@@ -1512,7 +1519,7 @@ getexprlist(void)
|
||||
|
||||
|
||||
/*
|
||||
* Get an opassignment or possibly just an assignment or expression.
|
||||
* Get an op-assignment or possibly just an assignment or expression.
|
||||
* Returns flags describing the type of assignment or expression found.
|
||||
* assignment = lvalue '=' assignment
|
||||
* | lvalue '+=' assignment
|
||||
@@ -2354,8 +2361,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
|
||||
|
||||
/* use the value of the literal string */
|
||||
s = findstring(tokenstring());
|
||||
strncpy(name, s->s_str, namelen-1);
|
||||
name[namelen-1] = '\0';
|
||||
strlcpy(name, s->s_str, namelen);
|
||||
sfree(s);
|
||||
break;
|
||||
|
||||
@@ -2378,22 +2384,21 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/* return symbol name or value of global var string */
|
||||
strncpy(name, symstr, namelen-1);
|
||||
name[namelen-1] = '\0';
|
||||
strlcpy(name, symstr, namelen);
|
||||
break;
|
||||
|
||||
case T_NEWLINE:
|
||||
@@ -2431,7 +2436,7 @@ getshowstatement(void)
|
||||
|
||||
switch (gettoken()) {
|
||||
case T_SYMBOL:
|
||||
strncpy(name, tokensymbol(), 4);
|
||||
strlcpy(name, tokensymbol(), sizeof(name));
|
||||
name[4] = '\0';
|
||||
/* Yuck! */
|
||||
arg = stringindex("buil\000"
|
||||
@@ -2595,8 +2600,7 @@ getid(char *buf)
|
||||
*buf = '\0';
|
||||
return FALSE;
|
||||
}
|
||||
strncpy(buf, tokensymbol(), SYMBOLSIZE);
|
||||
buf[SYMBOLSIZE] = '\0';
|
||||
strlcpy(buf, tokensymbol(), SYMBOLSIZE+1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
29
comfunc.c
29
comfunc.c
@@ -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
|
||||
*
|
||||
@@ -29,6 +29,11 @@
|
||||
#include "config.h"
|
||||
#include "cmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* cache the natural logarithm of 10
|
||||
*/
|
||||
@@ -56,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))
|
||||
@@ -377,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);
|
||||
@@ -442,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);
|
||||
@@ -498,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_);
|
||||
@@ -595,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();
|
||||
@@ -645,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_);
|
||||
@@ -1068,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_);
|
||||
@@ -1110,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_);
|
||||
}
|
||||
|
14
commath.c
14
commath.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* commath - extended precision complex arithmetic primitive routines
|
||||
*
|
||||
* Copyright (C) 1999-2007 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,10 @@
|
||||
#include "cmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 };
|
||||
COMPLEX _cone_ = { &_qone_, &_qzero_, 1 };
|
||||
COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };
|
||||
@@ -186,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_);
|
||||
@@ -257,7 +261,7 @@ c_inv(COMPLEX *c)
|
||||
|
||||
if (ciszero(c)) {
|
||||
math_error("Inverting zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = comalloc();
|
||||
if (cisreal(c)) {
|
||||
@@ -519,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);
|
||||
@@ -602,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_);
|
||||
|
208
config.c
208
config.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* config - configuration routines
|
||||
*
|
||||
* Copyright (C) 1999-2007 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
|
||||
*
|
||||
@@ -46,6 +46,7 @@
|
||||
#endif
|
||||
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "token.h"
|
||||
#include "zrand.h"
|
||||
#include "block.h"
|
||||
@@ -53,12 +54,18 @@
|
||||
#include "config.h"
|
||||
#include "str.h"
|
||||
#include "custom.h"
|
||||
#include "strl.h"
|
||||
|
||||
#include "have_strdup.h"
|
||||
#if !defined(HAVE_STRDUP)
|
||||
# define strdup(x) calc_strdup((CONST char *)(x))
|
||||
#endif /* HAVE_STRDUP */
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* deal with systems that lack a defined CLK_TCK
|
||||
*/
|
||||
@@ -143,8 +150,8 @@ 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, /* OK to print a tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -154,8 +161,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, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
PROMPT1, /* normal prompt */
|
||||
PROMPT2, /* prompt when inside multi-line input */
|
||||
@@ -170,10 +177,10 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
#else
|
||||
FALSE, /* congrats, you are not using windows */
|
||||
FALSE, /* not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
@@ -203,8 +210,8 @@ 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, /* OK to print a tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -214,8 +221,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, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
"; ", /* normal prompt */
|
||||
";; ", /* prompt when inside multi-line input */
|
||||
@@ -230,10 +237,10 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
#else
|
||||
FALSE, /* congrats, you are not using windows */
|
||||
FALSE, /* not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
@@ -268,6 +275,8 @@ STATIC NAMETYPE modes[] = {
|
||||
{"scientific", MODE_EXP},
|
||||
{"sci", MODE_EXP},
|
||||
{"exp", MODE_EXP},
|
||||
{"engineering", MODE_ENG},
|
||||
{"eng", MODE_ENG},
|
||||
{"hexadecimal", MODE_HEX},
|
||||
{"hex", MODE_HEX},
|
||||
{"octal", MODE_OCTAL},
|
||||
@@ -480,11 +489,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;
|
||||
}
|
||||
@@ -499,14 +508,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;
|
||||
@@ -514,7 +523,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;
|
||||
@@ -522,12 +531,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;
|
||||
@@ -535,12 +544,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;
|
||||
@@ -548,7 +557,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;
|
||||
@@ -556,7 +565,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;
|
||||
@@ -564,7 +573,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;
|
||||
@@ -574,7 +583,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;
|
||||
@@ -584,7 +593,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;
|
||||
@@ -594,7 +603,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;
|
||||
@@ -609,7 +618,7 @@ 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;
|
||||
}
|
||||
@@ -623,7 +632,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;
|
||||
}
|
||||
@@ -632,7 +641,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;
|
||||
@@ -640,7 +649,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;
|
||||
@@ -648,7 +657,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;
|
||||
@@ -656,7 +665,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;
|
||||
@@ -664,7 +673,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;
|
||||
@@ -672,7 +681,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;
|
||||
@@ -680,7 +689,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;
|
||||
@@ -688,7 +697,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;
|
||||
@@ -696,7 +705,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;
|
||||
@@ -707,10 +716,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;
|
||||
}
|
||||
@@ -724,7 +732,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;
|
||||
@@ -734,7 +742,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);
|
||||
@@ -742,7 +750,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;
|
||||
@@ -750,14 +758,14 @@ 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();
|
||||
}
|
||||
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
free(conf->prompt1);
|
||||
conf->prompt1 = p;
|
||||
break;
|
||||
@@ -765,14 +773,14 @@ 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();
|
||||
}
|
||||
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
free(conf->prompt2);
|
||||
conf->prompt2 = p;
|
||||
break;
|
||||
@@ -780,7 +788,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);
|
||||
@@ -788,7 +796,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;
|
||||
@@ -801,7 +809,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;
|
||||
}
|
||||
@@ -810,13 +818,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;
|
||||
@@ -824,13 +832,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;
|
||||
@@ -838,13 +846,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;
|
||||
@@ -852,13 +860,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;
|
||||
@@ -866,13 +874,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;
|
||||
@@ -886,7 +894,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;
|
||||
}
|
||||
@@ -895,56 +903,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) {
|
||||
@@ -955,7 +963,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;
|
||||
}
|
||||
@@ -970,7 +978,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;
|
||||
}
|
||||
@@ -978,13 +986,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,7 +1017,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1018,7 +1026,7 @@ config_copy(CONFIG *src)
|
||||
dest = (CONFIG *)malloc(sizeof(CONFIG));
|
||||
if (dest == NULL) {
|
||||
math_error("malloc of CONFIG failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1126,7 +1134,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1153,7 +1161,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;
|
||||
@@ -1164,7 +1172,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;
|
||||
@@ -1272,7 +1280,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;
|
||||
@@ -1282,7 +1290,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;
|
||||
@@ -1308,7 +1316,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;
|
||||
@@ -1378,7 +1386,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
|
||||
default:
|
||||
math_error("Getting illegal CONFIG element");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1408,12 +1416,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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
8
config.h
8
config.h
@@ -130,8 +130,8 @@ struct config {
|
||||
LEN sq2; /* size of number to use square algorithm 2 */
|
||||
LEN pow2; /* size of modulus to use REDC for powers */
|
||||
LEN redc2; /* size of modulus to use REDC algorithm 2 */
|
||||
BOOL tilde_ok; /* ok to print a tilde on approximations */
|
||||
BOOL tab_ok; /* ok to print tab before numeric values */
|
||||
BOOL tilde_ok; /* OK to print a tilde on approximations */
|
||||
BOOL tab_ok; /* OK to print tab before numeric values */
|
||||
LEN quomod; /* quomod() default rounding mode */
|
||||
LEN quo; /* quotient // default rounding mode */
|
||||
LEN mod; /* mod % default rounding mode */
|
||||
@@ -141,8 +141,8 @@ struct config {
|
||||
LEN cfsim; /* cfsim() default rounding mode */
|
||||
LEN outround; /* output default rounding mode */
|
||||
LEN round; /* round()/bround() default rounding mode */
|
||||
BOOL leadzero; /* ok to print leading 0 before decimal pt */
|
||||
BOOL fullzero; /* ok to print trailing 0's */
|
||||
BOOL leadzero; /* OK to print leading 0 before decimal pt */
|
||||
BOOL fullzero; /* OK to print trailing 0's */
|
||||
long maxscancount; /* max scan errors before abort */
|
||||
char *prompt1; /* normal prompt */
|
||||
char *prompt2; /* prompt when inside multi-line input */
|
||||
|
32
const.c
32
const.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* const - constant number storage module
|
||||
*
|
||||
* Copyright (C) 1999-2007 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
|
||||
@@ -28,6 +28,11 @@
|
||||
#include "calc.h"
|
||||
#include "qmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define CONSTALLOCSIZE 400 /* number of constants to allocate */
|
||||
|
||||
STATIC unsigned long constcount;/* number of constants defined */
|
||||
@@ -40,16 +45,16 @@ initconstants(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
consttable = (NUMBER **) malloc(sizeof(NUMBER *) * CONSTALLOCSIZE);
|
||||
consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE);
|
||||
if (consttable == NULL) {
|
||||
math_error("Unable to allocate constant table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (i = 0; i < INITCONSTCOUNT; i++)
|
||||
for (i = 0; initnumbs[i] != NULL; i++) {
|
||||
consttable[i] = initnumbs[i];
|
||||
consttable[INITCONSTCOUNT] = NULL; /* firewall */
|
||||
constcount = INITCONSTCOUNT;
|
||||
constavail = CONSTALLOCSIZE - INITCONSTCOUNT;
|
||||
}
|
||||
constcount = i-1;
|
||||
constavail = CONSTALLOCSIZE - constcount;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,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;
|
||||
@@ -119,6 +124,9 @@ addqconstant(NUMBER *q)
|
||||
tp = consttable;
|
||||
for (index = 0; index < constcount; index++, tp++) {
|
||||
t = *tp;
|
||||
if (t == NULL) { /* paranoia */
|
||||
break;
|
||||
}
|
||||
if (t->links == 0) {
|
||||
if (!havefirst) {
|
||||
havefirst = TRUE;
|
||||
@@ -172,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];
|
||||
}
|
||||
@@ -189,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) {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* 4dsphere - determine if 6 points lie on the surface of a sphere in R^4
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
|
||||
*
|
||||
* usage:
|
||||
* 4dsphere x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5
|
||||
*
|
||||
@@ -10,8 +12,6 @@
|
||||
* ... ...
|
||||
* x5 y5 z5 w5 point 5 in R^4
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019 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.
|
||||
|
193
cscript/Makefile
193
cscript/Makefile
@@ -1,7 +1,15 @@
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
@@ -27,15 +35,67 @@
|
||||
# Makefile by Landon Curt Noll
|
||||
|
||||
|
||||
# required vars
|
||||
# The shell used by this Makefile
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
# 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 sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/sh
|
||||
#
|
||||
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 */
|
||||
|
||||
|
||||
####
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
####
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
@@ -45,15 +105,6 @@ SHELL= /bin/sh
|
||||
#
|
||||
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:
|
||||
@@ -65,11 +116,11 @@ TOP_MAKE_FILE= Makefile
|
||||
# INCDIR= /usr/include
|
||||
#
|
||||
|
||||
#INCDIR= /usr/local/include
|
||||
#INCDIR= ${PREFIX}/include
|
||||
#INCDIR= /dev/env/DJDIR/include
|
||||
INCDIR= /usr/include
|
||||
|
||||
# where to install calc realted things
|
||||
# where to install calc related things
|
||||
#
|
||||
# ${BINDIR} where to install calc binary files
|
||||
# ${LIBDIR} where calc link library (*.a) files are installed
|
||||
@@ -91,15 +142,15 @@ INCDIR= /usr/include
|
||||
# LIBDIR= /usr/lib
|
||||
# CALC_SHAREDIR= /usr/share/calc
|
||||
#
|
||||
#BINDIR= /usr/local/bin
|
||||
#BINDIR= ${PREFIX}/bin
|
||||
#BINDIR= /dev/env/DJDIR/bin
|
||||
BINDIR= /usr/bin
|
||||
|
||||
#LIBDIR= /usr/local/lib
|
||||
#LIBDIR= ${PREFIX}/lib
|
||||
#LIBDIR= /dev/env/DJDIR/lib
|
||||
LIBDIR= /usr/lib
|
||||
|
||||
#CALC_SHAREDIR= /usr/local/lib/calc
|
||||
#CALC_SHAREDIR= ${PREFIX}/lib/calc
|
||||
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
|
||||
CALC_SHAREDIR= /usr/share/calc
|
||||
|
||||
@@ -157,28 +208,59 @@ T=
|
||||
|
||||
# Makefile debug
|
||||
#
|
||||
# Q=@ do not echo internal makefile actions (quiet mode)
|
||||
# Q= echo internal makefile actions (debug / verbose mode)
|
||||
# Q=@ do not echo internal Makefile actions (quiet mode)
|
||||
# Q= echo internal Makefile actions (debug / verbose mode)
|
||||
#
|
||||
# H=@: do not report hsrc file formation progress
|
||||
# H=@ do echo hsrc file formation progress
|
||||
#
|
||||
# S= >/dev/null 2>&1 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=@
|
||||
|
||||
# standard tools
|
||||
#
|
||||
CAT= cat
|
||||
CHMOD= chmod
|
||||
CMP= cmp
|
||||
CO= co
|
||||
CP= cp
|
||||
FMT= fmt
|
||||
MKDIR= mkdir
|
||||
MV= mv
|
||||
RM= rm
|
||||
RMDIR= rmdir
|
||||
SED= sed
|
||||
SORT= sort
|
||||
FMT= fmt
|
||||
CMP= cmp
|
||||
MKDIR= mkdir
|
||||
RMDIR= rmdir
|
||||
RM= rm
|
||||
TOUCH= touch
|
||||
MV= mv
|
||||
CP= cp
|
||||
CO= co
|
||||
TRUE= true
|
||||
|
||||
# NOTE: On some shells, echo is a builtin that does
|
||||
# not understand -n, so we call /bin/echo -n
|
||||
# directly to get around such shells.
|
||||
#
|
||||
ECHON= /bin/echo -n
|
||||
|
||||
# The ${SCRIPT} list is the list of calc shell script files (without the .calc
|
||||
# extension) which will be installed.
|
||||
#
|
||||
@@ -188,19 +270,17 @@ TRUE= true
|
||||
# To add a script:
|
||||
#
|
||||
# 1) Name the file with a .calc filename extension
|
||||
# 2) Place that file under RCS control
|
||||
# 3) Add the name, without the .calc extension to the ${SCRIPT} below
|
||||
# 4) Write out this Makefile
|
||||
# 5) Replace the ${SCRIPT} and ${SCRIPT_SRC} lines with the output of:
|
||||
# 2) Add the name, without the .calc extension to the ${SCRIPT} below
|
||||
# 3) Write out this Makefile
|
||||
# 4) Replace the SCRIPT= and SCRIPT_SRC= lines with the output of:
|
||||
#
|
||||
# make detaillist
|
||||
#
|
||||
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm \
|
||||
simple square
|
||||
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm simple \
|
||||
square
|
||||
|
||||
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc \
|
||||
piforever.calc plus.calc powerterm.calc simple.calc \
|
||||
square.calc
|
||||
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc piforever.calc \
|
||||
plus.calc powerterm.calc simple.calc square.calc
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
@@ -217,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:" $?>$@
|
||||
@@ -264,11 +350,7 @@ detaillist:
|
||||
${Q} -(echo "xxxxxxx"; \
|
||||
for i in ${SCRIPT} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
if [ ! -f RCS/$$i.calc,v ]; then \
|
||||
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
|
||||
else \
|
||||
echo $$i; \
|
||||
fi; \
|
||||
echo $$i; \
|
||||
fi; \
|
||||
done | LANG=C ${SORT}) | ${FMT} -70 | \
|
||||
${SED} -e '1s/xxxxxxx/SCRIPT=/' -e '2,$$s/^/ /' \
|
||||
@@ -277,11 +359,7 @@ detaillist:
|
||||
${Q} -(echo "xxxxxxxxxxx"; \
|
||||
for i in ${SCRIPT} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
if [ ! -f RCS/$$i.calc,v ]; then \
|
||||
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
|
||||
else \
|
||||
echo $$i.calc; \
|
||||
fi; \
|
||||
echo $$i.calc; \
|
||||
fi; \
|
||||
done | LANG=C ${SORT}) | ${FMT} -70 | \
|
||||
${SED} -e '1s/xxxxxxxxxxx/SCRIPT_SRC=/' -e '2,$$s/^/ /' \
|
||||
@@ -292,7 +370,7 @@ detaillist:
|
||||
# Home grown make dependency rules. Your system make not support
|
||||
# or have the needed tools. You can ignore this section.
|
||||
#
|
||||
# We will form a skelaton tree of *.c files containing only #include "foo.h"
|
||||
# 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.
|
||||
@@ -312,7 +390,7 @@ depend:
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
echo "$$i: $$i.calc"; \
|
||||
echo ' @$${RM} -f $$@'; \
|
||||
echo -n ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
|
||||
${ECHON} ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
|
||||
echo 'calc/calc:#!$${BINDIR}/calc:" $$?>$$@'; \
|
||||
echo ' @$${CHMOD} +x $$@'; \
|
||||
fi; \
|
||||
@@ -327,20 +405,13 @@ depend:
|
||||
${Q} ${CAT} makedep.out >> ${MAKE_FILE}
|
||||
${Q} ${RM} -f makedep.out
|
||||
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
|
||||
echo 'sample ${MAKE_FILE} was already up to date'; \
|
||||
echo 'cscript/${MAKE_FILE} was already up to date'; \
|
||||
echo 'restoring original cscript/${MAKE_FILE}'; \
|
||||
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
|
||||
else \
|
||||
${RM} -f ${MAKE_FILE}.tmp; \
|
||||
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
|
||||
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
|
||||
${CO} -l ${MAKE_FILE}; \
|
||||
fi; \
|
||||
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
|
||||
if [ -d RCS ]; then \
|
||||
echo '******************************************************'; \
|
||||
echo 'new cscript ${MAKE_FILE} formed -- need to check it in'; \
|
||||
echo '******************************************************'; \
|
||||
fi; \
|
||||
echo 'old cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
|
||||
echo 'new cscript/${MAKE_FILE} formed'; \
|
||||
echo 'try: diff -u cscript/${MAKE_FILE}.bak cscript/${MAKE_FILE}'; \
|
||||
fi
|
||||
|
||||
##
|
||||
@@ -427,7 +498,7 @@ uninstall:
|
||||
continue; \
|
||||
fi; \
|
||||
if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
|
||||
${RM} -f "${T}${SCRIPTDIR}/$$i"; \
|
||||
${RM} -f "${T}${SCRIPTDIR}/$$i"; \
|
||||
if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
|
||||
echo "cannot uninstall ${T}${SCRIPTDIR}/$$i"; \
|
||||
else \
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* fproduct - write the big Endian product of terms to a file
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
|
||||
*
|
||||
* usage:
|
||||
* fproduct filename term [term ...]
|
||||
*
|
||||
* filename where to write the product, use - for stdout
|
||||
* term ... terms to multiply
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019 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.
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* mersenne - print the value of a mersenne number
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2019 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2014,2019,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
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* piforever - print digits of pi forever (or as long as your mem/CPU allow)
|
||||
*
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* plus - add two or more arguments together
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2019 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2014,2019,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
|
||||
@@ -47,7 +47,7 @@ if (argc < 2) {
|
||||
* Since args are strings, we must eval them before using them numerically.
|
||||
*/
|
||||
sum = 0;
|
||||
for (i=1; i < argv(); ++i) {
|
||||
for (i=1; i < argc; ++i) {
|
||||
sum += eval(argv(i));
|
||||
}
|
||||
print sum;
|
||||
|
@@ -1,14 +1,22 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* powerterm - print the argument as a sum of powers of integers
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
|
||||
*
|
||||
* usage:
|
||||
* powerterm [base_limit] value
|
||||
*
|
||||
* base_limit largest base we will consider (def: 10000)
|
||||
* value value to convert into sums of powers of integers
|
||||
*
|
||||
* Copyright (C) 2001,2014,2019 Landon Curt Noll
|
||||
* Example:
|
||||
*
|
||||
* powerterm 5 1000000
|
||||
*
|
||||
* prints:
|
||||
*
|
||||
* 4^10 - 3^10 + 5^6 - 4^6 - 4^5 - 2^5
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the powerterm of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -84,7 +92,7 @@ if (base_lim <= 2^20+1) { /* 2^20 requires ~96 Megs of memory */
|
||||
}
|
||||
|
||||
/*
|
||||
* remove nestest powers
|
||||
* remove nearest powers
|
||||
*/
|
||||
while (abs(x) >= base_lim) {
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/*
|
||||
* simple - an example of a simple calc shell script
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2019 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2014,2019,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
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/usr/local/src/bin/calc/calc -q -s -f
|
||||
#!/usr/local/src/bin/calc/calc -q -p -f
|
||||
/*
|
||||
* sqaure - print the squares of input values
|
||||
* square - print the squares of input values
|
||||
*
|
||||
* Copyright (C) 2000-2007,2014,2019 Ernest Bowen
|
||||
* Copyright (C) 2000-2007,2014,2019,2021 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
|
||||
@@ -48,6 +48,8 @@
|
||||
* 1522756
|
||||
* ln(2)
|
||||
* ~.48045301391820142467
|
||||
* 2i
|
||||
* -4
|
||||
* config("mode","frac"), bernoulli(10)
|
||||
* 25/4356
|
||||
* config("mode", "hex"), 0xff
|
||||
|
13
custom.c
13
custom.c
@@ -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
|
||||
@@ -47,6 +47,11 @@
|
||||
|
||||
#endif /* CUSTOM */
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
BOOL allow_custom = FALSE; /* TRUE => custom builtins allowed */
|
||||
|
||||
|
||||
@@ -73,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 */
|
||||
@@ -196,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 */
|
||||
|
@@ -4,7 +4,7 @@ Custom calc resource files
|
||||
The following custom calc resource files are provided because they serve
|
||||
as examples of how use the custom interface. The custom interface
|
||||
allows for machine dependent and/or non-portable code to be added as
|
||||
builtins to the calc program. A few example custom functions and
|
||||
built-ins to the calc program. A few example custom functions and
|
||||
resource files are shipped with calc to provide you with examples.
|
||||
|
||||
By default, the custom builtin returns an error. Calc have been
|
||||
@@ -41,7 +41,7 @@ pzasusb8.cal
|
||||
Run custom("pzasusb8") on a standard set of data, print Endian
|
||||
related information and print value size information.
|
||||
|
||||
## 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
|
||||
|
@@ -374,12 +374,12 @@ Step 5: Write your custom function
|
||||
|
||||
One is able to set bit 8 by way of the calc command line:
|
||||
|
||||
calc -D 128
|
||||
calc -D 128
|
||||
|
||||
See the calc man page for details. One may also set that bit
|
||||
while running calc by way of the config() builtin function:
|
||||
|
||||
config("calc_debug", 128);
|
||||
config("calc_debug", 128);
|
||||
|
||||
See the help/config file for details on calc_debug.
|
||||
|
||||
|
1001
custom/Makefile
1001
custom/Makefile
File diff suppressed because it is too large
Load Diff
@@ -1,437 +0,0 @@
|
||||
#!/bin/make
|
||||
#
|
||||
# custom - makefile for calc custom routines
|
||||
#
|
||||
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
# 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
|
||||
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- 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)
|
||||
#
|
||||
#Q=
|
||||
Q=@
|
||||
|
||||
####
|
||||
# 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= /usr/local/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= /usr/local/bin
|
||||
#BINDIR= /dev/env/DJDIR/bin
|
||||
BINDIR= /usr/bin
|
||||
|
||||
#LIBDIR= /usr/local/lib
|
||||
#LIBDIR= /dev/env/DJDIR/lib
|
||||
LIBDIR= /usr/lib
|
||||
|
||||
#CALC_SHAREDIR= /usr/local/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+ -DWINDOZ 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+ -DWINDOZ
|
||||
|
||||
# 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 # windoz / Cygwin
|
||||
#
|
||||
# If in doubt, use EXT=
|
||||
#
|
||||
EXT=
|
||||
#EXT=.exe
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.12.8.2
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
LIB_EXT= .so
|
||||
LIB_EXT_VERSION= ${LIB_EXT}.${VERSION}
|
||||
|
||||
# standard tools
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
SED= sed
|
||||
MAKEDEPEND= makedepend
|
||||
GREP= egrep
|
||||
CHMOD= chmod
|
||||
FMT= fmt
|
||||
SORT= sort
|
||||
CMP= cmp
|
||||
AR= ar
|
||||
RM= rm
|
||||
TOUCH= touch
|
||||
MKDIR= mkdir
|
||||
RMDIR= rmdir
|
||||
MV= mv
|
||||
CP= cp
|
||||
CO= co
|
||||
TRUE= true
|
||||
MAKE= make
|
||||
LN= ln
|
||||
AWK= awk
|
||||
|
||||
# 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} ${CC_STATIC}
|
||||
else
|
||||
ICFLAGS= ${COMMON_CFLAGS} ${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 */
|
1394
custom/Makefile.simple
Normal file
1394
custom/Makefile.simple
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,742 +0,0 @@
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- 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: ${MAKE_FILE}
|
||||
${V} echo '=-=-=-=-= custom/${MAKE_FILE} start of $@ rule =-=-=-=-='
|
||||
${Q} ${RM} -f $@
|
||||
${Q} ${AWK} '/^#if 0/{skp=1} {if(!skp){print $$0}} /^#endif/{skp=0}' \
|
||||
${MAKE_FILE} > $@
|
||||
${Q} echo >> $@
|
||||
${Q} echo 'Makefile.simple:' >> $@
|
||||
${Q} echo ' $${Q} if [ ! -f Makefile.simple ]; then '"\\" >> $@
|
||||
${Q} echo ' $${CP} -f $${MAKE_FILE} $$@; 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 "${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)
|
||||
${Q} for i in `cd ..; ${MAKE} -f ${TOP_MAKE_FILE} h_list 2>&1 | \
|
||||
${SED} -e '/Entering directory/d' \
|
||||
-e '/Nothing to be done/d' \
|
||||
-e '/Leaving directory/d'` /dev/null; do \
|
||||
if [ "$$i" = "/dev/null" ]; then \
|
||||
continue; \
|
||||
fi; \
|
||||
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
|
||||
echo "#if !defined($$tag)" > "skel/$$i"; \
|
||||
echo "#define $$tag" >> "skel/$$i"; \
|
||||
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
|
||||
>> "skel/$$i"; \
|
||||
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
|
||||
done
|
||||
${Q} ${RM} -f skel/custom/makedep.out
|
||||
${Q} echo custom/skel formed
|
||||
${Q} echo forming custom dependency list
|
||||
${Q} :> skel/custom/makedep.out
|
||||
${Q} cd skel/custom; ${MAKEDEPEND} -I.. -w 1 -f makedep.out ${C_SRC}
|
||||
-${Q} 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} ${RM} -rf skel
|
||||
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
|
||||
echo 'custom ${MAKE_FILE} was already up to date'; \
|
||||
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
|
||||
else \
|
||||
${RM} -f ${MAKE_FILE}.tmp; \
|
||||
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
|
||||
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
|
||||
${CO} -l ${MAKE_FILE}; \
|
||||
fi ;\
|
||||
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
|
||||
if [ -d RCS ]; then \
|
||||
echo '****************************************************'; \
|
||||
echo 'new custom ${MAKE_FILE} formed -- you to check it in'; \
|
||||
echo '****************************************************'; \
|
||||
fi; \
|
||||
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*
|
||||
${V} echo remove files that are obsolete
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
${RM} -f Makefile.simple
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
-${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: ../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_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: ../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_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: ../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_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: ../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_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: ../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_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: ../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_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: ../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_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: ../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_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
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_argv - a custom function display info about its args
|
||||
*
|
||||
* Copyright (C) 1999-2006 Landon Curt Noll
|
||||
* Copyright (C) 1999-2006,2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -38,6 +38,10 @@
|
||||
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* c_argv - a custom function display info about its args
|
||||
*
|
||||
@@ -49,11 +53,11 @@
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_argv(char UNUSED *name, int count, VALUE **vals)
|
||||
c_argv(char *UNUSED(name), int count, VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
ZVALUE zfilelen; /* length of a file as a ZVALUE */
|
||||
NUMBER *filelen; /* pointer to length of a file as a NUMER */
|
||||
NUMBER *filelen; /* pointer to length of a file as a NUMBER */
|
||||
char *type; /* the name of the arg type */
|
||||
int i;
|
||||
|
||||
@@ -99,12 +103,12 @@ c_argv(char UNUSED *name, int count, VALUE **vals)
|
||||
type = "assoc";
|
||||
break;
|
||||
case V_OBJ: /* address of object structure */
|
||||
type = "ocject";
|
||||
type = "object";
|
||||
break;
|
||||
case V_FILE: /* opened file id */
|
||||
type = "file";
|
||||
break;
|
||||
case V_RAND: /* address of additive 55 random state */
|
||||
case V_RAND: /* subtractive 100 random state */
|
||||
type = "rand_state";
|
||||
break;
|
||||
case V_RANDOM: /* address of Blum random state */
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_devnull - a custom function that does nothing
|
||||
*
|
||||
* Copyright (C) 1999-2004 Landon Curt Noll
|
||||
* Copyright (C) 1999-2004,2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -39,6 +39,9 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* c_devnull - a custom function that does nothing
|
||||
*
|
||||
@@ -47,7 +50,7 @@
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_devnull(char UNUSED *name, int UNUSED count, VALUE UNUSED **vals)
|
||||
c_devnull(char *UNUSED(name), int UNUSED(count), VALUE **UNUSED(vals))
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_help - custom help function
|
||||
*
|
||||
* Copyright (C) 1999-2004 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,10 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* c_help - custom help function
|
||||
*
|
||||
@@ -58,7 +62,7 @@
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_help(char UNUSED *name, int UNUSED count, VALUE **vals)
|
||||
c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
|
||||
@@ -67,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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -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
|
||||
@@ -35,6 +35,11 @@
|
||||
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/* 2^255 */
|
||||
STATIC HALF h255[] = {
|
||||
#if BASEB == 32
|
||||
@@ -71,7 +76,7 @@ STATIC ZVALUE lastmodinv[1];
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_pmodm127(char UNUSED *name, int UNUSED count, VALUE **vals)
|
||||
c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
ZVALUE q; /* test factor */
|
||||
@@ -84,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -246,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;
|
||||
|
@@ -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
|
||||
@@ -35,6 +35,11 @@
|
||||
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* c_pzasusb8 - print numerator as a string of USB8s
|
||||
*
|
||||
@@ -47,7 +52,7 @@
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_pzasusb8(char UNUSED *name, int UNUSED count, VALUE **vals)
|
||||
c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
ZVALUE z; /* numerator of the value */
|
||||
@@ -63,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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_register - set or print a custom register value
|
||||
*
|
||||
* Copyright (C) 2007 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,10 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* registers
|
||||
*/
|
||||
@@ -76,7 +80,7 @@ init_custreg(void)
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_register(char UNUSED *name, int count, VALUE **vals)
|
||||
c_register(char *UNUSED(name), int count, VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
long reg; /* register number */
|
||||
@@ -87,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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -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,10 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* sys_info - names and values of selected #defines
|
||||
*/
|
||||
@@ -205,7 +209,7 @@ STATIC struct infoname sys_info[] = {
|
||||
(FULL)SBITS},
|
||||
{"SBYTES", "size of additive or shuffle entry in bytes", NULL,
|
||||
(FULL)SBYTES},
|
||||
{"SCNT", "length of additive 55 table in FULLs", NULL,
|
||||
{"SCNT", "length of subtractive 100 table in FULLs", NULL,
|
||||
(FULL)SCNT},
|
||||
{"SEEDXORBITS", "low bits of a55 seed devoted to xor", NULL,
|
||||
(FULL)SEEDXORBITS},
|
||||
@@ -266,7 +270,7 @@ S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
VALUE
|
||||
c_sysinfo(char UNUSED *name, int count, VALUE **vals)
|
||||
c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
|
||||
{
|
||||
VALUE result; /* what we will return */
|
||||
struct infoname *p; /* current infoname */
|
||||
@@ -298,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -316,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -365,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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -30,6 +30,10 @@
|
||||
#include "value.h"
|
||||
#include "custom.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* NOTE: See the file CUSTOM for instructions on how to add
|
||||
* custom functions.
|
||||
|
@@ -13,7 +13,7 @@ DESCRIPTION
|
||||
|
||||
This custom function will return the value:
|
||||
|
||||
q mod 2^(2^127-1)
|
||||
q mod 2^(2^127-1)
|
||||
|
||||
This custom function serves as a demonstration of how to write
|
||||
a custom function. It performs the equivalent of:
|
||||
|
13
decl.h
13
decl.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* decl - variable and function declaration macros
|
||||
*
|
||||
* Copyright (C) 2007,2014 Landon Curt Noll
|
||||
* Copyright (C) 2007,2014,2021 Landon Curt Noll
|
||||
*
|
||||
* Primary author: Landon Curt Noll
|
||||
*
|
||||
@@ -52,9 +52,9 @@
|
||||
|
||||
|
||||
/*
|
||||
* MS windoz macros
|
||||
* MS Windows macros
|
||||
*/
|
||||
#elif defined(_WIN32) || defined(WINDOZ)
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
|
||||
/* determine which type of DLL we must generate */
|
||||
@@ -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 */
|
||||
|
4
endian.c
4
endian.c
@@ -42,6 +42,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/* byte order array */
|
||||
char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
|
||||
(char)0x01, (char)0x23, (char)0x45, (char)0x67 };
|
||||
|
112
file.c
112
file.c
@@ -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
|
||||
*
|
||||
@@ -37,17 +37,24 @@
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <ctype.h>
|
||||
#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"
|
||||
#include "calcerr.h"
|
||||
#include "strl.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define READSIZE 1024 /* buffer size for reading */
|
||||
|
||||
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
|
||||
@@ -141,6 +148,7 @@ file_init(void)
|
||||
files[idnum].reading = TRUE;
|
||||
files[idnum].writing = TRUE;
|
||||
files[idnum].action = 0;
|
||||
memset(files[idnum].mode, 0, MODE_LEN+1);
|
||||
/*
|
||||
* stat the descriptor to see what we have
|
||||
*/
|
||||
@@ -148,16 +156,19 @@ file_init(void)
|
||||
size_t snprintf_len; /* malloced snprintf length */
|
||||
fp = (FILE *) fdopen(i,"r+"); /*guess mode*/
|
||||
if (fp) {
|
||||
strcpy(files[idnum].mode, "r+");
|
||||
strlcpy(files[idnum].mode, "r+",
|
||||
sizeof(files[idnum].mode));
|
||||
} else {
|
||||
fp = (FILE *) fdopen(i, "r");
|
||||
if (fp) {
|
||||
strcpy(files[idnum].mode, "r");
|
||||
strlcpy(files[idnum].mode, "r",
|
||||
sizeof(files[idnum].mode));
|
||||
files[idnum].writing = FALSE;
|
||||
} else {
|
||||
fp = (FILE *) fdopen(i, "w");
|
||||
if (fp) {
|
||||
strcpy(files[idnum].mode, "w");
|
||||
strlcpy(files[idnum].mode, "w",
|
||||
sizeof(files[idnum].mode));
|
||||
files[idnum].reading = FALSE;
|
||||
}
|
||||
else
|
||||
@@ -169,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 */
|
||||
@@ -208,22 +219,26 @@ S_FUNC void
|
||||
init_fileio(FILEIO *fiop, char *name, char *mode,
|
||||
struct stat *sbufp, FILEID id, FILE *fp)
|
||||
{
|
||||
char modestr[sizeof(fiop->mode)]; /* mode [rwa]b?\+? */
|
||||
size_t namelen; /* length of name */
|
||||
char modestr[MODE_LEN+1]; /* mode [rwa]b?\+? */
|
||||
size_t namelen; /* length of name */
|
||||
|
||||
/* clear modestr */
|
||||
memset(modestr, 0, sizeof(modestr));
|
||||
|
||||
/* allocate filename if requested */
|
||||
namelen = 0;
|
||||
if (name != NULL) {
|
||||
namelen = strlen(name);
|
||||
fiop->name = (char *)malloc(namelen + 1);
|
||||
if (fiop->name == NULL) {
|
||||
math_error("No memory for filename");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize FILEIO structure */
|
||||
if (name != NULL) {
|
||||
strncpy(fiop->name, name, namelen+1);
|
||||
strlcpy(fiop->name, name, namelen+1);
|
||||
}
|
||||
fiop->id = id;
|
||||
fiop->fp = fp;
|
||||
@@ -234,7 +249,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
|
||||
fiop->appending = FALSE;
|
||||
fiop->binary = FALSE;
|
||||
fiop->action = 0;
|
||||
fiop->mode[0] = '\0';
|
||||
memset(fiop->mode, 0, sizeof(fiop->mode));
|
||||
|
||||
/*
|
||||
* determine file open mode
|
||||
@@ -248,65 +263,65 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
|
||||
if (mode[0] == 'r') {
|
||||
|
||||
/* note read mode */
|
||||
strcpy(modestr, "r");
|
||||
strlcpy(modestr, "r", sizeof(modestr));
|
||||
fiop->reading = TRUE;
|
||||
|
||||
/* note binary mode even though mode is not used / ignored */
|
||||
if (strchr(mode, 'b') != NULL) {
|
||||
strcat(modestr, "b");
|
||||
strlcat(modestr, "b", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* note if reading and writing */
|
||||
if (strchr(mode, '+') != NULL) {
|
||||
fiop->writing = TRUE;
|
||||
strcat(modestr, "+");
|
||||
strlcat(modestr, "+", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* canonicalize write modes */
|
||||
} else if (mode[0] == 'w') {
|
||||
|
||||
/* note write mode */
|
||||
strcpy(modestr, "w");
|
||||
strlcpy(modestr, "w", sizeof(modestr));
|
||||
fiop->writing = TRUE;
|
||||
|
||||
/* note binary mode even though mode is not used / ignored */
|
||||
if (strchr(mode, 'b') != NULL) {
|
||||
strcat(modestr, "b");
|
||||
strlcat(modestr, "b", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* note if reading and writing */
|
||||
if (strchr(mode, '+') != NULL) {
|
||||
fiop->reading = TRUE;
|
||||
strcat(modestr, "+");
|
||||
strlcat(modestr, "+", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* canonicalize append modes */
|
||||
} else if (mode[0] == 'a') {
|
||||
|
||||
/* note append mode */
|
||||
strcpy(modestr, "a");
|
||||
strlcpy(modestr, "a", sizeof(modestr));
|
||||
fiop->writing = TRUE;
|
||||
fiop->appending = TRUE;
|
||||
|
||||
/* note binary mode even though mode is not used / ignored */
|
||||
if (strchr(mode, 'b') != NULL) {
|
||||
strcat(modestr, "b");
|
||||
strlcat(modestr, "b", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* note if reading and writing */
|
||||
if (strchr(mode, '+') != NULL) {
|
||||
fiop->reading = TRUE;
|
||||
strcat(modestr, "+");
|
||||
strlcat(modestr, "+", sizeof(modestr));
|
||||
}
|
||||
|
||||
/* canonicalize no I/O modes */
|
||||
} else {
|
||||
modestr[0] = '\0';
|
||||
}
|
||||
modestr[sizeof(modestr)-1] = '\0'; /* firewall */
|
||||
modestr[MODE_LEN] = '\0'; /* firewall */
|
||||
|
||||
/* record canonical open mode string */
|
||||
strncpy(fiop->mode, modestr, sizeof(fiop->mode));
|
||||
strlcpy(fiop->mode, modestr, sizeof(fiop->mode));
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +339,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
|
||||
* NOTE: This function will not return 0, 1 or 2 since they are
|
||||
* reserved for stdin, stdout, stderr. In fact, it must not
|
||||
* return 0, 1, or 2 because it will confuse those who call
|
||||
* the opensearchfiile() function
|
||||
* the opensearchfile() function
|
||||
*/
|
||||
FILEID
|
||||
openid(char *name, char *mode)
|
||||
@@ -353,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 */
|
||||
@@ -369,7 +384,7 @@ openid(char *name, char *mode)
|
||||
|
||||
|
||||
/*
|
||||
* openpathid - open the specified abse filename, or
|
||||
* openpathid - open the specified base filename, or
|
||||
* relative filename along a search path
|
||||
*
|
||||
* given:
|
||||
@@ -384,7 +399,7 @@ openid(char *name, char *mode)
|
||||
* NOTE: This function will not return 0, 1 or 2 since they are
|
||||
* reserved for stdin, stdout, stderr. In fact, it must not
|
||||
* return 0, 1, or 2 because it will confuse those who call
|
||||
* the opensearchfiile() function
|
||||
* the opensearchfile() function
|
||||
*/
|
||||
FILEID
|
||||
openpathid(char *name, char *mode, char *pathlist)
|
||||
@@ -422,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 */
|
||||
@@ -468,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 */
|
||||
@@ -493,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) {
|
||||
@@ -518,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 */
|
||||
@@ -618,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 */
|
||||
@@ -714,7 +729,7 @@ flushid(FILEID id)
|
||||
}
|
||||
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
int
|
||||
flushall(void)
|
||||
{
|
||||
@@ -730,7 +745,7 @@ flushall(void)
|
||||
}
|
||||
return err;
|
||||
}
|
||||
#endif /* Windoz free systems */
|
||||
#endif /* Windows free systems */
|
||||
|
||||
|
||||
/*
|
||||
@@ -818,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);
|
||||
@@ -912,7 +927,7 @@ printid(FILEID id, int flags)
|
||||
|
||||
if (get_open_pos(fp, &pos) < 0) {
|
||||
if (fileno(fp) > 2)
|
||||
math_str("Error while determining file position!");
|
||||
math_str("Error while determining file position!");
|
||||
math_chr(')');
|
||||
return 0;
|
||||
}
|
||||
@@ -1034,6 +1049,9 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
|
||||
case 'e':
|
||||
newmode = MODE_EXP;
|
||||
break;
|
||||
case 'n':
|
||||
newmode = MODE_ENG;
|
||||
break;
|
||||
case 'g':
|
||||
newmode = MODE_REAL_AUTO;
|
||||
break;
|
||||
@@ -1441,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 */
|
||||
@@ -1519,7 +1537,7 @@ getloc(FILEID id, ZVALUE *res)
|
||||
fp = fiop->fp;
|
||||
if (fp == NULL) {
|
||||
math_error("Bogus internal file pointer!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1678,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1692,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;
|
||||
@@ -1943,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;
|
||||
}
|
||||
@@ -2004,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;
|
||||
@@ -2082,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);
|
||||
@@ -2160,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);
|
||||
@@ -2311,7 +2329,7 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals)
|
||||
var = *vals++;
|
||||
count--;
|
||||
if (var->v_type != V_ADDR)
|
||||
math_error("Assigning to nonvariable");
|
||||
math_error("Assigning to non-variable");
|
||||
var = var->v_addr;
|
||||
subtype = var->v_subtype;
|
||||
freevalue(var);
|
||||
@@ -2704,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)
|
||||
|
9
file.h
9
file.h
@@ -32,15 +32,16 @@
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
/*
|
||||
* Definition of opened files.
|
||||
*/
|
||||
#define MODE_LEN (sizeof("rb+")-1)
|
||||
typedef struct {
|
||||
FILEID id; /* id to identify this file */
|
||||
FILE *fp; /* real file structure for I/O */
|
||||
@@ -52,7 +53,7 @@ typedef struct {
|
||||
BOOL appending; /* TRUE if also opened for appending */
|
||||
BOOL binary; /* TRUE if binary mode - mode ignored/unused */
|
||||
char action; /* most recent use for 'r', 'w' or 0 */
|
||||
char mode[sizeof("rb+")+1];/* open mode */
|
||||
char mode[MODE_LEN+1]; /* open mode */
|
||||
} FILEIO;
|
||||
|
||||
|
||||
@@ -70,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))
|
||||
|
41
fposval.c
41
fposval.c
@@ -59,16 +59,28 @@
|
||||
#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 */
|
||||
|
||||
|
||||
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 */
|
||||
@@ -84,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)
|
||||
@@ -102,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);
|
||||
}
|
||||
@@ -117,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');
|
||||
|
54
fposval.h.def
Normal file
54
fposval.h.def
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* fposval.h.def - fposval.h default macros
|
||||
*
|
||||
* Copyright (C) 2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
* Public License for more details.
|
||||
*
|
||||
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Under source code control: 2021/03/10 22;14:26
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING: For some reason fposval failed to generate values
|
||||
* so we choose these values that are hopefully OK
|
||||
*/
|
||||
|
||||
/* what are our file position & size types? */
|
||||
#undef FILEPOS_BITS
|
||||
#define FILEPOS_BITS 64
|
||||
#undef FILEPOS_LEN
|
||||
#define FILEPOS_LEN 8
|
||||
#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src))
|
||||
|
||||
#undef OFF_T_BITS
|
||||
#define OFF_T_BITS 64
|
||||
#undef OFF_T_LEN
|
||||
#define OFF_T_LEN 8
|
||||
#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src))
|
||||
|
||||
#undef DEV_BITS
|
||||
#define DEV_BITS 32
|
||||
#undef DEV_LEN
|
||||
#define DEV_LEN 4
|
||||
#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4)
|
||||
|
||||
#undef INODE_BITS
|
||||
#define INODE_BITS 64
|
||||
#undef INODE_LEN
|
||||
#define INODE_LEN 8
|
||||
#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 8)
|
20
hash.c
20
hash.c
@@ -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
|
||||
@@ -26,16 +26,24 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "have_string.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "value.h"
|
||||
#include "zrand.h"
|
||||
#include "zrandom.h"
|
||||
#include "hash.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* external hash_setup functions
|
||||
*/
|
||||
@@ -87,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,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;
|
||||
}
|
||||
@@ -167,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();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1041,7 +1049,7 @@ hash_value(int type, void *v, HASH *state)
|
||||
|
||||
default:
|
||||
math_error("hashing an unknown value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
73
have_arc4random.c
Normal file
73
have_arc4random.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* have_arc4random - Determine if we have the arc4random_buf() RNG
|
||||
*
|
||||
* 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/06 23:58:51
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage:
|
||||
* have_arc4random
|
||||
*
|
||||
* Not all enviroments have the arc4random_buf() function,
|
||||
* so this may not compile on your system.
|
||||
*
|
||||
* This prog outputs:
|
||||
*
|
||||
* HAVE_ARC4RANDOM
|
||||
* defined ==> have arc4random_buf() call
|
||||
* undefined ==> do not have arc4random_buf() call
|
||||
*/
|
||||
|
||||
#include "have_stdlib.h"
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define BUFLEN (32) /* length of the buffer to fill */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if defined(HAVE_NO_ARC4RANDOM)
|
||||
|
||||
printf("#undef HAVE_ARC4RANDOM /* no */\n");
|
||||
|
||||
#else /* HAVE_NO_ARC4RANDOM */
|
||||
|
||||
/* buffer for arc4random_buf() to fill */
|
||||
static char buf[BUFLEN];
|
||||
|
||||
arc4random_buf(buf, BUFLEN);
|
||||
printf("#define HAVE_ARC4RANDOM /* yes */\n");
|
||||
|
||||
#endif /* HAVE_NO_ARC4RANDOM */
|
||||
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
}
|
71
have_ban_pragma.c
Normal file
71
have_ban_pragma.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* have_ban_pragma.c - Determine if we have #pragma GCC poison func_name
|
||||
*
|
||||
* Copyright (C) 2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
* Public License for more details.
|
||||
*
|
||||
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Under source code control: 2021/03/08 01:02:34
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage:
|
||||
* have_ban_pragma
|
||||
*
|
||||
* Not all systems have #pragma GCC poison func_name, so this may not
|
||||
* compile on your system.
|
||||
*
|
||||
* This prog outputs several defines:
|
||||
*
|
||||
* HAVE_PRAGMA_GCC_POSION
|
||||
* defined ==> use #pragma GCC poison func_name
|
||||
* undefined ==> do not use #pragma GCC poison func_name
|
||||
*
|
||||
* NOTE: Modern clang compilers allow for 'pragma GCC poison func_name'.
|
||||
* This is NOT simply a GCC feature.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* undef UNBAN to be undefined to force use of banned.h */
|
||||
#undef UNBAN
|
||||
|
||||
/* prevent banned.h from including have_ban_pragma.h */
|
||||
#define PRE_HAVE_BAN_PRAGMA_H
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if defined(HAVE_NO_PRAGMA_GCC_POSION)
|
||||
|
||||
printf("#undef HAVE_PRAGMA_GCC_POSION /* no */\n");
|
||||
|
||||
#else /* HAVE_NO_PRAGMA_GCC_POSION */
|
||||
|
||||
printf("#define HAVE_PRAGMA_GCC_POSION /* yes */\n");
|
||||
|
||||
#endif /* HAVE_NO_PRAGMA_GCC_POSION */
|
||||
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
}
|
@@ -33,7 +33,7 @@
|
||||
* This prog outputs several defines:
|
||||
*
|
||||
* HAVE_CONST
|
||||
* defined ==> ok to use const
|
||||
* defined ==> OK to use const
|
||||
* undefined ==> do not use const
|
||||
*
|
||||
* CONST
|
||||
@@ -41,9 +41,12 @@
|
||||
* (nothing) ==> const not used
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
71
have_environ.c
Normal file
71
have_environ.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* have_environ - Determine if we have the environ user environment synbol
|
||||
*
|
||||
* 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/06 19:34:32
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage:
|
||||
* have_environ
|
||||
*
|
||||
* Not all enviroments have the user environment external:
|
||||
*
|
||||
* extern char **environ;
|
||||
*
|
||||
* so this may not compile on your system.
|
||||
*
|
||||
* This prog outputs:
|
||||
*
|
||||
* HAVE_ENVIRON
|
||||
* defined ==> environ is an non-NULL extern symbol
|
||||
* undefined ==> environ is NOT an extern symbol or is NULL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if defined(HAVE_NO_ENVIRON)
|
||||
|
||||
printf("#undef HAVE_ENVIRON /* no */\n");
|
||||
|
||||
#else /* HAVE_NO_ENVIRON */
|
||||
|
||||
extern char **environ;
|
||||
|
||||
if (environ == NULL) {
|
||||
printf("#define HAVE_ENVIRON /* no */\n");
|
||||
} else {
|
||||
printf("#define HAVE_ENVIRON /* yes */\n");
|
||||
}
|
||||
|
||||
#endif /* HAVE_NO_ENVIRON */
|
||||
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* have_fpos - Determine if have fgetpos and fsetpos functions
|
||||
*
|
||||
* Copyright (C) 1999 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,19 +25,22 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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>
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if !defined(HAVE_NO_FPOS)
|
||||
#if !defined(HAVE_NO_FGETSETPOS)
|
||||
fpos_t pos; /* file position */
|
||||
|
||||
/* get the current position */
|
||||
@@ -46,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); */
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* have_fpos_pos - Determine if a __pos element in FILEPOS
|
||||
*
|
||||
* Copyright (C) 2000 Landon Curt Noll
|
||||
* Copyright (C) 2000,2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -24,44 +24,55 @@
|
||||
* 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 "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
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 %d\n", sizeof(pos.__pos)*8);
|
||||
printf("#define FPOS_POS_LEN %d\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;
|
||||
|
@@ -38,12 +38,17 @@
|
||||
* undefined ==> do not or cannot call getpgid()
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "have_unistd.h"
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user