mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
391 Commits
2.12.8.0
...
prod-2.15.
Author | SHA1 | Date | |
---|---|---|---|
|
ddf0c8f1f5 | ||
|
d52cbcea14 | ||
|
d14d525a6a | ||
|
698f73cd3e | ||
|
e1888d9b9e | ||
|
b54f68a797 | ||
|
77d7e665e0 | ||
|
e96ef61718 | ||
|
0eee1a615d | ||
|
d2025c5f24 | ||
|
801dad8f57 | ||
|
5a227873e5 | ||
|
915054391e | ||
|
4b7ba942ee | ||
|
42129a3672 | ||
|
db582d6e34 | ||
|
fec9712b9a | ||
|
68e1914ee7 | ||
|
2c4abcd2b7 | ||
|
26fc394089 | ||
|
c78a893862 | ||
|
5d62e58704 | ||
|
ab95e47c0a | ||
|
db80afb843 | ||
|
70a8225c0b | ||
|
5fbb0ad2ea | ||
|
b741e98b13 | ||
|
066bb78f0e | ||
|
1a898caf3f | ||
|
120527d375 | ||
|
39429e370c | ||
|
ff90bc0e3a | ||
|
5e5656652f | ||
|
3b9393a8ac | ||
|
40c8f875c1 | ||
|
d943fda3eb | ||
|
a6824debbc | ||
|
1507adb261 | ||
|
229a60e4d5 | ||
|
19819340ff | ||
|
4c65986502 | ||
|
81eb6eac11 | ||
|
bf730f5518 | ||
|
a722b5cca7 | ||
|
78d536140f | ||
|
8caa8d8635 | ||
|
d8603d3980 | ||
|
3fd55f0431 | ||
|
b67e20881a | ||
|
c153ac08b9 | ||
|
fdbf53d7e8 | ||
|
ea5b5e0b53 | ||
|
3abedd6713 | ||
|
ed112997a7 | ||
|
86f1d9e029 | ||
|
8edff80826 | ||
|
b55d41c221 | ||
|
df11a211c9 | ||
|
20ce75a06d | ||
|
7398fbb2e9 | ||
|
b0a48a2b70 | ||
|
1c839dfede | ||
|
4787199462 | ||
|
b95a62c14e | ||
|
e021e2130f | ||
|
94d4c1ad64 | ||
|
5659ddbc4e | ||
|
faa93bf085 | ||
|
0d2d5e3df3 | ||
|
969e72b5c6 | ||
|
4dbc4dfe9a | ||
|
4e5fcc8812 | ||
|
56c568060a | ||
|
61206172f1 | ||
|
0bb66cff74 | ||
|
0353aba275 | ||
|
2d5339fc51 | ||
|
6abdd8ef3f | ||
|
8c6d2b2e07 | ||
|
999ad61a78 | ||
|
1cf05b660c | ||
|
4fddf82106 | ||
|
b0aa949ad5 | ||
|
3c18e6e25b | ||
|
e18b715f3f | ||
|
a0687079f4 | ||
|
91c0c99a2c | ||
|
a7597cdf6f | ||
|
4b5c0e7574 | ||
|
f60a1d6bc5 | ||
|
f2e4f638f6 | ||
|
c705b74e67 | ||
|
5a117d542a | ||
|
ea57d2f24f | ||
|
7ad1448a1a | ||
|
96f925bede | ||
|
8055bf07c2 | ||
|
28449fd187 | ||
|
d88b128b2d | ||
|
bc048bc029 | ||
|
4d32b138ed | ||
|
3cd8fd7053 | ||
|
b0f19c1011 | ||
|
fe520975cf | ||
|
f097dd7dc1 | ||
|
3a7e763b28 | ||
|
661e99829e | ||
|
faf3a4fab6 | ||
|
7d8d4cb5ea | ||
|
af9b052fe9 | ||
|
40f8654aa4 | ||
|
92c8d89ed1 | ||
|
1e2d02e449 | ||
|
e0df1646fc | ||
|
ee900ec6ec | ||
|
6ee34e709d | ||
|
f81d67b322 | ||
|
21ab25d1c9 | ||
|
06dcb3e51e | ||
|
6e0e48e17e | ||
|
f416973a31 | ||
|
b408b59d8d | ||
|
77405e1d84 | ||
|
da623e13cb | ||
|
f025dcf0d8 | ||
|
3bfcaae767 | ||
|
bf5b56d263 | ||
|
0b044ce972 | ||
|
e2686911ae | ||
|
544b873914 | ||
|
948d9e807b | ||
|
6d020b7fbe | ||
|
9fcdd80549 | ||
|
3148ce06a0 | ||
|
945977f1f4 | ||
|
b03e71f0ce | ||
|
db799aac10 | ||
|
adecf7d76e | ||
|
94bf264088 | ||
|
80e841eded | ||
|
3f78fc20d7 | ||
|
c26460b255 | ||
|
3ec7b39366 | ||
|
49c599aec9 | ||
|
a582511002 | ||
|
e05d904821 | ||
|
ccd579ecda | ||
|
15be1dec4d | ||
|
f34c659877 | ||
|
2ad27e7909 | ||
|
a4d3c8ff9d | ||
|
bd64a6cc36 | ||
|
e2b2976d18 | ||
|
3ea51ea937 | ||
|
5fa732b869 | ||
|
6a54caf1c2 | ||
|
cce930987b | ||
|
7c806f13ea | ||
|
616bcd8d46 | ||
|
36a1a042f3 | ||
|
75159fcbc2 | ||
|
8ef7b5311e | ||
|
d5a11b3df4 | ||
|
74c299ad4e | ||
|
d89ea78104 | ||
|
644b348bcb | ||
|
11ddc30528 | ||
|
f5fc06fbd4 | ||
|
8a4c12d2be | ||
|
d2139064cb | ||
|
774060944b | ||
|
61c268f1c2 | ||
|
dcf360d688 | ||
|
fddd24d6c6 | ||
|
bcae90959e | ||
|
5b42c557b0 | ||
|
1b0e6c4462 | ||
|
f0396fccde | ||
|
21be7adb82 | ||
|
6317991f2b | ||
|
f4f19f21dc | ||
|
348f3ed427 | ||
|
542a263de6 | ||
|
17702a4799 | ||
|
7c6723db88 | ||
|
0d99ba54d8 | ||
|
83adfaa720 | ||
|
ef6a30c9c9 | ||
|
3aaad95443 | ||
|
74b833977b | ||
|
333f0c4332 | ||
|
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 | ||
|
0aca07d278 | ||
|
1ab3b2c313 | ||
|
64e2c6a262 | ||
|
eac02835ed | ||
|
33657bb2cc | ||
|
8af0b351ae | ||
|
3260f90a73 |
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@v2
|
||||
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@v2
|
||||
|
||||
# ℹ️ 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@v2
|
12
.github/workflows/dependabot.yml
vendored
Normal file
12
.github/workflows/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
#
|
||||
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
127
.gitignore
vendored
127
.gitignore
vendored
@@ -1,63 +1,133 @@
|
||||
# generic excluded patterns
|
||||
#
|
||||
# We sort the list below via: sort -u -f
|
||||
#
|
||||
*,v
|
||||
*.BAK
|
||||
*.dSYM/
|
||||
*.exe
|
||||
*.o.tmp
|
||||
*.[oa]
|
||||
*~
|
||||
.*.swp
|
||||
.DS_Store
|
||||
core*
|
||||
|
||||
# files and directories created during the building of calc and other Makefile actions
|
||||
#
|
||||
# NOTE: While many of these might be part of a released calc tarball, they are
|
||||
# not consider development source. Some other file(s) and/or programs
|
||||
# generate these files.
|
||||
#
|
||||
# We sort the list below via: sort -u -f
|
||||
#
|
||||
.dynamic
|
||||
.hsrc
|
||||
Makefile.simple
|
||||
NOTES
|
||||
.static
|
||||
align32
|
||||
align32.h
|
||||
align32_tmp
|
||||
arc4random_tmp
|
||||
args.h
|
||||
cal/.all
|
||||
cal/test082.cal
|
||||
calc
|
||||
calc-static
|
||||
calc.1
|
||||
calc.spec
|
||||
calc.usage
|
||||
calcerr.c
|
||||
calcerr.h
|
||||
charbit.h
|
||||
chatbit
|
||||
chk_c
|
||||
conf.h
|
||||
const_tmp
|
||||
cscript/.all
|
||||
cscript/4dsphere
|
||||
cscript/README
|
||||
cscript/fproduct
|
||||
cscript/mersenne
|
||||
cscript/piforever
|
||||
cscript/plus
|
||||
cscript/powerterm
|
||||
cscript/README
|
||||
cscript/simple
|
||||
cscript/square
|
||||
custom/.all
|
||||
custom/Makefile.simple
|
||||
custom/libcustcalc*
|
||||
debug.out
|
||||
endian
|
||||
endian_calc.h
|
||||
environ_tmp
|
||||
errcode
|
||||
errsym.h
|
||||
fposval
|
||||
fposval.h
|
||||
fposval_tmp
|
||||
fpos_tmp
|
||||
func.show
|
||||
func.sort
|
||||
getpgid_tmp
|
||||
getprid_tmp
|
||||
getsid_tmp
|
||||
gettime_tmp
|
||||
have_arc4random
|
||||
have_arc4random.h
|
||||
have_ban_pragma
|
||||
have_ban_pragma.h
|
||||
have_const
|
||||
have_const.h
|
||||
have_fpos.h
|
||||
have_environ
|
||||
have_environ.h
|
||||
have_fgetsetpos.h
|
||||
have_fpos
|
||||
have_fpos_pos
|
||||
have_fpos_pos.h
|
||||
have_getpgid
|
||||
have_getpgid.h
|
||||
have_getprid
|
||||
have_getprid.h
|
||||
have_getsid
|
||||
have_getsid.h
|
||||
have_gettime
|
||||
have_gettime.h
|
||||
have_inttypes.h
|
||||
have_limits.h
|
||||
have_memmv
|
||||
have_memmv.h
|
||||
have_newstr
|
||||
have_newstr.h
|
||||
have_offscl
|
||||
have_offscl.h
|
||||
have_posscl
|
||||
have_posscl.h
|
||||
have_rusage
|
||||
have_rusage.h
|
||||
have_statfs
|
||||
have_statfs.h
|
||||
have_stdbool.h
|
||||
have_stdint.h
|
||||
have_stdlib.h
|
||||
have_stdvs
|
||||
have_strdup
|
||||
have_strdup.h
|
||||
have_string.h
|
||||
have_strlcat
|
||||
have_strlcat.h
|
||||
have_strlcpy
|
||||
have_strlcpy.h
|
||||
have_sys_mount.h
|
||||
have_sys_param.h
|
||||
have_sys_vfs.h
|
||||
have_times.h
|
||||
have_uid_t
|
||||
have_uid_t.h
|
||||
have_unistd.h
|
||||
have_unused
|
||||
have_unused.h
|
||||
have_urandom.h
|
||||
have_ustat
|
||||
have_ustat.h
|
||||
have_varvs
|
||||
help/.all
|
||||
help/COPYING
|
||||
help/COPYING-LGPL
|
||||
help/binding
|
||||
help/bindings
|
||||
help/bug
|
||||
@@ -67,6 +137,8 @@ help/change
|
||||
help/changes
|
||||
help/contrib
|
||||
help/copy
|
||||
help/COPYING
|
||||
help/COPYING-LGPL
|
||||
help/cscript
|
||||
help/custom_cal
|
||||
help/errorcode
|
||||
@@ -74,30 +146,41 @@ help/errorcodes
|
||||
help/full
|
||||
help/funclist
|
||||
help/funclist.c
|
||||
help/ilogn
|
||||
help/libcalc
|
||||
help/man
|
||||
help/new_custom
|
||||
help/question
|
||||
help/questions
|
||||
help/releases
|
||||
help/resource
|
||||
help/type
|
||||
help/usage
|
||||
libcalc*
|
||||
libcustcalc*
|
||||
libcalc.*
|
||||
libcustcalc.*
|
||||
ll_tmp
|
||||
longbits
|
||||
longbits.h
|
||||
Makefile.our
|
||||
memmv_tmp
|
||||
newstr_tmp
|
||||
NOTES
|
||||
offscl_tmp
|
||||
outfile
|
||||
posscl_tmp
|
||||
rusage_tmp
|
||||
sample_many
|
||||
sample_many-static
|
||||
sample_rand
|
||||
sample_rand-static
|
||||
statfs_tmp
|
||||
status.chk_c.h
|
||||
strdup_tmp
|
||||
tags
|
||||
terminal.h
|
||||
uid_tmp
|
||||
unused_tmp
|
||||
ustat_tmp
|
||||
ver_calc
|
||||
|
||||
# other commonly excluded patterns
|
||||
#
|
||||
*~
|
||||
*.BAK
|
||||
core*
|
||||
.DS_Store
|
||||
*.dSYM/
|
||||
*.[oa]
|
||||
.*.swp
|
||||
*,v
|
||||
vs_tmp
|
||||
win32/
|
||||
|
23
.lldbinit
Normal file
23
.lldbinit
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# lldb calc
|
||||
#
|
||||
# IMPORTANT: Under macOS, use this local ./lldbinit file, your home directory file:
|
||||
#
|
||||
# ~/.lldbinit
|
||||
#
|
||||
# must contain this line (w/o the leading # and whitespace):
|
||||
#
|
||||
# settings set target.load-cwd-lldbinit true
|
||||
#
|
||||
# Optimizing calc may make it harder to trace what calc is doing,
|
||||
# To turn off optimization while debugging, try:
|
||||
#
|
||||
# make clobber all DEBUG="-g3"
|
||||
#
|
||||
# To debug calc with lldb from this directory, just run:
|
||||
#
|
||||
# lldb
|
||||
#
|
||||
target create "./calc"
|
||||
process launch -tty --environment CALCPATH=./cal --environment LD_LIBRARY_PATH=. --environment DYLD_LIBRARY_PATH=. --environment CALCHELP=./help --environment CALCCUSTOMHELP=./custom -- -q -d
|
||||
b main
|
135
BUGS
135
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 changes 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
|
||||
|
||||
@@ -42,44 +60,7 @@ GitHub web page, click on this button:
|
||||
|
||||
((New Issue))
|
||||
|
||||
=-=
|
||||
|
||||
If you prefer to not use GitHub, then you
|
||||
may send bug and bug fixes reports to:
|
||||
|
||||
calc-bugrept-mail at asthe dot com
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
NOTE: This replaces the old calc-bugs at asthe dot com address.
|
||||
|
||||
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
|
||||
|
||||
calc bug report
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
PLEASE use the above SPECIAL PHRASE somewhere in the Subject line or
|
||||
the mail system won't deliver your Email message.
|
||||
|
||||
Keep in mind that the best way to report on a calc bug is
|
||||
via the above mentioned calc GitHub issue URL.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
=-=
|
||||
|
||||
When you send your report, via the calc GitHub issue URL or Email,
|
||||
please include the following information:
|
||||
Please include the following information in the new issue:
|
||||
|
||||
* A description of the problem
|
||||
|
||||
@@ -105,69 +86,22 @@ please include the following information:
|
||||
* If calc dumped core, try to send us a core dump stack trace
|
||||
|
||||
* cd to the calc source directory, and send the contents
|
||||
of debug.out produced by this command:
|
||||
of debug.out.txt produced by this command:
|
||||
|
||||
make debug > debug.out 2>&1
|
||||
make debug
|
||||
|
||||
Fell free to use the above address to send in bug fixes (in the form
|
||||
of a context diff patch).
|
||||
PLEASE attach the debug.out.txt file to your GitHub issue (bug report)!!
|
||||
|
||||
Please be patient as we cannot always respond to pull requests quickly.
|
||||
|
||||
=-=
|
||||
|
||||
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
|
||||
@@ -222,9 +156,18 @@ mis-features in calc:
|
||||
|
||||
will not.
|
||||
|
||||
* The numerator is assumed
|
||||
|
||||
The numerator value of 1 appears to be assumed. In calc:
|
||||
|
||||
/ 2
|
||||
|
||||
will produce a value of 0.5 as if the numerator 1 was given.
|
||||
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 1999-2014,2021 Landon Curt Noll
|
||||
## Copyright (C) 1999-2014,2021,2023 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
128
CODE_OF_CONDUCT.md
Normal file
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.
|
72
CONTRIB-CODE
72
CONTRIB-CODE
@@ -1,73 +1,37 @@
|
||||
Calc is open source. Contributions of code are welcome.
|
||||
|
||||
We welcome and encourage you to send us:
|
||||
In order to consider integrating your contributions, we need:
|
||||
|
||||
* calc resource files (cal/*.cal files)
|
||||
* calc shell scripts (cscript/*.calc files)
|
||||
* builtin functions that you have modified or written, i.e.:
|
||||
assocfunc.c comfunc.c func.c func.h
|
||||
listfunc.c matfunc.c qfunc.c zfunc.c
|
||||
* custom functions that you have modified or written
|
||||
* help files modified or written (help/*)
|
||||
* Makefile improvements (Makefile, */Makefile)
|
||||
* other source code modifications (*.c, *.h)
|
||||
* etc. (* */* :) )
|
||||
* your changes applied agsinst the top of the calc master branch:
|
||||
|
||||
In order to consider integrating your code, we need:
|
||||
https://github.com/lcn2/calc/
|
||||
|
||||
* calc version you are working with (please try use the latest version)
|
||||
* new help files or help file patches, if applicable (documentation)
|
||||
* proposed text for the CHANGES file (brief description of what it does)
|
||||
* regress.cal test patch as needed
|
||||
* your source code and/or source code changes (:-))
|
||||
|
||||
If you add functionality to calc, please be sure to modify/patch/add
|
||||
* Update CHANGES file (brief description of what it does)
|
||||
|
||||
* regress.cal test patch as needed
|
||||
|
||||
If you add functionality to calc, please be sure to modify
|
||||
Makefiles, help files, cal/regress.cal test code as well.
|
||||
Regression test cases are vital to maintaining calc's level
|
||||
of correctness and helps us avoid code bug regression.
|
||||
|
||||
Please try to generate a patch against the most recent
|
||||
version of calc, and if you use GitHub, the top of the
|
||||
master branch:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
The best way contribute to calc bug is to generate calc
|
||||
GitHub pull request:
|
||||
GitHub pull request against the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
Please be patient as we cannot always respond pull requests quickly.
|
||||
|
||||
=-=
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
Your code needs to be contributed under either the 2.1 of the GNU
|
||||
Lesser General Public License (LGPL 2.1) or in the public domain.
|
||||
Lesser General Public License (LGPL 2.1) or under "The Unlicense":
|
||||
|
||||
If you do not want to use calc GitHub, then send Email to:
|
||||
|
||||
calc-contrib-mail at asthe dot com
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
You MUST use following SPECIAL PHRASE in your Email Subject line:
|
||||
|
||||
calc contribution
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
|
||||
|
||||
IMPORTANT: If your Email doesn't contain the above phrase,
|
||||
then we WILL NOT SEE your Email.
|
||||
|
||||
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
|
||||
|
||||
Keep in mind that the best way to report on a calc bug is to use
|
||||
the above mentioned calc GitHub procedure.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
https://unlicense.org
|
||||
|
||||
=-=
|
||||
|
||||
@@ -77,7 +41,7 @@ See also the calc wishlist by running the calc command:
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 1999,2014,2021 Landon Curt Noll
|
||||
## Copyright (C) 1999,2014,2021,2023 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
|
||||
|
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.
|
55
COPYING
55
COPYING
@@ -1,12 +1,12 @@
|
||||
calc - arbitrary precision calculator
|
||||
|
||||
|
||||
This file is Copyrighted
|
||||
------------------------
|
||||
|
||||
This file is not covered under version 2.1 of the GNU LGPL.
|
||||
This file is covered under the following Copyright:
|
||||
|
||||
Copyright (C) 1999-2021 Landon Curt Noll
|
||||
Copyright (C) 1999-2023 Landon Curt Noll
|
||||
All rights reserved.
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
@@ -75,8 +75,8 @@ Calc's relationship to the GNU Lesser General Public License
|
||||
Clearly all files that go into the creation of those binary link
|
||||
libraries are covered under the License.
|
||||
|
||||
The ``scripts used to control compilation and installation of the
|
||||
of the library'' include:
|
||||
The "scripts used to control compilation and installation of the
|
||||
of the library" include:
|
||||
|
||||
* Makefiles
|
||||
* source files created by the Makefiles
|
||||
@@ -84,7 +84,7 @@ Calc's relationship to the GNU Lesser General Public License
|
||||
|
||||
All of those files are covered under the License.
|
||||
|
||||
The ``associated interface definition files'' are those files that:
|
||||
The "associated interface definition files" are those files that:
|
||||
|
||||
* show how the calc binary link libraries are used
|
||||
* test the validity of the binary link libraries
|
||||
@@ -99,9 +99,9 @@ Calc's relationship to the GNU Lesser General Public License
|
||||
* files under the lib sub-directory
|
||||
* the main calc.c file
|
||||
|
||||
The ``complete source code'' includes ALL files shipped with calc,
|
||||
except for the exception files explicitly listed in the ``Calc
|
||||
copyrights and exception files'' section below.
|
||||
The "complete source code" includes ALL files shipped with calc,
|
||||
except for the exception files explicitly listed in the "Calc
|
||||
copyrights and exception files" section below.
|
||||
|
||||
-=-
|
||||
|
||||
@@ -120,11 +120,13 @@ Calc copyrights and exception files
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||
Copyright (C) year Christoph Zurnieden
|
||||
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
|
||||
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
|
||||
|
||||
These files are not covered under one of the Copyrights listed above:
|
||||
|
||||
sha1.c sha1.h COPYING
|
||||
COPYING-LGPL cal/qtime.cal cal/screen.cal
|
||||
COPYING-LGPL cal/screen.cal
|
||||
|
||||
The file COPYING-LGPL, which contains a copy of the version 2.1
|
||||
GNU Lesser General Public License, is itself Copyrighted by the
|
||||
@@ -136,8 +138,39 @@ Calc copyrights and exception files
|
||||
top of this file. It is important to note that you may distribute
|
||||
verbatim copies of this file but you may not modify this file.
|
||||
|
||||
Some of these exception files are in the public domain. Other files
|
||||
are under the LGPL but have different authors that those listed above.
|
||||
These files are covered under "The Unlicense":
|
||||
|
||||
sha1.c
|
||||
sha1.h
|
||||
cal/dotest.cal
|
||||
cal/screen.cal
|
||||
|
||||
"The Unlicense" is as follows:
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
In all cases one may use and distribute these exception files freely.
|
||||
And because one may freely distribute the LGPL covered files, the
|
||||
|
460
HOWTO.INSTALL
460
HOWTO.INSTALL
@@ -1,204 +1,390 @@
|
||||
Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
# Installing a pre-compiled calc from an RPM
|
||||
|
||||
0) If your platform supports i686 RPMs, you may want to go to:
|
||||
If your platform supports RPMs, you may want to go to:
|
||||
|
||||
http://www.isthe.com/chongo/src/calc/
|
||||
https://github.com/lcn2/calc/releases
|
||||
|
||||
and use these RPMs:
|
||||
and see if there is a pre-compiled version of calc that you may install.
|
||||
|
||||
* calc*.i686.rpm
|
||||
- all that is needed if you just want to use calc
|
||||
Open up the 'Assets' tag below a given release and download these RPMs:
|
||||
|
||||
* calc-devel-*.i686.rpm
|
||||
- calc *.h header and *.a lib files for use in other programs
|
||||
* calc*.rpm
|
||||
|
||||
* calc.*.src.rpm
|
||||
- calc source in RPM package form
|
||||
- all that is needed if you just want to use calc
|
||||
|
||||
The following 4 steps apply to calc source tree that comes from either:
|
||||
If your platform supports rpm and matches one of the "calc*.rpm" files, you
|
||||
may just install that "calc*.rpm". For exammple on an x86_64 system:
|
||||
|
||||
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
||||
dnf install calc-x.y.z.cv-ww.x86_64.rpm
|
||||
|
||||
or from:
|
||||
where "calc-x.y.z.cv-ww.x86_64.rpm" is the name of the calc RPM.
|
||||
|
||||
rpm -ivh calc-*.src.rpm
|
||||
cd /var/tmp
|
||||
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
|
||||
In addition, if your platform supports rpm and matches one of the
|
||||
"calc*.rpm" files, you may also install the calc *.h header and *.a lib
|
||||
files for use in other programs:
|
||||
|
||||
1) Look at the makefile, and adjust it to suit your needs.
|
||||
* calc-devel-*.rpm
|
||||
|
||||
The top level Makefile and the custom/Makefile require a GNU
|
||||
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.
|
||||
- calc *.h header and *.a lib files for use in other programs
|
||||
|
||||
Some report that under macOS, one has to declare the target
|
||||
to be darwin. So for macOS, one might have to do:
|
||||
Alternately to the above github link, you might try looking at the RPMs under:
|
||||
|
||||
# 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
|
||||
http://www.isthe.com/chongo/src/calc/
|
||||
|
||||
If your target system does not have GNU Make (or equivalent), then
|
||||
you should try using the Makefile.simple and custom/Makefile.simple
|
||||
files:
|
||||
|
||||
mv Makefile Makefile.gmake
|
||||
cp Makefile.simple Makefile
|
||||
mv custom/Makefile custom/Makefile.gmake
|
||||
cp custom/Makefile.simple custom/Makefile
|
||||
|
||||
The Makefile, as shipped, is suitable for installation under
|
||||
Linux and Un*x-like environments. For the most part, the default
|
||||
values should work. If in doubt, follow the 'When in doubt'
|
||||
suggestion.
|
||||
# Building calc from a source tree
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! If you are building under Windoz or a Windoz-like environment !
|
||||
! (such as Cygwin or DJGPP), read the README.WINDOWS file. !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
You should determine if these Makefile variables are reasonable:
|
||||
|
||||
INCDIR Where the system include (.h) files are kept.
|
||||
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.
|
||||
## Step 0: Obtain the calc source tree
|
||||
|
||||
You may want to change the default installation locations for
|
||||
these values, which are based on the 4 values listed above:
|
||||
Go to the site:
|
||||
|
||||
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
|
||||
https://github.com/lcn2/calc/releases
|
||||
|
||||
If you want to install calc files under a top level directory,
|
||||
then set the T value:
|
||||
Look for release with a file of the form:
|
||||
|
||||
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.
|
||||
calc-x.y.z.v.tar.bz2
|
||||
|
||||
For example, if:
|
||||
A release marked with a green "(Latest)" is a production release
|
||||
that as undergone a fair amount of testing.
|
||||
|
||||
BINDIR= /usr/bin
|
||||
LIBDIR= /usr/lib
|
||||
CALC_SHAREDIR= /usr/share/calc
|
||||
A release marked with an orange "(Pre-release)" is likly to be
|
||||
more stable than the top of the master branch, as they do undergo
|
||||
thru a reasonable level of regression testing, just not to
|
||||
the level of a "(Latest)" production release.
|
||||
|
||||
and if:
|
||||
Use the followig command to uncompress the bzip2 compressed tarball:
|
||||
|
||||
T= /var/tmp/testing
|
||||
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
||||
|
||||
Then the installation locations will be:
|
||||
NOTE: An alternate location for calc bzip2 compressed tarballs is:
|
||||
|
||||
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/...
|
||||
http://www.isthe.com/chongo/src/calc/
|
||||
|
||||
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.
|
||||
|
||||
Look for the section that starts:
|
||||
|
||||
################
|
||||
# compiler set #
|
||||
################
|
||||
### Obtaining the experimental top of the master branch calc source
|
||||
|
||||
Select a compiler set by commenting in the appropriate set
|
||||
of cc options. As shipped the Makefile assumes a gcc-like
|
||||
environment such as Linux. If a more appropriate cc set if
|
||||
found below, comment out the Linux set and comment in that
|
||||
set or edit the gcc set or the common cc set as needed.
|
||||
You may also fetch the top of the master branch of the GitHub repo
|
||||
if you wish to see what the latest source code looks like:
|
||||
|
||||
You may want to change these Makefile variables from their defaults:
|
||||
git clone https://github.com/lcn2/calc.git
|
||||
|
||||
RANLIB
|
||||
IMPORTANT:
|
||||
|
||||
You may or may not need RANLIB when building libraries.
|
||||
As shipped the Makefile assumes RANLIB is needed.
|
||||
Comment the in/out the RANLIB value if ranlib does
|
||||
not work or does not exist.
|
||||
The latest source code may be "experimental in nature". You may be
|
||||
better off using a released bzip2 compressed tarball instead.
|
||||
Released bzip2 compressed tarballs tend to be more well tested
|
||||
than the top of the master branch.
|
||||
|
||||
CALCPAGER
|
||||
|
||||
You may want to change the default pager used by calc.
|
||||
As shipped the Makefile assumes 'more'. On your system
|
||||
you may find 'less' to be a better pager.
|
||||
|
||||
DEBUG
|
||||
## Step 1: Makefile considerations
|
||||
|
||||
Some compilers (to put it mildly) have bugs. Sometimes the
|
||||
DEBUG Makefile variable causes the compiler / optimizer to
|
||||
produce bad code. Other compilers do just fine.
|
||||
|
||||
If possible try to use DEBUG=-O3 -g3 (maximum optimization
|
||||
and debug symbols). If the calc test fails (see step 3),
|
||||
try lowering either the -O value and/or the -g3. Also try
|
||||
using -Osomething without -g.
|
||||
### IMPORTANT: Make support of conditional syntax required:
|
||||
|
||||
Adjust other Makefile variables as needed.
|
||||
To compile calc, you must use a make that supports the use of
|
||||
"Conditional syntax". As nearly all modern make tools
|
||||
support "Conditional syntax", thus should not be a problem
|
||||
for you. If for some reason your make tool does not support
|
||||
"Conditional syntax", consider upgraded to a make that does,
|
||||
such as the Gnu Make tool:
|
||||
|
||||
2) build calc:
|
||||
https://www.gnu.org/software/make/
|
||||
|
||||
The top level Makefile and the custom/Makefile require a GNU
|
||||
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.
|
||||
The Gnu Make is not required per-se, just a modern make tool
|
||||
that supports "Conditional syntax".
|
||||
|
||||
If your target system does not have GNU Make (or equivalent), then
|
||||
you should try using the Makefile.simple and custom/Makefile.simple
|
||||
files:
|
||||
|
||||
mv Makefile Makefile.gmake
|
||||
cp Makefile.simple Makefile
|
||||
mv custom/Makefile custom/Makefile.gmake
|
||||
cp custom/Makefile.simple custom/Makefile
|
||||
### Review Makefiles
|
||||
|
||||
make all
|
||||
Review Makefile.config and Makefile.target.
|
||||
|
||||
==> We are interested in any compiler warnings (and errors) that
|
||||
you may find. See the BUGS file if you find any compiler
|
||||
warning or errors.
|
||||
If you are curious, review Makefile as well, although
|
||||
there may be little in the main Makefile that you may
|
||||
want to change.
|
||||
|
||||
NOTE: You can force calc to build with only static libs:
|
||||
Consider modifying Makefile.local by replace values or
|
||||
appending values found in Makefile.config and Makefile.target.
|
||||
|
||||
make clobber
|
||||
make calc-static-only BLD_TYPE=calc-static-only
|
||||
If you are adding custom functions, review custom/Makefile
|
||||
and modify custom/Makefile as needed.
|
||||
|
||||
or force calc to build with only dynamic libs:
|
||||
|
||||
make clobber
|
||||
make calc-dynamic-only BLD_TYPE=calc-dynamic-only
|
||||
|
||||
3) test calc:
|
||||
### Suggestion: Modify Makefile.local
|
||||
|
||||
make check
|
||||
All Makefiles include Makefile.local just before the
|
||||
first and default all rule. So Makefile.local may be
|
||||
used to modify, replace or append values to Makefile variables.
|
||||
|
||||
==> If you run into problems, read the BUGS file and follow
|
||||
the instructions found in there.
|
||||
In most cases, to change the way that calc is made, consider
|
||||
adding lines to Makefile.local instead of modifying other Makefiles.
|
||||
|
||||
NOTE: For a quiet check which only prints if something goes wrong:
|
||||
A recommended way to adjust it is to add lines to: Makefile.local
|
||||
using the := syntax to replace values such as:
|
||||
|
||||
make chk
|
||||
DEBUG:= -O0 -g
|
||||
|
||||
4) install calc:
|
||||
or by using the += syntax to append to values such as:
|
||||
|
||||
make install
|
||||
DEBUG+= -ipa
|
||||
|
||||
You can, of course, modify other Makefiles. We only
|
||||
suggest using Makefile.local to minimize the number
|
||||
of source files you modify.
|
||||
|
||||
And finally, you can always just add arguments to your
|
||||
make command line instead of modifying a Makefile. For example:
|
||||
|
||||
make clobber all DEBUG="-O0 -g"
|
||||
|
||||
|
||||
## readline package assumed by default:
|
||||
|
||||
By "readline package" we refer to the combination of the
|
||||
readline library, the history library, and the ncurses library.
|
||||
|
||||
By default, calc assumes you have the readline package installed.
|
||||
The readline package (-lreadline, -lhistory, -lncurses) used by and
|
||||
linked into calc by default.
|
||||
|
||||
If your system (such as macOS) does NOT have those libaraies, then
|
||||
you have two options:
|
||||
|
||||
|
||||
|
||||
### Install the readline package:
|
||||
|
||||
We recommend that you 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/
|
||||
|
||||
|
||||
|
||||
### Compile calc without readline:
|
||||
|
||||
Why do we not recommend this option 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 compile with:
|
||||
|
||||
make clobber all USE_READLINE= READLINE_EXTRAS= READLINE_INCLUDE= READLINE_LIB=
|
||||
|
||||
or add to Makefile.local, these lines:
|
||||
|
||||
USE_READLINE=
|
||||
READLINE_EXTRAS=
|
||||
READLINE_INCLUDE=
|
||||
READLINE_LIB=
|
||||
|
||||
See the "Suggestion: Modify Makefile.local" section above for
|
||||
information on the Makefile.local file.
|
||||
|
||||
|
||||
### Windows or a Windows-like environments:
|
||||
|
||||
Currently Windows is not a well supported platform for calc. There are
|
||||
people within Microsoft who plan to assist us in being able to allow
|
||||
the standard Microsoft Windows developor environment to compile calc.
|
||||
|
||||
|
||||
|
||||
### Makefile variables to consider:
|
||||
|
||||
You should determine if these Makefile variables are reasonable:
|
||||
|
||||
INCDIR Where the system include (.h) files are kept.
|
||||
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.
|
||||
|
||||
You may want to change the default installation locations for
|
||||
these values, which are based on the 4 values listed above:
|
||||
|
||||
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
|
||||
|
||||
If you want to install calc files under a top level directory, then set the T value:
|
||||
|
||||
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.
|
||||
|
||||
Again, consider adding replacement lines or append linbes to
|
||||
the Makefile.local file. See "Suggestion Modify Makefile.local
|
||||
instead of Makefile" above. For example:
|
||||
|
||||
T:= /var/tmp/testing
|
||||
|
||||
See the "Suggestion: Modify Makefile.local" section above for
|
||||
information on the Makefile.local file.
|
||||
|
||||
|
||||
### platform target section
|
||||
|
||||
The file, Makefile.target, contains information about various platforms.
|
||||
The current list of targets in Makefile.target are:
|
||||
|
||||
- Linux target
|
||||
- Apple macOS / Darwin target
|
||||
- FreeBSD target
|
||||
- OpenBSD target
|
||||
- Cygwin target (as well as Msys2 / Msys OSNAME)
|
||||
- simple target
|
||||
- default target (when target is empty)
|
||||
|
||||
If you wish to modiy your target platform, consider doing
|
||||
so via the Makefile.local file. See "Suggestion Modify Makefile.local
|
||||
instead of Makefile" above.
|
||||
|
||||
|
||||
|
||||
## Step 2: compile calc
|
||||
|
||||
Remove any previous compile attempts and compile by default:
|
||||
|
||||
make clobber all
|
||||
|
||||
|
||||
|
||||
### Force calc to build with only static libs:
|
||||
|
||||
You may force calc to build with only static libs:
|
||||
|
||||
make clobber calc-static-only BLD_TYPE=calc-static-only
|
||||
|
||||
|
||||
|
||||
### Force calc to build with only dynamic shared libs:
|
||||
|
||||
You may force calc to build with only dynamic libs:
|
||||
|
||||
make clobber calc-dynamic-only BLD_TYPE=calc-dynamic-only
|
||||
|
||||
|
||||
|
||||
### Reports of compiler warnings (and errors) as welcome
|
||||
|
||||
We are interested learning about any compiler warnings (and errors) that you may find.
|
||||
See the BUGS file if you find any compiler warning or errors.
|
||||
|
||||
|
||||
|
||||
### Step 3: test calc
|
||||
|
||||
You may run the calc regression test suite, after successfully compiling, by:
|
||||
|
||||
make check
|
||||
|
||||
For a more quiet check which only prints if something goes wrong, use:
|
||||
|
||||
make chk
|
||||
|
||||
|
||||
|
||||
### Step 4: install calc
|
||||
|
||||
Depending on permissions, you may need to become the super-user:
|
||||
|
||||
sudo -s
|
||||
|
||||
before you install:
|
||||
|
||||
make install
|
||||
|
||||
|
||||
|
||||
### Step n: calc help - getting started
|
||||
|
||||
Calc is distributed with an extensive collection of help files that
|
||||
are accessible from the command line. The following assume that you
|
||||
are running calc from the distribution directory or that you have
|
||||
installed calc. In these examples, the "; " is the calc prompt, not
|
||||
something that you type.
|
||||
|
||||
For list of help topics:
|
||||
|
||||
; help
|
||||
|
||||
For overview of calc overview:
|
||||
|
||||
; help intro
|
||||
; help overview
|
||||
; help command
|
||||
; help define
|
||||
; help statement
|
||||
; help variable
|
||||
; help usage
|
||||
|
||||
For list of builtin functions:
|
||||
|
||||
; help builtin
|
||||
|
||||
C programmers should note some unexpected differences with the calc syntax:
|
||||
|
||||
; help unexpected
|
||||
|
||||
Calc is shipped with a standard collection of calc resource files.
|
||||
For a list of calc standard resource files see:
|
||||
|
||||
; help resource
|
||||
|
||||
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.
|
||||
|
||||
## Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
In general, if you run into problems, read the BUGS file and follow the instructions.
|
||||
|
||||
# IMPORTANT: parallel make not supported
|
||||
|
||||
We do not support making calc using a parallel make as most parallel
|
||||
make systems fail to understand the depedency relationships between
|
||||
a numner of important make rules and thus fail to properly compile calc.
|
||||
|
||||
|
||||
|
||||
## Copyright (C) 1999-2007,2021,2023 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
|
||||
|
117
LIBRARY
117
LIBRARY
@@ -1,4 +1,4 @@
|
||||
USING THE ARBITRARY PRECISION ROUTINES IN A C PROGRAM
|
||||
USING THE ARBITRARY PRECISION ROUTINES IN A C PROGRAM
|
||||
|
||||
Part of the calc release consists of an arbitrary precision math link library.
|
||||
This link library is used by the calc program to perform its own calculations.
|
||||
@@ -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,
|
||||
@@ -344,7 +344,7 @@ values of 0 and 1 are so common that special checks are made for them.
|
||||
|
||||
For initial values besides 0 or 1, you need to call itoz to convert a long
|
||||
value into a ZVALUE, as shown in the above example. Or alternatively,
|
||||
for larger numbers you can use the atoz routine to convert a string which
|
||||
for larger numbers you can use the str2z routine to convert a string which
|
||||
represents a number into a ZVALUE. The string can be in decimal, octal,
|
||||
hex, or binary according to the leading digits.
|
||||
|
||||
@@ -357,7 +357,7 @@ over a long sequence of operations.
|
||||
ZVALUE z1, z2, z3;
|
||||
|
||||
z1 = _one_;
|
||||
atoz("12345678987654321", &z2);
|
||||
str2z("12345678987654321", &z2);
|
||||
zadd(z1, z2, &z3);
|
||||
zfree(z1);
|
||||
zfree(z2);
|
||||
@@ -415,11 +415,23 @@ the low order bits converted.
|
||||
|
||||
There are two types of comparisons you can make on ZVALUEs. This is whether
|
||||
or not they are equal, or the ordering on size of the numbers. The zcmp
|
||||
function tests whether two ZVALUEs are equal, returning TRUE if they differ.
|
||||
function tests whether two ZVALUEs are equal, returning true if they differ.
|
||||
The zrel function tests the relative sizes of two ZVALUEs, returning -1 if
|
||||
the first one is smaller, 0 if they are the same, and 1 if the first one
|
||||
is larger.
|
||||
|
||||
To determine if z is an integer power of 2, use zispowerof2:
|
||||
|
||||
ZVALUE z; /* value to check if it is a power of */
|
||||
FULL log2; /* set to log base 2 of z when is_power_of_2 is true */
|
||||
bool is_power_of_2;
|
||||
|
||||
is_power_of_2 = zispowerof2(z, &log2)
|
||||
|
||||
Returns true if z an integer power of 2: set log2 to log base 2 of z.
|
||||
Returns false if z is NOT integer power of 2 and leave log2 untouched.
|
||||
The log2 arg must be a non-NULL pointer to a ZVALUE.
|
||||
|
||||
---------------
|
||||
USING FRACTIONS
|
||||
---------------
|
||||
@@ -446,18 +458,19 @@ to free them first. The following illustrates this:
|
||||
itoz(55L, &q->num);
|
||||
|
||||
A better way to create NUMBERs with particular values is to use the itoq,
|
||||
iitoq, or atoq functions. Using itoq makes a long value into a NUMBER,
|
||||
iitoq, or str2q functions. Using itoq makes a long value into a NUMBER,
|
||||
using iitoq makes a pair of longs into the numerator and denominator of a
|
||||
NUMBER (reducing them first if needed), and atoq converts a string representing
|
||||
a number into the corresponding NUMBER. The atoq function accepts input in
|
||||
NUMBER (reducing them first if needed), and str2q converts a string representing
|
||||
a number into the corresponding NUMBER. The str2q function accepts input in
|
||||
integral, fractional, real, or exponential formats. Examples of allocating
|
||||
numbers are:
|
||||
|
||||
NUMBER *q1, *q2, *q3;
|
||||
NUMBER *q1, *q2, *q3, *q4;
|
||||
|
||||
q1 = itoq(66L);
|
||||
q2 = iitoq(2L, 3L);
|
||||
q3 = atoq("456.78");
|
||||
q3 = str2q("456.78");
|
||||
q4 = utoq((FULL) 1234567890L);
|
||||
|
||||
Also unlike ZVALUEs, NUMBERs are quickly copied. This is because they contain
|
||||
a link count, which is the number of pointers there are to the NUMBER. The
|
||||
@@ -473,11 +486,13 @@ the ZVALUEs contained within the NUMBER, and then puts the NUMBER structure
|
||||
onto a free list for quick reuse. The following is an example of allocating
|
||||
NUMBERs, copying them, adding them, and finally deleting them again.
|
||||
|
||||
NUMBER *q1, *q2, *q3;
|
||||
NUMBER *q1, *q2, *q3, *q4;
|
||||
|
||||
q1 = itoq(111L);
|
||||
q2 = qlink(q1);
|
||||
q3 = qqadd(q1, q2);
|
||||
q4 = qnum(q2, q3);
|
||||
|
||||
qfree(q1);
|
||||
qfree(q2);
|
||||
qfree(q3);
|
||||
@@ -504,8 +519,8 @@ For example, to calculate sin(0.5) to 100 decimal places, you could do:
|
||||
|
||||
NUMBER *q, *ans, *epsilon;
|
||||
|
||||
q = atoq("0.5");
|
||||
epsilon = atoq("1e-100");
|
||||
q = str2q("0.5");
|
||||
epsilon = str2q("1e-100");
|
||||
ans = qsin(q, epsilon);
|
||||
|
||||
There are many convenience macros similar to the ones for ZVALUEs which can
|
||||
@@ -513,18 +528,18 @@ give quick information about NUMBERs. In addition, there are some new ones
|
||||
applicable to fractions. These are all defined in qmath.h. Some of these
|
||||
macros are:
|
||||
|
||||
qiszero(q) (number is zero)
|
||||
qisneg(q) (number is negative)
|
||||
qispos(q) (number is positive)
|
||||
qisint(q) (number is an integer)
|
||||
qisfrac(q) (number is fractional)
|
||||
qisunit(q) (number is 1 or -1)
|
||||
qisone(q) (number is 1)
|
||||
qisnegone(q) (number is -1)
|
||||
qistwo(q) (number is 2)
|
||||
qiseven(q) (number is an even integer)
|
||||
qisodd(q) (number is an odd integer)
|
||||
qistwopower(q) (number is a power of 2 >= 1)
|
||||
qiszero(q) (number is zero)
|
||||
qisneg(q) (number is negative)
|
||||
qispos(q) (number is positive)
|
||||
qisint(q) (number is an integer)
|
||||
qisfrac(q) (number is fractional)
|
||||
qisunit(q) (number is 1 or -1)
|
||||
qisone(q) (number is 1)
|
||||
qisnegone(q) (number is -1)
|
||||
qistwo(q) (number is 2)
|
||||
qiseven(q) (number is an even integer)
|
||||
qisodd(q) (number is an odd integer)
|
||||
qisreciprocal(q) (number is 1 / an integer and q != 0)
|
||||
|
||||
The comparisons for NUMBERs are similar to the ones for ZVALUEs. You use the
|
||||
qcmp and qrel functions.
|
||||
@@ -538,6 +553,20 @@ These have the values 0, 1, -1, and 1/2. An example of using them is:
|
||||
q1 = qlink(&_qonehalf_);
|
||||
q2 = qlink(&_qone_);
|
||||
|
||||
To determine if q is an integer power of 2, use qispowerof2:
|
||||
|
||||
NUMBER *q; /* value to check if it is a power of */
|
||||
NUMBER *qlog2; /* set to log base 2 of q when is_power_of_2 is true */
|
||||
bool is_power_of_2;
|
||||
|
||||
q = utoq((FULL) 1234567890L);
|
||||
qlog2 = qalloc();
|
||||
is_power_of_2 = qispowerof2(q, &qlog2);
|
||||
|
||||
Returns true if q an integer power of 2: set *qlog2 to log base 2 of q.
|
||||
Returns false if q is NOT integer power of 2 and leave *qlog2 untouched.
|
||||
Use qalloc() to setup the qlog2 arg before calling.
|
||||
|
||||
---------------------
|
||||
USING COMPLEX NUMBERS
|
||||
---------------------
|
||||
@@ -605,7 +634,31 @@ only used for complex numbers. Examples of macros are:
|
||||
cisodd(c) (number is has odd real and imaginary parts)
|
||||
|
||||
There is only one comparison you can make for COMPLEX values, and that is
|
||||
for equality. The ccmp function returns TRUE if two complex numbers differ.
|
||||
for equality. The ccmp function returns true if two complex numbers differ.
|
||||
|
||||
Sometimes to results of a COMPLEX based calculation is a real number.
|
||||
That is, the imaginary part of the COMPLEX is 0. You may convert the
|
||||
COMPLEX into a new allocated NUMBER that is real part of the COMPLEX value.
|
||||
For example:
|
||||
|
||||
COMPLEX *c;
|
||||
NUMBER *q;
|
||||
bool ok_to_free; /* true ==> free COMPLEX value, false ==> do not */
|
||||
|
||||
if (cisreal(c)) {
|
||||
q = c_to_q(c, ok_to_free);
|
||||
}
|
||||
|
||||
The 2nd argument to c_to_q() determines if the complex argument should be freed
|
||||
or not. Pass a false value as the 2nd arg if you wish to continue to use the
|
||||
COMPLEX value.
|
||||
|
||||
To convert a NUMBER into a COMPLEX value, use:
|
||||
|
||||
COMPLEX *c;
|
||||
NUMBER *q;
|
||||
|
||||
c = q_to_c(q);
|
||||
|
||||
There are three predefined values for complex numbers. You should clink
|
||||
them when you want to use them. They are _czero_, _cone_, and _conei_.
|
||||
@@ -615,14 +668,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,2023 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
|
||||
|
1384
Makefile.config
Normal file
1384
Makefile.config
Normal file
File diff suppressed because it is too large
Load Diff
124
Makefile.local
Normal file
124
Makefile.local
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# Makefile.local - modify, replace or append calc Makefile variables
|
||||
#
|
||||
# Copyright (C) 2023 Landon Curt Noll
|
||||
#
|
||||
# Suggestion: Read the HOWTO.INSTALL file.
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of 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.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# This calculator first developed by David I. Bell with help/mods from others.
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
####
|
||||
# This file is included all calc Makefiles after the last Makefile variable
|
||||
# is set and before the first make rule. This makes this file suitable to
|
||||
# modify, replace or append Makefile variables.
|
||||
#
|
||||
# To replace a Makefile variable, use := symbols. For example:
|
||||
#
|
||||
# CCWERR:= -Werror
|
||||
# DEBUG:= -O0 -g
|
||||
#
|
||||
# You can append to an existing Makefile variable using '+=' symbols.
|
||||
# For example:
|
||||
#
|
||||
# CCOPT+= -Ofast
|
||||
# COMMON_CFLAGS+= -std=gnu2x
|
||||
####
|
||||
|
||||
###################################################################
|
||||
# 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. #
|
||||
###################################################################
|
||||
|
||||
####
|
||||
#
|
||||
# Force calc to install under /usr/local
|
||||
#
|
||||
# BINDIR:= /usr/local/bin
|
||||
# LIBDIR:= /usr/local/lib
|
||||
# CALC_SHAREDIR:= /usr/local/share/calc
|
||||
# CALC_INCDIR:= /usr/local/include/calc
|
||||
#
|
||||
####
|
||||
|
||||
####
|
||||
# RHEL Diagnosing memory, thread, and crash issues:
|
||||
#
|
||||
# For more info see: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||
#
|
||||
# This comment block was tested under:
|
||||
#
|
||||
# RHEL9 gcc version 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
|
||||
#
|
||||
# with:
|
||||
#
|
||||
# libasan-11.3.1-4.3.el9.x86_64 libubsan-11.3.1-4.3.el9.x86_64
|
||||
#
|
||||
# NOTE: With the above version, these are NOT supported:
|
||||
#
|
||||
# UNSUPPORTED_FSANITIZE:= -fsanitize=nullability-arg -fsanitize=nullability-assign
|
||||
#
|
||||
# Uncomment these lines:
|
||||
#
|
||||
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
|
||||
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
|
||||
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
||||
# FSANITIZE+= -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute
|
||||
# FSANITIZE+= -fsanitize=null -fsanitize=shift -fsanitize=signed-integer-overflow
|
||||
# FSANITIZE+= -fsanitize=unreachable -fsanitize=vla-bound
|
||||
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||
# DEBUG:= -O0 -g
|
||||
####
|
||||
|
||||
####
|
||||
# macOS Diagnosing memory, thread, and crash issues:
|
||||
#
|
||||
# For more info see: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||
#
|
||||
# This comment block was tested under:
|
||||
#
|
||||
# macOS 13.5 with clang version 14.0.3 (clang-1403.0.22.14.1)
|
||||
#
|
||||
# For more info for clang to Diagnosing memory, thread, and crash issues early, see:
|
||||
#
|
||||
# https://developer.apple.com/documentation/xcode/diagnosing-memory-thread-and-crash-issues-early
|
||||
#
|
||||
# NOTE: With the above version, these are NOT supported:
|
||||
#
|
||||
# UNSUPPORTED_FSANITIZE:= -fsanitize-nullability-return
|
||||
#
|
||||
# Uncomment these lines:
|
||||
#
|
||||
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
|
||||
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
|
||||
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
||||
# FSANITIZE+= -fsanitize=nonnull-attribute -fsanitize=nullability-arg
|
||||
# FSANITIZE+= -fsanitize=nullability-assign -fsanitize=returns-nonnull-attribute
|
||||
# FSANITIZE+= -fsanitize=null -fsanitize=object-size -fsanitize=shift
|
||||
# FSANITIZE+= -fsanitize=signed-integer-overflow -fsanitize=unreachable -fsanitize=vla-bound
|
||||
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||
# DEBUG:= -O0 -g3
|
||||
####
|
6332
Makefile.ship
6332
Makefile.ship
File diff suppressed because it is too large
Load Diff
432
Makefile.target
Normal file
432
Makefile.target
Normal file
@@ -0,0 +1,432 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# Makefile.target - platform target section
|
||||
#
|
||||
# Copyright (C) 2023 Landon Curt Noll
|
||||
#
|
||||
# Suggestion: Read the HOWTO.INSTALL file.
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of 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.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# This calculator first developed by David I. Bell with help/mods from others.
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
|
||||
# SUGGESTION: Instead of modifying this file, consider adding
|
||||
# statements to modify, replace or append Makefile
|
||||
# variables in the Makefile.local file.
|
||||
|
||||
|
||||
#######################################################################
|
||||
# NOTE: These lines are included by both Makefile and custom/Makefile #
|
||||
#######################################################################
|
||||
|
||||
##################################################################################
|
||||
#-=-=-=-=-=- platform target section - targets that override defaults -=-=-=-=-=-#
|
||||
##################################################################################
|
||||
|
||||
# Common values set in targets
|
||||
#
|
||||
# BLD_TYPE determines if calc is built with static and/or dynamic libs.
|
||||
# Set this value to one of:
|
||||
#
|
||||
# BLD_TYPE= calc-dynamic-only
|
||||
# BLD_TYPE= calc-static-only
|
||||
#
|
||||
# CC_SHARE are flags given to ${CC} to build .o files suitable for shared libs
|
||||
# DEFAULT_LIB_INSTALL_PATH is where calc programs look for calc shared libs
|
||||
# LD_SHARE are common flags given to ${CC} to link with shared libraries
|
||||
# LIBCALC_SHLIB are flags given to ${CC} to build libcalc shared libraries
|
||||
# LIBCUSTCALC_SHLIB are flags given to ${CC} to build libcustcalc shared lib
|
||||
#
|
||||
# NOTE: The above 5 values are unused if BLD_TYPE= calc-static-only
|
||||
#
|
||||
# CC_STATIC are flags given to ${CC} to build .o files suitable for static libs
|
||||
# LD_STATIC are common flags given to ${CC} to link with static libraries
|
||||
# LIBCALC_STATIC are flags given to ${CC} to build libcalc static libraries
|
||||
# LIBCUSTCALC_STATIC are flags given to ${CC} to build libcustcalc static lib
|
||||
#
|
||||
# NOTE: The above 4 values are unused if BLD_TYPE= calc-dynamic-only
|
||||
#
|
||||
# CCOPT are flags given to ${CC} for optimization
|
||||
# CCWARN are flags given to ${CC} for warning message control
|
||||
#
|
||||
# The following are given to ${CC}:
|
||||
#
|
||||
# WNO_IMPLICT
|
||||
# WNO_ERROR_LONG_LONG
|
||||
# WNO_LONG_LONG
|
||||
#
|
||||
# when compiling special .o files that may need special compile options:
|
||||
#
|
||||
# NOTE: These flags simply turn off certain compiler warnings,
|
||||
# which is useful only when CCWERR is set to -Werror.
|
||||
#
|
||||
# NOTE: If your compiler does not have these -Wno files, just
|
||||
# set these variables to nothing as in:
|
||||
#
|
||||
# WNO_IMPLICT=
|
||||
# WNO_ERROR_LONG_LONG=
|
||||
# WNO_LONG_LONG=
|
||||
#
|
||||
# CCWERR are flags given to ${CC} to make warnings fatal errors
|
||||
# NOTE: CCWERR is only set in development Makefiles and must only be
|
||||
# used with ${CC}, not ${LCC}. If you do not want the compiler
|
||||
# to abort on warnings, then leave CCWERR blank.
|
||||
# CCMISC are misc flags given to ${CC}
|
||||
#
|
||||
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
|
||||
# NOTE: See where CCBAN is defined above for details.
|
||||
#
|
||||
# LCC is how the C compiler is invoked on locally executed intermediate programs
|
||||
# CC is how the C compiler is invoked (with an optional Purify)
|
||||
#
|
||||
# Specific target overrides or modifications to default values
|
||||
|
||||
|
||||
################
|
||||
# Linux target #
|
||||
################
|
||||
|
||||
ifeq ($(target),Linux)
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
BLD_TYPE= calc-dynamic-only
|
||||
|
||||
# target specific library parameters
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||
|
||||
# static library option
|
||||
#
|
||||
CC_STATIC=
|
||||
LD_STATIC=
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC=
|
||||
LCC= gcc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
|
||||
endif # ($(target),Linux)
|
||||
|
||||
|
||||
###############################
|
||||
# Apple macOS / Darwin target #
|
||||
###############################
|
||||
|
||||
ifeq ($(target),Darwin)
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
BLD_TYPE= calc-dynamic-only
|
||||
|
||||
# For old Apple Power PC systems, we need to add:
|
||||
#
|
||||
# -std=gnu99 -arch ppc
|
||||
#
|
||||
ifeq ($(arch),powerpc)
|
||||
COMMON_ADD+= -std=gnu99
|
||||
ARCH_CFLAGS+= -arch ppc
|
||||
endif # ($(arch),powerpc)
|
||||
|
||||
# target specific library parameters
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= ${ARCH_CFLAGS}
|
||||
LIBCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \
|
||||
-install_name ${LIBDIR}/libcalc${LIB_EXT_VERSION} \
|
||||
-current_version ${VER} \
|
||||
${ARCH_CFLAGS}
|
||||
LIBCUSTCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \
|
||||
-install_name ${LIBDIR}/libcustcalc${LIB_EXT_VERSION} \
|
||||
-current_version ${VER} \
|
||||
${ARCH_CFLAGS}
|
||||
|
||||
# To reduce dependency chains under macOS, we remove functions and
|
||||
# data that are unreachable by the entry point or exported symbols.
|
||||
#
|
||||
COMMON_LDFLAGS+= -Wl,-dead_strip
|
||||
COMMON_LDFLAGS+= -Wl,-dead_strip_dylibs
|
||||
|
||||
# static library option
|
||||
#
|
||||
CC_STATIC=
|
||||
LD_STATIC= ${ARCH_CFLAGS}
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC= ${ARCH_CFLAGS}
|
||||
LCC= cc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
|
||||
# Darwin dynamic shared lib filenames
|
||||
#
|
||||
LIB_EXT:= .dylib
|
||||
LIB_EXT_VERSION:= .${VERSION}${LIB_EXT}
|
||||
|
||||
# LDCONFIG not required on this platform, so we redefine it to an empty string
|
||||
#
|
||||
LDCONFIG:=
|
||||
|
||||
endif # ($(target),Darwin)
|
||||
|
||||
|
||||
##################
|
||||
# FreeBSD target #
|
||||
##################
|
||||
|
||||
ifeq ($(target),FreeBSD)
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
BLD_TYPE= calc-dynamic-only
|
||||
|
||||
# target specific library parameters
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||
|
||||
CC_STATIC=
|
||||
LD_STATIC=
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC=
|
||||
LCC= gcc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
|
||||
# We must use gmake as the FreeBSD target because under some older
|
||||
# releases of FreeBSD, make not support conditional syntax.
|
||||
#
|
||||
MAKE= gmake
|
||||
|
||||
endif # ($(target),FreeBSD)
|
||||
|
||||
|
||||
##################
|
||||
# OpenBSD target #
|
||||
##################
|
||||
|
||||
ifeq ($(target),OpenBSD)
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
BLD_TYPE= calc-dynamic-only
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||
|
||||
# static library option
|
||||
#
|
||||
CC_STATIC=
|
||||
LD_STATIC=
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC=
|
||||
#
|
||||
LCC= gcc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
#
|
||||
MAKE= gmake
|
||||
#
|
||||
endif # ($(target),OpenBSD)
|
||||
|
||||
|
||||
#################
|
||||
# Cygwin target #
|
||||
#################
|
||||
|
||||
ifeq ($(target),Cygwin)
|
||||
|
||||
BLD_TYPE= calc-static-only
|
||||
|
||||
# target specific library parameters
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||
|
||||
# static library option
|
||||
#
|
||||
CC_STATIC=
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
LD_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC=
|
||||
LCC= cc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
|
||||
endif # ($(target),Cygwin)
|
||||
|
||||
|
||||
###########################################
|
||||
# default target - (when target is empty) #
|
||||
###########################################
|
||||
|
||||
# NOTE: This is the default generic host target. Used when no other
|
||||
# host target matches.
|
||||
|
||||
ifeq ($(target),)
|
||||
|
||||
# default build type for this target
|
||||
#
|
||||
BLD_TYPE= calc-static-only
|
||||
|
||||
# target specific library parameters
|
||||
#
|
||||
CC_SHARE= -fPIC
|
||||
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||
|
||||
# static library option
|
||||
#
|
||||
CC_STATIC=
|
||||
LIBCALC_STATIC=
|
||||
LIBCUSTCALC_STATIC=
|
||||
LD_STATIC=
|
||||
|
||||
# common values set for this target
|
||||
#
|
||||
#CCWARN= -Wall
|
||||
CCWARN= -Wall -Wextra -pedantic
|
||||
WNO_IMPLICT= -Wno-implicit
|
||||
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||
WNO_LONG_LONG= -Wno-long-long
|
||||
CCWERR=
|
||||
CCOPT= ${DEBUG}
|
||||
CCMISC=
|
||||
LCC= gcc
|
||||
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||
|
||||
endif # ($(target),)
|
||||
|
||||
|
||||
###########################################
|
||||
# Set the default compile flags for ${CC} #
|
||||
###########################################
|
||||
|
||||
# If you want to add flags to all compiler and linker
|
||||
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
|
||||
# set ${COMMON_ADD}.
|
||||
#
|
||||
# For example to use gcc's -Werror to force warnings
|
||||
# to become errors, call make with:
|
||||
#
|
||||
# make .. COMMON_ADD='-Werror'
|
||||
#
|
||||
# This facility requires a Gnu Makefile, or a make command
|
||||
# that understands the += make operand.
|
||||
#
|
||||
COMMON_CFLAGS+= ${COMMON_ADD}
|
||||
COMMON_LDFLAGS+= ${COMMON_ADD}
|
||||
|
||||
# Required flags to compile C files for calc
|
||||
#
|
||||
# ICFLAGS are given to ${CC} for intermediate programs used to help compile calc
|
||||
# CFLAGS are given to ${CC} for calc programs other than intermediate programs
|
||||
#
|
||||
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
|
||||
#
|
||||
ifeq ($(BLD_TYPE),calc-static-only)
|
||||
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
|
||||
else # ($(BLD_TYPE),calc-static-only)
|
||||
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
|
||||
endif # ($(BLD_TYPE),calc-static-only)
|
||||
CFLAGS= ${ICFLAGS} ${CCOPT}
|
||||
|
||||
# Required flags to link files for calc
|
||||
#
|
||||
# ILDFLAGS for ${CC} in linking intermediate programs used to help compile calc
|
||||
# LDFLAGS for ${CC} in linking calc programs other than intermediate programs
|
||||
#
|
||||
ILDFLAGS= ${COMMON_LDFLAGS}
|
||||
LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
|
||||
|
||||
#######################################################################
|
||||
#-=-=-=-=-=- end of target section - only make rules below -=-=-=-=-=-#
|
||||
#######################################################################
|
33
QUESTIONS
33
QUESTIONS
@@ -1,37 +1,28 @@
|
||||
If you have a simple general question about calc, send Email to:
|
||||
If you have a general question about calc, consider opening
|
||||
a new Github discussion under:
|
||||
|
||||
calc-quest-mail at asthe dot com
|
||||
https://github.com/lcn2/calc/discussions
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
|
||||
Look over the existing discussions to see of your question fits
|
||||
under one of those exiting discussions.
|
||||
|
||||
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
|
||||
You may wish to add your question as a comment to an existing discussion.
|
||||
Otherwise click on:
|
||||
|
||||
calc question
|
||||
((New discussion))
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
IMPORTANT: If your Email doesn't contain the above phrase,
|
||||
then we WILL NOT SEE your Email.
|
||||
|
||||
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
|
||||
and ask your question in that new discussion.
|
||||
|
||||
Please limit your questions to general questions about calc. We
|
||||
cannot go into great detail in our answers, nor can we do your
|
||||
homework, nor can we do much more than answer short general questions
|
||||
homework, nor can we do much more than answer general questions
|
||||
about calc.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
Please be patient as we cannot always respond to discussion messages quickly.
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
## Copyright (C) 2021,2023 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,7 +27,7 @@ If you run into problems, see the BUGS file.
|
||||
Calc is distributed with an extensive collection of help files that
|
||||
are accessible from the command line. The following assume that you
|
||||
are running calc from the distribution directory or that you have
|
||||
installed calc. In these examples, the ">" is the calc prompt, not
|
||||
installed calc. In these examples, the "; " is the calc prompt, not
|
||||
something that you type in.
|
||||
|
||||
For list of help topics:
|
||||
@@ -48,7 +48,7 @@ For list of builtin functions:
|
||||
|
||||
; help builtin
|
||||
|
||||
C programmers should note some unexpected differences in the calc syntax:
|
||||
C programmers should note some unexpected differences with the calc syntax:
|
||||
|
||||
; help unexpected
|
||||
|
||||
|
158
README.RELEASE
Normal file
158
README.RELEASE
Normal file
@@ -0,0 +1,158 @@
|
||||
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.
|
||||
|
||||
|
||||
The file, "version.h" defines the 4 version levels:
|
||||
|
||||
MAJOR_VER /* level 1: major library version */
|
||||
MINOR_VER /* level 2: minor library version */
|
||||
MAJOR_PATCH /* level 3: major software version level */
|
||||
MINOR_PATCH /* level 4: minor software version level */
|
||||
|
||||
|
||||
The program "ver_calc" will print information about the compiled
|
||||
calc version as defined "version.h" when "ver_calc" was compiled:
|
||||
|
||||
usage: ./ver_calc [-h] [-V]
|
||||
|
||||
-h print this message and exit non-zero
|
||||
-V print 3-level version (def: print 4-level version)
|
||||
|
||||
Also "calc -v" will print the calc version as defined "version.h" when
|
||||
"calc" was compiled.
|
||||
|
||||
The master branch:
|
||||
|
||||
The public repository of calc source code is:
|
||||
|
||||
http://github.com/lcn2/calc
|
||||
|
||||
On that GitHub site you may find released version of calc,
|
||||
"production", "tested" and "alpha". All commits on the master
|
||||
branch that are not associated with a release are "alpha".
|
||||
|
||||
Any "alpha" commit is likely future code for a future
|
||||
"tested" or "production" version of calc.
|
||||
|
||||
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.
|
||||
|
||||
NOTE: The calc version found in "version.h", and printed
|
||||
by both "ver_calc [-V]" and "calc -v" for an untagged
|
||||
commit is the previous "tested" or "production" version
|
||||
of calc. Any "alpha" changes that remain are code
|
||||
for some future version of calc.
|
||||
|
||||
At the last stage of the release process, "version.h"
|
||||
will be updated as well as the top level version range
|
||||
listed in "CHANGES".
|
||||
|
||||
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,2023 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/
|
267
README.WINDOWS
267
README.WINDOWS
@@ -1,19 +1,150 @@
|
||||
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.
|
||||
Please also add notes to the 'Compiling calc under Windows 11'
|
||||
and 'Compiling with Cygwin' section in README.WINDOWS file.
|
||||
|
||||
NOTE: The main developers do not have access to a Windows based platform.
|
||||
While we will make an effort to not break calc Windows based system,
|
||||
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 with Windows Subsystem for Linux (WSL) =-Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc under Windows 11 =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
BTW: While we are unable to use Windows 11, we welcome Windows 11
|
||||
developers to try compiling calc natively (instead of via a Linux
|
||||
virtual machine). If you are able to compile Windows 11 natively,
|
||||
we would welcome GitHub pull requests showing any needed modifications:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
We were given this advice from a Windows 11 developer:
|
||||
|
||||
Windows 11 users 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.
|
||||
|
||||
See the "Compiling with Cygwin" section below.
|
||||
|
||||
NOTE: Compiling calc under Windows 11 is work in progress. If you run into
|
||||
problems, consider the "Compiling with Cygwin" section below.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling with Msys =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
The MSYS2 Software Distribution and Building Platform for Windows:
|
||||
|
||||
https://www.msys2.org
|
||||
|
||||
is a fork of Cygwin. In `Makefile.config`, when the OSNAME is "Msys",
|
||||
the Cygwin target it set. MSYS2 Software Distribution users should be
|
||||
sure that the following command prints "Msys".
|
||||
|
||||
uname -o
|
||||
|
||||
Or call make with OSNAME set as in:
|
||||
|
||||
make ... OSNAME=Msys
|
||||
|
||||
Follow the "Compiling with Cygwin" instructions below.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling with Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
An effort is being made to allow windows users to compile calc using the
|
||||
Cygwin project (http://sources.redhat.com/cygwin/) with the GCC compiler
|
||||
and Unix tools for Windows.
|
||||
|
||||
The major porting work for Cygwin was performed by Thomas Jones-Low
|
||||
(tjoneslo at softstart dot com).
|
||||
|
||||
In December 2022, GitHub user @Leoongithub successfully compiled
|
||||
calc-2.14.1.2 under cygwin 2.924 (64 bit). The following are the
|
||||
compilation steps that GitHub user @Leoongithub recommends:
|
||||
|
||||
0. Install the latest version of cygwin (https://cygwin.com/install.html).
|
||||
|
||||
NOTE: In addition to the default packages, you also need to check these
|
||||
three packages: gcc-core, make, and libreadline-devel. The version
|
||||
of these packages does not matter. Just choose the latest version.
|
||||
|
||||
NOTE: The addition of "target=Cygwin" to make commands below
|
||||
is done just in case the target is not set properly by make.
|
||||
|
||||
1. Change (cd) into the top of the source code directory of calc.
|
||||
|
||||
NOTE: The make command assume you are at the top of the calc source directory.
|
||||
|
||||
2. make clobber target=Cygwin
|
||||
|
||||
NOTE: This helps ensure that you are starting from a so-called "clean slate",
|
||||
and that you have nothing hanging around from previous attempts to compile.
|
||||
|
||||
3. make all target=Cygwin
|
||||
|
||||
NOTE: If successful, you should have a calc executable. However that executable
|
||||
may not be working properly. Advance to step (4) to test.
|
||||
|
||||
4. make chk target=Cygwin
|
||||
|
||||
NOTE: If you want this command be be verbose, try:
|
||||
|
||||
make check target=Cygwin
|
||||
|
||||
NOTE: This will run calc with the regress.cal regression suite. This step could take
|
||||
for a while to run, depending on the speed/performance of your machine.
|
||||
If all is well (all regression tests pass), you will see at the end:
|
||||
|
||||
chk OK
|
||||
|
||||
Otherwise you may see calc exit non-zero after it prints some lines with '****'
|
||||
error messages followed by a line including a final error count of the form:
|
||||
|
||||
**** 2 error(s) found \/++\/
|
||||
|
||||
If you see some errors that may relate to files and I/O, all may not be lost.
|
||||
It could simply mean that your Windows environment is not conforming to standard
|
||||
I/O and file operations. The calc mathematical engine may be just fine. On the
|
||||
other hand if you see mathematical related regression test failures, this is
|
||||
bad sign that your calc executable under Windows is not usable.
|
||||
|
||||
5. make install target=Cygwin
|
||||
|
||||
NOTE: This step is optional. While calc is usable at the top of the source code directory
|
||||
of calc, installing calc may be of benefit so you can use calc elsewhere on your system.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= 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.
|
||||
@@ -25,123 +156,11 @@ We were told:
|
||||
|
||||
https://docs.microsoft.com/cs-cz/windows/wsl/about
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling with Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
An effort is being made to allow windows users to compile calc using the
|
||||
Cygwin project (http://sources.redhat.com/cygwin/) with the GCC compiler
|
||||
and Un*x tools for Windows.
|
||||
|
||||
The major porting work for Cygwin was performed by Thomas Jones-Low
|
||||
(tjoneslo at softstart dot com).
|
||||
|
||||
In March 2009, Michael Penk (mpenk at wuska dot com) reported success in
|
||||
installs under Cygwin:
|
||||
|
||||
On my fairly complete Cygwin installs, everything compiles,
|
||||
checks, and installs correctly. My Cygwin is configured
|
||||
in a very standard way (out of the box, using all of Cygwin's
|
||||
defaults). The install worked on 5 different machines with
|
||||
Cygwin on them: one XP home, one XP professional, and three
|
||||
Vista professionals.
|
||||
|
||||
Using the calc Makefile, he did the following:
|
||||
|
||||
make all target=Cygwin
|
||||
make check
|
||||
make install
|
||||
|
||||
He also reports:
|
||||
|
||||
Of course, one should be logged in as an Administrator when
|
||||
one builds and installs calc.
|
||||
|
||||
He was compiling calc 2.12.4.0 with Cygwin version 1.5.25-15.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= If all else fails, for Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
Much earlier (2001?) Thomas Jones-Low (tjoneslo at softstart dot com)
|
||||
recommended that you generate by hand all of the header files that
|
||||
by the Makefile. This has been done for you via the makefile rule:
|
||||
|
||||
make win32_hsrc
|
||||
|
||||
which uses the Makefile variables in win32.mkdef to form these header
|
||||
files under win32 directory.
|
||||
|
||||
You will find generated versions of these files located in the win32
|
||||
sub-directory. These files may be appropriate for your Cygwin building
|
||||
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.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling under DJGPP =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
You might want to try using the DJGPP system to compile calc. See:
|
||||
|
||||
http://www.delorie.com/djgpp/
|
||||
|
||||
for DJGPP details and availability.
|
||||
|
||||
To compile with DJGPP, one needs to select a number of Makefile
|
||||
variable changes. Eli Zaretskii <eliz at is dot elta dot co dot il>
|
||||
recommends the following settings:
|
||||
|
||||
TERMCONTROL= -DUSE_TERMIOS
|
||||
BYTE_ORDER= -DLITTLE_ENDIAN
|
||||
LONG_BITS= 32
|
||||
HAVE_FPOS_POS= -DHAVE_NO_FPOS_POS
|
||||
FPOS_BITS= 32
|
||||
OFF_T_BITS= 32
|
||||
DEV_BITS= 32
|
||||
INODE_BITS= 32
|
||||
HAVE_USTAT= -DHAVE_NO_USTAT
|
||||
HAVE_GETSID= -DHAVE_NO_GETSID
|
||||
HAVE_GETPGID= -DHAVE_NO_GETPGID
|
||||
HAVE_GETTIME= -DHAVE_NO_GETTIME
|
||||
HAVE_GETPRID= -DHAVE_NO_GETPRID
|
||||
HAVE_URANDOM_H= NO
|
||||
ALIGN32= -UMUST_ALIGN32
|
||||
HAVE_MALLOC_H= YES
|
||||
HAVE_STDLIB_H= YES
|
||||
HAVE_STRING_H= YES
|
||||
HAVE_TIMES_H= NO
|
||||
HAVE_SYS_TIMES_H= YES
|
||||
HAVE_TIME_H= YES
|
||||
HAVE_SYS_TIME_H= YES
|
||||
HAVE_UNISTD_H= YES
|
||||
BINDIR= /dev/env/DJDIR/bin
|
||||
INCDIR= /dev/env/DJDIR/include
|
||||
LIBDIR= /dev/env/DJDIR/lib
|
||||
MANDIR= /dev/env/DJDIR/man/man1
|
||||
CATDIR= /dev/env/DJDIR/man/cat1
|
||||
NROFF= groff
|
||||
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
|
||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCPAGER= less.exe -ci
|
||||
DEBUG= -O2 -gstabs+ -DWINDOZ
|
||||
|
||||
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.
|
||||
|
||||
Look for Makefile comments of the form:
|
||||
|
||||
# Select ...something... for DJGPP.
|
||||
|
||||
Follow those recommendations. In cases where they conflict with
|
||||
the above Makefile list, follow the recommendation in the Makefile.
|
||||
NOTE: The use of calc under Windows 10 has been deprecated in favor of one
|
||||
of the Windows 11 methods above.
|
||||
|
||||
|
||||
## Copyright (C) 2002-2009 Landon Curt Noll and Thomas Jones-Low
|
||||
## Copyright (C) 2002-2009,2021-2023 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
|
||||
|
22
README.md
22
README.md
@@ -1,3 +1,25 @@
|
||||
# TL;DR Try calc
|
||||
|
||||
## TL;DR Install calc
|
||||
|
||||
```
|
||||
misc linux: sudo yum install calc
|
||||
on Debian: sudo apt install calc
|
||||
on RHEL: sudo dnf install calc
|
||||
on Ubuntu: sudo apt install calc
|
||||
via Termux: apt install calc
|
||||
via src: sudo make clobber all chk instsll
|
||||
```
|
||||
|
||||
## TL;DR Run calc
|
||||
|
||||
```
|
||||
misc shell: calc
|
||||
via bash: calc
|
||||
via misc app: launch calc via Termux
|
||||
via zsh: calc
|
||||
```
|
||||
|
||||
# What is calc?
|
||||
|
||||
Calc is an interactive calculator which provides for easy large
|
||||
|
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.
|
51
addop.c
51
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-2023 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 "errtbl.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;
|
||||
@@ -131,16 +136,16 @@ showfunctions(void)
|
||||
|
||||
/*
|
||||
* Initialize a function for definition.
|
||||
* Newflag is TRUE if we should allocate a new function structure,
|
||||
* Newflag is true if we should allocate a new function structure,
|
||||
* instead of the usual overwriting of the template function structure.
|
||||
* The new structure is returned in the global curfunc variable.
|
||||
*
|
||||
* given:
|
||||
* name name of function
|
||||
* newflag TRUE if need new structure
|
||||
* newflag true if need new structure
|
||||
*/
|
||||
void
|
||||
beginfunc(char *name, BOOL newflag)
|
||||
beginfunc(char *name, bool newflag)
|
||||
{
|
||||
register FUNC *fp; /* current function */
|
||||
|
||||
@@ -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,13 +204,13 @@ 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)
|
||||
free(curfunc);
|
||||
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
|
||||
dumpnames = TRUE;
|
||||
dumpnames = true;
|
||||
for (size = 0; size < fp->f_opcodecount; ) {
|
||||
printf("%ld: ", (unsigned long)size);
|
||||
size += dumpop(&fp->f_opcodes[size]);
|
||||
@@ -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,12 +317,12 @@ freefunc(FUNC *fp)
|
||||
}
|
||||
if (index == funccount) {
|
||||
math_error("Bad call to freefunc!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
|
||||
printf("Freeing function \"%s\"\n",namestr(&funcnames,index));
|
||||
dumpnames = FALSE;
|
||||
dumpnames = false;
|
||||
for (i = 0; i < fp->f_opcodecount; ) {
|
||||
printf("%ld: ", i);
|
||||
i += dumpop(&fp->f_opcodes[i]);
|
||||
@@ -382,7 +387,7 @@ findfunc(long index)
|
||||
{
|
||||
if (index >= funccount) {
|
||||
math_error("Undefined function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return functions[index];
|
||||
}
|
||||
@@ -406,7 +411,7 @@ void
|
||||
writeindexop(void)
|
||||
{
|
||||
if (oldop == OP_INDEXADDR)
|
||||
curfunc->f_opcodes[curfunc->f_opcodecount - 1] = TRUE;
|
||||
curfunc->f_opcodes[curfunc->f_opcodecount - 1] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -421,12 +426,12 @@ addop(long op)
|
||||
register FUNC *fp; /* current function */
|
||||
NUMBER *q, *q1, *q2;
|
||||
unsigned long count;
|
||||
BOOL cut;
|
||||
bool cut;
|
||||
int diff;
|
||||
|
||||
fp = curfunc;
|
||||
count = fp->f_opcodecount;
|
||||
cut = TRUE;
|
||||
cut = true;
|
||||
diff = 2;
|
||||
q = NULL;
|
||||
if ((count + 5) >= maxopcodes) {
|
||||
@@ -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));
|
||||
@@ -483,7 +488,7 @@ addop(long op)
|
||||
oldop = OP_ELEMVALUE;
|
||||
break;
|
||||
default:
|
||||
cut = FALSE;
|
||||
cut = false;
|
||||
|
||||
}
|
||||
if (cut) {
|
||||
@@ -517,7 +522,7 @@ addop(long op)
|
||||
oldoldop = OP_NOP;
|
||||
return;
|
||||
default:
|
||||
cut = FALSE;
|
||||
cut = false;
|
||||
}
|
||||
if (cut) {
|
||||
fp->f_opcodecount -= diff;
|
||||
@@ -542,7 +547,7 @@ addop(long op)
|
||||
switch (op) {
|
||||
case OP_DIV:
|
||||
if (qiszero(q2)) {
|
||||
cut = FALSE;
|
||||
cut = false;
|
||||
break;
|
||||
}
|
||||
q = qqdiv(q1,q2);
|
||||
@@ -558,12 +563,12 @@ addop(long op)
|
||||
break;
|
||||
case OP_POWER:
|
||||
if (qisfrac(q2) || qisneg(q2))
|
||||
cut = FALSE;
|
||||
cut = false;
|
||||
else
|
||||
q = qpowi(q1,q2);
|
||||
break;
|
||||
default:
|
||||
cut = FALSE;
|
||||
cut = false;
|
||||
}
|
||||
if (cut) {
|
||||
qfree(q1);
|
||||
|
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();
|
||||
|
58
assocfunc.c
58
assocfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* assocfunc - association table routines
|
||||
*
|
||||
* Copyright (C) 1999-2007 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021-2023 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 "errtbl.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 */
|
||||
@@ -43,15 +47,15 @@
|
||||
|
||||
|
||||
S_FUNC ASSOCELEM *elemindex(ASSOC *ap, long index);
|
||||
S_FUNC BOOL compareindices(VALUE *v1, VALUE *v2, long dim);
|
||||
S_FUNC bool compareindices(VALUE *v1, VALUE *v2, long dim);
|
||||
S_FUNC void resize(ASSOC *ap, long newsize);
|
||||
S_FUNC void assoc_elemfree(ASSOCELEM *ep);
|
||||
|
||||
|
||||
/*
|
||||
* Return the address of the value specified by normal indexing of
|
||||
* an association. The create flag is TRUE if a value is going to be
|
||||
* assigned into the specified indexing location. If create is FALSE and
|
||||
* an association. The create flag is true if a value is going to be
|
||||
* assigned into the specified indexing location. If create is false and
|
||||
* the index value doesn't exist, a pointer to a NULL value is returned.
|
||||
*
|
||||
* given:
|
||||
@@ -61,7 +65,7 @@ S_FUNC void assoc_elemfree(ASSOCELEM *ep);
|
||||
* indices table of values being indexed by
|
||||
*/
|
||||
VALUE *
|
||||
associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
|
||||
associndex(ASSOC *ap, bool create, long dim, VALUE *indices)
|
||||
{
|
||||
ASSOCELEM **listhead;
|
||||
ASSOCELEM *ep;
|
||||
@@ -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);
|
||||
@@ -262,9 +266,9 @@ associndices(ASSOC *ap, long index)
|
||||
|
||||
/*
|
||||
* Compare two associations to see if they are identical.
|
||||
* Returns TRUE if they are different.
|
||||
* Returns true if they are different.
|
||||
*/
|
||||
BOOL
|
||||
bool
|
||||
assoccmp(ASSOC *ap1, ASSOC *ap2)
|
||||
{
|
||||
ASSOCELEM **table1;
|
||||
@@ -276,9 +280,9 @@ assoccmp(ASSOC *ap1, ASSOC *ap2)
|
||||
long dim;
|
||||
|
||||
if (ap1 == ap2)
|
||||
return FALSE;
|
||||
return false;
|
||||
if (ap1->a_count != ap2->a_count)
|
||||
return TRUE;
|
||||
return true;
|
||||
|
||||
table1 = ap1->a_table;
|
||||
size1 = ap1->a_size;
|
||||
@@ -290,7 +294,7 @@ assoccmp(ASSOC *ap1, ASSOC *ap2)
|
||||
for (ep2 = ap2->a_table[hash % size2]; ;
|
||||
ep2 = ep2->e_next) {
|
||||
if (ep2 == NULL)
|
||||
return TRUE;
|
||||
return true;
|
||||
if (ep2->e_hash != hash)
|
||||
continue;
|
||||
if (ep2->e_dim != dim)
|
||||
@@ -300,10 +304,10 @@ assoccmp(ASSOC *ap1, ASSOC *ap2)
|
||||
break;
|
||||
}
|
||||
if (comparevalue(&ep1->e_value, &ep2->e_value))
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -516,20 +520,20 @@ assocprint(ASSOC *ap, long max_print)
|
||||
|
||||
/*
|
||||
* Compare two lists of index values to see if they are identical.
|
||||
* Returns TRUE if they are the same.
|
||||
* Returns true if they are the same.
|
||||
*/
|
||||
S_FUNC BOOL
|
||||
S_FUNC bool
|
||||
compareindices(VALUE *v1, VALUE *v2, long dim)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dim; i++)
|
||||
if (v1[i].v_type != v2[i].v_type)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
while (dim-- > 0)
|
||||
if (comparevalue(v1++, v2++))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
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 */
|
197
blkcpy.c
197
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-2023 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 "errtbl.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* copystod - copy num indexed items from source value to destination value
|
||||
*
|
||||
@@ -51,7 +56,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
{
|
||||
BLOCK *sblk;
|
||||
BLOCK *dblk;
|
||||
BOOL noreloc;
|
||||
bool noreloc;
|
||||
|
||||
sblk = NULL;
|
||||
dblk = NULL;
|
||||
@@ -60,9 +65,9 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
* check protections
|
||||
*/
|
||||
if (svp->v_subtype & V_NOCOPYFROM)
|
||||
return E_COPY13;
|
||||
return E_COPY_13;
|
||||
if (dvp->v_subtype & V_NOCOPYTO)
|
||||
return E_COPY14;
|
||||
return E_COPY_14;
|
||||
noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0);
|
||||
|
||||
/*
|
||||
@@ -71,10 +76,10 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
switch(svp->v_type) {
|
||||
case V_NBLOCK:
|
||||
if (svp->v_nblock->subtype & V_NOCOPYFROM)
|
||||
return E_COPY15;
|
||||
return E_COPY_15;
|
||||
sblk = svp->v_nblock->blk;
|
||||
if (sblk->data == NULL)
|
||||
return E_COPY8;
|
||||
return E_COPY_08;
|
||||
break;
|
||||
case V_BLOCK:
|
||||
sblk = svp->v_block;
|
||||
@@ -87,7 +92,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
case V_LIST:
|
||||
break;
|
||||
default:
|
||||
return E_COPY9;
|
||||
return E_COPY_09;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -96,11 +101,11 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
switch(dvp->v_type) {
|
||||
case V_NBLOCK:
|
||||
if (dvp->v_nblock->subtype & V_NOCOPYTO)
|
||||
return E_COPY16;
|
||||
return E_COPY_16;
|
||||
noreloc |=((dvp->v_nblock->subtype & V_NOREALLOC) != 0);
|
||||
dblk = dvp->v_nblock->blk;
|
||||
if (dblk->data == NULL)
|
||||
return E_COPY10;
|
||||
return E_COPY_10;
|
||||
break;
|
||||
case V_BLOCK:
|
||||
noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0);
|
||||
@@ -113,7 +118,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
case V_LIST:
|
||||
break;
|
||||
default:
|
||||
return E_COPY11;
|
||||
return E_COPY_11;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -149,7 +154,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
case V_STR:
|
||||
return copyblk2str(sblk, ssi, num, dvp->v_str, dsi);
|
||||
}
|
||||
return E_COPY12;
|
||||
return E_COPY_12;
|
||||
|
||||
case V_STR:
|
||||
switch(dvp->v_type) {
|
||||
@@ -165,7 +170,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
return copystr2str(svp->v_str, ssi, num, dvp->v_str,
|
||||
dsi);
|
||||
}
|
||||
return E_COPY12;
|
||||
return E_COPY_12;
|
||||
|
||||
case V_OCTET:
|
||||
switch(dvp->v_type) {
|
||||
@@ -177,7 +182,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
return copyostr2str((char *) svp->v_octet, ssi, num,
|
||||
dvp->v_str, dsi);
|
||||
}
|
||||
return E_COPY12;
|
||||
return E_COPY_12;
|
||||
|
||||
case V_NUM:
|
||||
|
||||
@@ -192,10 +197,10 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
switch (dvp->v_type) {
|
||||
case V_MAT:
|
||||
/* copy to a matrix */
|
||||
return E_COPY12; /* not yet - XXX */
|
||||
return E_COPY_12; /* not yet - XXX */
|
||||
case V_LIST:
|
||||
/* copy to a list */
|
||||
return E_COPY12; /* not yet - XXX */
|
||||
return E_COPY_12; /* not yet - XXX */
|
||||
}
|
||||
break;
|
||||
case V_FILE:
|
||||
@@ -211,7 +216,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
switch (dvp->v_type) {
|
||||
case V_NUM:
|
||||
/* copy to a number */
|
||||
return E_COPY12; /* not yet - XXX */
|
||||
return E_COPY_12; /* not yet - XXX */
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -244,7 +249,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
*/
|
||||
if (dblk != NULL) {
|
||||
/* copy to a block */
|
||||
return E_COPY12; /* not yet - XXX */
|
||||
return E_COPY_12; /* not yet - XXX */
|
||||
}
|
||||
switch (dvp->v_type) {
|
||||
case V_MAT:
|
||||
@@ -262,7 +267,7 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi)
|
||||
/*
|
||||
* unsupported copy combination
|
||||
*/
|
||||
return E_COPY12;
|
||||
return E_COPY_12;
|
||||
}
|
||||
|
||||
|
||||
@@ -279,22 +284,22 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
unsigned short subtype;
|
||||
|
||||
if (ssi > smat->m_size)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
|
||||
if (num < 0)
|
||||
num = smat->m_size - ssi;
|
||||
if (ssi + num > smat->m_size)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (dsi < 0)
|
||||
dsi = 0;
|
||||
if (dsi + num > dmat->m_size)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
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;
|
||||
@@ -328,22 +333,22 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
unsigned short subtype;
|
||||
|
||||
if (ssi > blk->datalen)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = blk->datalen - ssi;
|
||||
if (ssi + num > blk->datalen)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (dsi < 0)
|
||||
dsi = 0;
|
||||
if (dsi + num > dmat->m_size)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
op = blk->data + ssi;
|
||||
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;
|
||||
@@ -371,7 +376,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
*/
|
||||
int
|
||||
copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
BOOL noreloc)
|
||||
bool noreloc)
|
||||
{
|
||||
long i;
|
||||
long newlen;
|
||||
@@ -381,26 +386,26 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
OCTET *op;
|
||||
|
||||
if (ssi > smat->m_size)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = smat->m_size - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (ssi + num > smat->m_size)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = dblk->datalen;
|
||||
newlen = dsi + num;
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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;
|
||||
@@ -429,21 +434,21 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi)
|
||||
unsigned short subtype;
|
||||
|
||||
if (ssi > smat->m_size)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = smat->m_size - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (ssi + num > smat->m_size)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = 0;
|
||||
if (dsi + num > lp->l_count)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
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;
|
||||
@@ -479,21 +484,21 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
unsigned short subtype;
|
||||
|
||||
if (ssi > lp->l_count)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = lp->l_count - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (ssi + num > lp->l_count)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = 0;
|
||||
if (dsi + num > dmat->m_size)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
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;
|
||||
@@ -529,21 +534,21 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi)
|
||||
unsigned short subtype;
|
||||
|
||||
if (ssi > slp->l_count)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = slp->l_count - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (ssi + num > slp->l_count)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = 0;
|
||||
if (dsi + num > dlp->l_count)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
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;
|
||||
@@ -578,15 +583,15 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi)
|
||||
long numw;
|
||||
|
||||
if (ssi > sblk->datalen)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = sblk->datalen - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
|
||||
fiop = findid(id, TRUE);
|
||||
fiop = findid(id, true);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
return E_COPYF_1;
|
||||
fp = fiop->fp;
|
||||
if (id == 1 || id == 2) {
|
||||
numw = idfputstr(id, (char *)sblk->data + ssi); /* XXX */
|
||||
@@ -594,11 +599,11 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi)
|
||||
}
|
||||
if (dsi >= 0) {
|
||||
if (fseek(fp, dsi, 0))
|
||||
return E_COPYF2;
|
||||
return E_COPYF_2;
|
||||
}
|
||||
numw = fwrite(sblk->data + ssi, 1, num, fp);
|
||||
if (numw < num)
|
||||
return E_COPYF3;
|
||||
return E_COPYF_3;
|
||||
fflush(fp);
|
||||
return 0;
|
||||
}
|
||||
@@ -608,7 +613,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi)
|
||||
* copyfile2blk - copy file to block
|
||||
*/
|
||||
int
|
||||
copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
|
||||
copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, bool noreloc)
|
||||
{
|
||||
FILEIO *fiop;
|
||||
FILE *fp;
|
||||
@@ -620,52 +625,52 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
|
||||
OCTET *newdata;
|
||||
|
||||
if (id < 3) /* excludes copying from stdin */
|
||||
return E_COPYF1;
|
||||
fiop = findid(id, FALSE);
|
||||
return E_COPYF_1;
|
||||
fiop = findid(id, false);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
return E_COPYF_1;
|
||||
|
||||
fp = fiop->fp;
|
||||
|
||||
if (get_open_siz(fp, &fsize))
|
||||
return E_COPYF2;
|
||||
return E_COPYF_2;
|
||||
if (zge31b(fsize)) {
|
||||
zfree(fsize);
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
}
|
||||
filelen = ztoi(fsize);
|
||||
zfree(fsize);
|
||||
|
||||
if (ssi > filelen)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = filelen - ssi;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
if (ssi + num > filelen)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (fseek(fp, ssi, 0)) /* using system fseek XXX */
|
||||
return E_COPYF2;
|
||||
return E_COPYF_2;
|
||||
if (dsi < 0)
|
||||
dsi = dblk->datalen;
|
||||
newlen = dsi + num;
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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;
|
||||
}
|
||||
numw = fread(dblk->data + dsi, 1, num, fp);
|
||||
if (numw < num)
|
||||
return E_COPYF4;
|
||||
return E_COPYF_4;
|
||||
if (newlen > dblk->datalen)
|
||||
dblk->datalen = newlen;
|
||||
return 0;
|
||||
@@ -686,16 +691,16 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi)
|
||||
len = str->s_len;
|
||||
|
||||
if (ssi >= len)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = len - ssi;
|
||||
if (num <= 0) /* Nothing to be copied */
|
||||
return 0;
|
||||
if (ssi + num > len)
|
||||
return E_COPY5; /* Insufficient memory in str */
|
||||
fiop = findid(id, TRUE);
|
||||
return E_COPY_05; /* Insufficient memory in str */
|
||||
fiop = findid(id, true);
|
||||
if (fiop == NULL)
|
||||
return E_COPYF1;
|
||||
return E_COPYF_1;
|
||||
fp = fiop->fp;
|
||||
if (id == 1 || id == 2) {
|
||||
numw = idfputstr(id, str->s_str + ssi); /* XXX */
|
||||
@@ -703,11 +708,11 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi)
|
||||
}
|
||||
if (dsi >= 0) {
|
||||
if (fseek(fp, dsi, 0))
|
||||
return E_COPYF2;
|
||||
return E_COPYF_2;
|
||||
}
|
||||
numw = fwrite(str->s_str + ssi, 1, num, fp);
|
||||
if (numw < num)
|
||||
return E_COPYF3;
|
||||
return E_COPYF_3;
|
||||
fflush(fp);
|
||||
return 0;
|
||||
}
|
||||
@@ -718,33 +723,33 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi)
|
||||
*/
|
||||
int
|
||||
copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
BOOL noreloc)
|
||||
bool noreloc)
|
||||
{
|
||||
long newlen;
|
||||
long newsize;
|
||||
USB8 *newdata;
|
||||
|
||||
if (ssi > sblk->datalen)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = sblk->datalen - ssi;
|
||||
if (num == 0) /* Nothing to be copied */
|
||||
return 0;
|
||||
if (ssi + num > sblk->datalen)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = dblk->datalen;
|
||||
newlen = dsi + num;
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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;
|
||||
@@ -761,7 +766,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
*/
|
||||
int
|
||||
copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
BOOL noreloc)
|
||||
bool noreloc)
|
||||
{
|
||||
long len;
|
||||
long newlen;
|
||||
@@ -771,7 +776,7 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
len = str->s_len;
|
||||
|
||||
if (ssi >= len)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = len - ssi;
|
||||
if (num <= 0) /* Nothing to be copied */
|
||||
@@ -780,15 +785,15 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
dsi = dblk->datalen;
|
||||
newlen = dsi + num + 1;
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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;
|
||||
@@ -882,7 +887,7 @@ copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi)
|
||||
* copyostr2blk - copy octet-specified string to block
|
||||
*/
|
||||
int
|
||||
copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
|
||||
copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,bool noreloc)
|
||||
{
|
||||
size_t len;
|
||||
size_t newlen;
|
||||
@@ -892,7 +897,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
|
||||
len = strlen(str) + 1;
|
||||
|
||||
if (ssi > 0 && (size_t)ssi > len)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0 || (size_t)(ssi + num) > len)
|
||||
num = len - ssi;
|
||||
if (num <= 0) /* Nothing to be copied */
|
||||
@@ -901,15 +906,15 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
|
||||
dsi = dblk->datalen; /* Default destination index */
|
||||
newlen = dsi + num;
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= (size_t)dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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 */
|
||||
@@ -982,7 +987,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
|
||||
*/
|
||||
int
|
||||
copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
BOOL noreloc)
|
||||
bool noreloc)
|
||||
{
|
||||
size_t newlen;
|
||||
size_t newsize;
|
||||
@@ -992,26 +997,26 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
#endif
|
||||
|
||||
if (ssi > snum->num.len)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = snum->num.len - ssi;
|
||||
if (num == 0) /* Nothing to be copied */
|
||||
return 0;
|
||||
if (ssi + num > snum->num.len)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = dblk->datalen;
|
||||
newlen = dsi + (num*sizeof(HALF));
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
if (newlen >= (size_t)dblk->maxsize) {
|
||||
if (noreloc)
|
||||
return E_COPY17;
|
||||
return E_COPY_17;
|
||||
newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk;
|
||||
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;
|
||||
@@ -1019,7 +1024,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
#if CALC_BYTE_ORDER == LITTLE_ENDIAN
|
||||
memmove(dblk->data+dsi, (char *)(snum->num.v+ssi), num*sizeof(HALF));
|
||||
#else
|
||||
swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), FALSE);
|
||||
swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), false);
|
||||
memmove(dblk->data+dsi, (char *)(swnum->v+ssi), num*sizeof(HALF));
|
||||
zfree(*swnum);
|
||||
#endif
|
||||
@@ -1046,18 +1051,18 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
|
||||
#endif
|
||||
|
||||
if (ssi > sblk->datalen)
|
||||
return E_COPY2;
|
||||
return E_COPY_02;
|
||||
if (num < 0)
|
||||
num = sblk->datalen - ssi;
|
||||
if (num == 0) /* Nothing to be copied */
|
||||
return 0;
|
||||
if (ssi + num > sblk->datalen)
|
||||
return E_COPY5;
|
||||
return E_COPY_05;
|
||||
if (dsi < 0)
|
||||
dsi = dnum->num.len;
|
||||
newlen = dsi + ((num+sizeof(HALF)-1)/sizeof(HALF));
|
||||
if (newlen <= 0)
|
||||
return E_COPY7;
|
||||
return E_COPY_07;
|
||||
|
||||
/* quasi-clone the numerator to the new size */
|
||||
ret = qalloc();
|
||||
@@ -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;
|
||||
|
12
blkcpy.h
12
blkcpy.h
@@ -37,21 +37,21 @@ E_FUNC int copystod(VALUE *, long, long, VALUE *, long);
|
||||
/*
|
||||
* specific copy functions
|
||||
*/
|
||||
E_FUNC int copyblk2blk(BLOCK *, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copyblk2blk(BLOCK *, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copyblk2file(BLOCK *, long, long, FILEID, long);
|
||||
E_FUNC int copyblk2mat(BLOCK *, long, long, MATRIX *, long);
|
||||
E_FUNC int copyblk2num(BLOCK *, long, long, NUMBER *, long, NUMBER **);
|
||||
E_FUNC int copyblk2str(BLOCK *, long, long, STRING *, long);
|
||||
E_FUNC int copyfile2blk(FILEID, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copyfile2blk(FILEID, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copylist2list(LIST *, long, long, LIST *, long);
|
||||
E_FUNC int copylist2mat(LIST *, long, long, MATRIX *, long);
|
||||
E_FUNC int copymat2blk(MATRIX *, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copymat2blk(MATRIX *, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copymat2list(MATRIX *, long, long, LIST *, long);
|
||||
E_FUNC int copymat2mat(MATRIX *, long, long, MATRIX *, long);
|
||||
E_FUNC int copynum2blk(NUMBER *, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copyostr2blk(char *, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copynum2blk(NUMBER *, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copyostr2blk(char *, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copyostr2str(char *, long, long, STRING *, long);
|
||||
E_FUNC int copystr2blk(STRING *, long, long, BLOCK *, long, BOOL);
|
||||
E_FUNC int copystr2blk(STRING *, long, long, BLOCK *, long, bool);
|
||||
E_FUNC int copystr2file(STRING *, long, long, FILEID, long);
|
||||
E_FUNC int copystr2str(STRING *, long, long, STRING *, long);
|
||||
|
||||
|
71
block.c
71
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-2023 Landon Curt Noll and Ernest Bowen
|
||||
*
|
||||
* Primary author: Landon Curt Noll
|
||||
*
|
||||
@@ -28,13 +28,22 @@
|
||||
|
||||
|
||||
#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"
|
||||
#include "block.h"
|
||||
#include "nametype.h"
|
||||
#include "str.h"
|
||||
#include "calcerr.h"
|
||||
|
||||
|
||||
#include "errtbl.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define NBLOCKCHUNK 16
|
||||
|
||||
@@ -78,7 +87,7 @@ blkalloc(int len, int chunk)
|
||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||
if (nblk == NULL) {
|
||||
math_error("cannot allocate block");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -89,7 +98,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 +156,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 +172,7 @@ blkchk(BLOCK *blk)
|
||||
}
|
||||
if (blk == NULL) {
|
||||
math_error("internal: blk ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,7 +180,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->data == NULL) {
|
||||
math_error("internal: blk->data ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -179,7 +188,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,7 +196,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -250,7 +259,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 +367,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 +397,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 +411,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;
|
||||
@@ -417,8 +426,8 @@ blk_copy(BLOCK *blk)
|
||||
* b second BLOCK
|
||||
*
|
||||
* returns:
|
||||
* TRUE => BLOCKs are different
|
||||
* FALSE => BLOCKs are the same
|
||||
* true => BLOCKs are different
|
||||
* false => BLOCKs are the same
|
||||
*/
|
||||
int
|
||||
blk_cmp(BLOCK *a, BLOCK *b)
|
||||
@@ -428,11 +437,11 @@ blk_cmp(BLOCK *a, BLOCK *b)
|
||||
*/
|
||||
if (a == b) {
|
||||
/* pointers to the same object */
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
if (a == NULL || b == NULL) {
|
||||
/* one pointer is NULL, so they differ */
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -440,7 +449,7 @@ blk_cmp(BLOCK *a, BLOCK *b)
|
||||
*/
|
||||
if (a->datalen != b->datalen) {
|
||||
/* different lengths are different */
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -450,13 +459,13 @@ blk_cmp(BLOCK *a, BLOCK *b)
|
||||
*/
|
||||
if (memcmp(a->data, b->data, a->datalen) != 0) {
|
||||
/* different sections are different */
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* the blocks are the same
|
||||
*/
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -469,7 +478,7 @@ void
|
||||
blk_print(BLOCK *blk)
|
||||
{
|
||||
long i;
|
||||
BOOL havetail;
|
||||
bool havetail;
|
||||
USB8 *ptr;
|
||||
|
||||
/* XXX - should use the config parameters for better print control */
|
||||
@@ -530,7 +539,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 +556,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 +593,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 +602,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 +610,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;
|
||||
@@ -643,12 +652,12 @@ removenblock(int id)
|
||||
NBLOCK *nblk;
|
||||
|
||||
if (id < 0 || id >= nblockcount)
|
||||
return E_BLKFREE3;
|
||||
return E_BLKFREE_3;
|
||||
nblk = nblocks[id];
|
||||
if (nblk->blk->data == NULL)
|
||||
return 0;
|
||||
if (nblk->subtype & V_NOREALLOC)
|
||||
return E_BLKFREE5;
|
||||
return E_BLKFREE_5;
|
||||
free(nblk->blk->data);
|
||||
nblk->blk->data = NULL;
|
||||
nblk->blk->maxsize = 0;
|
||||
|
4
block.h
4
block.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* block - fixed, dynamic, fifo and circular memory blocks
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2014,2021,2023 Landon Curt Noll and Ernest Bowen
|
||||
*
|
||||
* Primary author: Landon Curt Noll
|
||||
*
|
||||
@@ -122,7 +122,7 @@
|
||||
* number of octets of a block to print, 0 means all
|
||||
*
|
||||
* config("blkverbose", boolean)
|
||||
* TRUE => print all lines, FALSE => skip dup lines
|
||||
* true => print all lines, false => skip dup lines
|
||||
*
|
||||
* config("blkbase", "base")
|
||||
* output block base = { "hex", "octal", "char", "binary", "raw" }
|
||||
|
65
bool.h
Normal file
65
bool.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* bool - calc standard truth :-)
|
||||
*
|
||||
* Copyright (C) 2023 David I. Bell and Landon Curt Noll
|
||||
*
|
||||
* Primary author: 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
|
||||
* 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: 2023/07/19 17:58:42
|
||||
* File existed as early as: 2023
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(INCLUDE_BOOL_H)
|
||||
#define INCLUDE_BOOL_H
|
||||
|
||||
#include "have_stdbool.h"
|
||||
#if defined(HAVE_STDBOOL_H)
|
||||
#include <stdbool.h>
|
||||
#endif /* HAVE_STDBOOL_H */
|
||||
|
||||
|
||||
/*
|
||||
* standard truth :-)
|
||||
*/
|
||||
#if !defined(HAVE_STDBOOL_H)
|
||||
|
||||
/* fake a <stdbool.h> header file */
|
||||
typedef unsigned char bool; /* fake boolean typedef */
|
||||
#undef true
|
||||
#define true ((bool)(1))
|
||||
#undef false
|
||||
#define false ((bool)(0))
|
||||
|
||||
#endif /* !HAVE_STDBOOL_H */
|
||||
|
||||
|
||||
/*
|
||||
* calc historic booleans
|
||||
*/
|
||||
#undef TRUE
|
||||
#define TRUE (true)
|
||||
#undef FALSE
|
||||
#define FALSE (false)
|
||||
#undef BOOL
|
||||
#define BOOL bool
|
||||
|
||||
|
||||
#endif /* !INCLUDE_BOOL_H*/
|
156
byteswap.c
156
byteswap.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* byteswap - byte swapping routines
|
||||
*
|
||||
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999,2021-2023 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 "errtbl.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,10 +77,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -86,7 +90,7 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len)
|
||||
* Little Endian) the elements of a ZVALUE.
|
||||
*/
|
||||
ZVALUE *
|
||||
swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +145,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -154,7 +158,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* Little Endian) the elements of a NUMBER.
|
||||
*/
|
||||
NUMBER *
|
||||
swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +209,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -218,7 +222,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* Little Endian) the elements of a COMPLEX.
|
||||
*/
|
||||
COMPLEX *
|
||||
swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,14 +309,58 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -322,7 +370,7 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
|
||||
* Little Endian) the elements of a ZVALUE.
|
||||
*/
|
||||
ZVALUE *
|
||||
swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +424,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -389,7 +437,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* Little Endian) the elements of a NUMBER.
|
||||
*/
|
||||
NUMBER *
|
||||
swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +488,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -453,7 +501,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* Little Endian) the elements of a COMPLEX.
|
||||
*/
|
||||
COMPLEX *
|
||||
swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +552,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -517,7 +565,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* Little Endian) the elements of a ZVALUE.
|
||||
*/
|
||||
ZVALUE *
|
||||
swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -527,10 +575,10 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
/*
|
||||
* allocate the storage
|
||||
*/
|
||||
dest = malloc(sizeof(ZVALUE));
|
||||
dest = calloc(1, sizeof(ZVALUE));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_HALF_in_ZVALUE: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -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,10 +620,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -585,7 +633,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
* Little Endian) the elements of a NUMBER.
|
||||
*/
|
||||
NUMBER *
|
||||
swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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,10 +684,10 @@ 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
|
||||
* all - true => swap every element, false => swap only the
|
||||
* multi-precision storage
|
||||
*
|
||||
* returns:
|
||||
@@ -649,7 +697,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
* Little Endian) the elements of a COMPLEX.
|
||||
*/
|
||||
COMPLEX *
|
||||
swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all)
|
||||
{
|
||||
/*
|
||||
* allocate storage if needed
|
||||
@@ -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.
|
||||
|
295
cal/Makefile
295
cal/Makefile
@@ -1,8 +1,10 @@
|
||||
#!/bin/make
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# cal - makefile for calc standard resource files
|
||||
#
|
||||
# Copyright (C) 1999-2006,2017,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2017,2021-2023 Landon Curt Noll
|
||||
#
|
||||
# Suggestion: Read 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
|
||||
@@ -21,163 +23,96 @@
|
||||
# Under source code control: 1991/07/21 05:00:54
|
||||
# File existed as early as: 1991
|
||||
#
|
||||
# This calculator first developed by David I. Bell with help/mods from others.
|
||||
#
|
||||
# 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
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
# required vars
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
|
||||
####
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
####
|
||||
# SUGGESTION: Instead of modifying this file, consider adding
|
||||
# statements to modify, replace or append Makefile
|
||||
# variables in the ../Makefile.local file.
|
||||
|
||||
|
||||
###########################################
|
||||
# Files used or included by this Makefile #
|
||||
###########################################
|
||||
|
||||
# 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.
|
||||
# MAKE_FILE is empty, then they won't.
|
||||
#
|
||||
# If in doubt, set MAKE_FILE to Makefile
|
||||
#
|
||||
MAKE_FILE= Makefile
|
||||
|
||||
# Controlling file makefile basename (without the path)
|
||||
# Calc configuration and compile configuration values
|
||||
#
|
||||
# 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
|
||||
CONFIG_MKF= ../Makefile.config
|
||||
|
||||
# Where the system include (.h) files are kept
|
||||
#
|
||||
# For DJGPP, select:
|
||||
#
|
||||
# INCDIR= /dev/env/DJDIR/include
|
||||
#
|
||||
# If in doubt, set:
|
||||
#
|
||||
# INCDIR= /usr/include
|
||||
# Host target information.
|
||||
#
|
||||
TARGET_MKF= ../Makefile.target
|
||||
|
||||
#INCDIR= /usr/local/include
|
||||
#INCDIR= /dev/env/DJDIR/include
|
||||
INCDIR= /usr/include
|
||||
# Local file that is included just prior to the first rule,
|
||||
# that allows one to override any values set in this Makefile.
|
||||
#
|
||||
LOCAL_MKF= ../Makefile.local
|
||||
|
||||
# where to install calc realted things
|
||||
# The set of Makefiles
|
||||
#
|
||||
# ${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
|
||||
MK_SET= ${MAKE_FILE} ${CONFIG_MKF} ${TARGET_MKF} ${LOCAL_MKF}
|
||||
|
||||
#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
|
||||
#######################################################
|
||||
# Calc configuration and compile configuration values #
|
||||
#######################################################
|
||||
include ${CONFIG_MKF}
|
||||
|
||||
# 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
|
||||
# ${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
|
||||
# SCRIPTDIR= ${BINDIR}/cscript
|
||||
#
|
||||
HELPDIR= ${CALC_SHAREDIR}/help
|
||||
CALC_INCDIR= ${INCDIR}/calc
|
||||
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=
|
||||
###############################
|
||||
# host target section include #
|
||||
###############################
|
||||
include ${TARGET_MKF}
|
||||
|
||||
|
||||
##########################################################################
|
||||
#=-=-=-=-=- Be careful if you change something below this line -=-=-=-=-=#
|
||||
##########################################################################
|
||||
|
||||
|
||||
# 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=@
|
||||
|
||||
# standard tools
|
||||
#
|
||||
CHMOD= chmod
|
||||
CMP= cmp
|
||||
RM= rm
|
||||
MKDIR= mkdir
|
||||
RMDIR= rmdir
|
||||
CP= cp
|
||||
MV= mv
|
||||
CO= co
|
||||
TRUE= true
|
||||
TOUCH= touch
|
||||
SED= sed
|
||||
SORT= sort
|
||||
FMT= fmt
|
||||
S= >/dev/null 2>&1
|
||||
#S=
|
||||
#
|
||||
E= 2>/dev/null
|
||||
#E=
|
||||
#
|
||||
#H=@:
|
||||
H=@
|
||||
#
|
||||
V=@:
|
||||
#V=@
|
||||
|
||||
# The calc files to install
|
||||
#
|
||||
@@ -185,31 +120,37 @@ FMT= fmt
|
||||
#
|
||||
# Please use:
|
||||
#
|
||||
# make calc_files_list
|
||||
# make clobber >/dev/null && make calc_files_list
|
||||
#
|
||||
# to keep this list in nice sorted order and to check that these
|
||||
# detailed help files are under RCS control.
|
||||
# to keep this list in nice sorted order.
|
||||
#
|
||||
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
||||
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
|
||||
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
|
||||
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
|
||||
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal \
|
||||
lucas.cal lucas_chk.cal mersenne.cal mfactor.cal \
|
||||
mod.cal natnumset.cal pell.cal pi.cal pix.cal pollard.cal poly.cal \
|
||||
prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
|
||||
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
|
||||
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
|
||||
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
|
||||
sumtimes.cal surd.cal test1700.cal test2300.cal test2600.cal \
|
||||
test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal \
|
||||
test4000.cal test4100.cal test4600.cal test5100.cal test5200.cal \
|
||||
test8400.cal test8500.cal test8600.cal test8900.cal toomcook.cal \
|
||||
unitfrac.cal varargs.cal xx_print.cal zeta2.cal
|
||||
comma.cal constants.cal deg.cal dms.cal dotest.cal ellip.cal \
|
||||
factorial.cal factorial2.cal fnv_tool.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.line smallfactors.cal \
|
||||
solve.cal specialfunctions.cal splitbits.cal statistics.cal \
|
||||
strings.cal sumsq.cal sumtimes.cal surd.cal test2300.obj_incdec.cal \
|
||||
test2600.numfunc.cal test2700.isqrt.cal test3100.matobj.cal \
|
||||
test3300.det.cal test3400.trig.cal test4000.ptest.cal \
|
||||
test4100.redc.cal test4600.fileop.cal test5100.newdecl.cal \
|
||||
test5200.globstat.cal test8000.read.cal test8400.quit.cal \
|
||||
test8500.divmod.cal test8600.maxargs.cal test8700.dotest.cal \
|
||||
test8900.special.cal test9300.frem.cal test9500.trigeq.cal \
|
||||
toomcook.cal unitfrac.cal varargs.cal write2file.cal xx_print.cal \
|
||||
zeta2.cal
|
||||
|
||||
# These calc files are now obsolete and are removed by the install rule.
|
||||
#
|
||||
DEAD_CALC_FILES= lucas_tbl.cal
|
||||
DEAD_CALC_FILES= lucas_tbl.cal set8700.cal test1700.cal test2300.cal test2600.cal \
|
||||
test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal test4000.cal \
|
||||
test4100.cal test4600.cal test5100.cal test5200.cal test8400.cal test8500.cal \
|
||||
test8600.cal test8900.cal
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
@@ -219,8 +160,31 @@ DISTLIST= ${CALC_FILES} ${MAKE_FILE}
|
||||
#
|
||||
CALCLIBLIST=
|
||||
|
||||
# rules that are not also names of files
|
||||
#
|
||||
PHONY= all distlist buildlist distdir calcliblist calc_files_list echo_inst_files \
|
||||
clean clobber install uninstall
|
||||
|
||||
|
||||
############################################################
|
||||
# Allow Makefile.local to change any of the above settings #
|
||||
############################################################
|
||||
include ${LOCAL_MKF}
|
||||
|
||||
|
||||
###########################################
|
||||
# all - First and default Makefile target #
|
||||
###########################################
|
||||
|
||||
all: ${CALC_FILES} ${MAKE_FILE} .all
|
||||
|
||||
|
||||
###############################
|
||||
# additional Makefile targets #
|
||||
###############################
|
||||
|
||||
.PHONY: ${PHONY}
|
||||
|
||||
# used by the upper level Makefile to determine of we have done all
|
||||
#
|
||||
.all:
|
||||
@@ -247,6 +211,13 @@ distlist: ${DISTLIST}
|
||||
fi; \
|
||||
done
|
||||
|
||||
buildlist:
|
||||
${Q} for i in ${BUILD_ALL} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
echo cal/$$i; \
|
||||
fi; \
|
||||
done | fgrep -v '.bak' | LANG=C ${SORT}
|
||||
|
||||
distdir:
|
||||
${Q} echo cal
|
||||
|
||||
@@ -261,19 +232,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/ \\$$//'
|
||||
@@ -305,14 +270,10 @@ clobber: clean
|
||||
echo ${RM} -rf .DS_Store; \
|
||||
${RM} -rf .DS_Store; \
|
||||
fi
|
||||
-${Q} for i in ${DEAD_CALC_FILES} /dev/null; do \
|
||||
-${Q} for i in ${DEAD_CALC_FILES} test082.cal outfile /dev/null; do \
|
||||
if [ "$$i" = "/dev/null" ]; then \
|
||||
continue; \
|
||||
fi; \
|
||||
if [ -e "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
||||
echo "${RM} -f ${T}${CALC_SHAREDIR}/$$i"; \
|
||||
${RM} -f ${T}${CALC_SHAREDIR}/$$i; \
|
||||
fi; \
|
||||
if [ -e "./$$i" ]; then \
|
||||
echo "${RM} -f ./$$i"; \
|
||||
${RM} -f ./$$i; \
|
||||
@@ -387,7 +348,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 \
|
||||
|
330
cal/README
330
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)
|
||||
@@ -330,6 +388,13 @@ dotest.cal
|
||||
dotest("set8700.line");
|
||||
|
||||
|
||||
ellip.cal
|
||||
|
||||
efactor(iN, ia, B, force)
|
||||
|
||||
Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
|
||||
|
||||
|
||||
factorial.cal
|
||||
|
||||
factorial(n)
|
||||
@@ -490,12 +555,65 @@ factorial2.cal
|
||||
for information on falling factorials.
|
||||
|
||||
|
||||
ellip.cal
|
||||
fnv_util.cal
|
||||
|
||||
efactor(iN, ia, B, force)
|
||||
Utility tools for FNV hash and "FNV-style" hash operations.
|
||||
|
||||
Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
|
||||
These functions, if given non-standard values, will produce bogus results.
|
||||
In some cases, such as specifying the number of bits in the hash,
|
||||
using a non-power of 2 bit will produce a result that may work,
|
||||
but the hash will be only an "FNV-style" hash and not a true FNV hash.
|
||||
|
||||
find_fnv_prime(bits)
|
||||
|
||||
If bits == null(), this function will attempt to prompt stdin
|
||||
for a value and provide commends on the value of bits.
|
||||
|
||||
given:
|
||||
bits number of bits in the hash, null() ==> prompt for value
|
||||
|
||||
returns:
|
||||
0 ==> no FNV prime found
|
||||
>0 ==> FNV prime
|
||||
|
||||
deprecated_fnv0(bits, fnv_prime, string)
|
||||
|
||||
If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
for a hash of size bits.
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
string string to hash
|
||||
|
||||
returns:
|
||||
FNV-0 hash, for size bytes, of string
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
fnv_offset_basis(bits, fnv_prime)
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
|
||||
returns:
|
||||
FNV offset basis for a hash size of bits and an FNV prime of fnv_prime
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
prev_hash previous hash value, null() ==> generate FNV offset basis
|
||||
string string to hash
|
||||
|
||||
returns:
|
||||
"FNV-style" hash of bits
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
gvec.cal
|
||||
|
||||
@@ -767,7 +885,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 +997,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 +1050,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.
|
||||
|
||||
@@ -980,7 +1130,7 @@ randbitrun.cal
|
||||
the number and length of identical bits runs match what is expected.
|
||||
By default, run_cnt is to test the next 65536 random values.
|
||||
|
||||
This tests the a55 generator.
|
||||
This tests the subtractive 100 shuffle pseudo-random number generator.
|
||||
|
||||
|
||||
randmprime.cal
|
||||
@@ -1027,7 +1177,7 @@ randrun.cal
|
||||
64 bit values. By default, run_cnt is to test the next 65536
|
||||
random values.
|
||||
|
||||
This tests the a55 generator.
|
||||
This tests the subtractive 100 shuffle pseudo-random number generator.
|
||||
|
||||
repeat.cal
|
||||
|
||||
@@ -1118,18 +1268,6 @@ seedrandom.cal
|
||||
Blum primes for the modulus.
|
||||
|
||||
|
||||
set8700.cal
|
||||
|
||||
set8700_getA1() defined
|
||||
set8700_getA2() defined
|
||||
set8700_getvar() defined
|
||||
set8700_f(set8700_x) defined
|
||||
set8700_g(set8700_x) defined
|
||||
|
||||
Declare globals and define functions needed by dotest() (see
|
||||
dotest.cal) to evaluate set8700.line a line at a time.
|
||||
|
||||
|
||||
set8700.line
|
||||
|
||||
A line-by-line evaluation file for dotest() (see dotest.cal).
|
||||
@@ -1343,6 +1481,60 @@ specialfunctions.cal
|
||||
on the script zeta2.cal.
|
||||
|
||||
|
||||
splitbits.cal
|
||||
|
||||
splitbits(x, b)
|
||||
|
||||
Given an integer x, split the value into a list of integers,
|
||||
each of which is at most b bits long.
|
||||
|
||||
The value b must be an integer > 0.
|
||||
|
||||
The number of elements in the returned list is:
|
||||
|
||||
ceil((highbit(x) + 1) / b)
|
||||
|
||||
If x == 0, then a list of 1 element containing 0 is returned.
|
||||
|
||||
If x < 0, then the two's compliment of abs(x) is returned.
|
||||
Even though calc represents negative integers as positive values
|
||||
with sign bit, the bits returned by this function are as if
|
||||
the integer converted as if the integer was a two's compliment
|
||||
value. For example:
|
||||
|
||||
; L = splitbits(-1, 8);
|
||||
; print L[[0]]
|
||||
255
|
||||
|
||||
; L = splitbits(-2, 8);
|
||||
; print L[[0]]
|
||||
254
|
||||
|
||||
; L = splitbits(-3, 8);
|
||||
; print L[[0]]
|
||||
253
|
||||
|
||||
The first element of the list contains the lowest order bits
|
||||
of x. The last element of the list contains the highest number
|
||||
bits of x.
|
||||
|
||||
For example:
|
||||
|
||||
; x = 2^23209-1
|
||||
; L = splitbits(x, 16);
|
||||
; print size(L), L[[0]]
|
||||
|
||||
; print istype(2, 3i), istype(2, "2"), istype(2, null())
|
||||
0 0 0
|
||||
|
||||
; mat a[2]
|
||||
; b = list(1,2,3)
|
||||
; c = assoc()
|
||||
; obj chongo {was, here} d;
|
||||
; print istype(a,b), istype(b,c), istype(c,d)
|
||||
0 0 0
|
||||
|
||||
|
||||
statistics.cal
|
||||
|
||||
gammaincoctave(z,a)
|
||||
@@ -1435,7 +1627,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
|
||||
@@ -1463,15 +1655,7 @@ surd.cal
|
||||
Calculate using quadratic surds of the form: a + b * sqrt(D).
|
||||
|
||||
|
||||
test1700.cal
|
||||
|
||||
value
|
||||
|
||||
This resource files is used by regress.cal to test the read and
|
||||
use keywords.
|
||||
|
||||
|
||||
test2600.cal
|
||||
test2600.numfunc.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
@@ -1497,7 +1681,7 @@ test2600.cal
|
||||
functions in terms of accuracy and roundoff.
|
||||
|
||||
|
||||
test2700.cal
|
||||
test2700.isqrt.cal
|
||||
|
||||
global defaultverbose
|
||||
mknonnegreal()
|
||||
@@ -1520,7 +1704,7 @@ test2700.cal
|
||||
complex values.
|
||||
|
||||
|
||||
test3100.cal
|
||||
test3100.matobj.cal
|
||||
|
||||
obj res
|
||||
global md
|
||||
@@ -1535,7 +1719,7 @@ test3100.cal
|
||||
a matrix.
|
||||
|
||||
|
||||
test3300.cal
|
||||
test3300.det.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
@@ -1547,7 +1731,7 @@ test3300.cal
|
||||
determinant tests.
|
||||
|
||||
|
||||
test3400.cal
|
||||
test3400.trig.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
@@ -1562,22 +1746,8 @@ test3400.cal
|
||||
This resource file is used by regress.cal to test trig functions.
|
||||
containing objects.
|
||||
|
||||
test3500.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
testfrem(x, y, verbose)
|
||||
testgcdrem(x, y, verbose)
|
||||
testf(str, n, verbose)
|
||||
testg(str, n, verbose)
|
||||
testh(str, n, N, verbose)
|
||||
test3500(verbose, n, N)
|
||||
|
||||
This resource file is used by regress.cal to test the functions frem,
|
||||
fcnt, gcdrem.
|
||||
|
||||
|
||||
test4000.cal
|
||||
test4000.ptest.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
@@ -1610,7 +1780,7 @@ test4000.cal
|
||||
prevcand builtins.
|
||||
|
||||
|
||||
test4100.cal
|
||||
test4100.redc.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
@@ -1630,7 +1800,7 @@ test4100.cal
|
||||
This resource file is used by regress.cal to test REDC operations.
|
||||
|
||||
|
||||
test4600.cal
|
||||
test4600.fileop.cal
|
||||
|
||||
stest(str [, verbose]) defined
|
||||
ttest([m, [n [,verbose]]]) defined
|
||||
@@ -1642,7 +1812,7 @@ test4600.cal
|
||||
This resource file is used by regress.cal to test searching in files.
|
||||
|
||||
|
||||
test5100.cal
|
||||
test5100.newdecl.cal
|
||||
|
||||
global a5100
|
||||
global b5100
|
||||
@@ -1652,7 +1822,7 @@ test5100.cal
|
||||
declaration scope and order.
|
||||
|
||||
|
||||
test5200.cal
|
||||
test5200.globstat.cal
|
||||
|
||||
global a5200
|
||||
static a5200
|
||||
@@ -1664,7 +1834,7 @@ test5200.cal
|
||||
global/static bug.
|
||||
|
||||
|
||||
test8400.cal
|
||||
test8400.quit.cal
|
||||
|
||||
test8400() defined
|
||||
|
||||
@@ -1672,7 +1842,7 @@ test8400.cal
|
||||
memory leaks.
|
||||
|
||||
|
||||
test8500.cal
|
||||
test8500.divmod.cal
|
||||
|
||||
global err_8500
|
||||
global L_8500
|
||||
@@ -1685,7 +1855,7 @@ test8500.cal
|
||||
This resource file is used by regress.cal to the // and % operators.
|
||||
|
||||
|
||||
test8600.cal
|
||||
test8600.maxargs.cal
|
||||
|
||||
global min_8600
|
||||
global max_8600
|
||||
@@ -1696,7 +1866,19 @@ test8600.cal
|
||||
allowing up to 1024 args to be passed to a builtin function.
|
||||
|
||||
|
||||
test8900.cal
|
||||
test8700.dotest.cal
|
||||
|
||||
set8700_getA1() defined
|
||||
set8700_getA2() defined
|
||||
set8700_getvar() defined
|
||||
set8700_f(set8700_x) defined
|
||||
set8700_g(set8700_x) defined
|
||||
|
||||
Declare globals and define functions needed by dotest() (see
|
||||
dotest.cal) to evaluate set8700.line a line at a time.
|
||||
|
||||
|
||||
test8900.special.cal
|
||||
|
||||
This function tests a number of calc resource functions contributed
|
||||
by Christoph Zurnieden. These include:
|
||||
@@ -1714,11 +1896,19 @@ test8900.cal
|
||||
zeta2.cal
|
||||
|
||||
|
||||
unitfrac.cal
|
||||
test9300.frem.cal
|
||||
|
||||
unitfrac(x)
|
||||
global defaultverbose
|
||||
global err
|
||||
testfrem(x, y, verbose)
|
||||
testgcdrem(x, y, verbose)
|
||||
testf(str, n, verbose)
|
||||
testg(str, n, verbose)
|
||||
testh(str, n, N, verbose)
|
||||
test3500(verbose, n, N)
|
||||
|
||||
Represent a fraction as sum of distinct unit fractions.
|
||||
This resource file is used by regress.cal to test the functions frem,
|
||||
fcnt, gcdrem.
|
||||
|
||||
|
||||
toomcook.cal
|
||||
@@ -1744,6 +1934,13 @@ toomcook.cal
|
||||
squaring functions act in the same way.
|
||||
|
||||
|
||||
unitfrac.cal
|
||||
|
||||
unitfrac(x)
|
||||
|
||||
Represent a fraction as sum of distinct unit fractions.
|
||||
|
||||
|
||||
varargs.cal
|
||||
|
||||
sc(a, b, ...)
|
||||
@@ -1751,6 +1948,17 @@ varargs.cal
|
||||
Example program to use 'varargs'. Program to sum the cubes of all
|
||||
the specified numbers.
|
||||
|
||||
write2file.cal
|
||||
|
||||
w2f(filename,stream,fmt,value) defined
|
||||
wd2f(value) defined
|
||||
wx2f(value) defined
|
||||
|
||||
write results to file
|
||||
|
||||
This resource file serves as an example of how to perform file
|
||||
I/O. This write2file hows how to perform file I/O and is provided
|
||||
as an illustrative example.
|
||||
|
||||
xx_print.cal
|
||||
|
||||
@@ -1779,7 +1987,7 @@ zeta2.cal
|
||||
for information on this special zeta function.
|
||||
|
||||
|
||||
## Copyright (C) 2000,2014,2017,2021 David I. Bell and Landon Curt Noll
|
||||
## Copyright (C) 2000,2014,2017,2021,2023 David I. Bell and Landon Curt Noll
|
||||
##
|
||||
## Primary author: Landon Curt Noll
|
||||
##
|
||||
|
@@ -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;
|
||||
|
@@ -4,19 +4,37 @@
|
||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>
|
||||
* and modified by Landon Curt Noll.
|
||||
*
|
||||
* This dotest_code has been placed in the public domain. Please do not
|
||||
* copyright this dotest_code.
|
||||
*
|
||||
* ERNEST BOWEN AND LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*
|
||||
* Under source dotest_code control: 2006/03/08 05:54:09
|
||||
* File existed as early as: 2006
|
||||
@@ -157,7 +175,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);
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* ellip - attempt to factor numbers using elliptic functions
|
||||
*
|
||||
* Copyright (C) 1999 David I. Bell
|
||||
* Copyright (C) 1999,2023 David I. Bell
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -53,7 +53,7 @@
|
||||
* B is the limit of the primes that make up the high power that the
|
||||
* point is raised to for each factoring attempt (default 100).
|
||||
* force is a flag to attempt to factor numbers even if they are
|
||||
* thought to already be prime (default FALSE).
|
||||
* thought to already be prime (default false).
|
||||
*
|
||||
* Making B larger makes the power the point being raised to contain more
|
||||
* prime factors, thus increasing the chance that the order of the point
|
||||
|
@@ -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;
|
||||
}
|
||||
|
473
cal/fnv_tool.cal
Normal file
473
cal/fnv_tool.cal
Normal file
@@ -0,0 +1,473 @@
|
||||
/*
|
||||
* fnv_util - utility tools for FNV hash and "FNV-style" hash operations
|
||||
*
|
||||
* This file provides the following functions:
|
||||
*
|
||||
* find_fnv_prime(bits)
|
||||
* deprecated_fnv0(bits, fnv_prime, string)
|
||||
* fnv_offset_basis(bits, fnv_prime)
|
||||
* fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
*
|
||||
* See the individual function for details on args and return value.
|
||||
*
|
||||
* If no args are given to find_fnv_prime() and stdin is associated
|
||||
* with a tty (i.e., an interactive terminal), then bits will be
|
||||
* prompted for and commentary will be printed to stdout as well.
|
||||
*
|
||||
* If fnv_prime == null(), then an attempt to compute the FNV prime
|
||||
* for a hash if size bits is attempted..
|
||||
*
|
||||
* If prev_hash == null(), then the FNV offset basis for
|
||||
* for a hash if size bits is computed.
|
||||
*
|
||||
* For more information on the FNV hash see:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function
|
||||
* http://www.isthe.com/chongo/tech/comp/fnv/index.html
|
||||
*
|
||||
* IMPORTANT NOTE:
|
||||
*
|
||||
* These functions, if given non-standard values, will produce bogus results.
|
||||
* In some cases, such as specifying the number of bits in the hash,
|
||||
* using a non-power of 2 bit will produce a result that may work,
|
||||
* but the hash will be only an "FNV-style" hash and not a true FNV hash.
|
||||
*
|
||||
* We say "FNV-style" because the result hash is not a "true FNV-like" hash.
|
||||
*
|
||||
* Let integer n > 0 be the number if bits in the FNV hash. Then:
|
||||
*
|
||||
* t = floor((5+n)/12)
|
||||
*
|
||||
* The FNV prime, for the given n bits is the smallest prime of the form:
|
||||
*
|
||||
* p = 256^t + 2^8 + b
|
||||
*
|
||||
* such that:
|
||||
*
|
||||
* 0 < b < 2^8
|
||||
* The number of one-bits in b must be 4 or 5
|
||||
* p mod (2^40 - 2^24 - 1) > (2^24 + 2^8 + 2^7)
|
||||
*
|
||||
* If you force n to not be a power of 2, for example:
|
||||
*
|
||||
* n = 44
|
||||
*
|
||||
* you will find that the FNV prime for 44 bits is:
|
||||
*
|
||||
* p44 = 4294967597
|
||||
* = 0x10000012d
|
||||
* = 0b100000000000000000000000100101101
|
||||
* = 2^32 + 301 = 2^32 + 2^8 + 2^5 + 2^3 + 2^2 + 2^0
|
||||
*
|
||||
* However a hash size of 44 bits is not a true FNV hash, it is only a "FNV-style" hash.
|
||||
*
|
||||
* NOTE: We disallow n <= 31 because there are no FNV primes that small.
|
||||
*
|
||||
* NOTE: For n that is a power of 2 and n > 1024, you will find that
|
||||
* that FNV primes become so rare that that one may not find a suitable
|
||||
* FNV prime. For n = powers of 2 >= 2048 and <= 1048576,
|
||||
* there is NO FNV primes.
|
||||
*
|
||||
* As for as hashing goes, large values of n, even if an
|
||||
* FNV hash may be found, are unlikely to be truly useful. :-)
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright, this permission notice and text
|
||||
* this comment, and the disclaimer below appear in all of the following:
|
||||
*
|
||||
* supporting documentation
|
||||
* source copies
|
||||
* source works derived from this source
|
||||
* binaries derived from this source or from derived source
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\
|
||||
*
|
||||
* Share and enjoy! :-)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* find_fnv_prime - try to find a FNV prime given the number of bits
|
||||
*
|
||||
* If bits == null(), this function will attempt to prompt stdin
|
||||
* for a value and provide commends on the value of bits.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in the hash, null() ==> prompt for value
|
||||
*
|
||||
* returns:
|
||||
* 0 ==> no FNV prime found
|
||||
* >0 ==> FNV prime
|
||||
*/
|
||||
define find_fnv_prime(bits)
|
||||
{
|
||||
local b; /* lower octet of the potential FNV prime: [1,255] */
|
||||
local p; /* value to test as an FNV prime */
|
||||
local t; /* power of 256 part of the FNV prime */
|
||||
local one_bits; /* number of 1 bits in b */
|
||||
local p_minus_b; /* potential FNV prime less b */
|
||||
local interactive; /* true ==> interactive mode and print commentary */
|
||||
|
||||
/*
|
||||
* case: no arg, prompt for bits and print commentary
|
||||
*/
|
||||
interactive = 0; /* assume non-interactive mode */
|
||||
if (isnull(bits)) {
|
||||
|
||||
/*
|
||||
* must be attached to an interactive terminal
|
||||
*/
|
||||
if (!isatty(files(0))) {
|
||||
print "# FATAL: stdin is not a tty: not attached to an interactive terminal";
|
||||
return 0;
|
||||
}
|
||||
interactive = 1; /* set interactive mode */
|
||||
|
||||
/*
|
||||
* prompt for the number of bits
|
||||
*/
|
||||
do {
|
||||
local strscanf_ret; /* return from strscanf_ret */
|
||||
local input; /* value read after prompt */
|
||||
|
||||
/*
|
||||
* prompt and obtain the input
|
||||
*/
|
||||
input = prompt("Enter hash size in bits: ");
|
||||
strscanf_ret = strscanf(input, "%i", bits);
|
||||
print "input =", input;
|
||||
print "bits =", bits;
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
print;
|
||||
print "# NOTE: must enter a integer > 0, try again";
|
||||
print;
|
||||
}
|
||||
} while (!isint(bits) || bits <= 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* firewall - bits must be non-negative integer
|
||||
*/
|
||||
if (!isint(bits) || bits < 0) {
|
||||
if (interactive) {
|
||||
print "# FATAL: bits must be non-negative integer";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* provide commentary on the choice of bits if we are interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
if (popcnt(bits) == 1) {
|
||||
if (bits > 1024) {
|
||||
print "# WARNING: FNV primes for bit size powers of 2 > 1024 are extremely rare.";
|
||||
print "# WARNING: There are no FNV primes for bit size powers of 2 >= 2048 and <= 1048576.";
|
||||
}
|
||||
print "n =", bits;
|
||||
} else {
|
||||
if (bits < 32) {
|
||||
print "# WARNING: bits < 32 is not recommended because there isn't enough bits to be worth hashing";
|
||||
}
|
||||
print "# WARNING: because bits is not a power of 2, we can only form an \"FNV-style hash\": not a true FNV hash.";
|
||||
print "# WARNING: A \"FNV-style hash\" may not have the desired hash properties of a true FNV hash.";
|
||||
print "n =", bits;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* search setup
|
||||
*/
|
||||
t = floor((5+bits)/12);
|
||||
p_minus_b = 256^t + 2^8;
|
||||
|
||||
/*
|
||||
* search for a b that forms a suitable FNV prime
|
||||
*/
|
||||
for (b=1; b < 256; ++b) {
|
||||
|
||||
/*
|
||||
* reject b unless the of one-bits in bottom octet of p is 4 or 5
|
||||
*/
|
||||
one_bits = popcnt(b);
|
||||
if (one_bits != 4 && one_bits != 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* reject p if p mod (2^40 - 2^24 - 1) <= (2^24 + 2^8 + 2^7)
|
||||
*/
|
||||
p = p_minus_b + b;
|
||||
if ((p % (2^40 - 2^24 - 1)) <= (2^24 + 2^8 + 2^7)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* accept potential p value that is prime
|
||||
*/
|
||||
if (ptest(p) == 1) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* case: did not find an FNV prime
|
||||
*/
|
||||
if (b >= 256) {
|
||||
|
||||
/*
|
||||
* examine results if interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
print "# FATAL: There is no a suitable FNV prime for bits =", bits;
|
||||
quit "find_fnv_prime: FATAL: FNV prime search failed";
|
||||
}
|
||||
|
||||
/*
|
||||
* return 0 to indicate no FNV prime found
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* provide FNV commentary if interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
print "t =", t;
|
||||
print "b =", b;
|
||||
print "# NOTE: p = 256^":t, "+ 2^8 +", b;
|
||||
print;
|
||||
print "p =", p;
|
||||
}
|
||||
|
||||
/*
|
||||
* return FNV prime
|
||||
*/
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* deprecated_fnv0 - FNV-0 hash that should only be used to generate an FNV offset basis
|
||||
*
|
||||
* If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
* string string to hash
|
||||
*
|
||||
* returns:
|
||||
* FNV-0 hash, for size bytes, of string
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define deprecated_fnv0(bits, fnv_prime, string)
|
||||
{
|
||||
local hash; /* FNV hash value */
|
||||
local len; /* length of string */
|
||||
local base; /* base of FNV hash: 2^bits */
|
||||
local i;
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "deprecated_fnv0: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
if (!isstr(string)) {
|
||||
quit "deprecated_fnv0: FATAL: string arg must be a string";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "deprecated_fnv0: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "deprecated_fnv0: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* FNV-0 hash each character
|
||||
*/
|
||||
len = strlen(string);
|
||||
base = 2^bits;
|
||||
hash = 0;
|
||||
for (i=0; i < len; ++i) {
|
||||
hash = xor((hash * fnv_prime) % base, ord(string[i]));
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fnv_offset_basis - generate and FNV offset basis
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
*
|
||||
* returns:
|
||||
* FNV offset basis for a hash size of bits and an FNV prime of fnv_prime
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define
|
||||
fnv_offset_basis(bits, fnv_prime)
|
||||
{
|
||||
local fnv0_hash = 0; /* FNV-0 hash value */
|
||||
|
||||
/* string to generate a FNV offset basis - do not change this value */
|
||||
static chongo_was_here = "chongo <Landon Curt Noll> /\\../\\";
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "fnv_offset_basis: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "fnv_offset_basis: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "fnv_offset_basis: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* return the FNV-0 hash of fnv_offset_basis as the FNV offset basis
|
||||
*/
|
||||
fnv0_hash = deprecated_fnv0(bits, fnv_prime, chongo_was_here);
|
||||
return fnv0_hash;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fnv_style_hash - compute an "FNV-1a-style" hash
|
||||
*
|
||||
* These functions, if given non-standard values, will produce bogus results.
|
||||
* To produce a true FNV-1a hash:
|
||||
*
|
||||
* bits must be a power of 2
|
||||
* 32 <= bits
|
||||
* fnv_prime == find_fnv_prime(bits) OR fnv_prime == null()
|
||||
* prev_hash == previous FNV hash OR prev_hash == null()
|
||||
*
|
||||
* If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* If prev_hash == null(), this function will try to compute the FNV offset basis
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* One may chain "FNV-style" hashes by replacing the offset_basis with
|
||||
* the hash state of the previous hash. For the first hash:
|
||||
*
|
||||
* fnv_prime = find_fnv_prime(bits)
|
||||
* hash_val = fnv_style_hash(bits, fnv_prime, null(), string_a);
|
||||
*
|
||||
* then:
|
||||
*
|
||||
* hash_val = fnv_style_hash(bits, fnv_prime, hash_val, string_b);
|
||||
*
|
||||
* This will produce the same as the string_a concatenated with string_b:
|
||||
*
|
||||
* hash_val = fnv_style_hash(bits, null(), null(), string_a + string_b);
|
||||
*
|
||||
* NOTE: Because string_a and string_b are strings, the expression:
|
||||
*
|
||||
* string_a + string_b
|
||||
*
|
||||
* is string_a concatenated with string_b.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
* prev_hash previous hash value, null() ==> generate FNV offset basis
|
||||
* string string to hash
|
||||
*
|
||||
* returns:
|
||||
* "FNV-style" hash of bits
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define
|
||||
fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
{
|
||||
local hash = 0; /* FNV hash value */
|
||||
local len; /* length of string */
|
||||
local base; /* base of FNV hash: 2^bits */
|
||||
local i;
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "fnv1a_style_hash: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
if (!isstr(string)) {
|
||||
quit "fnv1a_style_hash: FATAL: string arg must be a string";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "fnv1a_style_hash: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "fnv1a_style_hash: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* prev_hash == null() means to generate the FNV offset basis
|
||||
*/
|
||||
if (isnull(prev_hash)) {
|
||||
|
||||
/* generate the FNV offset basis for a hash of size bits */
|
||||
prev_hash = fnv_offset_basis(bits, fnv_prime);
|
||||
}
|
||||
if (!isint(prev_hash) || prev_hash < 0) {
|
||||
quit "fnv1a_style_hash: FATAL: prev_hash arg must be an integer => 0";
|
||||
}
|
||||
|
||||
/*
|
||||
* FNV-1a hash each character
|
||||
*/
|
||||
len = strlen(string);
|
||||
base = 2^bits;
|
||||
hash = prev_hash;
|
||||
for (i=0; i < len; ++i) {
|
||||
hash = xor((hash * fnv_prime) % base, ord(string[i]));
|
||||
}
|
||||
return hash;
|
||||
}
|
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
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* randbitrun - check rand bit run lengths of the a55 generator
|
||||
* randbitrun - check rand bit run lengths of the subtractive 100 shuffle generator
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 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
|
||||
|
4385
cal/regress.cal
4385
cal/regress.cal
File diff suppressed because it is too large
Load Diff
@@ -3,19 +3,37 @@
|
||||
*
|
||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>.
|
||||
*
|
||||
* This code has been placed in the public domain. Please do not
|
||||
* copyright this code.
|
||||
*
|
||||
* ERNEST BOWEN DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*
|
||||
* Under source code control: 2006/03/08 05:54:09
|
||||
* File existed as early as: 2006
|
||||
|
@@ -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
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* specialfunctions - special functions (e.g.: gamma, zeta, psi)
|
||||
*
|
||||
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||
* Copyright (C) 2013,2021,2023 Christoph Zurnieden
|
||||
*
|
||||
* 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
|
||||
@@ -802,8 +802,8 @@ define NUMBER_NEGATIVE_INFINITY()
|
||||
return -(1 / epsilon());
|
||||
}
|
||||
|
||||
static TRUE = 1;
|
||||
static FALSE = 0;
|
||||
static true = 1;
|
||||
static false = 0;
|
||||
|
||||
define g(prec)
|
||||
{
|
||||
@@ -827,9 +827,9 @@ define __CZ__series_converged(new, old, max)
|
||||
}
|
||||
if (abs(re(new - old)) <= eps * abs(re(new))
|
||||
&& abs(im(new - old)) <= eps * abs(im(new))) {
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
define __CZ__ei_power(z)
|
||||
|
83
cal/splitbits.cal
Normal file
83
cal/splitbits.cal
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* splitbits - split an integer into list on bit boundardies of a fixed size
|
||||
*
|
||||
* Copyright (C) 2018,2023 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: 2006/06/07 14:10:11
|
||||
* File existed as early as: 2006
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* setup splitbits errors
|
||||
*/
|
||||
static E_SPLITBITS_1, E_SPLITBITS_2, E_SPLITBITS_3;
|
||||
if (! iserror(E_SPLITBITS_1)) E_SPLITBITS_1 = newerror("1st argument to splitbits must be an integer");
|
||||
if (! iserror(E_SPLITBITS_2)) E_SPLITBITS_2 = newerror("2nd argument to splitbits must be an integer");
|
||||
if (! iserror(E_SPLITBITS_3)) E_SPLITBITS_3 = newerror("2nd argument must be an integer > 0");
|
||||
|
||||
|
||||
/*
|
||||
* define splitbits function
|
||||
*/
|
||||
define splitbits(x, b)
|
||||
{
|
||||
local ret; /* list to return */
|
||||
local mask; /* 2^b-1 */
|
||||
local x_is_reg = 0; /* true if x < 0 */
|
||||
|
||||
/* firewall */
|
||||
if (! isint(x)) {
|
||||
return error(E_SPLITBITS_1);
|
||||
}
|
||||
if (! isint(b)) {
|
||||
return error(E_SPLITBITS_2);
|
||||
}
|
||||
if (b <= 0) {
|
||||
return error(E_SPLITBITS_3);
|
||||
}
|
||||
|
||||
/* special case: x == 0 */
|
||||
if (x == 0) {
|
||||
return list(0);
|
||||
}
|
||||
|
||||
/* setup for splitting x */
|
||||
ret = list();
|
||||
mask = 2^b-1;
|
||||
if (x < 0) {
|
||||
x_is_reg = 1;
|
||||
x = abs(x);
|
||||
}
|
||||
|
||||
/* split x */
|
||||
while (x > 0) {
|
||||
printf("%d %x\n", size(ret), x);
|
||||
if (x_is_reg) {
|
||||
append(ret, xor(x & mask, mask));
|
||||
} else {
|
||||
append(ret, x & mask);
|
||||
}
|
||||
x >>= b;
|
||||
}
|
||||
|
||||
/* return list */
|
||||
return ret;
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test2300 - 2300 series of the regress.cal test suite
|
||||
* test_obj_incdec.2300 - test object increment/decrement for test 23dd
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 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,7 +1,7 @@
|
||||
/*
|
||||
* test2600 - 2600 series of the regress.cal test suite
|
||||
* test2600.builtin0 - test numeric functions extensively for test 26dd
|
||||
*
|
||||
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test2700 - 2700 series of the regress.cal test suite
|
||||
* test2700.isqrt - test complex sqrt for test 27dd
|
||||
*
|
||||
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test3100 - 3100 series of the regress.cal test suite
|
||||
* test3100.matobj - test matrix containing objects for test 31dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test3300 - 3300 series of the regress.cal test suite
|
||||
* test3300.det - test determinants of a matrix containing objects for test 31dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test3400 - 3400 series of the regress.cal test suite
|
||||
* test3400.trig - test common trig functions for test 34dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test4000 - 4000 series of the regress.cal test suite
|
||||
* test4000.ptest - test ptest, nextcand, prevcand for test 40dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test4100 - 4100 series of the regress.cal test suite
|
||||
* test4100.redc - test REDC operations for test 41dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test4600 - 4600 series of the regress.cal test suite
|
||||
* test4600.fileop - 4600 series of the regress.cal test suite
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test5100 - 5100 series of the regress.cal test suite
|
||||
* test5100.newdecl - test code generator declaration scope and order for test 51dd
|
||||
*
|
||||
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test5200 - 5200 series of the regress.cal test suite
|
||||
* test5200.globstat - test the fix of an old global/static bug for test 52dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test1700 - 1700 series of the regress.cal test suite
|
||||
* test8000.read - test read operation for test 80dd
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 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,7 +1,7 @@
|
||||
/*
|
||||
* test8400 - 8400 series of the regress.cal test suite
|
||||
* test8400.quit - test quit for test 84dd
|
||||
*
|
||||
* Copyright (C) 1999 Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 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,7 +1,7 @@
|
||||
/*
|
||||
* test8500 - 8500 series of the regress.cal test suite
|
||||
* test8500.divmod - test // and % with various rounding mode for test 85dd
|
||||
*
|
||||
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* test8600 - 8600 series of the regress.cal test suite
|
||||
* test8600.maxargs - test up to 1024 args being passed to a builtin function for test 86dd
|
||||
*
|
||||
* Copyright (C) 2000 Landon Curt Noll
|
||||
*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* set8700 - environment for dotest line tests for the 8700 set of regress.cal
|
||||
* test8700.dotest - environment for dotest line tests for test 87dd
|
||||
*
|
||||
* Copyright (C) 2006 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 2006,2023 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
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test8900 - 8900 series of the regress.cal test suite
|
||||
* test8900.special - test calc resource functions by Christoph Zurnieden for test 89dd
|
||||
*
|
||||
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||
* Copyright (C) 2013,2021,2023 Christoph Zurnieden
|
||||
*
|
||||
* 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
|
||||
@@ -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);
|
||||
|
||||
/*
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* test3500 - 3500 series of the regress.cal test suite
|
||||
* test9300.frem - test of functions frem, fcnt, gcdrem for test 93dd
|
||||
*
|
||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
||||
* Copyright (C) 1999,2023 Ernest Bowen and Landon Curt Noll
|
||||
*
|
||||
* Primary author: Ernest Bowen
|
||||
*
|
||||
@@ -255,16 +255,16 @@ define testh(str,n,N,verbose)
|
||||
}
|
||||
|
||||
/*
|
||||
* test3500 - perform all of the above tests a bunch of times
|
||||
* test9300 - perform all of the above tests a bunch of times
|
||||
*/
|
||||
define test3500(verbose, tnum, n, N)
|
||||
define test9300(verbose, tnum, n, N)
|
||||
{
|
||||
/* set test parameters */
|
||||
if (isnull(verbose)) {
|
||||
verbose = defaultverbose;
|
||||
}
|
||||
if (isnull(tnum)) {
|
||||
tnum = 3501; /* default test number */
|
||||
tnum = 9301; /* default test number */
|
||||
}
|
||||
if (isnull(n)) {
|
||||
n = 200;
|
||||
@@ -276,7 +276,7 @@ define test3500(verbose, tnum, n, N)
|
||||
/*
|
||||
* test a lot of stuff
|
||||
*/
|
||||
srand(3500e3500);
|
||||
srand(9300e9300);
|
||||
err += testf(strcat(str(tnum++), ": frem/fcnt"), n, verbose);
|
||||
err += testg(strcat(str(tnum++), ": gcdrem"), n, verbose);
|
||||
err += testh(strcat(str(tnum++),": gcdrem #2"), n, N, verbose);
|
1433
cal/test9500.trigeq.cal
Normal file
1433
cal/test9500.trigeq.cal
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
121
cal/write2file.cal
Normal file
121
cal/write2file.cal
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* write2file - write results to file
|
||||
*
|
||||
* This resource file serves as an example of how to perform file I/O.
|
||||
* This write2file hows how to perform file I/O and is provided as
|
||||
* an illustrative example.
|
||||
*
|
||||
* Copyright (C) 2023 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: 2023/08/20 13:13:11
|
||||
* File existed as early as: 2023
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
static outfilename; /* where to write stuff */
|
||||
static outfile; /* open file stream on which to write */
|
||||
static stderr; /* write errors to standard error */
|
||||
|
||||
|
||||
/*
|
||||
* setup
|
||||
*/
|
||||
if (!isstr(outfilename)) {
|
||||
outfilename = "./outfile";
|
||||
}
|
||||
if (!isfile(stderr)) {
|
||||
stderr = files(2);
|
||||
if (!isfile(stderr)) {
|
||||
printf("Warning: stderr as files(2) is not a file!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* try to create or open and truncate the outfile
|
||||
*/
|
||||
if (!isfile(outfile)) {
|
||||
/* open outfilename for writing at the beginning */
|
||||
outfile = fopen(outfilename, "w");
|
||||
|
||||
/* firewall - check for failing to open */
|
||||
if (!isfile(outfile)) {
|
||||
fprintf(stderr, "failed to open: %s error(%d): %s\n", outfilename, errno(outfile), strerror(outfile));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* write a value to a file given a format
|
||||
*/
|
||||
define w2f(filename, stream, fmt, value) {
|
||||
|
||||
/* firewall */
|
||||
if (!isfile(stderr)) {
|
||||
printf("stderr is not an open file\n");
|
||||
return;
|
||||
}
|
||||
if (!isstr(filename)) {
|
||||
fprintf(stderr, "filename argument is not a string\n");
|
||||
return;
|
||||
}
|
||||
if (!isfile(stream)) {
|
||||
fprintf(stderr, "stream argument is not an open file\n");
|
||||
return;
|
||||
}
|
||||
if (!isstr(fmt)) {
|
||||
fprintf(stderr, "fmt argument is not a string\n");
|
||||
return;
|
||||
}
|
||||
if (!isnum(value)) {
|
||||
fprintf(stderr, "value argument is not a numeric value\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* write value in decimal */
|
||||
fprintf(stream, fmt, value);
|
||||
if (ferror(stream)) {
|
||||
fprintf(stderr, "error in writing to file: %s error(%d): %s\n", filename, errno(stream), strerror(stream));
|
||||
return;
|
||||
}
|
||||
|
||||
/* flush to be sure it is completely written */
|
||||
fflush(outfile);
|
||||
if (ferror(outfile)) {
|
||||
fprintf(stderr, "error in flushing to file: %s error(%d): %s\n", filename, errno(stream), strerror(stream));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wd2f - write a value to an open file in decimal
|
||||
*/
|
||||
define wd2f(value) {
|
||||
return w2f(outfilename, outfile, "%d\n", value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wx2f - write a value to an open file in hexadecimal
|
||||
*/
|
||||
define wx2f(value) {
|
||||
return w2f(outfilename, outfile, "%x\n", value);
|
||||
}
|
@@ -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;
|
||||
|
264
calc.c
264
calc.c
@@ -1,10 +1,7 @@
|
||||
/*
|
||||
* calc - arbitrary precision calculator
|
||||
*
|
||||
* Copyright (C) 1999-2013,2021 David I. Bell, Landon Curt Noll
|
||||
* and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
* Copyright (C) 1999-2013,2021-2023 David I. Bell, Landon Curt Noll and 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
|
||||
@@ -26,18 +23,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 +46,7 @@
|
||||
# endif
|
||||
# define strdup _strdup
|
||||
# define isatty _isatty
|
||||
#endif /* Windoz */
|
||||
#endif /* Windows */
|
||||
|
||||
#define CALC_C
|
||||
#include "calc.h"
|
||||
@@ -66,6 +62,7 @@
|
||||
#include "lib_calc.h"
|
||||
#include "args.h"
|
||||
#include "zmath.h"
|
||||
#include "strl.h"
|
||||
|
||||
#include "have_unistd.h"
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
@@ -85,12 +82,16 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "errtbl.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
/*
|
||||
* S_FUNC definitions and functions
|
||||
*/
|
||||
S_FUNC void intint(int arg); /* interrupt routine */
|
||||
S_FUNC void calc_interrupt(char *fmt, ...);
|
||||
S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, BOOL haveendstr);
|
||||
S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr);
|
||||
S_FUNC void set_run_state(run state);
|
||||
|
||||
/*
|
||||
@@ -105,21 +106,24 @@ main(int argc, char **argv)
|
||||
int c; /* option */
|
||||
int index;
|
||||
int maxindex;
|
||||
/* fix gcc warning bug */
|
||||
int unusedint = 0;
|
||||
char *cp;
|
||||
char *endcp;
|
||||
char *bp;
|
||||
BOOL done = FALSE;
|
||||
BOOL havearg;
|
||||
BOOL haveendstr;
|
||||
BOOL stdin_closed = FALSE;
|
||||
bool done = false;
|
||||
bool havearg;
|
||||
bool haveendstr;
|
||||
bool stdin_closed = false;
|
||||
size_t len;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
@@ -129,7 +133,7 @@ main(int argc, char **argv)
|
||||
index = 1;
|
||||
cp = endcp = NULL;
|
||||
maxindex = argc;
|
||||
havecommands = FALSE;
|
||||
havecommands = false;
|
||||
while (index < maxindex && !done) {
|
||||
cp = argv[index];
|
||||
if (*cp == '\0') {
|
||||
@@ -137,9 +141,9 @@ main(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
for (;;) {
|
||||
havearg = FALSE;
|
||||
havearg = false;
|
||||
if (*cp != '-') {
|
||||
done = TRUE;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
++cp;
|
||||
@@ -147,7 +151,7 @@ main(int argc, char **argv)
|
||||
cp++;
|
||||
while (*cp == ' ')
|
||||
++cp;
|
||||
done = TRUE;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -158,9 +162,33 @@ main(int argc, char **argv)
|
||||
switch (c) {
|
||||
case 'C':
|
||||
#if defined(CUSTOM)
|
||||
allow_custom = TRUE;
|
||||
|
||||
/*
|
||||
* error if libcustcalc was compiled with CUSTOM undefined
|
||||
*/
|
||||
if (custom_compiled() != true) {
|
||||
math_error("%s: calc was built with custom functions enabled, "
|
||||
"custom_compiled() returned: %d != %d",
|
||||
program, custom_compiled(), true);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* indicate that custom functions are now allowed
|
||||
*/
|
||||
allow_custom = true;
|
||||
break;
|
||||
#else /* CUSTOM */
|
||||
|
||||
/*
|
||||
* error if libcustcalc was compiled with CUSTOM defined
|
||||
*/
|
||||
if (custom_compiled() != false) {
|
||||
math_error("%s: calc was built with custom functions disabled, "
|
||||
"custom_compiled() returned: %d != %d",
|
||||
program, custom_compiled(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* we are too early in processing to
|
||||
* call libcalc_call_me_last() -
|
||||
@@ -173,13 +201,13 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
#endif /* CUSTOM */
|
||||
case 'e':
|
||||
no_env = TRUE;
|
||||
no_env = true;
|
||||
break;
|
||||
case 'h':
|
||||
want_defhelp = 1;
|
||||
break;
|
||||
case 'i':
|
||||
i_flag = TRUE;
|
||||
i_flag = true;
|
||||
break;
|
||||
case 'm':
|
||||
cp++;
|
||||
@@ -216,7 +244,7 @@ main(int argc, char **argv)
|
||||
fprintf(stderr, "??? m-arg");
|
||||
exit(4);
|
||||
}
|
||||
havearg = TRUE;
|
||||
havearg = true;
|
||||
break;
|
||||
case 'n':
|
||||
/*
|
||||
@@ -225,22 +253,22 @@ main(int argc, char **argv)
|
||||
*/
|
||||
break;
|
||||
case 'O':
|
||||
use_old_std = TRUE;
|
||||
use_old_std = true;
|
||||
break;
|
||||
case 'p':
|
||||
p_flag = TRUE;
|
||||
p_flag = true;
|
||||
break;
|
||||
case 'q':
|
||||
q_flag = TRUE;
|
||||
q_flag = true;
|
||||
break;
|
||||
case 'u':
|
||||
u_flag = TRUE;
|
||||
u_flag = true;
|
||||
break;
|
||||
case 'c':
|
||||
c_flag = TRUE;
|
||||
c_flag = true;
|
||||
break;
|
||||
case 'd':
|
||||
d_flag = TRUE;
|
||||
d_flag = true;
|
||||
break;
|
||||
case 'v':
|
||||
/*
|
||||
@@ -267,41 +295,39 @@ main(int argc, char **argv)
|
||||
* calc_debug:resource_debug:user_debug
|
||||
*/
|
||||
if (nextcp(&cp, &index, argc, argv,
|
||||
FALSE)) {
|
||||
false)) {
|
||||
fprintf(stderr,
|
||||
"-D expects argument\n");
|
||||
"-D expects argument\n");
|
||||
exit(5);
|
||||
}
|
||||
havearg = TRUE;
|
||||
havearg = true;
|
||||
if (*cp != ':') {
|
||||
if (*cp < '0' || *cp > '9') {
|
||||
fprintf(stderr,
|
||||
"-D expects"
|
||||
"-D expects"
|
||||
" integer\n");
|
||||
exit(6);
|
||||
}
|
||||
calc_debug = cp;
|
||||
/* fix gcc warning bug */
|
||||
unusedint =
|
||||
strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
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,
|
||||
FALSE)
|
||||
argc, argv,
|
||||
false)
|
||||
|| *cp != ':')
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nextcp(&cp, &index, argc, argv,
|
||||
FALSE)) {
|
||||
false)) {
|
||||
fprintf(stderr,
|
||||
"-D : expects"
|
||||
" argument\n");
|
||||
@@ -310,45 +336,42 @@ main(int argc, char **argv)
|
||||
if (*cp != ':') {
|
||||
if (*cp < '0' || *cp > '9') {
|
||||
fprintf(stderr,
|
||||
"-D : expects"
|
||||
"-D : expects"
|
||||
" integer\n");
|
||||
exit(9);
|
||||
}
|
||||
resource_debug = cp;
|
||||
/* fix gcc warning bug */
|
||||
unusedint =
|
||||
strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
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,
|
||||
FALSE)
|
||||
argc, argv,
|
||||
false)
|
||||
|| *cp != ':') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nextcp(&cp, &index, argc, argv,
|
||||
FALSE)) {
|
||||
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;
|
||||
/* unusedint avoids gcc warning bug */
|
||||
unusedint = strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
if (*cp != '\0' && *cp != ' ') {
|
||||
fprintf(stderr, "Bad syntax in"
|
||||
@@ -370,43 +393,65 @@ main(int argc, char **argv)
|
||||
" filename\n");
|
||||
exit(15);
|
||||
}
|
||||
havearg = TRUE;
|
||||
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 +459,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,12 +473,16 @@ 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':
|
||||
s_flag = TRUE;
|
||||
s_flag = true;
|
||||
maxindex = index + 1;
|
||||
break;
|
||||
default:
|
||||
@@ -452,7 +501,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 +527,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++;
|
||||
@@ -507,35 +542,34 @@ main(int argc, char **argv)
|
||||
if (havecommands) {
|
||||
cmdbuf[cmdlen++] = '\n';
|
||||
cmdbuf[cmdlen] = '\0';
|
||||
if (p_flag != TRUE) {
|
||||
if (p_flag != true) {
|
||||
if (fclose(stdin)) {
|
||||
perror("main(): fclose(stdin) failed:");
|
||||
}
|
||||
stdin_closed = TRUE;
|
||||
stdin_closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
argc_value = argc - maxindex;
|
||||
argc_value = argc - maxindex + 1;
|
||||
argv_value = argv + maxindex;
|
||||
|
||||
/*
|
||||
* unbuffered mode
|
||||
*/
|
||||
if (u_flag) {
|
||||
if (stdin_closed == FALSE) {
|
||||
if (stdin_closed == false) {
|
||||
setbuf(stdin, NULL);
|
||||
}
|
||||
setbuf(stdout, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* initialize
|
||||
*/
|
||||
libcalc_call_me_first();
|
||||
if (u_flag) {
|
||||
if (conf->calc_debug & CALCDBG_TTY) {
|
||||
if (stdin_closed == FALSE) {
|
||||
if (stdin_closed == false) {
|
||||
printf("main: stdin set to unbuffered before "
|
||||
"calling libcalc_call_me_first()\n");
|
||||
} else {
|
||||
@@ -611,7 +645,7 @@ main(int argc, char **argv)
|
||||
while (run_state == RUN_RCFILES) {
|
||||
fprintf(stderr, "Error in rcfiles\n");
|
||||
if ((c_flag && !stoponerror) || stoponerror < 0) {
|
||||
getcommands(FALSE);
|
||||
getcommands(false);
|
||||
if (inputlevel() == 0) {
|
||||
closeinput();
|
||||
runrcfiles();
|
||||
@@ -632,7 +666,7 @@ main(int argc, char **argv)
|
||||
if (havecommands) {
|
||||
set_run_state(RUN_CMD_ARGS);
|
||||
(void) openstring(cmdbuf, strlen(cmdbuf));
|
||||
getcommands(FALSE);
|
||||
getcommands(false);
|
||||
closeinput();
|
||||
}
|
||||
set_run_state(RUN_PRE_TOP_LEVEL);
|
||||
@@ -641,7 +675,7 @@ main(int argc, char **argv)
|
||||
while (run_state == RUN_CMD_ARGS) {
|
||||
fprintf(stderr, "Error in commands\n");
|
||||
if ((c_flag && !stoponerror) || stoponerror < 0) {
|
||||
getcommands(FALSE);
|
||||
getcommands(false);
|
||||
if (inputlevel() == 0)
|
||||
set_run_state(RUN_PRE_TOP_LEVEL);
|
||||
closeinput();
|
||||
@@ -667,7 +701,7 @@ main(int argc, char **argv)
|
||||
openterminal();
|
||||
}
|
||||
set_run_state(RUN_TOP_LEVEL);
|
||||
getcommands(TRUE);
|
||||
getcommands(true);
|
||||
}
|
||||
if (p_flag || (!i_flag && havecommands))
|
||||
set_run_state(RUN_EXIT);
|
||||
@@ -677,7 +711,7 @@ main(int argc, char **argv)
|
||||
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
||||
printf("main: run_state = TOP_LEVEL\n");
|
||||
if ((c_flag && !stoponerror) || stoponerror < 0) {
|
||||
getcommands(TRUE);
|
||||
getcommands(true);
|
||||
if (!inputisterminal()) {
|
||||
closeinput();
|
||||
continue;
|
||||
@@ -685,23 +719,23 @@ 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;
|
||||
}
|
||||
|
||||
stdin_tty = TRUE;
|
||||
stdin_tty = true;
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("main: stdin_tty is %d\n",
|
||||
stdin_tty);
|
||||
@@ -710,27 +744,27 @@ main(int argc, char **argv)
|
||||
} else {
|
||||
if (stdin_tty) {
|
||||
reinitialize();
|
||||
getcommands(TRUE);
|
||||
getcommands(true);
|
||||
} else if (inputisterminal() &&
|
||||
!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;
|
||||
}
|
||||
stdin_tty = TRUE;
|
||||
stdin_tty = true;
|
||||
if (conf->calc_debug & CALCDBG_TTY)
|
||||
printf("main: stdin_tty is %d\n",
|
||||
stdin_tty);
|
||||
@@ -746,8 +780,6 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* All done! - Jessica Noll, Age 2
|
||||
*/
|
||||
/* fix gcc warning bug */
|
||||
unusedint++;
|
||||
libcalc_call_me_last();
|
||||
return (run_state == RUN_EXIT_WITH_ERROR ||
|
||||
run_state == RUN_ZERO) ? 1 : 0;
|
||||
@@ -762,15 +794,15 @@ 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;
|
||||
_math_abort_ = true;
|
||||
printf("\n[Abort level %d]\n", abortlevel);
|
||||
}
|
||||
|
||||
@@ -803,12 +835,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
S_FUNC int
|
||||
nextcp(char **cpp, int *ip, int argc, char **argv, BOOL haveendstr)
|
||||
nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr)
|
||||
{
|
||||
char *cp;
|
||||
int index;
|
||||
|
62
calc.h
62
calc.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* calc - definitions for calculator program
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2014,2021,2023 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
|
||||
@@ -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 */
|
||||
@@ -104,9 +104,9 @@
|
||||
E_FUNC FILEID openid(char *name, char *mode);
|
||||
E_FUNC FILEID openpathid(char *name, char *mode, char *pathlist);
|
||||
E_FUNC FILEID indexid(long index);
|
||||
E_FUNC BOOL validid(FILEID id);
|
||||
E_FUNC BOOL errorid(FILEID id);
|
||||
E_FUNC BOOL eofid(FILEID id);
|
||||
E_FUNC bool validid(FILEID id);
|
||||
E_FUNC bool errorid(FILEID id);
|
||||
E_FUNC bool eofid(FILEID id);
|
||||
E_FUNC int closeid(FILEID id);
|
||||
E_FUNC int getcharid(FILEID id);
|
||||
E_FUNC int idprintf(FILEID id, char *fmt, int count, VALUE **vals);
|
||||
@@ -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
|
||||
|
||||
@@ -157,7 +157,7 @@ E_FUNC int nextchar(void);
|
||||
E_FUNC void reread(void);
|
||||
E_FUNC void resetinput(void);
|
||||
E_FUNC void setprompt(char *);
|
||||
E_FUNC BOOL inputisterminal(void);
|
||||
E_FUNC bool inputisterminal(void);
|
||||
E_FUNC int inputlevel(void);
|
||||
E_FUNC long calclevel(void);
|
||||
E_FUNC char *inputname(void);
|
||||
@@ -172,12 +172,12 @@ E_FUNC NUMBER *constvalue(unsigned long index);
|
||||
E_FUNC long addnumber(char *str);
|
||||
E_FUNC long addqconstant(NUMBER *q);
|
||||
E_FUNC void initstack(void);
|
||||
E_FUNC void getcommands(BOOL toplevel);
|
||||
E_FUNC void getcommands(bool toplevel);
|
||||
E_FUNC void givehelp(char *type);
|
||||
E_FUNC void libcalc_call_me_first(void);
|
||||
E_FUNC void libcalc_call_me_last(void);
|
||||
E_FUNC BOOL calc_tty(int fd);
|
||||
E_FUNC BOOL orig_tty(int fd);
|
||||
E_FUNC bool calc_tty(int fd);
|
||||
E_FUNC bool orig_tty(int fd);
|
||||
E_FUNC void showerrors(void);
|
||||
E_FUNC char *calc_strdup(CONST char *);
|
||||
|
||||
@@ -186,8 +186,8 @@ E_FUNC char *calc_strdup(CONST char *);
|
||||
*/
|
||||
E_FUNC void initialize(void);
|
||||
E_FUNC void reinitialize(void);
|
||||
#if !defined (_WIN32)
|
||||
E_FUNC int isatty(int tty); /* TRUE if fd is a tty */
|
||||
#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 */
|
||||
|
||||
@@ -195,32 +195,34 @@ E_FUNC char *version(void); /* return version string */
|
||||
* global flags and definitions
|
||||
*/
|
||||
EXTERN int abortlevel; /* current level of aborts */
|
||||
EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */
|
||||
EXTERN bool inputwait; /* true if in a terminal input wait */
|
||||
|
||||
EXTERN int p_flag; /* TRUE => pipe mode */
|
||||
EXTERN int q_flag; /* TRUE => don't execute rc files */
|
||||
EXTERN int u_flag; /* TRUE => unbuffer stdin and stdout */
|
||||
EXTERN int d_flag; /* TRUE => disable heading, resource_debug */
|
||||
EXTERN int c_flag; /* TRUE => continue after error if permitted */
|
||||
EXTERN int i_flag; /* TRUE => try to go interactive after error */
|
||||
E_FUNC int s_flag; /* TRUE => keep args as strings for argv() */
|
||||
EXTERN int p_flag; /* true => pipe mode */
|
||||
EXTERN int q_flag; /* true => don't execute rc files */
|
||||
EXTERN int u_flag; /* true => unbuffer stdin and stdout */
|
||||
EXTERN int d_flag; /* true => disable heading, resource_debug */
|
||||
EXTERN int c_flag; /* true => continue after error if permitted */
|
||||
EXTERN int i_flag; /* true => try to go interactive after error */
|
||||
E_FUNC int s_flag; /* true => keep args as strings for argv() */
|
||||
EXTERN long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */
|
||||
EXTERN BOOL abort_now; /* TRUE => try to go interactive */
|
||||
EXTERN bool abort_now; /* true => try to go interactive */
|
||||
|
||||
E_FUNC int argc_value; /* count of argv[] strings for argv() builtin */
|
||||
E_FUNC char **argv_value; /* argv[] strings for argv() builtin */
|
||||
|
||||
EXTERN char *pager; /* $PAGER or default */
|
||||
EXTERN int stdin_tty; /* TRUE if stdin is a tty */
|
||||
EXTERN int havecommands; /* TRUE if have cmd args) */
|
||||
EXTERN int stdin_tty; /* true if stdin is a tty */
|
||||
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 */
|
||||
EXTERN bool inputwait; /* true if in a terminal input wait */
|
||||
EXTERN VALUE *stack; /* execution stack */
|
||||
EXTERN int dumpnames; /* TRUE => dump names rather than indices */
|
||||
EXTERN int dumpnames; /* true => dump names rather than indices */
|
||||
EXTERN int calc_errno; /* global calc_errno value */
|
||||
|
||||
EXTERN char *calcpath; /* $CALCPATH or default */
|
||||
EXTERN char *calcrc; /* $CALCRC or default */
|
||||
@@ -228,13 +230,13 @@ EXTERN char *calcbindings; /* $CALCBINDINGS or default */
|
||||
EXTERN char *home; /* $HOME or default */
|
||||
EXTERN char *shell; /* $SHELL or default */
|
||||
|
||||
EXTERN int no_env; /* TRUE (-e) => ignore env vars on startup */
|
||||
EXTERN int no_env; /* true (-e) => ignore env vars on startup */
|
||||
EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */
|
||||
EXTERN int use_old_std; /* TRUE (-O) => use classic configuration */
|
||||
EXTERN int use_old_std; /* true (-O) => use classic configuration */
|
||||
|
||||
EXTERN int allow_read; /* FALSE => don't open any files for reading */
|
||||
EXTERN int allow_write; /* FALSE => don't open any files for writing */
|
||||
EXTERN int allow_exec; /* FALSE => may not execute any commands */
|
||||
EXTERN int allow_read; /* false => don't open any files for reading */
|
||||
EXTERN int allow_write; /* false => don't open any files for writing */
|
||||
EXTERN int allow_exec; /* false => may not execute any commands */
|
||||
|
||||
/*
|
||||
* calc startup and run state
|
||||
|
566
calc.man
566
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,52 @@ 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
|
||||
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 +276,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 +290,32 @@ 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.
|
||||
.B NOTE:
|
||||
The use of
|
||||
.BR \-f
|
||||
does
|
||||
.B NOT
|
||||
imply
|
||||
.BR \-q
|
||||
and thus one would need to use
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
to disable the use of calc startup files as well.
|
||||
|
||||
.sp 1
|
||||
The use of
|
||||
.B \-f
|
||||
filename
|
||||
implies the
|
||||
.B \-s
|
||||
flag.
|
||||
|
||||
.TP
|
||||
.B \-h
|
||||
@@ -462,6 +473,13 @@ flag overrides
|
||||
.TP
|
||||
.B \-q
|
||||
Disable the reading of the startup scripts.
|
||||
.sp 1
|
||||
This allows the script to run independently of
|
||||
startup scripts such those managed by the
|
||||
.B $CALCRC
|
||||
environment variable.
|
||||
For example, this will disable the use of the common calcrc file
|
||||
(usually ~/.calcrc).
|
||||
|
||||
.TP
|
||||
.B \-s
|
||||
@@ -491,16 +509,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 +618,7 @@ may have to be replaced by:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
print 27! ^2 or print 27\!^2
|
||||
print 27! ^2 or print 27\\!^2
|
||||
.fi
|
||||
.in -5n
|
||||
|
||||
@@ -638,10 +656,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 +696,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 +778,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 +806,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 +819,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
|
||||
@@ -815,13 +835,30 @@ are automatically set if
|
||||
.B \-i
|
||||
is not given.
|
||||
.sp 1
|
||||
.B NOTE:
|
||||
The use of
|
||||
.BR \-f
|
||||
does
|
||||
.B NOT
|
||||
imply
|
||||
.BR \-q
|
||||
and thus one would need to use
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
to disable the use of calc startup files as well.
|
||||
.sp 1
|
||||
For example, if
|
||||
the file
|
||||
.BR /tmp/mersenne :
|
||||
.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 +931,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 +960,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 +989,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 +1025,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 +1058,13 @@ help operator
|
||||
.br
|
||||
help config
|
||||
.in -1.0i
|
||||
|
||||
.PP
|
||||
|
||||
.SH FILES
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
.PD 0
|
||||
.TP 5
|
||||
${BINDIR}/calc
|
||||
@@ -1062,9 +1106,13 @@ custom resource files
|
||||
${CUSTOMHELPDIR}/*
|
||||
custom help files
|
||||
.sp 1
|
||||
|
||||
.PP
|
||||
|
||||
.SH ENVIRONMENT
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
.PD 0
|
||||
.TP 5
|
||||
CALCPATH
|
||||
@@ -1123,9 +1171,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 +1206,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
|
||||
@@ -1170,6 +1225,7 @@ The calc commands:
|
||||
help copyright
|
||||
help copying
|
||||
help copying-lgpl
|
||||
help credit
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
@@ -1204,6 +1260,10 @@ Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
Copyright (C) year Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen and Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||
Copyright (C) year Christoph Zurnieden
|
||||
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
|
||||
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
@@ -1211,272 +1271,149 @@ This man page is:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
Copyright (C) 1999-2021 Landon Curt Noll
|
||||
Copyright (C) 1999-2023 Landon Curt Noll
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
and is covered under version 2.1 GNU Lesser General
|
||||
Public License.
|
||||
.sp
|
||||
A few files in calc are covered under "The Unlicense".
|
||||
For more information on this license, see:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
https://unlicense.org
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CALC QUESTIONS"
|
||||
\&
|
||||
.br
|
||||
If you have a simple general question about calc, send Email to:
|
||||
.sp
|
||||
.in +0.5i
|
||||
calc-quest-mail at asthe dot com
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
|
||||
.in -0.5i
|
||||
.sp
|
||||
.in +0.5i
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
.B PLEASE
|
||||
put following the
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc question
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
.PP
|
||||
|
||||
To ask the calc maintainers a general question about calc,
|
||||
see the output of the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
|
||||
; help question
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
Please limit your questions to general questions about calc.
|
||||
We cannot go into great detail in our answers,
|
||||
nor can we do your homework, nor can
|
||||
we do much more than answer short general questions about calc.
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.in +0.5i
|
||||
.nf
|
||||
QUESTIONS
|
||||
.fi
|
||||
.in +0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
https://github.com/lcn2/calc/blob/master/QUESTIONS
|
||||
.fi
|
||||
.in +0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "BUG REPORTS / BUG FIXES"
|
||||
\&
|
||||
.br
|
||||
.sp
|
||||
Send bug reports and bug fixes to:
|
||||
|
||||
.PP
|
||||
|
||||
To inform the calc maintainers about a bug, or to submit a bug fix,
|
||||
see the output of the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
calc-bugrept at asthe dot com
|
||||
; help bugs
|
||||
.fi
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
.sp
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
You
|
||||
.B MUST
|
||||
use following
|
||||
.B SPECIAL PHRASE
|
||||
in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc bug report
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
|
||||
BUGS
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
See the
|
||||
.I BUGS
|
||||
source file or use the
|
||||
.I calc
|
||||
command:
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
help bugs
|
||||
https://github.com/lcn2/calc/blob/master/BUGS
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
for more information about bug reporting.
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.in +0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CONTRIBUTING CODE TO CALC"
|
||||
\&
|
||||
.br
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.I Calc
|
||||
is open source.
|
||||
Contributions of code are welcome.
|
||||
.sp
|
||||
We welcome and encourage you to send us:
|
||||
You are welcome to contribute code to calc, or submit bug fixes to to calc.
|
||||
.sp
|
||||
To contribute code to calc, please see see the output of
|
||||
the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
* calc resource files (cal/*.cal)
|
||||
* calc shell scripts (cscript/*.calc)
|
||||
* builtin functions that you have modified or written, i.e.:
|
||||
assocfunc.c comfunc.c func.c func.h
|
||||
listfunc.c matfunc.c qfunc.c zfunc.c
|
||||
* custom functions that you have modified or written (custom/*)
|
||||
* help files modified or written (help/*)
|
||||
* brief description of you added, fixed, improved in CHANGES
|
||||
* regression test cases (cal/regress.cal)
|
||||
* Makefile improvements (Makefile, */Makefile)
|
||||
* other source code modifications (*.c, *.h)
|
||||
* etc. (* */* :) )
|
||||
; help contrib
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
If you add functionality to calc, please be sure to modify/patch/add
|
||||
Makefiles, help files, cal/regress.cal test code as well.
|
||||
Regression test cases are vital to maintaining calc's level
|
||||
of correctness and helps us avoid code bug regression.
|
||||
.sp
|
||||
In order to consider integrating your code, we need:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
* calc version you are working with (please try use the latest version)
|
||||
* new help files or help file patches, if applicable (documentation)
|
||||
* proposed text for the CHANGES file (brief description of what it does)
|
||||
* regress.cal test patch as needed
|
||||
* your source code and/or source code changes (:-))
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
The best way to send us new code, if your changes are small, is
|
||||
via a patch (diff -c from the latest alpha code to your code).
|
||||
If your change is large, you should send entire files (either
|
||||
as a diff -c /dev/null your-file patch, or as a uuencoded and
|
||||
gziped (or compressed) tar file).
|
||||
.sp
|
||||
Please try to generate a patch against the most recent
|
||||
version of calc, and if you use GitHub, the top of the
|
||||
master branch:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
.sp
|
||||
The best way contribute to calc bug is to generate calc
|
||||
GitHub pull request:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc/pulls
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
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:
|
||||
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
calc-contrib at asthe dot com
|
||||
CONTRIB-CODE
|
||||
.fi
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
.sp
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
You
|
||||
.B MUST
|
||||
use following
|
||||
.B SPECIAL PHRASE
|
||||
in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc contribution
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
|
||||
https://github.com/lcn2/calc/blob/master/CONTRIB-CODE
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
.in +0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
.SH "CALC WEB SITE"
|
||||
\&
|
||||
.br
|
||||
|
||||
.PP
|
||||
|
||||
Landon Noll maintains the
|
||||
.B calc
|
||||
web site is located at:
|
||||
@@ -1484,5 +1421,30 @@ web site is located at:
|
||||
.in +0.5i
|
||||
www.isthe.com/chongo/tech/comp/calc/
|
||||
.in -0.5i
|
||||
|
||||
.SH "CALC SOURCE CODE"
|
||||
|
||||
The latest version of calc source code may be obtained at
|
||||
the following GitHub repo:
|
||||
.sp
|
||||
Share and Enjoy! :\-)
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc
|
||||
.in -0.5i
|
||||
.sp
|
||||
The very latest calc souece is found at the top master branch.
|
||||
|
||||
.PP
|
||||
|
||||
You may download the calc releases from:
|
||||
.sp
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc/releases
|
||||
.in -0.5i
|
||||
.sp
|
||||
The releases marked
|
||||
.B ((Pre-release))
|
||||
are beta releases.
|
||||
.sp
|
||||
The most recent release that is NOT marked
|
||||
.B ((Pre-release))
|
||||
is the recommended stable release.
|
||||
|
45
calc.spec.in
45
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,2023 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
|
||||
@@ -20,23 +20,25 @@
|
||||
# Under source code control: 2003/02/16 20:21:39
|
||||
# File existed as early as: 2003
|
||||
#
|
||||
# calculator by David I. Bell with help/mods from others
|
||||
# Makefile by Petteri Kettunen with modifications from Landon Curt Noll
|
||||
# This calculator first developed by David I. Bell with help/mods from others.
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
# BUGS
|
||||
# - Uninstalling calc and calc-devel leaves empty dirs /usr/include/calc
|
||||
# and /usr/share/calc and its subdirs. In case e.g. %{_includedir}/calc
|
||||
# and /usr/share/calc and its subdirs. In case e.g., _includedir/calc
|
||||
# is defined in `files devel' section, then rpmbuild complains that
|
||||
# header files are defined twice - rpmbuild bug or bug in specfile conf???
|
||||
|
||||
Summary: Arbitrary precision calculator.
|
||||
Name: calc
|
||||
Version: <<<PROJECT_VERSION>>>
|
||||
Release: 13
|
||||
Release: 14
|
||||
License: LGPL
|
||||
Group: Applications/Engineering
|
||||
Source: http://www.isthe.com/chongo/src/calc/%{name}-%{version}.tar.bz2
|
||||
URL: http://www.isthe.com/chongo/tech/comp/calc/index.html
|
||||
Source: https://github.com/lcn2/calc/releases/download/v<<<PROJECT_VERSION>>>/%{name}-%{version}.tar.bz2
|
||||
URL: https://github.com/lcn2/calc
|
||||
Vendor: Landon Noll and Associates
|
||||
Packager: Landon Noll and Associates (http://www.isthe.com/chongo/index.html)
|
||||
Requires: ncurses >= 5.5-24, readline >= 5.1-3, less >= 358
|
||||
@@ -49,9 +51,13 @@ 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:
|
||||
For the latest calc release, see the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
or the calc home page:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/index.html
|
||||
|
||||
@@ -67,7 +73,11 @@ Requires: ncurses >= 5.5-24, readline >= 5.1-3, less >= 358
|
||||
This package contains the header files and static libraries for developing
|
||||
calc (arbitrary precision calculator).
|
||||
|
||||
For the latest calc release, see the project home page:
|
||||
For the latest calc release, see the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
or the calc home page:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/index.html
|
||||
|
||||
@@ -152,8 +162,10 @@ echo '-=- calc.spec beginning make clean -=-'
|
||||
%attr(644, root, root) %{_datadir}/%{name}/*.cal
|
||||
%attr(644, root, root) %{_datadir}/%{name}/set8700.line
|
||||
%attr(644, root, root) %{_libdir}/libcalc.so
|
||||
%attr(644, root, root) %{_libdir}/libcalc.so.<<<PROJECT_VER>>>
|
||||
%attr(644, root, root) %{_libdir}/libcalc.so.%{version}
|
||||
%attr(644, root, root) %{_libdir}/libcustcalc.so
|
||||
%attr(644, root, root) %{_libdir}/libcustcalc.so.<<<PROJECT_VER>>>
|
||||
%attr(644, root, root) %{_libdir}/libcustcalc.so.%{version}
|
||||
|
||||
%files devel
|
||||
@@ -165,11 +177,16 @@ 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
|
||||
* Mon Aug 14 2023 Landon Curt Noll http://www.isthe.com/chongo
|
||||
- Release: 14
|
||||
- Use Source and URL based on calc GitHub repo URLs.
|
||||
- Install dynamic shared libraries with 3-digit version numbers.
|
||||
|
||||
* 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 +195,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,
|
||||
|
498
calcerr.tbl
498
calcerr.tbl
@@ -1,498 +0,0 @@
|
||||
#
|
||||
# calcerr - error codes and messages
|
||||
#
|
||||
# Copyright (C) 1999-2006 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
|
||||
# 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: 1996/05/23 17:38:44
|
||||
# File existed as early as: 1996
|
||||
#
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
# This file is used to build calcerr.h include file.
|
||||
#
|
||||
# Lines should be of the form:
|
||||
#
|
||||
# SYMBOL meaning
|
||||
|
||||
######################################################################
|
||||
# WARNING: The order of the lines below is critical! If you change #
|
||||
# the order, you will break code that depends on the return #
|
||||
# value of the errno() builtin function. #
|
||||
# #
|
||||
# If you need to add values to this table, ONLY add then #
|
||||
# to the bottom of the file! #
|
||||
######################################################################
|
||||
|
||||
|
||||
E_1OVER0 Division by zero
|
||||
E_0OVER0 Indeterminate (0/0)
|
||||
E_ADD Bad arguments for +
|
||||
E_SUB Bad arguments for binary -
|
||||
E_MUL Bad arguments for *
|
||||
E_DIV Bad arguments for /
|
||||
E_NEG Bad argument for unary -
|
||||
E_SQUARE Bad argument for squaring
|
||||
E_INV Bad argument for inverse
|
||||
E_INCV Bad argument for ++
|
||||
E_DECV Bad argument for --
|
||||
E_INT Bad argument for int
|
||||
E_FRAC Bad argument for frac
|
||||
E_CONJ Bad argument for conj
|
||||
E_APPR Bad first argument for appr
|
||||
E_APPR2 Bad second argument for appr
|
||||
E_APPR3 Bad third argument for appr
|
||||
E_ROUND Bad first argument for round
|
||||
E_ROUND2 Bad second argument for round
|
||||
E_ROUND3 Bad third argument for round
|
||||
E_BROUND Bad first argument for bround
|
||||
E_BROUND2 Bad second argument for bround
|
||||
E_BROUND3 Bad third argument for bround
|
||||
E_SQRT Bad first argument for sqrt
|
||||
E_SQRT2 Bad second argument for sqrt
|
||||
E_SQRT3 Bad third argument for sqrt
|
||||
E_ROOT Bad first argument for root
|
||||
E_ROOT2 Bad second argument for root
|
||||
E_ROOT3 Bad third argument for root
|
||||
E_NORM Bad argument for norm
|
||||
E_SHIFT Bad first argument for << or >>
|
||||
E_SHIFT2 Bad second argument for << or >>
|
||||
E_SCALE Bad first argument for scale
|
||||
E_SCALE2 Bad second argument for scale
|
||||
E_POWI Bad first argument for ^
|
||||
E_POWI2 Bad second argument for ^
|
||||
E_POWER Bad first argument for power
|
||||
E_POWER2 Bad second argument for power
|
||||
E_POWER3 Bad third argument for power
|
||||
E_QUO Bad first argument for quo or //
|
||||
E_QUO2 Bad second argument for quo or //
|
||||
E_QUO3 Bad third argument for quo
|
||||
E_MOD Bad first argument for mod or %
|
||||
E_MOD2 Bad second argument for mod or %
|
||||
E_MOD3 Bad third argument for mod
|
||||
E_SGN Bad argument for sgn
|
||||
E_ABS Bad first argument for abs
|
||||
E_ABS2 Bad second argument for abs
|
||||
E_EVAL Scan error in argument for eval
|
||||
E_STR Non-simple type for str
|
||||
E_EXP1 Non-real epsilon for exp
|
||||
E_EXP2 Bad first argument for exp
|
||||
E_FPUTC1 Non-file first argument for fputc
|
||||
E_FPUTC2 Bad second argument for fputc
|
||||
E_FPUTC3 File not open for writing for fputc
|
||||
E_FGETC1 Non-file first argument for fgetc
|
||||
E_FGETC2 File not open for reading for fgetc
|
||||
E_FOPEN1 Non-string arguments for fopen
|
||||
E_FOPEN2 Unrecognized mode for fopen
|
||||
E_FREOPEN1 Non-file first argument for freopen
|
||||
E_FREOPEN2 Non-string or unrecognized mode for freopen
|
||||
E_FREOPEN3 Non-string third argument for freopen
|
||||
E_FCLOSE1 Non-file argument for fclose
|
||||
E_FFLUSH Non-file argument for fflush
|
||||
E_FPUTS1 Non-file first argument for fputs
|
||||
E_FPUTS2 Non-string argument after first for fputs
|
||||
E_FPUTS3 File not open for writing for fputs
|
||||
E_FGETS1 Non-file argument for fgets
|
||||
E_FGETS2 File not open for reading for fgets
|
||||
E_FPUTSTR1 Non-file first argument for fputstr
|
||||
E_FPUTSTR2 Non-string argument after first for fputstr
|
||||
E_FPUTSTR3 File not open for writing for fputstr
|
||||
E_FGETSTR1 Non-file first argument for fgetstr
|
||||
E_FGETSTR2 File not open for reading for fgetstr
|
||||
E_FGETLINE1 Non-file argument for fgetline
|
||||
E_FGETLINE2 File not open for reading for fgetline
|
||||
E_FGETFIELD1 Non-file argument for fgetfield
|
||||
E_FGETFIELD2 File not open for reading for fgetfield
|
||||
E_REWIND1 Non-file argument for rewind
|
||||
E_FILES Non-integer argument for files
|
||||
E_PRINTF1 Non-string fmt argument for fprint
|
||||
E_PRINTF2 Stdout not open for writing to ???
|
||||
E_FPRINTF1 Non-file first argument for fprintf
|
||||
E_FPRINTF2 Non-string second (fmt) argument for fprintf
|
||||
E_FPRINTF3 File not open for writing for fprintf
|
||||
E_STRPRINTF1 Non-string first (fmt) argument for strprintf
|
||||
E_STRPRINTF2 Error in attempting strprintf ???
|
||||
E_FSCAN1 Non-file first argument for fscan
|
||||
E_FSCAN2 File not open for reading for fscan
|
||||
E_STRSCAN Non-string first argument for strscan
|
||||
E_FSCANF1 Non-file first argument for fscanf
|
||||
E_FSCANF2 Non-string second (fmt) argument for fscanf
|
||||
E_FSCANF3 Non-lvalue argument after second for fscanf
|
||||
E_FSCANF4 File not open for reading or other error for fscanf
|
||||
E_STRSCANF1 Non-string first argument for strscanf
|
||||
E_STRSCANF2 Non-string second (fmt) argument for strscanf
|
||||
E_STRSCANF3 Non-lvalue argument after second for strscanf
|
||||
E_STRSCANF4 Some error in attempting strscanf ???
|
||||
E_SCANF1 Non-string first (fmt) argument for scanf
|
||||
E_SCANF2 Non-lvalue argument after first for scanf
|
||||
E_SCANF3 Some error in attempting scanf ???
|
||||
E_FTELL1 Non-file argument for ftell
|
||||
E_FTELL2 File not open or other error for ftell
|
||||
E_FSEEK1 Non-file first argument for fseek
|
||||
E_FSEEK2 Non-integer or negative second argument for fseek
|
||||
E_FSEEK3 File not open or other error for fseek
|
||||
E_FSIZE1 Non-file argument for fsize
|
||||
E_FSIZE2 File not open or other error for fsize
|
||||
E_FEOF1 Non-file argument for feof
|
||||
E_FEOF2 File not open or other error for feof
|
||||
E_FERROR1 Non-file argument for ferror
|
||||
E_FERROR2 File not open or other error for ferror
|
||||
E_UNGETC1 Non-file argument for ungetc
|
||||
E_UNGETC2 File not open for reading for ungetc
|
||||
E_UNGETC3 Bad second argument or other error for ungetc
|
||||
E_BIGEXP Exponent too big in scanning
|
||||
E_ISATTY1 E_ISATTY1 is no longer used
|
||||
E_ISATTY2 E_ISATTY2 is no longer used
|
||||
E_ACCESS1 Non-string first argument for access
|
||||
E_ACCESS2 Bad second argument for access
|
||||
E_SEARCH1 Bad first argument for search
|
||||
E_SEARCH2 Bad second argument for search
|
||||
E_SEARCH3 Bad third argument for search
|
||||
E_SEARCH4 Bad fourth argument for search
|
||||
E_SEARCH5 Cannot find fsize or fpos for search
|
||||
E_SEARCH6 File not readable for search
|
||||
E_RSEARCH1 Bad first argument for rsearch
|
||||
E_RSEARCH2 Bad second argument for rsearch
|
||||
E_RSEARCH3 Bad third argument for rsearch
|
||||
E_RSEARCH4 Bad fourth argument for rsearch
|
||||
E_RSEARCH5 Cannot find fsize or fpos for rsearch
|
||||
E_RSEARCH6 File not readable for rsearch
|
||||
E_MANYOPEN Too many open files
|
||||
E_REWIND2 Attempt to rewind a file that is not open
|
||||
E_STRERROR1 Bad argument type for strerror
|
||||
E_STRERROR2 Index out of range for strerror
|
||||
E_COS1 Bad epsilon for cos
|
||||
E_COS2 Bad first argument for cos
|
||||
E_SIN1 Bad epsilon for sin
|
||||
E_SIN2 Bad first argument for sin
|
||||
E_EVAL2 Non-string argument for eval
|
||||
E_ARG1 Bad epsilon for arg
|
||||
E_ARG2 Bad first argument for arg
|
||||
E_POLAR1 Non-real argument for polar
|
||||
E_POLAR2 Bad epsilon for polar
|
||||
E_FCNT Non-integral argument for fcnt
|
||||
E_MATFILL1 Non-variable first argument for matfill
|
||||
E_MATFILL2 Non-matrix first argument-value for matfill
|
||||
E_MATDIM Non-matrix argument for matdim
|
||||
E_MATSUM Non-matrix argument for matsum
|
||||
E_ISIDENT E_ISIDENT is no longer used
|
||||
E_MATTRANS1 Non-matrix argument for mattrans
|
||||
E_MATTRANS2 Non-two-dimensional matrix for mattrans
|
||||
E_DET1 Non-matrix argument for det
|
||||
E_DET2 Matrix for det not of dimension 2
|
||||
E_DET3 Non-square matrix for det
|
||||
E_MATMIN1 Non-matrix first argument for matmin
|
||||
E_MATMIN2 Non-positive-integer second argument for matmin
|
||||
E_MATMIN3 Second argument for matmin exceeds dimension
|
||||
E_MATMAX1 Non-matrix first argument for matmin
|
||||
E_MATMAX2 Second argument for matmax not positive integer
|
||||
E_MATMAX3 Second argument for matmax exceeds dimension
|
||||
E_CP1 Non-matrix argument for cp
|
||||
E_CP2 Non-one-dimensional matrix for cp
|
||||
E_CP3 Matrix size not 3 for cp
|
||||
E_DP1 Non-matrix argument for dp
|
||||
E_DP2 Non-one-dimensional matrix for dp
|
||||
E_DP3 Different-size matrices for dp
|
||||
E_STRLEN Non-string argument for strlen
|
||||
E_STRCAT Non-string argument for strcat
|
||||
E_SUBSTR1 Non-string first argument for strcat
|
||||
E_SUBSTR2 Non-non-negative integer second argument for strcat
|
||||
E_CHAR Bad argument for char
|
||||
E_ORD Non-string argument for ord
|
||||
E_INSERT1 Non-list-variable first argument for insert
|
||||
E_INSERT2 Non-integral second argument for insert
|
||||
E_PUSH Non-list-variable first argument for push
|
||||
E_APPEND Non-list-variable first argument for append
|
||||
E_DELETE1 Non-list-variable first argument for delete
|
||||
E_DELETE2 Non-integral second argument for delete
|
||||
E_POP Non-list-variable argument for pop
|
||||
E_REMOVE Non-list-variable argument for remove
|
||||
E_LN1 Bad epsilon argument for ln
|
||||
E_LN2 Non-numeric first argument for ln
|
||||
E_ERROR1 Non-integer argument for error
|
||||
E_ERROR2 Argument outside range for error
|
||||
E_EVAL3 Attempt to eval at maximum input depth
|
||||
E_EVAL4 Unable to open string for reading
|
||||
E_RM1 First argument for rm is not a non-empty string
|
||||
E_RM2 Unable to remove a file
|
||||
E_RDPERM Operation allowed because calc mode disallows read operations
|
||||
E_WRPERM Operation allowed because calc mode disallows write operations
|
||||
E_EXPERM Operation allowed because calc mode disallows exec operations
|
||||
E_MIN Unordered arguments for min
|
||||
E_MAX Unordered arguments for max
|
||||
E_LISTMIN Unordered items for minimum of list
|
||||
E_LISTMAX Unordered items for maximum of list
|
||||
E_SIZE Size undefined for argument type
|
||||
E_NO_C_ARG Calc must be run with a -C argument to use custom function
|
||||
E_NO_CUSTOM Calc was built with custom functions disabled
|
||||
E_UNK_CUSTOM Custom function unknown, try: show custom
|
||||
E_BLK1 Non-integral length for block
|
||||
E_BLK2 Negative or too-large length for block
|
||||
E_BLK3 Non-integral chunksize for block
|
||||
E_BLK4 Negative or too-large chunksize for block
|
||||
E_BLKFREE1 Named block does not exist for blkfree
|
||||
E_BLKFREE2 Non-integral id specification for blkfree
|
||||
E_BLKFREE3 Block with specified id does not exist
|
||||
E_BLKFREE4 Block already freed
|
||||
E_BLKFREE5 No-realloc protection prevents blkfree
|
||||
E_BLOCKS1 Non-integer argument for blocks
|
||||
E_BLOCKS2 Non-allocated index number for blocks
|
||||
E_COPY1 Non-integer or negative source index for copy
|
||||
E_COPY2 Source index too large for copy
|
||||
E_COPY3 E_COPY3 is no longer used
|
||||
E_COPY4 Non-integer or negative number for copy
|
||||
E_COPY5 Number too large for copy
|
||||
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_COPY11 Unsuitable destination type for copy
|
||||
E_COPY12 Incompatible source and destination for copy
|
||||
E_COPY13 No-copy-from source variable
|
||||
E_COPY14 No-copy-to destination variable
|
||||
E_COPY15 No-copy-from source named block
|
||||
E_COPY16 No-copy-to destination named block
|
||||
E_COPY17 No-relocate destination for copy
|
||||
E_COPYF1 File not open for copy
|
||||
E_COPYF2 fseek or fsize failure for copy
|
||||
E_COPYF3 fwrite error for copy
|
||||
E_COPYF4 fread error for copy
|
||||
E_PROTECT1 Non-variable first argument for protect
|
||||
E_PROTECT2 Bad second argument for protect
|
||||
E_PROTECT3 Bad third argument for protect
|
||||
E_MATFILL3 No-copy-to destination for matfill
|
||||
E_MATFILL4 No-assign-from source for matfill
|
||||
E_MATTRACE1 Non-matrix argument for mattrace
|
||||
E_MATTRACE2 Non-two-dimensional argument for mattrace
|
||||
E_MATTRACE3 Non-square argument for mattrace
|
||||
E_TAN1 Bad epsilon for tan
|
||||
E_TAN2 Bad argument for tan
|
||||
E_COT1 Bad epsilon for cot
|
||||
E_COT2 Bad argument for cot
|
||||
E_SEC1 Bad epsilon for sec
|
||||
E_SEC2 Bad argument for sec
|
||||
E_CSC1 Bad epsilon for csc
|
||||
E_CSC2 Bad argument for csc
|
||||
E_SINH1 Bad epsilon for sinh
|
||||
E_SINH2 Bad argument for sinh
|
||||
E_COSH1 Bad epsilon for cosh
|
||||
E_COSH2 Bad argument for cosh
|
||||
E_TANH1 Bad epsilon for tanh
|
||||
E_TANH2 Bad argument for tanh
|
||||
E_COTH1 Bad epsilon for coth
|
||||
E_COTH2 Bad argument for coth
|
||||
E_SECH1 Bad epsilon for sech
|
||||
E_SECH2 Bad argument for sech
|
||||
E_CSCH1 Bad epsilon for csch
|
||||
E_CSCH2 Bad argument for csch
|
||||
E_ASIN1 Bad epsilon for asin
|
||||
E_ASIN2 Bad argument for asin
|
||||
E_ACOS1 Bad epsilon for acos
|
||||
E_ACOS2 Bad argument for acos
|
||||
E_ATAN1 Bad epsilon for atan
|
||||
E_ATAN2 Bad argument for atan
|
||||
E_ACOT1 Bad epsilon for acot
|
||||
E_ACOT2 Bad argument for acot
|
||||
E_ASEC1 Bad epsilon for asec
|
||||
E_ASEC2 Bad argument for asec
|
||||
E_ACSC1 Bad epsilon for acsc
|
||||
E_ACSC2 Bad argument for acsc
|
||||
E_ASINH1 Bad epsilon for asin
|
||||
E_ASINH2 Bad argument for asinh
|
||||
E_ACOSH1 Bad epsilon for acosh
|
||||
E_ACOSH2 Bad argument for acosh
|
||||
E_ATANH1 Bad epsilon for atanh
|
||||
E_ATANH2 Bad argument for atanh
|
||||
E_ACOTH1 Bad epsilon for acoth
|
||||
E_ACOTH2 Bad argument for acoth
|
||||
E_ASECH1 Bad epsilon for asech
|
||||
E_ASECH2 Bad argument for asech
|
||||
E_ACSCH1 Bad epsilon for acsch
|
||||
E_ACSCH2 Bad argument for acsch
|
||||
E_GD1 Bad epsilon for gd
|
||||
E_GD2 Bad argument for gd
|
||||
E_AGD1 Bad epsilon for agd
|
||||
E_AGD2 Bad argument for agd
|
||||
E_LOGINF Log of zero or infinity
|
||||
E_STRADD String addition failure
|
||||
E_STRMUL String multiplication failure
|
||||
E_STRNEG String reversal failure
|
||||
E_STRSUB String subtraction failure
|
||||
E_BIT1 Bad argument type for bit
|
||||
E_BIT2 Index too large for bit
|
||||
E_SETBIT1 Non-integer second argument for setbit
|
||||
E_SETBIT2 Out-of-range index for setbit
|
||||
E_SETBIT3 Non-string first argument for setbit
|
||||
E_OR Bad argument for or
|
||||
E_AND Bad argument for and
|
||||
E_STROR Allocation failure for string or
|
||||
E_STRAND Allocation failure for string and
|
||||
E_XOR Bad argument for xorvalue
|
||||
E_COMP Bad argument for comp
|
||||
E_STRDIFF Allocation failure for string diff
|
||||
E_STRCOMP Allocation failure for string comp
|
||||
E_SEG1 Bad first argument for segment
|
||||
E_SEG2 Bad second argument for segment
|
||||
E_SEG3 Bad third argument for segment
|
||||
E_STRSEG Failure for string segment
|
||||
E_HIGHBIT1 Bad argument type for highbit
|
||||
E_HIGHBIT2 Non-integer argument for highbit
|
||||
E_LOWBIT1 Bad argument type for lowbit
|
||||
E_LOWBIT2 Non-integer argument for lowbit
|
||||
E_CONTENT Bad argument type for unary hash op
|
||||
E_HASHOP Bad argument type for binary hash op
|
||||
E_HEAD1 Bad first argument for head
|
||||
E_HEAD2 Bad second argument for head
|
||||
E_STRHEAD Failure for strhead
|
||||
E_TAIL1 Bad first argument for tail
|
||||
E_TAIL2 Bad second argument for tail
|
||||
E_STRTAIL Failure for strtail
|
||||
E_STRSHIFT Failure for strshift
|
||||
E_STRCMP Non-string argument for strcmp
|
||||
E_STRNCMP Bad argument type for strncmp
|
||||
E_XOR1 Varying types of argument for xor
|
||||
E_XOR2 Bad argument type for xor
|
||||
E_STRCPY Bad argument type for strcpy
|
||||
E_STRNCPY Bad argument type for strncpy
|
||||
E_BACKSLASH Bad argument type for unary backslash
|
||||
E_SETMINUS Bad argument type for setminus
|
||||
E_INDICES1 Bad first argument type for indices
|
||||
E_INDICES2 Bad second argument for indices
|
||||
E_EXP3 Too-large re(argument) for exp
|
||||
E_SINH3 Too-large re(argument) for sinh
|
||||
E_COSH3 Too-large re(argument) for cosh
|
||||
E_SIN3 Too-large im(argument) for sin
|
||||
E_COS3 Too-large im(argument) for cos
|
||||
E_GD3 Infinite or too-large result for gd
|
||||
E_AGD3 Infinite or too-large result for agd
|
||||
E_POWER4 Too-large value for power
|
||||
E_ROOT4 Too-large value for root
|
||||
E_DGT1 Non-real first arg for digit
|
||||
E_DGT2 Non-integral second arg for digit
|
||||
E_DGT3 Bad third arg for digit
|
||||
E_PLCS1 Bad first argument for places
|
||||
E_PLCS2 Bad second argument for places
|
||||
E_DGTS1 Bad first argument for digits
|
||||
E_DGTS2 Bad second argument for digits
|
||||
E_ILOG Bad first argument for ilog
|
||||
E_ILOGB Bad second argument for ilog
|
||||
E_ILOG10 Bad argument for ilog10
|
||||
E_ILOG2 Bad argument for ilog2
|
||||
E_COMB1 Non-integer second arg for comb
|
||||
E_COMB2 Too-large second arg for comb
|
||||
E_CTLN Bad argument for catalan
|
||||
E_BERN Bad argument for bern
|
||||
E_EULER Bad argument for euler
|
||||
E_SLEEP Bad argument for sleep
|
||||
E_TTY calc_tty failure
|
||||
E_ASSIGN1 No-copy-to destination for octet assign
|
||||
E_ASSIGN2 No-copy-from source for octet assign
|
||||
E_ASSIGN3 No-change destination for octet assign
|
||||
E_ASSIGN4 Non-variable destination for assign
|
||||
E_ASSIGN5 No-assign-to destination for assign
|
||||
E_ASSIGN6 No-assign-from source for assign
|
||||
E_ASSIGN7 No-change destination for assign
|
||||
E_ASSIGN8 No-type-change destination for assign
|
||||
E_ASSIGN9 No-error-value destination for assign
|
||||
E_SWAP1 No-copy argument for octet swap
|
||||
E_SWAP2 No-assign-to-or-from argument for swap
|
||||
E_SWAP3 Non-lvalue argument for swap
|
||||
E_QUOMOD1 Non-lvalue argument 3 or 4 for quomod
|
||||
E_QUOMOD2 Non-real-number arg 1 or 2 or bad arg 5 for quomod
|
||||
E_QUOMOD3 No-assign-to argument 3 or 4 for quomod
|
||||
E_PREINC1 No-copy-to or no-change argument for octet preinc
|
||||
E_PREINC2 Non-variable argument for preinc
|
||||
E_PREINC3 No-assign-to or no-change argument for preinc
|
||||
E_PREDEC1 No-copy-to or no-change argument for octet predec
|
||||
E_PREDEC2 Non-variable argument for predec
|
||||
E_PREDEC3 No-assign-to or no-change argument for predec
|
||||
E_POSTINC1 No-copy-to or no-change argument for octet postinc
|
||||
E_POSTINC2 Non-variable argument for postinc
|
||||
E_POSTINC3 No-assign-to or no-change argument for postinc
|
||||
E_POSTDEC1 No-copy-to or no-change argument for octet postdec
|
||||
E_POSTDEC2 Non-variable argument for postdec
|
||||
E_POSTDEC3 No-assign-to or no-change argument for postdec
|
||||
E_INIT1 Error-type structure for initialization
|
||||
E_INIT2 No-copy-to structure for initialization
|
||||
E_INIT3 Too many initializer values
|
||||
E_INIT4 Attempt to initialize freed named block
|
||||
E_INIT5 Bad structure type for initialization
|
||||
E_INIT6 No-assign-to element for initialization
|
||||
E_INIT7 No-change element for initialization
|
||||
E_INIT8 No-type-change element for initialization
|
||||
E_INIT9 No-error-value element for initialization
|
||||
E_INIT10 No-assign-or-copy-from source for initialization
|
||||
E_LIST1 No-relocate for list insert
|
||||
E_LIST2 No-relocate for list delete
|
||||
E_LIST3 No-relocate for list push
|
||||
E_LIST4 No-relocate for list append
|
||||
E_LIST5 No-relocate for list pop
|
||||
E_LIST6 No-relocate for list remove
|
||||
E_MODIFY1 Non-variable first argument for modify
|
||||
E_MODIFY2 Non-string second argument for modify
|
||||
E_MODIFY3 No-change first argument for modify
|
||||
E_MODIFY4 Undefined function for modify
|
||||
E_MODIFY5 Unacceptable type first argument for modify
|
||||
E_FPATHOPEN1 Non-string arguments for fpathopen
|
||||
E_FPATHOPEN2 Unrecognized mode for fpathopen
|
||||
E_LOG1 Bad epsilon argument for log
|
||||
E_LOG2 Non-numeric first argument for log
|
||||
E_LOG3 Cannot calculate log for this value
|
||||
E_FGETFILE1 Non-file argument for fgetfile
|
||||
E_FGETFILE2 File argument for fgetfile not open for reading
|
||||
E_FGETFILE3 Unable to set file position in fgetfile
|
||||
E_ESTR Non-representable type for estr
|
||||
E_STRCASECMP Non-string argument for strcasecmp
|
||||
E_STRNCASECMP Bad argument type for strncasecmp
|
||||
E_ISUPPER Bad argument for isupper
|
||||
E_ISLOWER Bad argument for islower
|
||||
E_ISALNUM Bad argument for isalnum
|
||||
E_ISALPHA Bad argument for isalpha
|
||||
E_ISASCII Bad argument for isascii
|
||||
E_ISCNTRL Bad argument for iscntrl
|
||||
E_ISDIGIT Bad argument for isdigit
|
||||
E_ISGRAPH Bad argument for isgraph
|
||||
E_ISPRINT Bad argument for isprint
|
||||
E_ISPUNCT Bad argument for ispunct
|
||||
E_ISSPACE Bad argument for isspace
|
||||
E_ISXDIGIT Bad argument for isxdigit
|
||||
E_STRTOUPPER Bad argument type for strtoupper
|
||||
E_STRTOLOWER Bad argument type for strtolower
|
||||
E_TAN3 Invalid value for calculating the sin numerator for tan
|
||||
E_TAN4 Invalid value for calculating the cos denominator for tan
|
||||
E_COT3 Invalid value for calculating the sin numerator for cot
|
||||
E_COT4 Invalid value for calculating the cos denominator for cot
|
||||
E_SEC3 Invalid value for calculating the cos reciprocal for sec
|
||||
E_CSC3 Invalid value for calculating the sin reciprocal for csc
|
||||
E_TANH3 Invalid value for calculating the sinh numerator for tanh
|
||||
E_TANH4 Invalid value for calculating the cosh denominator for tanh
|
||||
E_COTH3 Invalid value for calculating the sinh numerator for coth
|
||||
E_COTH4 Invalid value for calculating the cosh denominator for coth
|
||||
E_SECH3 Invalid value for calculating the cosh reciprocal for sech
|
||||
E_CSCH3 Invalid value for calculating the sinh reciprocal for csch
|
||||
E_ASIN3 Invalid value for calculating asin
|
||||
E_ACOS3 Invalid value for calculating acos
|
||||
E_ASINH3 Invalid value for calculating asinh
|
||||
E_ACOSH3 Invalid value for calculating acosn
|
||||
E_ATAN3 Invalid value for calculating atan
|
||||
E_ACOT3 Invalid value for calculating acot
|
||||
E_ASEC3 Invalid value for calculating asec
|
||||
E_ACSC3 Invalid value for calculating acsc
|
||||
E_ATANH3 Invalid value for calculating atan
|
||||
E_ACOTH3 Invalid value for calculating acot
|
||||
E_ASECH3 Invalid value for calculating asec
|
||||
E_ACSCH3 Invalid value for calculating acsc
|
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/sed
|
||||
#
|
||||
# calcerr_c - help produce calcerr.c from calcerr.tbl
|
||||
#
|
||||
# Copyright (C) 1999 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: 1996/05/24 03:15:35
|
||||
# File existed as early as: 1996
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
#
|
||||
BEGIN {
|
||||
printf("#include <stdio.h>\n");
|
||||
printf("#include \"calcerr.h\"\n\n");
|
||||
printf("#include \"have_const.h\"\n\n");
|
||||
printf("/*\n");
|
||||
printf(" * names of calc error values\n");
|
||||
printf(" */\n");
|
||||
printf("CONST char *error_table[E__COUNT+2] = {\n");
|
||||
printf(" \"No error\",\n");
|
||||
}
|
||||
{
|
||||
print $0;
|
||||
}
|
||||
END {
|
||||
printf(" NULL\n");
|
||||
printf("};\n");
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/sed
|
||||
#
|
||||
# calcerr_c - help produce calcerr.c from calcerr.tbl
|
||||
#
|
||||
# Copyright (C) 1999 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: 1996/05/24 03:15:35
|
||||
# File existed as early as: 1996
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
#
|
||||
s/#.*//
|
||||
s/[ ][ ]*$//
|
||||
/^$/d
|
||||
s/[^ ][^ ]*[ ][ ]*\(.*\)$/ "\1",/
|
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/awk
|
||||
#
|
||||
# calcerr_h - help produce calcerr.h from calcerr.tbl
|
||||
#
|
||||
# Copyright (C) 1999 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: 1996/05/23 17:38:44
|
||||
# File existed as early as: 1996
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
#
|
||||
BEGIN {
|
||||
ebase = 10000;
|
||||
printf("#define E__BASE %d\t/* calc errors start above here */\n\n", ebase);
|
||||
}
|
||||
NF > 1 {
|
||||
if (length($1) > 7) {
|
||||
printf("#define %s\t", $1, NR);
|
||||
} else {
|
||||
printf("#define %s\t\t", $1, NR);
|
||||
}
|
||||
printf("%d\t/* ", ebase+NR);
|
||||
for (i=2; i < NF; ++i) {
|
||||
printf("%s ", $i);
|
||||
}
|
||||
printf("%s */\n", $NF);
|
||||
}
|
||||
END {
|
||||
printf("\n#define E__HIGHEST\t%d\t/* highest calc error */\n", NR+ebase);
|
||||
printf("#define E__COUNT\t\t%d\t/* number of calc errors */\n", NR);
|
||||
printf("#define E_USERDEF\t20000\t/* base of user defined errors */\n\n");
|
||||
printf("/* names of calc error values */\n");
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/sed
|
||||
#
|
||||
# calcerr_h - help produce calcerr.h from calcerr.tbl
|
||||
#
|
||||
# Copyright (C) 1999 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: 1996/05/23 17:38:44
|
||||
# File existed as early as: 1996
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
#
|
||||
s/#.*//
|
||||
s/[ ][ ]*$//
|
||||
/^$/d
|
||||
s/\([^ ][^ ]*\)[ ][ ]*\(.*\)$/\1 \2/
|
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;
|
||||
}
|
351
chk_c.c
Normal file
351
chk_c.c
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* chk_c - chk C compiler and C include for calc requirements
|
||||
*
|
||||
* This program, to successfully compile, must include:
|
||||
*
|
||||
* #include <stdint.h>
|
||||
* #include <inttypes.h>
|
||||
*
|
||||
* and must be able to compile all of these types:
|
||||
*
|
||||
* int8_t uint8_t
|
||||
* int16_t uint16_t
|
||||
* int32_t uint32_t
|
||||
* int64_t uint64_t
|
||||
* intptr_t uintptr_t
|
||||
* intmax_t uintmax_t
|
||||
*
|
||||
* be able to sum values from all of those files,
|
||||
* plus the INTX_C(val) and UINTX_C(val) composing macros,
|
||||
* and be able to print for signed and unsigned values.
|
||||
*
|
||||
* If you are unable to compile this program, or if this program when
|
||||
* compiles does not exit 0, then your C compiler and/or C include
|
||||
* fails to meet calc requirements.
|
||||
*
|
||||
* Compilers that are at least c99 MUST be able to compile this program
|
||||
* such that when run will exit 0.
|
||||
*
|
||||
* Copyright (C) 2023 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: 2023/08/20 23:57:50
|
||||
* File existed as early as: 2023
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "have_stdint.h"
|
||||
#if defined(HAVE_STDINT_H)
|
||||
#include <stdint.h>
|
||||
#endif /* HAVE_STDINT_H */
|
||||
|
||||
#include "have_inttypes.h"
|
||||
#if defined(HAVE_INTTYPES_H)
|
||||
#include <inttypes.h>
|
||||
#endif /* HAVE_INTTYPES_H */
|
||||
|
||||
#include "have_stdlib.h"
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include "bool.h"
|
||||
|
||||
|
||||
/*
|
||||
* our version
|
||||
*/
|
||||
#define CHK_C_VERSION "1.0 2023-08-20"
|
||||
|
||||
|
||||
/*
|
||||
* usage:
|
||||
*/
|
||||
static char const *usage =
|
||||
"usage: %s [-h] [-c] [-V]\n"
|
||||
"\n"
|
||||
"\t-h\t\toutput this message and exit\n"
|
||||
"\t-c\t\toutput C compiler and C include info (def: no stdout output)\n"
|
||||
"\t-V\t\tprint version string and exit\n"
|
||||
"\n"
|
||||
"Exit codes:\n"
|
||||
" 0 all OK\n"
|
||||
" 1 C compiler and C include is insufficient for calc\n"
|
||||
" 2 -h and help string printed or -V and version string printed\n"
|
||||
" 3 invalid command line, invalid option or option missing an argument\n"
|
||||
" >= 10 internal error\n"
|
||||
"\n"
|
||||
"chk_c version: %s\n";
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *program = "((NULL))"; /* our name */
|
||||
int opt; /* the -option found or -1 */
|
||||
bool c_flag = false; /* if -h was found */
|
||||
#if defined(HAVE_STDINT_H) && defined(HAVE_INTTYPES_H)
|
||||
int i = -1; /* signed int test value */
|
||||
unsigned int ui = 1; /* unsigned int test value */
|
||||
long l = -2L; /* signed long test value */
|
||||
unsigned long ul = 2UL; /* unsigned long test value */
|
||||
long long ll = -4LL; /* signed long long test value */
|
||||
unsigned long long ull = 4ULL; /* unsigned long long test value */
|
||||
int8_t i8 = INT8_C(-8); /* signed 8-bit test value */
|
||||
uint8_t ui8 = UINT8_C(8); /* unsigned 8-bit test value */
|
||||
int16_t i16 = INT16_C(-16); /* signed 16-bit test value */
|
||||
uint16_t ui16 = UINT16_C(16); /* unsigned 16-bit test value */
|
||||
int32_t i32 = INT32_C(-32); /* signed 32-bit test value */
|
||||
uint32_t ui32 = UINT32_C(32); /* unsigned 32-bit test value */
|
||||
int64_t i64 = INT64_C(-64); /* signed 64-bit test value */
|
||||
uint64_t ui64 = UINT64_C(64); /* unsigned 64-bit test value */
|
||||
intptr_t iptr = -128; /* integer type capable of holding a pointer */
|
||||
intptr_t uiptr = 128; /* unsigned integer type capable of holding a pointer */
|
||||
intmax_t imax = INTMAX_C(-256); /* maximum sized signed int test value */
|
||||
uintmax_t uimax = UINTMAX_C(256); /* maximum sized unsigned int test value */
|
||||
uintmax_t isum = 0; /* sum of all test values as signed value */
|
||||
uintmax_t uisum = 0; /* sum of all test values as unsigned value */
|
||||
#endif /* HAVE_STDINT_H && HAVE_INTTYPES_H */
|
||||
|
||||
/*
|
||||
* parse args
|
||||
*/
|
||||
program = argv[0];
|
||||
while ((opt = getopt(argc, argv, "hcV")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||
exit(2);
|
||||
break;
|
||||
case 'c':
|
||||
c_flag = true;
|
||||
break;
|
||||
case 'V':
|
||||
printf("%s\n", CHK_C_VERSION);
|
||||
exit(2);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
if (optind != argc) {
|
||||
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
/*
|
||||
* must have <stdint.h>
|
||||
*/
|
||||
#if !defined(HAVE_STDINT_H)
|
||||
if (c_flag == true) {
|
||||
printf("HAVE_STDINT_H is undefined\n");
|
||||
}
|
||||
fprintf(stderr, "calc requires <stdint.h> include file\n");
|
||||
exit(1);
|
||||
#else /* HAVE_STDINT_H */
|
||||
if (c_flag == true) {
|
||||
printf("HAVE_STDINT_H is defined\n");
|
||||
printf("<stdint.h> successfully included\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* must have <inttypes.h>
|
||||
*/
|
||||
#if !defined(HAVE_INTTYPES_H)
|
||||
if (c_flag == true) {
|
||||
printf("HAVE_INTTYPES_H is undefined\n");
|
||||
}
|
||||
fprintf(stderr, "calc requires <inttypes.h> include file\n");
|
||||
exit(1);
|
||||
#else /* HAVE_INTTYPES_H */
|
||||
if (c_flag == true) {
|
||||
printf("\nHAVE_INTTYPES_H is defined\n");
|
||||
printf("<inttypes.h> successfully included\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* check for __STDC__ defined
|
||||
*/
|
||||
#if !defined(__STDC__)
|
||||
fprintf(stderr, "__STDC__ is not defined\n");
|
||||
exit(1);
|
||||
#endif /* __STDC__ */
|
||||
if (c_flag == true) {
|
||||
printf("\n__STDC__ is defined\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* check for __STDC_VERSION__ defined
|
||||
*/
|
||||
#if !defined(__STDC_VERSION__)
|
||||
fprintf(stderr, "__STDC_VERSION__ is not defined\n");
|
||||
exit(1);
|
||||
#endif /* __STDC_VERSION__ */
|
||||
if (c_flag == true) {
|
||||
printf("__STDC_VERSION__: %ld is defined\n", __STDC_VERSION__);
|
||||
}
|
||||
|
||||
/*
|
||||
* check for __STDC_VERSION__ >= 199901L for c99 or later
|
||||
*/
|
||||
#if __STDC_VERSION__ < 199901L
|
||||
fprintf(stderr, "__STDC_VERSION__: %ld < 199901L\n", __STDC_VERSION__);
|
||||
exit(1);
|
||||
#endif /* __STDC_VERSION__ >= 199901L */
|
||||
if (c_flag == true) {
|
||||
printf("__STDC_VERSION__: %ld >= 199901L\n", __STDC_VERSION__);
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate sum of all test values as signed value
|
||||
*/
|
||||
isum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + iptr + uiptr + imax + uimax;
|
||||
if (c_flag == true) {
|
||||
printf("\nzero valued isum: %jd\n", isum);
|
||||
}
|
||||
if (isum != 0) {
|
||||
fprintf(stderr, "failed to add all required integer types into a signed value\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate sum of all test values as unsigned value
|
||||
*/
|
||||
uisum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + iptr + uiptr + imax + uimax;
|
||||
if (c_flag == true) {
|
||||
printf("zero valued uisum: %ju\n", uisum);
|
||||
}
|
||||
if (uisum != 0) {
|
||||
fprintf(stderr, "failed to add all required integer types into an unsigned value\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* verify various 32, 64 and max PRI macros as well as MIN and MAX constants
|
||||
*/
|
||||
if (c_flag == true) {
|
||||
printf("\nsigned integer MIN and MAX\n");
|
||||
printf("INT8_MIN: %+"PRId8"\n", (int8_t)INT8_MIN);
|
||||
printf("INT8_MAX: %+"PRId8"\n", (int8_t)INT8_MAX);
|
||||
printf("INT16_MIN: %+"PRId16"\n", (int16_t)INT16_MIN);
|
||||
printf("INT16_MAX: %+"PRId16"\n", (int16_t)INT16_MAX);
|
||||
printf("INT32_MIN: %+"PRId32"\n", (int32_t)INT32_MIN);
|
||||
printf("INT32_MAX: %+"PRId32"\n", (int32_t)INT32_MAX);
|
||||
printf("INT64_MIN: %+"PRId64"\n", (int64_t)INT64_MIN);
|
||||
printf("INT64_MAX: %+"PRId64"\n", (int64_t)INT64_MAX);
|
||||
printf("INTPTR_MIN: %+"PRIdMAX"\n", (intptr_t)INTPTR_MIN);
|
||||
printf("INTPTR_MAX: %+"PRIdMAX"\n", (intptr_t)INTPTR_MAX);
|
||||
printf("INTMAX_MIN: %+"PRIdMAX"\n", (intmax_t)INTMAX_MIN);
|
||||
printf("INTMAX_MAX: %+"PRIdMAX"\n", (intmax_t)INTMAX_MAX);
|
||||
|
||||
printf("\nunsigned integer MAX\n");
|
||||
printf("UINT8_MAX: %"PRIu8"\n", (uint8_t)UINT8_MAX);
|
||||
printf("UINT16_MAX: %"PRIu16"\n", (uint16_t)UINT16_MAX);
|
||||
printf("UINT32_MAX: %"PRIu32"\n", (uint32_t)UINT32_MAX);
|
||||
printf("UINT64_MAX: %"PRIu64"\n", (uint64_t)UINT64_MAX);
|
||||
printf("UINTPTR_MAX: %"PRIuMAX"\n", (uintptr_t)UINTPTR_MAX);
|
||||
printf("UINTMAX_MAX: %"PRIuMAX"\n", (uintmax_t)UINTMAX_MAX);
|
||||
|
||||
printf("\ninteger MIN and MAX\n");
|
||||
printf("INT8_MIN: %"PRIi8"\n", (int8_t)INT8_MIN);
|
||||
printf("INT8_MAX: %"PRIi8"\n", (int8_t)INT8_MAX);
|
||||
printf("INT16_MIN: %"PRIi16"\n", (int16_t)INT16_MIN);
|
||||
printf("INT16_MAX: %"PRIi16"\n", (int16_t)INT16_MAX);
|
||||
printf("INT32_MIN: %"PRIi32"\n", (int32_t)INT32_MIN);
|
||||
printf("INT32_MAX: %"PRIi32"\n", (int32_t)INT32_MAX);
|
||||
printf("INT64_MIN: %"PRIi64"\n", (int64_t)INT64_MIN);
|
||||
printf("INT64_MAX: %"PRIi64"\n", (int64_t)INT64_MAX);
|
||||
printf("INTPTR_MIN: %"PRIiMAX"\n", (intptr_t)INTPTR_MIN);
|
||||
printf("INTPTR_MAX: %"PRIiMAX"\n", (intptr_t)INTPTR_MAX);
|
||||
printf("INTMAX_MIN: %"PRIiMAX"\n", (intmax_t)INTMAX_MIN);
|
||||
printf("INTMAX_MAX: %"PRIiMAX"\n", (intmax_t)INTMAX_MAX);
|
||||
|
||||
printf("\noctal MIN and MAX\n");
|
||||
printf("INT8_MIN: %"PRIo8"\n", (int8_t)INT8_MIN);
|
||||
printf("INT8_MAX: %"PRIo8"\n", (int8_t)INT8_MAX);
|
||||
printf("INT16_MIN: %"PRIo16"\n", (int16_t)INT16_MIN);
|
||||
printf("INT16_MAX: %"PRIo16"\n", (int16_t)INT16_MAX);
|
||||
printf("INT32_MIN: %"PRIo32"\n", (int32_t)INT32_MIN);
|
||||
printf("INT32_MAX: %"PRIo32"\n", (int32_t)INT32_MAX);
|
||||
printf("INT64_MIN: %"PRIo64"\n", (int64_t)INT64_MIN);
|
||||
printf("INT64_MAX: %"PRIo64"\n", (int64_t)INT64_MAX);
|
||||
printf("INTPTR_MIN: %"PRIoMAX"\n", (intptr_t)INTPTR_MIN);
|
||||
printf("INTPTR_MAX: %"PRIoMAX"\n", (intptr_t)INTPTR_MAX);
|
||||
printf("INTMAX_MIN: %"PRIoMAX"\n", (intmax_t)INTMAX_MIN);
|
||||
printf("INTMAX_MAX: %"PRIoMAX"\n", (intmax_t)INTMAX_MAX);
|
||||
|
||||
printf("\nhex MIN and MAX\n");
|
||||
printf("INT8_MIN: %"PRIx8"\n", (int8_t)INT8_MIN);
|
||||
printf("INT8_MAX: %"PRIx8"\n", (int8_t)INT8_MAX);
|
||||
printf("INT16_MIN: %"PRIx16"\n", (int16_t)INT16_MIN);
|
||||
printf("INT16_MAX: %"PRIx16"\n", (int16_t)INT16_MAX);
|
||||
printf("INT32_MIN: %"PRIx32"\n", (int32_t)INT32_MIN);
|
||||
printf("INT32_MAX: %"PRIx32"\n", (int32_t)INT32_MAX);
|
||||
printf("INT64_MIN: %"PRIx64"\n", (int64_t)INT64_MIN);
|
||||
printf("INT64_MAX: %"PRIx64"\n", (int64_t)INT64_MAX);
|
||||
printf("INTPTR_MIN: %"PRIxMAX"\n", (intptr_t)INTPTR_MIN);
|
||||
printf("INTPTR_MAX: %"PRIxMAX"\n", (intptr_t)INTPTR_MAX);
|
||||
printf("INTMAX_MIN: %"PRIxMAX"\n", (intmax_t)INTMAX_MIN);
|
||||
printf("INTMAX_MAX: %"PRIxMAX"\n", (intmax_t)INTMAX_MAX);
|
||||
|
||||
printf("\nHEX MIN and MAX\n");
|
||||
printf("INT8_MIN: %"PRIX8"\n", (int8_t)INT8_MIN);
|
||||
printf("INT8_MAX: %"PRIX8"\n", (int8_t)INT8_MAX);
|
||||
printf("INT16_MIN: %"PRIX16"\n", (int16_t)INT16_MIN);
|
||||
printf("INT16_MAX: %"PRIX16"\n", (int16_t)INT16_MAX);
|
||||
printf("INT32_MIN: %"PRIX32"\n", (int32_t)INT32_MIN);
|
||||
printf("INT32_MAX: %"PRIX32"\n", (int32_t)INT32_MAX);
|
||||
printf("INT64_MIN: %"PRIX64"\n", (int64_t)INT64_MIN);
|
||||
printf("INT64_MAX: %"PRIX64"\n", (int64_t)INT64_MAX);
|
||||
printf("INTPTR_MIN: %"PRIXMAX"\n", (intptr_t)INTPTR_MIN);
|
||||
printf("INTPTR_MAX: %"PRIXMAX"\n", (intptr_t)INTPTR_MAX);
|
||||
printf("INTMAX_MIN: %"PRIXMAX"\n", (intmax_t)INTMAX_MIN);
|
||||
printf("INTMAX_MAX: %"PRIXMAX"\n", (intmax_t)INTMAX_MAX);
|
||||
|
||||
printf("\nsizes\n");
|
||||
printf("sizeof(int8_t): %lu\n", sizeof(int8_t));
|
||||
printf("sizeof(uint8_t): %lu\n", sizeof(uint8_t));
|
||||
printf("sizeof(int16_t): %lu\n", sizeof(int16_t));
|
||||
printf("sizeof(uint16_t): %lu\n", sizeof(uint16_t));
|
||||
printf("sizeof(int32_t): %lu\n", sizeof(int32_t));
|
||||
printf("sizeof(uint32_t): %lu\n", sizeof(uint32_t));
|
||||
printf("sizeof(int64_t): %lu\n", sizeof(int64_t));
|
||||
printf("sizeof(uint64_t): %lu\n", sizeof(uint64_t));
|
||||
printf("sizeof(intptr_t): %lu\n", sizeof(intptr_t));
|
||||
printf("sizeof(uintptr_t): %lu\n", sizeof(uintptr_t));
|
||||
printf("sizeof(intmax_t): %lu\n", sizeof(intmax_t));
|
||||
printf("sizeof(uintmax_t): %lu\n", sizeof(uintmax_t));
|
||||
}
|
||||
|
||||
/*
|
||||
* All Done!! -- Jessica Noll, age 2
|
||||
*/
|
||||
if (c_flag == true) {
|
||||
printf("\nC compiler and select include files appear to support calc.\n");
|
||||
}
|
||||
exit(0);
|
||||
#endif /* HAVE_INTTYPES_H */
|
||||
#endif /* HAVE_STDINT_H */
|
||||
}
|
243
chk_tree
Executable file
243
chk_tree
Executable file
@@ -0,0 +1,243 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# chk_tree - verify that the source tree and git and Makefiles are in sync
|
||||
#
|
||||
# This tools is used by "make prep".
|
||||
#
|
||||
# Copyright (C) 2023 Landon Curt Noll
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of 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.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Under source code control: 2023/10/04 21:04:44
|
||||
# File existed as early as: 2023
|
||||
#
|
||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
|
||||
# setup
|
||||
#
|
||||
EXIT_CODE=0
|
||||
|
||||
# firewall - verify that the "make distdir" directories exist
|
||||
#
|
||||
make distdir >/dev/null 2>&1
|
||||
status="$?"
|
||||
if [[ $status -ne 0 ]]; then
|
||||
echo "$0: ERROR: make distdir exit code: $status" 1>&2
|
||||
EXIT_CODE=10
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
|
||||
# collect make distdir directory list
|
||||
#
|
||||
# We ignore make action lines.
|
||||
#
|
||||
declare -a DISTDIR
|
||||
mapfile -t DISTDIR < <(make -s distdir | grep -v '^make\[[0-9]*\]: ' | sort -u)
|
||||
|
||||
# collect directories
|
||||
#
|
||||
# We ignore NOTES because it contains notes that are not part of calc source.
|
||||
# We ignore .git and GitHub because they are not part of the calc source tarball.
|
||||
#
|
||||
declare -a FINDDIR
|
||||
mapfile -t FINDDIR < <(find . -type d \
|
||||
! -path './NOTES/*' ! -name NOTES \
|
||||
! -path './.git/*' ! -name .git \
|
||||
! -path './.github/*' ! -name .github | \
|
||||
sed -e 's/^\.\///' | sort -u)
|
||||
|
||||
# compare DISTDIR and FINDDIR
|
||||
#
|
||||
declare -a DIFF_DISTDIR_FINDDIR
|
||||
mapfile -t DIFF_DISTDIR_FINDDIR < <(printf '%s\n' "${DISTDIR[@]}" "${FINDDIR[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#DIFF_DISTDIR_FINDDIR[@]} -ne 0 ]]; then
|
||||
|
||||
# report that DISTDIR and FINDDIR differ
|
||||
#
|
||||
echo "$0: ERROR: distdir and find dir differ for critical directories" 1>&2
|
||||
declare -a ONLY_FINDDIR
|
||||
mapfile -t ONLY_FINDDIR < <(printf '%s\n' "${DISTDIR[@]}" "${DISTDIR[@]}" "${FINDDIR[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#ONLY_FINDDIR[@]} -ne 0 ]]; then
|
||||
echo "$0: ERROR: found only in find dir: ${ONLY_FINDDIR[*]}" 1>&2
|
||||
fi
|
||||
declare -a ONLY_DISTDIR
|
||||
mapfile -t ONLY_DISTDIR < <(printf '%s\n' "${FINDDIR[@]}" "${FINDDIR[@]}" "${DISTDIR[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#ONLY_DISTDIR[@]} -ne 0 ]]; then
|
||||
echo "$0: ERROR: found only in distdir: ${ONLY_DISTDIR[*]}" 1>&2
|
||||
fi
|
||||
EXIT_CODE=11
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
|
||||
# firewall - verify that the "make distlist" files exist
|
||||
#
|
||||
make distlist >/dev/null 2>&1
|
||||
status="$?"
|
||||
if [[ $status -ne 0 ]]; then
|
||||
echo "$0: ERROR: make distlist exit code: $status" 1>&2
|
||||
EXIT_CODE=12
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
|
||||
# collect make distlist file list
|
||||
#
|
||||
declare -a DISTLIST
|
||||
mapfile -t DISTLIST < <(make -s distlist | grep -v '^make\[[0-9]*\]: ' | sort -u)
|
||||
declare -A DISTLIST_A
|
||||
for i in "${DISTLIST[@]}"; do
|
||||
DISTLIST_A["$i"]="$i"
|
||||
done
|
||||
|
||||
# case: under git control
|
||||
#
|
||||
if [[ -d .git ]]; then
|
||||
|
||||
# obtain the list of files under git
|
||||
#
|
||||
# We ignore .git and GitHub related files because they are not part of the calc source tarball.
|
||||
#
|
||||
declare -a GITLS
|
||||
mapfile -t GITLS < <(git ls |
|
||||
grep -v -E '^\.github/|^\.gitignore$|^CODE_OF_CONDUCT\.md$|^CONTRIBUTING\.md$|^SECURITY\.md$' |
|
||||
sort -u)
|
||||
|
||||
# compare DISTLIST and GITLS
|
||||
#
|
||||
declare -a DIFF_DISTLIST_GITLS
|
||||
mapfile -t DIFF_DISTLIST_GITLS < <(printf '%s\n' "${DISTLIST[@]}" "${GITLS[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#DIFF_DISTLIST_GITLS[@]} -ne 0 ]]; then
|
||||
|
||||
# report that DISTLIST and GITLS differ
|
||||
#
|
||||
echo "$0: ERROR: distlist and git ls differ for critical files" 1>&2
|
||||
declare -a ONLY_GITLS
|
||||
mapfile -t ONLY_GITLS < <(printf '%s\n' "${DISTLIST[@]}" "${DISTLIST[@]}" "${GITLS[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#ONLY_GITLS[@]} -ne 0 ]]; then
|
||||
echo "$0: ERROR: found only in git ls: ${ONLY_GITLS[*]}" 1>&2
|
||||
fi
|
||||
declare -a ONLY_DISTLIST
|
||||
mapfile -t ONLY_DISTLIST < <(printf '%s\n' "${GITLS[@]}" "${GITLS[@]}" "${DISTLIST[@]}" |
|
||||
tr ' ' '\n' | sort | uniq -u)
|
||||
if [[ ${#ONLY_DISTLIST[@]} -ne 0 ]]; then
|
||||
echo "$0: ERROR: found only in distlist: ${ONLY_DISTLIST[*]}" 1>&2
|
||||
fi
|
||||
EXIT_CODE=13
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
fi
|
||||
|
||||
# collect make buildlist file list
|
||||
#
|
||||
declare -a BUILDLIST
|
||||
mapfile -t BUILDLIST < <(make -s buildlist | grep -v '^make\[[0-9]*\]: ' | sort -u)
|
||||
declare -A BUILDLIST_A
|
||||
for i in "${BUILDLIST[@]}"; do
|
||||
BUILDLIST_A["$i"]="$i"
|
||||
done
|
||||
|
||||
# look for something in DISTLIST that is also in BUILDLIST
|
||||
#
|
||||
# The BUILDLIST are a set of files that are result of building calc
|
||||
# and thus should NOT be part of the DISTLIST (list of files used
|
||||
# to form the calc source distribtion).
|
||||
#
|
||||
declare -a DISTLIST_ALSO_IN_BUILDLIST
|
||||
mapfile -t DISTLIST_ALSO_IN_BUILDLIST < <(
|
||||
for i in "${DISTLIST_A[@]}"; do
|
||||
if [[ -n "${BUILDLIST_A[$i]}" ]]; then
|
||||
echo "$i";
|
||||
fi
|
||||
done
|
||||
)
|
||||
if [[ ${#DISTLIST_ALSO_IN_BUILDLIST[@]} -ne 0 ]]; then
|
||||
|
||||
# report that something in DISTLIST was found in BUILDLIST
|
||||
#
|
||||
echo "$0: ERROR: distlist files found in buildlist" 1>&2
|
||||
echo "$0: ERROR: distlist files found in buildlist: ${DISTLIST_ALSO_IN_BUILDLIST[*]}" 1>&2
|
||||
EXIT_CODE=14
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
|
||||
# collect list of files
|
||||
#
|
||||
# We ignore NOTES because it contains notes that are not part of calc source.
|
||||
# We ignore .git and GitHub because they are not part of the calc source tarball.
|
||||
# We ignore .*.swp files as they are a result of vim sessions.
|
||||
# We ignore *.out files as they are used to collect information.
|
||||
# We ignore single letter files as they are used for temporary files.
|
||||
#
|
||||
declare -a FINDFILE
|
||||
mapfile -t FINDFILE < <(find . -type f \
|
||||
! -path './NOTES/*' ! -name NOTES \
|
||||
! -path './.git/*' ! -name .git \
|
||||
! -path './.github/*' ! -name .github \
|
||||
! -name 'CODE_OF_CONDUCT.md' ! -name 'CONTRIBUTING.md' ! -name '.gitignore' ! -name 'SECURITY.md' \
|
||||
! -name '*.swp' ! -name '*.out' ! -name '?' |
|
||||
sed -e 's/^\.\///' | sort -u)
|
||||
|
||||
# look for something in FINDFILE that in neither DISTLIST nor BUILDLIST
|
||||
#
|
||||
# We look for a file that is neither a file that neither a result of building calc,
|
||||
# nor part of the calc distribution list in a file list.
|
||||
#
|
||||
# NOTE that the file list has already excluded certain files (see previous section).
|
||||
#
|
||||
# We flag any file in the list that is neither a result of building calc,
|
||||
# nor part of the calc distribution list in a file list.
|
||||
#
|
||||
declare -a UNKNOWN_FILE
|
||||
mapfile -t UNKNOWN_FILE < <(
|
||||
for i in "${FINDFILE[@]}"; do
|
||||
|
||||
# skip if this is a file that is result of building calc
|
||||
#
|
||||
if [[ -n ${BUILDLIST_A["$i"]} ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# skip if this is a file that is calc distribution list
|
||||
#
|
||||
if [[ -n ${DISTLIST_A["$i"]} ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# print the file of unknown status
|
||||
#
|
||||
echo "$i"
|
||||
done
|
||||
)
|
||||
if [[ ${#UNKNOWN_FILE[@]} -ne 0 ]]; then
|
||||
|
||||
# report that something in DISTLIST was found in BUILDLIST
|
||||
#
|
||||
echo "$0: ERROR: files that are neither built nor distlist are found" 1>&2
|
||||
echo "$0: ERROR: distlist files found in buildlist: ${UNKNOWN_FILE[*]}" 1>&2
|
||||
EXIT_CODE=15
|
||||
echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2
|
||||
fi
|
||||
|
||||
# All Done!!! -- Jessica Noll, Age 2
|
||||
#
|
||||
if [[ $EXIT_CODE -ne 0 ]]; then
|
||||
echo "$0: Warning: about to exit $EXIT_CODE" 1>&2
|
||||
fi
|
||||
exit "$EXIT_CODE"
|
46
cmath.h
46
cmath.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cmath - data structures for extended precision complex arithmetic
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014 David I. Bell
|
||||
* Copyright (C) 1999-2007,2014,2023 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
|
||||
@@ -48,6 +48,7 @@ typedef struct {
|
||||
/*
|
||||
* Input, output, and conversion routines.
|
||||
*/
|
||||
E_FUNC COMPLEX *cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree);
|
||||
E_FUNC COMPLEX *comalloc(void);
|
||||
E_FUNC COMPLEX *qqtoc(NUMBER *q1, NUMBER *q2);
|
||||
E_FUNC void comfree(COMPLEX *c);
|
||||
@@ -72,12 +73,14 @@ E_FUNC COMPLEX *c_shift(COMPLEX *c, long i);
|
||||
E_FUNC COMPLEX *c_square(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_conj(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_real(COMPLEX *c);
|
||||
E_FUNC NUMBER *c_to_q(COMPLEX *c, bool cfree);
|
||||
E_FUNC COMPLEX *q_to_c(NUMBER *q);
|
||||
E_FUNC COMPLEX *c_imag(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_neg(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_inv(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_int(COMPLEX *c);
|
||||
E_FUNC COMPLEX *c_frac(COMPLEX *c);
|
||||
E_FUNC BOOL c_cmp(COMPLEX *c1, COMPLEX *c2);
|
||||
E_FUNC bool c_cmp(COMPLEX *c1, COMPLEX *c2);
|
||||
|
||||
|
||||
/*
|
||||
@@ -97,6 +100,7 @@ E_FUNC COMPLEX *c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_exp(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_ln(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_log(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_log2(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_cos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_sin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_cosh(COMPLEX *c, NUMBER *epsilon);
|
||||
@@ -105,9 +109,13 @@ E_FUNC COMPLEX *c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_rel(COMPLEX *c1, COMPLEX *c2);
|
||||
E_FUNC COMPLEX *c_asin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_tan(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_atan(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_cot(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acot(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_sec(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_asec(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_csc(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acsc(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_asinh(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acosh(COMPLEX *c, NUMBER *epsilon);
|
||||
@@ -118,14 +126,42 @@ E_FUNC COMPLEX *c_acsch(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_gd(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_agd(COMPLEX *c, NUMBER *epsilon);
|
||||
|
||||
/*
|
||||
* historical trig functions
|
||||
*/
|
||||
E_FUNC COMPLEX *c_versin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_aversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_coversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acoversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_vercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_avercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_covercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acovercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_haversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_ahaversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_hacoversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_ahacoversin(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_havercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_ahavercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_hacovercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_ahacovercos(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_exsec(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_aexsec(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_excsc(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_aexcsc(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_crd(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_acrd(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_cas(COMPLEX *c, NUMBER *epsilon);
|
||||
E_FUNC COMPLEX *c_cis(COMPLEX *c, NUMBER *epsilon);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* external functions
|
||||
*/
|
||||
E_FUNC COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
|
||||
E_FUNC COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
|
||||
E_FUNC COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
|
||||
E_FUNC COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all);
|
||||
E_FUNC COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all);
|
||||
E_FUNC COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all);
|
||||
|
||||
|
||||
/*
|
||||
|
132
codegen.c
132
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-2023 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,18 +42,26 @@
|
||||
#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
|
||||
|
||||
STATIC BOOL rdonce; /* TRUE => do not reread this file */
|
||||
|
||||
#include "errtbl.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
STATIC bool rdonce; /* true => do not reread this file */
|
||||
|
||||
FUNC *curfunc;
|
||||
|
||||
S_FUNC int getsymvalue(char *name, VALUE *v_p);
|
||||
S_FUNC int getfilename(char *name, size_t namelen, BOOL *once);
|
||||
S_FUNC BOOL getid(char *buf);
|
||||
S_FUNC int getfilename(char *name, size_t namelen, bool *once);
|
||||
S_FUNC bool getid(char *buf);
|
||||
S_FUNC void getshowstatement(void);
|
||||
S_FUNC void getfunction(void);
|
||||
S_FUNC void ungetfunction(void);
|
||||
@@ -92,7 +101,7 @@ S_FUNC int getshiftexpr(void);
|
||||
S_FUNC int getreference(void);
|
||||
S_FUNC int getincdecexpr(void);
|
||||
S_FUNC int getterm(void);
|
||||
S_FUNC int getidexpr(BOOL okmat, int autodef);
|
||||
S_FUNC int getidexpr(bool okmat, int autodef);
|
||||
S_FUNC long getinitlist(void);
|
||||
|
||||
#define INDICALLOC 8
|
||||
@@ -112,14 +121,14 @@ STATIC int maxindices;
|
||||
* The toplevel flag indicates whether we are at the top interactive level.
|
||||
*/
|
||||
void
|
||||
getcommands(BOOL toplevel)
|
||||
getcommands(bool toplevel)
|
||||
{
|
||||
char name[MAXCMD+1+1]; /* program name */
|
||||
|
||||
/* firewall */
|
||||
name[0] = '\0';
|
||||
name[MAXCMD+1] = '\0';
|
||||
abort_now = FALSE;
|
||||
abort_now = false;
|
||||
|
||||
/* getcommands */
|
||||
if (!toplevel)
|
||||
@@ -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;
|
||||
@@ -177,7 +184,7 @@ getcommands(BOOL toplevel)
|
||||
CALCEXT,rdonce);
|
||||
switch (open_ret) {
|
||||
case 0:
|
||||
getcommands(FALSE);
|
||||
getcommands(false);
|
||||
closeinput();
|
||||
continue;
|
||||
case 1:
|
||||
@@ -220,7 +227,7 @@ getcommands(BOOL toplevel)
|
||||
default:
|
||||
rescantoken();
|
||||
initstack();
|
||||
if (evaluate(FALSE))
|
||||
if (evaluate(false))
|
||||
updateoldvalue(curfunc);
|
||||
freefunc(curfunc);
|
||||
if (abort_now) {
|
||||
@@ -245,18 +252,18 @@ getcommands(BOOL toplevel)
|
||||
/*
|
||||
* Evaluate a line of statements.
|
||||
* This is done by treating the current line as a function body,
|
||||
* compiling it, and then executing it. Returns TRUE if the line
|
||||
* compiling it, and then executing it. Returns true if the line
|
||||
* successfully compiled and executed. The last expression result
|
||||
* is saved in the f_savedvalue element of the current function.
|
||||
* The nestflag variable should be FALSE for the outermost evaluation
|
||||
* level, and TRUE for all other calls (such as the 'eval' function).
|
||||
* The nestflag variable should be false for the outermost evaluation
|
||||
* level, and true for all other calls (such as the 'eval' function).
|
||||
* The function name begins with an asterisk to indicate specialness.
|
||||
*
|
||||
* given:
|
||||
* nestflag TRUE if this is a nested evaluation
|
||||
* nestflag true if this is a nested evaluation
|
||||
*/
|
||||
BOOL
|
||||
evaluate(BOOL nestflag)
|
||||
bool
|
||||
evaluate(bool nestflag)
|
||||
{
|
||||
char *funcname;
|
||||
int loop = 1; /* 0 => end the main while loop */
|
||||
@@ -289,9 +296,9 @@ evaluate(BOOL nestflag)
|
||||
addop(OP_RETURN);
|
||||
checklabels();
|
||||
if (errorcount)
|
||||
return FALSE;
|
||||
return false;
|
||||
calculate(curfunc, 0);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -327,7 +334,7 @@ ungetfunction(void)
|
||||
return;
|
||||
}
|
||||
name = tokensymbol();
|
||||
endscope(name, FALSE);
|
||||
endscope(name, false);
|
||||
continue;
|
||||
|
||||
case T_NEWLINE:
|
||||
@@ -367,7 +374,7 @@ getfunction(void)
|
||||
scanerror(T_SEMICOLON, "Using builtin function name");
|
||||
return;
|
||||
}
|
||||
beginfunc(name, FALSE);
|
||||
beginfunc(name, false);
|
||||
enterfuncscope();
|
||||
if (gettoken() != T_LEFTPAREN) {
|
||||
scanerror(T_SEMICOLON,
|
||||
@@ -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'
|
||||
*/
|
||||
@@ -459,7 +466,7 @@ getbody(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel,
|
||||
int oldmode;
|
||||
|
||||
oldmode = tokenmode(TM_DEFAULT);
|
||||
while (TRUE) {
|
||||
while (true) {
|
||||
switch (gettoken()) {
|
||||
case T_RIGHTBRACE:
|
||||
(void) tokenmode(oldmode);
|
||||
@@ -488,7 +495,7 @@ getdeclarations(int symtype)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
while (TRUE) {
|
||||
while (true) {
|
||||
switch (gettoken()) {
|
||||
case T_COMMA:
|
||||
continue;
|
||||
@@ -624,7 +631,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel,
|
||||
LABEL label;
|
||||
LABEL label1, label2, label3, label4; /* locations for jumps */
|
||||
int type;
|
||||
BOOL printeol;
|
||||
bool printeol;
|
||||
int oldmode;
|
||||
|
||||
addopone(OP_DEBUG, linenumber());
|
||||
@@ -953,7 +960,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel,
|
||||
break;
|
||||
|
||||
case T_PRINT:
|
||||
printeol = TRUE;
|
||||
printeol = true;
|
||||
for (;;) {
|
||||
switch (gettoken()) {
|
||||
case T_RIGHTPAREN:
|
||||
@@ -972,14 +979,14 @@ getstatement(LABEL *contlabel, LABEL *breaklabel,
|
||||
addop(OP_PRINTSPACE);
|
||||
/*FALLTHRU*/
|
||||
case T_COLON:
|
||||
printeol = FALSE;
|
||||
printeol = false;
|
||||
break;
|
||||
case T_STRING:
|
||||
printeol = TRUE;
|
||||
printeol = true;
|
||||
addopone(OP_PRINTSTRING, tokenstring());
|
||||
break;
|
||||
default:
|
||||
printeol = TRUE;
|
||||
printeol = true;
|
||||
rescantoken();
|
||||
(void) getopassignment();
|
||||
addopone(OP_PRINT, (long) PRINT_NORMAL);
|
||||
@@ -1188,7 +1195,7 @@ getoneobj(long index, int symtype)
|
||||
if (gettoken() == T_SYMBOL) {
|
||||
if (symtype == SYM_UNDEFINED) {
|
||||
rescantoken();
|
||||
(void) getidexpr(TRUE, 1);
|
||||
(void) getidexpr(true, 1);
|
||||
} else {
|
||||
symname = tokensymbol();
|
||||
definesymbol(symname, symtype);
|
||||
@@ -1271,7 +1278,7 @@ getonematrix(int symtype)
|
||||
if (gettoken() == T_SYMBOL) {
|
||||
if (symtype == SYM_UNDEFINED) {
|
||||
rescantoken();
|
||||
(void) getidexpr(FALSE, 1);
|
||||
(void) getidexpr(false, 1);
|
||||
} else {
|
||||
name = tokensymbol();
|
||||
definesymbol(name, symtype);
|
||||
@@ -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
|
||||
@@ -2134,7 +2141,7 @@ getterm(void)
|
||||
|
||||
case T_SYMBOL:
|
||||
rescantoken();
|
||||
type = getidexpr(TRUE, 0);
|
||||
type = getidexpr(true, 0);
|
||||
break;
|
||||
|
||||
case T_MULT:
|
||||
@@ -2157,7 +2164,7 @@ getterm(void)
|
||||
break;
|
||||
}
|
||||
rescantoken();
|
||||
type = getidexpr(TRUE, T_GLOBAL);
|
||||
type = getidexpr(true, T_GLOBAL);
|
||||
break;
|
||||
|
||||
case T_LOCAL:
|
||||
@@ -2167,7 +2174,7 @@ getterm(void)
|
||||
break;
|
||||
}
|
||||
rescantoken();
|
||||
type = getidexpr(TRUE, T_LOCAL);
|
||||
type = getidexpr(true, T_LOCAL);
|
||||
break;
|
||||
|
||||
case T_STATIC:
|
||||
@@ -2177,7 +2184,7 @@ getterm(void)
|
||||
break;
|
||||
}
|
||||
rescantoken();
|
||||
type = getidexpr(TRUE, T_STATIC);
|
||||
type = getidexpr(true, T_STATIC);
|
||||
break;
|
||||
|
||||
case T_LEFTBRACKET:
|
||||
@@ -2231,7 +2238,7 @@ getterm(void)
|
||||
* Returns the type of expression found.
|
||||
*/
|
||||
S_FUNC int
|
||||
getidexpr(BOOL okmat, int autodef)
|
||||
getidexpr(bool okmat, int autodef)
|
||||
{
|
||||
int type;
|
||||
char name[SYMBOLSIZE+1]; /* symbol name */
|
||||
@@ -2332,15 +2339,15 @@ getsymvalue(char *name, VALUE *v_p)
|
||||
* Read in a filename for a read or write command.
|
||||
* Both quoted and unquoted filenames are handled here.
|
||||
* The name must be terminated by an end of line or semicolon.
|
||||
* Returns TRUE if the filename was successfully parsed.
|
||||
* Returns true if the filename was successfully parsed.
|
||||
*
|
||||
* given:
|
||||
* name filename to read
|
||||
* namelen length of filename buffer including NUL byte
|
||||
* once non-NULL => set to TRUE of -once read
|
||||
* once non-NULL => set to true of -once read
|
||||
*/
|
||||
S_FUNC int
|
||||
getfilename(char *name, size_t namelen, BOOL *once)
|
||||
getfilename(char *name, size_t namelen, bool *once)
|
||||
{
|
||||
STRING *s;
|
||||
char *symstr; /* symbol string */
|
||||
@@ -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"
|
||||
@@ -2527,7 +2532,7 @@ getmatargs(void)
|
||||
*/
|
||||
dim = 0;
|
||||
if (gettoken() == T_RIGHTBRACKET) {
|
||||
addoptwo(OP_INDEXADDR, (long) dim, (long) FALSE);
|
||||
addoptwo(OP_INDEXADDR, (long) dim, (long) false);
|
||||
return;
|
||||
}
|
||||
rescantoken();
|
||||
@@ -2537,7 +2542,7 @@ getmatargs(void)
|
||||
switch (gettoken()) {
|
||||
case T_RIGHTBRACKET:
|
||||
addoptwo(OP_INDEXADDR, (long) dim,
|
||||
(long) FALSE);
|
||||
(long) false);
|
||||
return;
|
||||
case T_COMMA:
|
||||
break;
|
||||
@@ -2575,9 +2580,9 @@ getelement(void)
|
||||
|
||||
/*
|
||||
* Read in a single symbol name and copy its value into the given buffer.
|
||||
* Returns TRUE if a valid symbol id was found.
|
||||
* Returns true if a valid symbol id was found.
|
||||
*/
|
||||
S_FUNC BOOL
|
||||
S_FUNC bool
|
||||
getid(char *buf)
|
||||
{
|
||||
int type;
|
||||
@@ -2587,17 +2592,16 @@ getid(char *buf)
|
||||
scanerror(T_NULL, "Reserved keyword used as symbol name");
|
||||
type = T_SYMBOL;
|
||||
*buf = '\0';
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
if (type != T_SYMBOL) {
|
||||
rescantoken();
|
||||
scanerror(T_NULL, "Symbol name expected");
|
||||
*buf = '\0';
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
strncpy(buf, tokensymbol(), SYMBOLSIZE);
|
||||
buf[SYMBOLSIZE] = '\0';
|
||||
return TRUE;
|
||||
strlcpy(buf, tokensymbol(), SYMBOLSIZE+1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2683,11 +2687,11 @@ usesymbol(char *name, int autodef)
|
||||
if (type == SYM_GLOBAL) {
|
||||
warning("Unnecessary global specifier");
|
||||
}
|
||||
addopptr(OP_GLOBALADDR, (char *) addglobal(name, FALSE));
|
||||
addopptr(OP_GLOBALADDR, (char *) addglobal(name, false));
|
||||
return;
|
||||
}
|
||||
if (autodef == T_STATIC) {
|
||||
addopptr(OP_GLOBALADDR, (char *) addglobal(name, TRUE));
|
||||
addopptr(OP_GLOBALADDR, (char *) addglobal(name, true));
|
||||
return;
|
||||
}
|
||||
if (autodef == T_LOCAL) {
|
||||
@@ -2717,7 +2721,7 @@ usesymbol(char *name, int autodef)
|
||||
scanerror(T_NULL, "\"%s\" is undefined", name);
|
||||
return;
|
||||
}
|
||||
(void) addglobal(name, FALSE);
|
||||
(void) addglobal(name, false);
|
||||
addopptr(OP_GLOBALADDR, (char *) findglobal(name));
|
||||
}
|
||||
|
||||
@@ -2736,7 +2740,7 @@ getcallargs(char *name)
|
||||
long index; /* function index */
|
||||
long op; /* opcode to add */
|
||||
int argcount; /* number of arguments */
|
||||
BOOL addrflag;
|
||||
bool addrflag;
|
||||
|
||||
op = OP_CALL;
|
||||
index = getbuiltinfunc(name);
|
||||
|
184
commath.c
184
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-2023 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 "errtbl.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 };
|
||||
COMPLEX _cone_ = { &_qone_, &_qzero_, 1 };
|
||||
COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };
|
||||
@@ -34,6 +38,77 @@ COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };
|
||||
STATIC COMPLEX _cnegone_ = { &_qnegone_, &_qzero_, 1 };
|
||||
|
||||
|
||||
/*
|
||||
* cmappr - complex multiple approximation
|
||||
*
|
||||
* Approximate a number to nearest multiple of a given real number. Whether
|
||||
* rounding is down, up, etc. is determined by rnd.
|
||||
*
|
||||
* This function is useful to round a result to the nearest epsilon:
|
||||
*
|
||||
* COMPLEX *c; (* complex number to round to nearest epsilon *)
|
||||
* NUMBER *eps; (* epsilon rounding precision *)
|
||||
* COMPLEX *res; (* c rounded to nearest epsilon *)
|
||||
* long rnd = 24L; (* a common rounding mode *)
|
||||
* bool ok_to_free; (* true ==> free c, false ==> do not free c *)
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* res = cmappr(c, eps, ok_to_free);
|
||||
*
|
||||
* given:
|
||||
* c pointer to COMPLEX value to round
|
||||
* e pointer to NUMBER multiple
|
||||
* rnd rounding mode
|
||||
* cfree true ==> free c, false ==> do not free c
|
||||
*
|
||||
* returns:
|
||||
* allocated pointer to COMPLEX multiple of e approximation of c
|
||||
*/
|
||||
COMPLEX *
|
||||
cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree)
|
||||
{
|
||||
COMPLEX *r; /* COMPLEX multiple of e approximation of c */
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (c == NULL) {
|
||||
math_error("%s: c is NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
if (e == NULL) {
|
||||
math_error("%s: e is NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate return result
|
||||
*/
|
||||
r = comalloc();
|
||||
|
||||
/*
|
||||
* round c to multiple of e
|
||||
*/
|
||||
qfree(r->real);
|
||||
r->real = qmappr(c->real, e, rnd);
|
||||
qfree(r->imag);
|
||||
r->imag = qmappr(c->imag, e, rnd);
|
||||
|
||||
/*
|
||||
* free c if requested
|
||||
*/
|
||||
if (cfree == true) {
|
||||
comfree(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the allocated multiple of e approximation of c
|
||||
*/
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add two complex numbers.
|
||||
*/
|
||||
@@ -186,7 +261,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 +332,7 @@ c_inv(COMPLEX *c)
|
||||
|
||||
if (ciszero(c)) {
|
||||
math_error("Inverting zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = comalloc();
|
||||
if (cisreal(c)) {
|
||||
@@ -392,6 +467,97 @@ c_real(COMPLEX *c)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* c_to_q - convert a real part of a COMPLEX to a NUMBER
|
||||
*
|
||||
* given:
|
||||
* c complex number for which the real part will be used
|
||||
* cfree true ==> free c, false ==> do not free c
|
||||
*
|
||||
* returns:
|
||||
* allocated NUMBER that the equivalent of the real part of a complex number
|
||||
*
|
||||
* NOTE: Any imaginary part of the COMPLEX value is ignored.
|
||||
*
|
||||
* NOTE: To avoid a loss of value, test with cisreal(c) first:
|
||||
*
|
||||
* COMPLEX *c;
|
||||
* NUMBER *q;
|
||||
* bool ok_to_free;
|
||||
*
|
||||
* if (cisreal(c)) {
|
||||
* q = c_to_q(c, ok_to_free);
|
||||
* }
|
||||
*/
|
||||
NUMBER *
|
||||
c_to_q(COMPLEX *c, bool cfree)
|
||||
{
|
||||
NUMBER *r; /* allocated NUMBER equivalent to return */
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (c == NULL) {
|
||||
math_error("%s: c is NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate a new NUMBER
|
||||
*/
|
||||
r = qalloc();
|
||||
|
||||
/*
|
||||
* link in the real part of the COMPLEX value
|
||||
*/
|
||||
r = qlink(c->real);
|
||||
|
||||
/*
|
||||
* free c if requested
|
||||
*/
|
||||
if (cfree == true) {
|
||||
comfree(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the allocated equivalent NUMBER
|
||||
*/
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* q_to_c - convert a NUMBER into an allocated COMPLEX
|
||||
*
|
||||
* given:
|
||||
* q NUMBER to be converted
|
||||
*
|
||||
* returns:
|
||||
* allocated COMPLEX number whose real part is NUMBER and imag part is 0
|
||||
*/
|
||||
COMPLEX *
|
||||
q_to_c(NUMBER *q)
|
||||
{
|
||||
COMPLEX *res; /* COMPLEX number to return */
|
||||
|
||||
/*
|
||||
* allocate complex number
|
||||
*/
|
||||
res = comalloc();
|
||||
|
||||
/*
|
||||
* assign NUMBER to real part
|
||||
*/
|
||||
qfree(res->real);
|
||||
res->real = qlink(q);
|
||||
|
||||
/*
|
||||
* return the allocated equivalent COMPLEX
|
||||
*/
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the imaginary part of a complex number as a real.
|
||||
*/
|
||||
@@ -519,7 +685,7 @@ c_divq(COMPLEX *c, NUMBER *q)
|
||||
|
||||
if (qiszero(q)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisone(q))
|
||||
return clink(c);
|
||||
@@ -556,13 +722,13 @@ qqtoc(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
|
||||
/*
|
||||
* Compare two complex numbers for equality, returning FALSE if they are equal,
|
||||
* and TRUE if they differ.
|
||||
* Compare two complex numbers for equality, returning false if they are equal,
|
||||
* and true if they differ.
|
||||
*/
|
||||
BOOL
|
||||
bool
|
||||
c_cmp(COMPLEX *c1, COMPLEX *c2)
|
||||
{
|
||||
BOOL i;
|
||||
bool i;
|
||||
|
||||
i = qcmp(c1->real, c2->real);
|
||||
if (!i)
|
||||
@@ -602,7 +768,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_);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user