The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=ea31d1a5c490193348e0b71fdda6d08a2c80a2eb
commit ea31d1a5c490193348e0b71fdda6d08a2c80a2eb Author: Stefan Eßer <s...@freebsd.org> AuthorDate: 2021-10-04 07:41:06 +0000 Commit: Stefan Eßer <s...@freebsd.org> CommitDate: 2021-10-04 07:41:06 +0000 contrib/bc: remove files ommitted from the release A number of files have been removed from the release distribution of this bc implementation. They were mostly relevant for pre release testing and benchmarking to identify regressions. The Markdown sources of the man pages are only relevant for combinations of build options not used in FreeBSD and need non-default conversion tools (available as ports in FreeBSD). All the omitted files can be found in the upstream git repository, and they are fetched when building this software as a port. But they have never been used in the FreeBSD base system. --- contrib/bc/benchmarks/bc/add.bc | 21 - contrib/bc/benchmarks/bc/arrays.bc | 34 - contrib/bc/benchmarks/bc/arrays_and_constants.bc | 35 - contrib/bc/benchmarks/bc/bitfuncs.bc | 18 - contrib/bc/benchmarks/bc/constants.bc | 41 - contrib/bc/benchmarks/bc/divide.bc | 26 - contrib/bc/benchmarks/bc/functions.bc | 34 - contrib/bc/benchmarks/bc/irand_long.bc | 9 - contrib/bc/benchmarks/bc/irand_short.bc | 5 - contrib/bc/benchmarks/bc/lib.bc | 7 - contrib/bc/benchmarks/bc/multiply.bc | 23 - contrib/bc/benchmarks/bc/postfix_incdec.bc | 7 - contrib/bc/benchmarks/bc/power.bc | 2 - contrib/bc/benchmarks/bc/strings.bc | 36 - contrib/bc/benchmarks/bc/subtract.bc | 22 - contrib/bc/benchmarks/dc/modexp.dc | 42 - contrib/bc/manuals/development.md | 4950 ---------------------- contrib/bc/manuals/release.md | 72 - contrib/bc/scripts/afl.py | 245 -- contrib/bc/scripts/alloc.sh | 84 - contrib/bc/scripts/benchmark.sh | 159 - contrib/bc/scripts/bitgen.c | 101 - contrib/bc/scripts/fuzz_prep.sh | 81 - contrib/bc/scripts/manpage.sh | 175 - contrib/bc/scripts/ministat.c | 670 --- contrib/bc/scripts/package.sh | 173 - contrib/bc/scripts/radamsa.sh | 133 - contrib/bc/scripts/radamsa.txt | 17 - contrib/bc/scripts/randmath.py | 421 -- contrib/bc/scripts/release.sh | 779 ---- contrib/bc/scripts/release_settings.txt | 16 - contrib/bc/scripts/test_settings.sh | 77 - contrib/bc/scripts/test_settings.txt | 93 - contrib/bc/tests/fuzzing/bc_afl.yaml | 125 - contrib/bc/tests/fuzzing/bc_afl_continue.yaml | 122 - contrib/bc/tests/fuzzing/bc_inputs1/strings.txt | 14 - contrib/bc/tests/fuzzing/dc_inputs/stack_len.txt | 1 - 37 files changed, 8870 deletions(-) diff --git a/contrib/bc/benchmarks/bc/add.bc b/contrib/bc/benchmarks/bc/add.bc deleted file mode 100644 index 90a83e4758d9..000000000000 --- a/contrib/bc/benchmarks/bc/add.bc +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/bc -lq - -print "scale = 20\n" -print "x = 1234567890 / scale\n" -print "len = length(x) + 1 + scale\n" -print "len *= 2\n" - -scale = 20 -x = 1234567890 / scale -len = length(x) + 1 + scale -len *= 2 - -for (i = 0; i <= len; ++i) { - print "a[", i, "] = x * (10^", i, ")\n" -} - -for (i = 1; i <= 10000; ++i) { - for (j = 0; j < len; ++j) { - print "v = a[", i, "] + a[", j, "]\n" - } -} diff --git a/contrib/bc/benchmarks/bc/arrays.bc b/contrib/bc/benchmarks/bc/arrays.bc deleted file mode 100644 index e3c463187d78..000000000000 --- a/contrib/bc/benchmarks/bc/arrays.bc +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/bc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -max = 1000000 - -for (i = 0; i < max; ++i) { - print "a", i, "[0] = ", i, "\n" -} diff --git a/contrib/bc/benchmarks/bc/arrays_and_constants.bc b/contrib/bc/benchmarks/bc/arrays_and_constants.bc deleted file mode 100644 index 93c5594bec20..000000000000 --- a/contrib/bc/benchmarks/bc/arrays_and_constants.bc +++ /dev/null @@ -1,35 +0,0 @@ -#! /usr/bin/bc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -max = 1000000 - -for (i = 0; i < max; ++i) { - print "b", i, "[100] = ", i, "\n" -} - diff --git a/contrib/bc/benchmarks/bc/bitfuncs.bc b/contrib/bc/benchmarks/bc/bitfuncs.bc deleted file mode 100644 index 1c2a6529d04b..000000000000 --- a/contrib/bc/benchmarks/bc/bitfuncs.bc +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/bc -lq - -scale = 0 -max = 10000 - -print "scale = 0\n" - -for (i = 0; i < max; ++i) { - - a = rand() - b = rand() - - print "band(", a, ", ", b, ")\n" - print "bor(", a, ", ", b, ")\n" - print "bxor(", a, ", ", b, ")\n" - print "blshift(", a, ", ", b % 32, ")\n" - print "brshift(", a, ", ", b % 32, ")\n" -} diff --git a/contrib/bc/benchmarks/bc/constants.bc b/contrib/bc/benchmarks/bc/constants.bc deleted file mode 100644 index 1f7b92d47566..000000000000 --- a/contrib/bc/benchmarks/bc/constants.bc +++ /dev/null @@ -1,41 +0,0 @@ -#! /usr/bin/bc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -max = 1000 -max2 = 1000 - -for (i = 0; i < max; ++i) { - - print "c = ", i, "\n" - print "e = 0.", i, "\n" - - for (j = 0; j < max2; ++j) { - print "d = ", i, ".", j, "\n" - } -} diff --git a/contrib/bc/benchmarks/bc/divide.bc b/contrib/bc/benchmarks/bc/divide.bc deleted file mode 100644 index 227794badbcb..000000000000 --- a/contrib/bc/benchmarks/bc/divide.bc +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/bc -lq - -print "scale = 20\n" -print "x = 1234567890 * 10^(-scale)\n" -print "len = 1 + 2 * scale\n" -print "scale += 10\n" - -scale = 20 -x = 1234567890 * 10^(-scale) -len = 1 + 2 * scale - -scale += 10 - -for (i = 0; i <= len; ++i) { - print "a[", i, "] = x * (10^", i, ")\n" -} - -for (i = 1; i <= 10000; ++i) { - for (j = 0; j < len; ++j) { - print "v = a[0] / a[", j, "]\n" - print "v = a[", i, "] / a[", j, "]\n" - print "v = (a[0] * ", i, ") / a[", j, "]\n" - print "v = a[0] / (a[", j, "] * ", i, ")\n" - print "v = (a[0] * ", i, ") / (a[", j, "] * ", i, ")\n" - } -} diff --git a/contrib/bc/benchmarks/bc/functions.bc b/contrib/bc/benchmarks/bc/functions.bc deleted file mode 100644 index dc6ae8d6edc5..000000000000 --- a/contrib/bc/benchmarks/bc/functions.bc +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/bc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -max = 1000000 - -for (i = 0; i < max; ++i) { - print "define etsna", i, "(n) {\n\tn\n}\n" -} diff --git a/contrib/bc/benchmarks/bc/irand_long.bc b/contrib/bc/benchmarks/bc/irand_long.bc deleted file mode 100644 index 9274f8953b60..000000000000 --- a/contrib/bc/benchmarks/bc/irand_long.bc +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/bc -lq - -start = 2^256 -end = start + 10000000 - -for (i = start; i < end; ++i) { - print "irand(", i, ")\n" -} - diff --git a/contrib/bc/benchmarks/bc/irand_short.bc b/contrib/bc/benchmarks/bc/irand_short.bc deleted file mode 100644 index 16ae863f2e2b..000000000000 --- a/contrib/bc/benchmarks/bc/irand_short.bc +++ /dev/null @@ -1,5 +0,0 @@ -#! /usr/bin/bc -lq - -for (i = 2; i < 10000000; ++i) { - print "irand(", i, ")\n" -} diff --git a/contrib/bc/benchmarks/bc/lib.bc b/contrib/bc/benchmarks/bc/lib.bc deleted file mode 100644 index 87b5f9168458..000000000000 --- a/contrib/bc/benchmarks/bc/lib.bc +++ /dev/null @@ -1,7 +0,0 @@ -#! /usr/bin/bc -lq - -print "for (i = 100; i < 1000; ++i) {\n" -print " v = pi(i)\n" -print " v = e(v)\n" -print " v = l(v)\n" -print "}\n" diff --git a/contrib/bc/benchmarks/bc/multiply.bc b/contrib/bc/benchmarks/bc/multiply.bc deleted file mode 100644 index d4ed08e055c8..000000000000 --- a/contrib/bc/benchmarks/bc/multiply.bc +++ /dev/null @@ -1,23 +0,0 @@ -#! /usr/bin/bc -lq - -print "scale = 20\n" -print "x = 1234567890 / scale\n" -print "len = length(x) + 1 + scale\n" - -scale = 20 -x = 1234567890 / scale -len = length(x) + 1 + scale - -for (i = 0; i <= len; ++i) { - print "a[", i, "] = x * (10^", i, ")\n" -} - -for (i = 1; i <= 10000; ++i) { - for (j = 0; j < len; ++j) { - print "v = a[0] * a[", j, "]\n" - print "v = a[", i, "] * a[", j, "]\n" - print "v = (a[0] * ", i, ") * a[", j, "]\n" - print "v = a[0] * (a[", j, "] * ", i, ")\n" - print "v = (a[0] * ", i, ") * (a[", j, "] * ", i, ")\n" - } -} diff --git a/contrib/bc/benchmarks/bc/postfix_incdec.bc b/contrib/bc/benchmarks/bc/postfix_incdec.bc deleted file mode 100644 index 922a065a8172..000000000000 --- a/contrib/bc/benchmarks/bc/postfix_incdec.bc +++ /dev/null @@ -1,7 +0,0 @@ -#! /usr/bin/bc -lq - -max = 1000000 - -for (i = 0; i < max; ++i) { - print "i++\ni--\n" -} diff --git a/contrib/bc/benchmarks/bc/power.bc b/contrib/bc/benchmarks/bc/power.bc deleted file mode 100644 index b067aa732d10..000000000000 --- a/contrib/bc/benchmarks/bc/power.bc +++ /dev/null @@ -1,2 +0,0 @@ -#! /usr/bin/bc -lq - diff --git a/contrib/bc/benchmarks/bc/strings.bc b/contrib/bc/benchmarks/bc/strings.bc deleted file mode 100644 index 13cf200cdb89..000000000000 --- a/contrib/bc/benchmarks/bc/strings.bc +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/bc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -max = 1000000 - -print "\qasotehnuasnotehustnaoheusntaoheustnaoheusntaoehunsatoheuastoehuaosnetuhaosetnuhaosentuahoesntuahoeuhstoeunhatoehusanotehusatnoheus\q\n" - -for (i = 0; i < max; ++i) { - print "\qabc", i, " = ", i, "\\n\q\n" -} diff --git a/contrib/bc/benchmarks/bc/subtract.bc b/contrib/bc/benchmarks/bc/subtract.bc deleted file mode 100644 index b88bd60e935c..000000000000 --- a/contrib/bc/benchmarks/bc/subtract.bc +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/bc -lq - -print "scale = 20\n" -print "x = 1234567890 / scale\n" -print "len = length(x) + 1 + scale\n" -print "len *= 2\n" - -scale = 20 -x = 1234567890 / scale -len = length(x) + 1 + scale -len *= 2 - -for (i = 0; i <= len; ++i) { - print "a[", i, "] = x * (10^", i, ")\n" -} - -for (i = 1; i <= 10000; ++i) { - for (j = 0; j < len; ++j) { - print "v = a[", i, "] - a[", j, "]\n" - } -} - diff --git a/contrib/bc/benchmarks/dc/modexp.dc b/contrib/bc/benchmarks/dc/modexp.dc deleted file mode 100644 index 48f304cb92da..000000000000 --- a/contrib/bc/benchmarks/dc/modexp.dc +++ /dev/null @@ -1,42 +0,0 @@ -#! /usr/bin/dc -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -[ ]ss -[|]so -100sm 0si -[ - li1+si 0sj - [ - lj1+sj 0sk - [ - lk1+sk lin lsn ljn lsn lkn lsn lon 10P lk lm !<z - ]dszx - lj lm !<y - ]dsyx - li lm !<x -]dsxx diff --git a/contrib/bc/manuals/development.md b/contrib/bc/manuals/development.md deleted file mode 100644 index bbc82e37b82c..000000000000 --- a/contrib/bc/manuals/development.md +++ /dev/null @@ -1,4950 +0,0 @@ -# Development - -Updated: 25 July 2021 - -This document is meant for the day when I (Gavin D. Howard) get [hit by a -bus][1]. In other words, it's meant to make the [bus factor][1] a non-issue. - -This document is supposed to contain all of the knowledge necessary to develop -`bc` and `dc`. - -In addition, this document is meant to add to the [oral tradition of software -engineering][118], as described by Bryan Cantrill. - -This document will reference other parts of the repository. That is so a lot of -the documentation can be closest to the part of the repo where it is actually -necessary. - -## What Is It? - -This repository contains an implementation of both [POSIX `bc`][2] and [Unix -`dc`][3]. - -POSIX `bc` is a standard utility required for POSIX systems. `dc` is a -historical utility that was included in early Unix and even predates both Unix -and C. They both are arbitrary-precision command-line calculators with their own -programming languages. `bc`'s language looks similar to C, with infix notation -and including functions, while `dc` uses [Reverse Polish Notation][4] and allows -the user to execute strings as though they were functions. - -In addition, it is also possible to build the arbitrary-precision math as a -library, named [`bcl`][156]. - -**Note**: for ease, I will refer to both programs as `bc` in this document. -However, if I say "just `bc`," I am referring to just `bc`, and if I say `dc`, I -am referring to just `dc`. - -### History - -This project started in January 2018 when a certain individual on IRC, hearing -that I knew how to write parsers, asked me to write a `bc` parser for his math -library. I did so. I thought about writing my own math library, but he -disparaged my programming skills and made me think that I couldn't do it. - -However, he took so long to do it that I eventually decided to give it a try and -had a working math portion in two weeks. It taught me that I should not listen -to such people. - -From that point, I decided to make it an extreme learning experience about how -to write quality software. - -That individual's main goal had been to get his `bc` into [toybox][16], and I -managed to get my own `bc` in. I also got it in [busybox][17]. - -Eventually, in late 2018, I also decided to try my hand at implementing -[Karatsuba multiplication][18], an algorithm that that unnamed individual -claimed I could never implement. It took me a bit, but I did it. - -This project became a passion project for me, and I continued. In mid-2019, -Stefan Eßer suggested I improve performance by putting more than 1 digit in each -section of the numbers. After I showed immaturity because of some burnout, I -implemented his suggestion, and the results were incredible. - -Since that time, I have gradually been improving the `bc` as I have learned more -about things like fuzzing, [`scan-build`][19], [valgrind][20], -[AddressSanitizer][21] (and the other sanitizers), and many other things. - -One of my happiest moments was when my `bc` was made the default in FreeBSD. - -But since I believe in [finishing the software I write][22], I have done less -work on `bc` over time, though there are still times when I put a lot of effort -in, such as now (17 June 2021), when I am attempting to convince OpenBSD to use -my `bc`. - -And that is why I am writing this document: someday, someone else is going to -want to change my code, and this document is my attempt to make it as simple as -possible. - -### Values - -[According to Bryan Cantrill][10], all software has values. I think he's -correct, though I [added one value for programming languages in particular][11]. - -However, for `bc`, his original list will do: - -* Approachability -* Availability -* Compatibility -* Composability -* Debuggability -* Expressiveness -* Extensibility -* Interoperability -* Integrity -* Maintainability -* Measurability -* Operability -* Performance -* Portability -* Resiliency -* Rigor -* Robustness -* Safety -* Security -* Simplicity -* Stability -* Thoroughness -* Transparency -* Velocity - -There are several values that don't apply. The reason they don't apply is -because `bc` and `dc` are existing utilities; this is just another -reimplementation. The designs of `bc` and `dc` are set in stone; there is -nothing we can do to change them, so let's get rid of those values that would -apply to their design: - -* Compatibility -* Integrity -* Maintainability -* Measurability -* Performance -* Portability -* Resiliency -* Rigor -* Robustness -* Safety -* Security -* Simplicity -* Stability -* Thoroughness -* Transparency - -Furthermore, some of the remaining ones don't matter to me, so let me get rid of -those and order the rest according to my *actual* values for this project: - -* Robustness -* Stability -* Portability -* Compatibility -* Performance -* Security -* Simplicity - -First is **robustness**. This `bc` and `dc` should be robust, accepting any -input, never crashing, and instead, returning an error. - -Closely related to that is **stability**. The execution of `bc` and `dc` should -be deterministic and never change for the same inputs, including the -pseudo-random number generator (for the same seed). - -Third is **portability**. These programs should run everywhere that POSIX -exists, as well as Windows. This means that just about every person on the -planet will have access to these programs. - -Next is **compatibility**. These programs should, as much as possible, be -compatible with other existing implementations and standards. - -Then we come to **performance**. A calculator is only usable if it's fast, so -these programs should run as fast as possible. - -After that is **security**. These programs should *never* be the reason a user's -computer is compromised. - -And finally, **simplicity**. Where possible, the code should be simple, while -deferring to the above values. - -Keep these values in mind for the rest of this document, and for exploring any -other part of this repo. - -#### Portability - -But before I go on, I want to talk about portability in particular. - -Most of these principles just require good attention and care, but portability -is different. Sometimes, it requires pulling in code from other places and -adapting it. In other words, sometimes I need to duplicate and adapt code. - -This happened in a few cases: - -* Option parsing (see [`include/opt.h`][35]). -* History (see [`include/history.h`][36]). -* Pseudo-Random Number Generator (see [`include/rand.h`][37]). - -This was done because I decided to ensure that `bc`'s dependencies were -basically zero. In particular, either users have a normal install of Windows or -they have a POSIX system. - -A POSIX system limited me to C99, `sh`, and zero external dependencies. That -last item is why I pull code into `bc`: if I pull it in, it's not an external -dependency. - -That's why `bc` has duplicated code. Remove it, and you risk `bc` not being -portable to some platforms. - -## Suggested Course - -I do have a suggested course for programmers to follow when trying to understand -this codebase. The order is this: - -1. `bc` Spec. -2. Manpages. -3. Test suite. -4. Understand the build. -5. Algorithms manual. -6. Code concepts. -7. Repo structure. -8. Headers. -9. Source code. - -This order roughly follows this order: - -1. High-level requirements -2. Low-level requirements -3. High-level implementation -4. Low-level implementation - -In other words, first understand what the code is *supposed* to do, then -understand the code itself. - -## Useful External Tools - -I have a few tools external to `bc` that are useful: - -* A [Vim plugin with syntax files made specifically for my `bc` and `dc`][132]. -* A [repo of `bc` and `dc` scripts][133]. -* A set of `bash` aliases (see below). -* A `.bcrc` file with items useful for my `bash` setup (see below). - -My `bash` aliases are these: - -```sh -alias makej='make -j16' -alias mcmake='make clean && make' -alias mcmakej='make clean && make -j16' -alias bcdebug='CPPFLAGS="-DBC_DEBUG_CODE=1" CFLAGS="-Weverything -Wno-padded \ - -Wno-switch-enum -Wno-format-nonliteral -Wno-cast-align \ - -Wno-unreachable-code-return -Wno-missing-noreturn \ - -Wno-disabled-macro-expansion -Wno-unreachable-code -Wall -Wextra \ - -pedantic -std=c99" ./configure.sh' -alias bcconfig='CFLAGS="-Weverything -Wno-padded -Wno-switch-enum \ - -Wno-format-nonliteral -Wno-cast-align -Wno-unreachable-code-return \ - -Wno-missing-noreturn -Wno-disabled-macro-expansion -Wno-unreachable-code \ - -Wall -Wextra -pedantic -std=c99" ./configure.sh' -alias bcnoassert='CPPFLAGS="-DNDEBUG" CFLAGS="-Weverything -Wno-padded \ - -Wno-switch-enum -Wno-format-nonliteral -Wno-cast-align \ - -Wno-unreachable-code-return -Wno-missing-noreturn \ - -Wno-disabled-macro-expansion -Wno-unreachable-code -Wall -Wextra \ - -pedantic -std=c99" ./configure.sh' -alias bcdebugnoassert='CPPFLAGS="-DNDEBUG -DBC_DEBUG_CODE=1" \ - CFLAGS="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral \ - -Wno-cast-align -Wno-unreachable-code-return -Wno-missing-noreturn \ - -Wno-disabled-macro-expansion -Wno-unreachable-code -Wall -Wextra \ - -pedantic -std=c99" ./configure.sh' -alias bcunset='unset BC_LINE_LENGTH && unset BC_ENV_ARGS' -``` - -`makej` runs `make` with all of my cores. - -`mcmake` runs `make clean` before running `make`. It will take a target on the -command-line. - -`mcmakej` is a combination of `makej` and `mcmake`. - -`bcdebug` configures `bc` for a full debug build, including `BC_DEBUG_CODE` (see -[Debugging][134] below). - -`bcconfig` configures `bc` with Clang (Clang is my personal default compiler) -using full warnings, with a few really loud and useless warnings turned off. - -`bcnoassert` configures `bc` to not have asserts built in. - -`bcdebugnoassert` is like `bcnoassert`, except it also configures `bc` for debug -mode. - -`bcunset` unsets my personal `bc` environment variables, which are set to: - -```sh -export BC_ENV_ARGS="-l $HOME/.bcrc" -export BC_LINE_LENGTH="74" -``` - -Unsetting these environment variables are necessary for running -[`scripts/release.sh`][83] because otherwise, it will error when attempting to -run `bc -s` on my `$HOME/.bcrc`. - -Speaking of which, the contents of that file are: - -```bc -define void print_time_unit(t){ - if(t<10)print "0" - if(t<1&&t)print "0" - print t,":" -} -define void sec2time(t){ - auto s,m,h,d,r - r=scale - scale=0 - t=abs(t) - s=t%60 - t-=s - m=t/60%60 - t-=m - h=t/3600%24 - t-=h - d=t/86400 - if(d)print_time_unit(d) - if(h)print_time_unit(h) - print_time_unit(m) - if(s<10)print "0" - if(s<1&&s)print "0" - s - scale=r -} -define minutes(secs){ - return secs/60; -} -define hours(secs){ - return secs/3600; -} -define days(secs){ - return secs/3600/24; -} -define years(secs){ - return secs/3600/24/365.25; -} -define fbrand(b,p){ - auto l,s,t - b=abs(b)$ - if(b<2)b=2 - s=scale - t=b^abs(p)$ - l=ceil(l2(t),0) - if(l>scale)scale=l - t=irand(t)/t - scale=s - return t -} -define ifbrand(i,b,p){return irand(abs(i)$)+fbrand(b,p)} -``` - -This allows me to use `bc` as part of my `bash` prompt. - -## Code Style - -The code style for `bc` is...weird, and that comes from historical accident. - -In [History][23], I mentioned how I got my `bc` in [toybox][16]. Well, in order -to do that, my `bc` originally had toybox style. Eventually, I changed to using -tabs, and assuming they were 4 spaces wide, but other than that, I basically -kept the same style, with some exceptions that are more or less dependent on my -taste. - -The code style is as follows: - -* Tabs are 4 spaces. -* Tabs are used at the beginning of lines for indent. -* Spaces are used for alignment. -* Lines are limited to 80 characters, period. -* Pointer asterisk (`*`) goes with the variable (on the right), not the type, - unless it is for a pointer type returned from a function. -* The opening brace is put on the same line as the header for the function, - loop, or `if` statement. -* Unless the header is more than one line, in which case the opening brace is - put on its own line. -* If the opening brace is put on its own line, there is no blank line after it. -* If the opening brace is *not* put on its own line, there *is* a blank line - after it, *unless* the block is only one or two lines long. -* Code lines are grouped into what I call "paragraphs." Basically, lines that - seem like they should go together are grouped together. This one comes down - to judgment. -* Bodies of `if` statements, `else` statements, and loops that are one line - long are put on the same line as the statement, unless the header is more than - one line long, and/or, the header and body cannot fit into 80 characters with - a space inbetween them. -* If single-line bodies are on a separate line from their headers, and the - headers are only a single line, then no braces are used. -* However, braces are *always* used if they contain another `if` statement or - loop. -* Loops with empty bodies are ended with a semicolon. -* Expressions that return a boolean value are surrounded by paretheses. -* Macro backslashes are aligned as far to the left as possible. -* Binary operators have spaces on both sides. -* If a line with binary operators overflows 80 characters, a newline is inserted - *after* binary operators. -* Function modifiers and return types are on the same line as the function name. -* With one exception, `goto`'s are only used to jump to the end of a function - for cleanup. -* All structs, enums, and unions are `typedef`'ed. -* All constant data is in one file: [`src/data.c`][131], but the corresponding - `extern` declarations are in the appropriate header file. -* All local variables are declared at the beginning of the scope where they - appear. They may be initialized at that point, if it does not invoke UB or - otherwise cause bugs. -* All precondition `assert()`'s (see [Asserts][135]) come *after* local variable - declarations. -* Besides short `if` statements and loops, there should *never* be more than one - statement per line. - -### ClangFormat - -I attempted three times to use [ClangFormat][24] to impose a standard, -machine-useful style on `bc`. All three failed. Otherwise, the style in this -repo would be more consistent. - -## Repo Structure - -Functions are documented with Doxygen-style doc comments. Functions that appear -in headers are documented in the headers, while static functions are documented -where they are defined. - -### `bcl.sln` - -A Visual Studio solution file for [`bcl`][156]. This, along with -[`bcl.vcxproj`][63] and [`bcl.vcxproj.filters`][64] is what makes it possible to -build [`bcl`][156] on Windows. - -### `bcl.vcxproj` - -A Visual Studio project file for [`bcl`][156]. This, along with [`bcl.sln`][65] -and [`bcl.vcxproj.filters`][64] is what makes it possible to build [`bcl`][156] -on Windows. - -### `bcl.vcxproj.filters` - -A Visual Studio filters file for [`bcl`][156]. This, along with [`bcl.sln`][65] -and [`bcl.vcxproj`][63] is what makes it possible to build [`bcl`][156] on -Windows. - -### `bc.sln` - -A Visual Studio solution file for `bc`. This, along with [`bc.vcxproj`][66] -and [`bc.vcxproj.filters`][67] is what makes it possible to build `bc` on -Windows. - -### `bc.vcxproj` - -A Visual Studio project file for `bc`. This, along with [`bc.sln`][68] and -[`bc.vcxproj.filters`][67] is what makes it possible to build `bc` on Windows. - -### `bc.vcxproj.filters` - -A Visual Studio filters file for `bc`. This, along with [`bc.sln`][68] and -[`bc.vcxproj`][66] is what makes it possible to build `bc` on Windows. - -### `configure` - -A symlink to [`configure.sh`][69]. - -### `configure.sh` - -This is the script to configure `bc` and [`bcl`][156] for building. - -This `bc` has a custom build system. The reason for this is because of -[*portability*][136]. - -If `bc` used an outside build system, that build system would be an external -dependency. Thus, I had to write a build system for `bc` that used nothing but -C99 and POSIX utilities. - -One of those utilities is POSIX `sh`, which technically implements a -Turing-complete programming language. It's a terrible one, but it works. - *** 8168 LINES SKIPPED *** _______________________________________________ dev-commits-src-main@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"