From nobody Sat Jan 28 21:41:53 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P47FF3HGNz3b29G; Sat, 28 Jan 2023 21:41:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P47FF2yHmz3KDw; Sat, 28 Jan 2023 21:41:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674942113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TAKMDhO6/Y8n3R0vf1kleIX4y2aevMx4R3L8xh4RKbY=; b=lKf5pdIzZ2lW2Qe9loV+fSmbJlowfUYKdVxYWloztXgPCiRhlyf9eS+0/pv/4q2u3xFcAS nVIrVIcPrWXevBM68ceUAN2VbRW3emmRglNT509h+/TNWqlUKDYhSzNgaJqdvZP8+NjCpj MqIbegnAqfNWd/+KI5PUw8uIRfSUnMGBzA1uCfUvGdlFZU9YqOLMdIrBk0FmSGe3QsKklL 4sFDM7YVWQRbE9FX9NmaBN2Mg9IkBFWoVlrPoDdeQnl/u80YbV+WnK9t5NsGehI35ERyOU EWXA/3u6QM6G+Mc73Ou7EUuxMDprcIrio0LqIrA8o9sB2iCqIPDJV6cvUPg+FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674942113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TAKMDhO6/Y8n3R0vf1kleIX4y2aevMx4R3L8xh4RKbY=; b=VZhuwg6+Qem8hTqWEl2x0QHTOJxKzwU/rWwhdU/TKq+AvStqk+wU2HJIac2cwcYK1DwtOw 6zsPJwUyfCeFKEA5nKcd0Cx5l+VjKcSSh3HMCXjHWaywDo89zyZzIrn5wCtOEeWTPuXosk 0hM2ydQMsWWyodnOgYr/I2stfiQaZCQesK5x4Q4HTlRWmGcI3wmyJFdJB1yNwvKVqVpZxu szK5rhpR/r2ZomG+8w6o490JP/7EPLt2ytsmSe5h1SdYX6T+C3X2jzEXi5hobwPb28JDDJ /biiINF4LaFvG+N4gj2xfosEe3DEPDeLLnZxazXQ8MbrtsitJzKY0ZBjIZ2Vlg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674942113; a=rsa-sha256; cv=none; b=KsArL66dHXWjGjbLZkOzaNQwu5jWKBRGV1sTr5QTrOngazPcQ/Fs42eounZlWMLv3sVGhg Fogj3dOlMJd9T3ZahQ0ZbouPhSb0eKoVvaTqbUURAYHokPbjW3TxYxQ6ZT1fmEHR+2y5kD YfkzEjOQNHVqE10pFcQ6xBrIJgx/Mjkva4vix4NiG3BMfSP+OXuQca0HO2zbH+4Ekb1b0X gClsrYgbBSH5xmAouqF1fTAd09f8dDoxlB/cWaaJutXf9q8L5SEBW+Whcl/PaLOw9cTIuc pyWzolEuA9n9zO/uQNCZU9/W++pl16ghaiYJkyojVvSTopDS2SYI6MNOxF5Mgw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P47FF22ZTz14T9; Sat, 28 Jan 2023 21:41:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30SLfr48079427; Sat, 28 Jan 2023 21:41:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30SLfrV8079426; Sat, 28 Jan 2023 21:41:53 GMT (envelope-from git) Date: Sat, 28 Jan 2023 21:41:53 GMT Message-Id: <202301282141.30SLfrV8079426@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Stefan=20E=C3=9Fer?= Subject: git: d101cdd6edd7 - main - contrib/bc: merge from vendor release 6.2.2 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d101cdd6edd782f6ec56eef63ed91abd77a8b317 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=d101cdd6edd782f6ec56eef63ed91abd77a8b317 commit d101cdd6edd782f6ec56eef63ed91abd77a8b317 Merge: 8f02c0d15669 1a63323d17fe Author: Stefan Eßer AuthorDate: 2023-01-28 21:26:22 +0000 Commit: Stefan Eßer CommitDate: 2023-01-28 21:26:22 +0000 contrib/bc: merge from vendor release 6.2.2 This update fixes a few issues in history editing and the processing of the "quit" function. The "quit" function will no longer cause bc to exit when encountered in a script file (before any command from the script has been executed). New functions is_number(), is_string return 1 if the passed argument is a number resp. a string. The asciify() function has been extended to support the conversion of an array of numbers into a string. Merge commit '1a63323d17fedb05b6962853e821c9d7c6b9853e' contrib/bc/.clang-format | 152 --- contrib/bc/.clang-tidy | 43 - contrib/bc/.gitignore | 86 -- contrib/bc/LICENSE.md | 6 +- contrib/bc/MEMORY_BUGS.md | 53 + contrib/bc/Makefile.in | 26 +- contrib/bc/NEWS.md | 136 ++ contrib/bc/NOTICE.md | 2 +- contrib/bc/README.md | 61 +- contrib/bc/configure.sh | 370 +++++- contrib/bc/gen/bc_help.txt | 40 +- contrib/bc/gen/dc_help.txt | 38 +- contrib/bc/gen/lib.bc | 3 +- contrib/bc/gen/lib2.bc | 15 +- contrib/bc/gen/strgen.c | 8 +- contrib/bc/gen/strgen.sh | 6 +- contrib/bc/include/args.h | 33 +- contrib/bc/include/bc.h | 6 +- contrib/bc/include/bcl.h | 57 +- contrib/bc/include/dc.h | 2 +- contrib/bc/include/file.h | 20 +- contrib/bc/include/history.h | 30 +- contrib/bc/include/lang.h | 39 +- contrib/bc/include/lex.h | 59 +- contrib/bc/include/library.h | 142 +- contrib/bc/include/num.h | 14 +- contrib/bc/include/opt.h | 2 +- contrib/bc/include/parse.h | 40 +- contrib/bc/include/program.h | 104 +- contrib/bc/include/rand.h | 2 +- contrib/bc/include/read.h | 2 +- contrib/bc/include/status.h | 461 +++++-- contrib/bc/include/vector.h | 18 +- contrib/bc/include/version.h | 4 +- contrib/bc/include/vm.h | 294 ++++- contrib/bc/locales/de_DE.ISO8859-1.msg | 17 +- contrib/bc/locales/de_DE.UTF-8.msg | 17 +- contrib/bc/locales/en_US.msg | 17 +- contrib/bc/locales/es_ES.ISO8859-1.msg | 17 +- contrib/bc/locales/es_ES.UTF-8.msg | 17 +- contrib/bc/locales/fr_FR.ISO8859-1.msg | 17 +- contrib/bc/locales/fr_FR.UTF-8.msg | 17 +- contrib/bc/locales/ja_JP.UTF-8.msg | 17 +- contrib/bc/locales/ja_JP.eucJP.msg | 17 +- contrib/bc/locales/nl_NL.ISO8859-1.msg | 17 +- contrib/bc/locales/nl_NL.UTF-8.msg | 17 +- contrib/bc/locales/pl_PL.ISO8859-2.msg | 17 +- contrib/bc/locales/pl_PL.UTF-8.msg | 17 +- contrib/bc/locales/pt_PT.ISO8859-1.msg | 17 +- contrib/bc/locales/pt_PT.UTF-8.msg | 17 +- contrib/bc/locales/ru_RU.CP1251.msg | 17 +- contrib/bc/locales/ru_RU.CP866.msg | 17 +- contrib/bc/locales/ru_RU.ISO8859-5.msg | 17 +- contrib/bc/locales/ru_RU.KOI8-R.msg | 17 +- contrib/bc/locales/ru_RU.UTF-8.msg | 17 +- contrib/bc/locales/zh_CN.GB18030.msg | 17 +- contrib/bc/locales/zh_CN.GB2312.msg | 17 +- contrib/bc/locales/zh_CN.GBK.msg | 17 +- contrib/bc/locales/zh_CN.UTF-8.msg | 17 +- contrib/bc/locales/zh_CN.eucCN.msg | 17 +- contrib/bc/manuals/algorithms.md | 2 +- contrib/bc/manuals/bc/A.1 | 459 ++++--- contrib/bc/manuals/bc/A.1.md | 372 ++++-- contrib/bc/manuals/bc/E.1 | 420 +++--- contrib/bc/manuals/bc/E.1.md | 350 +++-- contrib/bc/manuals/bc/EH.1 | 420 +++--- contrib/bc/manuals/bc/EH.1.md | 350 +++-- contrib/bc/manuals/bc/EHN.1 | 420 +++--- contrib/bc/manuals/bc/EHN.1.md | 350 +++-- contrib/bc/manuals/bc/EN.1 | 420 +++--- contrib/bc/manuals/bc/EN.1.md | 350 +++-- contrib/bc/manuals/bc/H.1 | 459 ++++--- contrib/bc/manuals/bc/H.1.md | 372 ++++-- contrib/bc/manuals/bc/HN.1 | 459 ++++--- contrib/bc/manuals/bc/HN.1.md | 372 ++++-- contrib/bc/manuals/bc/N.1 | 459 ++++--- contrib/bc/manuals/bc/N.1.md | 372 ++++-- contrib/bc/manuals/bcl.3 | 197 ++- contrib/bc/manuals/bcl.3.md | 161 ++- contrib/bc/manuals/build.md | 131 +- contrib/bc/manuals/dc/A.1 | 304 +++-- contrib/bc/manuals/dc/A.1.md | 242 ++-- contrib/bc/manuals/dc/E.1 | 296 +++-- contrib/bc/manuals/dc/E.1.md | 244 ++-- contrib/bc/manuals/dc/EH.1 | 296 +++-- contrib/bc/manuals/dc/EH.1.md | 244 ++-- contrib/bc/manuals/dc/EHN.1 | 296 +++-- contrib/bc/manuals/dc/EHN.1.md | 244 ++-- contrib/bc/manuals/dc/EN.1 | 296 +++-- contrib/bc/manuals/dc/EN.1.md | 244 ++-- contrib/bc/manuals/dc/H.1 | 304 +++-- contrib/bc/manuals/dc/H.1.md | 242 ++-- contrib/bc/manuals/dc/HN.1 | 304 +++-- contrib/bc/manuals/dc/HN.1.md | 242 ++-- contrib/bc/manuals/dc/N.1 | 304 +++-- contrib/bc/manuals/dc/N.1.md | 242 ++-- contrib/bc/scripts/exec-install.sh | 2 +- contrib/bc/scripts/format.sh | 4 +- contrib/bc/scripts/functions.sh | 2 +- contrib/bc/scripts/karatsuba.py | 2 +- contrib/bc/scripts/link.sh | 2 +- contrib/bc/scripts/lint.sh | 2 +- contrib/bc/scripts/locale_install.sh | 2 +- contrib/bc/scripts/locale_uninstall.sh | 2 +- contrib/bc/src/args.c | 108 +- contrib/bc/src/bc.c | 16 +- contrib/bc/src/bc_lex.c | 8 +- contrib/bc/src/bc_parse.c | 190 ++- contrib/bc/src/data.c | 46 +- contrib/bc/src/dc.c | 16 +- contrib/bc/src/dc_lex.c | 12 +- contrib/bc/src/dc_parse.c | 115 +- contrib/bc/src/file.c | 169 +-- contrib/bc/src/history.c | 101 +- contrib/bc/src/lang.c | 14 +- contrib/bc/src/lex.c | 51 +- contrib/bc/src/library.c | 555 ++++---- contrib/bc/src/main.c | 22 +- contrib/bc/src/num.c | 535 +++++--- contrib/bc/src/opt.c | 8 +- contrib/bc/src/parse.c | 67 +- contrib/bc/src/program.c | 682 ++++++---- contrib/bc/src/rand.c | 2 +- contrib/bc/src/read.c | 52 +- contrib/bc/src/vector.c | 50 +- contrib/bc/src/vm.c | 787 +++++++----- contrib/bc/tests/all.sh | 15 +- contrib/bc/tests/bc/all.txt | 7 + contrib/bc/tests/bc/asciify_array.txt | 17 + contrib/bc/tests/bc/asciify_array_results.txt | 3 + contrib/bc/tests/bc/errors/33.txt | 2 + contrib/bc/tests/bc/errors/34.txt | 357 +++++ contrib/bc/tests/bc/errors/35.txt | 1 + contrib/bc/tests/bc/errors/36.txt | 11 + contrib/bc/tests/bc/is_number.txt | 13 + contrib/bc/tests/bc/is_number_results.txt | 10 + contrib/bc/tests/bc/is_string.txt | 13 + contrib/bc/tests/bc/is_string_results.txt | 10 + contrib/bc/tests/bc/line_by_line1.txt | 10 + contrib/bc/tests/bc/line_by_line1_results.txt | 1 + contrib/bc/tests/bc/line_by_line2.txt | 9 + contrib/bc/tests/bc/line_by_line2_results.txt | 3 + contrib/bc/tests/bc/line_loop_quit1.txt | 2 + contrib/bc/tests/bc/line_loop_quit1_results.txt | 4 + contrib/bc/tests/bc/line_loop_quit2.txt | 3 + contrib/bc/tests/bc/line_loop_quit2_results.txt | 4 + contrib/bc/tests/bc/scripts/afl1.bc | 261 ++++ contrib/bc/tests/bc/scripts/afl1.txt | 1571 +++++++++++++++++++++++ contrib/bc/tests/bc/scripts/all.txt | 2 + contrib/bc/tests/bc/scripts/array2.bc | 20 + contrib/bc/tests/bc/scripts/array2.txt | 2 + contrib/bc/tests/bc/timeconst.sh | 2 +- contrib/bc/tests/bcl.c | 7 +- contrib/bc/tests/dc/all.txt | 3 + contrib/bc/tests/dc/errors/15.txt | 128 +- contrib/bc/tests/dc/errors/34.txt | 117 -- contrib/bc/tests/dc/is_number.txt | 9 + contrib/bc/tests/dc/is_number_results.txt | 9 + contrib/bc/tests/dc/is_string.txt | 9 + contrib/bc/tests/dc/is_string_results.txt | 9 + contrib/bc/tests/dc/misc1.txt | 26 + contrib/bc/tests/dc/misc1_results.txt | 21 + contrib/bc/tests/dc/scripts/all.txt | 1 + contrib/bc/tests/dc/scripts/no_clamp.dc | 29 + contrib/bc/tests/dc/scripts/no_clamp.txt | 29 + contrib/bc/tests/error.sh | 48 +- contrib/bc/tests/errors.sh | 2 +- contrib/bc/tests/history.py | 2 +- contrib/bc/tests/history.sh | 2 +- contrib/bc/tests/other.sh | 53 +- contrib/bc/tests/read.sh | 2 +- contrib/bc/tests/script.sh | 10 +- contrib/bc/tests/scripts.sh | 2 +- contrib/bc/tests/stdin.sh | 2 +- contrib/bc/tests/test.sh | 10 +- contrib/bc/vs/bc.vcxproj | 16 +- 176 files changed, 14121 insertions(+), 6440 deletions(-) diff --cc contrib/bc/MEMORY_BUGS.md index 000000000000,d675b28b342a..d675b28b342a mode 000000,100644..100644 --- a/contrib/bc/MEMORY_BUGS.md +++ b/contrib/bc/MEMORY_BUGS.md diff --cc contrib/bc/README.md index 64c58410162c,000000000000..438cab0d1694 mode 100644,000000..100644 --- a/contrib/bc/README.md +++ b/contrib/bc/README.md @@@ -1,443 -1,0 +1,498 @@@ +# `bc` + +***WARNING: New user registration for https://git.yzena.com/ is disabled because +of spam. If you need to report a bug with `bc`, email gavin at this site minus +the `git.` part for an account, and I will create one for you. Or you can report +an issue at [GitHub][29].*** + +***WARNING: This project has moved to [https://git.yzena.com/][20] for [these +reasons][21], though GitHub will remain a mirror.*** + +This is an implementation of the [POSIX `bc` calculator][12] that implements +[GNU `bc`][1] extensions, as well as the period (`.`) extension for the BSD +flavor of `bc`. + +For more information, see this `bc`'s full manual. + +This `bc` also includes an implementation of `dc` in the same binary, accessible +via a symbolic link, which implements all FreeBSD and GNU extensions. (If a +standalone `dc` binary is desired, `bc` can be copied and renamed to `dc`.) The +`!` command is omitted; I believe this poses security concerns and that such +functionality is unnecessary. + +For more information, see the `dc`'s full manual. + +This `bc` also provides `bc`'s math as a library with C bindings, called `bcl`. + +For more information, see the full manual for `bcl`. + +## License + +This `bc` is Free and Open Source Software (FOSS). It is offered under the BSD +2-clause License. Full license text may be found in the [`LICENSE.md`][4] file. + +## Prerequisites + +This `bc` only requires either: + +1. Windows 10 or later, or +2. A C99-compatible compiler and a (mostly) POSIX 2008-compatible system with + the XSI (X/Open System Interfaces) option group. + +Since POSIX 2008 with XSI requires the existence of a C99 compiler as `c99`, any +POSIX and XSI-compatible system will have everything needed. + +POSIX-compatible systems that are known to work: + +* Linux +* FreeBSD +* OpenBSD +* NetBSD +* Mac OSX +* Solaris* (as long as the Solaris version supports POSIX 2008) +* AIX +* HP-UX* (except for history) + +In addition, there is compatibility code to make this `bc` work on Windows. + +Please submit bug reports if this `bc` does not build out of the box on any +system. + +## Build + +This `bc` should build unmodified on any POSIX-compliant system or on Windows +starting with Windows 10 (though earlier versions may work). + +For more complex build requirements than the ones below, see the [build +manual][5]. + +### Windows + +There is no guarantee that this `bc` will work on any version of Windows earlier +than Windows 10 (I cannot test on earlier versions), but it is guaranteed to +work on Windows 10 at least. + +Also, if building with MSBuild, the MSBuild bundled with Visual Studio is +required. + +**Note**: Unlike the POSIX-compatible platforms, only one build configuration is +supported on Windows: extra math and history enabled, NLS (locale support) +disabled, with both calculators built. + +#### `bc` + +To build `bc`, you can open the `vs/bc.sln` file in Visual Studio, select the +configuration, and build. + +You can also build using MSBuild with the following from the root directory: + +``` +msbuild -property:Configuration= vs/bc.sln +``` + +where `` is either one of `Debug` or `Release`. + +On Windows, the calculators are built as `vs/bin///bc.exe` and +`vs/bin///dc.exe`, where `` can be either `Win32` or +`x64`, and `` can be `Debug` or `Release`. + +**Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked. +Patches are welcome for a way to do that. + +#### `bcl` (Library) + +To build the library, you can open the `vs/bcl.sln` file in Visual Studio, +select the configuration, and build. + +You can also build using MSBuild with the following from the root directory: + +``` +msbuild -property:Configuration= vs/bcl.sln +``` + +where `` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`. + +On Windows, the library is built as `vs/lib///bcl.lib`, where +`` can be either `Win32` or `x64`, and `` can be `Debug`, +`ReleaseMD`, or `ReleaseMT`. + +### POSIX-Compatible Systems + +On POSIX-compatible systems, `bc` is built as `bin/bc` and `dc` is built as +`bin/dc` by default. + +#### Default + +For the default build with optimization, use the following commands in the root +directory: + +``` +./configure.sh -O3 +make +``` + +#### One Calculator + +To only build `bc`, use the following commands: + +``` +./configure.sh --disable-dc +make +``` + +To only build `dc`, use the following commands: + +``` +./configure.sh --disable-bc +make +``` + +#### Debug + +For debug builds, use the following commands in the root directory: + +``` +./configure.sh -g +make +``` + +#### Install + +To install, use the following command: + +``` +make install +``` + +By default, `bc` and `dc` will be installed in `/usr/local`. For installing in +other locations, use the `PREFIX` environment variable when running +`configure.sh` or pass the `--prefix=` option to `configure.sh`. See the +[build manual][5], or run `./configure.sh --help`, for more details. + +#### Library + - This `bc` does provide a way to build a math library with C bindings. This is - done by the `-a` or `--library` options to `configure.sh`: ++To build the math library, pass the `-a` or `--library` options to ++`configure.sh`: + +``` +./configure.sh -a +``` + +When building the library, the executables are not built. For more information, +see the [build manual][5]. + +The library API can be found in [`manuals/bcl.3.md`][26] or `man bcl` once the +library is installed. + +#### Package and Distro Maintainers + +This section is for package and distro maintainers. + +##### Out-of-Source Builds + +Out-of-source builds are supported; just call `configure.sh` from the directory +where the actual build will happen. + +For example, if the source is in `bc`, the build should happen in `build`, then +call `configure.sh` and `make` like so: + +``` +../bc/configure.sh +make +``` + +***WARNING***: The path to `configure.sh` from the build directory must not have +spaces because `make` does not support target names with spaces. + +##### Recommended Compiler + +When I ran benchmarks with my `bc` compiled under `clang`, it performed much +better than when compiled under `gcc`. I recommend compiling this `bc` with +`clang`. + +I also recommend building this `bc` with C11 if you can because `bc` will detect +a C11 compiler and add `_Noreturn` to any relevant function(s). + +##### Recommended Optimizations + +I wrote this `bc` with Separation of Concerns, which means that there are many +small functions that could be inlined. However, they are often called across +file boundaries, and the default optimizer can only look at the current file, +which means that they are not inlined. + +Thus, because of the way this `bc` is built, it will automatically be slower +than other `bc` implementations when running scripts with no math. (My `bc`'s +math is *much* faster, so any non-trivial script should run faster in my `bc`.) + +Some, or all, of the difference can be made up with the right optimizations. The +optimizations I recommend are: + +1. `-O3` +2. `-flto` (link-time optimization) + +in that order. + +Link-time optimization, in particular, speeds up the `bc` a lot. This is because +when link-time optimization is turned on, the optimizer can look across files +and inline *much* more heavily. + +However, I recommend ***NOT*** using `-march=native`. Doing so will reduce this +`bc`'s performance, at least when building with link-time optimization. See the +[benchmarks][19] for more details. + +##### Stripping Binaries + +By default, non-debug binaries are stripped, but stripping can be disabled with +the `-T` option to `configure.sh`. + +##### Using This `bc` as an Alternative + +If this `bc` is packaged as an alternative to an already existing `bc` package, +it is possible to rename it in the build to prevent name collision. To prepend +to the name, just run the following: + +``` +EXECPREFIX= ./configure.sh +``` + +To append to the name, just run the following: + +``` +EXECSUFFIX= ./configure.sh +``` + +If a package maintainer wishes to add both a prefix and a suffix, that is +allowed. + +**Note**: The suggested name (and package name) when `bc` is not available is +`bc-gh`. + +##### Karatsuba Number + +Package and distro maintainers have one tool at their disposal to build this +`bc` in the optimal configuration: `scripts/karatsuba.py`. + +This script is not a compile-time or runtime prerequisite; it is for package and +distro maintainers to run once when a package is being created. It finds the +optimal Karatsuba number (see the [algorithms manual][7] for more information) +for the machine that it is running on. + +The easiest way to run this script is with `make karatsuba`. + +If desired, maintainers can also skip running this script because there is a +sane default for the Karatsuba number. + +## Status + +This `bc` is robust. + +It is well-tested, fuzzed, and fully standards-compliant (though not certified) +with POSIX `bc`. The math has been tested with 40+ million random problems, so +it is as correct as I can make it. + +This `bc` can be used as a drop-in replacement for any existing `bc`. This `bc` +is also compatible with MinGW toolchains. + +In addition, this `bc` is considered complete; i.e., there will be no more +releases with additional features. However, it *is* actively maintained, so if +any bugs are found, they will be fixed in new releases. Also, additional +translations will also be added as they are provided. + +### Development + +If I (Gavin D. Howard) get [hit by a bus][27] and future programmers need to +handle work themselves, the best place to start is the [Development manual][28]. + +## Vim Syntax + +I have developed (using other people's code to start) [`vim` syntax files][17] +for this `bc` and `dc`, including the extensions. + +## `bc` Libs + +I have gathered some excellent [`bc` and `dc` libraries][18]. These libraries +may prove useful to any serious users. + +## Comparison to GNU `bc` + +This `bc` compares favorably to GNU `bc`. + +* This `bc` builds natively on Windows. - * It has more extensions, which make this `bc` more useful for scripting. ++* It has more extensions, which make this `bc` more useful for scripting. (See ++ [Extensions](#extensions).) +* This `bc` is a bit more POSIX compliant. +* It has a much less buggy parser. The GNU `bc` will give parse errors for what + is actually valid `bc` code, or should be. For example, putting an `else` on + a new line after a brace can cause GNU `bc` to give a parse error. +* This `bc` has fewer crashes. +* GNU `bc` calculates the wrong number of significant digits for `length(x)`. +* GNU `bc` will sometimes print numbers incorrectly. For example, when running + it on the file `tests/bc/power.txt` in this repo, GNU `bc` gets all the right + answers, but it fails to wrap the numbers at the proper place when outputting + to a file. +* This `bc` is faster. (See [Performance](#performance).) + +### Performance + +Because this `bc` packs more than `1` decimal digit per hardware integer, this +`bc` is faster than GNU `bc` and can be *much* faster. Full benchmarks can be +found at [manuals/benchmarks.md][19]. + +There is one instance where this `bc` is slower: if scripts are light on math. +This is because this `bc`'s intepreter is slightly slower than GNU `bc`, but +that is because it is more robust. See the [benchmarks][19]. + ++### Extensions ++ ++Below is a non-comprehensive list of extensions that this `bc` and `dc` have ++that all others do not. ++ ++* An extended math library. (See [here][30] for more information.) ++* A command-line prompt. ++* Turning on and off digit clamping. (Digit clamping is about how to treat ++ "invalid" digits for a particular base. GNU `bc` uses it, and the BSD `bc` ++ does not. Mine does both.) ++* A pseudo-random number generator. This includes the ability to set the seed ++ and get reproducible streams of random numbers. ++* The ability to use stacks for the globals `scale`, `ibase`, and `obase` ++ instead of needing to restore them in *every* function. ++* The ability to *not* use non-standard keywords. For example, `abs` is a ++ keyword (a built-in function), but if some script actually defines a function ++ called that, it's possible to tell my `bc` to not treat it as a keyword, which ++ will make the script parses correctly. ++* The ability to turn on and off printing leading zeroes on numbers greater than ++ `-1` and less than `1`. ++* Outputting in scientific and engineering notation. ++* Accepting input in scientific and engineering notation. ++* Passing strings and arrays to the `length()` built-in function. (In `dc`, the ++ `Y` command will do this for arrays, and the `Z` command will do this for both ++ numbers and strings.) ++* The `abs()` built-in function. (This is the `b` command in `dc`.) ++* The `is_number()` and `is_string()` built-in functions. (These tell whether a ++ variable is holding a string or a number, for runtime type checking. The ++ commands are `u` and `t` in `dc`.) ++* For `bc` only, the `divmod()` built-in function for computing a quotient and ++ remainder at the same time. ++* For `bc` only, the `asciify()` built-in function for converting an array to a ++ string. ++* The `$` truncation operator. (It's the same in `bc` and `dc`.) ++* The `@` "set scale" operator. (It's the same in `bc` and `dc`.) ++* The decimal shift operators. (`<<` and `>>` in `bc`, `H` and `h` in `dc`.) ++* Built-in functions or commands to get the max of `scale`, `ibase`, and ++ `obase`. ++* The ability to put strings into variables in `bc`. (This always existed in ++ `dc`.) ++* The `'` command in `dc` for the depth of the execution stack. ++* The `y` command in `dc` for the depth of register stacks. ++* Built-in functions or commands to get the value of certain environment ++ variables that might affect execution. ++* The `stream` keyword to do the same thing as the `P` command in `dc`. ++* Defined order of evaluation. ++* Defined exit statuses. ++* All environment variables other than `POSIXLY_CORRECT`, `BC_ENV_ARGS`, and ++ `BC_LINE_LENGTH`. ++* The ability for users to define their own defaults for various options during ++ build. (See [here][31] for more information.) ++ +## Algorithms + +To see what algorithms this `bc` uses, see the [algorithms manual][7]. + +## Locales + +Currently, there is no locale support on Windows. + +Additionally, this `bc` only has support for English (and US English), French, +German, Portuguese, Dutch, Polish, Russian, Japanese, and Chinese locales. +Patches are welcome for translations; use the existing `*.msg` files in +`locales/` as a starting point. + +In addition, patches for improvements are welcome; the last two messages in +Portuguese were made with Google Translate, and the Dutch, Polish, Russian, +Japanese, and Chinese locales were all generated with [DeepL][22]. + +The message files provided assume that locales apply to all regions where a +language is used, but this might not be true for, e.g., `fr_CA` and `fr_CH`. +Any corrections or a confirmation that the current texts are acceptable for +those regions would be appreciated, too. + +## Other Projects + +Other projects based on this bc are: + +* [busybox `bc`][8]. The busybox maintainers have made their own changes, so any + bugs in the busybox `bc` should be reported to them. + +* [toybox `bc`][9]. The maintainer has also made his own changes, so bugs in the + toybox `bc` should be reported there. + +* [FreeBSD `bc`][23]. While the `bc` in FreeBSD is kept up-to-date, it is better + to [report bugs there][24], as well as [submit patches][25], and the + maintainers of the package will contact me if necessary. + +## Language + +This `bc` is written in pure ISO C99, using POSIX 2008 APIs with custom Windows +compatibility code. + +## Commit Messages + +This `bc` uses the commit message guidelines laid out in [this blog post][10]. + +## Semantic Versioning + +This `bc` uses [semantic versioning][11]. + +## Contents + +Items labeled with `(maintainer use only)` are not included in release source +tarballs. + +Files: + + .gitignore The git ignore file (maintainer use only). + .gitattributes The git attributes file (maintainer use only). + bcl.pc.in A template pkg-config file for bcl. + configure A symlink to configure.sh to make packaging easier. + configure.sh The configure script. + LICENSE.md A Markdown form of the BSD 2-clause License. + Makefile.in The Makefile template. + NEWS.md The changelog. + NOTICE.md List of contributors and copyright owners. + +Folders: + + benchmarks A folder of benchmarks for various aspects of bc performance. + gen The bc math library, help texts, and code to generate C source. + include All header files. + locales Locale files, in .msg format. Patches welcome for translations. + manuals Manuals for both programs. + src All source code. + scripts A bunch of shell scripts to help with development and building. + tests All tests. + vs Files needed for the build on Windows. + +[1]: https://www.gnu.org/software/bc/ +[4]: ./LICENSE.md +[5]: ./manuals/build.md +[7]: ./manuals/algorithms.md +[8]: https://git.busybox.net/busybox/tree/miscutils/bc.c +[9]: https://github.com/landley/toybox/blob/master/toys/pending/bc.c +[10]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html +[11]: http://semver.org/ +[12]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html +[17]: https://git.yzena.com/gavin/vim-bc +[18]: https://git.yzena.com/gavin/bc_libs +[19]: ./manuals/benchmarks.md +[20]: https://git.yzena.com/gavin/bc +[21]: https://gavinhoward.com/2020/04/i-am-moving-away-from-github/ +[22]: https://www.deepl.com/translator +[23]: https://cgit.freebsd.org/src/tree/contrib/bc +[24]: https://bugs.freebsd.org/ +[25]: https://reviews.freebsd.org/ +[26]: ./manuals/bcl.3.md +[27]: https://en.wikipedia.org/wiki/Bus_factor +[28]: ./manuals/development.md +[29]: https://github.com/gavinhoward/bc ++[30]: ./manuals/bc/A.1.md#extended-library ++[31]: ./manuals/build.md#settings diff --cc contrib/bc/tests/bc/asciify_array.txt index 000000000000,4efae1d13876..4efae1d13876 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/asciify_array.txt +++ b/contrib/bc/tests/bc/asciify_array.txt diff --cc contrib/bc/tests/bc/asciify_array_results.txt index 000000000000,d0dc2bc37514..d0dc2bc37514 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/asciify_array_results.txt +++ b/contrib/bc/tests/bc/asciify_array_results.txt diff --cc contrib/bc/tests/bc/errors/33.txt index 000000000000,a16568bb2d98..a16568bb2d98 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/errors/33.txt +++ b/contrib/bc/tests/bc/errors/33.txt diff --cc contrib/bc/tests/bc/errors/34.txt index 000000000000,1b452c609159..1b452c609159 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/errors/34.txt +++ b/contrib/bc/tests/bc/errors/34.txt diff --cc contrib/bc/tests/bc/errors/35.txt index 000000000000,40e79633c4a5..40e79633c4a5 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/errors/35.txt +++ b/contrib/bc/tests/bc/errors/35.txt diff --cc contrib/bc/tests/bc/errors/36.txt index 000000000000,5929bdb7a5b9..5929bdb7a5b9 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/errors/36.txt +++ b/contrib/bc/tests/bc/errors/36.txt diff --cc contrib/bc/tests/bc/is_number.txt index 000000000000,f9e1f753b0a3..f9e1f753b0a3 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/is_number.txt +++ b/contrib/bc/tests/bc/is_number.txt diff --cc contrib/bc/tests/bc/is_number_results.txt index 000000000000,1c03b9c18714..1c03b9c18714 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/is_number_results.txt +++ b/contrib/bc/tests/bc/is_number_results.txt diff --cc contrib/bc/tests/bc/is_string.txt index 000000000000,bfd7136d2dea..bfd7136d2dea mode 000000,100644..100644 --- a/contrib/bc/tests/bc/is_string.txt +++ b/contrib/bc/tests/bc/is_string.txt diff --cc contrib/bc/tests/bc/is_string_results.txt index 000000000000,99f11f6b2e75..99f11f6b2e75 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/is_string_results.txt +++ b/contrib/bc/tests/bc/is_string_results.txt diff --cc contrib/bc/tests/bc/line_by_line1.txt index 000000000000,daf328e2c03e..daf328e2c03e mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_by_line1.txt +++ b/contrib/bc/tests/bc/line_by_line1.txt diff --cc contrib/bc/tests/bc/line_by_line1_results.txt index 000000000000,0cfbf08886fc..0cfbf08886fc mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_by_line1_results.txt +++ b/contrib/bc/tests/bc/line_by_line1_results.txt diff --cc contrib/bc/tests/bc/line_by_line2.txt index 000000000000,b05c2169aced..b05c2169aced mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_by_line2.txt +++ b/contrib/bc/tests/bc/line_by_line2.txt diff --cc contrib/bc/tests/bc/line_by_line2_results.txt index 000000000000,3760375f171d..3760375f171d mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_by_line2_results.txt +++ b/contrib/bc/tests/bc/line_by_line2_results.txt diff --cc contrib/bc/tests/bc/line_loop_quit1.txt index 000000000000,03a6ca111f47..03a6ca111f47 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_loop_quit1.txt +++ b/contrib/bc/tests/bc/line_loop_quit1.txt diff --cc contrib/bc/tests/bc/line_loop_quit1_results.txt index 000000000000,17342202bbfc..17342202bbfc mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_loop_quit1_results.txt +++ b/contrib/bc/tests/bc/line_loop_quit1_results.txt diff --cc contrib/bc/tests/bc/line_loop_quit2.txt index 000000000000,6d6a440b3dd4..6d6a440b3dd4 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_loop_quit2.txt +++ b/contrib/bc/tests/bc/line_loop_quit2.txt diff --cc contrib/bc/tests/bc/line_loop_quit2_results.txt index 000000000000,17342202bbfc..17342202bbfc mode 000000,100644..100644 --- a/contrib/bc/tests/bc/line_loop_quit2_results.txt +++ b/contrib/bc/tests/bc/line_loop_quit2_results.txt diff --cc contrib/bc/tests/bc/scripts/afl1.bc index 000000000000,bbb393a30fe3..bbb393a30fe3 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/scripts/afl1.bc +++ b/contrib/bc/tests/bc/scripts/afl1.bc diff --cc contrib/bc/tests/bc/scripts/afl1.txt index 000000000000,9d3ac4b542fa..9d3ac4b542fa mode 000000,100644..100644 --- a/contrib/bc/tests/bc/scripts/afl1.txt +++ b/contrib/bc/tests/bc/scripts/afl1.txt diff --cc contrib/bc/tests/bc/scripts/array2.bc index 000000000000,34d88c3e276b..34d88c3e276b mode 000000,100644..100644 --- a/contrib/bc/tests/bc/scripts/array2.bc +++ b/contrib/bc/tests/bc/scripts/array2.bc diff --cc contrib/bc/tests/bc/scripts/array2.txt index 000000000000,76dcb035f907..76dcb035f907 mode 000000,100644..100644 --- a/contrib/bc/tests/bc/scripts/array2.txt +++ b/contrib/bc/tests/bc/scripts/array2.txt diff --cc contrib/bc/tests/dc/is_number.txt index 000000000000,358182927326..358182927326 mode 000000,100644..100644 --- a/contrib/bc/tests/dc/is_number.txt +++ b/contrib/bc/tests/dc/is_number.txt diff --cc contrib/bc/tests/dc/is_number_results.txt index 000000000000,6c8f29cea4ab..6c8f29cea4ab mode 000000,100644..100644 --- a/contrib/bc/tests/dc/is_number_results.txt +++ b/contrib/bc/tests/dc/is_number_results.txt diff --cc contrib/bc/tests/dc/is_string.txt index 000000000000,6798fa3904b8..6798fa3904b8 mode 000000,100644..100644 --- a/contrib/bc/tests/dc/is_string.txt +++ b/contrib/bc/tests/dc/is_string.txt diff --cc contrib/bc/tests/dc/is_string_results.txt index 000000000000,0c6a1c9abd7a..0c6a1c9abd7a mode 000000,100644..100644 --- a/contrib/bc/tests/dc/is_string_results.txt +++ b/contrib/bc/tests/dc/is_string_results.txt diff --cc contrib/bc/tests/dc/misc1.txt index 000000000000,a512573ae548..a512573ae548 mode 000000,100644..100644 --- a/contrib/bc/tests/dc/misc1.txt +++ b/contrib/bc/tests/dc/misc1.txt diff --cc contrib/bc/tests/dc/misc1_results.txt index 000000000000,d2f8ad70b4b8..d2f8ad70b4b8 mode 000000,100644..100644 --- a/contrib/bc/tests/dc/misc1_results.txt +++ b/contrib/bc/tests/dc/misc1_results.txt diff --cc contrib/bc/tests/dc/scripts/no_clamp.dc index 000000000000,bad184a54401..bad184a54401 mode 000000,100644..100644 --- a/contrib/bc/tests/dc/scripts/no_clamp.dc +++ b/contrib/bc/tests/dc/scripts/no_clamp.dc diff --cc contrib/bc/tests/dc/scripts/no_clamp.txt index 000000000000,c8b680be10aa..c8b680be10aa mode 000000,100644..100644 --- a/contrib/bc/tests/dc/scripts/no_clamp.txt +++ b/contrib/bc/tests/dc/scripts/no_clamp.txt