aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Eßer <se@FreeBSD.org>2022-06-11 09:50:28 +0000
committerStefan Eßer <se@FreeBSD.org>2022-06-11 09:50:28 +0000
commit5bdd626528a2bb3e341e283b2eb279235997b8f4 (patch)
tree76ed2ffea2671f693d61e61f456805da8c39c7b2
parented0603704174b01c25b49efc08c82e1532dc5622 (diff)
downloadsrc-5bdd626528a2bb3e341e283b2eb279235997b8f4.tar.gz
src-5bdd626528a2bb3e341e283b2eb279235997b8f4.zip
vendor/bc: import of version 5.3.0vendor/bc/5.3.0
This version adds support for command line editing and history using the editline or readline libraries in addition to the line editing features available in previous versions.
-rw-r--r--Makefile.in15
-rw-r--r--NEWS.md17
-rw-r--r--README.md34
-rwxr-xr-xconfigure.sh87
-rw-r--r--gen/bc_help.txt26
-rw-r--r--gen/dc_help.txt26
-rw-r--r--gen/strgen.c308
-rwxr-xr-xgen/strgen.sh27
-rw-r--r--include/args.h4
-rw-r--r--include/bc.h65
-rw-r--r--include/bcl.h258
-rw-r--r--include/dc.h15
-rw-r--r--include/file.h80
-rw-r--r--include/history.h177
-rw-r--r--include/lang.h95
-rw-r--r--include/lex.h49
-rw-r--r--include/library.h104
-rw-r--r--include/num.h161
-rw-r--r--include/opt.h24
-rw-r--r--include/parse.h47
-rw-r--r--include/program.h1065
-rw-r--r--include/rand.h48
-rw-r--r--include/read.h12
-rw-r--r--include/status.h113
-rw-r--r--include/vector.h106
-rw-r--r--include/version.h2
-rw-r--r--include/vm.h155
-rw-r--r--manuals/bc/A.1128
-rw-r--r--manuals/bc/A.1.md141
-rw-r--r--manuals/bc/E.1100
-rw-r--r--manuals/bc/E.1.md121
-rw-r--r--manuals/bc/EH.1100
-rw-r--r--manuals/bc/EH.1.md121
-rw-r--r--manuals/bc/EHN.1100
-rw-r--r--manuals/bc/EHN.1.md121
-rw-r--r--manuals/bc/EN.1100
-rw-r--r--manuals/bc/EN.1.md121
-rw-r--r--manuals/bc/H.1128
-rw-r--r--manuals/bc/H.1.md141
-rw-r--r--manuals/bc/HN.1128
-rw-r--r--manuals/bc/HN.1.md141
-rw-r--r--manuals/bc/N.1128
-rw-r--r--manuals/bc/N.1.md141
-rw-r--r--manuals/bcl.316
-rw-r--r--manuals/bcl.3.md10
-rw-r--r--manuals/build.md39
-rw-r--r--manuals/dc/A.177
-rw-r--r--manuals/dc/A.1.md59
-rw-r--r--manuals/dc/E.160
-rw-r--r--manuals/dc/E.1.md48
-rw-r--r--manuals/dc/EH.160
-rw-r--r--manuals/dc/EH.1.md48
-rw-r--r--manuals/dc/EHN.160
-rw-r--r--manuals/dc/EHN.1.md48
-rw-r--r--manuals/dc/EN.160
-rw-r--r--manuals/dc/EN.1.md48
-rw-r--r--manuals/dc/H.177
-rw-r--r--manuals/dc/H.1.md59
-rw-r--r--manuals/dc/HN.177
-rw-r--r--manuals/dc/HN.1.md59
-rw-r--r--manuals/dc/N.177
-rw-r--r--manuals/dc/N.1.md59
-rwxr-xr-xscripts/format.sh49
-rwxr-xr-xscripts/functions.sh94
-rwxr-xr-xscripts/lint.sh63
-rw-r--r--src/args.c157
-rw-r--r--src/bc.c5
-rw-r--r--src/bc_lex.c90
-rw-r--r--src/bc_parse.c692
-rw-r--r--src/data.c870
-rw-r--r--src/dc.c5
-rw-r--r--src/dc_lex.c70
-rw-r--r--src/dc_parse.c66
-rw-r--r--src/file.c214
-rw-r--r--src/history.c816
-rw-r--r--src/lang.c124
-rw-r--r--src/lex.c145
-rw-r--r--src/library.c387
-rw-r--r--src/main.c11
-rw-r--r--src/num.c1188
-rw-r--r--src/opt.c141
-rw-r--r--src/parse.c85
-rw-r--r--src/program.c1108
-rw-r--r--src/rand.c196
-rw-r--r--src/read.c85
-rw-r--r--src/vector.c248
-rw-r--r--src/vm.c548
-rw-r--r--tests/bcl.c69
-rwxr-xr-xtests/history.py10
-rwxr-xr-xtests/other.sh58
-rw-r--r--vs/bc.vcxproj41
91 files changed, 9111 insertions, 4645 deletions
diff --git a/Makefile.in b/Makefile.in
index b9136a57aa92..041b9b014cfd 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -147,6 +147,7 @@ BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
BC_ENABLE_NLS = %%NLS%%
BC_LONG_BIT = %%LONG_BIT%%
+BC_EXCLUDE_EXTRA_MATH = %%EXCLUDE_EXTRA_MATH%%
BC_ENABLE_AFL = %%FUZZ%%
BC_ENABLE_MEMCHECK = %%MEMCHECK%%
@@ -201,14 +202,14 @@ DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3) $(DC_DEFS4)
CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
CPPFLAGS2 = $(CPPFLAGS1) -I$(INCDIR)/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%%
CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC)
-CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 %%BSD%%
+CPPFLAGS4 = $(CPPFLAGS3) %%BSD%%
CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS)
CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
CPPFLAGS8 = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) -DBC_ENABLE_LIBRARY=$(BC_ENABLE_LIBRARY)
CPPFLAGS = $(CPPFLAGS8) -DBC_ENABLE_MEMCHECK=$(BC_ENABLE_MEMCHECK) -DBC_ENABLE_AFL=$(BC_ENABLE_AFL)
-CFLAGS = $(CPPFLAGS) $(BC_DEFS) $(DC_DEFS) %%CPPFLAGS%% %%CFLAGS%%
-LDFLAGS = %%LDFLAGS%%
+CFLAGS = $(CPPFLAGS) $(BC_DEFS) $(DC_DEFS) %%CPPFLAGS%% %%CFLAGS%% -I$(INCLUDEDIR)
+LDFLAGS = %%LDFLAGS%% -L$(LIBDIR)
HOSTCFLAGS = %%HOSTCFLAGS%%
@@ -235,25 +236,25 @@ $(GEN_EXEC): $(GEN_DIR)
%%GEN_EXEC_TARGET%%
$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
- $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_LIB_C_ARGS)
+ $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_EXCLUDE_EXTRA_MATH) $(BC_LIB_C_ARGS)
$(BC_LIB_O): $(BC_LIB_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
- $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_LIB2_C_ARGS)
+ $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_EXCLUDE_EXTRA_MATH) $(BC_LIB2_C_ARGS)
$(BC_LIB2_O): $(BC_LIB2_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
- $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
+ $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) $(BC_EXCLUDE_EXTRA_MATH) bc_help "" $(BC_ENABLED_NAME)
$(BC_HELP_O): $(BC_HELP_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
- $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
+ $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) $(BC_EXCLUDE_EXTRA_MATH) dc_help "" $(DC_ENABLED_NAME)
$(DC_HELP_O): $(DC_HELP_C)
$(CC) $(CFLAGS) -o $@ -c $<
diff --git a/NEWS.md b/NEWS.md
index 1a8a5dd31ad8..c526239a6987 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,22 @@
# News
+## 5.3.0
+
+This is a production release that adds features and has a few bug fixes.
+
+First, support for editline and readline history has been added. To use
+editline, pass `-e` to `configure.sh`, and to use readline, pass `-r`.
+
+Second, history support for Windows has been fixed and re-enabled.
+
+Third, command-line options to set `scale`, `ibase`, `obase`, and `seed` were
+added. This was requested long ago, and I originally disagreed with the idea.
+
+Fourth, the manuals had typos and were missing information. That has been fixed.
+
+Fifth, the manuals received different formatting to be more readable as
+manpages.
+
## 5.2.5
This is a production release that fixes this `bc`'s behavior on `^D` to match
diff --git a/README.md b/README.md
index 259ab923bfc4..64c58410162c 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,10 @@
# `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.***
@@ -71,8 +76,8 @@ 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 prompt enabled, history and NLS (locale
-support) disabled, with both calculators built.
+supported on Windows: extra math and history enabled, NLS (locale support)
+disabled, with both calculators built.
#### `bc`
@@ -179,9 +184,6 @@ 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.
-The library is built as `bin/libbcl.a` on POSIX-compatible systems or as
-`Release/bcl/bcl.lib` on Windows.
-
#### Package and Distro Maintainers
This section is for package and distro maintainers.
@@ -289,8 +291,7 @@ 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, though history is not supported on
-Windows.
+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
@@ -405,18 +406,18 @@ Files:
Makefile.in The Makefile template.
NEWS.md The changelog.
NOTICE.md List of contributors and copyright owners.
- RELEASE.md A checklist for making a release (maintainer use only).
Folders:
- 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.
+ 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
@@ -439,3 +440,4 @@ Folders:
[26]: ./manuals/bcl.3.md
[27]: https://en.wikipedia.org/wiki/Bus_factor
[28]: ./manuals/development.md
+[29]: https://github.com/gavinhoward/bc
diff --git a/configure.sh b/configure.sh
index fc66ffc51066..5dc4853fbb47 100755
--- a/configure.sh
+++ b/configure.sh
@@ -52,12 +52,13 @@ usage() {
printf 'usage:\n'
printf ' %s -h\n' "$script"
printf ' %s --help\n' "$script"
- printf ' %s [-a|-bD|-dB|-c] [-CEfgGHlmMNtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
+ printf ' %s [-a|-bD|-dB|-c] [-CeEfgGHlmMNrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
printf ' [-s SETTING] [-S SETTING]\n'
printf ' %s \\\n' "$script"
printf ' [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage] \\\n'
printf ' [--force --debug --disable-extra-math --disable-generated-tests] \\\n'
printf ' [--disable-history --disable-man-pages --disable-nls --disable-strip] \\\n'
+ printf ' [--enable-editline] [--enable-readline] \\\n'
printf ' [--install-all-locales] [--opt=OPT_LEVEL] \\\n'
printf ' [--karatsuba-len=KARATSUBA_LEN] \\\n'
printf ' [--set-default-on=SETTING] [--set-default-off=SETTING] \\\n'
@@ -87,6 +88,11 @@ usage() {
printf ' -D, --disable-dc\n'
printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
printf ' are specified too.\n'
+ printf ' -e, --enable-editline\n'
+ printf ' Enable the use of libedit/editline. This is meant for those users that\n'
+ printf ' want vi-like or Emacs-like behavior in history.This option is ignored if\n'
+ printf ' history is disabled. It is an error if this option is enabled when the\n'
+ printf ' -r/--enable-readline option is enabled.\n'
printf ' -E, --disable-extra-math\n'
printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
@@ -125,6 +131,11 @@ usage() {
printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
printf ' but it is provided, so maintainers can build optimized debug builds.\n'
printf ' This is passed through to the compiler, so it must be supported.\n'
+ printf ' -r, --enable-readline\n'
+ printf ' Enable the use of libreadline/readline. This is meant for those users\n'
+ printf ' that want vi-like or Emacs-like behavior in history.This option is\n'
+ printf ' ignored if history is disabled. It is an error if this option is\n'
+ printf ' enabled when the -e/--enable-editline option is enabled.\n'
printf ' -s SETTING, --set-default-on SETTING\n'
printf ' Set the default named by SETTING to on. See below for possible values\n'
printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
@@ -233,11 +244,10 @@ usage() {
printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
printf ' removes the need to compile and run an executable on the host\n'
printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
- printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
- printf ' supported length of a string literal in C99 (and it could be\n'
- printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
- printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
- printf ' production-ready compilers, this limit probably is not\n'
+ printf ' `gen/lib2.bc` is over 4095 characters, the max supported length\n'
+ printf ' of a string literal in C99, and `gen/strgen.sh` generates a\n'
+ printf ' string literal instead of an array, as `gen/strgen.c` does. For\n'
+ printf ' most production-ready compilers, this limit probably is not\n'
printf ' enforced, but it could be. Both options are still available for\n'
printf ' this reason. If you are sure your compiler does not have the\n'
printf ' limit and do not want to compile and run a binary on the host\n'
@@ -667,6 +677,8 @@ coverage=0
karatsuba_len=32
debug=0
hist=1
+editline=0
+readline=0
extra_math=1
optimization=""
generate_tests=1
@@ -697,7 +709,7 @@ dc_default_expr_exit=1
# getopts is a POSIX utility, but it cannot handle long options. Thus, the
# handling of long options is done by hand, and that's the reason that short and
# long options cannot be mixed.
-while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
+while getopts "abBcdDeEfgGhHk:lMmNO:rS:s:tTvz-" opt; do
case "$opt" in
a) library=1 ;;
@@ -707,6 +719,7 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
C) clean=0 ;;
d) dc_only=1 ;;
D) bc_only=1 ;;
+ e) editline=1 ;;
E) extra_math=0 ;;
f) force=1 ;;
g) debug=1 ;;
@@ -719,6 +732,7 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
M) install_manpages=0 ;;
N) nls=0 ;;
O) optimization="$OPTARG" ;;
+ r) readline=1 ;;
S) set_default 0 "$OPTARG" ;;
s) set_default 1 "$OPTARG" ;;
t) time_tests=1 ;;
@@ -844,6 +858,8 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
disable-man-pages) install_manpages=0 ;;
disable-nls) nls=0 ;;
disable-strip) strip_bin=0 ;;
+ enable-editline) editline=1 ;;
+ enable-readline) readline=1 ;;
enable-test-timing) time_tests=1 ;;
enable-valgrind) vg=1 ;;
enable-fuzz-mode) fuzz=1 ;;
@@ -863,6 +879,8 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
usage "No arg allowed for --$arg option" ;;
enable-memcheck* | install-all-locales*)
usage "No arg allowed for --$arg option" ;;
+ enable-editline* | enable-readline*)
+ usage "No arg allowed for --$arg option" ;;
'') break ;; # "--" terminates argument processing
* ) usage "Invalid option $LONG_OPTARG" ;;
esac
@@ -1333,12 +1351,17 @@ fi
# Like the above tested locale support, this tests history.
if [ "$hist" -eq 1 ]; then
+ if [ "$editline" -ne 0 ] && [ "$readline" -ne 0 ]; then
+ usage "Must only enable one of readline or editline"
+ fi
+
set +e
printf 'Testing history...\n'
flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
+ flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline"
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
@@ -1366,13 +1389,56 @@ if [ "$hist" -eq 1 ]; then
fi
-# We have to disable the history tests if it is disabled or valgrind is on.
+# We have to disable the history tests if it is disabled or valgrind is on. Or
+# if we are using editline or readline.
if [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then
test_bc_history_prereqs=" test_bc_history_skip"
test_dc_history_prereqs=" test_dc_history_skip"
history_tests="@printf 'Skipping history tests...\\\\n'"
+ CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
+else
+
+ if [ "$editline" -eq 0 ] && [ "$readline" -eq 0 ]; then
+ history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n'"
+ history_tests="$history_tests \&\& \$(TESTSDIR)/history.sh bc -a \&\&"
+ history_tests="$history_tests \$(TESTSDIR)/history.sh dc -a \&\& printf"
+ history_tests="$history_tests '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
+ else
+ test_bc_history_prereqs=" test_bc_history_skip"
+ test_dc_history_prereqs=" test_dc_history_skip"
+ history_tests="@printf 'Skipping history tests...\\\\n'"
+ fi
+
+ # We are also setting the CFLAGS and LDFLAGS here.
+ if [ "$editline" -ne 0 ]; then
+ LDFLAGS="$LDFLAGS -ledit"
+ CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=1 -DBC_ENABLE_READLINE=0"
+ elif [ "$readline" -ne 0 ]; then
+ LDFLAGS="$LDFLAGS -lreadline"
+ CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=1"
+ else
+ CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
+ fi
+
+fi
+
+# Test FreeBSD. This is not in an if statement because regardless of whatever
+# the user says, we need to know if we are on FreeBSD. If we are, we cannot set
+# _POSIX_C_SOURCE and _XOPEN_SOURCE. The FreeBSD headers turn *off* stuff when
+# that is done.
+set +e
+printf 'Testing for FreeBSD...\n'
+
+flags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0"
+"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/include/status.h" > /dev/null 2>&1
+
+err="$?"
+
+if [ "$err" -ne 0 ]; then
+ printf 'On FreeBSD. Not using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
else
- history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n' \&\& \$(TESTSDIR)/history.sh bc -a \&\& \$(TESTSDIR)/history.sh dc -a \&\& printf '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
+ printf 'Not on FreeBSD. Using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
+ CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
fi
# Test OpenBSD. This is not in an if statement because regardless of whatever
@@ -1431,9 +1497,11 @@ headers="\$(HEADERS)"
# This series of if statements figure out what source files are *not* needed.
if [ "$extra_math" -eq 0 ]; then
+ exclude_extra_math=1
manpage_args="E"
unneeded="$unneeded rand.c"
else
+ exclude_extra_math=0
headers="$headers \$(EXTRA_MATH_HEADERS)"
fi
@@ -1645,6 +1713,7 @@ contents=$(replace "$contents" "DC_ERROR_TESTS" "$dc_err_tests")
contents=$(replace "$contents" "DC_TEST_EXEC" "$dc_test_exec")
contents=$(replace "$contents" "BUILD_TYPE" "$manpage_args")
+contents=$(replace "$contents" "EXCLUDE_EXTRA_MATH" "$exclude_extra_math")
contents=$(replace "$contents" "LIBRARY" "$library")
contents=$(replace "$contents" "HISTORY" "$hist")
diff --git a/gen/bc_help.txt b/gen/bc_help.txt
index 36329b1d7aaf..7189d5bae723 100644
--- a/gen/bc_help.txt
+++ b/gen/bc_help.txt
@@ -62,6 +62,14 @@ This bc has three differences to the GNU bc:
This bc also implements the dot (.) extension of the BSD bc.
Options:
+{{ A H N HN }}
+
+ -E seed --seed=seed
+
+ Sets the builtin variable seed to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+{{ end }}
-e expr --expression=expr
@@ -82,6 +90,12 @@ Options:
Print this usage message and exit.
+ -I ibase --ibase=ibase
+
+ Sets the builtin variable ibase to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-i --interactive
Force interactive mode.
@@ -104,6 +118,12 @@ Options:
This bc may load more functions with these options. See the manpage or
online documentation for details.
+ -O obase --obase=obase
+
+ Sets the builtin variable obase to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-P --no-prompt
Disable the prompts in interactive mode.
@@ -127,6 +147,12 @@ Options:
Don't print version and copyright.
+ -S scale --scale=scale
+
+ Sets the builtin variable scale to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-s --standard
Error if any non-POSIX extensions are used.
diff --git a/gen/dc_help.txt b/gen/dc_help.txt
index a0f275b60b64..05a9a68fafc1 100644
--- a/gen/dc_help.txt
+++ b/gen/dc_help.txt
@@ -71,6 +71,14 @@ This dc has a few differences from the two above:
that requires a register name is taken as the register name.
Options:
+{{ A H N HN }}
+
+ -E seed --seed=seed
+
+ Sets the builtin variable seed to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+{{ end }}
-e expr --expression=expr
@@ -85,6 +93,12 @@ Options:
Print this usage message and exit.
+ -I ibase --ibase=ibase
+
+ Sets the builtin variable ibase to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-i --interactive
Put dc into interactive mode. See the man page for more details.
@@ -93,6 +107,12 @@ Options:
Disable line length checking.
+ -O obase --obase=obase
+
+ Sets the builtin variable obase to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-P --no-prompt
Disable the prompts in interactive mode.
@@ -101,6 +121,12 @@ Options:
Disable the read prompt in interactive mode.
+ -S scale --scale=scale
+
+ Sets the builtin variable scale to the given value assuming that the given
+ value is in base 10. It is a fatal error if the given value is not a valid
+ number.
+
-V --version
Print version and copyright and exit.
diff --git a/gen/strgen.c b/gen/strgen.c
index 63faf1ec3472..f4d01ca1391e 100644
--- a/gen/strgen.c
+++ b/gen/strgen.c
@@ -33,6 +33,7 @@
*
*/
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -40,17 +41,39 @@
#include <errno.h>
-// For some reason, Windows needs this header.
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#ifndef _WIN32
+#include <unistd.h>
+#endif // _WIN32
+
+// For some reason, Windows can't have this header.
#ifndef _WIN32
#include <libgen.h>
#endif // _WIN32
+// This pulls in cross-platform stuff.
+#include "../include/bcl.h"
+
+#define BC_ERR(v) (v)
+
+// clang-format off
+
+// The usage help.
+static const char* const bc_gen_usage =
+ "usage: %s input output exclude name [label [define [remove_tabs]]]\n";
+
+static const char* const bc_gen_ex_start = "{{ A H N HN }}";
+static const char* const bc_gen_ex_end = "{{ end }}";
+
// This is exactly what it looks like. It just slaps a simple license header on
// the generated C source file.
static const char* const bc_gen_header =
"// Copyright (c) 2018-2021 Gavin D. Howard and contributors.\n"
"// Licensed under the 2-clause BSD license.\n"
"// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n\n";
+// clang-format on
// These are just format strings used to generate the C source.
static const char* const bc_gen_label = "const char *%s = \"%s\";\n\n";
@@ -77,8 +100,9 @@ static const char* const bc_gen_name_extern = "extern const char %s[];\n\n";
* @param filename The name of the file.
* @param mode The mode to open the file in.
*/
-static void open_file(FILE** f, const char* filename, const char* mode) {
-
+static void
+open_file(FILE** f, const char* filename, const char* mode)
+{
#ifndef _WIN32
*f = fopen(filename, mode);
@@ -94,6 +118,108 @@ static void open_file(FILE** f, const char* filename, const char* mode) {
}
/**
+ * A portability file open function. This is copied from src/read.c. Make sure
+ * to update that if this changes.
+ * @param path The path to the file to open.
+ * @param mode The mode to open in.
+ */
+static int
+bc_read_open(const char* path, int mode)
+{
+ int fd;
+
+#ifndef _WIN32
+ fd = open(path, mode);
+#else // _WIN32
+ fd = -1;
+ open(&fd, path, mode);
+#endif
+
+ return fd;
+}
+
+/**
+ * Reads a file and returns the file as a string. This has been copied from
+ * src/read.c. Make sure to change that if this changes.
+ * @param path The path to the file.
+ * @return The contents of the file as a string.
+ */
+static char*
+bc_read_file(const char* path)
+{
+ int e = IO_ERR;
+ size_t size, to_read;
+ struct stat pstat;
+ int fd;
+ char* buf;
+ char* buf2;
+
+ // This has been copied from src/read.c. Make sure to change that if this
+ // changes.
+
+ assert(path != NULL);
+
+#ifndef NDEBUG
+ // Need this to quiet MSan.
+ // NOLINTNEXTLINE
+ memset(&pstat, 0, sizeof(struct stat));
+#endif // NDEBUG
+
+ fd = bc_read_open(path, O_RDONLY);
+
+ // If we can't read a file, we just barf.
+ if (BC_ERR(fd < 0))
+ {
+ fprintf(stderr, "Could not open file: %s\n", path);
+ exit(INVALID_INPUT_FILE);
+ }
+
+ // The reason we call fstat is to eliminate TOCTOU race conditions. This
+ // way, we have an open file, so it's not going anywhere.
+ if (BC_ERR(fstat(fd, &pstat) == -1))
+ {
+ fprintf(stderr, "Could not stat file: %s\n", path);
+ exit(INVALID_INPUT_FILE);
+ }
+
+ // Make sure it's not a directory.
+ if (BC_ERR(S_ISDIR(pstat.st_mode)))
+ {
+ fprintf(stderr, "Path is directory: %s\n", path);
+ exit(INVALID_INPUT_FILE);
+ }
+
+ // Get the size of the file and allocate that much.
+ size = (size_t) pstat.st_size;
+ buf = (char*) malloc(size + 1);
+ if (buf == NULL)
+ {
+ fprintf(stderr, "Could not malloc\n");
+ exit(INVALID_INPUT_FILE);
+ }
+ buf2 = buf;
+ to_read = size;
+
+ do
+ {
+ // Read the file. We just bail if a signal interrupts. This is so that
+ // users can interrupt the reading of big files if they want.
+ ssize_t r = read(fd, buf2, to_read);
+ if (BC_ERR(r < 0)) exit(e);
+ to_read -= (size_t) r;
+ buf2 += (size_t) r;
+ }
+ while (to_read);
+
+ // Got to have a nul byte.
+ buf[size] = '\0';
+
+ close(fd);
+
+ return buf;
+}
+
+/**
* Outputs a label, which is a string literal that the code can use as a name
* for the file that is being turned into a string. This is important for the
* math libraries because the parse and lex code expects a filename. The label
@@ -112,8 +238,9 @@ static void open_file(FILE** f, const char* filename, const char* mode) {
* @param name The actual label text, which is a filename.
* @return Positive if no error, negative on error, just like *printf().
*/
-static int output_label(FILE* out, const char* label, const char* name) {
-
+static int
+output_label(FILE* out, const char* label, const char* name)
+{
#ifndef _WIN32
return fprintf(out, bc_gen_label, label, name);
@@ -125,7 +252,10 @@ static int output_label(FILE* out, const char* label, const char* name) {
int ret;
// This loop counts how many backslashes there are in the label.
- for (i = 0; i < len; ++i) count += (name[i] == '\\');
+ for (i = 0; i < len; ++i)
+ {
+ count += (name[i] == '\\');
+ }
buf = (char*) malloc(len + 1 + count);
if (buf == NULL) return -1;
@@ -136,11 +266,12 @@ static int output_label(FILE* out, const char* label, const char* name) {
// label byte-for-byte, unless it encounters a backslash, in which case, it
// copies the backslash twice to have it escaped properly in the string
// literal.
- for (i = 0; i < len; ++i) {
-
+ for (i = 0; i < len; ++i)
+ {
buf[i + count] = name[i];
- if (name[i] == '\\') {
+ if (name[i] == '\\')
+ {
count += 1;
buf[i + count] = name[i];
}
@@ -178,9 +309,10 @@ static int output_label(FILE* out, const char* label, const char* name) {
*
* The required command-line parameters are:
*
- * input Input filename.
- * output Output filename.
- * name The name of the char array.
+ * input Input filename.
+ * output Output filename.
+ * exclude Whether to exclude extra math-only stuff.
+ * name The name of the char array.
*
* The optional parameters are:
*
@@ -202,34 +334,41 @@ static int output_label(FILE* out, const char* label, const char* name) {
* All text files that are transformed have license comments. This program finds
* the end of that comment and strips it out as well.
*/
-int main(int argc, char *argv[]) {
-
- FILE *in, *out;
- char *label, *define, *name;
- int c, count, slashes, err = IO_ERR;
- bool has_label, has_define, remove_tabs;
-
- if (argc < 4) {
- printf("usage: %s input output name [label [define [remove_tabs]]]\n",
- argv[0]);
+int
+main(int argc, char* argv[])
+{
+ char* in;
+ FILE* out;
+ const char* label;
+ const char* define;
+ char* name;
+ unsigned int count, slashes, err = IO_ERR;
+ bool has_label, has_define, remove_tabs, exclude_extra_math;
+ size_t i;
+
+ if (argc < 5)
+ {
+ printf(bc_gen_usage, argv[0]);
return INVALID_PARAMS;
}
- name = argv[3];
+ exclude_extra_math = (strtoul(argv[3], NULL, 10) != 0);
- has_label = (argc > 4 && strcmp("", argv[4]) != 0);
- label = has_label ? argv[4] : "";
+ name = argv[4];
- has_define = (argc > 5 && strcmp("", argv[5]) != 0);
- define = has_define ? argv[5] : "";
+ has_label = (argc > 5 && strcmp("", argv[5]) != 0);
+ label = has_label ? argv[5] : "";
- remove_tabs = (argc > 6);
+ has_define = (argc > 6 && strcmp("", argv[6]) != 0);
+ define = has_define ? argv[6] : "";
- open_file(&in, argv[1], "r");
- if (!in) return INVALID_INPUT_FILE;
+ remove_tabs = (argc > 7);
+
+ in = bc_read_file(argv[1]);
+ if (in == NULL) return INVALID_INPUT_FILE;
open_file(&out, argv[2], "w");
- if (!out) goto out_err;
+ if (out == NULL) goto out_err;
if (fprintf(out, bc_gen_header, argv[1]) < 0) goto err;
if (has_label && fprintf(out, bc_gen_label_extern, label) < 0) goto err;
@@ -238,46 +377,121 @@ int main(int argc, char *argv[]) {
if (has_label && output_label(out, label, argv[1]) < 0) goto err;
if (fprintf(out, bc_gen_name, name) < 0) goto err;
- c = count = slashes = 0;
+ i = count = slashes = 0;
// This is where the end of the license comment is found.
- while (slashes < 2 && (c = fgetc(in)) >= 0) {
- slashes += (slashes == 1 && c == '/' && fgetc(in) == '\n');
- slashes += (!slashes && c == '/' && fgetc(in) == '*');
+ while (slashes < 2 && in[i] > 0)
+ {
+ if (slashes == 1 && in[i] == '*' && in[i + 1] == '/' &&
+ (in[i + 2] == '\n' || in[i + 2] == '\r'))
+ {
+ slashes += 1;
+ i += 2;
+ }
+ else if (!slashes && in[i] == '/' && in[i + 1] == '*')
+ {
+ slashes += 1;
+ i += 1;
+ }
+
+ i += 1;
}
// The file is invalid if the end of the license comment could not be found.
- if (c < 0) {
+ if (in[i] == 0)
+ {
+ fprintf(stderr, "Could not find end of license comment\n");
err = INVALID_INPUT_FILE;
goto err;
}
+ i += 1;
+
// Do not put extra newlines at the beginning of the char array.
- while ((c = fgetc(in)) == '\n');
+ while (in[i] == '\n' || in[i] == '\r')
+ {
+ i += 1;
+ }
// This loop is what generates the actual char array. It counts how many
// chars it has printed per line in order to insert newlines at appropriate
// places. It also skips tabs if they should be removed.
- while (c >= 0) {
-
+ while (in[i] != 0)
+ {
int val;
- if (!remove_tabs || c != '\t') {
+ if (in[i] == '\r')
+ {
+ i += 1;
+ continue;
+ }
+
+ if (!remove_tabs || in[i] != '\t')
+ {
+ // Check for excluding something for extra math.
+ if (in[i] == '{')
+ {
+ // If we found the start...
+ if (!strncmp(in + i, bc_gen_ex_start, strlen(bc_gen_ex_start)))
+ {
+ if (exclude_extra_math)
+ {
+ // Get past the braces.
+ i += 2;
+
+ // Find the end of the end.
+ while (in[i] != '{' && strncmp(in + i, bc_gen_ex_end,
+ strlen(bc_gen_ex_end)))
+ {
+ i += 1;
+ }
+
+ i += strlen(bc_gen_ex_end);
+
+ // Skip the last newline.
+ if (in[i] == '\r') i += 1;
+ i += 1;
+ continue;
+ }
+ else
+ {
+ i += strlen(bc_gen_ex_start);
+
+ // Skip the last newline.
+ if (in[i] == '\r') i += 1;
+ i += 1;
+ continue;
+ }
+ }
+ else if (!exclude_extra_math &&
+ !strncmp(in + i, bc_gen_ex_end, strlen(bc_gen_ex_end)))
+ {
+ i += strlen(bc_gen_ex_end);
+
+ // Skip the last newline.
+ if (in[i] == '\r') i += 1;
+ i += 1;
+ continue;
+ }
+ }
+ // Print a tab if we are at the beginning of a line.
if (!count && fputc('\t', out) == EOF) goto err;
- val = fprintf(out, "%d,", c);
+ // Print the character.
+ val = fprintf(out, "%d,", in[i]);
if (val < 0) goto err;
- count += val;
-
- if (count > MAX_WIDTH) {
+ // Adjust the count.
+ count += (unsigned int) val;
+ if (count > MAX_WIDTH)
+ {
count = 0;
if (fputc('\n', out) == EOF) goto err;
}
}
- c = fgetc(in);
+ i += 1;
}
// Make sure the end looks nice and insert the NUL byte at the end.
@@ -289,6 +503,6 @@ int main(int argc, char *argv[]) {
err:
fclose(out);
out_err:
- fclose(in);
- return err;
+ free(in);
+ return (int) err;
}
diff --git a/gen/strgen.sh b/gen/strgen.sh
index acaa6cdf0791..2b41da4a4a48 100755
--- a/gen/strgen.sh
+++ b/gen/strgen.sh
@@ -32,20 +32,33 @@ export LC_CTYPE=C
progname=${0##*/}
+script="$0"
+scriptdir=$(dirname "$script")
+. "$scriptdir/../scripts/functions.sh"
+
# See strgen.c comment on main() for what these mean. Note, however, that this
# script generates a string literal, not a char array. To understand the
# consequences of that, see manuals/development.md#strgenc.
if [ $# -lt 3 ]; then
- echo "usage: $progname input output name [label [define [remove_tabs]]]"
+ echo "usage: $progname input output exclude name [label [define [remove_tabs]]]"
exit 1
fi
input="$1"
output="$2"
-name="$3"
-label="$4"
-define="$5"
-remove_tabs="$6"
+exclude="$3"
+name="$4"
+label="$5"
+define="$6"
+remove_tabs="$7"
+
+if [ "$exclude" -ne 0 ]; then
+ filter_text "$input" "$input.tmp" "E"
+else
+ filter_text "$input" "$input.tmp" "A"
+fi
+
+input="$input.tmp"
exec < "$input"
exec > "$output"
@@ -83,3 +96,7 @@ $(sed -e "$remtabsexpr " -e '1,/^$/d; s:\\n:\\\\n:g; s:":\\":g; s:^:":; s:$:\\n"
;
${condend}
EOF
+
+#if [ "$exclude" -ne 0 ]; then
+ #rm -rf "$input"
+#fi
diff --git a/include/args.h b/include/args.h
index a2f5b416ce9b..cf6bcbef621c 100644
--- a/include/args.h
+++ b/include/args.h
@@ -46,8 +46,10 @@
* @param argv The array of arguments.
* @param exit_exprs True if bc/dc should exit when there are expressions,
* false otherwise.
+ * @param scale The current scale.
*/
-void bc_args(int argc, char *argv[], bool exit_exprs);
+void
+bc_args(int argc, char* argv[], bool exit_exprs, BcBigDig scale);
// A reference to the list of long options.
extern const BcOptLong bc_args_lopt[];
diff --git a/include/bc.h b/include/bc.h
index a4198b91ebc6..06b2131c967b 100644
--- a/include/bc.h
+++ b/include/bc.h
@@ -49,7 +49,8 @@
* The main function for bc. It just sets variables and passes its arguments
* through to @a bc_vm_boot().
*/
-void bc_main(int argc, char *argv[]);
+void
+bc_main(int argc, char* argv[]);
// These are references to the help text, the library text, and the "filename"
// for the library.
@@ -66,8 +67,8 @@ extern const char* bc_lib2_name;
/**
* A struct containing information about a bc keyword.
*/
-typedef struct BcLexKeyword {
-
+typedef struct BcLexKeyword
+{
/// Holds the length of the keyword along with a bit that, if set, means the
/// keyword is used in POSIX bc.
uchar data;
@@ -87,8 +88,10 @@ typedef struct BcLexKeyword {
#define BC_LEX_KW_LEN(kw) ((size_t) ((kw)->data & ~(BC_LEX_CHAR_MSB(1))))
/// A macro to easily build a keyword entry. See bc_lex_kws in src/data.c.
-#define BC_LEX_KW_ENTRY(a, b, c) \
- { .data = ((b) & ~(BC_LEX_CHAR_MSB(1))) | BC_LEX_CHAR_MSB(c), .name = a }
+#define BC_LEX_KW_ENTRY(a, b, c) \
+ { \
+ .data = ((b) & ~(BC_LEX_CHAR_MSB(1))) | BC_LEX_CHAR_MSB(c), .name = a \
+ }
#if BC_ENABLE_EXTRA_MATH
@@ -113,7 +116,8 @@ extern const size_t bc_lex_kws_len;
* @a BcLexNext.)
* @param l The lexer.
*/
-void bc_lex_token(BcLex *l);
+void
+bc_lex_token(BcLex* l);
// The following section is for flags needed when parsing bc code. These flags
// are complicated, but necessary. Why you ask? Because bc's standard is awful.
@@ -144,49 +148,49 @@ void bc_lex_token(BcLex *l);
// flag stack. All `p` arguments are pointers to a BcParse.
// This flag is set if the parser has seen a left brace.
-#define BC_PARSE_FLAG_BRACE (UINTMAX_C(1)<<0)
+#define BC_PARSE_FLAG_BRACE (UINTMAX_C(1) << 0)
#define BC_PARSE_BRACE(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_BRACE)
// This flag is set if the parser is parsing inside of the braces of a function
// body.
-#define BC_PARSE_FLAG_FUNC_INNER (UINTMAX_C(1)<<1)
+#define BC_PARSE_FLAG_FUNC_INNER (UINTMAX_C(1) << 1)
#define BC_PARSE_FUNC_INNER(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_FUNC_INNER)
// This flag is set if the parser is parsing a function. It is different from
// the one above because it is set if it is parsing a function body *or* header,
// not just if it's parsing a function body.
-#define BC_PARSE_FLAG_FUNC (UINTMAX_C(1)<<2)
+#define BC_PARSE_FLAG_FUNC (UINTMAX_C(1) << 2)
#define BC_PARSE_FUNC(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_FUNC)
// This flag is set if the parser is expecting to parse a body, whether of a
// function, an if statement, or a loop.
-#define BC_PARSE_FLAG_BODY (UINTMAX_C(1)<<3)
+#define BC_PARSE_FLAG_BODY (UINTMAX_C(1) << 3)
#define BC_PARSE_BODY(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_BODY)
// This flag is set if bc is parsing a loop. This is important because the break
// and continue keywords are only valid inside of a loop.
-#define BC_PARSE_FLAG_LOOP (UINTMAX_C(1)<<4)
+#define BC_PARSE_FLAG_LOOP (UINTMAX_C(1) << 4)
#define BC_PARSE_LOOP(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_LOOP)
// This flag is set if bc is parsing the body of a loop. It is different from
// the one above the same way @a BC_PARSE_FLAG_FUNC_INNER is different from
// @a BC_PARSE_FLAG_FUNC.
-#define BC_PARSE_FLAG_LOOP_INNER (UINTMAX_C(1)<<5)
+#define BC_PARSE_FLAG_LOOP_INNER (UINTMAX_C(1) << 5)
#define BC_PARSE_LOOP_INNER(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_LOOP_INNER)
// This flag is set if bc is parsing an if statement.
-#define BC_PARSE_FLAG_IF (UINTMAX_C(1)<<6)
+#define BC_PARSE_FLAG_IF (UINTMAX_C(1) << 6)
#define BC_PARSE_IF(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_IF)
// This flag is set if bc is parsing an else statement. This is important
// because of "else if" constructions, among other things.
-#define BC_PARSE_FLAG_ELSE (UINTMAX_C(1)<<7)
+#define BC_PARSE_FLAG_ELSE (UINTMAX_C(1) << 7)
#define BC_PARSE_ELSE(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_ELSE)
// This flag is set if bc just finished parsing an if statement and its body.
// It tells the parser that it can probably expect an else statement next. This
// flag is, thus, one of the most subtle.
-#define BC_PARSE_FLAG_IF_END (UINTMAX_C(1)<<8)
+#define BC_PARSE_FLAG_IF_END (UINTMAX_C(1) << 8)
#define BC_PARSE_IF_END(p) (BC_PARSE_TOP_FLAG(p) & BC_PARSE_FLAG_IF_END)
/**
@@ -230,7 +234,7 @@ void bc_lex_token(BcLex *l);
* @param t The token to return operator data for.
* @return The operator data for @a t.
*/
-#define BC_PARSE_OP_DATA(t) bc_parse_ops[((t) - BC_LEX_OP_INC)]
+#define BC_PARSE_OP_DATA(t) bc_parse_ops[((t) -BC_LEX_OP_INC)]
/**
* Returns non-zero if operator @a op is left associative, zero otherwise.
@@ -261,7 +265,7 @@ void bc_lex_token(BcLex *l);
* @param e8 The eighth bit.
* @return An expression entry for bc_parse_exprs[].
*/
-#define BC_PARSE_EXPR_ENTRY(e1, e2, e3, e4, e5, e6, e7, e8) \
+#define BC_PARSE_EXPR_ENTRY(e1, e2, e3, e4, e5, e6, e7, e8) \
((UINTMAX_C(e1) << 7) | (UINTMAX_C(e2) << 6) | (UINTMAX_C(e3) << 5) | \
(UINTMAX_C(e4) << 4) | (UINTMAX_C(e5) << 3) | (UINTMAX_C(e6) << 2) | \
(UINTMAX_C(e7) << 1) | (UINTMAX_C(e8) << 0))
@@ -272,7 +276,7 @@ void bc_lex_token(BcLex *l);
* @return True if i is an expression token, false otherwise.
*/
#define BC_PARSE_EXPR(i) \
- (bc_parse_exprs[(((i) & (uchar) ~(0x07)) >> 3)] & (1 << (7 - ((i) & 0x07))))
+ (bc_parse_exprs[(((i) & (uchar) ~(0x07)) >> 3)] & (1 << (7 - ((i) &0x07))))
/**
* Returns the operator (by lex token) that is at the top of the operator
@@ -337,7 +341,7 @@ void bc_lex_token(BcLex *l);
* @param t The token to turn into an instruction.
* @return The token as an instruction.
*/
-#define BC_PARSE_TOKEN_INST(t) ((uchar) ((t) - BC_LEX_NEG + BC_INST_NEG))
+#define BC_PARSE_TOKEN_INST(t) ((uchar) ((t) -BC_LEX_NEG + BC_INST_NEG))
/**
* Returns true if the token is a bc keyword.
@@ -353,8 +357,8 @@ void bc_lex_token(BcLex *l);
///
/// Obviously, @a len is the number of tokens in the @a tokens array. If more
/// than 4 is needed in the future, @a tokens will have to be changed.
-typedef struct BcParseNext {
-
+typedef struct BcParseNext
+{
/// The number of tokens in the tokens array.
uchar len;
@@ -368,13 +372,15 @@ typedef struct BcParseNext {
/// A macro to generate a BcParseNext literal from BcParseNext data. See
/// src/data.c for examples.
-#define BC_PARSE_NEXT(a, ...) \
- { .len = (uchar) (a), BC_PARSE_NEXT_TOKENS(__VA_ARGS__) }
+#define BC_PARSE_NEXT(a, ...) \
+ { \
+ .len = (uchar) (a), BC_PARSE_NEXT_TOKENS(__VA_ARGS__) \
+ }
/// A status returned by @a bc_parse_expr_err(). It can either return success or
/// an error indicating an empty expression.
-typedef enum BcParseStatus {
-
+typedef enum BcParseStatus
+{
BC_PARSE_STATUS_SUCCESS,
BC_PARSE_STATUS_EMPTY_EXPR,
@@ -387,14 +393,16 @@ typedef enum BcParseStatus {
* @param flags Flags that define the requirements that the parsed code must
* meet or an error will result. See @a BcParseExpr for more info.
*/
-void bc_parse_expr(BcParse *p, uint8_t flags);
+void
+bc_parse_expr(BcParse* p, uint8_t flags);
/**
* The @a BcParseParse function for bc. (See include/parse.h for a definition of
* @a BcParseParse.)
* @param p The parser.
*/
-void bc_parse_parse(BcParse *p);
+void
+bc_parse_parse(BcParse* p);
/**
* Ends a series of if statements. This is to ensure that full parses happen
@@ -403,7 +411,8 @@ void bc_parse_parse(BcParse *p);
* function definition, we know we can add an empty else clause.
* @param p The parser.
*/
-void bc_parse_endif(BcParse *p);
+void
+bc_parse_endif(BcParse* p);
/// References to the signal message and its length.
extern const char bc_sig_msg[];
diff --git a/include/bcl.h b/include/bcl.h
index 9c0e5e59cfd0..54be3239d241 100644
--- a/include/bcl.h
+++ b/include/bcl.h
@@ -73,7 +73,7 @@
#define STDOUT_FILENO _fileno(stdout)
#define STDERR_FILENO _fileno(stderr)
#define ssize_t SSIZE_T
-#define S_ISDIR(m) ((m) & _S_IFDIR)
+#define S_ISDIR(m) ((m) & (_S_IFDIR))
#define O_RDONLY _O_RDONLY
#define stat _stat
#define fstat _fstat
@@ -129,8 +129,8 @@ typedef uint32_t BclRandInt;
#if BC_ENABLE_LIBRARY
-typedef enum BclError {
-
+typedef enum BclError
+{
BCL_ERROR_NONE,
BCL_ERROR_INVALID_NUM,
@@ -151,8 +151,8 @@ typedef enum BclError {
} BclError;
-typedef struct BclNumber {
-
+typedef struct BclNumber
+{
size_t i;
} BclNumber;
@@ -161,81 +161,179 @@ struct BclCtxt;
typedef struct BclCtxt* BclContext;
-void bcl_handleSignal(void);
-bool bcl_running(void);
-
-BclError bcl_init(void);
-void bcl_free(void);
-
-bool bcl_abortOnFatalError(void);
-void bcl_setAbortOnFatalError(bool abrt);
-bool bcl_leadingZeroes(void);
-void bcl_setLeadingZeroes(bool leadingZeroes);
-
-void bcl_gc(void);
-
-BclError bcl_pushContext(BclContext ctxt);
-void bcl_popContext(void);
-BclContext bcl_context(void);
-
-BclContext bcl_ctxt_create(void);
-void bcl_ctxt_free(BclContext ctxt);
-void bcl_ctxt_freeNums(BclContext ctxt);
-
-size_t bcl_ctxt_scale(BclContext ctxt);
-void bcl_ctxt_setScale(BclContext ctxt, size_t scale);
-size_t bcl_ctxt_ibase(BclContext ctxt);
-void bcl_ctxt_setIbase(BclContext ctxt, size_t ibase);
-size_t bcl_ctxt_obase(BclContext ctxt);
-void bcl_ctxt_setObase(BclContext ctxt, size_t obase);
-
-BclError bcl_err(BclNumber n);
-
-BclNumber bcl_num_create(void);
-void bcl_num_free(BclNumber n);
-
-bool bcl_num_neg(BclNumber n);
-void bcl_num_setNeg(BclNumber n, bool neg);
-size_t bcl_num_scale(BclNumber n);
-BclError bcl_num_setScale(BclNumber n, size_t scale);
-size_t bcl_num_len(BclNumber n);
-
-BclError bcl_copy(BclNumber d, BclNumber s);
-BclNumber bcl_dup(BclNumber s);
-
-BclError bcl_bigdig(BclNumber n, BclBigDig *result);
-BclNumber bcl_bigdig2num(BclBigDig val);
-
-BclNumber bcl_add(BclNumber a, BclNumber b);
-BclNumber bcl_sub(BclNumber a, BclNumber b);
-BclNumber bcl_mul(BclNumber a, BclNumber b);
-BclNumber bcl_div(BclNumber a, BclNumber b);
-BclNumber bcl_mod(BclNumber a, BclNumber b);
-BclNumber bcl_pow(BclNumber a, BclNumber b);
-BclNumber bcl_lshift(BclNumber a, BclNumber b);
-BclNumber bcl_rshift(BclNumber a, BclNumber b);
-BclNumber bcl_sqrt(BclNumber a);
-BclError bcl_divmod(BclNumber a, BclNumber b, BclNumber *c, BclNumber *d);
-BclNumber bcl_modexp(BclNumber a, BclNumber b, BclNumber c);
-
-ssize_t bcl_cmp(BclNumber a, BclNumber b);
-
-void bcl_zero(BclNumber n);
-void bcl_one(BclNumber n);
-
-BclNumber bcl_parse(const char *restrict val);
-char* bcl_string(BclNumber n);
-
-BclNumber bcl_irand(BclNumber a);
-BclNumber bcl_frand(size_t places);
-BclNumber bcl_ifrand(BclNumber a, size_t places);
-
-BclError bcl_rand_seedWithNum(BclNumber n);
-BclError bcl_rand_seed(unsigned char seed[BCL_SEED_SIZE]);
-void bcl_rand_reseed(void);
-BclNumber bcl_rand_seed2num(void);
-BclRandInt bcl_rand_int(void);
-BclRandInt bcl_rand_bounded(BclRandInt bound);
+void
+bcl_handleSignal(void);
+
+bool
+bcl_running(void);
+
+BclError
+bcl_init(void);
+
+void
+bcl_free(void);
+
+bool
+bcl_abortOnFatalError(void);
+
+void
+bcl_setAbortOnFatalError(bool abrt);
+
+bool
+bcl_leadingZeroes(void);
+
+void
+bcl_setLeadingZeroes(bool leadingZeroes);
+
+void
+bcl_gc(void);
+
+BclError
+bcl_pushContext(BclContext ctxt);
+
+void
+bcl_popContext(void);
+
+BclContext
+bcl_context(void);
+
+BclContext
+bcl_ctxt_create(void);
+
+void
+bcl_ctxt_free(BclContext ctxt);
+
+void
+bcl_ctxt_freeNums(BclContext ctxt);
+
+size_t
+bcl_ctxt_scale(BclContext ctxt);
+
+void
+bcl_ctxt_setScale(BclContext ctxt, size_t scale);
+
+size_t
+bcl_ctxt_ibase(BclContext ctxt);
+
+void
+bcl_ctxt_setIbase(BclContext ctxt, size_t ibase);
+
+size_t
+bcl_ctxt_obase(BclContext ctxt);
+
+void
+bcl_ctxt_setObase(BclContext ctxt, size_t obase);
+
+BclError
+bcl_err(BclNumber n);
+
+BclNumber
+bcl_num_create(void);
+
+void
+bcl_num_free(BclNumber n);
+
+bool
+bcl_num_neg(BclNumber n);
+
+void
+bcl_num_setNeg(BclNumber n, bool neg);
+
+size_t
+bcl_num_scale(BclNumber n);
+
+BclError
+bcl_num_setScale(BclNumber n, size_t scale);
+
+size_t
+bcl_num_len(BclNumber n);
+
+BclError
+bcl_copy(BclNumber d, BclNumber s);
+
+BclNumber
+bcl_dup(BclNumber s);
+
+BclError
+bcl_bigdig(BclNumber n, BclBigDig* result);
+
+BclNumber
+bcl_bigdig2num(BclBigDig val);
+
+BclNumber
+bcl_add(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_sub(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_mul(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_div(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_mod(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_pow(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_lshift(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_rshift(BclNumber a, BclNumber b);
+
+BclNumber
+bcl_sqrt(BclNumber a);
+
+BclError
+bcl_divmod(BclNumber a, BclNumber b, BclNumber* c, BclNumber* d);
+
+BclNumber
+bcl_modexp(BclNumber a, BclNumber b, BclNumber c);
+
+ssize_t
+bcl_cmp(BclNumber a, BclNumber b);
+
+void
+bcl_zero(BclNumber n);
+
+void
+bcl_one(BclNumber n);
+
+BclNumber
+bcl_parse(const char* restrict val);
+
+char*
+bcl_string(BclNumber n);
+
+BclNumber
+bcl_irand(BclNumber a);
+
+BclNumber
+bcl_frand(size_t places);
+
+BclNumber
+bcl_ifrand(BclNumber a, size_t places);
+
+BclError
+bcl_rand_seedWithNum(BclNumber n);
+
+BclError
+bcl_rand_seed(unsigned char seed[BCL_SEED_SIZE]);
+
+void
+bcl_rand_reseed(void);
+
+BclNumber
+bcl_rand_seed2num(void);
+
+BclRandInt
+bcl_rand_int(void);
+
+BclRandInt
+bcl_rand_bounded(BclRandInt bound);
#endif // BC_ENABLE_LIBRARY
diff --git a/include/dc.h b/include/dc.h
index 88b5e054f878..42cd842b57ce 100644
--- a/include/dc.h
+++ b/include/dc.h
@@ -46,7 +46,8 @@
* The main function for dc. It just sets variables and passes its arguments
* through to @a bc_vm_boot().
*/
-void dc_main(int argc, char *argv[]);
+void
+dc_main(int argc, char* argv[]);
// A reference to the dc help text.
extern const char dc_help[];
@@ -56,7 +57,8 @@ extern const char dc_help[];
* @a BcLexNext.)
* @param l The lexer.
*/
-void dc_lex_token(BcLex *l);
+void
+dc_lex_token(BcLex* l);
/**
* Returns true if the negative char `_` should be treated as a command or not.
@@ -66,7 +68,8 @@ void dc_lex_token(BcLex *l);
* @return True if a negative should be treated as a command, false if it
* should be treated as a negative sign on a number.
*/
-bool dc_lex_negCommand(BcLex *l);
+bool
+dc_lex_negCommand(BcLex* l);
// References to the signal message and its length.
extern const char dc_sig_msg[];
@@ -88,7 +91,8 @@ extern const uint8_t dc_parse_insts[];
* @a BcParseParse.)
* @param p The parser.
*/
-void dc_parse_parse(BcParse *p);
+void
+dc_parse_parse(BcParse* p);
/**
* The @a BcParseExpr function for dc. (See include/parse.h for a definition of
@@ -97,7 +101,8 @@ void dc_parse_parse(BcParse *p);
* @param flags Flags that define the requirements that the parsed code must
* meet or an error will result. See @a BcParseExpr for more info.
*/
-void dc_parse_expr(BcParse *p, uint8_t flags);
+void
+dc_parse_expr(BcParse* p, uint8_t flags);
#endif // DC_ENABLED
diff --git a/include/file.h b/include/file.h
index b30b932c9abb..30a0d9011c00 100644
--- a/include/file.h
+++ b/include/file.h
@@ -38,18 +38,34 @@
#include <stdarg.h>
+#include <history.h>
#include <vector.h>
#define BC_FILE_ULL_LENGTH (21)
+#if BC_ENABLE_LINE_LIB
+
+#include <stdio.h>
+
/// The file struct.
-typedef struct BcFile {
+typedef struct BcFile
+{
+ // The file. This is here simply to make the line lib code as compatible
+ // with the existing code as possible.
+ FILE* f;
+
+} BcFile;
+#else // BC_ENABLE_LINE_LIB
+
+/// The file struct.
+typedef struct BcFile
+{
// The actual file descriptor.
int fd;
// The buffer for the file.
- char *buf;
+ char* buf;
// The length (number of actual chars) in the buffer.
size_t len;
@@ -59,13 +75,15 @@ typedef struct BcFile {
} BcFile;
-#if BC_ENABLE_HISTORY
+#endif // BC_ENABLE_LINE_LIB
+
+#if BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
/// Types of flushing. These are important because of history and printing
/// strings without newlines, something that users could use as their own
/// prompts.
-typedef enum BcFlushType {
-
+typedef enum BcFlushType
+{
/// Do not clear the stored partial line, but don't add to it.
BC_FLUSH_NO_EXTRAS_NO_CLEAR,
@@ -80,10 +98,10 @@ typedef enum BcFlushType {
} BcFlushType;
-#else // BC_ENABLE_HISTORY
+#else // BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
// These make sure that the BcFlushType parameter disappears if history is not
-// used.
+// used, editline is used, or readline is used.
#define bc_file_putchar(f, t, c) bc_file_putchar(f, c)
#define bc_file_flushErr(f, t) bc_file_flushErr(f)
@@ -91,7 +109,19 @@ typedef enum BcFlushType {
#define bc_file_write(f, t, b, n) bc_file_write(f, b, n)
#define bc_file_puts(f, t, s) bc_file_puts(f, s)
-#endif // BC_ENABLE_HISTORY
+#endif // BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
+
+#if BC_ENABLE_LINE_LIB
+
+/**
+ * Initialize a file.
+ * @param f The file to initialize.
+ * @param file The stdio file.
+ */
+void
+bc_file_init(BcFile* f, FILE* file);
+
+#else // BC_ENABLE_LINE_LIB
/**
* Initialize a file.
@@ -100,13 +130,17 @@ typedef enum BcFlushType {
* @param buf The buffer for the file.
* @param cap The capacity of the buffer.
*/
-void bc_file_init(BcFile *f, int fd, char *buf, size_t cap);
+void
+bc_file_init(BcFile* f, int fd, char* buf, size_t cap);
+
+#endif // BC_ENABLE_LINE_LIB
/**
* Frees a file, including flushing it.
* @param f The file to free.
*/
-void bc_file_free(BcFile *f);
+void
+bc_file_free(BcFile* f);
/**
* Print a char into the file.
@@ -114,7 +148,8 @@ void bc_file_free(BcFile *f);
* @param type The flush type.
* @param c The character to write.
*/
-void bc_file_putchar(BcFile *restrict f, BcFlushType type, uchar c);
+void
+bc_file_putchar(BcFile* restrict f, BcFlushType type, uchar c);
/**
* Flush and return an error if it failed. This is meant to be used when needing
@@ -124,14 +159,16 @@ void bc_file_putchar(BcFile *restrict f, BcFlushType type, uchar c);
* @param type The flush type.
* @return A status indicating if an error occurred.
*/
-BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type);
+BcStatus
+bc_file_flushErr(BcFile* restrict f, BcFlushType type);
/**
* Flush and throw an error on failure.
* @param f The file to flush.
* @param type The flush type.
*/
-void bc_file_flush(BcFile *restrict f, BcFlushType type);
+void
+bc_file_flush(BcFile* restrict f, BcFlushType type);
/**
* Write the contents of buf to the file.
@@ -140,22 +177,24 @@ void bc_file_flush(BcFile *restrict f, BcFlushType type);
* @param buf The buffer whose contents will be written to the file.
* @param n The length of buf.
*/
-void bc_file_write(BcFile *restrict f, BcFlushType type,
- const char *buf, size_t n);
+void
+bc_file_write(BcFile* restrict f, BcFlushType type, const char* buf, size_t n);
/**
* Write to the file like fprintf would. This is very rudimentary.
* @param f The file to flush.
* @param fmt The format string.
*/
-void bc_file_printf(BcFile *restrict f, const char *fmt, ...);
+void
+bc_file_printf(BcFile* restrict f, const char* fmt, ...);
/**
* Write to the file like vfprintf would. This is very rudimentary.
* @param f The file to flush.
* @param fmt The format string.
*/
-void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args);
+void
+bc_file_vprintf(BcFile* restrict f, const char* fmt, va_list args);
/**
* Write str to the file.
@@ -163,15 +202,16 @@ void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args);
* @param type The flush type.
* @param str The string to write to the file.
*/
-void bc_file_puts(BcFile *restrict f, BcFlushType type, const char *str);
+void
+bc_file_puts(BcFile* restrict f, BcFlushType type, const char* str);
-#if BC_ENABLE_HISTORY
+#if BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
// Some constant flush types for ease of use.
extern const BcFlushType bc_flush_none;
extern const BcFlushType bc_flush_err;
extern const BcFlushType bc_flush_save;
-#endif // BC_ENABLE_HISTORY
+#endif // BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
#endif // BC_FILE_H
diff --git a/include/history.h b/include/history.h
index 8d9c3417d897..1e9962ded1eb 100644
--- a/include/history.h
+++ b/include/history.h
@@ -83,9 +83,88 @@
#define BC_ENABLE_HISTORY (1)
#endif // BC_ENABLE_HISTORY
-#if BC_ENABLE_HISTORY
+#ifndef BC_ENABLE_EDITLINE
+#define BC_ENABLE_EDITLINE (0)
+#endif // BC_ENABLE_EDITLINE
+
+#ifndef BC_ENABLE_READLINE
+#define BC_ENABLE_READLINE (0)
+#endif // BC_ENABLE_READLINE
+
+#if BC_ENABLE_EDITLINE && BC_ENABLE_READLINE
+#error Must enable only one of editline or readline, not both.
+#endif // BC_ENABLE_EDITLINE && BC_ENABLE_READLINE
+
+#if BC_ENABLE_EDITLINE || BC_ENABLE_READLINE
+#define BC_ENABLE_LINE_LIB (1)
+#else // BC_ENABLE_EDITLINE || BC_ENABLE_READLINE
+#define BC_ENABLE_LINE_LIB (0)
+#endif // BC_ENABLE_EDITLINE || BC_ENABLE_READLINE
+
+#if BC_ENABLE_LINE_LIB
#include <stdbool.h>
+#include <setjmp.h>
+#include <signal.h>
+
+#include <status.h>
+#include <vector.h>
+
+extern sigjmp_buf bc_history_jmpbuf;
+extern volatile sig_atomic_t bc_history_inlinelib;
+
+#endif // BC_ENABLE_LINE_LIB
+
+#if BC_ENABLE_EDITLINE
+
+#include <stdio.h>
+#include <histedit.h>
+
+/**
+ * The history struct for editline.
+ */
+typedef struct BcHistory
+{
+ /// A place to store the current line.
+ EditLine* el;
+
+ /// The history.
+ History* hist;
+
+ /// Whether the terminal is bad. This is more or less not used.
+ bool badTerm;
+
+} BcHistory;
+
+// The path to the editrc and its length.
+extern const char bc_history_editrc[];
+extern const size_t bc_history_editrc_len;
+
+#else // BC_ENABLE_EDITLINE
+
+#if BC_ENABLE_READLINE
+
+#include <stdio.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+
+/**
+ * The history struct for readline.
+ */
+typedef struct BcHistory
+{
+ /// A place to store the current line.
+ char* line;
+
+ /// Whether the terminal is bad. This is more or less not used.
+ bool badTerm;
+
+} BcHistory;
+
+#else // BC_ENABLE_READLINE
+
+#if BC_ENABLE_HISTORY
+
#include <stddef.h>
#include <signal.h>
@@ -106,7 +185,7 @@
#include <conio.h>
#define strncasecmp _strnicmp
-#define strcasecmp _stricmp
+#define strcasecmp _stricmp
#endif // _WIN32
@@ -154,9 +233,12 @@
#define BC_HISTORY_DEBUG_BUF_SIZE (1024)
+// clang-format off
#define lndebug(...) \
- do { \
- if (bc_history_debug_fp.fd == 0) { \
+ do \
+ { \
+ if (bc_history_debug_fp.fd == 0) \
+ { \
bc_history_debug_buf = bc_vm_malloc(BC_HISTORY_DEBUG_BUF_SIZE); \
bc_file_init(&bc_history_debug_fp, \
open("/tmp/lndebug.txt", O_APPEND), \
@@ -169,15 +251,17 @@
} \
bc_file_printf(&bc_history_debug_fp, ", " __VA_ARGS__); \
bc_file_flush(&bc_history_debug_fp); \
- } while (0)
+ } \
+ while (0)
#else // BC_DEBUG_CODE
#define lndebug(fmt, ...)
#endif // BC_DEBUG_CODE
+// clang-format on
/// An enum of useful actions. To understand what these mean, check terminal
/// emulators for their shortcuts or the VT100 codes.
-typedef enum BcHistoryAction {
-
+typedef enum BcHistoryAction
+{
BC_ACTION_NULL = 0,
BC_ACTION_CTRL_A = 1,
BC_ACTION_CTRL_B = 2,
@@ -200,7 +284,7 @@ typedef enum BcHistoryAction {
BC_ACTION_CTRL_Z = 26,
BC_ACTION_ESC = 27,
BC_ACTION_CTRL_BSLASH = 28,
- BC_ACTION_BACKSPACE = 127
+ BC_ACTION_BACKSPACE = 127
} BcHistoryAction;
@@ -208,8 +292,8 @@ typedef enum BcHistoryAction {
* This represents the state during line editing. We pass this state
* to functions implementing specific editing functionalities.
*/
-typedef struct BcHistory {
-
+typedef struct BcHistory
+{
/// Edited line buffer.
BcVec buf;
@@ -220,7 +304,7 @@ typedef struct BcHistory {
BcVec extras;
/// Prompt to display.
- const char *prompt;
+ const char* prompt;
/// Prompt length.
size_t plen;
@@ -273,38 +357,14 @@ typedef struct BcHistory {
} BcHistory;
/**
- * Get a line from stdin using history. This returns a status because I don't
- * want to throw errors while the terminal is in raw mode.
- * @param h The history data.
- * @param vec A vector to put the line into.
- * @param prompt The prompt to display, if desired.
- * @return A status indicating an error, if any. Returning a status here
- * is better because if we throw an error out of history, we
- * leave the terminal in raw mode or in some other half-baked
- * state.
- */
-BcStatus bc_history_line(BcHistory *h, BcVec *vec, const char *prompt);
-
-/**
- * Initialize history data.
- * @param h The struct to initialize.
- */
-void bc_history_init(BcHistory *h);
-
-/**
- * Free history data (and recook the terminal).
- * @param h The struct to free.
- */
-void bc_history_free(BcHistory *h);
-
-/**
* Frees strings used by history.
* @param str The string to free.
*/
-void bc_history_string_free(void *str);
+void
+bc_history_string_free(void* str);
// A list of terminals that don't work.
-extern const char *bc_history_bad_terms[];
+extern const char* bc_history_bad_terms[];
// A tab in history and its length.
extern const char bc_history_tab[];
@@ -323,16 +383,53 @@ extern const size_t bc_history_combo_chars_len;
// Debug data.
extern BcFile bc_history_debug_fp;
-extern char *bc_history_debug_buf;
+extern char* bc_history_debug_buf;
/**
* A function to print keycodes for debugging.
* @param h The history data.
*/
-void bc_history_printKeyCodes(BcHistory* h);
+void
+bc_history_printKeyCodes(BcHistory* h);
#endif // BC_DEBUG_CODE
#endif // BC_ENABLE_HISTORY
+#endif // BC_ENABLE_READLINE
+
+#endif // BC_ENABLE_EDITLINE
+
+#if BC_ENABLE_HISTORY
+
+/**
+ * Get a line from stdin using history. This returns a status because I don't
+ * want to throw errors while the terminal is in raw mode.
+ * @param h The history data.
+ * @param vec A vector to put the line into.
+ * @param prompt The prompt to display, if desired.
+ * @return A status indicating an error, if any. Returning a status here
+ * is better because if we throw an error out of history, we
+ * leave the terminal in raw mode or in some other half-baked
+ * state.
+ */
+BcStatus
+bc_history_line(BcHistory* h, BcVec* vec, const char* prompt);
+
+/**
+ * Initialize history data.
+ * @param h The struct to initialize.
+ */
+void
+bc_history_init(BcHistory* h);
+
+/**
+ * Free history data (and recook the terminal).
+ * @param h The struct to free.
+ */
+void
+bc_history_free(BcHistory* h);
+
+#endif // BC_ENABLE_HISTORY
+
#endif // BC_HISTORY_H
diff --git a/include/lang.h b/include/lang.h
index b7d12b53c7f3..6b8ebabf6a95 100644
--- a/include/lang.h
+++ b/include/lang.h
@@ -47,8 +47,8 @@
#include <num.h>
/// The instructions for bytecode.
-typedef enum BcInst {
-
+typedef enum BcInst
+{
#if BC_ENABLED
/// Postfix increment and decrement. Prefix are translated into
@@ -329,15 +329,15 @@ typedef enum BcInst {
} BcInst;
#if BC_C11
-static_assert(BC_INST_INVALID <= UCHAR_MAX,
- "Too many instructions to fit into an unsigned char");
+_Static_assert(BC_INST_INVALID <= UCHAR_MAX,
+ "Too many instructions to fit into an unsigned char");
#endif // BC_C11
/// Used by maps to identify where items are in the array.
-typedef struct BcId {
-
+typedef struct BcId
+{
/// The name of the item.
- char *name;
+ char* name;
/// The index into the array where the item is.
size_t idx;
@@ -345,8 +345,8 @@ typedef struct BcId {
} BcId;
/// The location of a var, array, or array element.
-typedef struct BcLoc {
-
+typedef struct BcLoc
+{
/// The index of the var or array.
size_t loc;
@@ -356,10 +356,10 @@ typedef struct BcLoc {
} BcLoc;
/// An entry for a constant.
-typedef struct BcConst {
-
+typedef struct BcConst
+{
/// The original string as parsed from the source code.
- char *val;
+ char* val;
/// The last base that the constant was parsed in.
BcBigDig base;
@@ -372,8 +372,8 @@ typedef struct BcConst {
/// A function. This is also used in dc, not just bc. The reason is that strings
/// are executed in dc, and they are converted to functions in order to be
/// executed.
-typedef struct BcFunc {
-
+typedef struct BcFunc
+{
/// The bytecode instructions.
BcVec code;
@@ -399,7 +399,7 @@ typedef struct BcFunc {
BcVec consts;
/// The function's name.
- const char *name;
+ const char* name;
#if BC_ENABLED
/// True if the function is a void function.
@@ -409,8 +409,8 @@ typedef struct BcFunc {
} BcFunc;
/// Types of results that can be pushed onto the results stack.
-typedef enum BcResultType {
-
+typedef enum BcResultType
+{
/// Result is a variable.
BC_RESULT_VAR,
@@ -464,8 +464,8 @@ typedef enum BcResultType {
} BcResultType;
/// A union to store data for various result types.
-typedef union BcResultData {
-
+typedef union BcResultData
+{
/// A number. Strings are stored here too; they are numbers with
/// cap == 0 && num == NULL. The string's index into the strings vector is
/// stored in the scale field. But this is only used for strings stored in
@@ -482,8 +482,8 @@ typedef union BcResultData {
} BcResultData;
/// A tagged union for results.
-typedef struct BcResult {
-
+typedef struct BcResult
+{
/// The tag. The type of the result.
BcResultType t;
@@ -494,8 +494,8 @@ typedef struct BcResult {
/// An instruction pointer. This is how bc knows where in the bytecode vector,
/// and which function, the current execution is.
-typedef struct BcInstPtr {
-
+typedef struct BcInstPtr
+{
/// The index of the currently executing function in the fns vector.
size_t func;
@@ -510,8 +510,8 @@ typedef struct BcInstPtr {
} BcInstPtr;
/// Types of identifiers.
-typedef enum BcType {
-
+typedef enum BcType
+{
/// Variable.
BC_TYPE_VAR,
@@ -529,8 +529,8 @@ typedef enum BcType {
#if BC_ENABLED
/// An auto variable in bc.
-typedef struct BcAuto {
-
+typedef struct BcAuto
+{
/// The index of the variable in the vars or arrs vectors.
size_t idx;
@@ -549,7 +549,8 @@ struct BcProgram;
* @param name The name of the function. The string is assumed to be owned by
* some other entity.
*/
-void bc_func_init(BcFunc *f, const char* name);
+void
+bc_func_init(BcFunc* f, const char* name);
/**
* Inserts an auto into the function.
@@ -560,15 +561,17 @@ void bc_func_init(BcFunc *f, const char* name);
* @param line The line in the source code where the insert happened. This is
* solely for error reporting.
*/
-void bc_func_insert(BcFunc *f, struct BcProgram* p, char* name,
- BcType type, size_t line);
+void
+bc_func_insert(BcFunc* f, struct BcProgram* p, char* name, BcType type,
+ size_t line);
/**
* Resets a function in preparation for it to be reused. This can happen in bc
* because it is a dynamic language and functions can be redefined.
* @param f The functio to reset.
*/
-void bc_func_reset(BcFunc *f);
+void
+bc_func_reset(BcFunc* f);
#ifndef NDEBUG
/**
@@ -577,7 +580,8 @@ void bc_func_reset(BcFunc *f);
* check for memory leaks.
* @param func The function to free as a void pointer.
*/
-void bc_func_free(void *func);
+void
+bc_func_free(void* func);
#endif // NDEBUG
/**
@@ -591,7 +595,8 @@ void bc_func_free(void *func);
* @param nums True if the array should be for numbers, false if it should be
* for vectors.
*/
-void bc_array_init(BcVec *a, bool nums);
+void
+bc_array_init(BcVec* a, bool nums);
/**
* Copies an array to another array. This is used to do pass arrays to functions
@@ -600,19 +605,22 @@ void bc_array_init(BcVec *a, bool nums);
* @param d The destination array.
* @param s The source array.
*/
-void bc_array_copy(BcVec *d, const BcVec *s);
+void
+bc_array_copy(BcVec* d, const BcVec* s);
/**
* Frees a string stored in a function. This is a destructor.
* @param string The string to free as a void pointer.
*/
-void bc_string_free(void *string);
+void
+bc_string_free(void* string);
/**
* Frees a constant stored in a function. This is a destructor.
* @param constant The constant to free as a void pointer.
*/
-void bc_const_free(void *constant);
+void
+bc_const_free(void* constant);
/**
* Clears a result. It sets the type to BC_RESULT_TEMP and clears the union by
@@ -620,7 +628,8 @@ void bc_const_free(void *constant);
* uninitialized data.
* @param r The result to clear.
*/
-void bc_result_clear(BcResult *r);
+void
+bc_result_clear(BcResult* r);
/**
* Copies a result into another. This is done for things like duplicating the
@@ -629,13 +638,15 @@ void bc_result_clear(BcResult *r);
* @param d The destination result.
* @param src The source result.
*/
-void bc_result_copy(BcResult *d, BcResult *src);
+void
+bc_result_copy(BcResult* d, BcResult* src);
/**
* Frees a result. This is a destructor.
* @param result The result to free as a void pointer.
*/
-void bc_result_free(void *result);
+void
+bc_result_free(void* result);
/**
* Expands an array to @a len. This can happen because in bc, you do not have to
@@ -646,7 +657,8 @@ void bc_result_free(void *result);
* @param a The array to expand.
* @param len The length to expand to.
*/
-void bc_array_expand(BcVec *a, size_t len);
+void
+bc_array_expand(BcVec* a, size_t len);
/**
* Compare two BcId's and return the result. Since they are just comparing the
@@ -656,7 +668,8 @@ void bc_array_expand(BcVec *a, size_t len);
* @param e2 The second id.
* @return The result of strcmp() on the BcId's names.
*/
-int bc_id_cmp(const BcId *e1, const BcId *e2);
+int
+bc_id_cmp(const BcId* e1, const BcId* e2);
#if BC_ENABLED
diff --git a/include/lex.h b/include/lex.h
index 129b9940618f..20be6efa9cde 100644
--- a/include/lex.h
+++ b/include/lex.h
@@ -84,8 +84,8 @@
((c) == '.' && !(pt) && !(int_only)))
/// An enum of lex token types.
-typedef enum BcLexType {
-
+typedef enum BcLexType
+{
/// End of file.
BC_LEX_EOF,
@@ -462,10 +462,10 @@ struct BcLex;
typedef void (*BcLexNext)(struct BcLex* l);
/// The lexer.
-typedef struct BcLex {
-
+typedef struct BcLex
+{
/// A pointer to the text to lex.
- const char *buf;
+ const char* buf;
/// The current index into buf.
size_t i;
@@ -502,7 +502,8 @@ typedef struct BcLex {
* Initializes a lexer.
* @param l The lexer to initialize.
*/
-void bc_lex_init(BcLex *l);
+void
+bc_lex_init(BcLex* l);
/**
* Frees a lexer. This is not guarded by #ifndef NDEBUG because a separate
@@ -510,14 +511,16 @@ void bc_lex_init(BcLex *l);
* that parser needs a lexer.
* @param l The lexer to free.
*/
-void bc_lex_free(BcLex *l);
+void
+bc_lex_free(BcLex* l);
/**
* Sets the filename that the lexer will be lexing.
* @param l The lexer.
* @param file The filename that the lexer will lex.
*/
-void bc_lex_file(BcLex *l, const char *file);
+void
+bc_lex_file(BcLex* l, const char* file);
/**
* Sets the text the lexer will lex.
@@ -527,32 +530,37 @@ void bc_lex_file(BcLex *l, const char *file);
* @param is_exprs True if the text is from command-line expressions, false
* otherwise.
*/
-void bc_lex_text(BcLex *l, const char *text, bool is_stdin, bool is_exprs);
+void
+bc_lex_text(BcLex* l, const char* text, bool is_stdin, bool is_exprs);
/**
* Generic next function for the parser to call. It takes care of calling the
* correct @a BcLexNext function and consuming whitespace.
* @param l The lexer.
*/
-void bc_lex_next(BcLex *l);
+void
+bc_lex_next(BcLex* l);
/**
* Lexes a line comment (one beginning with '#' and going to a newline).
* @param l The lexer.
*/
-void bc_lex_lineComment(BcLex *l);
+void
+bc_lex_lineComment(BcLex* l);
/**
* Lexes a general comment (C-style comment).
* @param l The lexer.
*/
-void bc_lex_comment(BcLex *l);
+void
+bc_lex_comment(BcLex* l);
/**
* Lexes whitespace, finding as much as possible.
* @param l The lexer.
*/
-void bc_lex_whitespace(BcLex *l);
+void
+bc_lex_whitespace(BcLex* l);
/**
* Lexes a number that begins with char @a start. This takes care of parsing
@@ -562,32 +570,37 @@ void bc_lex_whitespace(BcLex *l);
* this function, the lexer had to eat the first char. It fixes
* that by passing it in.
*/
-void bc_lex_number(BcLex *l, char start);
+void
+bc_lex_number(BcLex* l, char start);
/**
* Lexes a name/identifier.
* @param l The lexer.
*/
-void bc_lex_name(BcLex *l);
+void
+bc_lex_name(BcLex* l);
/**
* Lexes common whitespace characters.
* @param l The lexer.
* @param c The character to lex.
*/
-void bc_lex_commonTokens(BcLex *l, char c);
+void
+bc_lex_commonTokens(BcLex* l, char c);
/**
* Throws a parse error because char @a c was invalid.
* @param l The lexer.
* @param c The problem character.
*/
-void bc_lex_invalidChar(BcLex *l, char c);
+void
+bc_lex_invalidChar(BcLex* l, char c);
/**
* Reads a line from stdin and puts it into the lexer's buffer.
* @param l The lexer.
*/
-bool bc_lex_readLine(BcLex *l);
+bool
+bc_lex_readLine(BcLex* l);
#endif // BC_LEX_H
diff --git a/include/library.h b/include/library.h
index 8a055eb81063..63d24ee5f7a9 100644
--- a/include/library.h
+++ b/include/library.h
@@ -46,12 +46,14 @@
* @param l The label to jump to on error.
*/
#define BC_FUNC_HEADER_LOCK(l) \
- do { \
+ do \
+ { \
BC_SIG_LOCK; \
BC_SETJMP_LOCKED(l); \
vm.err = BCL_ERROR_NONE; \
vm.running = 1; \
- } while (0)
+ } \
+ while (0)
/**
* A footer to unlock and stop the jumping if an error happened. It also sets
@@ -59,25 +61,29 @@
* @param e The error variable to set.
*/
#define BC_FUNC_FOOTER_UNLOCK(e) \
- do { \
+ do \
+ { \
BC_SIG_ASSERT_LOCKED; \
e = vm.err; \
vm.running = 0; \
BC_UNSETJMP; \
BC_LONGJMP_STOP; \
vm.sig_lock = 0; \
- } while (0)
+ } \
+ while (0)
/**
* A header that sets a jump and sets running.
* @param l The label to jump to on error.
*/
#define BC_FUNC_HEADER(l) \
- do { \
+ do \
+ { \
BC_SETJMP(l); \
vm.err = BCL_ERROR_NONE; \
vm.running = 1; \
- } while (0)
+ } \
+ while (0)
/**
* A header that assumes that signals are already locked. It sets a jump and
@@ -85,23 +91,27 @@
* @param l The label to jump to on error.
*/
#define BC_FUNC_HEADER_INIT(l) \
- do { \
+ do \
+ { \
BC_SETJMP_LOCKED(l); \
vm.err = BCL_ERROR_NONE; \
vm.running = 1; \
- } while (0)
+ } \
+ while (0)
/**
* A footer for functions that do not return an error code. It clears running
* and unlocks the signals. It also stops the jumping.
*/
#define BC_FUNC_FOOTER_NO_ERR \
- do { \
+ do \
+ { \
vm.running = 0; \
BC_UNSETJMP; \
BC_LONGJMP_STOP; \
vm.sig_lock = 0; \
- } while (0)
+ } \
+ while (0)
/**
* A footer for functions that *do* return an error code. It clears running and
@@ -109,10 +119,12 @@
* @param e The error variable to set.
*/
#define BC_FUNC_FOOTER(e) \
- do { \
+ do \
+ { \
e = vm.err; \
BC_FUNC_FOOTER_NO_ERR; \
- } while (0)
+ } \
+ while (0)
/**
* A footer that sets up n based the value of e and sets up the return value in
@@ -123,13 +135,16 @@
* @param idx The idx to set as the return value.
*/
#define BC_MAYBE_SETUP(c, e, n, idx) \
- do { \
- if (BC_ERR((e) != BCL_ERROR_NONE)) { \
+ do \
+ { \
+ if (BC_ERR((e) != BCL_ERROR_NONE)) \
+ { \
if ((n).num != NULL) bc_num_free(&(n)); \
idx.i = 0 - (size_t) (e); \
} \
else idx = bcl_num_insert(c, &(n)); \
- } while (0)
+ } \
+ while (0)
/**
* A header to check the context and return an error encoded in a number if it
@@ -137,37 +152,44 @@
* @param c The context.
*/
#define BC_CHECK_CTXT(c) \
- do { \
+ do \
+ { \
c = bcl_context(); \
- if (BC_ERR(c == NULL)) { \
+ if (BC_ERR(c == NULL)) \
+ { \
BclNumber n_num; \
n_num.i = 0 - (size_t) BCL_ERROR_INVALID_CONTEXT; \
return n_num; \
} \
- } while (0)
-
+ } \
+ while (0)
/**
* A header to check the context and return an error directly if it is bad.
* @param c The context.
*/
#define BC_CHECK_CTXT_ERR(c) \
- do { \
+ do \
+ { \
c = bcl_context(); \
- if (BC_ERR(c == NULL)) { \
+ if (BC_ERR(c == NULL)) \
+ { \
return BCL_ERROR_INVALID_CONTEXT; \
} \
- } while (0)
+ } \
+ while (0)
/**
* A header to check the context and abort if it is bad.
* @param c The context.
*/
#define BC_CHECK_CTXT_ASSERT(c) \
- do { \
+ do \
+ { \
c = bcl_context(); \
assert(c != NULL); \
- } while (0)
+ } \
+ while (0)
/**
* A header to check the number in the context and return an error encoded as a
@@ -176,16 +198,22 @@
* @param n The BclNumber.
*/
#define BC_CHECK_NUM(c, n) \
- do { \
- if (BC_ERR((n).i >= (c)->nums.len)) { \
+ do \
+ { \
+ if (BC_ERR((n).i >= (c)->nums.len)) \
+ { \
if ((n).i > 0 - (size_t) BCL_ERROR_NELEMS) return (n); \
- else { \
+ else \
+ { \
BclNumber n_num; \
n_num.i = 0 - (size_t) BCL_ERROR_INVALID_NUM; \
return n_num; \
} \
} \
- } while (0)
+ } \
+ while (0)
+
+//clang-format off
/**
* A header to check the number in the context and return an error directly if
@@ -194,13 +222,20 @@
* @param n The BclNumber.
*/
#define BC_CHECK_NUM_ERR(c, n) \
- do { \
- if (BC_ERR((n).i >= (c)->nums.len)) { \
+ do \
+ { \
+ if (BC_ERR((n).i >= (c)->nums.len)) \
+ { \
if ((n).i > 0 - (size_t) BCL_ERROR_NELEMS) \
+ { \
return (BclError) (0 - (n).i); \
+ } \
else return BCL_ERROR_INVALID_NUM; \
} \
- } while (0)
+ } \
+ while (0)
+
+//clang-format on
/**
* Turns a BclNumber into a BcNum.
@@ -213,11 +248,12 @@
* Frees a BcNum for bcl. This is a destructor.
* @param num The BcNum to free, as a void pointer.
*/
-void bcl_num_destruct(void *num);
+void
+bcl_num_destruct(void* num);
/// The actual context struct.
-typedef struct BclCtxt {
-
+typedef struct BclCtxt
+{
/// The context's scale.
size_t scale;
diff --git a/include/num.h b/include/num.h
index bfd360b520f3..4a4dc5bc54fa 100644
--- a/include/num.h
+++ b/include/num.h
@@ -106,12 +106,12 @@ typedef int_least16_t BcDig;
#define BC_NUM_DEF_SIZE (8)
/// The actual number struct. This is where the magic happens.
-typedef struct BcNum {
-
+typedef struct BcNum
+{
/// The limb array. It is restrict because *no* other item should own the
/// array. For more information, see the development manual
/// (manuals/development.md#numbers).
- BcDig *restrict num;
+ BcDig* restrict num;
/// The number of limbs before the decimal (radix) point. This also stores
/// the negative bit in the least significant bit since it uses at least two
@@ -259,8 +259,7 @@ struct BcRNG;
* @param v The value to set the rdx to.
* @param neg The value to set the negative bit to.
*/
-#define BC_NUM_RDX_SET_NEG(n, v, neg) \
- ((n)->rdx = (((v) << 1) | (neg)))
+#define BC_NUM_RDX_SET_NEG(n, v, neg) ((n)->rdx = (((v) << 1) | (neg)))
/**
* Returns true if the rdx and scale for @a n match.
@@ -350,11 +349,11 @@ struct BcRNG;
// These are for debugging only.
#if BC_DEBUG_CODE
-#define BC_NUM_PRINT(x) fprintf(stderr, "%s = %lu\n", #x, (unsigned long)(x))
+#define BC_NUM_PRINT(x) fprintf(stderr, "%s = %lu\n", #x, (unsigned long) (x))
#define DUMP_NUM bc_num_dump
#else // BC_DEBUG_CODE
#undef DUMP_NUM
-#define DUMP_NUM(x,y)
+#define DUMP_NUM(x, y)
#define BC_NUM_PRINT(x)
#endif // BC_DEBUG_CODE
@@ -419,7 +418,8 @@ typedef void (*BcNumShiftAddOp)(BcDig* restrict a, const BcDig* restrict b,
* @param n The number to initialize.
* @param req The number of limbs @a n must have in its limb array.
*/
-void bc_num_init(BcNum *restrict n, size_t req);
+void
+bc_num_init(BcNum* restrict n, size_t req);
/**
* Initializes (sets up) @a n with the preallocated limb array @a num that has
@@ -429,7 +429,8 @@ void bc_num_init(BcNum *restrict n, size_t req);
* @param num The preallocated limb array.
* @param cap The capacity of @a num.
*/
-void bc_num_setup(BcNum *restrict n, BcDig *restrict num, size_t cap);
+void
+bc_num_setup(BcNum* restrict n, BcDig* restrict num, size_t cap);
/**
* Copies @a s into @a d. This does a deep copy and requires that @a d is
@@ -437,7 +438,8 @@ void bc_num_setup(BcNum *restrict n, BcDig *restrict num, size_t cap);
* @param d The destination BcNum.
* @param s The source BcNum.
*/
-void bc_num_copy(BcNum *d, const BcNum *s);
+void
+bc_num_copy(BcNum* d, const BcNum* s);
/**
* Creates @a d and copies @a s into @a d. This does a deep copy and requires
@@ -445,7 +447,8 @@ void bc_num_copy(BcNum *d, const BcNum *s);
* @param d The destination BcNum.
* @param s The source BcNum.
*/
-void bc_num_createCopy(BcNum *d, const BcNum *s);
+void
+bc_num_createCopy(BcNum* d, const BcNum* s);
/**
* Creates (initializes) @a n and sets its value to the equivalent of @a val.
@@ -453,27 +456,31 @@ void bc_num_createCopy(BcNum *d, const BcNum *s);
* @param n The number to initialize and set.
* @param val The value to set @a n's value to.
*/
-void bc_num_createFromBigdig(BcNum *restrict n, BcBigDig val);
+void
+bc_num_createFromBigdig(BcNum* restrict n, BcBigDig val);
/**
* Makes @a n valid for holding strings. @a n must *not* be allocated; this
* simply clears some fields, including setting the num field to NULL.
* @param n The number to clear.
*/
-void bc_num_clear(BcNum *restrict n);
+void
+bc_num_clear(BcNum* restrict n);
/**
* Frees @a num, which is a BcNum as a void pointer. This is a destructor.
* @param num The BcNum to free as a void pointer.
*/
-void bc_num_free(void *num);
+void
+bc_num_free(void* num);
/**
* Returns the scale of @a n.
* @param n The number.
* @return The scale of @a n.
*/
-size_t bc_num_scale(const BcNum *restrict n);
+size_t
+bc_num_scale(const BcNum* restrict n);
/**
* Returns the length (in decimal digits) of @a n. This is complicated. First,
@@ -483,7 +490,8 @@ size_t bc_num_scale(const BcNum *restrict n);
* @param n The number.
* @return The length of @a n.
*/
-size_t bc_num_len(const BcNum *restrict n);
+size_t
+bc_num_len(const BcNum* restrict n);
/**
* Convert a number to a BcBigDig (hardware integer). This version does error
@@ -492,7 +500,8 @@ size_t bc_num_len(const BcNum *restrict n);
* @param n The number to convert.
* @return The number as a hardware integer.
*/
-BcBigDig bc_num_bigdig(const BcNum *restrict n);
+BcBigDig
+bc_num_bigdig(const BcNum* restrict n);
/**
* Convert a number to a BcBigDig (hardware integer). This version does no error
@@ -500,7 +509,8 @@ BcBigDig bc_num_bigdig(const BcNum *restrict n);
* @param n The number to convert.
* @return The number as a hardware integer.
*/
-BcBigDig bc_num_bigdig2(const BcNum *restrict n);
+BcBigDig
+bc_num_bigdig2(const BcNum* restrict n);
/**
* Sets @a n to the value of @a val. @a n is expected to be a valid and
@@ -508,7 +518,8 @@ BcBigDig bc_num_bigdig2(const BcNum *restrict n);
* @param n The number to set.
* @param val The value to set the number to.
*/
-void bc_num_bigdig2num(BcNum *restrict n, BcBigDig val);
+void
+bc_num_bigdig2num(BcNum* restrict n, BcBigDig val);
#if BC_ENABLE_EXTRA_MATH
@@ -519,22 +530,24 @@ void bc_num_bigdig2num(BcNum *restrict n, BcBigDig val);
* @param b The return value.
* @param rng The pseudo-random number generator.
*/
-void bc_num_irand(BcNum *restrict a, BcNum *restrict b,
- struct BcRNG *restrict rng);
+void
+bc_num_irand(BcNum* restrict a, BcNum* restrict b, struct BcRNG* restrict rng);
/**
* Sets the seed for the PRNG @a rng from @a n.
* @param n The new seed for the PRNG.
* @param rng The PRNG to set the seed for.
*/
-void bc_num_rng(const BcNum *restrict n, struct BcRNG *rng);
+void
+bc_num_rng(const BcNum* restrict n, struct BcRNG* rng);
/**
* Sets @a n to the value produced by the PRNG. This implements rand().
* @param n The number to set.
* @param rng The pseudo-random number generator.
*/
-void bc_num_createFromRNG(BcNum *restrict n, struct BcRNG *rng);
+void
+bc_num_createFromRNG(BcNum* restrict n, struct BcRNG* rng);
#endif // BC_ENABLE_EXTRA_MATH
@@ -545,7 +558,8 @@ void bc_num_createFromRNG(BcNum *restrict n, struct BcRNG *rng);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_add(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The subtract function. This is a BcNumBinaryOp function.
@@ -554,7 +568,8 @@ void bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_sub(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The multiply function.
@@ -563,7 +578,8 @@ void bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_mul(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The division function.
@@ -572,7 +588,8 @@ void bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_div(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The modulus function.
@@ -581,7 +598,8 @@ void bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_mod(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The power function.
@@ -590,7 +608,8 @@ void bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_pow(BcNum* a, BcNum* b, BcNum* c, size_t scale);
#if BC_ENABLE_EXTRA_MATH
/**
@@ -600,7 +619,8 @@ void bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_places(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_places(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The left shift function (<< operator). This is a BcNumBinaryOp function.
@@ -609,7 +629,8 @@ void bc_num_places(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_lshift(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_lshift(BcNum* a, BcNum* b, BcNum* c, size_t scale);
/**
* The right shift function (>> operator). This is a BcNumBinaryOp function.
@@ -618,7 +639,8 @@ void bc_num_lshift(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param c The return value.
* @param scale The current scale.
*/
-void bc_num_rshift(BcNum *a, BcNum *b, BcNum *c, size_t scale);
+void
+bc_num_rshift(BcNum* a, BcNum* b, BcNum* c, size_t scale);
#endif // BC_ENABLE_EXTRA_MATH
@@ -628,7 +650,8 @@ void bc_num_rshift(BcNum *a, BcNum *b, BcNum *c, size_t scale);
* @param b The return value.
* @param scale The current scale.
*/
-void bc_num_sqrt(BcNum *restrict a, BcNum *restrict b, size_t scale);
+void
+bc_num_sqrt(BcNum* restrict a, BcNum* restrict b, size_t scale);
/**
* Divsion and modulus together. This is a dc extension.
@@ -638,7 +661,8 @@ void bc_num_sqrt(BcNum *restrict a, BcNum *restrict b, size_t scale);
* @param d The second return value (modulus).
* @param scale The current scale.
*/
-void bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, size_t scale);
+void
+bc_num_divmod(BcNum* a, BcNum* b, BcNum* c, BcNum* d, size_t scale);
/**
* A function returning the required allocation size for an addition or a
@@ -649,7 +673,8 @@ void bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, size_t scale);
* @return The size of allocation needed for the result of add or subtract
* with @a a, @a b, and @a scale.
*/
-size_t bc_num_addReq(const BcNum* a, const BcNum* b, size_t scale);
+size_t
+bc_num_addReq(const BcNum* a, const BcNum* b, size_t scale);
/**
* A function returning the required allocation size for a multiplication. This
@@ -660,7 +685,8 @@ size_t bc_num_addReq(const BcNum* a, const BcNum* b, size_t scale);
* @return The size of allocation needed for the result of multiplication
* with @a a, @a b, and @a scale.
*/
-size_t bc_num_mulReq(const BcNum *a, const BcNum *b, size_t scale);
+size_t
+bc_num_mulReq(const BcNum* a, const BcNum* b, size_t scale);
/**
* A function returning the required allocation size for a division or modulus.
@@ -671,7 +697,8 @@ size_t bc_num_mulReq(const BcNum *a, const BcNum *b, size_t scale);
* @return The size of allocation needed for the result of division or
* modulus with @a a, @a b, and @a scale.
*/
-size_t bc_num_divReq(const BcNum *a, const BcNum *b, size_t scale);
+size_t
+bc_num_divReq(const BcNum* a, const BcNum* b, size_t scale);
/**
* A function returning the required allocation size for an exponentiation. This
@@ -682,7 +709,8 @@ size_t bc_num_divReq(const BcNum *a, const BcNum *b, size_t scale);
* @return The size of allocation needed for the result of exponentiation
* with @a a, @a b, and @a scale.
*/
-size_t bc_num_powReq(const BcNum *a, const BcNum *b, size_t scale);
+size_t
+bc_num_powReq(const BcNum* a, const BcNum* b, size_t scale);
#if BC_ENABLE_EXTRA_MATH
@@ -695,7 +723,8 @@ size_t bc_num_powReq(const BcNum *a, const BcNum *b, size_t scale);
* @return The size of allocation needed for the result of places, left
* shift, or right shift with @a a, @a b, and @a scale.
*/
-size_t bc_num_placesReq(const BcNum *a, const BcNum *b, size_t scale);
+size_t
+bc_num_placesReq(const BcNum* a, const BcNum* b, size_t scale);
#endif // BC_ENABLE_EXTRA_MATH
@@ -705,7 +734,8 @@ size_t bc_num_placesReq(const BcNum *a, const BcNum *b, size_t scale);
* @param n The number to truncate.
* @param places The number of places to truncate @a n by.
*/
-void bc_num_truncate(BcNum *restrict n, size_t places);
+void
+bc_num_truncate(BcNum* restrict n, size_t places);
/**
* Extend @a n *by* @a places decimal places. This only extends places *after*
@@ -713,7 +743,8 @@ void bc_num_truncate(BcNum *restrict n, size_t places);
* @param n The number to truncate.
* @param places The number of places to extend @a n by.
*/
-void bc_num_extend(BcNum *restrict n, size_t places);
+void
+bc_num_extend(BcNum* restrict n, size_t places);
/**
* Shifts @a n right by @a places decimal places. This is the workhorse of the
@@ -722,7 +753,8 @@ void bc_num_extend(BcNum *restrict n, size_t places);
* @param n The number to shift right.
* @param places The number of decimal places to shift @a n right by.
*/
-void bc_num_shiftRight(BcNum *restrict n, size_t places);
+void
+bc_num_shiftRight(BcNum* restrict n, size_t places);
/**
* Compare a and b and return the result of their comparison as an ssize_t.
@@ -732,7 +764,8 @@ void bc_num_shiftRight(BcNum *restrict n, size_t places);
* @param b The second number.
* @return The result of the comparison.
*/
-ssize_t bc_num_cmp(const BcNum *a, const BcNum *b);
+ssize_t
+bc_num_cmp(const BcNum* a, const BcNum* b);
/**
* Modular exponentiation.
@@ -741,28 +774,30 @@ ssize_t bc_num_cmp(const BcNum *a, const BcNum *b);
* @param c The third parameter.
* @param d The return value.
*/
-void bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d);
+void
+bc_num_modexp(BcNum* a, BcNum* b, BcNum* c, BcNum* restrict d);
/**
* Sets @a n to zero with a scale of zero.
* @param n The number to zero.
*/
-void bc_num_zero(BcNum *restrict n);
+void
+bc_num_zero(BcNum* restrict n);
/**
* Sets @a n to one with a scale of zero.
* @param n The number to set to one.
*/
-void bc_num_one(BcNum *restrict n);
+void
+bc_num_one(BcNum* restrict n);
/**
* An efficient function to compare @a n to zero.
* @param n The number to compare to zero.
* @return The result of the comparison.
*/
-ssize_t bc_num_cmpZero(const BcNum *n);
-
-#if !defined(NDEBUG) || BC_ENABLE_LIBRARY
+ssize_t
+bc_num_cmpZero(const BcNum* n);
/**
* Check a number string for validity and return true if it is, false otherwise.
@@ -772,9 +807,8 @@ ssize_t bc_num_cmpZero(const BcNum *n);
* @param val The string to check.
* @return True if the string is a valid number, false otherwise.
*/
-bool bc_num_strValid(const char *restrict val);
-
-#endif // !defined(NDEBUG) || BC_ENABLE_LIBRARY
+bool
+bc_num_strValid(const char* restrict val);
/**
* Parses a number string into the number @a n according to @a base.
@@ -782,7 +816,8 @@ bool bc_num_strValid(const char *restrict val);
* @param val The number string to parse.
* @param base The base to parse the number string by.
*/
-void bc_num_parse(BcNum *restrict n, const char *restrict val, BcBigDig base);
+void
+bc_num_parse(BcNum* restrict n, const char* restrict val, BcBigDig base);
/**
* Prints the number @a n according to @a base.
@@ -791,7 +826,8 @@ void bc_num_parse(BcNum *restrict n, const char *restrict val, BcBigDig base);
* @param newline True if a newline should be inserted at the end, false
* otherwise.
*/
-void bc_num_print(BcNum *restrict n, BcBigDig base, bool newline);
+void
+bc_num_print(BcNum* restrict n, BcBigDig base, bool newline);
#if !BC_ENABLE_LIBRARY
@@ -799,7 +835,8 @@ void bc_num_print(BcNum *restrict n, BcBigDig base, bool newline);
* Prints a number as a character stream.
* @param n The number to print as a character stream.
*/
-void bc_num_stream(BcNum *restrict n);
+void
+bc_num_stream(BcNum* restrict n);
#endif // !BC_ENABLE_LIBRARY
@@ -811,7 +848,8 @@ void bc_num_stream(BcNum *restrict n);
* @param name The label to print the number with.
* @param emptyline True if there should be an empty line after the number.
*/
-void bc_num_printDebug(const BcNum *n, const char *name, bool emptyline);
+void
+bc_num_printDebug(const BcNum* n, const char* name, bool emptyline);
/**
* Print the limbs of @a n. This is a debug-only function.
@@ -819,7 +857,8 @@ void bc_num_printDebug(const BcNum *n, const char *name, bool emptyline);
* @param len The length of the number.
* @param emptyline True if there should be an empty line after the number.
*/
-void bc_num_printDigs(const BcDig* n, size_t len, bool emptyline);
+void
+bc_num_printDigs(const BcDig* n, size_t len, bool emptyline);
/**
* Print debug info about @a n along with its limbs.
@@ -827,14 +866,16 @@ void bc_num_printDigs(const BcDig* n, size_t len, bool emptyline);
* @param name The label to print the number with.
* @param emptyline True if there should be an empty line after the number.
*/
-void bc_num_printWithDigs(const BcNum *n, const char *name, bool emptyline);
+void
+bc_num_printWithDigs(const BcNum* n, const char* name, bool emptyline);
/**
* Dump debug info about a BcNum variable.
* @param varname The variable name.
* @param n The number.
*/
-void bc_num_dump(const char *varname, const BcNum *n);
+void
+bc_num_dump(const char* varname, const BcNum* n);
#endif // BC_DEBUG_CODE
@@ -842,7 +883,7 @@ void bc_num_dump(const char *varname, const BcNum *n);
extern const char bc_num_hex_digits[];
/// An array of powers of 10 for easy conversion from number of digits to
-//powers.
+/// powers.
extern const BcBigDig bc_num_pow10[BC_BASE_DIGS + 1];
/// A reference to a constant array that is the max of a BigDig.
diff --git a/include/opt.h b/include/opt.h
index cffe63682236..3c465c80fbf6 100644
--- a/include/opt.h
+++ b/include/opt.h
@@ -44,10 +44,10 @@
#include <stdlib.h>
/// The data required to parse command-line arguments.
-typedef struct BcOpt {
-
+typedef struct BcOpt
+{
/// The array of arguments.
- char **argv;
+ char** argv;
/// The index of the current argument.
size_t optind;
@@ -59,13 +59,13 @@ typedef struct BcOpt {
int subopt;
/// The option argument.
- char *optarg;
+ char* optarg;
} BcOpt;
/// The types of arguments. This is specially adapted for bc.
-typedef enum BcOptType {
-
+typedef enum BcOptType
+{
/// No argument required.
BC_OPT_NONE,
@@ -84,10 +84,10 @@ typedef enum BcOptType {
} BcOptType;
/// A struct to hold const data for long options.
-typedef struct BcOptLong {
-
+typedef struct BcOptLong
+{
/// The name of the option.
- const char *name;
+ const char* name;
/// The type of the option.
BcOptType type;
@@ -102,7 +102,8 @@ typedef struct BcOptLong {
* @param o The option data to initialize.
* @param argv The array of arguments.
*/
-void bc_opt_init(BcOpt *o, char **argv);
+void
+bc_opt_init(BcOpt* o, char** argv);
/**
* Parse an option. This returns a value the same way getopt() and getopt_long()
@@ -111,7 +112,8 @@ void bc_opt_init(BcOpt *o, char **argv);
* @param longopts The long options.
* @return A character for the parsed option, or -1 if done.
*/
-int bc_opt_parse(BcOpt *o, const BcOptLong *longopts);
+int
+bc_opt_parse(BcOpt* o, const BcOptLong* longopts);
/**
* Returns true if the option is `--` and not a long option.
diff --git a/include/parse.h b/include/parse.h
index 35ca1652fc98..e692462395ca 100644
--- a/include/parse.h
+++ b/include/parse.h
@@ -53,23 +53,24 @@
/// loops, while loops, and if statements. This is because POSIX requires that
/// certain operators are *only* used in those cases. It's whacked, but that's
/// how it is.
-#define BC_PARSE_REL (UINTMAX_C(1)<<0)
+#define BC_PARSE_REL (UINTMAX_C(1) << 0)
/// A flag that requires that the expression is valid for a print statement.
-#define BC_PARSE_PRINT (UINTMAX_C(1)<<1)
+#define BC_PARSE_PRINT (UINTMAX_C(1) << 1)
/// A flag that requires that the expression does *not* have any function call.
-#define BC_PARSE_NOCALL (UINTMAX_C(1)<<2)
+#define BC_PARSE_NOCALL (UINTMAX_C(1) << 2)
-/// A flag that requires that the expression does *not* have a read() expression.
-#define BC_PARSE_NOREAD (UINTMAX_C(1)<<3)
+/// A flag that requires that the expression does *not* have a read()
+/// expression.
+#define BC_PARSE_NOREAD (UINTMAX_C(1) << 3)
/// A flag that *allows* (rather than requires) that an array appear in the
/// expression. This is mostly used as parameters in bc.
-#define BC_PARSE_ARRAY (UINTMAX_C(1)<<4)
+#define BC_PARSE_ARRAY (UINTMAX_C(1) << 4)
/// A flag that requires that the expression is not empty and returns a value.
-#define BC_PARSE_NEEDVAL (UINTMAX_C(1)<<5)
+#define BC_PARSE_NEEDVAL (UINTMAX_C(1) << 5)
/**
* Returns true if the parser has been initialized.
@@ -154,8 +155,8 @@ typedef void (*BcParseParse)(struct BcParse* p);
typedef void (*BcParseExpr)(struct BcParse* p, uint8_t flags);
/// The parser struct.
-typedef struct BcParse {
-
+typedef struct BcParse
+{
/// The lexer.
BcLex l;
@@ -191,11 +192,11 @@ typedef struct BcParse {
#endif // BC_ENABLED
/// A reference to the program to grab the current function when necessary.
- struct BcProgram *prog;
+ struct BcProgram* prog;
/// A reference to the current function. The function is what holds the
/// bytecode vector that the parser is filling.
- BcFunc *func;
+ BcFunc* func;
/// The index of the function.
size_t fidx;
@@ -214,40 +215,46 @@ typedef struct BcParse {
* @param prog A referenc to the program.
* @param func The index of the current function.
*/
-void bc_parse_init(BcParse *p, struct BcProgram *prog, size_t func);
+void
+bc_parse_init(BcParse* p, struct BcProgram* prog, size_t func);
/**
* Frees a parser. This is not guarded by #ifndef NDEBUG because a separate
* parser is created at runtime to parse read() expressions and dc strings.
* @param p The parser to free.
*/
-void bc_parse_free(BcParse *p);
+void
+bc_parse_free(BcParse* p);
/**
* Resets the parser. Resetting means erasing all state to the point that the
* parser would think it was just initialized.
* @param p The parser to reset.
*/
-void bc_parse_reset(BcParse *p);
+void
+bc_parse_reset(BcParse* p);
/**
* Adds a string. See @a BcProgram in include/program.h for more details.
* @param p The parser that parsed the string.
*/
-void bc_parse_addString(BcParse *p);
+void
+bc_parse_addString(BcParse* p);
/**
* Adds a number. See @a BcProgram in include/program.h for more details.
* @param p The parser that parsed the number.
*/
-void bc_parse_number(BcParse *p);
+void
+bc_parse_number(BcParse* p);
/**
* Update the current function in the parser.
* @param p The parser.
* @param fidx The index of the new function.
*/
-void bc_parse_updateFunc(BcParse *p, size_t fidx);
+void
+bc_parse_updateFunc(BcParse* p, size_t fidx);
/**
* Adds a new variable or array. See @a BcProgram in include/program.h for more
@@ -256,7 +263,8 @@ void bc_parse_updateFunc(BcParse *p, size_t fidx);
* @param name The name of the variable or array to add.
* @param var True if the name is for a variable, false if it's for an array.
*/
-void bc_parse_pushName(const BcParse* p, char *name, bool var);
+void
+bc_parse_pushName(const BcParse* p, char* name, bool var);
/**
* Sets the text that the parser will parse.
@@ -266,7 +274,8 @@ void bc_parse_pushName(const BcParse* p, char *name, bool var);
* @param is_exprs True if the text is from command-line expressions, false
* otherwise.
*/
-void bc_parse_text(BcParse *p, const char *text, bool is_stdin, bool is_exprs);
+void
+bc_parse_text(BcParse* p, const char* text, bool is_stdin, bool is_exprs);
// References to const 0 and 1 strings for special cases. bc and dc have
// specific instructions for 0 and 1 because they pop up so often and (in the
diff --git a/include/program.h b/include/program.h
index 3f90f2b9f552..1a87aa612c90 100644
--- a/include/program.h
+++ b/include/program.h
@@ -64,8 +64,8 @@
/// The length of the globals array.
#define BC_PROG_GLOBALS_LEN (3 + BC_ENABLE_EXTRA_MATH)
-typedef struct BcProgram {
-
+typedef struct BcProgram
+{
/// The array of globals values.
BcBigDig globals[BC_PROG_GLOBALS_LEN];
@@ -86,10 +86,10 @@ typedef struct BcProgram {
BcVec stack;
/// A pointer to the current function's constants.
- BcVec *consts;
+ BcVec* consts;
/// A pointer to the current function's strings.
- BcVec *strs;
+ BcVec* strs;
/// The array of functions.
BcVec fns;
@@ -206,8 +206,7 @@ typedef struct BcProgram {
/// This define disappears the parameter last because for dc only, last is
/// always true.
-#define bc_program_copyToVar(p, name, t, last) \
- bc_program_copyToVar(p, name, t)
+#define bc_program_copyToVar(p, name, t, last) bc_program_copyToVar(p, name, t)
#endif // !BC_ENABLED
@@ -263,13 +262,14 @@ typedef struct BcProgram {
* @param r The BcResult to store the result into.
* @param n The parameter to the unary operation.
*/
-typedef void (*BcProgramUnary)(BcResult *r, BcNum *n);
+typedef void (*BcProgramUnary)(BcResult* r, BcNum* n);
/**
* Initializes the BcProgram.
* @param p The program to initialize.
*/
-void bc_program_init(BcProgram *p);
+void
+bc_program_init(BcProgram* p);
#ifndef NDEBUG
@@ -279,7 +279,8 @@ void bc_program_init(BcProgram *p);
* exit.
* @param p The program to initialize.
*/
-void bc_program_free(BcProgram *p);
+void
+bc_program_free(BcProgram* p);
#endif // NDEBUG
@@ -290,7 +291,8 @@ void bc_program_free(BcProgram *p);
* Prints the bytecode in a function. This is a debug-only function.
* @param p The program.
*/
-void bc_program_code(const BcProgram *p);
+void
+bc_program_code(const BcProgram* p);
/**
* Prints an instruction. This is a debug-only function.
@@ -299,14 +301,16 @@ void bc_program_code(const BcProgram *p);
* @param bgn A pointer to the current index. It is also updated to the next
* index.
*/
-void bc_program_printInst(const BcProgram *p, const char *code,
- size_t *restrict bgn);
+void
+bc_program_printInst(const BcProgram* p, const char* code,
+ size_t* restrict bgn);
/**
* Prints the stack. This is a debug-only function.
* @param p The program.
*/
-void bc_program_printStackDebug(BcProgram* p);
+void
+bc_program_printStackDebug(BcProgram* p);
#endif // BC_ENABLED && DC_ENABLED
#endif // BC_DEBUG_CODE
@@ -318,7 +322,8 @@ void bc_program_printStackDebug(BcProgram* p);
* @param var True if the search should be for a variable, false for an array.
* @return The index of the variable or array in the correct array.
*/
-size_t bc_program_search(BcProgram *p, const char* id, bool var);
+size_t
+bc_program_search(BcProgram* p, const char* id, bool var);
/**
* Adds a string to a function and returns the string's index in the function.
@@ -326,7 +331,8 @@ size_t bc_program_search(BcProgram *p, const char* id, bool var);
* @param str The string to add.
* @param fidx The index of the function to add to.
*/
-size_t bc_program_addString(BcProgram *p, const char *str, size_t fidx);
+size_t
+bc_program_addString(BcProgram* p, const char* str, size_t fidx);
/**
* Inserts a function into the program and returns the index of the function in
@@ -335,33 +341,38 @@ size_t bc_program_addString(BcProgram *p, const char *str, size_t fidx);
* @param name The name of the function.
* @return The index of the function after insertion.
*/
-size_t bc_program_insertFunc(BcProgram *p, const char *name);
+size_t
+bc_program_insertFunc(BcProgram* p, const char* name);
/**
* Resets a program, usually because of resetting after an error.
* @param p The program to reset.
*/
-void bc_program_reset(BcProgram *p);
+void
+bc_program_reset(BcProgram* p);
/**
* Executes bc or dc code in the BcProgram.
* @param p The program.
*/
-void bc_program_exec(BcProgram *p);
+void
+bc_program_exec(BcProgram* p);
/**
* Negates a copy of a BcNum. This is a BcProgramUnary function.
* @param r The BcResult to store the result into.
* @param n The parameter to the unary operation.
*/
-void bc_program_negate(BcResult *r, BcNum *n);
+void
+bc_program_negate(BcResult* r, BcNum* n);
/**
* Returns a boolean not of a BcNum. This is a BcProgramUnary function.
* @param r The BcResult to store the result into.
* @param n The parameter to the unary operation.
*/
-void bc_program_not(BcResult *r, BcNum *n);
+void
+bc_program_not(BcResult* r, BcNum* n);
#if BC_ENABLE_EXTRA_MATH
@@ -370,10 +381,30 @@ void bc_program_not(BcResult *r, BcNum *n);
* @param r The BcResult to store the result into.
* @param n The parameter to the unary operation.
*/
-void bc_program_trunc(BcResult *r, BcNum *n);
+void
+bc_program_trunc(BcResult* r, BcNum* n);
+
+/**
+ * Assigns a value to the seed builtin variable.
+ * @param p The program.
+ * @param val The value to assign to the seed.
+ */
+void
+bc_program_assignSeed(BcProgram* p, BcNum* val);
#endif // BC_ENABLE_EXTRA_MATH
+/**
+ * Assigns a value to a builtin value that is not seed.
+ * @param p The program.
+ * @param scale True if the builtin is scale.
+ * @param obase True if the builtin is obase. This cannot be true at the same
+ * time @a scale is.
+ * @param val The value to assign to the builtin.
+ */
+void
+bc_program_assignBuiltin(BcProgram* p, bool scale, bool obase, BcBigDig val);
+
/// A reference to an array of binary operator functions.
extern const BcNumBinaryOp bc_program_ops[];
@@ -406,34 +437,42 @@ extern const char bc_program_esc_seqs[];
#if BC_DEBUG_CODE
+// clang-format off
#define BC_PROG_JUMP(inst, code, ip) \
- do { \
+ do \
+ { \
inst = (uchar) (code)[(ip)->idx++]; \
bc_file_printf(&vm.ferr, "inst: %s\n", bc_inst_names[inst]); \
bc_file_flush(&vm.ferr, bc_flush_none); \
goto *bc_program_inst_lbls[inst]; \
- } while (0)
+ } \
+ while (0)
+// clang-format on
#else // BC_DEBUG_CODE
+// clang-format off
#define BC_PROG_JUMP(inst, code, ip) \
- do { \
+ do \
+ { \
inst = (uchar) (code)[(ip)->idx++]; \
goto *bc_program_inst_lbls[inst]; \
- } while (0)
+ } \
+ while (0)
+// clang-format on
#endif // BC_DEBUG_CODE
-#define BC_PROG_DIRECT_JUMP(l) goto lbl_ ## l;
-#define BC_PROG_LBL(l) lbl_ ## l
+#define BC_PROG_DIRECT_JUMP(l) goto lbl_##l;
+#define BC_PROG_LBL(l) lbl_##l
#define BC_PROG_FALLTHROUGH
#if BC_C11
#define BC_PROG_LBLS_SIZE (sizeof(bc_program_inst_lbls) / sizeof(void*))
-#define BC_PROG_LBLS_ASSERT \
- static_assert(BC_PROG_LBLS_SIZE == BC_INST_INVALID + 1,\
- "bc_program_inst_lbls[] mismatches the instructions")
+#define BC_PROG_LBLS_ASSERT \
+ _Static_assert(BC_PROG_LBLS_SIZE == BC_INST_INVALID + 1, \
+ "bc_program_inst_lbls[] mismatches the instructions")
#else // BC_C11
@@ -447,197 +486,199 @@ extern const char bc_program_esc_seqs[];
#if BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_INC, \
- &&lbl_BC_INST_DEC, \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_TRUNC, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_PLACES, \
- &&lbl_BC_INST_LSHIFT, \
- &&lbl_BC_INST_RSHIFT, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_POWER, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY, \
- &&lbl_BC_INST_ASSIGN_DIVIDE, \
- &&lbl_BC_INST_ASSIGN_MODULUS, \
- &&lbl_BC_INST_ASSIGN_PLUS, \
- &&lbl_BC_INST_ASSIGN_MINUS, \
- &&lbl_BC_INST_ASSIGN_PLACES, \
- &&lbl_BC_INST_ASSIGN_LSHIFT, \
- &&lbl_BC_INST_ASSIGN_RSHIFT, \
- &&lbl_BC_INST_ASSIGN, \
- &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLACES_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_LSHIFT_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_RSHIFT_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_LAST, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_SEED, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_IRAND, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_RAND, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_MAXRAND, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_GLOBAL_STACKS, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_PRINT_STR, \
- &&lbl_BC_INST_JUMP, \
- &&lbl_BC_INST_JUMP_ZERO, \
- &&lbl_BC_INST_CALL, \
- &&lbl_BC_INST_RET, \
- &&lbl_BC_INST_RET0, \
- &&lbl_BC_INST_RET_VOID, \
- &&lbl_BC_INST_HALT, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_POP_EXEC, \
- &&lbl_BC_INST_EXECUTE, \
- &&lbl_BC_INST_EXEC_COND, \
- &&lbl_BC_INST_PRINT_STACK, \
- &&lbl_BC_INST_CLEAR_STACK, \
- &&lbl_BC_INST_REG_STACK_LEN, \
- &&lbl_BC_INST_STACK_LEN, \
- &&lbl_BC_INST_DUPLICATE, \
- &&lbl_BC_INST_LOAD, \
- &&lbl_BC_INST_PUSH_VAR, \
- &&lbl_BC_INST_PUSH_TO_VAR, \
- &&lbl_BC_INST_QUIT, \
- &&lbl_BC_INST_NQUIT, \
- &&lbl_BC_INST_EXEC_STACK_LEN, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_INC, \
+ &&lbl_BC_INST_DEC, \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_TRUNC, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_PLACES, \
+ &&lbl_BC_INST_LSHIFT, \
+ &&lbl_BC_INST_RSHIFT, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_POWER, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE, \
+ &&lbl_BC_INST_ASSIGN_MODULUS, \
+ &&lbl_BC_INST_ASSIGN_PLUS, \
+ &&lbl_BC_INST_ASSIGN_MINUS, \
+ &&lbl_BC_INST_ASSIGN_PLACES, \
+ &&lbl_BC_INST_ASSIGN_LSHIFT, \
+ &&lbl_BC_INST_ASSIGN_RSHIFT, \
+ &&lbl_BC_INST_ASSIGN, \
+ &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLACES_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_LSHIFT_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_RSHIFT_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_LAST, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_SEED, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_IRAND, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_RAND, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_MAXRAND, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_GLOBAL_STACKS, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_PRINT_STR, \
+ &&lbl_BC_INST_JUMP, \
+ &&lbl_BC_INST_JUMP_ZERO, \
+ &&lbl_BC_INST_CALL, \
+ &&lbl_BC_INST_RET, \
+ &&lbl_BC_INST_RET0, \
+ &&lbl_BC_INST_RET_VOID, \
+ &&lbl_BC_INST_HALT, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_POP_EXEC, \
+ &&lbl_BC_INST_EXECUTE, \
+ &&lbl_BC_INST_EXEC_COND, \
+ &&lbl_BC_INST_PRINT_STACK, \
+ &&lbl_BC_INST_CLEAR_STACK, \
+ &&lbl_BC_INST_REG_STACK_LEN, \
+ &&lbl_BC_INST_STACK_LEN, \
+ &&lbl_BC_INST_DUPLICATE, \
+ &&lbl_BC_INST_LOAD, \
+ &&lbl_BC_INST_PUSH_VAR, \
+ &&lbl_BC_INST_PUSH_TO_VAR, \
+ &&lbl_BC_INST_QUIT, \
+ &&lbl_BC_INST_NQUIT, \
+ &&lbl_BC_INST_EXEC_STACK_LEN, \
+ &&lbl_BC_INST_INVALID, \
+ }
#else // BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_INC, \
- &&lbl_BC_INST_DEC, \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_POWER, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY, \
- &&lbl_BC_INST_ASSIGN_DIVIDE, \
- &&lbl_BC_INST_ASSIGN_MODULUS, \
- &&lbl_BC_INST_ASSIGN_PLUS, \
- &&lbl_BC_INST_ASSIGN_MINUS, \
- &&lbl_BC_INST_ASSIGN, \
- &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_LAST, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_GLOBAL_STACKS, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_PRINT_STR, \
- &&lbl_BC_INST_JUMP, \
- &&lbl_BC_INST_JUMP_ZERO, \
- &&lbl_BC_INST_CALL, \
- &&lbl_BC_INST_RET, \
- &&lbl_BC_INST_RET0, \
- &&lbl_BC_INST_RET_VOID, \
- &&lbl_BC_INST_HALT, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_POP_EXEC, \
- &&lbl_BC_INST_EXECUTE, \
- &&lbl_BC_INST_EXEC_COND, \
- &&lbl_BC_INST_PRINT_STACK, \
- &&lbl_BC_INST_CLEAR_STACK, \
- &&lbl_BC_INST_REG_STACK_LEN, \
- &&lbl_BC_INST_STACK_LEN, \
- &&lbl_BC_INST_DUPLICATE, \
- &&lbl_BC_INST_LOAD, \
- &&lbl_BC_INST_PUSH_VAR, \
- &&lbl_BC_INST_PUSH_TO_VAR, \
- &&lbl_BC_INST_QUIT, \
- &&lbl_BC_INST_NQUIT, \
- &&lbl_BC_INST_EXEC_STACK_LEN, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_INC, \
+ &&lbl_BC_INST_DEC, \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_POWER, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE, \
+ &&lbl_BC_INST_ASSIGN_MODULUS, \
+ &&lbl_BC_INST_ASSIGN_PLUS, \
+ &&lbl_BC_INST_ASSIGN_MINUS, \
+ &&lbl_BC_INST_ASSIGN, \
+ &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_LAST, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_GLOBAL_STACKS, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_PRINT_STR, \
+ &&lbl_BC_INST_JUMP, \
+ &&lbl_BC_INST_JUMP_ZERO, \
+ &&lbl_BC_INST_CALL, \
+ &&lbl_BC_INST_RET, \
+ &&lbl_BC_INST_RET0, \
+ &&lbl_BC_INST_RET_VOID, \
+ &&lbl_BC_INST_HALT, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_POP_EXEC, \
+ &&lbl_BC_INST_EXECUTE, \
+ &&lbl_BC_INST_EXEC_COND, \
+ &&lbl_BC_INST_PRINT_STACK, \
+ &&lbl_BC_INST_CLEAR_STACK, \
+ &&lbl_BC_INST_REG_STACK_LEN, \
+ &&lbl_BC_INST_STACK_LEN, \
+ &&lbl_BC_INST_DUPLICATE, \
+ &&lbl_BC_INST_LOAD, \
+ &&lbl_BC_INST_PUSH_VAR, \
+ &&lbl_BC_INST_PUSH_TO_VAR, \
+ &&lbl_BC_INST_QUIT, \
+ &&lbl_BC_INST_NQUIT, \
+ &&lbl_BC_INST_EXEC_STACK_LEN, \
+ &&lbl_BC_INST_INVALID, \
+ }
#endif // BC_ENABLE_EXTRA_MATH
@@ -645,169 +686,171 @@ extern const char bc_program_esc_seqs[];
#if BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_INC, \
- &&lbl_BC_INST_DEC, \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_TRUNC, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_PLACES, \
- &&lbl_BC_INST_LSHIFT, \
- &&lbl_BC_INST_RSHIFT, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_POWER, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY, \
- &&lbl_BC_INST_ASSIGN_DIVIDE, \
- &&lbl_BC_INST_ASSIGN_MODULUS, \
- &&lbl_BC_INST_ASSIGN_PLUS, \
- &&lbl_BC_INST_ASSIGN_MINUS, \
- &&lbl_BC_INST_ASSIGN_PLACES, \
- &&lbl_BC_INST_ASSIGN_LSHIFT, \
- &&lbl_BC_INST_ASSIGN_RSHIFT, \
- &&lbl_BC_INST_ASSIGN, \
- &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLACES_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_LSHIFT_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_RSHIFT_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_LAST, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_SEED, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_IRAND, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_RAND, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_MAXRAND, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_GLOBAL_STACKS, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_PRINT_STR, \
- &&lbl_BC_INST_JUMP, \
- &&lbl_BC_INST_JUMP_ZERO, \
- &&lbl_BC_INST_CALL, \
- &&lbl_BC_INST_RET, \
- &&lbl_BC_INST_RET0, \
- &&lbl_BC_INST_RET_VOID, \
- &&lbl_BC_INST_HALT, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_INC, \
+ &&lbl_BC_INST_DEC, \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_TRUNC, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_PLACES, \
+ &&lbl_BC_INST_LSHIFT, \
+ &&lbl_BC_INST_RSHIFT, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_POWER, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE, \
+ &&lbl_BC_INST_ASSIGN_MODULUS, \
+ &&lbl_BC_INST_ASSIGN_PLUS, \
+ &&lbl_BC_INST_ASSIGN_MINUS, \
+ &&lbl_BC_INST_ASSIGN_PLACES, \
+ &&lbl_BC_INST_ASSIGN_LSHIFT, \
+ &&lbl_BC_INST_ASSIGN_RSHIFT, \
+ &&lbl_BC_INST_ASSIGN, \
+ &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLACES_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_LSHIFT_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_RSHIFT_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_LAST, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_SEED, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_IRAND, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_RAND, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_MAXRAND, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_GLOBAL_STACKS, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_PRINT_STR, \
+ &&lbl_BC_INST_JUMP, \
+ &&lbl_BC_INST_JUMP_ZERO, \
+ &&lbl_BC_INST_CALL, \
+ &&lbl_BC_INST_RET, \
+ &&lbl_BC_INST_RET0, \
+ &&lbl_BC_INST_RET_VOID, \
+ &&lbl_BC_INST_HALT, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_INVALID, \
+ }
#else // BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_INC, \
- &&lbl_BC_INST_DEC, \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_POWER, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY, \
- &&lbl_BC_INST_ASSIGN_DIVIDE, \
- &&lbl_BC_INST_ASSIGN_MODULUS, \
- &&lbl_BC_INST_ASSIGN_PLUS, \
- &&lbl_BC_INST_ASSIGN_MINUS, \
- &&lbl_BC_INST_ASSIGN, \
- &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_LAST, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_GLOBAL_STACKS, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_PRINT_STR, \
- &&lbl_BC_INST_JUMP, \
- &&lbl_BC_INST_JUMP_ZERO, \
- &&lbl_BC_INST_CALL, \
- &&lbl_BC_INST_RET, \
- &&lbl_BC_INST_RET0, \
- &&lbl_BC_INST_RET_VOID, \
- &&lbl_BC_INST_HALT, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_INC, \
+ &&lbl_BC_INST_DEC, \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_POWER, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE, \
+ &&lbl_BC_INST_ASSIGN_MODULUS, \
+ &&lbl_BC_INST_ASSIGN_PLUS, \
+ &&lbl_BC_INST_ASSIGN_MINUS, \
+ &&lbl_BC_INST_ASSIGN, \
+ &&lbl_BC_INST_ASSIGN_POWER_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MULTIPLY_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_DIVIDE_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MODULUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_PLUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_MINUS_NO_VAL, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_LAST, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_GLOBAL_STACKS, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_PRINT_STR, \
+ &&lbl_BC_INST_JUMP, \
+ &&lbl_BC_INST_JUMP_ZERO, \
+ &&lbl_BC_INST_CALL, \
+ &&lbl_BC_INST_RET, \
+ &&lbl_BC_INST_RET0, \
+ &&lbl_BC_INST_RET_VOID, \
+ &&lbl_BC_INST_HALT, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_INVALID, \
+ }
#endif // BC_ENABLE_EXTRA_MATH
@@ -817,141 +860,143 @@ extern const char bc_program_esc_seqs[];
#if BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_TRUNC, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_PLACES, \
- &&lbl_BC_INST_LSHIFT, \
- &&lbl_BC_INST_RSHIFT, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_SEED, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_IRAND, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_RAND, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_MAXRAND, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_POP_EXEC, \
- &&lbl_BC_INST_EXECUTE, \
- &&lbl_BC_INST_EXEC_COND, \
- &&lbl_BC_INST_PRINT_STACK, \
- &&lbl_BC_INST_CLEAR_STACK, \
- &&lbl_BC_INST_REG_STACK_LEN, \
- &&lbl_BC_INST_STACK_LEN, \
- &&lbl_BC_INST_DUPLICATE, \
- &&lbl_BC_INST_LOAD, \
- &&lbl_BC_INST_PUSH_VAR, \
- &&lbl_BC_INST_PUSH_TO_VAR, \
- &&lbl_BC_INST_QUIT, \
- &&lbl_BC_INST_NQUIT, \
- &&lbl_BC_INST_EXEC_STACK_LEN, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_TRUNC, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_PLACES, \
+ &&lbl_BC_INST_LSHIFT, \
+ &&lbl_BC_INST_RSHIFT, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_SEED, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_IRAND, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_RAND, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_MAXRAND, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_POP_EXEC, \
+ &&lbl_BC_INST_EXECUTE, \
+ &&lbl_BC_INST_EXEC_COND, \
+ &&lbl_BC_INST_PRINT_STACK, \
+ &&lbl_BC_INST_CLEAR_STACK, \
+ &&lbl_BC_INST_REG_STACK_LEN, \
+ &&lbl_BC_INST_STACK_LEN, \
+ &&lbl_BC_INST_DUPLICATE, \
+ &&lbl_BC_INST_LOAD, \
+ &&lbl_BC_INST_PUSH_VAR, \
+ &&lbl_BC_INST_PUSH_TO_VAR, \
+ &&lbl_BC_INST_QUIT, \
+ &&lbl_BC_INST_NQUIT, \
+ &&lbl_BC_INST_EXEC_STACK_LEN, \
+ &&lbl_BC_INST_INVALID, \
+ }
#else // BC_ENABLE_EXTRA_MATH
-#define BC_PROG_LBLS static const void* const bc_program_inst_lbls[] = { \
- &&lbl_BC_INST_NEG, \
- &&lbl_BC_INST_BOOL_NOT, \
- &&lbl_BC_INST_POWER, \
- &&lbl_BC_INST_MULTIPLY, \
- &&lbl_BC_INST_DIVIDE, \
- &&lbl_BC_INST_MODULUS, \
- &&lbl_BC_INST_PLUS, \
- &&lbl_BC_INST_MINUS, \
- &&lbl_BC_INST_REL_EQ, \
- &&lbl_BC_INST_REL_LE, \
- &&lbl_BC_INST_REL_GE, \
- &&lbl_BC_INST_REL_NE, \
- &&lbl_BC_INST_REL_LT, \
- &&lbl_BC_INST_REL_GT, \
- &&lbl_BC_INST_BOOL_OR, \
- &&lbl_BC_INST_BOOL_AND, \
- &&lbl_BC_INST_ASSIGN_NO_VAL, \
- &&lbl_BC_INST_NUM, \
- &&lbl_BC_INST_VAR, \
- &&lbl_BC_INST_ARRAY_ELEM, \
- &&lbl_BC_INST_ARRAY, \
- &&lbl_BC_INST_ZERO, \
- &&lbl_BC_INST_ONE, \
- &&lbl_BC_INST_IBASE, \
- &&lbl_BC_INST_OBASE, \
- &&lbl_BC_INST_SCALE, \
- &&lbl_BC_INST_LENGTH, \
- &&lbl_BC_INST_SCALE_FUNC, \
- &&lbl_BC_INST_SQRT, \
- &&lbl_BC_INST_ABS, \
- &&lbl_BC_INST_ASCIIFY, \
- &&lbl_BC_INST_READ, \
- &&lbl_BC_INST_MAXIBASE, \
- &&lbl_BC_INST_MAXOBASE, \
- &&lbl_BC_INST_MAXSCALE, \
- &&lbl_BC_INST_LINE_LENGTH, \
- &&lbl_BC_INST_LEADING_ZERO, \
- &&lbl_BC_INST_PRINT, \
- &&lbl_BC_INST_PRINT_POP, \
- &&lbl_BC_INST_STR, \
- &&lbl_BC_INST_POP, \
- &&lbl_BC_INST_SWAP, \
- &&lbl_BC_INST_MODEXP, \
- &&lbl_BC_INST_DIVMOD, \
- &&lbl_BC_INST_PRINT_STREAM, \
- &&lbl_BC_INST_POP_EXEC, \
- &&lbl_BC_INST_EXECUTE, \
- &&lbl_BC_INST_EXEC_COND, \
- &&lbl_BC_INST_PRINT_STACK, \
- &&lbl_BC_INST_CLEAR_STACK, \
- &&lbl_BC_INST_REG_STACK_LEN, \
- &&lbl_BC_INST_STACK_LEN, \
- &&lbl_BC_INST_DUPLICATE, \
- &&lbl_BC_INST_LOAD, \
- &&lbl_BC_INST_PUSH_VAR, \
- &&lbl_BC_INST_PUSH_TO_VAR, \
- &&lbl_BC_INST_QUIT, \
- &&lbl_BC_INST_NQUIT, \
- &&lbl_BC_INST_EXEC_STACK_LEN, \
- &&lbl_BC_INST_INVALID, \
-}
+#define BC_PROG_LBLS \
+ static const void* const bc_program_inst_lbls[] = { \
+ &&lbl_BC_INST_NEG, \
+ &&lbl_BC_INST_BOOL_NOT, \
+ &&lbl_BC_INST_POWER, \
+ &&lbl_BC_INST_MULTIPLY, \
+ &&lbl_BC_INST_DIVIDE, \
+ &&lbl_BC_INST_MODULUS, \
+ &&lbl_BC_INST_PLUS, \
+ &&lbl_BC_INST_MINUS, \
+ &&lbl_BC_INST_REL_EQ, \
+ &&lbl_BC_INST_REL_LE, \
+ &&lbl_BC_INST_REL_GE, \
+ &&lbl_BC_INST_REL_NE, \
+ &&lbl_BC_INST_REL_LT, \
+ &&lbl_BC_INST_REL_GT, \
+ &&lbl_BC_INST_BOOL_OR, \
+ &&lbl_BC_INST_BOOL_AND, \
+ &&lbl_BC_INST_ASSIGN_NO_VAL, \
+ &&lbl_BC_INST_NUM, \
+ &&lbl_BC_INST_VAR, \
+ &&lbl_BC_INST_ARRAY_ELEM, \
+ &&lbl_BC_INST_ARRAY, \
+ &&lbl_BC_INST_ZERO, \
+ &&lbl_BC_INST_ONE, \
+ &&lbl_BC_INST_IBASE, \
+ &&lbl_BC_INST_OBASE, \
+ &&lbl_BC_INST_SCALE, \
+ &&lbl_BC_INST_LENGTH, \
+ &&lbl_BC_INST_SCALE_FUNC, \
+ &&lbl_BC_INST_SQRT, \
+ &&lbl_BC_INST_ABS, \
+ &&lbl_BC_INST_ASCIIFY, \
+ &&lbl_BC_INST_READ, \
+ &&lbl_BC_INST_MAXIBASE, \
+ &&lbl_BC_INST_MAXOBASE, \
+ &&lbl_BC_INST_MAXSCALE, \
+ &&lbl_BC_INST_LINE_LENGTH, \
+ &&lbl_BC_INST_LEADING_ZERO, \
+ &&lbl_BC_INST_PRINT, \
+ &&lbl_BC_INST_PRINT_POP, \
+ &&lbl_BC_INST_STR, \
+ &&lbl_BC_INST_POP, \
+ &&lbl_BC_INST_SWAP, \
+ &&lbl_BC_INST_MODEXP, \
+ &&lbl_BC_INST_DIVMOD, \
+ &&lbl_BC_INST_PRINT_STREAM, \
+ &&lbl_BC_INST_POP_EXEC, \
+ &&lbl_BC_INST_EXECUTE, \
+ &&lbl_BC_INST_EXEC_COND, \
+ &&lbl_BC_INST_PRINT_STACK, \
+ &&lbl_BC_INST_CLEAR_STACK, \
+ &&lbl_BC_INST_REG_STACK_LEN, \
+ &&lbl_BC_INST_STACK_LEN, \
+ &&lbl_BC_INST_DUPLICATE, \
+ &&lbl_BC_INST_LOAD, \
+ &&lbl_BC_INST_PUSH_VAR, \
+ &&lbl_BC_INST_PUSH_TO_VAR, \
+ &&lbl_BC_INST_QUIT, \
+ &&lbl_BC_INST_NQUIT, \
+ &&lbl_BC_INST_EXEC_STACK_LEN, \
+ &&lbl_BC_INST_INVALID, \
+ }
#endif // BC_ENABLE_EXTRA_MATH
diff --git a/include/rand.h b/include/rand.h
index 58eb2cf0e320..7546891dbd64 100644
--- a/include/rand.h
+++ b/include/rand.h
@@ -65,7 +65,7 @@
* @param ptr A void ptr to some data that will help generate the random ulong.
* @return The random ulong.
*/
-typedef ulong (*BcRandUlong)(void *ptr);
+typedef ulong (*BcRandUlong)(void* ptr);
#if BC_LONG_BIT >= 64
@@ -178,8 +178,8 @@ typedef __uint128_t BcRandState;
#else // BC_RAND_BUILTIN
/// A typedef for the PCG state.
-typedef struct BcRandState {
-
+typedef struct BcRandState
+{
/// The low bits.
uint_fast64_t lo;
@@ -241,7 +241,10 @@ typedef struct BcRandState {
* @param l The low 64 bits.
* @return The constant built from @a h and @a l.
*/
-#define BC_RAND_CONSTANT(h, l) { .lo = (l), .hi = (h) }
+#define BC_RAND_CONSTANT(h, l) \
+ { \
+ .lo = (l), .hi = (h) \
+ }
/**
* Truncates a PCG state to the number of bits in a random integer.
@@ -272,7 +275,7 @@ typedef struct BcRandState {
* @param n The integer to truncate.
* @return The bottom 32 bits of @a n.
*/
-#define BC_RAND_TRUNC32(n) ((n) & BC_RAND_BOTTOM32)
+#define BC_RAND_TRUNC32(n) ((n) & (BC_RAND_BOTTOM32))
/**
* Returns the second 32 bits of @a n.
@@ -419,8 +422,8 @@ typedef uint_fast64_t BcRandState;
#define BC_RAND_SRAND_BITS ((1 << CHAR_BIT) - 1)
/// The actual RNG data. These are the actual PRNG's.
-typedef struct BcRNGData {
-
+typedef struct BcRNGData
+{
/// The state.
BcRandState state;
@@ -431,8 +434,8 @@ typedef struct BcRNGData {
/// The public PRNG. This is just a stack of PRNG's to maintain the globals
/// stack illusion.
-typedef struct BcRNG {
-
+typedef struct BcRNG
+{
/// The stack of PRNG's.
BcVec v;
@@ -442,7 +445,8 @@ typedef struct BcRNG {
* Initializes a BcRNG.
* @param r The BcRNG to initialize.
*/
-void bc_rand_init(BcRNG *r);
+void
+bc_rand_init(BcRNG* r);
#if BC_RAND_USE_FREE
@@ -451,7 +455,8 @@ void bc_rand_init(BcRNG *r);
* exit.
* @param r The BcRNG to free.
*/
-void bc_rand_free(BcRNG *r);
+void
+bc_rand_free(BcRNG* r);
#endif // BC_RAND_USE_FREE
@@ -460,7 +465,8 @@ void bc_rand_free(BcRNG *r);
* @param r The PRNG.
* @return A random integer.
*/
-BcRand bc_rand_int(BcRNG *r);
+BcRand
+bc_rand_int(BcRNG* r);
/**
* Returns a random integer from the PRNG bounded by @a bound. Bias is
@@ -469,7 +475,8 @@ BcRand bc_rand_int(BcRNG *r);
* @param bound The bound for the random integer.
* @return A bounded random integer.
*/
-BcRand bc_rand_bounded(BcRNG *r, BcRand bound);
+BcRand
+bc_rand_bounded(BcRNG* r, BcRand bound);
/**
* Seed the PRNG with the state in two parts and the increment in two parts.
@@ -479,13 +486,15 @@ BcRand bc_rand_bounded(BcRNG *r, BcRand bound);
* @param inc1 The first part of the increment.
* @param inc2 The second part of the increment.
*/
-void bc_rand_seed(BcRNG *r, ulong state1, ulong state2, ulong inc1, ulong inc2);
+void
+bc_rand_seed(BcRNG* r, ulong state1, ulong state2, ulong inc1, ulong inc2);
/**
* Pushes a new PRNG onto the PRNG stack.
* @param r The PRNG.
*/
-void bc_rand_push(BcRNG *r);
+void
+bc_rand_push(BcRNG* r);
/**
* Pops one or all but one items off of the PRNG stack.
@@ -493,7 +502,8 @@ void bc_rand_push(BcRNG *r);
* @param reset True if all but one PRNG should be popped off the stack, false
* if only one should be popped.
*/
-void bc_rand_pop(BcRNG *r, bool reset);
+void
+bc_rand_pop(BcRNG* r, bool reset);
/**
* Returns, via pointers, the state of the PRNG in pieces.
@@ -503,13 +513,15 @@ void bc_rand_pop(BcRNG *r, bool reset);
* @param i1 The return value for the first part of the increment.
* @param i2 The return value for the second part of the increment.
*/
-void bc_rand_getRands(BcRNG *r, BcRand *s1, BcRand *s2, BcRand *i1, BcRand *i2);
+void
+bc_rand_getRands(BcRNG* r, BcRand* s1, BcRand* s2, BcRand* i1, BcRand* i2);
/**
* Seed the PRNG with random data.
* @param rng The PRNG.
*/
-void bc_rand_srand(BcRNGData *rng);
+void
+bc_rand_srand(BcRNGData* rng);
/// A reference to a constant multiplier.
extern const BcRandState bc_rand_multiplier;
diff --git a/include/read.h b/include/read.h
index 2ebb456e83fe..0e824d941b50 100644
--- a/include/read.h
+++ b/include/read.h
@@ -53,14 +53,16 @@
* @param vec The vector to put the stdin data into.
* @param prompt The prompt to print, if desired.
*/
-BcStatus bc_read_line(BcVec *vec, const char *prompt);
+BcStatus
+bc_read_line(BcVec* vec, const char* prompt);
/**
* Read a file and return a buffer with the data. The buffer must be freed by
* the caller.
* @param path The path to the file to read.
*/
-char* bc_read_file(const char *path);
+char*
+bc_read_file(const char* path);
/**
* Helper function for reading characters from stdin. This takes care of a bunch
@@ -69,7 +71,8 @@ char* bc_read_file(const char *path);
* @param vec The vec to put the stdin into.
* @param prompt The prompt to print, if desired.
*/
-BcStatus bc_read_chars(BcVec *vec, const char *prompt);
+BcStatus
+bc_read_chars(BcVec* vec, const char* prompt);
/**
* Read a line from buf into vec.
@@ -77,6 +80,7 @@ BcStatus bc_read_chars(BcVec *vec, const char *prompt);
* @param buf The buffer to read from.
* @param buf_len The length of the buffer.
*/
-bool bc_read_buf(BcVec *vec, char *buf, size_t *buf_len);
+bool
+bc_read_buf(BcVec* vec, char* buf, size_t* buf_len);
#endif // BC_READ_H
diff --git a/include/status.h b/include/status.h
index df084c70c1b5..d038944d40c9 100644
--- a/include/status.h
+++ b/include/status.h
@@ -45,6 +45,13 @@
#endif // __OpenBSD__
#endif // BC_TEST_OPENBSD
+// This is used by configure.sh to test for FreeBSD.
+#ifdef BC_TEST_FREEBSD
+#ifdef __FreeBSD__
+#error On FreeBSD with _POSIX_C_SOURCE
+#endif // __FreeBSD__
+#endif // BC_TEST_FREEBSD
+
#ifndef BC_ENABLED
#define BC_ENABLED (1)
#endif // BC_ENABLED
@@ -295,8 +302,8 @@
/// Statuses, which mark either which category of error happened, or some other
/// status that matters.
-typedef enum BcStatus {
-
+typedef enum BcStatus
+{
/// Normal status.
BC_STATUS_SUCCESS = 0,
@@ -321,8 +328,8 @@ typedef enum BcStatus {
} BcStatus;
/// Errors, which are more specific errors.
-typedef enum BcErr {
-
+typedef enum BcErr
+{
// Math errors.
/// Negative number used when not allowed.
@@ -565,13 +572,23 @@ typedef enum BcErr {
/// bc, and they *must* have signals locked. Other functions are expected to
/// *not* have signals locked, for reasons. So this is a pre-built assert
/// (no-op in non-debug mode) that check that signals are locked.
-#define BC_SIG_ASSERT_LOCKED do { assert(vm.sig_lock); } while (0)
+#define BC_SIG_ASSERT_LOCKED \
+ do \
+ { \
+ assert(vm.sig_lock); \
+ } \
+ while (0)
/// Assert that signals are unlocked. There are non-async-signal-safe functions
/// in bc, and they *must* have signals locked. Other functions are expected to
/// *not* have signals locked, for reasons. So this is a pre-built assert
/// (no-op in non-debug mode) that check that signals are unlocked.
-#define BC_SIG_ASSERT_NOT_LOCKED do { assert(vm.sig_lock == 0); } while (0)
+#define BC_SIG_ASSERT_NOT_LOCKED \
+ do \
+ { \
+ assert(vm.sig_lock == 0); \
+ } \
+ while (0)
#else // NDEBUG
@@ -591,35 +608,43 @@ typedef enum BcErr {
/// Locks signals.
#define BC_SIG_LOCK \
- do { \
+ do \
+ { \
BC_SIG_ASSERT_NOT_LOCKED; \
vm.sig_lock = 1; \
- } while (0)
+ } \
+ while (0)
/// Unlocks signals. If a signal happened, then this will cause a jump.
#define BC_SIG_UNLOCK \
- do { \
+ do \
+ { \
BC_SIG_ASSERT_LOCKED; \
vm.sig_lock = 0; \
if (vm.sig) BC_JMP; \
- } while (0)
+ } \
+ while (0)
/// Locks signals, regardless of if they are already locked. This is really only
/// used after labels that longjmp() goes to after the jump because the cleanup
/// code must have signals locked, and BC_LONGJMP_CONT will unlock signals if it
/// doesn't jump.
#define BC_SIG_MAYLOCK \
- do { \
+ do \
+ { \
vm.sig_lock = 1; \
- } while (0)
+ } \
+ while (0)
/// Unlocks signals, regardless of if they were already unlocked. If a signal
/// happened, then this will cause a jump.
#define BC_SIG_MAYUNLOCK \
- do { \
+ do \
+ { \
vm.sig_lock = 0; \
if (vm.sig) BC_JMP; \
- } while (0)
+ } \
+ while (0)
/*
* Locks signals, but stores the old lock state, to be restored later by
@@ -627,20 +652,24 @@ typedef enum BcErr {
* @param v The variable to store the old lock state to.
*/
#define BC_SIG_TRYLOCK(v) \
- do { \
+ do \
+ { \
v = vm.sig_lock; \
vm.sig_lock = 1; \
- } while (0)
+ } \
+ while (0)
/* Restores the previous state of a signal lock, and if it is now unlocked,
* initiates an exception/jump.
* @param v The old lock state.
*/
#define BC_SIG_TRYUNLOCK(v) \
- do { \
+ do \
+ { \
vm.sig_lock = (v); \
if (!(v) && vm.sig) BC_JMP; \
- } while (0)
+ } \
+ while (0)
/**
* Sets a jump, and sets it up as well so that if a longjmp() happens, bc will
@@ -653,17 +682,20 @@ typedef enum BcErr {
* param l The label to jump to on a longjmp().
*/
#define BC_SETJMP(l) \
- do { \
+ do \
+ { \
sigjmp_buf sjb; \
BC_SIG_LOCK; \
bc_vec_grow(&vm.jmp_bufs, 1); \
- if (sigsetjmp(sjb, 0)) { \
+ if (sigsetjmp(sjb, 0)) \
+ { \
assert(BC_SIG_EXC); \
goto l; \
} \
bc_vec_push(&vm.jmp_bufs, &sjb); \
BC_SIG_UNLOCK; \
- } while (0)
+ } \
+ while (0)
/**
* Sets a jump like BC_SETJMP, but unlike BC_SETJMP, it assumes signals are
@@ -673,46 +705,55 @@ typedef enum BcErr {
* param l The label to jump to on a longjmp().
*/
#define BC_SETJMP_LOCKED(l) \
- do { \
+ do \
+ { \
sigjmp_buf sjb; \
BC_SIG_ASSERT_LOCKED; \
- if (sigsetjmp(sjb, 0)) { \
+ if (sigsetjmp(sjb, 0)) \
+ { \
assert(BC_SIG_EXC); \
goto l; \
} \
bc_vec_push(&vm.jmp_bufs, &sjb); \
- } while (0)
+ } \
+ while (0)
/// Used after cleanup labels set by BC_SETJMP and BC_SETJMP_LOCKED to jump to
/// the next place. This is what continues the stack unwinding. This basically
/// copies BC_SIG_UNLOCK into itself, but that is because its condition for
/// jumping is BC_SIG_EXC, not just that a signal happened.
#define BC_LONGJMP_CONT \
- do { \
+ do \
+ { \
BC_SIG_ASSERT_LOCKED; \
if (!vm.sig_pop) bc_vec_pop(&vm.jmp_bufs); \
vm.sig_lock = 0; \
if (BC_SIG_EXC) BC_JMP; \
- } while (0)
+ } \
+ while (0)
/// Unsets a jump. It always assumes signals are locked. This basically just
/// pops a jmp_buf off of the stack of jmp_bufs, and since the jump mechanism
/// always jumps to the location at the top of the stack, this effectively
/// undoes a setjmp().
#define BC_UNSETJMP \
- do { \
+ do \
+ { \
BC_SIG_ASSERT_LOCKED; \
bc_vec_pop(&vm.jmp_bufs); \
- } while (0)
+ } \
+ while (0)
/// Stops a stack unwinding. Technically, a stack unwinding needs to be done
/// manually, but it will always be done unless certain flags are cleared. This
/// clears the flags.
#define BC_LONGJMP_STOP \
- do { \
+ do \
+ { \
vm.sig_pop = 0; \
vm.sig = 0; \
- } while (0)
+ } \
+ while (0)
// Various convenience macros for calling the bc's error handling routine.
#if BC_ENABLE_LIBRARY
@@ -773,7 +814,8 @@ typedef enum BcErr {
// for easy marking of where functions are entered and exited.
#if BC_DEBUG_CODE
#define BC_FUNC_ENTER \
- do { \
+ do \
+ { \
size_t bc_func_enter_i; \
for (bc_func_enter_i = 0; bc_func_enter_i < vm.func_depth; \
++bc_func_enter_i) \
@@ -783,10 +825,12 @@ typedef enum BcErr {
vm.func_depth += 1; \
bc_file_printf(&vm.ferr, "Entering %s\n", __func__); \
bc_file_flush(&vm.ferr, bc_flush_none); \
- } while (0);
+ } \
+ while (0);
#define BC_FUNC_EXIT \
- do { \
+ do \
+ { \
size_t bc_func_enter_i; \
vm.func_depth -= 1; \
for (bc_func_enter_i = 0; bc_func_enter_i < vm.func_depth; \
@@ -796,7 +840,8 @@ typedef enum BcErr {
} \
bc_file_printf(&vm.ferr, "Leaving %s\n", __func__); \
bc_file_flush(&vm.ferr, bc_flush_none); \
- } while (0);
+ } \
+ while (0);
#else // BC_DEBUG_CODE
#define BC_FUNC_ENTER
#define BC_FUNC_EXIT
diff --git a/include/vector.h b/include/vector.h
index c35d22c9eff7..43158ef4ba63 100644
--- a/include/vector.h
+++ b/include/vector.h
@@ -47,7 +47,7 @@
/// The starting capacity for vectors. This is based on the minimum allocation
/// for 64-bit systems.
-#define BC_VEC_START_CAP (UINTMAX_C(1)<<5)
+#define BC_VEC_START_CAP (UINTMAX_C(1) << 5)
/// An alias.
typedef unsigned char uchar;
@@ -57,7 +57,7 @@ typedef unsigned char uchar;
* to free the memory they own.
* @param ptr Pointer to the data to free.
*/
-typedef void (*BcVecFree)(void *ptr);
+typedef void (*BcVecFree)(void* ptr);
// Forward declaration.
struct BcId;
@@ -75,8 +75,8 @@ typedef uint16_t BcSize;
#endif // BC_LONG_BIT >= 64
/// An enum of all of the destructors. We use an enum to save space.
-typedef enum BcDtorType {
-
+typedef enum BcDtorType
+{
/// No destructor needed.
BC_DTOR_NONE,
@@ -120,11 +120,11 @@ typedef enum BcDtorType {
} BcDtorType;
/// The actual vector struct.
-typedef struct BcVec {
-
+typedef struct BcVec
+{
/// The vector array itself. This uses a char* because it is compatible with
/// pointers of all other types, and I can do pointer arithmetic on it.
- char *restrict v;
+ char* restrict v;
/// The length of the vector, which is how many items actually exist.
size_t len;
@@ -147,7 +147,8 @@ typedef struct BcVec {
* @param esize The size of the elements, as returned by sizeof().
* @param dtor The destructor of the elements, as a BcDtorType enum.
*/
-void bc_vec_init(BcVec *restrict v, size_t esize, BcDtorType dtor);
+void
+bc_vec_init(BcVec* restrict v, size_t esize, BcDtorType dtor);
/**
* Expands the vector to have a capacity of @a req items, if it doesn't have
@@ -155,14 +156,16 @@ void bc_vec_init(BcVec *restrict v, size_t esize, BcDtorType dtor);
* @param v The vector to expand.
* @param req The requested capacity.
*/
-void bc_vec_expand(BcVec *restrict v, size_t req);
+void
+bc_vec_expand(BcVec* restrict v, size_t req);
/**
* Grow a vector by at least @a n elements.
* @param v The vector to grow.
* @param n The number of elements to grow the vector by.
*/
-void bc_vec_grow(BcVec *restrict v, size_t n);
+void
+bc_vec_grow(BcVec* restrict v, size_t n);
/**
* Pops @a n items off the back of the vector. The vector must have at least
@@ -170,7 +173,8 @@ void bc_vec_grow(BcVec *restrict v, size_t n);
* @param v The vector to pop off of.
* @param n The number of elements to pop off.
*/
-void bc_vec_npop(BcVec *restrict v, size_t n);
+void
+bc_vec_npop(BcVec* restrict v, size_t n);
/**
* Pops @a n items, starting at index @a idx, off the vector. The vector must
@@ -180,7 +184,8 @@ void bc_vec_npop(BcVec *restrict v, size_t n);
* @param n The number of elements to pop off.
* @param idx The index to start popping at.
*/
-void bc_vec_npopAt(BcVec *restrict v, size_t n, size_t idx);
+void
+bc_vec_npopAt(BcVec* restrict v, size_t n, size_t idx);
/**
* Pushes one item on the back of the vector. It does a memcpy(), but it assumes
@@ -188,7 +193,8 @@ void bc_vec_npopAt(BcVec *restrict v, size_t n, size_t idx);
* @param v The vector to push onto.
* @param data A pointer to the data to push.
*/
-void bc_vec_push(BcVec *restrict v, const void *data);
+void
+bc_vec_push(BcVec* restrict v, const void* data);
/**
* Pushes @a n items on the back of the vector. It does a memcpy(), but it
@@ -196,7 +202,8 @@ void bc_vec_push(BcVec *restrict v, const void *data);
* @param v The vector to push onto.
* @param data A pointer to the elements of data to push.
*/
-void bc_vec_npush(BcVec *restrict v, size_t n, const void *data);
+void
+bc_vec_npush(BcVec* restrict v, size_t n, const void* data);
/**
* Push an empty element and return a pointer to it. This is done as an
@@ -205,7 +212,8 @@ void bc_vec_npush(BcVec *restrict v, size_t n, const void *data);
* @param v The vector to push onto.
* @return A pointer to the newly-pushed element.
*/
-void* bc_vec_pushEmpty(BcVec *restrict v);
+void*
+bc_vec_pushEmpty(BcVec* restrict v);
/**
* Pushes a byte onto a bytecode vector. This is a convenience function for the
@@ -213,7 +221,8 @@ void* bc_vec_pushEmpty(BcVec *restrict v);
* @param v The vector to push onto.
* @param data The byte to push.
*/
-void bc_vec_pushByte(BcVec *restrict v, uchar data);
+void
+bc_vec_pushByte(BcVec* restrict v, uchar data);
/**
* Pushes and index onto a bytecode vector. The vector must be a bytecode
@@ -222,7 +231,8 @@ void bc_vec_pushByte(BcVec *restrict v, uchar data);
* @param v The vector to push onto.
* @param idx The index to push.
*/
-void bc_vec_pushIndex(BcVec *restrict v, size_t idx);
+void
+bc_vec_pushIndex(BcVec* restrict v, size_t idx);
/**
* Push an item onto the vector at a certain index. The index must be valid
@@ -233,7 +243,8 @@ void bc_vec_pushIndex(BcVec *restrict v, size_t idx);
* @param data A pointer to the data to push.
* @param idx The index to push at.
*/
-void bc_vec_pushAt(BcVec *restrict v, const void *data, size_t idx);
+void
+bc_vec_pushAt(BcVec* restrict v, const void* data, size_t idx);
/**
* Empties the vector and sets it to the string. The vector must be a valid
@@ -243,7 +254,8 @@ void bc_vec_pushAt(BcVec *restrict v, const void *data, size_t idx);
* of the string, but must never be more.
* @param str The string to push.
*/
-void bc_vec_string(BcVec *restrict v, size_t len, const char *restrict str);
+void
+bc_vec_string(BcVec* restrict v, size_t len, const char* restrict str);
/**
* Appends the string to the end of the vector, which must be holding a string
@@ -251,13 +263,15 @@ void bc_vec_string(BcVec *restrict v, size_t len, const char *restrict str);
* @param v The vector to append to.
* @param str The string to append (by copying).
*/
-void bc_vec_concat(BcVec *restrict v, const char *restrict str);
+void
+bc_vec_concat(BcVec* restrict v, const char* restrict str);
/**
* Empties a vector and pushes a nul-byte at the first index. The vector must be
* a char vector.
*/
-void bc_vec_empty(BcVec *restrict v);
+void
+bc_vec_empty(BcVec* restrict v);
#if BC_ENABLE_HISTORY
@@ -268,7 +282,8 @@ void bc_vec_empty(BcVec *restrict v);
* @param idx The index of the item to replace.
* @param data The data to replace the item with.
*/
-void bc_vec_replaceAt(BcVec *restrict v, size_t idx, const void *data);
+void
+bc_vec_replaceAt(BcVec* restrict v, size_t idx, const void* data);
#endif // BC_ENABLE_HISTORY
@@ -279,7 +294,8 @@ void bc_vec_replaceAt(BcVec *restrict v, size_t idx, const void *data);
* @param idx The index to the item to get a pointer to.
* @return A pointer to the item at @a idx.
*/
-void* bc_vec_item(const BcVec *restrict v, size_t idx);
+void*
+bc_vec_item(const BcVec* restrict v, size_t idx);
/**
* Returns a pointer to the item in the vector at the index, reversed. This is
@@ -288,19 +304,22 @@ void* bc_vec_item(const BcVec *restrict v, size_t idx);
* @param idx The index to the item to get a pointer to.
* @return A pointer to the item at len - @a idx - 1.
*/
-void* bc_vec_item_rev(const BcVec *restrict v, size_t idx);
+void*
+bc_vec_item_rev(const BcVec* restrict v, size_t idx);
/**
* Zeros a vector. The vector must not be allocated.
* @param v The vector to clear.
*/
-void bc_vec_clear(BcVec *restrict v);
+void
+bc_vec_clear(BcVec* restrict v);
/**
* Frees a vector and its elements. This is a destructor.
* @param vec A vector as a void pointer.
*/
-void bc_vec_free(void *vec);
+void
+bc_vec_free(void* vec);
/**
* Attempts to insert an item into a map and returns true if it succeeded, false
@@ -313,8 +332,9 @@ void bc_vec_free(void *vec);
* in the map.
* @return True if the item was inserted, false if the item already exists.
*/
-bool bc_map_insert(BcVec *restrict v, const char *name,
- size_t idx, size_t *restrict i);
+bool
+bc_map_insert(BcVec* restrict v, const char* name, size_t idx,
+ size_t* restrict i);
/**
* Returns the index of the item with @a name in the map, or BC_VEC_INVALID_IDX
@@ -324,7 +344,8 @@ bool bc_map_insert(BcVec *restrict v, const char *name,
* @return The index in the map of the item with @a name, or
* BC_VEC_INVALID_IDX if the item does not exist.
*/
-size_t bc_map_index(const BcVec *restrict v, const char *name);
+size_t
+bc_map_index(const BcVec* restrict v, const char* name);
#if DC_ENABLED
@@ -334,7 +355,8 @@ size_t bc_map_index(const BcVec *restrict v, const char *name);
* @param idx The index.
* @return The name of the item at @a idx.
*/
-const char* bc_map_name(const BcVec *restrict v, size_t idx);
+const char*
+bc_map_name(const BcVec* restrict v, size_t idx);
#endif // DC_ENABLED
@@ -372,10 +394,10 @@ extern const BcVecFree bc_vec_dtors[];
#define BC_SLAB_SIZE (4096)
/// A slab for allocating strings.
-typedef struct BcSlab {
-
+typedef struct BcSlab
+{
/// The actual allocation.
- char *s;
+ char* s;
/// How many bytes of the slab are taken.
size_t len;
@@ -386,13 +408,15 @@ typedef struct BcSlab {
* Frees a slab. This is a destructor.
* @param slab The slab as a void pointer.
*/
-void bc_slab_free(void *slab);
+void
+bc_slab_free(void* slab);
/**
* Initializes a slab vector.
* @param v The vector to initialize.
*/
-void bc_slabvec_init(BcVec *restrict v);
+void
+bc_slabvec_init(BcVec* restrict v);
/**
* Duplicates the string using slabs in the slab vector.
@@ -400,7 +424,8 @@ void bc_slabvec_init(BcVec *restrict v);
* @param str The string to duplicate.
* @return A pointer to the duplicated string, owned by the slab vector.
*/
-char* bc_slabvec_strdup(BcVec *restrict v, const char *str);
+char*
+bc_slabvec_strdup(BcVec* restrict v, const char* str);
#if BC_ENABLED
@@ -408,7 +433,8 @@ char* bc_slabvec_strdup(BcVec *restrict v, const char *str);
* Undoes the last allocation on the slab vector. This allows bc to have a
* heap-based stacks for strings. This is used by the bc parser.
*/
-void bc_slabvec_undo(BcVec *restrict v, size_t len);
+void
+bc_slabvec_undo(BcVec* restrict v, size_t len);
#endif // BC_ENABLED
@@ -417,7 +443,8 @@ void bc_slabvec_undo(BcVec *restrict v, size_t len);
* first slab.
* @param v The slab vector to clear.
*/
-void bc_slabvec_clear(BcVec *restrict v);
+void
+bc_slabvec_clear(BcVec* restrict v);
#if BC_DEBUG_CODE
@@ -425,7 +452,8 @@ void bc_slabvec_clear(BcVec *restrict v);
* Prints all of the items in a slab vector, in order.
* @param v The vector whose items will be printed.
*/
-void bc_slabvec_print(BcVec *v, const char *func);
+void
+bc_slabvec_print(BcVec* v, const char* func);
#endif // BC_DEBUG_CODE
diff --git a/include/version.h b/include/version.h
index da98b30bb767..7dc3c053447f 100644
--- a/include/version.h
+++ b/include/version.h
@@ -37,6 +37,6 @@
#define BC_VERSION_H
/// The current version.
-#define VERSION 5.2.5
+#define VERSION 5.3.0
#endif // BC_VERSION_H
diff --git a/include/vm.h b/include/vm.h
index cf7eb5238870..dd4577489467 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -132,52 +132,52 @@
#if DC_ENABLED
/// The flag for the extended register option.
-#define DC_FLAG_X (UINTMAX_C(1)<<0)
+#define DC_FLAG_X (UINTMAX_C(1) << 0)
#endif // DC_ENABLED
#if BC_ENABLED
/// The flag for the POSIX warning option.
-#define BC_FLAG_W (UINTMAX_C(1)<<1)
+#define BC_FLAG_W (UINTMAX_C(1) << 1)
/// The flag for the POSIX error option.
-#define BC_FLAG_S (UINTMAX_C(1)<<2)
+#define BC_FLAG_S (UINTMAX_C(1) << 2)
/// The flag for the math library option.
-#define BC_FLAG_L (UINTMAX_C(1)<<3)
+#define BC_FLAG_L (UINTMAX_C(1) << 3)
/// The flag for the global stacks option.
-#define BC_FLAG_G (UINTMAX_C(1)<<4)
+#define BC_FLAG_G (UINTMAX_C(1) << 4)
#endif // BC_ENABLED
/// The flag for quiet, though this one is reversed; the option clears the flag.
-#define BC_FLAG_Q (UINTMAX_C(1)<<5)
+#define BC_FLAG_Q (UINTMAX_C(1) << 5)
/// The flag for interactive.
-#define BC_FLAG_I (UINTMAX_C(1)<<6)
+#define BC_FLAG_I (UINTMAX_C(1) << 6)
/// The flag for prompt. This is also reversed; the option clears the flag.
-#define BC_FLAG_P (UINTMAX_C(1)<<7)
+#define BC_FLAG_P (UINTMAX_C(1) << 7)
/// The flag for read prompt. This is also reversed; the option clears the flag.
-#define BC_FLAG_R (UINTMAX_C(1)<<8)
+#define BC_FLAG_R (UINTMAX_C(1) << 8)
/// The flag for a leading zero.
-#define BC_FLAG_Z (UINTMAX_C(1)<<9)
+#define BC_FLAG_Z (UINTMAX_C(1) << 9)
/// The flag for stdin being a TTY.
-#define BC_FLAG_TTYIN (UINTMAX_C(1)<<10)
+#define BC_FLAG_TTYIN (UINTMAX_C(1) << 10)
/// The flag for TTY mode.
-#define BC_FLAG_TTY (UINTMAX_C(1)<<11)
+#define BC_FLAG_TTY (UINTMAX_C(1) << 11)
/// The flag for reset on SIGINT.
-#define BC_FLAG_SIGINT (UINTMAX_C(1)<<12)
+#define BC_FLAG_SIGINT (UINTMAX_C(1) << 12)
/// The flag for exiting with expressions.
-#define BC_FLAG_EXPR_EXIT (UINTMAX_C(1)<<13)
+#define BC_FLAG_EXPR_EXIT (UINTMAX_C(1) << 13)
/// A convenience macro for getting the TTYIN flag.
#define BC_TTYIN (vm.flags & BC_FLAG_TTYIN)
@@ -320,18 +320,30 @@
/// Returns the max number of variables that is allowed.
#define BC_MAX_VARS ((ulong) (SIZE_MAX - 1))
+#if BC_ENABLE_LINE_LIB
+
+/// The size of the global buffer.
+#define BC_VM_BUF_SIZE (1 << 10)
+
+/// The amount of the global buffer allocated to stdin.
+#define BC_VM_STDIN_BUF_SIZE (BC_VM_BUF_SIZE - 1)
+
+#else // BC_ENABLE_LINE_LIB
+
/// The size of the global buffer.
-#define BC_VM_BUF_SIZE (1<<12)
+#define BC_VM_BUF_SIZE (1 << 12)
/// The amount of the global buffer allocated to stdout.
-#define BC_VM_STDOUT_BUF_SIZE (1<<11)
+#define BC_VM_STDOUT_BUF_SIZE (1 << 11)
/// The amount of the global buffer allocated to stderr.
-#define BC_VM_STDERR_BUF_SIZE (1<<10)
+#define BC_VM_STDERR_BUF_SIZE (1 << 10)
/// The amount of the global buffer allocated to stdin.
#define BC_VM_STDIN_BUF_SIZE (BC_VM_STDERR_BUF_SIZE - 1)
+#endif // BC_ENABLE_LINE_LIB
+
/// The max number of temporary BcNums that can be kept.
#define BC_VM_MAX_TEMPS (1 << 9)
@@ -360,8 +372,8 @@
/// The global vm struct. This holds all of the global data besides the file
/// buffers.
-typedef struct BcVm {
-
+typedef struct BcVm
+{
/// The current status. This is volatile sig_atomic_t because it is also
/// used in the signal handler. See the development manual
/// (manuals/development.md#async-signal-safe-signal-handling) for more
@@ -443,7 +455,7 @@ typedef struct BcVm {
const char* file;
/// The message printed when SIGINT happens.
- const char *sigmsg;
+ const char* sigmsg;
#endif // !BC_ENABLE_LIBRARY
@@ -515,10 +527,10 @@ typedef struct BcVm {
/// The name of the calculator under use. This is used by BC_IS_BC and
/// BC_IS_DC.
- const char *name;
+ const char* name;
/// The help text for the calculator.
- const char *help;
+ const char* help;
#if BC_ENABLE_HISTORY
@@ -537,17 +549,17 @@ typedef struct BcVm {
BcParseExpr expr;
/// The text to display to label functions in error messages.
- const char *func_header;
+ const char* func_header;
/// The names of the categories of errors.
- const char *err_ids[BC_ERR_IDX_NELEMS + BC_ENABLED];
+ const char* err_ids[BC_ERR_IDX_NELEMS + BC_ENABLED];
/// The messages for each error.
- const char *err_msgs[BC_ERR_NELEMS];
+ const char* err_msgs[BC_ERR_NELEMS];
#if BC_ENABLE_NLS
/// The locale.
- const char *locale;
+ const char* locale;
#endif // BC_ENABLE_NLS
#endif // !BC_ENABLE_LIBRARY
@@ -568,7 +580,7 @@ typedef struct BcVm {
/// A buffer of environment arguments. This is the actual value of the
/// environment variable.
- char *env_args_buffer;
+ char* env_args_buffer;
/// A vector for environment arguments after parsing.
BcVec env_args;
@@ -615,7 +627,7 @@ typedef struct BcVm {
#endif // BC_ENABLE_NLS
/// A pointer to the stdin buffer.
- char *buf;
+ char* buf;
/// The number of items in the input buffer.
size_t buf_len;
@@ -653,44 +665,51 @@ typedef struct BcVm {
* Print the copyright banner and help if it's non-NULL.
* @param help The help message to print if it's non-NULL.
*/
-void bc_vm_info(const char* const help);
+void
+bc_vm_info(const char* const help);
/**
* The entrance point for bc/dc together.
* @param argc The count of arguments.
* @param argv The argument array.
*/
-void bc_vm_boot(int argc, char *argv[]);
+void
+bc_vm_boot(int argc, char* argv[]);
/**
* Initializes some of the BcVm global. This is separate to make things easier
* on the library code.
*/
-void bc_vm_init(void);
+void
+bc_vm_init(void);
/**
* Frees the BcVm global.
*/
-void bc_vm_shutdown(void);
+void
+bc_vm_shutdown(void);
/**
* Add a temp to the temp array.
* @param num The BcDig array to add to the temp array.
*/
-void bc_vm_addTemp(BcDig *num);
+void
+bc_vm_addTemp(BcDig* num);
/**
* Dish out a temp, or NULL if there are none.
* @return A temp, or NULL if none exist.
*/
-BcDig* bc_vm_takeTemp(void);
+BcDig*
+bc_vm_takeTemp(void);
/**
* Frees all temporaries.
*/
-void bc_vm_freeTemps(void);
+void
+bc_vm_freeTemps(void);
-#if !BC_ENABLE_HISTORY
+#if !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB
/**
* Erases the flush argument if history does not exist because it does not
@@ -698,20 +717,22 @@ void bc_vm_freeTemps(void);
*/
#define bc_vm_putchar(c, t) bc_vm_putchar(c)
-#endif // !BC_ENABLE_HISTORY
+#endif // !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB
/**
* Print to stdout with limited formating.
* @param fmt The format string.
*/
-void bc_vm_printf(const char *fmt, ...);
+void
+bc_vm_printf(const char* fmt, ...);
/**
* Puts a char into the stdout buffer.
* @param c The character to put on the stdout buffer.
* @param type The flush type.
*/
-void bc_vm_putchar(int c, BcFlushType type);
+void
+bc_vm_putchar(int c, BcFlushType type);
/**
* Multiplies @a n and @a size and throws an allocation error if overflow
@@ -720,7 +741,8 @@ void bc_vm_putchar(int c, BcFlushType type);
* @param size The size of each element.
* @return The product of @a n and @a size.
*/
-size_t bc_vm_arraySize(size_t n, size_t size);
+size_t
+bc_vm_arraySize(size_t n, size_t size);
/**
* Adds @a a and @a b and throws an error if overflow occurs.
@@ -728,14 +750,16 @@ size_t bc_vm_arraySize(size_t n, size_t size);
* @param b The second operand.
* @return The sum of @a a and @a b.
*/
-size_t bc_vm_growSize(size_t a, size_t b);
+size_t
+bc_vm_growSize(size_t a, size_t b);
/**
* Allocate @a n bytes and throw an allocation error if allocation fails.
* @param n The bytes to allocate.
* @return A pointer to the allocated memory.
*/
-void* bc_vm_malloc(size_t n);
+void*
+bc_vm_malloc(size_t n);
/**
* Reallocate @a ptr to be @a n bytes and throw an allocation error if
@@ -744,48 +768,55 @@ void* bc_vm_malloc(size_t n);
* @param n The bytes to allocate.
* @return A pointer to the reallocated memory.
*/
-void* bc_vm_realloc(void *ptr, size_t n);
+void*
+bc_vm_realloc(void* ptr, size_t n);
/**
* Allocates space for, and duplicates, @a str.
* @param str The string to allocate.
* @return The allocated string.
*/
-char* bc_vm_strdup(const char *str);
+char*
+bc_vm_strdup(const char* str);
/**
* Reads a line from stdin into BcVm's buffer field.
* @param clear True if the buffer should be cleared first, false otherwise.
* @return True if a line was read, false otherwise.
*/
-bool bc_vm_readLine(bool clear);
+bool
+bc_vm_readLine(bool clear);
/**
* Reads a line from the command-line expressions into BcVm's buffer field.
* @param clear True if the buffer should be cleared first, false otherwise.
* @return True if a line was read, false otherwise.
*/
-bool bc_vm_readBuf(bool clear);
+bool
+bc_vm_readBuf(bool clear);
/**
* A convenience and portability function for OpenBSD's pledge().
* @param promises The promises to pledge().
* @param execpromises The exec promises to pledge().
*/
-void bc_pledge(const char *promises, const char *execpromises);
+void
+bc_pledge(const char* promises, const char* execpromises);
/**
* Returns the value of an environment variable.
* @param var The environment variable.
* @return The value of the environment variable.
*/
-char* bc_vm_getenv(const char* var);
+char*
+bc_vm_getenv(const char* var);
/**
* Frees an environment variable value.
* @param val The value to free.
*/
-void bc_vm_getenvFree(char* val);
+void
+bc_vm_getenvFree(char* val);
#if BC_DEBUG_CODE
@@ -793,13 +824,15 @@ void bc_vm_getenvFree(char* val);
* Start executing a jump series.
* @param f The name of the function that started the jump series.
*/
-void bc_vm_jmp(const char *f);
+void
+bc_vm_jmp(const char* f);
#else // BC_DEBUG_CODE
/**
* Start executing a jump series.
*/
-void bc_vm_jmp(void);
+void
+bc_vm_jmp(void);
#endif // BC_DEBUG_CODE
@@ -811,18 +844,21 @@ void bc_vm_jmp(void);
* or no POSIX errors are enabled.
* @param e The error.
*/
-void bc_vm_handleError(BcErr e);
+void
+bc_vm_handleError(BcErr e);
/**
* Handle a fatal error.
* @param e The error.
*/
-void bc_vm_fatalError(BcErr e);
+void
+bc_vm_fatalError(BcErr e);
/**
* A function to call at exit.
*/
-void bc_vm_atexit(void);
+void
+bc_vm_atexit(void);
#else // BC_ENABLE_LIBRARY
@@ -833,7 +869,8 @@ void bc_vm_atexit(void);
* @param e The error.
* @param line The source line where the error occurred.
*/
-void bc_vm_handleError(BcErr e, size_t line, ...);
+void
+bc_vm_handleError(BcErr e, size_t line, ...);
/**
* Handle a fatal error.
@@ -842,13 +879,15 @@ void bc_vm_handleError(BcErr e, size_t line, ...);
#if !BC_ENABLE_MEMCHECK
BC_NORETURN
#endif // !BC_ENABLE_MEMCHECK
-void bc_vm_fatalError(BcErr e);
+void
+bc_vm_fatalError(BcErr e);
/**
* A function to call at exit.
* @param status The exit status.
*/
-int bc_vm_atexit(int status);
+int
+bc_vm_atexit(int status);
#endif // BC_ENABLE_LIBRARY
/// A reference to the copyright header.
@@ -861,7 +900,7 @@ extern const char* const bc_err_line;
extern const char* const bc_err_func_header;
/// A reference to the array of default error category names.
-extern const char *bc_errs[];
+extern const char* bc_errs[];
/// A reference to the array of error category indices for each error.
extern const uchar bc_err_ids[];
diff --git a/manuals/bc/A.1 b/manuals/bc/A.1
index 038932d52ada..f19ed3c9ac78 100644
--- a/manuals/bc/A.1
+++ b/manuals/bc/A.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -38,13 +40,17 @@ bc - arbitrary-precision decimal arithmetic language and calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -287,26 +293,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -382,13 +394,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -435,8 +491,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -1020,8 +1076,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1328,8 +1384,8 @@ when the \f[B]-s\f[R] option, the \f[B]-w\f[R] option, or equivalents
are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1385,7 +1441,8 @@ Functions\f[R] subsection below).
The extended library is \f[I]not\f[R] loaded when the
\f[B]-s\f[R]/\f[B]--standard\f[R] or \f[B]-w\f[R]/\f[B]--warn\f[R]
options are given since they are not part of the library defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
+standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
.PP
The extended library is a \f[B]non-portable extension\f[R].
.TP
@@ -1404,13 +1461,13 @@ Functions\f[R] subsection below).
.TP
\f[B]r(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round half away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
+the rounding mode round half away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
.TP
\f[B]ceil(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
+the rounding mode round away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
.TP
\f[B]f(x)\f[R]
Returns the factorial of the truncated absolute value of \f[B]x\f[R].
@@ -2275,11 +2332,11 @@ subsection of the \f[B]FUNCTIONS\f[R] section).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -2558,8 +2615,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -2646,8 +2702,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -2680,8 +2736,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Command-Line History
@@ -2776,8 +2832,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/A.1.md b/manuals/bc/A.1.md
index 112e98078cf0..6061260ee087 100644
--- a/manuals/bc/A.1.md
+++ b/manuals/bc/A.1.md
@@ -34,14 +34,15 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# SYNOPSIS
-**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -223,23 +224,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -299,12 +306,48 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -350,9 +393,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -805,9 +849,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -1054,7 +1099,9 @@ equivalents are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -1102,7 +1149,8 @@ The [standard][1] defines the following functions for the math library:
The extended library is *not* loaded when the **-s**/**-\-standard** or
**-w**/**-\-warn** options are given since they are not part of the library
-defined by the [standard][1].
+defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
The extended library is a **non-portable extension**.
@@ -1119,12 +1167,14 @@ The extended library is a **non-portable extension**.
**r(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round half away from **0**][3].
+ round half away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
**ceil(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round away from **0**][6].
+ round away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
**f(x)**
@@ -1888,10 +1938,11 @@ The extended library is a **non-portable extension**.
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -2134,8 +2185,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -2215,10 +2266,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -2244,8 +2297,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -2331,9 +2386,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -2349,10 +2405,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/E.1 b/manuals/bc/E.1
index 6ee1e063ebde..d57b8b50c4af 100644
--- a/manuals/bc/E.1
+++ b/manuals/bc/E.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -43,8 +45,8 @@ bc - arbitrary-precision decimal arithmetic language and calculator
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -256,26 +258,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -351,13 +359,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -404,8 +445,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -812,8 +853,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1102,8 +1143,8 @@ All of the functions below are available when the \f[B]-l\f[R] or
\f[B]--mathlib\f[R] command-line flags are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1156,11 +1197,11 @@ Functions\f[R] subsection below).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -1406,8 +1447,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1492,8 +1532,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -1526,8 +1566,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Command-Line History
@@ -1622,8 +1662,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/E.1.md b/manuals/bc/E.1.md
index ba6e44c248c2..6c562cf69d24 100644
--- a/manuals/bc/E.1.md
+++ b/manuals/bc/E.1.md
@@ -39,9 +39,10 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -203,23 +204,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -279,12 +286,39 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -330,9 +364,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -648,9 +683,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -883,7 +919,9 @@ command-line flags are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -929,10 +967,11 @@ The [standard][1] defines the following functions for the math library:
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -1154,8 +1193,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1233,10 +1272,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -1262,8 +1303,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1349,9 +1392,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -1367,10 +1411,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/EH.1 b/manuals/bc/EH.1
index 4509583a0141..95b94ae90e8e 100644
--- a/manuals/bc/EH.1
+++ b/manuals/bc/EH.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -43,8 +45,8 @@ bc - arbitrary-precision decimal arithmetic language and calculator
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -256,26 +258,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -351,13 +359,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -404,8 +445,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -812,8 +853,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1102,8 +1143,8 @@ All of the functions below are available when the \f[B]-l\f[R] or
\f[B]--mathlib\f[R] command-line flags are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1156,11 +1197,11 @@ Functions\f[R] subsection below).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -1406,8 +1447,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1492,8 +1532,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -1526,8 +1566,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Prompt
@@ -1593,8 +1633,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/EH.1.md b/manuals/bc/EH.1.md
index 2178c375cb92..82c3d6c36159 100644
--- a/manuals/bc/EH.1.md
+++ b/manuals/bc/EH.1.md
@@ -39,9 +39,10 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -203,23 +204,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -279,12 +286,39 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -330,9 +364,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -648,9 +683,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -883,7 +919,9 @@ command-line flags are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -929,10 +967,11 @@ The [standard][1] defines the following functions for the math library:
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -1154,8 +1193,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1233,10 +1272,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -1262,8 +1303,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1323,9 +1366,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -1341,10 +1385,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/EHN.1 b/manuals/bc/EHN.1
index 6b49f3651d5a..ca88115a5864 100644
--- a/manuals/bc/EHN.1
+++ b/manuals/bc/EHN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -43,8 +45,8 @@ bc - arbitrary-precision decimal arithmetic language and calculator
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -256,26 +258,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -351,13 +359,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -404,8 +445,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -812,8 +853,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1102,8 +1143,8 @@ All of the functions below are available when the \f[B]-l\f[R] or
\f[B]--mathlib\f[R] command-line flags are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1156,11 +1197,11 @@ Functions\f[R] subsection below).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -1406,8 +1447,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1492,8 +1532,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -1526,8 +1566,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Prompt
@@ -1589,8 +1629,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/EHN.1.md b/manuals/bc/EHN.1.md
index 3b60d3d0251b..d3873ba6ac97 100644
--- a/manuals/bc/EHN.1.md
+++ b/manuals/bc/EHN.1.md
@@ -39,9 +39,10 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -203,23 +204,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -279,12 +286,39 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -330,9 +364,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -648,9 +683,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -883,7 +919,9 @@ command-line flags are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -929,10 +967,11 @@ The [standard][1] defines the following functions for the math library:
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -1154,8 +1193,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1233,10 +1272,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -1262,8 +1303,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1318,9 +1361,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -1333,10 +1377,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/EN.1 b/manuals/bc/EN.1
index c4704807fac6..1f1e60aad093 100644
--- a/manuals/bc/EN.1
+++ b/manuals/bc/EN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -43,8 +45,8 @@ bc - arbitrary-precision decimal arithmetic language and calculator
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -256,26 +258,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -351,13 +359,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -404,8 +445,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -812,8 +853,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1102,8 +1143,8 @@ All of the functions below are available when the \f[B]-l\f[R] or
\f[B]--mathlib\f[R] command-line flags are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1156,11 +1197,11 @@ Functions\f[R] subsection below).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -1406,8 +1447,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1492,8 +1532,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -1526,8 +1566,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Command-Line History
@@ -1618,8 +1658,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/EN.1.md b/manuals/bc/EN.1.md
index 13ad5f8b570a..3ebd10f8ecb5 100644
--- a/manuals/bc/EN.1.md
+++ b/manuals/bc/EN.1.md
@@ -39,9 +39,10 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -203,23 +204,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -279,12 +286,39 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -330,9 +364,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -648,9 +683,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -883,7 +919,9 @@ command-line flags are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -929,10 +967,11 @@ The [standard][1] defines the following functions for the math library:
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -1154,8 +1193,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1233,10 +1272,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -1262,8 +1303,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1344,9 +1387,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -1359,10 +1403,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/H.1 b/manuals/bc/H.1
index f6d555943367..b3e3880b0723 100644
--- a/manuals/bc/H.1
+++ b/manuals/bc/H.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -38,13 +40,17 @@ bc - arbitrary-precision decimal arithmetic language and calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -287,26 +293,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -382,13 +394,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -435,8 +491,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -1020,8 +1076,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1328,8 +1384,8 @@ when the \f[B]-s\f[R] option, the \f[B]-w\f[R] option, or equivalents
are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1385,7 +1441,8 @@ Functions\f[R] subsection below).
The extended library is \f[I]not\f[R] loaded when the
\f[B]-s\f[R]/\f[B]--standard\f[R] or \f[B]-w\f[R]/\f[B]--warn\f[R]
options are given since they are not part of the library defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
+standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
.PP
The extended library is a \f[B]non-portable extension\f[R].
.TP
@@ -1404,13 +1461,13 @@ Functions\f[R] subsection below).
.TP
\f[B]r(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round half away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
+the rounding mode round half away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
.TP
\f[B]ceil(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
+the rounding mode round away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
.TP
\f[B]f(x)\f[R]
Returns the factorial of the truncated absolute value of \f[B]x\f[R].
@@ -2275,11 +2332,11 @@ subsection of the \f[B]FUNCTIONS\f[R] section).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -2558,8 +2615,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -2646,8 +2702,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -2680,8 +2736,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Prompt
@@ -2747,8 +2803,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/H.1.md b/manuals/bc/H.1.md
index 47b17f1188e4..f494e5632967 100644
--- a/manuals/bc/H.1.md
+++ b/manuals/bc/H.1.md
@@ -34,14 +34,15 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# SYNOPSIS
-**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -223,23 +224,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -299,12 +306,48 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -350,9 +393,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -805,9 +849,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -1054,7 +1099,9 @@ equivalents are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -1102,7 +1149,8 @@ The [standard][1] defines the following functions for the math library:
The extended library is *not* loaded when the **-s**/**-\-standard** or
**-w**/**-\-warn** options are given since they are not part of the library
-defined by the [standard][1].
+defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
The extended library is a **non-portable extension**.
@@ -1119,12 +1167,14 @@ The extended library is a **non-portable extension**.
**r(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round half away from **0**][3].
+ round half away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
**ceil(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round away from **0**][6].
+ round away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
**f(x)**
@@ -1888,10 +1938,11 @@ The extended library is a **non-portable extension**.
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -2134,8 +2185,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -2215,10 +2266,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -2244,8 +2297,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -2305,9 +2360,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -2323,10 +2379,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/HN.1 b/manuals/bc/HN.1
index 0687cb263b6e..6235a3b9931c 100644
--- a/manuals/bc/HN.1
+++ b/manuals/bc/HN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -38,13 +40,17 @@ bc - arbitrary-precision decimal arithmetic language and calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -287,26 +293,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -382,13 +394,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -435,8 +491,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -1020,8 +1076,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1328,8 +1384,8 @@ when the \f[B]-s\f[R] option, the \f[B]-w\f[R] option, or equivalents
are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1385,7 +1441,8 @@ Functions\f[R] subsection below).
The extended library is \f[I]not\f[R] loaded when the
\f[B]-s\f[R]/\f[B]--standard\f[R] or \f[B]-w\f[R]/\f[B]--warn\f[R]
options are given since they are not part of the library defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
+standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
.PP
The extended library is a \f[B]non-portable extension\f[R].
.TP
@@ -1404,13 +1461,13 @@ Functions\f[R] subsection below).
.TP
\f[B]r(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round half away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
+the rounding mode round half away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
.TP
\f[B]ceil(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
+the rounding mode round away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
.TP
\f[B]f(x)\f[R]
Returns the factorial of the truncated absolute value of \f[B]x\f[R].
@@ -2275,11 +2332,11 @@ subsection of the \f[B]FUNCTIONS\f[R] section).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -2558,8 +2615,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -2646,8 +2702,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -2680,8 +2736,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Prompt
@@ -2743,8 +2799,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/HN.1.md b/manuals/bc/HN.1.md
index 12ed1c9c5e74..13f085a5cca7 100644
--- a/manuals/bc/HN.1.md
+++ b/manuals/bc/HN.1.md
@@ -34,14 +34,15 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# SYNOPSIS
-**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -223,23 +224,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -299,12 +306,48 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -350,9 +393,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -805,9 +849,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -1054,7 +1099,9 @@ equivalents are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -1102,7 +1149,8 @@ The [standard][1] defines the following functions for the math library:
The extended library is *not* loaded when the **-s**/**-\-standard** or
**-w**/**-\-warn** options are given since they are not part of the library
-defined by the [standard][1].
+defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
The extended library is a **non-portable extension**.
@@ -1119,12 +1167,14 @@ The extended library is a **non-portable extension**.
**r(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round half away from **0**][3].
+ round half away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
**ceil(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round away from **0**][6].
+ round away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
**f(x)**
@@ -1888,10 +1938,11 @@ The extended library is a **non-portable extension**.
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -2134,8 +2185,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -2215,10 +2266,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -2244,8 +2297,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -2300,9 +2355,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -2315,10 +2371,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bc/N.1 b/manuals/bc/N.1
index 40dbad9bb2f2..def2aee98bbc 100644
--- a/manuals/bc/N.1
+++ b/manuals/bc/N.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "BC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH NAME
.PP
bc - arbitrary-precision decimal arithmetic language and calculator
@@ -38,13 +40,17 @@ bc - arbitrary-precision decimal arithmetic language and calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
bc(1) is an interactive processor for a language first standardized in
1991 by POSIX.
-(The current standard is
-here (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).)
+(The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .)
The language provides unlimited precision decimal arithmetic and is
somewhat C-like, but there are differences.
Such differences will be noted in this document.
@@ -287,26 +293,32 @@ multiple times.
Keywords are \f[I]not\f[R] redefined when parsing the builtin math
library (see the \f[B]LIBRARY\f[R] section).
.PP
-It is a fatal error to redefine keywords mandated by the POSIX standard.
+It is a fatal error to redefine keywords mandated by the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
It is a fatal error to attempt to redefine words that this bc(1) does
not reserve as keywords.
.RE
.TP
\f[B]-q\f[R], \f[B]--quiet\f[R]
-This option is for compatibility with the GNU
-bc(1) (https://www.gnu.org/software/bc/); it is a no-op.
+This option is for compatibility with the GNU bc(1)
+(https://www.gnu.org/software/bc/); it is a no-op.
Without this option, GNU bc(1) prints a copyright header.
This bc(1) only prints the copyright header if one or more of the
-\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given.
+\f[B]-v\f[R], \f[B]-V\f[R], or \f[B]--version\f[R] options are given
+unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
+a non-zero integer or if this bc(1) was built with the header displayed
+by default.
+If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
+prevent bc(1) from printing the header.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-s\f[R], \f[B]--standard\f[R]
-Process exactly the language defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-and error if any extensions are used.
+Process exactly the language defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+error if any extensions are used.
.RS
.PP
This is a \f[B]non-portable extension\f[R].
@@ -382,13 +394,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files or expressions are given by the \f[B]-f\f[R],
\f[B]--file\f[R], \f[B]-e\f[R], or \f[B]--expression\f[R] options, then
-bc(1) read from \f[B]stdin\f[R].
+bc(1) reads from \f[B]stdin\f[R].
.PP
However, there are a few caveats to this.
.PP
@@ -435,8 +491,8 @@ redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
.SH SYNTAX
.PP
The syntax for bc(1) programs is mostly C-like, with some differences.
-This bc(1) follows the POSIX
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+This bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
which is a much more thorough resource for the language this bc(1)
accepts.
This section is meant to be a summary and a listing of all the
@@ -1020,8 +1076,8 @@ Note that unlike in C, these operators have a lower precedence than the
\f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
interpreted as \f[B](a=b)>c\f[R].
.PP
-Also, unlike the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+Also, unlike the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
requires, these operators can appear anywhere any other expressions can
be used.
This allowance is a \f[B]non-portable extension\f[R].
@@ -1328,8 +1384,8 @@ when the \f[B]-s\f[R] option, the \f[B]-w\f[R] option, or equivalents
are given.
.SS Standard Library
.PP
-The
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
defines the following functions for the math library:
.TP
\f[B]s(x)\f[R]
@@ -1385,7 +1441,8 @@ Functions\f[R] subsection below).
The extended library is \f[I]not\f[R] loaded when the
\f[B]-s\f[R]/\f[B]--standard\f[R] or \f[B]-w\f[R]/\f[B]--warn\f[R]
options are given since they are not part of the library defined by the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
+standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
.PP
The extended library is a \f[B]non-portable extension\f[R].
.TP
@@ -1404,13 +1461,13 @@ Functions\f[R] subsection below).
.TP
\f[B]r(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round half away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
+the rounding mode round half away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
.TP
\f[B]ceil(x, p)\f[R]
Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
-the rounding mode round away from
-\f[B]0\f[R] (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
+the rounding mode round away from \f[B]0\f[R]
+(https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
.TP
\f[B]f(x)\f[R]
Returns the factorial of the truncated absolute value of \f[B]x\f[R].
@@ -2275,11 +2332,11 @@ subsection of the \f[B]FUNCTIONS\f[R] section).
.RE
.SS Transcendental Functions
.PP
-All transcendental functions can return slightly inaccurate results (up
-to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place)).
-This is unavoidable, and this
-article (https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT) explains
-why it is impossible and unnecessary to calculate exact results for the
+All transcendental functions can return slightly inaccurate results, up
+to 1 ULP (https://en.wikipedia.org/wiki/Unit_in_the_last_place).
+This is unavoidable, and the article at
+https://people.eecs.berkeley.edu/\[ti]wkahan/LOG10HAF.TXT explains why
+it is impossible and unnecessary to calculate exact results for the
transcendental functions.
.PP
Because of the possible inaccuracy, I recommend that users call those
@@ -2558,8 +2615,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
-expressions and expression files, and a non-zero value makes bc(1) not
-exit.
+expressions and expression files, and a zero value makes bc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -2646,8 +2702,8 @@ checking, and its normal behavior can be forced by using the
\f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
.SH INTERACTIVE MODE
.PP
-Per the
-standard (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
bc(1) has an interactive mode and a non-interactive mode.
Interactive mode is turned on automatically when both \f[B]stdin\f[R]
and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
@@ -2680,8 +2736,8 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
+required in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
to be connected to a terminal.
.SS Command-Line History
@@ -2772,8 +2828,8 @@ dc(1)
.SH STANDARDS
.PP
bc(1) is compliant with the IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+(\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
The flags \f[B]-efghiqsvVw\f[R], all long options, and the extensions
noted above are extensions to that specification.
.PP
diff --git a/manuals/bc/N.1.md b/manuals/bc/N.1.md
index 92c239c0b12b..27cc68c8d39a 100644
--- a/manuals/bc/N.1.md
+++ b/manuals/bc/N.1.md
@@ -34,14 +34,15 @@ bc - arbitrary-precision decimal arithmetic language and calculator
# SYNOPSIS
-**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
bc(1) is an interactive processor for a language first standardized in 1991 by
-POSIX. (The current standard is [here][1].) The language provides unlimited
-precision decimal arithmetic and is somewhat C-like, but there are differences.
-Such differences will be noted in this document.
+POSIX. (The current standard is at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
+language provides unlimited precision decimal arithmetic and is somewhat C-like,
+but there are differences. Such differences will be noted in this document.
After parsing and handling options, this bc(1) reads any files given on the
command line and executes them before reading from **stdin**.
@@ -223,23 +224,29 @@ The following are the options that bc(1) accepts.
Keywords are *not* redefined when parsing the builtin math library (see the
**LIBRARY** section).
- It is a fatal error to redefine keywords mandated by the POSIX standard. It
- is a fatal error to attempt to redefine words that this bc(1) does not
- reserve as keywords.
+ It is a fatal error to redefine keywords mandated by the POSIX standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
+ a fatal error to attempt to redefine words that this bc(1) does not reserve
+ as keywords.
**-q**, **-\-quiet**
-: This option is for compatibility with the [GNU bc(1)][2]; it is a no-op.
- Without this option, GNU bc(1) prints a copyright header. This bc(1) only
- prints the copyright header if one or more of the **-v**, **-V**, or
- **-\-version** options are given.
+: This option is for compatibility with the GNU bc(1)
+ (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
+ bc(1) prints a copyright header. This bc(1) only prints the copyright header
+ if one or more of the **-v**, **-V**, or **-\-version** options are given
+ unless the **BC_BANNER** environment variable is set and contains a non-zero
+ integer or if this bc(1) was built with the header displayed by default. If
+ *any* of that is the case, then this option *does* prevent bc(1) from
+ printing the header.
This is a **non-portable extension**.
**-s**, **-\-standard**
-: Process exactly the language defined by the [standard][1] and error if any
- extensions are used.
+: Process exactly the language defined by the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
+ error if any extensions are used.
This is a **non-portable extension**.
@@ -299,12 +306,48 @@ The following are the options that bc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
-**-\-expression** options, then bc(1) read from **stdin**.
+**-\-expression** options, then bc(1) reads from **stdin**.
However, there are a few caveats to this.
@@ -350,9 +393,10 @@ it is recommended that those scripts be changed to redirect **stderr** to
# SYNTAX
The syntax for bc(1) programs is mostly C-like, with some differences. This
-bc(1) follows the [POSIX standard][1], which is a much more thorough resource
-for the language this bc(1) accepts. This section is meant to be a summary and a
-listing of all the extensions to the standard.
+bc(1) follows the POSIX standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
+much more thorough resource for the language this bc(1) accepts. This section is
+meant to be a summary and a listing of all the extensions to the standard.
In the sections below, **E** means expression, **S** means statement, and **I**
means identifier.
@@ -805,9 +849,10 @@ The operators will be described in more detail below.
**assignment** operators, which means that **a=b\>c** is interpreted as
**(a=b)\>c**.
- Also, unlike the [standard][1] requires, these operators can appear anywhere
- any other expressions can be used. This allowance is a
- **non-portable extension**.
+ Also, unlike the standard
+ (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
+ requires, these operators can appear anywhere any other expressions can be
+ used. This allowance is a **non-portable extension**.
**&&**
@@ -1054,7 +1099,9 @@ equivalents are given.
## Standard Library
-The [standard][1] defines the following functions for the math library:
+The standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
+following functions for the math library:
**s(x)**
@@ -1102,7 +1149,8 @@ The [standard][1] defines the following functions for the math library:
The extended library is *not* loaded when the **-s**/**-\-standard** or
**-w**/**-\-warn** options are given since they are not part of the library
-defined by the [standard][1].
+defined by the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html).
The extended library is a **non-portable extension**.
@@ -1119,12 +1167,14 @@ The extended library is a **non-portable extension**.
**r(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round half away from **0**][3].
+ round half away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero).
**ceil(x, p)**
: Returns **x** rounded to **p** decimal places according to the rounding mode
- [round away from **0**][6].
+ round away from **0**
+ (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero).
**f(x)**
@@ -1888,10 +1938,11 @@ The extended library is a **non-portable extension**.
## Transcendental Functions
-All transcendental functions can return slightly inaccurate results (up to 1
-[ULP][4]). This is unavoidable, and [this article][5] explains why it is
-impossible and unnecessary to calculate exact results for the transcendental
-functions.
+All transcendental functions can return slightly inaccurate results, up to 1 ULP
+(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
+the article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
+why it is impossible and unnecessary to calculate exact results for the
+transcendental functions.
Because of the possible inaccuracy, I recommend that users call those functions
with the precision (**scale**) set to at least 1 higher than is necessary. If
@@ -2134,8 +2185,8 @@ bc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes bc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -2215,10 +2266,12 @@ checking, and its normal behavior can be forced by using the **-i** flag or
# INTERACTIVE MODE
-Per the [standard][1], bc(1) has an interactive mode and a non-interactive mode.
-Interactive mode is turned on automatically when both **stdin** and **stdout**
-are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
-turn it on in other situations.
+Per the standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
+an interactive mode and a non-interactive mode. Interactive mode is turned on
+automatically when both **stdin** and **stdout** are hooked to a terminal, but
+the **-i** flag and **-\-interactive** option can turn it on in other
+situations.
In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
section), and in normal execution, flushes **stdout** as soon as execution is
@@ -2244,8 +2297,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) standard
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -2326,9 +2381,10 @@ dc(1)
# STANDARDS
-bc(1) is compliant with the [IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1]
-specification. The flags **-efghiqsvVw**, all long options, and the extensions
-noted above are extensions to that specification.
+bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
+at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
+flags **-efghiqsvVw**, all long options, and the extensions noted above are
+extensions to that specification.
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -2341,10 +2397,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
-[2]: https://www.gnu.org/software/bc/
-[3]: https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
-[4]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
-[5]: https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT
-[6]: https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero
diff --git a/manuals/bcl.3 b/manuals/bcl.3
index 9370417dcfef..c0678722db0c 100644
--- a/manuals/bcl.3
+++ b/manuals/bcl.3
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "BCL" "3" "June 2021" "Gavin D. Howard" "Libraries Manual"
+.TH "BCL" "3" "June 2022" "Gavin D. Howard" "Libraries Manual"
+.nh
+.ad l
.SH NAME
.PP
bcl - library of arbitrary precision decimal arithmetic
@@ -228,9 +230,9 @@ generator in bcl(3).
.SH DESCRIPTION
.PP
bcl(3) is a library that implements arbitrary-precision decimal math, as
-standardized by
-POSIX (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-in bc(1).
+standardized by POSIX
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) in
+bc(1).
.PP
bcl(3) is async-signal-safe if
\f[B]bcl_handleSignal(\f[R]\f[I]void\f[R]\f[B])\f[R] is used properly.
@@ -1376,9 +1378,9 @@ bc(1) and dc(1)
.SH STANDARDS
.PP
bcl(3) is compliant with the arithmetic defined in the IEEE Std
-1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification for bc(1).
+1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.PP
Note that the specification explicitly says that bc(1) only accepts
numbers that use a period (\f[B].\f[R]) as a radix point, regardless of
diff --git a/manuals/bcl.3.md b/manuals/bcl.3.md
index fa630fc79f1a..1f694413f7d6 100644
--- a/manuals/bcl.3.md
+++ b/manuals/bcl.3.md
@@ -215,7 +215,8 @@ generator in bcl(3).
# DESCRIPTION
bcl(3) is a library that implements arbitrary-precision decimal math, as
-[standardized by POSIX][1] in bc(1).
+standardized by POSIX
+(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) in bc(1).
bcl(3) is async-signal-safe if **bcl_handleSignal(**_void_**)** is used
properly. (See the **SIGNAL HANDLING** section.)
@@ -1184,8 +1185,9 @@ bc(1) and dc(1)
# STANDARDS
-bcl(3) is compliant with the arithmetic defined in the
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification for bc(1).
+bcl(3) is compliant with the arithmetic defined in the IEEE Std 1003.1-2017
+(“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
Note that the specification explicitly says that bc(1) only accepts numbers that
use a period (**.**) as a radix point, regardless of the value of
@@ -1198,5 +1200,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHORS
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/build.md b/manuals/build.md
index aa0ed78e2d72..af0b7c15e0c3 100644
--- a/manuals/build.md
+++ b/manuals/build.md
@@ -46,7 +46,7 @@ However, if you wish to build it yourself, this `bc` can be built using Visual
Studio or MSBuild.
Unfortunately, only one build configuration (besides Debug or Release) is
-supported: extra math enabled, history and NLS (locale support) disabled, with
+supported: extra math and history enabled, NLS (locale support) disabled, with
both calculators built. The default [settings][11] are `BC_BANNER=1`,
`{BC,DC}_SIGINT_RESET=0`, `{BC,DC}_TTY_MODE=1`, `{BC,DC}_PROMPT=1`.
@@ -424,15 +424,46 @@ to `configure.sh`, as follows:
Both commands are equivalent.
-History is automatically disabled when building for Windows or on another
-platform that does not support the terminal handling that is required.
-
***WARNING***: Of all of the code in the `bc`, this is the only code that is not
completely portable. If the `bc` does not work on your platform, your first step
should be to retry with history disabled.
This option affects the [build type][7].
+##### Editline
+
+History support can be provided by editline, in order to implement `vi`-like
+keybindings and other features.
+
+To enable editline support pass either the `-e` flag or the `--enable-editline`
+option to `configure.sh`, as follows:
+
+```
+./configure.sh -e
+./configure.sh --enable-editline
+```
+
+Both commands are equivalent.
+
+This is ignored if history is disabled.
+
+##### Readline
+
+History support can be provided by readline, in order to implement `vi`-like
+keybindings and other features.
+
+To enable readline support pass either the `-r` flag or the `--enable-readline`
+option to `configure.sh`, as follows:
+
+```
+./configure.sh -r
+./configure.sh --enable-readline
+```
+
+Both commands are equivalent.
+
+This is ignored if history is disabled.
+
#### NLS (Locale Support)
To disable locale support (use only English), pass either the `-N` flag or the
diff --git a/manuals/dc/A.1 b/manuals/dc/A.1
index 3dff3b16d080..cc1ad0e7bb75 100644
--- a/manuals/dc/A.1
+++ b/manuals/dc/A.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -37,7 +39,11 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
dc(1) is an arbitrary-precision calculator.
@@ -129,7 +135,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +188,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1346,8 +1396,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1456,10 +1505,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Command-Line History
.PP
Command-line history is only enabled if TTY mode is, i.e., that
@@ -1548,10 +1597,10 @@ locales and thus, supports \f[B]LC_MESSAGES\f[R].
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/A.1.md b/manuals/dc/A.1.md
index 618543d7f397..f678c5f5a869 100644
--- a/manuals/dc/A.1.md
+++ b/manuals/dc/A.1.md
@@ -34,7 +34,7 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
# SYNOPSIS
-**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,49 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1195,8 +1231,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1297,8 +1333,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1381,8 +1419,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1391,5 +1430,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/E.1 b/manuals/dc/E.1
index a677bcea0c0c..7f90beac6b1c 100644
--- a/manuals/dc/E.1
+++ b/manuals/dc/E.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -129,7 +131,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +184,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1141,8 +1176,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1249,10 +1283,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Command-Line History
.PP
Command-line history is only enabled if TTY mode is, i.e., that
@@ -1341,10 +1375,10 @@ locales and thus, supports \f[B]LC_MESSAGES\f[R].
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/E.1.md b/manuals/dc/E.1.md
index a138fdb32158..f854cbba874b 100644
--- a/manuals/dc/E.1.md
+++ b/manuals/dc/E.1.md
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,40 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1030,8 +1057,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1130,8 +1157,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1214,8 +1243,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1224,5 +1254,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/EH.1 b/manuals/dc/EH.1
index 97c05ca44094..96cb156e789f 100644
--- a/manuals/dc/EH.1
+++ b/manuals/dc/EH.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -129,7 +131,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +184,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1141,8 +1176,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1249,10 +1283,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Prompt
.PP
If TTY mode is available, then a prompt can be enabled.
@@ -1315,10 +1349,10 @@ locales and thus, supports \f[B]LC_MESSAGES\f[R].
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/EH.1.md b/manuals/dc/EH.1.md
index 459f8ac12e7e..50850226ddbe 100644
--- a/manuals/dc/EH.1.md
+++ b/manuals/dc/EH.1.md
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,40 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1030,8 +1057,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1130,8 +1157,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1191,8 +1220,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1201,5 +1231,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/EHN.1 b/manuals/dc/EHN.1
index 223bd9f08dfa..31e60102b971 100644
--- a/manuals/dc/EHN.1
+++ b/manuals/dc/EHN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -129,7 +131,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +184,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1141,8 +1176,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1249,10 +1283,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Prompt
.PP
If TTY mode is available, then a prompt can be enabled.
@@ -1311,10 +1345,10 @@ exit, and it uses the default handler for all other signals.
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/EHN.1.md b/manuals/dc/EHN.1.md
index 56ac39ed599e..e3b42d4453f6 100644
--- a/manuals/dc/EHN.1.md
+++ b/manuals/dc/EHN.1.md
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,40 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1030,8 +1057,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1130,8 +1157,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1186,8 +1215,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1196,5 +1226,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/EN.1 b/manuals/dc/EN.1
index 8c2d14f57840..d941c130e847 100644
--- a/manuals/dc/EN.1
+++ b/manuals/dc/EN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -129,7 +131,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +184,46 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1141,8 +1176,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1249,10 +1283,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Command-Line History
.PP
Command-line history is only enabled if TTY mode is, i.e., that
@@ -1337,10 +1371,10 @@ section).
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/EN.1.md b/manuals/dc/EN.1.md
index 03836923c00e..fa02ccf4b43f 100644
--- a/manuals/dc/EN.1.md
+++ b/manuals/dc/EN.1.md
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,40 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1030,8 +1057,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1130,8 +1157,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1209,8 +1238,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1219,5 +1249,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/H.1 b/manuals/dc/H.1
index f27358fb7f12..58703e03be34 100644
--- a/manuals/dc/H.1
+++ b/manuals/dc/H.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -37,7 +39,11 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
dc(1) is an arbitrary-precision calculator.
@@ -129,7 +135,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +188,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1346,8 +1396,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1456,10 +1505,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Prompt
.PP
If TTY mode is available, then a prompt can be enabled.
@@ -1522,10 +1571,10 @@ locales and thus, supports \f[B]LC_MESSAGES\f[R].
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/H.1.md b/manuals/dc/H.1.md
index c97cc8b58eef..50111044d265 100644
--- a/manuals/dc/H.1.md
+++ b/manuals/dc/H.1.md
@@ -34,7 +34,7 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
# SYNOPSIS
-**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,49 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1195,8 +1231,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1297,8 +1333,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1358,8 +1396,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1368,5 +1407,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/HN.1 b/manuals/dc/HN.1
index 13a39ef26540..d67e2325817e 100644
--- a/manuals/dc/HN.1
+++ b/manuals/dc/HN.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -37,7 +39,11 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
dc(1) is an arbitrary-precision calculator.
@@ -129,7 +135,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +188,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1346,8 +1396,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1456,10 +1505,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Prompt
.PP
If TTY mode is available, then a prompt can be enabled.
@@ -1518,10 +1567,10 @@ exit, and it uses the default handler for all other signals.
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/HN.1.md b/manuals/dc/HN.1.md
index 47c2a0330ae9..79292243304c 100644
--- a/manuals/dc/HN.1.md
+++ b/manuals/dc/HN.1.md
@@ -34,7 +34,7 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
# SYNOPSIS
-**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,49 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1195,8 +1231,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1297,8 +1333,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Prompt
@@ -1353,8 +1391,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1363,5 +1402,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/manuals/dc/N.1 b/manuals/dc/N.1
index 16f89b7ee2a1..39782bf95e5e 100644
--- a/manuals/dc/N.1
+++ b/manuals/dc/N.1
@@ -25,7 +25,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "DC" "1" "June 2021" "Gavin D. Howard" "General Commands Manual"
+.TH "DC" "1" "June 2022" "Gavin D. Howard" "General Commands Manual"
+.nh
+.ad l
.SH Name
.PP
dc - arbitrary-precision decimal reverse-Polish notation calculator
@@ -37,7 +39,11 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
[\f[B]-e\f[R] \f[I]expr\f[R]]
[\f[B]--expression\f[R]=\f[I]expr\f[R]\&...] [\f[B]-f\f[R]
\f[I]file\f[R]\&...] [\f[B]--file\f[R]=\f[I]file\f[R]\&...]
-[\f[I]file\f[R]\&...]
+[\f[I]file\f[R]\&...] [\f[B]-I\f[R] \f[I]ibase\f[R]]
+[\f[B]--ibase\f[R]=\f[I]ibase\f[R]] [\f[B]-O\f[R] \f[I]obase\f[R]]
+[\f[B]--obase\f[R]=\f[I]obase\f[R]] [\f[B]-S\f[R] \f[I]scale\f[R]]
+[\f[B]--scale\f[R]=\f[I]scale\f[R]] [\f[B]-E\f[R] \f[I]seed\f[R]]
+[\f[B]--seed\f[R]=\f[I]seed\f[R]]
.SH DESCRIPTION
.PP
dc(1) is an arbitrary-precision calculator.
@@ -129,7 +135,7 @@ This is a \f[B]non-portable extension\f[R].
.RE
.TP
\f[B]-z\f[R], \f[B]--leading-zeroes\f[R]
-Makes bc(1) print all numbers greater than \f[B]-1\f[R] and less than
+Makes dc(1) print all numbers greater than \f[B]-1\f[R] and less than
\f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
.RS
.PP
@@ -182,13 +188,57 @@ exit.
.PP
This is a \f[B]non-portable extension\f[R].
.RE
+.TP
+\f[B]-I\f[R] \f[I]ibase\f[R], \f[B]--ibase\f[R]=\f[I]ibase\f[R]
+Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
+assuming that \f[I]ibase\f[R] is in base 10.
+It is a fatal error if \f[I]ibase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-O\f[R] \f[I]obase\f[R], \f[B]--obase\f[R]=\f[I]obase\f[R]
+Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
+assuming that \f[I]obase\f[R] is in base 10.
+It is a fatal error if \f[I]obase\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-S\f[R] \f[I]scale\f[R], \f[B]--scale\f[R]=\f[I]scale\f[R]
+Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
+assuming that \f[I]scale\f[R] is in base 10.
+It is a fatal error if \f[I]scale\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
+.TP
+\f[B]-E\f[R] \f[I]seed\f[R], \f[B]--seed\f[R]=\f[I]seed\f[R]
+Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
+assuming that \f[I]seed\f[R] is in base 10.
+It is a fatal error if \f[I]seed\f[R] is not a valid number.
+.RS
+.PP
+If multiple instances of this option are given, the last is used.
+.PP
+This is a \f[B]non-portable extension\f[R].
+.RE
.PP
All long options are \f[B]non-portable extensions\f[R].
.SH STDIN
.PP
If no files are given on the command-line and no files or expressions
are given by the \f[B]-f\f[R], \f[B]--file\f[R], \f[B]-e\f[R], or
-\f[B]--expression\f[R] options, then dc(1) read from \f[B]stdin\f[R].
+\f[B]--expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
.PP
However, there is a caveat to this.
.PP
@@ -1346,8 +1396,7 @@ If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
-expressions and expression files, and a non-zero value makes dc(1) not
-exit.
+expressions and expression files, and a zero value makes dc(1) not exit.
.RS
.PP
This environment variable overrides the default, which can be queried
@@ -1456,10 +1505,10 @@ The default setting can be queried with the \f[B]-h\f[R] or
\f[B]--help\f[R] options.
.PP
TTY mode is different from interactive mode because interactive mode is
-required in the bc(1)
-specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
-and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
-to be connected to a terminal.
+required in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R] to
+be connected to a terminal.
.SS Command-Line History
.PP
Command-line history is only enabled if TTY mode is, i.e., that
@@ -1544,10 +1593,10 @@ section).
bc(1)
.SH STANDARDS
.PP
-The dc(1) utility operators are compliant with the operators in the
-bc(1) IEEE Std 1003.1-2017
-(\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
-specification.
+The dc(1) utility operators are compliant with the operators in the IEEE
+Std 1003.1-2017 (\[lq]POSIX.1-2017\[rq]) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for
+bc(1).
.SH BUGS
.PP
None are known.
diff --git a/manuals/dc/N.1.md b/manuals/dc/N.1.md
index a14c922b4dbc..25c13b7c2fd4 100644
--- a/manuals/dc/N.1.md
+++ b/manuals/dc/N.1.md
@@ -34,7 +34,7 @@ dc - arbitrary-precision decimal reverse-Polish notation calculator
# SYNOPSIS
-**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
+**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
# DESCRIPTION
@@ -116,7 +116,7 @@ The following are the options that dc(1) accepts.
**-z**, **-\-leading-zeroes**
-: Makes bc(1) print all numbers greater than **-1** and less than **1**, and
+: Makes dc(1) print all numbers greater than **-1** and less than **1**, and
not equal to **0**, with a leading zero.
This can be set for individual numbers with the **plz(x)**, plznl(x)**,
@@ -157,13 +157,49 @@ The following are the options that dc(1) accepts.
This is a **non-portable extension**.
+**-I** *ibase*, **-\-ibase**=*ibase*
+
+: Sets the builtin variable **ibase** to the value *ibase* assuming that
+ *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-O** *obase*, **-\-obase**=*obase*
+
+: Sets the builtin variable **obase** to the value *obase* assuming that
+ *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-S** *scale*, **-\-scale**=*scale*
+
+: Sets the builtin variable **scale** to the value *scale* assuming that
+ *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
+**-E** *seed*, **-\-seed**=*seed*
+
+: Sets the builtin variable **seed** to the value *seed* assuming that *seed*
+ is in base 10. It is a fatal error if *seed* is not a valid number.
+
+ If multiple instances of this option are given, the last is used.
+
+ This is a **non-portable extension**.
+
All long options are **non-portable extensions**.
# STDIN
If no files are given on the command-line and no files or expressions are given
by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
-read from **stdin**.
+reads from **stdin**.
However, there is a caveat to this.
@@ -1195,8 +1231,8 @@ dc(1) recognizes the following environment variables:
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
- after executing the expressions and expression files, and a non-zero value
- makes dc(1) not exit.
+ after executing the expressions and expression files, and a zero value makes
+ dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
@@ -1297,8 +1333,10 @@ setting is used. The default setting can be queried with the **-h** or
**-\-help** options.
TTY mode is different from interactive mode because interactive mode is required
-in the [bc(1) specification][1], and interactive mode requires only **stdin**
-and **stdout** to be connected to a terminal.
+in the bc(1) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
+interactive mode requires only **stdin** and **stdout** to be connected to a
+terminal.
## Command-Line History
@@ -1376,8 +1414,9 @@ bc(1)
# STANDARDS
-The dc(1) utility operators are compliant with the operators in the bc(1)
-[IEEE Std 1003.1-2017 (“POSIX.1-2017”)][1] specification.
+The dc(1) utility operators are compliant with the operators in the IEEE Std
+1003.1-2017 (“POSIX.1-2017”) specification at
+https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
# BUGS
@@ -1386,5 +1425,3 @@ None are known. Report bugs at https://git.yzena.com/gavin/bc.
# AUTHOR
Gavin D. Howard <gavin@yzena.com> and contributors.
-
-[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
diff --git a/scripts/format.sh b/scripts/format.sh
new file mode 100755
index 000000000000..3e399da5777c
--- /dev/null
+++ b/scripts/format.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+#
+# 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.
+#
+
+scriptdir=$(dirname "$0")
+
+cd "$scriptdir/.."
+
+if [ "$#" -gt 0 ]; then
+ files="$@"
+else
+ files=$(find "." -name "*.c" -or -name "*.h")
+fi
+
+for f in $files; do
+
+ case "$f" in
+ *scripts/ministat.c) continue ;;
+ esac
+
+ clang-format -i --style=file "$f"
+ sed -i 's|^#else //|#else //|g' "$f"
+
+done
diff --git a/scripts/functions.sh b/scripts/functions.sh
index 65ec0a1167fe..53778ad4d16b 100755
--- a/scripts/functions.sh
+++ b/scripts/functions.sh
@@ -326,3 +326,97 @@ gen_nlspath() {
# Return the result.
printf '%s' "$_gen_nlspath_nlspath"
}
+
+ALL=0
+NOSKIP=1
+SKIP=2
+
+# Filters text out of a file according to the build type.
+# @param in File to filter.
+# @param out File to write the filtered output to.
+# @param type Build type.
+filter_text() {
+
+ _filter_text_in="$1"
+ shift
+
+ _filter_text_out="$1"
+ shift
+
+ _filter_text_buildtype="$1"
+ shift
+
+ # Set up some local variables.
+ _filter_text_status="$ALL"
+ _filter_text_temp="$_filter_text_out.tmp"
+
+ # We need to set IFS, so we store it here for restoration later.
+ _filter_text_ifs="$IFS"
+
+ # Remove the file- that will be generated.
+ rm -rf "$_filter_text_out" "$_filter_text_temp"
+
+ # Here is the magic. This loop reads the template line-by-line, and based on
+ # _filter_text_status, either prints it to the markdown manual or not.
+ #
+ # Here is how the template is set up: it is a normal markdown file except
+ # that there are sections surrounded tags that look like this:
+ #
+ # {{ <build_type_list> }}
+ # ...
+ # {{ end }}
+ #
+ # Those tags mean that whatever build types are found in the
+ # <build_type_list> get to keep that section. Otherwise, skip.
+ #
+ # Obviously, the tag itself and its end are not printed to the markdown
+ # manual.
+ while IFS= read -r line; do
+
+ # If we have found an end, reset the status.
+ if [ "$line" = "{{ end }}" ]; then
+
+ # Some error checking. This helps when editing the templates.
+ if [ "$_filter_text_status" -eq "$ALL" ]; then
+ err_exit "{{ end }} tag without corresponding start tag" 2
+ fi
+
+ _filter_text_status="$ALL"
+
+ # We have found a tag that allows our build type to use it.
+ elif [ "${line#\{\{* $_filter_text_buildtype *\}\}}" != "$line" ]; then
+
+ # More error checking. We don't want tags nested.
+ if [ "$_filter_text_status" -ne "$ALL" ]; then
+ err_exit "start tag nested in start tag" 3
+ fi
+
+ _filter_text_status="$NOSKIP"
+
+ # We have found a tag that is *not* allowed for our build type.
+ elif [ "${line#\{\{*\}\}}" != "$line" ]; then
+
+ if [ "$_filter_text_status" -ne "$ALL" ]; then
+ err_exit "start tag nested in start tag" 3
+ fi
+
+ _filter_text_status="$SKIP"
+
+ # This is for normal lines. If we are not skipping, print.
+ else
+ if [ "$_filter_text_status" -ne "$SKIP" ]; then
+ printf '%s\n' "$line" >> "$_filter_text_temp"
+ fi
+ fi
+
+ done < "$_filter_text_in"
+
+ # Remove multiple blank lines.
+ uniq "$_filter_text_temp" "$_filter_text_out"
+
+ # Remove the temp file.
+ #rm -rf "$_filter_text_temp"
+
+ # Reset IFS.
+ IFS="$_filter_text_ifs"
+}
diff --git a/scripts/lint.sh b/scripts/lint.sh
new file mode 100755
index 000000000000..65f81c5f6511
--- /dev/null
+++ b/scripts/lint.sh
@@ -0,0 +1,63 @@
+#! /bin/sh
+#
+# 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.
+#
+
+scriptdir=$(dirname "$0")
+
+cd "$scriptdir/.."
+
+if [ "$#" -gt 0 ]; then
+ files="$@"
+else
+ files=$(find "." -name "*.c" -or -name "*.h")
+fi
+
+for f in $files; do
+
+ case "$f" in
+ *scripts/ministat.c) continue ;;
+ esac
+
+ contents=$(clang-tidy --use-color -p ../build "$f" -- -I./include \
+ -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_BSD_SOURCE \
+ -D_GNU_SOURCE -D_DEFAULT_SOURCE 2>&1)
+
+ err="$?"
+
+ if [ ! -z "$contents" ] || [ "$err" -ne 0 ]; then
+
+ printf '%s\n' "$f"
+ printf '%s\n' "$contents"
+ printf '\n'
+
+ if [ "$err" -ne 0 ]; then
+ exit "$err"
+ fi
+ fi
+
+done
diff --git a/src/args.c b/src/args.c
index 5eee96f5b559..64fd02c1d7b8 100644
--- a/src/args.c
+++ b/src/args.c
@@ -47,12 +47,15 @@
#include <read.h>
#include <args.h>
#include <opt.h>
+#include <num.h>
/**
* Adds @a str to the list of expressions to execute later.
* @param str The string to add to the list of expressions.
*/
-static void bc_args_exprs(const char *str) {
+static void
+bc_args_exprs(const char* str)
+{
BC_SIG_ASSERT_LOCKED;
if (vm.exprs.v == NULL) bc_vec_init(&vm.exprs, sizeof(uchar), BC_DTOR_NONE);
bc_vec_concat(&vm.exprs, str);
@@ -64,9 +67,10 @@ static void bc_args_exprs(const char *str) {
* @param file The name of the file whose contents should be added to the list
* of expressions to execute.
*/
-static void bc_args_file(const char *file) {
-
- char *buf;
+static void
+bc_args_file(const char* file)
+{
+ char* buf;
BC_SIG_ASSERT_LOCKED;
@@ -80,6 +84,31 @@ static void bc_args_file(const char *file) {
free(buf);
}
+static BcBigDig
+bc_args_builtin(const char* arg)
+{
+ bool strvalid;
+ BcNum n;
+ BcBigDig res;
+
+ strvalid = bc_num_strValid(arg);
+
+ if (BC_ERR(!strvalid))
+ {
+ bc_verr(BC_ERR_FATAL_ARG, arg);
+ }
+
+ bc_num_init(&n, 0);
+
+ bc_num_parse(&n, arg, 10);
+
+ res = bc_num_bigdig(&n);
+
+ bc_num_free(&n);
+
+ return res;
+}
+
#if BC_ENABLED
/**
@@ -87,18 +116,19 @@ static void bc_args_file(const char *file) {
* throws a fatal error.
* @param keyword The keyword to redefine.
*/
-static void bc_args_redefine(const char *keyword) {
-
+static void
+bc_args_redefine(const char* keyword)
+{
size_t i;
BC_SIG_ASSERT_LOCKED;
- for (i = 0; i < bc_lex_kws_len; ++i) {
-
- const BcLexKeyword *kw = bc_lex_kws + i;
-
- if (!strcmp(keyword, kw->name)) {
+ for (i = 0; i < bc_lex_kws_len; ++i)
+ {
+ const BcLexKeyword* kw = bc_lex_kws + i;
+ if (!strcmp(keyword, kw->name))
+ {
if (BC_LEX_KW_POSIX(kw)) break;
vm.redefined_kws[i] = true;
@@ -112,12 +142,17 @@ static void bc_args_redefine(const char *keyword) {
#endif // BC_ENABLED
-void bc_args(int argc, char *argv[], bool exit_exprs) {
-
+void
+bc_args(int argc, char* argv[], bool exit_exprs, BcBigDig scale)
+{
int c;
size_t i;
bool do_exit = false, version = false;
BcOpt opts;
+ BcBigDig newscale = scale, ibase = BC_BASE, obase = BC_BASE;
+#if BC_ENABLE_EXTRA_MATH
+ char* seed = NULL;
+#endif // BC_ENABLE_EXTRA_MATH
BC_SIG_ASSERT_LOCKED;
@@ -125,15 +160,17 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
// This loop should look familiar to anyone who has used getopt() or
// getopt_long() in C.
- while ((c = bc_opt_parse(&opts, bc_args_lopt)) != -1) {
-
- switch (c) {
-
+ while ((c = bc_opt_parse(&opts, bc_args_lopt)) != -1)
+ {
+ switch (c)
+ {
case 'e':
{
// Barf if not allowed.
if (vm.no_exprs)
+ {
bc_verr(BC_ERR_FATAL_OPTION, "-e (--expression)");
+ }
// Add the expressions and set exit.
bc_args_exprs(opts.optarg);
@@ -146,13 +183,15 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
{
// Figure out if exiting on expressions is disabled.
if (!strcmp(opts.optarg, "-")) vm.no_exprs = true;
- else {
-
+ else
+ {
// Barf if not allowed.
if (vm.no_exprs)
+ {
bc_verr(BC_ERR_FATAL_OPTION, "-f (--file)");
+ }
- // Add the expressions and set exit.
+ // Add the expressions and set exit.
bc_args_file(opts.optarg);
vm.exit_exprs = (exit_exprs || vm.exit_exprs);
}
@@ -173,6 +212,12 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
break;
}
+ case 'I':
+ {
+ ibase = bc_args_builtin(opts.optarg);
+ break;
+ }
+
case 'z':
{
vm.flags |= BC_FLAG_Z;
@@ -185,6 +230,12 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
break;
}
+ case 'O':
+ {
+ obase = bc_args_builtin(opts.optarg);
+ break;
+ }
+
case 'P':
{
vm.flags &= ~(BC_FLAG_P);
@@ -197,6 +248,26 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
break;
}
+ case 'S':
+ {
+ newscale = bc_args_builtin(opts.optarg);
+ break;
+ }
+
+#if BC_ENABLE_EXTRA_MATH
+ case 'E':
+ {
+ if (BC_ERR(!bc_num_strValid(opts.optarg)))
+ {
+ bc_verr(BC_ERR_FATAL_ARG, opts.optarg);
+ }
+
+ seed = opts.optarg;
+
+ break;
+ }
+#endif // BC_ENABLE_EXTRA_MATH
+
#if BC_ENABLED
case 'g':
{
@@ -271,7 +342,8 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
}
if (version) bc_vm_info(NULL);
- if (do_exit) {
+ if (do_exit)
+ {
vm.status = (sig_atomic_t) BC_STATUS_QUIT;
BC_JMP;
}
@@ -282,9 +354,52 @@ void bc_args(int argc, char *argv[], bool exit_exprs) {
// We need to make sure the files list is initialized. We don't want to
// initialize it if there are no files because it's just a waste of memory.
if (opts.optind < (size_t) argc && vm.files.v == NULL)
+ {
bc_vec_init(&vm.files, sizeof(char*), BC_DTOR_NONE);
+ }
// Add all the files to the vector.
for (i = opts.optind; i < (size_t) argc; ++i)
+ {
bc_vec_push(&vm.files, argv + i);
+ }
+
+#if BC_ENABLE_EXTRA_MATH
+ if (seed != NULL)
+ {
+ BcNum n;
+
+ bc_num_init(&n, strlen(seed));
+
+ BC_SIG_UNLOCK;
+
+ bc_num_parse(&n, seed, BC_BASE);
+
+ bc_program_assignSeed(&vm.prog, &n);
+
+ BC_SIG_LOCK;
+
+ bc_num_free(&n);
+ }
+#endif // BC_ENABLE_EXTRA_MATH
+
+ BC_SIG_UNLOCK;
+
+ if (newscale != scale)
+ {
+ bc_program_assignBuiltin(&vm.prog, true, false, newscale);
+ }
+
+ if (obase != BC_BASE)
+ {
+ bc_program_assignBuiltin(&vm.prog, false, true, obase);
+ }
+
+ // This is last to avoid it affecting the value of the others.
+ if (ibase != BC_BASE)
+ {
+ bc_program_assignBuiltin(&vm.prog, false, false, ibase);
+ }
+
+ BC_SIG_LOCK;
}
diff --git a/src/bc.c b/src/bc.c
index 4f35cc42b916..77fa06512dda 100644
--- a/src/bc.c
+++ b/src/bc.c
@@ -45,8 +45,9 @@
* @param argc The number of arguments.
* @param argv The arguments.
*/
-void bc_main(int argc, char *argv[]) {
-
+void
+bc_main(int argc, char* argv[])
+{
// All of these just set bc-specific items in BcVm.
vm.read_ret = BC_INST_RET;
diff --git a/src/bc_lex.c b/src/bc_lex.c
index 4ab17c824b71..1097b92647a6 100644
--- a/src/bc_lex.c
+++ b/src/bc_lex.c
@@ -46,21 +46,22 @@
* Lexes an identifier, which may be a keyword.
* @param l The lexer.
*/
-static void bc_lex_identifier(BcLex *l) {
-
+static void
+bc_lex_identifier(BcLex* l)
+{
// We already passed the first character, so we need to be sure to include
// it.
- const char *buf = l->buf + l->i - 1;
+ const char* buf = l->buf + l->i - 1;
size_t i;
// This loop is simply checking for keywords.
- for (i = 0; i < bc_lex_kws_len; ++i) {
-
- const BcLexKeyword *kw = bc_lex_kws + i;
+ for (i = 0; i < bc_lex_kws_len; ++i)
+ {
+ const BcLexKeyword* kw = bc_lex_kws + i;
size_t n = BC_LEX_KW_LEN(kw);
- if (!strncmp(buf, kw->name, n) && !isalnum(buf[n]) && buf[n] != '_') {
-
+ if (!strncmp(buf, kw->name, n) && !isalnum(buf[n]) && buf[n] != '_')
+ {
// If the keyword has been redefined, and redefinition is allowed
// (it is not allowed for builtin libraries), break out of the loop
// and use it as a name. This depends on the argument parser to
@@ -87,7 +88,9 @@ static void bc_lex_identifier(BcLex *l) {
// POSIX doesn't allow identifiers that are more than one character, so we
// might have to warn or error here too.
if (BC_ERR(l->str.len - 1 > 1))
+ {
bc_lex_verr(l, BC_ERR_POSIX_NAME_LEN, l->str.v);
+ }
}
/**
@@ -95,18 +98,19 @@ static void bc_lex_identifier(BcLex *l) {
* to be balanced.
* @param l The lexer.
*/
-static void bc_lex_string(BcLex *l) {
-
+static void
+bc_lex_string(BcLex* l)
+{
// We need to keep track of newlines to increment them properly.
size_t len, nlines, i;
- const char *buf;
+ const char* buf;
char c;
bool got_more;
l->t = BC_LEX_STR;
- do {
-
+ do
+ {
nlines = 0;
buf = l->buf;
got_more = false;
@@ -115,15 +119,21 @@ static void bc_lex_string(BcLex *l) {
// Fortunately for us, bc doesn't escape quotes. Instead, the equivalent
// is '\q', which makes this loop simpler.
- for (i = l->i; (c = buf[i]) && c != '"'; ++i) nlines += (c == '\n');
+ for (i = l->i; (c = buf[i]) && c != '"'; ++i)
+ {
+ nlines += (c == '\n');
+ }
if (BC_ERR(c == '\0') && !vm.eof && (l->is_stdin || l->is_exprs))
+ {
got_more = bc_lex_readLine(l);
-
- } while (got_more && c != '"');
+ }
+ }
+ while (got_more && c != '"');
// If the string did not end properly, barf.
- if (c != '"') {
+ if (c != '"')
+ {
l->i = i;
bc_lex_err(l, BC_ERR_PARSE_STRING);
}
@@ -143,16 +153,20 @@ static void bc_lex_string(BcLex *l) {
* @param with The token to assign if it is an assignment operator.
* @param without The token to assign if it is not an assignment operator.
*/
-static void bc_lex_assign(BcLex *l, BcLexType with, BcLexType without) {
- if (l->buf[l->i] == '=') {
+static void
+bc_lex_assign(BcLex* l, BcLexType with, BcLexType without)
+{
+ if (l->buf[l->i] == '=')
+ {
l->i += 1;
l->t = with;
}
else l->t = without;
}
-void bc_lex_token(BcLex *l) {
-
+void
+bc_lex_token(BcLex* l)
+{
// We increment here. This means that all lexing needs to take that into
// account, such as when parsing an identifier. If we don't, the first
// character of every identifier would be missing.
@@ -161,8 +175,8 @@ void bc_lex_token(BcLex *l) {
BC_SIG_ASSERT_LOCKED;
// This is the workhorse of the lexer.
- switch (c) {
-
+ switch (c)
+ {
case '\0':
case '\n':
case '\t':
@@ -182,7 +196,9 @@ void bc_lex_token(BcLex *l) {
// POSIX doesn't allow boolean not.
if (l->t == BC_LEX_OP_BOOL_NOT)
+ {
bc_lex_verr(l, BC_ERR_POSIX_BOOL, "!");
+ }
break;
}
@@ -213,8 +229,8 @@ void bc_lex_token(BcLex *l) {
// Either we have boolean and or an error. And boolean and is not
// allowed by POSIX.
- if (BC_NO_ERR(c2 == '&')) {
-
+ if (BC_NO_ERR(c2 == '&'))
+ {
bc_lex_verr(l, BC_ERR_POSIX_BOOL, "&&");
l->i += 1;
@@ -255,7 +271,8 @@ void bc_lex_token(BcLex *l) {
c2 = l->buf[l->i];
// Have to check for increment first.
- if (c2 == '+') {
+ if (c2 == '+')
+ {
l->i += 1;
l->t = BC_LEX_OP_INC;
}
@@ -274,7 +291,8 @@ void bc_lex_token(BcLex *l) {
c2 = l->buf[l->i];
// Have to check for decrement first.
- if (c2 == '-') {
+ if (c2 == '-')
+ {
l->i += 1;
l->t = BC_LEX_OP_DEC;
}
@@ -288,7 +306,8 @@ void bc_lex_token(BcLex *l) {
// If it's alone, it's an alias for last.
if (BC_LEX_NUM_CHAR(c2, true, false)) bc_lex_number(l, c);
- else {
+ else
+ {
l->t = BC_LEX_KW_LAST;
bc_lex_err(l, BC_ERR_POSIX_DOT);
}
@@ -299,7 +318,7 @@ void bc_lex_token(BcLex *l) {
case '/':
{
c2 = l->buf[l->i];
- if (c2 =='*') bc_lex_comment(l);
+ if (c2 == '*') bc_lex_comment(l);
else bc_lex_assign(l, BC_LEX_OP_ASSIGN_DIVIDE, BC_LEX_OP_DIVIDE);
break;
}
@@ -361,7 +380,8 @@ void bc_lex_token(BcLex *l) {
c2 = l->buf[l->i];
// Check for shift.
- if (c2 == '<') {
+ if (c2 == '<')
+ {
l->i += 1;
bc_lex_assign(l, BC_LEX_OP_ASSIGN_LSHIFT, BC_LEX_OP_LSHIFT);
break;
@@ -383,7 +403,8 @@ void bc_lex_token(BcLex *l) {
c2 = l->buf[l->i];
// Check for shift.
- if (c2 == '>') {
+ if (c2 == '>')
+ {
l->i += 1;
bc_lex_assign(l, BC_LEX_OP_ASSIGN_RSHIFT, BC_LEX_OP_RSHIFT);
break;
@@ -403,7 +424,8 @@ void bc_lex_token(BcLex *l) {
case '\\':
{
// In bc, a backslash+newline is whitespace.
- if (BC_NO_ERR(l->buf[l->i] == '\n')) {
+ if (BC_NO_ERR(l->buf[l->i] == '\n'))
+ {
l->i += 1;
l->t = BC_LEX_WHITESPACE;
}
@@ -460,8 +482,8 @@ void bc_lex_token(BcLex *l) {
c2 = l->buf[l->i];
// Once again, boolean or is not allowed by POSIX.
- if (BC_NO_ERR(c2 == '|')) {
-
+ if (BC_NO_ERR(c2 == '|'))
+ {
bc_lex_verr(l, BC_ERR_POSIX_BOOL, "||");
l->i += 1;
diff --git a/src/bc_parse.c b/src/bc_parse.c
index 8849c1b8e9c7..33f98c896398 100644
--- a/src/bc_parse.c
+++ b/src/bc_parse.c
@@ -55,23 +55,31 @@
// compared to this. This is where dreams go to die, where dragons live, and
// from which Ken Thompson himself would flee.
-static void bc_parse_else(BcParse *p);
-static void bc_parse_stmt(BcParse *p);
-static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
- BcParseNext next);
-static void bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next);
+static void
+bc_parse_else(BcParse* p);
+
+static void
+bc_parse_stmt(BcParse* p);
+
+static BcParseStatus
+bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next);
+
+static void
+bc_parse_expr_status(BcParse* p, uint8_t flags, BcParseNext next);
/**
* Returns true if an instruction could only have come from a "leaf" expression.
* For more on what leaf expressions are, read the comment for BC_PARSE_LEAF().
* @param t The instruction to test.
*/
-static bool bc_parse_inst_isLeaf(BcInst t) {
+static bool
+bc_parse_inst_isLeaf(BcInst t)
+{
return (t >= BC_INST_NUM && t <= BC_INST_MAXSCALE) ||
#if BC_ENABLE_EXTRA_MATH
- t == BC_INST_TRUNC ||
+ t == BC_INST_TRUNC ||
#endif // BC_ENABLE_EXTRA_MATH
- t <= BC_INST_DEC;
+ t <= BC_INST_DEC;
}
/**
@@ -81,8 +89,9 @@ static bool bc_parse_inst_isLeaf(BcInst t) {
* @param p The parser.
* @return True if the token is a legal delimiter.
*/
-static bool bc_parse_isDelimiter(const BcParse *p) {
-
+static bool
+bc_parse_isDelimiter(const BcParse* p)
+{
BcLexType t = p->l.t;
bool good;
@@ -94,33 +103,36 @@ static bool bc_parse_isDelimiter(const BcParse *p) {
// If the current token is a keyword, then...beware. That means that we need
// to check for a "dangling" else, where there was no brace-delimited block
// on the previous if.
- if (t == BC_LEX_KW_ELSE) {
-
+ if (t == BC_LEX_KW_ELSE)
+ {
size_t i;
uint16_t *fptr = NULL, flags = BC_PARSE_FLAG_ELSE;
// As long as going up the stack is valid for a dangling else, keep on.
- for (i = 0; i < p->flags.len && BC_PARSE_BLOCK_STMT(flags); ++i) {
-
+ for (i = 0; i < p->flags.len && BC_PARSE_BLOCK_STMT(flags); ++i)
+ {
fptr = bc_vec_item_rev(&p->flags, i);
flags = *fptr;
// If we need a brace and don't have one, then we don't have a
// delimiter.
if ((flags & BC_PARSE_FLAG_BRACE) && p->l.last != BC_LEX_RBRACE)
+ {
return false;
+ }
}
// Oh, and we had also better have an if statement somewhere.
good = ((flags & BC_PARSE_FLAG_IF) != 0);
}
- else if (t == BC_LEX_RBRACE) {
-
+ else if (t == BC_LEX_RBRACE)
+ {
size_t i;
// Since we have a brace, we need to just check if a brace was needed.
- for (i = 0; !good && i < p->flags.len; ++i) {
- uint16_t *fptr = bc_vec_item_rev(&p->flags, i);
+ for (i = 0; !good && i < p->flags.len; ++i)
+ {
+ uint16_t* fptr = bc_vec_item_rev(&p->flags, i);
good = (((*fptr) & BC_PARSE_FLAG_BRACE) != 0);
}
}
@@ -135,8 +147,9 @@ static bool bc_parse_isDelimiter(const BcParse *p) {
* @param p The parser.
* @return True if we are in the top level of parsing a function body.
*/
-static bool bc_parse_TopFunc(const BcParse *p) {
-
+static bool
+bc_parse_TopFunc(const BcParse* p)
+{
bool good = p->flags.len == 2;
uint16_t val = BC_PARSE_FLAG_BRACE | BC_PARSE_FLAG_FUNC_INNER;
@@ -150,11 +163,12 @@ static bool bc_parse_TopFunc(const BcParse *p) {
* section of the Development manual (manuals/development.md).
* @param p The parser.
*/
-static void bc_parse_setLabel(BcParse *p) {
-
- BcFunc *func = p->func;
- BcInstPtr *ip = bc_vec_top(&p->exits);
- size_t *label;
+static void
+bc_parse_setLabel(BcParse* p)
+{
+ BcFunc* func = p->func;
+ BcInstPtr* ip = bc_vec_top(&p->exits);
+ size_t* label;
assert(func == bc_vec_item(&p->prog->fns, p->fidx));
@@ -173,7 +187,9 @@ static void bc_parse_setLabel(BcParse *p) {
* @param p The parser.
* @param idx The index of the label.
*/
-static void bc_parse_createLabel(BcParse *p, size_t idx) {
+static void
+bc_parse_createLabel(BcParse* p, size_t idx)
+{
bc_vec_push(&p->func->labels, &idx);
}
@@ -183,7 +199,9 @@ static void bc_parse_createLabel(BcParse *p, size_t idx) {
* @param p The parser.
* @param idx The index of the label.
*/
-static void bc_parse_createCondLabel(BcParse *p, size_t idx) {
+static void
+bc_parse_createCondLabel(BcParse* p, size_t idx)
+{
bc_parse_createLabel(p, p->func->code.len);
bc_vec_push(&p->conds, &idx);
}
@@ -202,8 +220,9 @@ static void bc_parse_createCondLabel(BcParse *p, size_t idx) {
* @param idx The index of the label's position.
* @param loop True if the exit label is for a loop or not.
*/
-static void bc_parse_createExitLabel(BcParse *p, size_t idx, bool loop) {
-
+static void
+bc_parse_createExitLabel(BcParse* p, size_t idx, bool loop)
+{
BcInstPtr ip;
assert(p->func == bc_vec_item(&p->prog->fns, p->fidx));
@@ -228,16 +247,16 @@ static void bc_parse_createExitLabel(BcParse *p, size_t idx, bool loop) {
* @param nexprs A pointer to the current number of expressions that have not
* been consumed yet. This is an IN and OUT parameter.
*/
-static void bc_parse_operator(BcParse *p, BcLexType type,
- size_t start, size_t *nexprs)
+static void
+bc_parse_operator(BcParse* p, BcLexType type, size_t start, size_t* nexprs)
{
BcLexType t;
uchar l, r = BC_PARSE_OP_PREC(type);
uchar left = BC_PARSE_OP_LEFT(type);
// While we haven't hit the stop point yet.
- while (p->ops.len > start) {
-
+ while (p->ops.len > start)
+ {
// Get the top operator.
t = BC_PARSE_TOP_OP(p);
@@ -270,12 +289,14 @@ static void bc_parse_operator(BcParse *p, BcLexType type,
* @param nexprs A pointer to the current number of expressions that have not
* been consumed yet. This is an IN and OUT parameter.
*/
-static void bc_parse_rightParen(BcParse *p, size_t *nexprs) {
-
+static void
+bc_parse_rightParen(BcParse* p, size_t* nexprs)
+{
BcLexType top;
// Consume operators until a left paren.
- while ((top = BC_PARSE_TOP_OP(p)) != BC_LEX_LPAREN) {
+ while ((top = BC_PARSE_TOP_OP(p)) != BC_LEX_LPAREN)
+ {
bc_parse_push(p, BC_PARSE_TOKEN_INST(top));
bc_vec_pop(&p->ops);
*nexprs -= !BC_PARSE_OP_PREFIX(top);
@@ -294,8 +315,9 @@ static void bc_parse_rightParen(BcParse *p, size_t *nexprs) {
* @param flags Flags restricting what kind of expressions the arguments can
* be.
*/
-static void bc_parse_args(BcParse *p, uint8_t flags) {
-
+static void
+bc_parse_args(BcParse* p, uint8_t flags)
+{
bool comma = false;
size_t nargs;
@@ -307,8 +329,8 @@ static void bc_parse_args(BcParse *p, uint8_t flags) {
flags |= (BC_PARSE_ARRAY | BC_PARSE_NEEDVAL);
// Count the arguments and parse them.
- for (nargs = 0; p->l.t != BC_LEX_RPAREN; ++nargs) {
-
+ for (nargs = 0; p->l.t != BC_LEX_RPAREN; ++nargs)
+ {
bc_parse_expr_status(p, flags, bc_parse_next_arg);
comma = (p->l.t == BC_LEX_COMMA);
@@ -329,8 +351,9 @@ static void bc_parse_args(BcParse *p, uint8_t flags) {
* @param flags Flags restricting what kind of expressions the arguments can
* be.
*/
-static void bc_parse_call(BcParse *p, const char *name, uint8_t flags) {
-
+static void
+bc_parse_call(BcParse* p, const char* name, uint8_t flags)
+{
size_t idx;
bc_parse_args(p, flags);
@@ -345,8 +368,8 @@ static void bc_parse_call(BcParse *p, const char *name, uint8_t flags) {
// The function does not exist yet. Create a space for it. If the user does
// not define it, it's a *runtime* error, not a parse error.
- if (idx == BC_VEC_INVALID_IDX) {
-
+ if (idx == BC_VEC_INVALID_IDX)
+ {
idx = bc_program_insertFunc(p->prog, name);
assert(idx != BC_VEC_INVALID_IDX);
@@ -368,10 +391,10 @@ static void bc_parse_call(BcParse *p, const char *name, uint8_t flags) {
* element, an array itself (for function arguments), a function call, etc.
*
*/
-static void bc_parse_name(BcParse *p, BcInst *type,
- bool *can_assign, uint8_t flags)
+static void
+bc_parse_name(BcParse* p, BcInst* type, bool* can_assign, uint8_t flags)
{
- char *name;
+ char* name;
BC_SIG_ASSERT_LOCKED;
@@ -384,22 +407,24 @@ static void bc_parse_name(BcParse *p, BcInst *type,
bc_lex_next(&p->l);
// Array element or array.
- if (p->l.t == BC_LEX_LBRACKET) {
-
+ if (p->l.t == BC_LEX_LBRACKET)
+ {
bc_lex_next(&p->l);
// Array only. This has to be a function parameter.
- if (p->l.t == BC_LEX_RBRACKET) {
-
+ if (p->l.t == BC_LEX_RBRACKET)
+ {
// Error if arrays are not allowed.
if (BC_ERR(!(flags & BC_PARSE_ARRAY)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
*type = BC_INST_ARRAY;
*can_assign = false;
}
- else {
-
+ else
+ {
// If we are here, we have an array element. We need to set the
// expression parsing flags.
uint8_t flags2 = (flags & ~(BC_PARSE_PRINT | BC_PARSE_REL)) |
@@ -409,7 +434,9 @@ static void bc_parse_name(BcParse *p, BcInst *type,
// The next token *must* be a right bracket.
if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
*type = BC_INST_ARRAY_ELEM;
*can_assign = true;
@@ -422,18 +449,21 @@ static void bc_parse_name(BcParse *p, BcInst *type,
bc_parse_push(p, *type);
bc_parse_pushName(p, name, false);
}
- else if (p->l.t == BC_LEX_LPAREN) {
-
+ else if (p->l.t == BC_LEX_LPAREN)
+ {
// We are parsing a function call; error if not allowed.
if (BC_ERR(flags & BC_PARSE_NOCALL))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
*type = BC_INST_CALL;
*can_assign = false;
bc_parse_call(p, name, flags);
}
- else {
+ else
+ {
// Just a variable.
*type = BC_INST_VAR;
*can_assign = true;
@@ -454,8 +484,9 @@ err:
* @param p The parser.
* @param inst The instruction corresponding to the builtin.
*/
-static void bc_parse_noArgBuiltin(BcParse *p, BcInst inst) {
-
+static void
+bc_parse_noArgBuiltin(BcParse* p, BcInst inst)
+{
// Must have a left paren.
bc_lex_next(&p->l);
if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
@@ -477,13 +508,12 @@ static void bc_parse_noArgBuiltin(BcParse *p, BcInst inst) {
* @param flags The expression parsing flags for parsing the argument.
* @param prev An out parameter; the previous instruction pointer.
*/
-static void bc_parse_builtin(BcParse *p, BcLexType type,
- uint8_t flags, BcInst *prev)
+static void
+bc_parse_builtin(BcParse* p, BcLexType type, uint8_t flags, BcInst* prev)
{
// Must have a left paren.
bc_lex_next(&p->l);
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
@@ -497,8 +527,7 @@ static void bc_parse_builtin(BcParse *p, BcLexType type,
bc_parse_expr_status(p, flags, bc_parse_next_rel);
// Must have a right paren.
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// Adjust previous based on the token and push it.
*prev = type - BC_LEX_KW_LENGTH + BC_INST_LENGTH;
@@ -511,15 +540,14 @@ static void bc_parse_builtin(BcParse *p, BcLexType type,
* Parses a builtin function that takes 3 arguments. This includes modexp() and
* divmod().
*/
-static void bc_parse_builtin3(BcParse *p, BcLexType type,
- uint8_t flags, BcInst *prev)
+static void
+bc_parse_builtin3(BcParse* p, BcLexType type, uint8_t flags, BcInst* prev)
{
assert(type == BC_LEX_KW_MODEXP || type == BC_LEX_KW_DIVMOD);
// Must have a left paren.
bc_lex_next(&p->l);
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
@@ -530,23 +558,21 @@ static void bc_parse_builtin3(BcParse *p, BcLexType type,
bc_parse_expr_status(p, flags, bc_parse_next_builtin);
// Must have a comma.
- if (BC_ERR(p->l.t != BC_LEX_COMMA))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_COMMA)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
bc_parse_expr_status(p, flags, bc_parse_next_builtin);
// Must have a comma.
- if (BC_ERR(p->l.t != BC_LEX_COMMA))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_COMMA)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
// If it is a divmod, parse an array name. Otherwise, just parse another
// expression.
- if (type == BC_LEX_KW_DIVMOD) {
-
+ if (type == BC_LEX_KW_DIVMOD)
+ {
// Must have a name.
if (BC_ERR(p->l.t != BC_LEX_NAME)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
@@ -555,14 +581,18 @@ static void bc_parse_builtin3(BcParse *p, BcLexType type,
// Must have a left bracket.
if (BC_ERR(p->l.t != BC_LEX_LBRACKET))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
// This is safe because the next token should not overwrite the name.
bc_lex_next(&p->l);
// Must have a right bracket.
if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
// This is safe because the next token should not overwrite the name.
bc_lex_next(&p->l);
@@ -570,8 +600,7 @@ static void bc_parse_builtin3(BcParse *p, BcLexType type,
else bc_parse_expr_status(p, flags, bc_parse_next_rel);
// Must have a right paren.
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// Adjust previous based on the token and push it.
*prev = type - BC_LEX_KW_MODEXP + BC_INST_MODEXP;
@@ -579,8 +608,8 @@ static void bc_parse_builtin3(BcParse *p, BcLexType type,
// If we have divmod, we need to assign the modulus to the array element, so
// we need to push the instructions for doing so.
- if (type == BC_LEX_KW_DIVMOD) {
-
+ if (type == BC_LEX_KW_DIVMOD)
+ {
// The zeroth element.
bc_parse_push(p, BC_INST_ZERO);
bc_parse_push(p, BC_INST_ARRAY_ELEM);
@@ -606,14 +635,14 @@ static void bc_parse_builtin3(BcParse *p, BcLexType type,
* to.
* @param flags The expression parsing flags for parsing a scale() arg.
*/
-static void bc_parse_scale(BcParse *p, BcInst *type,
- bool *can_assign, uint8_t flags)
+static void
+bc_parse_scale(BcParse* p, BcInst* type, bool* can_assign, uint8_t flags)
{
bc_lex_next(&p->l);
// Without the left paren, it's just the keyword.
- if (p->l.t != BC_LEX_LPAREN) {
-
+ if (p->l.t != BC_LEX_LPAREN)
+ {
// Set, push, and return.
*type = BC_INST_SCALE;
*can_assign = true;
@@ -634,8 +663,7 @@ static void bc_parse_scale(BcParse *p, BcInst *type,
bc_parse_expr_status(p, flags, bc_parse_next_rel);
// Must have a right paren.
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_parse_push(p, BC_INST_SCALE_FUNC);
@@ -652,8 +680,9 @@ static void bc_parse_scale(BcParse *p, BcInst *type,
* parse tree that are not used.
* @param flags The expression parsing flags for parsing a scale() arg.
*/
-static void bc_parse_incdec(BcParse *p, BcInst *prev, bool *can_assign,
- size_t *nexs, uint8_t flags)
+static void
+bc_parse_incdec(BcParse* p, BcInst* prev, bool* can_assign, size_t* nexs,
+ uint8_t flags)
{
BcLexType type;
uchar inst;
@@ -670,8 +699,8 @@ static void bc_parse_incdec(BcParse *p, BcInst *prev, bool *can_assign,
}
// Is the previous instruction for a variable?
- if (BC_PARSE_INST_VAR(etype)) {
-
+ if (BC_PARSE_INST_VAR(etype))
+ {
// If so, this is a postfix operator.
if (!*can_assign) bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
@@ -681,8 +710,8 @@ static void bc_parse_incdec(BcParse *p, BcInst *prev, bool *can_assign,
bc_lex_next(&p->l);
*can_assign = false;
}
- else {
-
+ else
+ {
// This is a prefix operator. In that case, we just convert it to
// an assignment instruction.
*prev = inst = BC_INST_ASSIGN_PLUS + (p->l.t != BC_LEX_OP_INC);
@@ -695,25 +724,28 @@ static void bc_parse_incdec(BcParse *p, BcInst *prev, bool *can_assign,
*nexs = *nexs + 1;
// Is the next token a normal identifier?
- if (type == BC_LEX_NAME) {
-
+ if (type == BC_LEX_NAME)
+ {
// Parse the name.
uint8_t flags2 = flags & ~BC_PARSE_ARRAY;
bc_parse_name(p, prev, can_assign, flags2 | BC_PARSE_NOCALL);
}
// Is the next token a global?
- else if (type >= BC_LEX_KW_LAST && type <= BC_LEX_KW_OBASE) {
+ else if (type >= BC_LEX_KW_LAST && type <= BC_LEX_KW_OBASE)
+ {
bc_parse_push(p, type - BC_LEX_KW_LAST + BC_INST_LAST);
bc_lex_next(&p->l);
}
// Is the next token specifically scale, which needs special treatment?
- else if (BC_NO_ERR(type == BC_LEX_KW_SCALE)) {
-
+ else if (BC_NO_ERR(type == BC_LEX_KW_SCALE))
+ {
bc_lex_next(&p->l);
// Check that scale() was not used.
if (BC_ERR(p->l.t == BC_LEX_LPAREN))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
else bc_parse_push(p, BC_INST_SCALE);
}
// Now we know we have an error.
@@ -736,8 +768,9 @@ static void bc_parse_incdec(BcParse *p, BcInst *prev, bool *can_assign,
* @param binlast True if the last token was a binary operator.
* @param nexprs An in/out parameter; the number of unused expressions.
*/
-static void bc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
- bool rparen, bool binlast, size_t *nexprs)
+static void
+bc_parse_minus(BcParse* p, BcInst* prev, size_t ops_bgn, bool rparen,
+ bool binlast, size_t* nexprs)
{
BcLexType type;
@@ -759,7 +792,9 @@ static void bc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
* @param inst The instruction corresponding to how the string was found and
* how it should be printed.
*/
-static void bc_parse_str(BcParse *p, BcInst inst) {
+static void
+bc_parse_str(BcParse* p, BcInst inst)
+{
bc_parse_addString(p);
bc_parse_push(p, inst);
bc_lex_next(&p->l);
@@ -769,12 +804,13 @@ static void bc_parse_str(BcParse *p, BcInst inst) {
* Parses a print statement.
* @param p The parser.
*/
-static void bc_parse_print(BcParse *p, BcLexType type) {
-
+static void
+bc_parse_print(BcParse* p, BcLexType type)
+{
BcLexType t;
bool comma = false;
- BcInst inst = type == BC_LEX_KW_STREAM ?
- BC_INST_PRINT_STREAM : BC_INST_PRINT_POP;
+ BcInst inst = type == BC_LEX_KW_STREAM ? BC_INST_PRINT_STREAM :
+ BC_INST_PRINT_POP;
bc_lex_next(&p->l);
@@ -783,12 +819,13 @@ static void bc_parse_print(BcParse *p, BcLexType type) {
// A print or stream statement has to have *something*.
if (bc_parse_isDelimiter(p)) bc_parse_err(p, BC_ERR_PARSE_PRINT);
- do {
-
+ do
+ {
// If the token is a string, then print it with escapes.
// BC_INST_PRINT_POP plays that role for bc.
if (t == BC_LEX_STR) bc_parse_str(p, inst);
- else {
+ else
+ {
// We have an actual number; parse and add a print instruction.
bc_parse_expr_status(p, BC_PARSE_NEEDVAL, bc_parse_next_print);
bc_parse_push(p, inst);
@@ -799,17 +836,16 @@ static void bc_parse_print(BcParse *p, BcLexType type) {
// Get the next token if we have a comma.
if (comma) bc_lex_next(&p->l);
- else {
-
+ else
+ {
// If we don't have a comma, the statement needs to end.
- if (!bc_parse_isDelimiter(p))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (!bc_parse_isDelimiter(p)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
else break;
}
t = p->l.t;
-
- } while (true);
+ }
+ while (true);
// If we have a comma but no token, that's bad.
if (BC_ERR(comma)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
@@ -819,8 +855,9 @@ static void bc_parse_print(BcParse *p, BcLexType type) {
* Parses a return statement.
* @param p The parser.
*/
-static void bc_parse_return(BcParse *p) {
-
+static void
+bc_parse_return(BcParse* p)
+{
BcLexType t;
bool paren;
uchar inst = BC_INST_RET0;
@@ -838,28 +875,33 @@ static void bc_parse_return(BcParse *p) {
// An empty return statement just needs to push the selected instruction.
if (bc_parse_isDelimiter(p)) bc_parse_push(p, inst);
- else {
-
+ else
+ {
BcParseStatus s;
// Need to parse the expression whose value will be returned.
s = bc_parse_expr_err(p, BC_PARSE_NEEDVAL, bc_parse_next_expr);
// If the expression was empty, just push the selected instruction.
- if (s == BC_PARSE_STATUS_EMPTY_EXPR) {
+ if (s == BC_PARSE_STATUS_EMPTY_EXPR)
+ {
bc_parse_push(p, inst);
bc_lex_next(&p->l);
}
// POSIX requires parentheses.
- if (!paren || p->l.last != BC_LEX_RPAREN) {
+ if (!paren || p->l.last != BC_LEX_RPAREN)
+ {
bc_parse_err(p, BC_ERR_POSIX_RET);
}
// Void functions require an empty expression.
- if (BC_ERR(p->func->voidfn)) {
+ if (BC_ERR(p->func->voidfn))
+ {
if (s != BC_PARSE_STATUS_EMPTY_EXPR)
+ {
bc_parse_verr(p, BC_ERR_PARSE_RET_VOID, p->func->name);
+ }
}
// If we got here, we want to be sure to end the function with a real
// return instruction, just in case.
@@ -872,8 +914,10 @@ static void bc_parse_return(BcParse *p) {
* the jump location.
* @param p The parser.
*/
-static void bc_parse_noElse(BcParse *p) {
- uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
+static void
+bc_parse_noElse(BcParse* p)
+{
+ uint16_t* flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
*flag_ptr = (*flag_ptr & ~(BC_PARSE_FLAG_IF_END));
bc_parse_setLabel(p);
}
@@ -883,15 +927,16 @@ static void bc_parse_noElse(BcParse *p) {
* @param p The parser.
* @param brace True if the body was ended by a brace, false otherwise.
*/
-static void bc_parse_endBody(BcParse *p, bool brace) {
-
+static void
+bc_parse_endBody(BcParse* p, bool brace)
+{
bool has_brace, new_else = false;
// We cannot be ending a body if there are no bodies to end.
if (BC_ERR(p->flags.len <= 1)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
- if (brace) {
-
+ if (brace)
+ {
// The brace was already gotten; make sure that the caller did not lie.
// We check for the requirement of braces later.
assert(p->l.t == BC_LEX_RBRACE);
@@ -900,13 +945,16 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
// If the next token is not a delimiter, that is a problem.
if (BC_ERR(!bc_parse_isDelimiter(p) && !bc_parse_TopFunc(p)))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
}
// Do we have a brace flag?
has_brace = (BC_PARSE_BRACE(p) != 0);
- do {
+ do
+ {
size_t len = p->flags.len;
bool loop;
@@ -917,12 +965,12 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
loop = (BC_PARSE_LOOP_INNER(p) != 0);
// If we are ending a loop or an else...
- if (loop || BC_PARSE_ELSE(p)) {
-
+ if (loop || BC_PARSE_ELSE(p))
+ {
// Loops have condition labels that we have to take care of as well.
- if (loop) {
-
- size_t *label = bc_vec_top(&p->conds);
+ if (loop)
+ {
+ size_t* label = bc_vec_top(&p->conds);
bc_parse_push(p, BC_INST_JUMP);
bc_parse_pushIndex(p, *label);
@@ -934,7 +982,8 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
bc_vec_pop(&p->flags);
}
// If we are ending a function...
- else if (BC_PARSE_FUNC_INNER(p)) {
+ else if (BC_PARSE_FUNC_INNER(p))
+ {
BcInst inst = (p->func->voidfn ? BC_INST_RET_VOID : BC_INST_RET0);
bc_parse_push(p, inst);
bc_parse_updateFunc(p, BC_PROG_MAIN);
@@ -945,17 +994,20 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
else if (has_brace && !BC_PARSE_IF(p)) bc_vec_pop(&p->flags);
// This needs to be last to parse nested if's properly.
- if (BC_PARSE_IF(p) && (len == p->flags.len || !BC_PARSE_BRACE(p))) {
-
+ if (BC_PARSE_IF(p) && (len == p->flags.len || !BC_PARSE_BRACE(p)))
+ {
// Eat newlines.
- while (p->l.t == BC_LEX_NLINE) bc_lex_next(&p->l);
+ while (p->l.t == BC_LEX_NLINE)
+ {
+ bc_lex_next(&p->l);
+ }
// *Now* we can pop the flags.
bc_vec_pop(&p->flags);
// If we are allowed non-POSIX stuff...
- if (!BC_S) {
-
+ if (!BC_S)
+ {
// Have we found yet another dangling else?
*(BC_PARSE_TOP_FLAG_PTR(p)) |= BC_PARSE_FLAG_IF_END;
new_else = (p->l.t == BC_LEX_KW_ELSE);
@@ -963,7 +1015,9 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
// Parse the else or end the if statement body.
if (new_else) bc_parse_else(p);
else if (!has_brace && (!BC_PARSE_IF_END(p) || brace))
+ {
bc_parse_noElse(p);
+ }
}
// POSIX requires us to do the bare minimum only.
else bc_parse_noElse(p);
@@ -971,20 +1025,19 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
// If these are both true, we have "used" the braces that we found.
if (brace && has_brace) brace = false;
-
- // This condition was perhaps the hardest single part of the parser. If the
- // flags stack does not have enough, we should stop. If we have a new else
- // statement, we should stop. If we do have the end of an if statement and
- // we have eaten the brace, we should stop. If we do have a brace flag, we
- // should stop.
- } while (p->flags.len > 1 && !new_else && (!BC_PARSE_IF_END(p) || brace) &&
- !(has_brace = (BC_PARSE_BRACE(p) != 0)));
+ }
+ // This condition was perhaps the hardest single part of the parser. If
+ // the flags stack does not have enough, we should stop. If we have a
+ // new else statement, we should stop. If we do have the end of an if
+ // statement and we have eaten the brace, we should stop. If we do have
+ // a brace flag, we should stop.
+ while (p->flags.len > 1 && !new_else && (!BC_PARSE_IF_END(p) || brace) &&
+ !(has_brace = (BC_PARSE_BRACE(p) != 0)));
// If we have a brace, yet no body for it, that's a problem.
- if (BC_ERR(p->flags.len == 1 && brace))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
- else if (brace && BC_PARSE_BRACE(p)) {
-
+ if (BC_ERR(p->flags.len == 1 && brace)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ else if (brace && BC_PARSE_BRACE(p))
+ {
// If we make it here, we have a brace and a flag for it.
uint16_t flags = BC_PARSE_TOP_FLAG(p);
@@ -1004,15 +1057,18 @@ static void bc_parse_endBody(BcParse *p, bool brace) {
* @param p The parser.
* @param flags The current flags (will be edited).
*/
-static void bc_parse_startBody(BcParse *p, uint16_t flags) {
+static void
+bc_parse_startBody(BcParse* p, uint16_t flags)
+{
assert(flags);
flags |= (BC_PARSE_TOP_FLAG(p) & (BC_PARSE_FLAG_FUNC | BC_PARSE_FLAG_LOOP));
flags |= BC_PARSE_FLAG_BODY;
bc_vec_push(&p->flags, &flags);
}
-void bc_parse_endif(BcParse *p) {
-
+void
+bc_parse_endif(BcParse* p)
+{
size_t i;
bool good;
@@ -1023,14 +1079,15 @@ void bc_parse_endif(BcParse *p) {
// Find an instance of a body that needs closing, i.e., a statement that did
// not have a right brace when it should have.
- for (i = 0; good && i < p->flags.len; ++i) {
+ for (i = 0; good && i < p->flags.len; ++i)
+ {
uint16_t flag = *((uint16_t*) bc_vec_item(&p->flags, i));
good = ((flag & BC_PARSE_FLAG_BRACE) != BC_PARSE_FLAG_BRACE);
}
// If we did not find such an instance...
- if (good) {
-
+ if (good)
+ {
// We set this to restore it later. We don't want the parser thinking
// that we are on stdin for this one because it will want more.
bool is_stdin = vm.is_stdin;
@@ -1038,7 +1095,8 @@ void bc_parse_endif(BcParse *p) {
vm.is_stdin = false;
// End all of the if statements and loops.
- while (p->flags.len > 1 || BC_PARSE_IF_END(p)) {
+ while (p->flags.len > 1 || BC_PARSE_IF_END(p))
+ {
if (BC_PARSE_IF_END(p)) bc_parse_noElse(p);
if (p->flags.len > 1) bc_parse_endBody(p, false);
}
@@ -1053,24 +1111,23 @@ void bc_parse_endif(BcParse *p) {
* Parses an if statement.
* @param p The parser.
*/
-static void bc_parse_if(BcParse *p) {
-
+static void
+bc_parse_if(BcParse* p)
+{
// We are allowed relational operators, and we must have a value.
size_t idx;
uint8_t flags = (BC_PARSE_REL | BC_PARSE_NEEDVAL);
// Get the left paren and barf if necessary.
bc_lex_next(&p->l);
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// Parse the condition.
bc_lex_next(&p->l);
bc_parse_expr_status(p, flags, bc_parse_next_rel);
// Must have a right paren.
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
@@ -1091,13 +1148,13 @@ static void bc_parse_if(BcParse *p) {
* Parses an else statement.
* @param p The parser.
*/
-static void bc_parse_else(BcParse *p) {
-
+static void
+bc_parse_else(BcParse* p)
+{
size_t idx = p->func->labels.len;
// We must be at the end of an if statement.
- if (BC_ERR(!BC_PARSE_IF_END(p)))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(!BC_PARSE_IF_END(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// Push an unconditional jump to make bc jump over the else statement if it
// executed the original if statement.
@@ -1119,16 +1176,16 @@ static void bc_parse_else(BcParse *p) {
* Parse a while loop.
* @param p The parser.
*/
-static void bc_parse_while(BcParse *p) {
-
+static void
+bc_parse_while(BcParse* p)
+{
// We are allowed relational operators, and we must have a value.
size_t idx;
uint8_t flags = (BC_PARSE_REL | BC_PARSE_NEEDVAL);
// Get the left paren and barf if necessary.
bc_lex_next(&p->l);
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
// Create the labels. Loops need both.
@@ -1138,8 +1195,7 @@ static void bc_parse_while(BcParse *p) {
// Parse the actual condition and barf on non-right paren.
bc_parse_expr_status(p, flags, bc_parse_next_rel);
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
// Now we can push the conditional jump and start the body.
@@ -1152,20 +1208,19 @@ static void bc_parse_while(BcParse *p) {
* Parse a for loop.
* @param p The parser.
*/
-static void bc_parse_for(BcParse *p) {
-
+static void
+bc_parse_for(BcParse* p)
+{
size_t cond_idx, exit_idx, body_idx, update_idx;
// Barf on the missing left paren.
bc_lex_next(&p->l);
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
// The first statement can be empty, but if it is, check for error in POSIX
// mode. Otherwise, parse it.
- if (p->l.t != BC_LEX_SCOLON)
- bc_parse_expr_status(p, 0, bc_parse_next_for);
+ if (p->l.t != BC_LEX_SCOLON) bc_parse_expr_status(p, 0, bc_parse_next_for);
else bc_parse_err(p, BC_ERR_POSIX_FOR);
// Must have a semicolon.
@@ -1185,12 +1240,13 @@ static void bc_parse_for(BcParse *p) {
bc_parse_createLabel(p, p->func->code.len);
// Parse an expression if it exists.
- if (p->l.t != BC_LEX_SCOLON) {
+ if (p->l.t != BC_LEX_SCOLON)
+ {
uint8_t flags = (BC_PARSE_REL | BC_PARSE_NEEDVAL);
bc_parse_expr_status(p, flags, bc_parse_next_for);
}
- else {
-
+ else
+ {
// Set this for the next call to bc_parse_number because an empty
// condition means that it is an infinite loop, so the condition must be
// non-zero. This is safe to set because the current token is a
@@ -1203,8 +1259,7 @@ static void bc_parse_for(BcParse *p) {
}
// Must have a semicolon.
- if (BC_ERR(p->l.t != BC_LEX_SCOLON))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_SCOLON)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
bc_lex_next(&p->l);
// Now we can set up the conditional jump to the exit and an unconditional
@@ -1220,13 +1275,11 @@ static void bc_parse_for(BcParse *p) {
bc_parse_createCondLabel(p, update_idx);
// Parse if not empty, and if it is, let POSIX yell if necessary.
- if (p->l.t != BC_LEX_RPAREN)
- bc_parse_expr_status(p, 0, bc_parse_next_rel);
+ if (p->l.t != BC_LEX_RPAREN) bc_parse_expr_status(p, 0, bc_parse_next_rel);
else bc_parse_err(p, BC_ERR_POSIX_FOR);
// Must have a right paren.
- if (BC_ERR(p->l.t != BC_LEX_RPAREN))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// Set up a jump to the condition right after the update code.
bc_parse_push(p, BC_INST_JUMP);
@@ -1245,17 +1298,18 @@ static void bc_parse_for(BcParse *p) {
* @param p The parser.
* @param type The type of exit.
*/
-static void bc_parse_loopExit(BcParse *p, BcLexType type) {
-
+static void
+bc_parse_loopExit(BcParse* p, BcLexType type)
+{
size_t i;
- BcInstPtr *ip;
+ BcInstPtr* ip;
// Must have a loop. If we don't, that's an error.
if (BC_ERR(!BC_PARSE_LOOP(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
// If we have a break statement...
- if (type == BC_LEX_KW_BREAK) {
-
+ if (type == BC_LEX_KW_BREAK)
+ {
// If there are no exits, something went wrong somewhere.
if (BC_ERR(!p->exits.len)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
@@ -1265,7 +1319,11 @@ static void bc_parse_loopExit(BcParse *p, BcLexType type) {
// The condition !ip->func is true if the exit is not for a loop, so we
// need to find the first actual loop exit.
- while (!ip->func && i < p->exits.len) ip = bc_vec_item(&p->exits, i--);
+ while (!ip->func && i < p->exits.len)
+ {
+ ip = bc_vec_item(&p->exits, i);
+ i -= 1;
+ }
// Make sure everything is hunky dory.
assert(ip != NULL && (i < p->exits.len || ip->func));
@@ -1288,8 +1346,9 @@ static void bc_parse_loopExit(BcParse *p, BcLexType type) {
* Parse a function (header).
* @param p The parser.
*/
-static void bc_parse_func(BcParse *p) {
-
+static void
+bc_parse_func(BcParse* p)
+{
bool comma = false, voidfn;
uint16_t flags;
size_t idx;
@@ -1311,8 +1370,8 @@ static void bc_parse_func(BcParse *p) {
voidfn = (voidfn && p->l.t == BC_LEX_NAME);
// With a void function, allow POSIX to complain and get a new token.
- if (voidfn) {
-
+ if (voidfn)
+ {
bc_parse_err(p, BC_ERR_POSIX_VOID);
// We can safely do this because the expected token should not overwrite
@@ -1321,8 +1380,7 @@ static void bc_parse_func(BcParse *p) {
}
// Must have a left paren.
- if (BC_ERR(p->l.t != BC_LEX_LPAREN))
- bc_parse_err(p, BC_ERR_PARSE_FUNC);
+ if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
// Make sure the functions map and vector are synchronized.
assert(p->prog->fns.len == p->prog->fn_map.len);
@@ -1340,13 +1398,13 @@ static void bc_parse_func(BcParse *p) {
bc_lex_next(&p->l);
// While we do not have a right paren, we are still parsing arguments.
- while (p->l.t != BC_LEX_RPAREN) {
-
+ while (p->l.t != BC_LEX_RPAREN)
+ {
BcType t = BC_TYPE_VAR;
// If we have an asterisk, we are parsing a reference argument.
- if (p->l.t == BC_LEX_OP_MULTIPLY) {
-
+ if (p->l.t == BC_LEX_OP_MULTIPLY)
+ {
t = BC_TYPE_REF;
bc_lex_next(&p->l);
@@ -1355,8 +1413,7 @@ static void bc_parse_func(BcParse *p) {
}
// If we don't have a name, the argument will not have a name. Barf.
- if (BC_ERR(p->l.t != BC_LEX_NAME))
- bc_parse_err(p, BC_ERR_PARSE_FUNC);
+ if (BC_ERR(p->l.t != BC_LEX_NAME)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
// Increment the number of parameters.
p->func->nparams += 1;
@@ -1367,8 +1424,8 @@ static void bc_parse_func(BcParse *p) {
bc_lex_next(&p->l);
// We are parsing an array parameter if this is true.
- if (p->l.t == BC_LEX_LBRACKET) {
-
+ if (p->l.t == BC_LEX_LBRACKET)
+ {
// Set the array type, unless we are already parsing a reference.
if (t == BC_TYPE_VAR) t = BC_TYPE_ARRAY;
@@ -1376,14 +1433,18 @@ static void bc_parse_func(BcParse *p) {
// The brackets *must* be empty.
if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
+ {
bc_parse_err(p, BC_ERR_PARSE_FUNC);
+ }
bc_lex_next(&p->l);
}
// If we did *not* get a bracket, but we are expecting a reference, we
// have a problem.
else if (BC_ERR(t == BC_TYPE_REF))
+ {
bc_parse_verr(p, BC_ERR_PARSE_REF_VAR, p->buf.v);
+ }
// Test for comma and get the next token if it exists.
comma = (p->l.t == BC_LEX_COMMA);
@@ -1411,8 +1472,9 @@ static void bc_parse_func(BcParse *p) {
* Parse an auto list.
* @param p The parser.
*/
-static void bc_parse_auto(BcParse *p) {
-
+static void
+bc_parse_auto(BcParse* p)
+{
bool comma, one;
// Error if the auto keyword appeared in the wrong place.
@@ -1425,8 +1487,8 @@ static void bc_parse_auto(BcParse *p) {
one = (p->l.t == BC_LEX_NAME);
// While we have a variable or array.
- while (p->l.t == BC_LEX_NAME) {
-
+ while (p->l.t == BC_LEX_NAME)
+ {
BcType t;
// Copy the name from the lexer, so we can use it again.
@@ -1435,15 +1497,17 @@ static void bc_parse_auto(BcParse *p) {
bc_lex_next(&p->l);
// If we are parsing an array...
- if (p->l.t == BC_LEX_LBRACKET) {
-
+ if (p->l.t == BC_LEX_LBRACKET)
+ {
t = BC_TYPE_ARRAY;
bc_lex_next(&p->l);
// The brackets *must* be empty.
if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
+ {
bc_parse_err(p, BC_ERR_PARSE_FUNC);
+ }
bc_lex_next(&p->l);
}
@@ -1464,8 +1528,7 @@ static void bc_parse_auto(BcParse *p) {
if (BC_ERR(!one)) bc_parse_err(p, BC_ERR_PARSE_NO_AUTO);
// The auto statement should be all that's in the statement.
- if (BC_ERR(!bc_parse_isDelimiter(p)))
- bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ if (BC_ERR(!bc_parse_isDelimiter(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
}
/**
@@ -1473,9 +1536,10 @@ static void bc_parse_auto(BcParse *p) {
* @param p The parser.
* @param brace True if a brace was encountered, false otherwise.
*/
-static void bc_parse_body(BcParse *p, bool brace) {
-
- uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
+static void
+bc_parse_body(BcParse* p, bool brace)
+{
+ uint16_t* flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
assert(flag_ptr != NULL);
assert(p->flags.len >= 2);
@@ -1486,15 +1550,15 @@ static void bc_parse_body(BcParse *p, bool brace) {
// If we are inside a function, that means we just barely entered it, and
// we can expect an auto list.
- if (*flag_ptr & BC_PARSE_FLAG_FUNC_INNER) {
-
+ if (*flag_ptr & BC_PARSE_FLAG_FUNC_INNER)
+ {
// We *must* have a brace in this case.
if (BC_ERR(!brace)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
p->auto_part = (p->l.t != BC_LEX_KW_AUTO);
- if (!p->auto_part) {
-
+ if (!p->auto_part)
+ {
// Make sure this is true to not get a parse error.
p->auto_part = true;
@@ -1505,8 +1569,8 @@ static void bc_parse_body(BcParse *p, bool brace) {
// Eat a newline.
if (p->l.t == BC_LEX_NLINE) bc_lex_next(&p->l);
}
- else {
-
+ else
+ {
// This is the easy part.
size_t len = p->flags.len;
@@ -1520,7 +1584,9 @@ static void bc_parse_body(BcParse *p, bool brace) {
// have a body that was not delimited by braces, so we need to end it
// now, after just one statement.
if (!brace && !BC_PARSE_BODY(p) && len <= p->flags.len)
+ {
bc_parse_endBody(p, false);
+ }
}
}
@@ -1529,20 +1595,23 @@ static void bc_parse_body(BcParse *p, bool brace) {
* function definitions.
* @param p The parser.
*/
-static void bc_parse_stmt(BcParse *p) {
-
+static void
+bc_parse_stmt(BcParse* p)
+{
size_t len;
uint16_t flags;
BcLexType type = p->l.t;
// Eat newline.
- if (type == BC_LEX_NLINE) {
+ if (type == BC_LEX_NLINE)
+ {
bc_lex_next(&p->l);
return;
}
// Eat auto list.
- if (type == BC_LEX_KW_AUTO) {
+ if (type == BC_LEX_KW_AUTO)
+ {
bc_parse_auto(p);
return;
}
@@ -1552,30 +1621,35 @@ static void bc_parse_stmt(BcParse *p) {
// Everything but an else needs to be taken care of here, but else is
// special.
- if (type != BC_LEX_KW_ELSE) {
-
+ if (type != BC_LEX_KW_ELSE)
+ {
// After an if, no else found.
- if (BC_PARSE_IF_END(p)) {
-
+ if (BC_PARSE_IF_END(p))
+ {
// Clear the expectation for else, end body, and return. Returning
// gives us a clean slate for parsing again.
bc_parse_noElse(p);
if (p->flags.len > 1 && !BC_PARSE_BRACE(p))
+ {
bc_parse_endBody(p, false);
+ }
+
return;
}
// With a left brace, we are parsing a body.
- else if (type == BC_LEX_LBRACE) {
-
+ else if (type == BC_LEX_LBRACE)
+ {
// We need to start a body if we are not expecting one yet.
- if (!BC_PARSE_BODY(p)) {
+ if (!BC_PARSE_BODY(p))
+ {
bc_parse_startBody(p, BC_PARSE_FLAG_BRACE);
bc_lex_next(&p->l);
}
// If we *are* expecting a body, that body should get a brace. This
// takes care of braces being on a different line than if and loop
// headers.
- else {
+ else
+ {
*(BC_PARSE_TOP_FLAG_PTR(p)) |= BC_PARSE_FLAG_BRACE;
bc_lex_next(&p->l);
bc_parse_body(p, true);
@@ -1588,7 +1662,8 @@ static void bc_parse_stmt(BcParse *p) {
// This happens when we are expecting a body and get a single statement,
// i.e., a body with no braces surrounding it. Returns after for a clean
// slate.
- else if (BC_PARSE_BODY(p) && !BC_PARSE_BRACE(p)) {
+ else if (BC_PARSE_BODY(p) && !BC_PARSE_BRACE(p))
+ {
bc_parse_body(p, false);
return;
}
@@ -1597,8 +1672,8 @@ static void bc_parse_stmt(BcParse *p) {
len = p->flags.len;
flags = BC_PARSE_TOP_FLAG(p);
- switch (type) {
-
+ switch (type)
+ {
// All of these are valid for expressions.
case BC_LEX_OP_INC:
case BC_LEX_OP_DEC:
@@ -1752,13 +1827,19 @@ static void bc_parse_stmt(BcParse *p) {
}
// If the flags did not change, we expect a delimiter.
- if (len == p->flags.len && flags == BC_PARSE_TOP_FLAG(p)) {
+ if (len == p->flags.len && flags == BC_PARSE_TOP_FLAG(p))
+ {
if (BC_ERR(!bc_parse_isDelimiter(p)))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
}
// Make sure semicolons are eaten.
- while (p->l.t == BC_LEX_SCOLON) bc_lex_next(&p->l);
+ while (p->l.t == BC_LEX_SCOLON)
+ {
+ bc_lex_next(&p->l);
+ }
// POSIX's grammar does not allow a function definition after a semicolon
// without a newline, so check specifically for that case and error if
@@ -1769,8 +1850,9 @@ static void bc_parse_stmt(BcParse *p) {
}
}
-void bc_parse_parse(BcParse *p) {
-
+void
+bc_parse_parse(BcParse* p)
+{
assert(p);
BC_SETJMP_LOCKED(exit);
@@ -1780,11 +1862,15 @@ void bc_parse_parse(BcParse *p) {
if (BC_ERR(p->l.t == BC_LEX_EOF)) bc_parse_err(p, BC_ERR_PARSE_EOF);
// Functions need special parsing.
- else if (p->l.t == BC_LEX_KW_DEFINE) {
- if (BC_ERR(BC_PARSE_NO_EXEC(p))) {
+ else if (p->l.t == BC_LEX_KW_DEFINE)
+ {
+ if (BC_ERR(BC_PARSE_NO_EXEC(p)))
+ {
bc_parse_endif(p);
if (BC_ERR(BC_PARSE_NO_EXEC(p)))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
}
bc_parse_func(p);
}
@@ -1796,7 +1882,9 @@ exit:
// We need to reset on error.
if (BC_ERR(((vm.status && vm.status != BC_STATUS_QUIT) || vm.sig)))
+ {
bc_parse_reset(p);
+ }
BC_LONGJMP_CONT;
BC_SIG_MAYLOCK;
@@ -1813,8 +1901,8 @@ exit:
* to tell the caller if the expression was empty and let the
* caller handle it.
*/
-static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
- BcParseNext next)
+static BcParseStatus
+bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
{
BcInst prev = BC_INST_PRINT;
uchar inst = BC_INST_INVALID;
@@ -1854,15 +1942,19 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// We want to eat newlines if newlines are not a valid ending token.
// This is for spacing in things like for loop headers.
- if (!(flags & BC_PARSE_NOREAD)) {
- while ((t = p->l.t) == BC_LEX_NLINE) bc_lex_next(&p->l);
+ if (!(flags & BC_PARSE_NOREAD))
+ {
+ while ((t = p->l.t) == BC_LEX_NLINE)
+ {
+ bc_lex_next(&p->l);
+ }
}
// This is the Shunting-Yard algorithm loop.
for (; !done && BC_PARSE_EXPR(t); t = p->l.t)
{
- switch (t) {
-
+ switch (t)
+ {
case BC_LEX_OP_INC:
case BC_LEX_OP_DEC:
{
@@ -1885,7 +1977,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// The previous token must have been a leaf expression, or the
// operator is in the wrong place.
if (BC_ERR(!BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_TOKEN);
+ }
// I can just add the instruction because
// negative will already be taken care of.
@@ -1931,10 +2025,13 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// We need to make sure the assignment is valid.
if (!BC_PARSE_INST_VAR(prev))
+ {
bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
+ }
+
+ // Fallthrough.
+ BC_FALLTHROUGH
}
- // Fallthrough.
- BC_FALLTHROUGH
case BC_LEX_OP_POWER:
case BC_LEX_OP_MULTIPLY:
@@ -1958,18 +2055,22 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// This is true if the operator if the token is a prefix
// operator. This is only for boolean not.
- if (BC_PARSE_OP_PREFIX(t)) {
-
+ if (BC_PARSE_OP_PREFIX(t))
+ {
// Prefix operators are only allowed after binary operators
// or prefix operators.
if (BC_ERR(!bin_last && !BC_PARSE_OP_PREFIX(p->l.last)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
}
// If we execute the else, that means we have a binary operator.
// If the previous operator was a prefix or a binary operator,
// then a binary operator is not allowed.
else if (BC_ERR(BC_PARSE_PREV_PREFIX(prev) || bin_last))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
nrelops += (t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT);
prev = BC_PARSE_TOKEN_INST(t);
@@ -1988,7 +2089,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// A left paren is *not* allowed right after a leaf expr.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
nparens += 1;
rprn = incdec = can_assign = false;
@@ -2005,16 +2108,21 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// This needs to be a status. The error is handled in
// bc_parse_expr_status().
if (BC_ERR(p->l.last == BC_LEX_LPAREN))
+ {
return BC_PARSE_STATUS_EMPTY_EXPR;
+ }
// The right paren must not come after a prefix or binary
// operator.
if (BC_ERR(bin_last || BC_PARSE_PREV_PREFIX(prev)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
// If there are no parens left, we are done, but we need another
// token.
- if (!nparens) {
+ if (!nparens)
+ {
done = true;
get_token = false;
break;
@@ -2036,7 +2144,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// A string is a leaf and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
bc_parse_addString(p);
@@ -2051,7 +2161,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// A name is a leaf and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
get_token = bin_last = false;
@@ -2068,7 +2180,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// A number is a leaf and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
// The number instruction is pushed in here.
bc_parse_number(p);
@@ -2091,7 +2205,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
prev = t - BC_LEX_KW_LAST + BC_INST_LAST;
bc_parse_push(p, prev);
@@ -2114,7 +2230,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
bc_parse_builtin(p, t, flags, &prev);
@@ -2141,11 +2259,15 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
// Error if we have read and it's not allowed.
else if (t == BC_LEX_KW_READ && BC_ERR(flags & BC_PARSE_NOREAD))
+ {
bc_parse_err(p, BC_ERR_EXEC_REC_READ);
+ }
prev = t - BC_LEX_KW_READ + BC_INST_READ;
bc_parse_noArgBuiltin(p, prev);
@@ -2161,7 +2283,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// This is a leaf and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
// Scale needs special work because it can be a variable *or* a
// function.
@@ -2179,7 +2303,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
{
// This is a leaf and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
bc_parse_builtin3(p, t, flags, &prev);
@@ -2205,14 +2331,16 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// Now that we have parsed the expression, we need to empty the operator
// stack.
- while (p->ops.len > ops_bgn) {
-
+ while (p->ops.len > ops_bgn)
+ {
top = BC_PARSE_TOP_OP(p);
assign = top >= BC_LEX_OP_ASSIGN_POWER && top <= BC_LEX_OP_ASSIGN;
// There should not be *any* parens on the stack anymore.
if (BC_ERR(top == BC_LEX_LPAREN || top == BC_LEX_RPAREN))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
bc_parse_push(p, BC_PARSE_TOKEN_INST(top));
@@ -2227,35 +2355,46 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
if (BC_ERR(nexprs != 1)) bc_parse_err(p, BC_ERR_PARSE_EXPR);
// Check that the next token is correct.
- for (i = 0; i < next.len && t != next.tokens[i]; ++i);
+ for (i = 0; i < next.len && t != next.tokens[i]; ++i)
+ {
+ continue;
+ }
if (BC_ERR(i == next.len && !bc_parse_isDelimiter(p)))
+ {
bc_parse_err(p, BC_ERR_PARSE_EXPR);
+ }
// Check that POSIX would be happy with the number of relational operators.
if (!(flags & BC_PARSE_REL) && nrelops)
+ {
bc_parse_err(p, BC_ERR_POSIX_REL_POS);
+ }
else if ((flags & BC_PARSE_REL) && nrelops > 1)
+ {
bc_parse_err(p, BC_ERR_POSIX_MULTIREL);
+ }
// If this is true, then we might be in a situation where we don't print.
// We would want to have the increment/decrement operator not make an extra
// copy if it's not necessary.
- if (!(flags & BC_PARSE_NEEDVAL) && !pfirst) {
-
+ if (!(flags & BC_PARSE_NEEDVAL) && !pfirst)
+ {
// We have the easy case if the last operator was an assignment
// operator.
- if (assign) {
+ if (assign)
+ {
inst = *((uchar*) bc_vec_top(&p->func->code));
inst += (BC_INST_ASSIGN_POWER_NO_VAL - BC_INST_ASSIGN_POWER);
incdec = false;
}
// If we have an inc/dec operator and we are *not* printing, implement
// the optimization to get rid of the extra copy.
- else if (incdec && !(flags & BC_PARSE_PRINT)) {
+ else if (incdec && !(flags & BC_PARSE_PRINT))
+ {
inst = *((uchar*) bc_vec_top(&p->func->code));
incdec = (inst <= BC_INST_DEC);
- inst = BC_INST_ASSIGN_PLUS_NO_VAL + (inst != BC_INST_INC &&
- inst != BC_INST_ASSIGN_PLUS);
+ inst = BC_INST_ASSIGN_PLUS_NO_VAL +
+ (inst != BC_INST_INC && inst != BC_INST_ASSIGN_PLUS);
}
// This condition allows us to change the previous assignment
@@ -2275,8 +2414,8 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
}
// If we might have to print...
- if ((flags & BC_PARSE_PRINT)) {
-
+ if ((flags & BC_PARSE_PRINT))
+ {
// With a paren first or the last operator not being an assignment, we
// *do* want to print.
if (pfirst || !assign) bc_parse_push(p, BC_INST_PRINT);
@@ -2296,9 +2435,15 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
// Yes, this is one case where I reuse a variable for a different purpose;
// in this case, incdec being true now means that newlines are not valid.
for (incdec = true, i = 0; i < next.len && incdec; ++i)
+ {
incdec = (next.tokens[i] != BC_LEX_NLINE);
- if (incdec) {
- while (p->l.t == BC_LEX_NLINE) bc_lex_next(&p->l);
+ }
+ if (incdec)
+ {
+ while (p->l.t == BC_LEX_NLINE)
+ {
+ bc_lex_next(&p->l);
+ }
}
return BC_PARSE_STATUS_SUCCESS;
@@ -2311,15 +2456,20 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
* @param flags The flags for what is valid in the expression.
* @param next A set of tokens for what is valid *after* the expression.
*/
-static void bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next) {
-
+static void
+bc_parse_expr_status(BcParse* p, uint8_t flags, BcParseNext next)
+{
BcParseStatus s = bc_parse_expr_err(p, flags, next);
if (BC_ERR(s == BC_PARSE_STATUS_EMPTY_EXPR))
+ {
bc_parse_err(p, BC_ERR_PARSE_EMPTY_EXPR);
+ }
}
-void bc_parse_expr(BcParse *p, uint8_t flags) {
+void
+bc_parse_expr(BcParse* p, uint8_t flags)
+{
assert(p);
bc_parse_expr_status(p, flags, bc_parse_next_read);
}
diff --git a/src/data.c b/src/data.c
index 4dc77e7e746c..4009dcc1f0d1 100644
--- a/src/data.c
+++ b/src/data.c
@@ -66,12 +66,16 @@ const uchar dc_sig_msg_len = (uchar) (sizeof(dc_sig_msg) - 1);
#endif // DC_ENABLED
+// clang-format off
+
/// The copyright banner.
const char bc_copyright[] =
"Copyright (c) 2018-2022 Gavin D. Howard and contributors\n"
"Report bugs at: https://git.yzena.com/gavin/bc\n\n"
"This is free software with ABSOLUTELY NO WARRANTY.\n";
+// clang-format on
+
#ifdef __OpenBSD__
#if BC_ENABLE_EXTRA_MATH
@@ -141,10 +145,16 @@ const BcOptLong bc_args_lopt[] = {
{ "file", BC_OPT_REQUIRED, 'f' },
{ "help", BC_OPT_NONE, 'h' },
{ "interactive", BC_OPT_NONE, 'i' },
+ { "ibase", BC_OPT_REQUIRED, 'I' },
{ "leading-zeroes", BC_OPT_NONE, 'z' },
{ "no-line-length", BC_OPT_NONE, 'L' },
+ { "obase", BC_OPT_REQUIRED, 'O' },
{ "no-prompt", BC_OPT_NONE, 'P' },
{ "no-read-prompt", BC_OPT_NONE, 'R' },
+ { "scale", BC_OPT_REQUIRED, 'S' },
+#if BC_ENABLE_EXTRA_MATH
+ { "seed", BC_OPT_REQUIRED, 'E' },
+#endif // BC_ENABLE_EXTRA_MATH
#if BC_ENABLED
{ "global-stacks", BC_OPT_BC_ONLY, 'g' },
{ "mathlib", BC_OPT_BC_ONLY, 'l' },
@@ -168,6 +178,8 @@ const char* const bc_err_func_header = "Function:";
/// The line format string for error messages.
const char* const bc_err_line = ":%zu";
+// clang-format off
+
/// The default error category strings.
const char *bc_errs[] = {
"Math error:",
@@ -179,18 +191,20 @@ const char *bc_errs[] = {
#endif // BC_ENABLED
};
+// clang-format on
+
/// The error category for each error.
const uchar bc_err_ids[] = {
- BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
+ BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL,
BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL,
BC_ERR_IDX_FATAL,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
+ BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
+ BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
+ BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
BC_ERR_IDX_PARSE,
@@ -236,14 +250,17 @@ const char* const bc_err_msgs[] = {
"stack has too few elements",
"stack for register \"%s\" has too few elements",
#else // DC_ENABLED
- NULL, NULL,
+ NULL,
+ NULL,
#endif // DC_ENABLED
#if BC_ENABLED
"wrong number of parameters; need %zu, have %zu",
"undefined function: %s()",
"cannot use a void value in an expression",
#else
- NULL, NULL, NULL,
+ NULL,
+ NULL,
+ NULL,
#endif // BC_ENABLED
"end of file",
@@ -257,7 +274,7 @@ const char* const bc_err_msgs[] = {
"bad print or stream statement",
"bad function definition",
("bad assignment: left side must be scale, ibase, "
- "obase, seed, last, var, or array element"),
+ "obase, seed, last, var, or array element"),
"no auto variable found",
"function parameter or auto \"%s%s\" already exists",
"block end cannot be found",
@@ -301,9 +318,9 @@ const BcVecFree bc_vec_dtors[] = {
bc_slab_free,
bc_const_free,
bc_result_free,
-#if BC_ENABLE_HISTORY
+#if BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
bc_history_string_free,
-#endif // BC_ENABLE_HISTORY
+#endif // BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
#else // !BC_ENABLE_LIBRARY
bcl_num_destruct,
#endif // !BC_ENABLE_LIBRARY
@@ -311,7 +328,17 @@ const BcVecFree bc_vec_dtors[] = {
#if !BC_ENABLE_LIBRARY
-#if BC_ENABLE_HISTORY
+#if BC_ENABLE_EDITLINE
+
+/// The normal path to the editrc.
+const char bc_history_editrc[] = "/.editrc";
+
+/// The length of the normal path to the editrc.
+const size_t bc_history_editrc_len = sizeof(bc_history_editrc) - 1;
+
+#endif // BC_ENABLE_EDITLINE
+
+#if BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
/// A flush type for not clearing current extras but not saving new ones either.
const BcFlushType bc_flush_none = BC_FLUSH_NO_EXTRAS_NO_CLEAR;
@@ -321,351 +348,279 @@ const BcFlushType bc_flush_err = BC_FLUSH_NO_EXTRAS_CLEAR;
/// A flush type for clearing previous extras and saving new ones.
const BcFlushType bc_flush_save = BC_FLUSH_SAVE_EXTRAS_CLEAR;
-#endif // BC_ENABLE_HISTORY
-
-#if BC_ENABLE_HISTORY
/// A list of known bad terminals.
-const char *bc_history_bad_terms[] = { "dumb", "cons25", "emacs", NULL };
+const char* bc_history_bad_terms[] = { "dumb", "cons25", "emacs", NULL };
/// A constant for tabs and its length. My tab handling is dumb and always
/// outputs the entire thing.
-const char bc_history_tab[] = " ";
+const char bc_history_tab[] = "\t";
const size_t bc_history_tab_len = sizeof(bc_history_tab) - 1;
/// A list of wide chars. These are listed in ascending order for efficiency.
const uint32_t bc_history_wchars[][2] = {
- { 0x1100, 0x115F },
- { 0x231A, 0x231B },
- { 0x2329, 0x232A },
- { 0x23E9, 0x23EC },
- { 0x23F0, 0x23F0 },
- { 0x23F3, 0x23F3 },
- { 0x25FD, 0x25FE },
- { 0x2614, 0x2615 },
- { 0x2648, 0x2653 },
- { 0x267F, 0x267F },
- { 0x2693, 0x2693 },
- { 0x26A1, 0x26A1 },
- { 0x26AA, 0x26AB },
- { 0x26BD, 0x26BE },
- { 0x26C4, 0x26C5 },
- { 0x26CE, 0x26CE },
- { 0x26D4, 0x26D4 },
- { 0x26EA, 0x26EA },
- { 0x26F2, 0x26F3 },
- { 0x26F5, 0x26F5 },
- { 0x26FA, 0x26FA },
- { 0x26FD, 0x26FD },
- { 0x2705, 0x2705 },
- { 0x270A, 0x270B },
- { 0x2728, 0x2728 },
- { 0x274C, 0x274C },
- { 0x274E, 0x274E },
- { 0x2753, 0x2755 },
- { 0x2757, 0x2757 },
- { 0x2795, 0x2797 },
- { 0x27B0, 0x27B0 },
- { 0x27BF, 0x27BF },
- { 0x2B1B, 0x2B1C },
- { 0x2B50, 0x2B50 },
- { 0x2B55, 0x2B55 },
- { 0x2E80, 0x2E99 },
- { 0x2E9B, 0x2EF3 },
- { 0x2F00, 0x2FD5 },
- { 0x2FF0, 0x2FFB },
- { 0x3001, 0x303E },
- { 0x3041, 0x3096 },
- { 0x3099, 0x30FF },
- { 0x3105, 0x312D },
- { 0x3131, 0x318E },
- { 0x3190, 0x31BA },
- { 0x31C0, 0x31E3 },
- { 0x31F0, 0x321E },
- { 0x3220, 0x3247 },
- { 0x3250, 0x32FE },
- { 0x3300, 0x4DBF },
- { 0x4E00, 0xA48C },
- { 0xA490, 0xA4C6 },
- { 0xA960, 0xA97C },
- { 0xAC00, 0xD7A3 },
- { 0xF900, 0xFAFF },
- { 0xFE10, 0xFE19 },
- { 0xFE30, 0xFE52 },
- { 0xFE54, 0xFE66 },
- { 0xFE68, 0xFE6B },
- { 0x16FE0, 0x16FE0 },
- { 0x17000, 0x187EC },
- { 0x18800, 0x18AF2 },
- { 0x1B000, 0x1B001 },
- { 0x1F004, 0x1F004 },
- { 0x1F0CF, 0x1F0CF },
- { 0x1F18E, 0x1F18E },
- { 0x1F191, 0x1F19A },
- { 0x1F200, 0x1F202 },
- { 0x1F210, 0x1F23B },
- { 0x1F240, 0x1F248 },
- { 0x1F250, 0x1F251 },
- { 0x1F300, 0x1F320 },
- { 0x1F32D, 0x1F335 },
- { 0x1F337, 0x1F37C },
- { 0x1F37E, 0x1F393 },
- { 0x1F3A0, 0x1F3CA },
- { 0x1F3CF, 0x1F3D3 },
- { 0x1F3E0, 0x1F3F0 },
- { 0x1F3F4, 0x1F3F4 },
- { 0x1F3F8, 0x1F43E },
- { 0x1F440, 0x1F440 },
- { 0x1F442, 0x1F4FC },
- { 0x1F4FF, 0x1F53D },
- { 0x1F54B, 0x1F54E },
- { 0x1F550, 0x1F567 },
- { 0x1F57A, 0x1F57A },
- { 0x1F595, 0x1F596 },
- { 0x1F5A4, 0x1F5A4 },
- { 0x1F5FB, 0x1F64F },
- { 0x1F680, 0x1F6C5 },
- { 0x1F6CC, 0x1F6CC },
- { 0x1F6D0, 0x1F6D2 },
- { 0x1F6EB, 0x1F6EC },
- { 0x1F6F4, 0x1F6F6 },
- { 0x1F910, 0x1F91E },
- { 0x1F920, 0x1F927 },
- { 0x1F930, 0x1F930 },
- { 0x1F933, 0x1F93E },
- { 0x1F940, 0x1F94B },
- { 0x1F950, 0x1F95E },
- { 0x1F980, 0x1F991 },
- { 0x1F9C0, 0x1F9C0 },
- { 0x20000, 0x2FFFD },
- { 0x30000, 0x3FFFD },
+ { 0x1100, 0x115F }, { 0x231A, 0x231B }, { 0x2329, 0x232A },
+ { 0x23E9, 0x23EC }, { 0x23F0, 0x23F0 }, { 0x23F3, 0x23F3 },
+ { 0x25FD, 0x25FE }, { 0x2614, 0x2615 }, { 0x2648, 0x2653 },
+ { 0x267F, 0x267F }, { 0x2693, 0x2693 }, { 0x26A1, 0x26A1 },
+ { 0x26AA, 0x26AB }, { 0x26BD, 0x26BE }, { 0x26C4, 0x26C5 },
+ { 0x26CE, 0x26CE }, { 0x26D4, 0x26D4 }, { 0x26EA, 0x26EA },
+ { 0x26F2, 0x26F3 }, { 0x26F5, 0x26F5 }, { 0x26FA, 0x26FA },
+ { 0x26FD, 0x26FD }, { 0x2705, 0x2705 }, { 0x270A, 0x270B },
+ { 0x2728, 0x2728 }, { 0x274C, 0x274C }, { 0x274E, 0x274E },
+ { 0x2753, 0x2755 }, { 0x2757, 0x2757 }, { 0x2795, 0x2797 },
+ { 0x27B0, 0x27B0 }, { 0x27BF, 0x27BF }, { 0x2B1B, 0x2B1C },
+ { 0x2B50, 0x2B50 }, { 0x2B55, 0x2B55 }, { 0x2E80, 0x2E99 },
+ { 0x2E9B, 0x2EF3 }, { 0x2F00, 0x2FD5 }, { 0x2FF0, 0x2FFB },
+ { 0x3001, 0x303E }, { 0x3041, 0x3096 }, { 0x3099, 0x30FF },
+ { 0x3105, 0x312D }, { 0x3131, 0x318E }, { 0x3190, 0x31BA },
+ { 0x31C0, 0x31E3 }, { 0x31F0, 0x321E }, { 0x3220, 0x3247 },
+ { 0x3250, 0x32FE }, { 0x3300, 0x4DBF }, { 0x4E00, 0xA48C },
+ { 0xA490, 0xA4C6 }, { 0xA960, 0xA97C }, { 0xAC00, 0xD7A3 },
+ { 0xF900, 0xFAFF }, { 0xFE10, 0xFE19 }, { 0xFE30, 0xFE52 },
+ { 0xFE54, 0xFE66 }, { 0xFE68, 0xFE6B }, { 0x16FE0, 0x16FE0 },
+ { 0x17000, 0x187EC }, { 0x18800, 0x18AF2 }, { 0x1B000, 0x1B001 },
+ { 0x1F004, 0x1F004 }, { 0x1F0CF, 0x1F0CF }, { 0x1F18E, 0x1F18E },
+ { 0x1F191, 0x1F19A }, { 0x1F200, 0x1F202 }, { 0x1F210, 0x1F23B },
+ { 0x1F240, 0x1F248 }, { 0x1F250, 0x1F251 }, { 0x1F300, 0x1F320 },
+ { 0x1F32D, 0x1F335 }, { 0x1F337, 0x1F37C }, { 0x1F37E, 0x1F393 },
+ { 0x1F3A0, 0x1F3CA }, { 0x1F3CF, 0x1F3D3 }, { 0x1F3E0, 0x1F3F0 },
+ { 0x1F3F4, 0x1F3F4 }, { 0x1F3F8, 0x1F43E }, { 0x1F440, 0x1F440 },
+ { 0x1F442, 0x1F4FC }, { 0x1F4FF, 0x1F53D }, { 0x1F54B, 0x1F54E },
+ { 0x1F550, 0x1F567 }, { 0x1F57A, 0x1F57A }, { 0x1F595, 0x1F596 },
+ { 0x1F5A4, 0x1F5A4 }, { 0x1F5FB, 0x1F64F }, { 0x1F680, 0x1F6C5 },
+ { 0x1F6CC, 0x1F6CC }, { 0x1F6D0, 0x1F6D2 }, { 0x1F6EB, 0x1F6EC },
+ { 0x1F6F4, 0x1F6F6 }, { 0x1F910, 0x1F91E }, { 0x1F920, 0x1F927 },
+ { 0x1F930, 0x1F930 }, { 0x1F933, 0x1F93E }, { 0x1F940, 0x1F94B },
+ { 0x1F950, 0x1F95E }, { 0x1F980, 0x1F991 }, { 0x1F9C0, 0x1F9C0 },
+ { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD },
};
/// The length of the wide chars list.
-const size_t bc_history_wchars_len =
- sizeof(bc_history_wchars) / sizeof(bc_history_wchars[0]);
+const size_t bc_history_wchars_len = sizeof(bc_history_wchars) /
+ sizeof(bc_history_wchars[0]);
/// A list of combining characters in Unicode. These are listed in ascending
/// order for efficiency.
const uint32_t bc_history_combo_chars[] = {
- 0x0300,0x0301,0x0302,0x0303,0x0304,0x0305,0x0306,0x0307,
- 0x0308,0x0309,0x030A,0x030B,0x030C,0x030D,0x030E,0x030F,
- 0x0310,0x0311,0x0312,0x0313,0x0314,0x0315,0x0316,0x0317,
- 0x0318,0x0319,0x031A,0x031B,0x031C,0x031D,0x031E,0x031F,
- 0x0320,0x0321,0x0322,0x0323,0x0324,0x0325,0x0326,0x0327,
- 0x0328,0x0329,0x032A,0x032B,0x032C,0x032D,0x032E,0x032F,
- 0x0330,0x0331,0x0332,0x0333,0x0334,0x0335,0x0336,0x0337,
- 0x0338,0x0339,0x033A,0x033B,0x033C,0x033D,0x033E,0x033F,
- 0x0340,0x0341,0x0342,0x0343,0x0344,0x0345,0x0346,0x0347,
- 0x0348,0x0349,0x034A,0x034B,0x034C,0x034D,0x034E,0x034F,
- 0x0350,0x0351,0x0352,0x0353,0x0354,0x0355,0x0356,0x0357,
- 0x0358,0x0359,0x035A,0x035B,0x035C,0x035D,0x035E,0x035F,
- 0x0360,0x0361,0x0362,0x0363,0x0364,0x0365,0x0366,0x0367,
- 0x0368,0x0369,0x036A,0x036B,0x036C,0x036D,0x036E,0x036F,
- 0x0483,0x0484,0x0485,0x0486,0x0487,0x0591,0x0592,0x0593,
- 0x0594,0x0595,0x0596,0x0597,0x0598,0x0599,0x059A,0x059B,
- 0x059C,0x059D,0x059E,0x059F,0x05A0,0x05A1,0x05A2,0x05A3,
- 0x05A4,0x05A5,0x05A6,0x05A7,0x05A8,0x05A9,0x05AA,0x05AB,
- 0x05AC,0x05AD,0x05AE,0x05AF,0x05B0,0x05B1,0x05B2,0x05B3,
- 0x05B4,0x05B5,0x05B6,0x05B7,0x05B8,0x05B9,0x05BA,0x05BB,
- 0x05BC,0x05BD,0x05BF,0x05C1,0x05C2,0x05C4,0x05C5,0x05C7,
- 0x0610,0x0611,0x0612,0x0613,0x0614,0x0615,0x0616,0x0617,
- 0x0618,0x0619,0x061A,0x064B,0x064C,0x064D,0x064E,0x064F,
- 0x0650,0x0651,0x0652,0x0653,0x0654,0x0655,0x0656,0x0657,
- 0x0658,0x0659,0x065A,0x065B,0x065C,0x065D,0x065E,0x065F,
- 0x0670,0x06D6,0x06D7,0x06D8,0x06D9,0x06DA,0x06DB,0x06DC,
- 0x06DF,0x06E0,0x06E1,0x06E2,0x06E3,0x06E4,0x06E7,0x06E8,
- 0x06EA,0x06EB,0x06EC,0x06ED,0x0711,0x0730,0x0731,0x0732,
- 0x0733,0x0734,0x0735,0x0736,0x0737,0x0738,0x0739,0x073A,
- 0x073B,0x073C,0x073D,0x073E,0x073F,0x0740,0x0741,0x0742,
- 0x0743,0x0744,0x0745,0x0746,0x0747,0x0748,0x0749,0x074A,
- 0x07A6,0x07A7,0x07A8,0x07A9,0x07AA,0x07AB,0x07AC,0x07AD,
- 0x07AE,0x07AF,0x07B0,0x07EB,0x07EC,0x07ED,0x07EE,0x07EF,
- 0x07F0,0x07F1,0x07F2,0x07F3,0x0816,0x0817,0x0818,0x0819,
- 0x081B,0x081C,0x081D,0x081E,0x081F,0x0820,0x0821,0x0822,
- 0x0823,0x0825,0x0826,0x0827,0x0829,0x082A,0x082B,0x082C,
- 0x082D,0x0859,0x085A,0x085B,0x08D4,0x08D5,0x08D6,0x08D7,
- 0x08D8,0x08D9,0x08DA,0x08DB,0x08DC,0x08DD,0x08DE,0x08DF,
- 0x08E0,0x08E1,0x08E3,0x08E4,0x08E5,0x08E6,0x08E7,0x08E8,
- 0x08E9,0x08EA,0x08EB,0x08EC,0x08ED,0x08EE,0x08EF,0x08F0,
- 0x08F1,0x08F2,0x08F3,0x08F4,0x08F5,0x08F6,0x08F7,0x08F8,
- 0x08F9,0x08FA,0x08FB,0x08FC,0x08FD,0x08FE,0x08FF,0x0900,
- 0x0901,0x0902,0x093A,0x093C,0x0941,0x0942,0x0943,0x0944,
- 0x0945,0x0946,0x0947,0x0948,0x094D,0x0951,0x0952,0x0953,
- 0x0954,0x0955,0x0956,0x0957,0x0962,0x0963,0x0981,0x09BC,
- 0x09C1,0x09C2,0x09C3,0x09C4,0x09CD,0x09E2,0x09E3,0x0A01,
- 0x0A02,0x0A3C,0x0A41,0x0A42,0x0A47,0x0A48,0x0A4B,0x0A4C,
- 0x0A4D,0x0A51,0x0A70,0x0A71,0x0A75,0x0A81,0x0A82,0x0ABC,
- 0x0AC1,0x0AC2,0x0AC3,0x0AC4,0x0AC5,0x0AC7,0x0AC8,0x0ACD,
- 0x0AE2,0x0AE3,0x0B01,0x0B3C,0x0B3F,0x0B41,0x0B42,0x0B43,
- 0x0B44,0x0B4D,0x0B56,0x0B62,0x0B63,0x0B82,0x0BC0,0x0BCD,
- 0x0C00,0x0C3E,0x0C3F,0x0C40,0x0C46,0x0C47,0x0C48,0x0C4A,
- 0x0C4B,0x0C4C,0x0C4D,0x0C55,0x0C56,0x0C62,0x0C63,0x0C81,
- 0x0CBC,0x0CBF,0x0CC6,0x0CCC,0x0CCD,0x0CE2,0x0CE3,0x0D01,
- 0x0D41,0x0D42,0x0D43,0x0D44,0x0D4D,0x0D62,0x0D63,0x0DCA,
- 0x0DD2,0x0DD3,0x0DD4,0x0DD6,0x0E31,0x0E34,0x0E35,0x0E36,
- 0x0E37,0x0E38,0x0E39,0x0E3A,0x0E47,0x0E48,0x0E49,0x0E4A,
- 0x0E4B,0x0E4C,0x0E4D,0x0E4E,0x0EB1,0x0EB4,0x0EB5,0x0EB6,
- 0x0EB7,0x0EB8,0x0EB9,0x0EBB,0x0EBC,0x0EC8,0x0EC9,0x0ECA,
- 0x0ECB,0x0ECC,0x0ECD,0x0F18,0x0F19,0x0F35,0x0F37,0x0F39,
- 0x0F71,0x0F72,0x0F73,0x0F74,0x0F75,0x0F76,0x0F77,0x0F78,
- 0x0F79,0x0F7A,0x0F7B,0x0F7C,0x0F7D,0x0F7E,0x0F80,0x0F81,
- 0x0F82,0x0F83,0x0F84,0x0F86,0x0F87,0x0F8D,0x0F8E,0x0F8F,
- 0x0F90,0x0F91,0x0F92,0x0F93,0x0F94,0x0F95,0x0F96,0x0F97,
- 0x0F99,0x0F9A,0x0F9B,0x0F9C,0x0F9D,0x0F9E,0x0F9F,0x0FA0,
- 0x0FA1,0x0FA2,0x0FA3,0x0FA4,0x0FA5,0x0FA6,0x0FA7,0x0FA8,
- 0x0FA9,0x0FAA,0x0FAB,0x0FAC,0x0FAD,0x0FAE,0x0FAF,0x0FB0,
- 0x0FB1,0x0FB2,0x0FB3,0x0FB4,0x0FB5,0x0FB6,0x0FB7,0x0FB8,
- 0x0FB9,0x0FBA,0x0FBB,0x0FBC,0x0FC6,0x102D,0x102E,0x102F,
- 0x1030,0x1032,0x1033,0x1034,0x1035,0x1036,0x1037,0x1039,
- 0x103A,0x103D,0x103E,0x1058,0x1059,0x105E,0x105F,0x1060,
- 0x1071,0x1072,0x1073,0x1074,0x1082,0x1085,0x1086,0x108D,
- 0x109D,0x135D,0x135E,0x135F,0x1712,0x1713,0x1714,0x1732,
- 0x1733,0x1734,0x1752,0x1753,0x1772,0x1773,0x17B4,0x17B5,
- 0x17B7,0x17B8,0x17B9,0x17BA,0x17BB,0x17BC,0x17BD,0x17C6,
- 0x17C9,0x17CA,0x17CB,0x17CC,0x17CD,0x17CE,0x17CF,0x17D0,
- 0x17D1,0x17D2,0x17D3,0x17DD,0x180B,0x180C,0x180D,0x1885,
- 0x1886,0x18A9,0x1920,0x1921,0x1922,0x1927,0x1928,0x1932,
- 0x1939,0x193A,0x193B,0x1A17,0x1A18,0x1A1B,0x1A56,0x1A58,
- 0x1A59,0x1A5A,0x1A5B,0x1A5C,0x1A5D,0x1A5E,0x1A60,0x1A62,
- 0x1A65,0x1A66,0x1A67,0x1A68,0x1A69,0x1A6A,0x1A6B,0x1A6C,
- 0x1A73,0x1A74,0x1A75,0x1A76,0x1A77,0x1A78,0x1A79,0x1A7A,
- 0x1A7B,0x1A7C,0x1A7F,0x1AB0,0x1AB1,0x1AB2,0x1AB3,0x1AB4,
- 0x1AB5,0x1AB6,0x1AB7,0x1AB8,0x1AB9,0x1ABA,0x1ABB,0x1ABC,
- 0x1ABD,0x1B00,0x1B01,0x1B02,0x1B03,0x1B34,0x1B36,0x1B37,
- 0x1B38,0x1B39,0x1B3A,0x1B3C,0x1B42,0x1B6B,0x1B6C,0x1B6D,
- 0x1B6E,0x1B6F,0x1B70,0x1B71,0x1B72,0x1B73,0x1B80,0x1B81,
- 0x1BA2,0x1BA3,0x1BA4,0x1BA5,0x1BA8,0x1BA9,0x1BAB,0x1BAC,
- 0x1BAD,0x1BE6,0x1BE8,0x1BE9,0x1BED,0x1BEF,0x1BF0,0x1BF1,
- 0x1C2C,0x1C2D,0x1C2E,0x1C2F,0x1C30,0x1C31,0x1C32,0x1C33,
- 0x1C36,0x1C37,0x1CD0,0x1CD1,0x1CD2,0x1CD4,0x1CD5,0x1CD6,
- 0x1CD7,0x1CD8,0x1CD9,0x1CDA,0x1CDB,0x1CDC,0x1CDD,0x1CDE,
- 0x1CDF,0x1CE0,0x1CE2,0x1CE3,0x1CE4,0x1CE5,0x1CE6,0x1CE7,
- 0x1CE8,0x1CED,0x1CF4,0x1CF8,0x1CF9,0x1DC0,0x1DC1,0x1DC2,
- 0x1DC3,0x1DC4,0x1DC5,0x1DC6,0x1DC7,0x1DC8,0x1DC9,0x1DCA,
- 0x1DCB,0x1DCC,0x1DCD,0x1DCE,0x1DCF,0x1DD0,0x1DD1,0x1DD2,
- 0x1DD3,0x1DD4,0x1DD5,0x1DD6,0x1DD7,0x1DD8,0x1DD9,0x1DDA,
- 0x1DDB,0x1DDC,0x1DDD,0x1DDE,0x1DDF,0x1DE0,0x1DE1,0x1DE2,
- 0x1DE3,0x1DE4,0x1DE5,0x1DE6,0x1DE7,0x1DE8,0x1DE9,0x1DEA,
- 0x1DEB,0x1DEC,0x1DED,0x1DEE,0x1DEF,0x1DF0,0x1DF1,0x1DF2,
- 0x1DF3,0x1DF4,0x1DF5,0x1DFB,0x1DFC,0x1DFD,0x1DFE,0x1DFF,
- 0x20D0,0x20D1,0x20D2,0x20D3,0x20D4,0x20D5,0x20D6,0x20D7,
- 0x20D8,0x20D9,0x20DA,0x20DB,0x20DC,0x20E1,0x20E5,0x20E6,
- 0x20E7,0x20E8,0x20E9,0x20EA,0x20EB,0x20EC,0x20ED,0x20EE,
- 0x20EF,0x20F0,0x2CEF,0x2CF0,0x2CF1,0x2D7F,0x2DE0,0x2DE1,
- 0x2DE2,0x2DE3,0x2DE4,0x2DE5,0x2DE6,0x2DE7,0x2DE8,0x2DE9,
- 0x2DEA,0x2DEB,0x2DEC,0x2DED,0x2DEE,0x2DEF,0x2DF0,0x2DF1,
- 0x2DF2,0x2DF3,0x2DF4,0x2DF5,0x2DF6,0x2DF7,0x2DF8,0x2DF9,
- 0x2DFA,0x2DFB,0x2DFC,0x2DFD,0x2DFE,0x2DFF,0x302A,0x302B,
- 0x302C,0x302D,0x3099,0x309A,0xA66F,0xA674,0xA675,0xA676,
- 0xA677,0xA678,0xA679,0xA67A,0xA67B,0xA67C,0xA67D,0xA69E,
- 0xA69F,0xA6F0,0xA6F1,0xA802,0xA806,0xA80B,0xA825,0xA826,
- 0xA8C4,0xA8C5,0xA8E0,0xA8E1,0xA8E2,0xA8E3,0xA8E4,0xA8E5,
- 0xA8E6,0xA8E7,0xA8E8,0xA8E9,0xA8EA,0xA8EB,0xA8EC,0xA8ED,
- 0xA8EE,0xA8EF,0xA8F0,0xA8F1,0xA926,0xA927,0xA928,0xA929,
- 0xA92A,0xA92B,0xA92C,0xA92D,0xA947,0xA948,0xA949,0xA94A,
- 0xA94B,0xA94C,0xA94D,0xA94E,0xA94F,0xA950,0xA951,0xA980,
- 0xA981,0xA982,0xA9B3,0xA9B6,0xA9B7,0xA9B8,0xA9B9,0xA9BC,
- 0xA9E5,0xAA29,0xAA2A,0xAA2B,0xAA2C,0xAA2D,0xAA2E,0xAA31,
- 0xAA32,0xAA35,0xAA36,0xAA43,0xAA4C,0xAA7C,0xAAB0,0xAAB2,
- 0xAAB3,0xAAB4,0xAAB7,0xAAB8,0xAABE,0xAABF,0xAAC1,0xAAEC,
- 0xAAED,0xAAF6,0xABE5,0xABE8,0xABED,0xFB1E,0xFE00,0xFE01,
- 0xFE02,0xFE03,0xFE04,0xFE05,0xFE06,0xFE07,0xFE08,0xFE09,
- 0xFE0A,0xFE0B,0xFE0C,0xFE0D,0xFE0E,0xFE0F,0xFE20,0xFE21,
- 0xFE22,0xFE23,0xFE24,0xFE25,0xFE26,0xFE27,0xFE28,0xFE29,
- 0xFE2A,0xFE2B,0xFE2C,0xFE2D,0xFE2E,0xFE2F,
- 0x101FD,0x102E0,0x10376,0x10377,0x10378,0x10379,0x1037A,0x10A01,
- 0x10A02,0x10A03,0x10A05,0x10A06,0x10A0C,0x10A0D,0x10A0E,0x10A0F,
- 0x10A38,0x10A39,0x10A3A,0x10A3F,0x10AE5,0x10AE6,0x11001,0x11038,
- 0x11039,0x1103A,0x1103B,0x1103C,0x1103D,0x1103E,0x1103F,0x11040,
- 0x11041,0x11042,0x11043,0x11044,0x11045,0x11046,0x1107F,0x11080,
- 0x11081,0x110B3,0x110B4,0x110B5,0x110B6,0x110B9,0x110BA,0x11100,
- 0x11101,0x11102,0x11127,0x11128,0x11129,0x1112A,0x1112B,0x1112D,
- 0x1112E,0x1112F,0x11130,0x11131,0x11132,0x11133,0x11134,0x11173,
- 0x11180,0x11181,0x111B6,0x111B7,0x111B8,0x111B9,0x111BA,0x111BB,
- 0x111BC,0x111BD,0x111BE,0x111CA,0x111CB,0x111CC,0x1122F,0x11230,
- 0x11231,0x11234,0x11236,0x11237,0x1123E,0x112DF,0x112E3,0x112E4,
- 0x112E5,0x112E6,0x112E7,0x112E8,0x112E9,0x112EA,0x11300,0x11301,
- 0x1133C,0x11340,0x11366,0x11367,0x11368,0x11369,0x1136A,0x1136B,
- 0x1136C,0x11370,0x11371,0x11372,0x11373,0x11374,0x11438,0x11439,
- 0x1143A,0x1143B,0x1143C,0x1143D,0x1143E,0x1143F,0x11442,0x11443,
- 0x11444,0x11446,0x114B3,0x114B4,0x114B5,0x114B6,0x114B7,0x114B8,
- 0x114BA,0x114BF,0x114C0,0x114C2,0x114C3,0x115B2,0x115B3,0x115B4,
- 0x115B5,0x115BC,0x115BD,0x115BF,0x115C0,0x115DC,0x115DD,0x11633,
- 0x11634,0x11635,0x11636,0x11637,0x11638,0x11639,0x1163A,0x1163D,
- 0x1163F,0x11640,0x116AB,0x116AD,0x116B0,0x116B1,0x116B2,0x116B3,
- 0x116B4,0x116B5,0x116B7,0x1171D,0x1171E,0x1171F,0x11722,0x11723,
- 0x11724,0x11725,0x11727,0x11728,0x11729,0x1172A,0x1172B,0x11C30,
- 0x11C31,0x11C32,0x11C33,0x11C34,0x11C35,0x11C36,0x11C38,0x11C39,
- 0x11C3A,0x11C3B,0x11C3C,0x11C3D,0x11C3F,0x11C92,0x11C93,0x11C94,
- 0x11C95,0x11C96,0x11C97,0x11C98,0x11C99,0x11C9A,0x11C9B,0x11C9C,
- 0x11C9D,0x11C9E,0x11C9F,0x11CA0,0x11CA1,0x11CA2,0x11CA3,0x11CA4,
- 0x11CA5,0x11CA6,0x11CA7,0x11CAA,0x11CAB,0x11CAC,0x11CAD,0x11CAE,
- 0x11CAF,0x11CB0,0x11CB2,0x11CB3,0x11CB5,0x11CB6,0x16AF0,0x16AF1,
- 0x16AF2,0x16AF3,0x16AF4,0x16B30,0x16B31,0x16B32,0x16B33,0x16B34,
- 0x16B35,0x16B36,0x16F8F,0x16F90,0x16F91,0x16F92,0x1BC9D,0x1BC9E,
- 0x1D167,0x1D168,0x1D169,0x1D17B,0x1D17C,0x1D17D,0x1D17E,0x1D17F,
- 0x1D180,0x1D181,0x1D182,0x1D185,0x1D186,0x1D187,0x1D188,0x1D189,
- 0x1D18A,0x1D18B,0x1D1AA,0x1D1AB,0x1D1AC,0x1D1AD,0x1D242,0x1D243,
- 0x1D244,0x1DA00,0x1DA01,0x1DA02,0x1DA03,0x1DA04,0x1DA05,0x1DA06,
- 0x1DA07,0x1DA08,0x1DA09,0x1DA0A,0x1DA0B,0x1DA0C,0x1DA0D,0x1DA0E,
- 0x1DA0F,0x1DA10,0x1DA11,0x1DA12,0x1DA13,0x1DA14,0x1DA15,0x1DA16,
- 0x1DA17,0x1DA18,0x1DA19,0x1DA1A,0x1DA1B,0x1DA1C,0x1DA1D,0x1DA1E,
- 0x1DA1F,0x1DA20,0x1DA21,0x1DA22,0x1DA23,0x1DA24,0x1DA25,0x1DA26,
- 0x1DA27,0x1DA28,0x1DA29,0x1DA2A,0x1DA2B,0x1DA2C,0x1DA2D,0x1DA2E,
- 0x1DA2F,0x1DA30,0x1DA31,0x1DA32,0x1DA33,0x1DA34,0x1DA35,0x1DA36,
- 0x1DA3B,0x1DA3C,0x1DA3D,0x1DA3E,0x1DA3F,0x1DA40,0x1DA41,0x1DA42,
- 0x1DA43,0x1DA44,0x1DA45,0x1DA46,0x1DA47,0x1DA48,0x1DA49,0x1DA4A,
- 0x1DA4B,0x1DA4C,0x1DA4D,0x1DA4E,0x1DA4F,0x1DA50,0x1DA51,0x1DA52,
- 0x1DA53,0x1DA54,0x1DA55,0x1DA56,0x1DA57,0x1DA58,0x1DA59,0x1DA5A,
- 0x1DA5B,0x1DA5C,0x1DA5D,0x1DA5E,0x1DA5F,0x1DA60,0x1DA61,0x1DA62,
- 0x1DA63,0x1DA64,0x1DA65,0x1DA66,0x1DA67,0x1DA68,0x1DA69,0x1DA6A,
- 0x1DA6B,0x1DA6C,0x1DA75,0x1DA84,0x1DA9B,0x1DA9C,0x1DA9D,0x1DA9E,
- 0x1DA9F,0x1DAA1,0x1DAA2,0x1DAA3,0x1DAA4,0x1DAA5,0x1DAA6,0x1DAA7,
- 0x1DAA8,0x1DAA9,0x1DAAA,0x1DAAB,0x1DAAC,0x1DAAD,0x1DAAE,0x1DAAF,
- 0x1E000,0x1E001,0x1E002,0x1E003,0x1E004,0x1E005,0x1E006,0x1E008,
- 0x1E009,0x1E00A,0x1E00B,0x1E00C,0x1E00D,0x1E00E,0x1E00F,0x1E010,
- 0x1E011,0x1E012,0x1E013,0x1E014,0x1E015,0x1E016,0x1E017,0x1E018,
- 0x1E01B,0x1E01C,0x1E01D,0x1E01E,0x1E01F,0x1E020,0x1E021,0x1E023,
- 0x1E024,0x1E026,0x1E027,0x1E028,0x1E029,0x1E02A,0x1E8D0,0x1E8D1,
- 0x1E8D2,0x1E8D3,0x1E8D4,0x1E8D5,0x1E8D6,0x1E944,0x1E945,0x1E946,
- 0x1E947,0x1E948,0x1E949,0x1E94A,0xE0100,0xE0101,0xE0102,0xE0103,
- 0xE0104,0xE0105,0xE0106,0xE0107,0xE0108,0xE0109,0xE010A,0xE010B,
- 0xE010C,0xE010D,0xE010E,0xE010F,0xE0110,0xE0111,0xE0112,0xE0113,
- 0xE0114,0xE0115,0xE0116,0xE0117,0xE0118,0xE0119,0xE011A,0xE011B,
- 0xE011C,0xE011D,0xE011E,0xE011F,0xE0120,0xE0121,0xE0122,0xE0123,
- 0xE0124,0xE0125,0xE0126,0xE0127,0xE0128,0xE0129,0xE012A,0xE012B,
- 0xE012C,0xE012D,0xE012E,0xE012F,0xE0130,0xE0131,0xE0132,0xE0133,
- 0xE0134,0xE0135,0xE0136,0xE0137,0xE0138,0xE0139,0xE013A,0xE013B,
- 0xE013C,0xE013D,0xE013E,0xE013F,0xE0140,0xE0141,0xE0142,0xE0143,
- 0xE0144,0xE0145,0xE0146,0xE0147,0xE0148,0xE0149,0xE014A,0xE014B,
- 0xE014C,0xE014D,0xE014E,0xE014F,0xE0150,0xE0151,0xE0152,0xE0153,
- 0xE0154,0xE0155,0xE0156,0xE0157,0xE0158,0xE0159,0xE015A,0xE015B,
- 0xE015C,0xE015D,0xE015E,0xE015F,0xE0160,0xE0161,0xE0162,0xE0163,
- 0xE0164,0xE0165,0xE0166,0xE0167,0xE0168,0xE0169,0xE016A,0xE016B,
- 0xE016C,0xE016D,0xE016E,0xE016F,0xE0170,0xE0171,0xE0172,0xE0173,
- 0xE0174,0xE0175,0xE0176,0xE0177,0xE0178,0xE0179,0xE017A,0xE017B,
- 0xE017C,0xE017D,0xE017E,0xE017F,0xE0180,0xE0181,0xE0182,0xE0183,
- 0xE0184,0xE0185,0xE0186,0xE0187,0xE0188,0xE0189,0xE018A,0xE018B,
- 0xE018C,0xE018D,0xE018E,0xE018F,0xE0190,0xE0191,0xE0192,0xE0193,
- 0xE0194,0xE0195,0xE0196,0xE0197,0xE0198,0xE0199,0xE019A,0xE019B,
- 0xE019C,0xE019D,0xE019E,0xE019F,0xE01A0,0xE01A1,0xE01A2,0xE01A3,
- 0xE01A4,0xE01A5,0xE01A6,0xE01A7,0xE01A8,0xE01A9,0xE01AA,0xE01AB,
- 0xE01AC,0xE01AD,0xE01AE,0xE01AF,0xE01B0,0xE01B1,0xE01B2,0xE01B3,
- 0xE01B4,0xE01B5,0xE01B6,0xE01B7,0xE01B8,0xE01B9,0xE01BA,0xE01BB,
- 0xE01BC,0xE01BD,0xE01BE,0xE01BF,0xE01C0,0xE01C1,0xE01C2,0xE01C3,
- 0xE01C4,0xE01C5,0xE01C6,0xE01C7,0xE01C8,0xE01C9,0xE01CA,0xE01CB,
- 0xE01CC,0xE01CD,0xE01CE,0xE01CF,0xE01D0,0xE01D1,0xE01D2,0xE01D3,
- 0xE01D4,0xE01D5,0xE01D6,0xE01D7,0xE01D8,0xE01D9,0xE01DA,0xE01DB,
- 0xE01DC,0xE01DD,0xE01DE,0xE01DF,0xE01E0,0xE01E1,0xE01E2,0xE01E3,
- 0xE01E4,0xE01E5,0xE01E6,0xE01E7,0xE01E8,0xE01E9,0xE01EA,0xE01EB,
- 0xE01EC,0xE01ED,0xE01EE,0xE01EF,
+ 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307,
+ 0x0308, 0x0309, 0x030A, 0x030B, 0x030C, 0x030D, 0x030E, 0x030F,
+ 0x0310, 0x0311, 0x0312, 0x0313, 0x0314, 0x0315, 0x0316, 0x0317,
+ 0x0318, 0x0319, 0x031A, 0x031B, 0x031C, 0x031D, 0x031E, 0x031F,
+ 0x0320, 0x0321, 0x0322, 0x0323, 0x0324, 0x0325, 0x0326, 0x0327,
+ 0x0328, 0x0329, 0x032A, 0x032B, 0x032C, 0x032D, 0x032E, 0x032F,
+ 0x0330, 0x0331, 0x0332, 0x0333, 0x0334, 0x0335, 0x0336, 0x0337,
+ 0x0338, 0x0339, 0x033A, 0x033B, 0x033C, 0x033D, 0x033E, 0x033F,
+ 0x0340, 0x0341, 0x0342, 0x0343, 0x0344, 0x0345, 0x0346, 0x0347,
+ 0x0348, 0x0349, 0x034A, 0x034B, 0x034C, 0x034D, 0x034E, 0x034F,
+ 0x0350, 0x0351, 0x0352, 0x0353, 0x0354, 0x0355, 0x0356, 0x0357,
+ 0x0358, 0x0359, 0x035A, 0x035B, 0x035C, 0x035D, 0x035E, 0x035F,
+ 0x0360, 0x0361, 0x0362, 0x0363, 0x0364, 0x0365, 0x0366, 0x0367,
+ 0x0368, 0x0369, 0x036A, 0x036B, 0x036C, 0x036D, 0x036E, 0x036F,
+ 0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0591, 0x0592, 0x0593,
+ 0x0594, 0x0595, 0x0596, 0x0597, 0x0598, 0x0599, 0x059A, 0x059B,
+ 0x059C, 0x059D, 0x059E, 0x059F, 0x05A0, 0x05A1, 0x05A2, 0x05A3,
+ 0x05A4, 0x05A5, 0x05A6, 0x05A7, 0x05A8, 0x05A9, 0x05AA, 0x05AB,
+ 0x05AC, 0x05AD, 0x05AE, 0x05AF, 0x05B0, 0x05B1, 0x05B2, 0x05B3,
+ 0x05B4, 0x05B5, 0x05B6, 0x05B7, 0x05B8, 0x05B9, 0x05BA, 0x05BB,
+ 0x05BC, 0x05BD, 0x05BF, 0x05C1, 0x05C2, 0x05C4, 0x05C5, 0x05C7,
+ 0x0610, 0x0611, 0x0612, 0x0613, 0x0614, 0x0615, 0x0616, 0x0617,
+ 0x0618, 0x0619, 0x061A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,
+ 0x0650, 0x0651, 0x0652, 0x0653, 0x0654, 0x0655, 0x0656, 0x0657,
+ 0x0658, 0x0659, 0x065A, 0x065B, 0x065C, 0x065D, 0x065E, 0x065F,
+ 0x0670, 0x06D6, 0x06D7, 0x06D8, 0x06D9, 0x06DA, 0x06DB, 0x06DC,
+ 0x06DF, 0x06E0, 0x06E1, 0x06E2, 0x06E3, 0x06E4, 0x06E7, 0x06E8,
+ 0x06EA, 0x06EB, 0x06EC, 0x06ED, 0x0711, 0x0730, 0x0731, 0x0732,
+ 0x0733, 0x0734, 0x0735, 0x0736, 0x0737, 0x0738, 0x0739, 0x073A,
+ 0x073B, 0x073C, 0x073D, 0x073E, 0x073F, 0x0740, 0x0741, 0x0742,
+ 0x0743, 0x0744, 0x0745, 0x0746, 0x0747, 0x0748, 0x0749, 0x074A,
+ 0x07A6, 0x07A7, 0x07A8, 0x07A9, 0x07AA, 0x07AB, 0x07AC, 0x07AD,
+ 0x07AE, 0x07AF, 0x07B0, 0x07EB, 0x07EC, 0x07ED, 0x07EE, 0x07EF,
+ 0x07F0, 0x07F1, 0x07F2, 0x07F3, 0x0816, 0x0817, 0x0818, 0x0819,
+ 0x081B, 0x081C, 0x081D, 0x081E, 0x081F, 0x0820, 0x0821, 0x0822,
+ 0x0823, 0x0825, 0x0826, 0x0827, 0x0829, 0x082A, 0x082B, 0x082C,
+ 0x082D, 0x0859, 0x085A, 0x085B, 0x08D4, 0x08D5, 0x08D6, 0x08D7,
+ 0x08D8, 0x08D9, 0x08DA, 0x08DB, 0x08DC, 0x08DD, 0x08DE, 0x08DF,
+ 0x08E0, 0x08E1, 0x08E3, 0x08E4, 0x08E5, 0x08E6, 0x08E7, 0x08E8,
+ 0x08E9, 0x08EA, 0x08EB, 0x08EC, 0x08ED, 0x08EE, 0x08EF, 0x08F0,
+ 0x08F1, 0x08F2, 0x08F3, 0x08F4, 0x08F5, 0x08F6, 0x08F7, 0x08F8,
+ 0x08F9, 0x08FA, 0x08FB, 0x08FC, 0x08FD, 0x08FE, 0x08FF, 0x0900,
+ 0x0901, 0x0902, 0x093A, 0x093C, 0x0941, 0x0942, 0x0943, 0x0944,
+ 0x0945, 0x0946, 0x0947, 0x0948, 0x094D, 0x0951, 0x0952, 0x0953,
+ 0x0954, 0x0955, 0x0956, 0x0957, 0x0962, 0x0963, 0x0981, 0x09BC,
+ 0x09C1, 0x09C2, 0x09C3, 0x09C4, 0x09CD, 0x09E2, 0x09E3, 0x0A01,
+ 0x0A02, 0x0A3C, 0x0A41, 0x0A42, 0x0A47, 0x0A48, 0x0A4B, 0x0A4C,
+ 0x0A4D, 0x0A51, 0x0A70, 0x0A71, 0x0A75, 0x0A81, 0x0A82, 0x0ABC,
+ 0x0AC1, 0x0AC2, 0x0AC3, 0x0AC4, 0x0AC5, 0x0AC7, 0x0AC8, 0x0ACD,
+ 0x0AE2, 0x0AE3, 0x0B01, 0x0B3C, 0x0B3F, 0x0B41, 0x0B42, 0x0B43,
+ 0x0B44, 0x0B4D, 0x0B56, 0x0B62, 0x0B63, 0x0B82, 0x0BC0, 0x0BCD,
+ 0x0C00, 0x0C3E, 0x0C3F, 0x0C40, 0x0C46, 0x0C47, 0x0C48, 0x0C4A,
+ 0x0C4B, 0x0C4C, 0x0C4D, 0x0C55, 0x0C56, 0x0C62, 0x0C63, 0x0C81,
+ 0x0CBC, 0x0CBF, 0x0CC6, 0x0CCC, 0x0CCD, 0x0CE2, 0x0CE3, 0x0D01,
+ 0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D4D, 0x0D62, 0x0D63, 0x0DCA,
+ 0x0DD2, 0x0DD3, 0x0DD4, 0x0DD6, 0x0E31, 0x0E34, 0x0E35, 0x0E36,
+ 0x0E37, 0x0E38, 0x0E39, 0x0E3A, 0x0E47, 0x0E48, 0x0E49, 0x0E4A,
+ 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0EB1, 0x0EB4, 0x0EB5, 0x0EB6,
+ 0x0EB7, 0x0EB8, 0x0EB9, 0x0EBB, 0x0EBC, 0x0EC8, 0x0EC9, 0x0ECA,
+ 0x0ECB, 0x0ECC, 0x0ECD, 0x0F18, 0x0F19, 0x0F35, 0x0F37, 0x0F39,
+ 0x0F71, 0x0F72, 0x0F73, 0x0F74, 0x0F75, 0x0F76, 0x0F77, 0x0F78,
+ 0x0F79, 0x0F7A, 0x0F7B, 0x0F7C, 0x0F7D, 0x0F7E, 0x0F80, 0x0F81,
+ 0x0F82, 0x0F83, 0x0F84, 0x0F86, 0x0F87, 0x0F8D, 0x0F8E, 0x0F8F,
+ 0x0F90, 0x0F91, 0x0F92, 0x0F93, 0x0F94, 0x0F95, 0x0F96, 0x0F97,
+ 0x0F99, 0x0F9A, 0x0F9B, 0x0F9C, 0x0F9D, 0x0F9E, 0x0F9F, 0x0FA0,
+ 0x0FA1, 0x0FA2, 0x0FA3, 0x0FA4, 0x0FA5, 0x0FA6, 0x0FA7, 0x0FA8,
+ 0x0FA9, 0x0FAA, 0x0FAB, 0x0FAC, 0x0FAD, 0x0FAE, 0x0FAF, 0x0FB0,
+ 0x0FB1, 0x0FB2, 0x0FB3, 0x0FB4, 0x0FB5, 0x0FB6, 0x0FB7, 0x0FB8,
+ 0x0FB9, 0x0FBA, 0x0FBB, 0x0FBC, 0x0FC6, 0x102D, 0x102E, 0x102F,
+ 0x1030, 0x1032, 0x1033, 0x1034, 0x1035, 0x1036, 0x1037, 0x1039,
+ 0x103A, 0x103D, 0x103E, 0x1058, 0x1059, 0x105E, 0x105F, 0x1060,
+ 0x1071, 0x1072, 0x1073, 0x1074, 0x1082, 0x1085, 0x1086, 0x108D,
+ 0x109D, 0x135D, 0x135E, 0x135F, 0x1712, 0x1713, 0x1714, 0x1732,
+ 0x1733, 0x1734, 0x1752, 0x1753, 0x1772, 0x1773, 0x17B4, 0x17B5,
+ 0x17B7, 0x17B8, 0x17B9, 0x17BA, 0x17BB, 0x17BC, 0x17BD, 0x17C6,
+ 0x17C9, 0x17CA, 0x17CB, 0x17CC, 0x17CD, 0x17CE, 0x17CF, 0x17D0,
+ 0x17D1, 0x17D2, 0x17D3, 0x17DD, 0x180B, 0x180C, 0x180D, 0x1885,
+ 0x1886, 0x18A9, 0x1920, 0x1921, 0x1922, 0x1927, 0x1928, 0x1932,
+ 0x1939, 0x193A, 0x193B, 0x1A17, 0x1A18, 0x1A1B, 0x1A56, 0x1A58,
+ 0x1A59, 0x1A5A, 0x1A5B, 0x1A5C, 0x1A5D, 0x1A5E, 0x1A60, 0x1A62,
+ 0x1A65, 0x1A66, 0x1A67, 0x1A68, 0x1A69, 0x1A6A, 0x1A6B, 0x1A6C,
+ 0x1A73, 0x1A74, 0x1A75, 0x1A76, 0x1A77, 0x1A78, 0x1A79, 0x1A7A,
+ 0x1A7B, 0x1A7C, 0x1A7F, 0x1AB0, 0x1AB1, 0x1AB2, 0x1AB3, 0x1AB4,
+ 0x1AB5, 0x1AB6, 0x1AB7, 0x1AB8, 0x1AB9, 0x1ABA, 0x1ABB, 0x1ABC,
+ 0x1ABD, 0x1B00, 0x1B01, 0x1B02, 0x1B03, 0x1B34, 0x1B36, 0x1B37,
+ 0x1B38, 0x1B39, 0x1B3A, 0x1B3C, 0x1B42, 0x1B6B, 0x1B6C, 0x1B6D,
+ 0x1B6E, 0x1B6F, 0x1B70, 0x1B71, 0x1B72, 0x1B73, 0x1B80, 0x1B81,
+ 0x1BA2, 0x1BA3, 0x1BA4, 0x1BA5, 0x1BA8, 0x1BA9, 0x1BAB, 0x1BAC,
+ 0x1BAD, 0x1BE6, 0x1BE8, 0x1BE9, 0x1BED, 0x1BEF, 0x1BF0, 0x1BF1,
+ 0x1C2C, 0x1C2D, 0x1C2E, 0x1C2F, 0x1C30, 0x1C31, 0x1C32, 0x1C33,
+ 0x1C36, 0x1C37, 0x1CD0, 0x1CD1, 0x1CD2, 0x1CD4, 0x1CD5, 0x1CD6,
+ 0x1CD7, 0x1CD8, 0x1CD9, 0x1CDA, 0x1CDB, 0x1CDC, 0x1CDD, 0x1CDE,
+ 0x1CDF, 0x1CE0, 0x1CE2, 0x1CE3, 0x1CE4, 0x1CE5, 0x1CE6, 0x1CE7,
+ 0x1CE8, 0x1CED, 0x1CF4, 0x1CF8, 0x1CF9, 0x1DC0, 0x1DC1, 0x1DC2,
+ 0x1DC3, 0x1DC4, 0x1DC5, 0x1DC6, 0x1DC7, 0x1DC8, 0x1DC9, 0x1DCA,
+ 0x1DCB, 0x1DCC, 0x1DCD, 0x1DCE, 0x1DCF, 0x1DD0, 0x1DD1, 0x1DD2,
+ 0x1DD3, 0x1DD4, 0x1DD5, 0x1DD6, 0x1DD7, 0x1DD8, 0x1DD9, 0x1DDA,
+ 0x1DDB, 0x1DDC, 0x1DDD, 0x1DDE, 0x1DDF, 0x1DE0, 0x1DE1, 0x1DE2,
+ 0x1DE3, 0x1DE4, 0x1DE5, 0x1DE6, 0x1DE7, 0x1DE8, 0x1DE9, 0x1DEA,
+ 0x1DEB, 0x1DEC, 0x1DED, 0x1DEE, 0x1DEF, 0x1DF0, 0x1DF1, 0x1DF2,
+ 0x1DF3, 0x1DF4, 0x1DF5, 0x1DFB, 0x1DFC, 0x1DFD, 0x1DFE, 0x1DFF,
+ 0x20D0, 0x20D1, 0x20D2, 0x20D3, 0x20D4, 0x20D5, 0x20D6, 0x20D7,
+ 0x20D8, 0x20D9, 0x20DA, 0x20DB, 0x20DC, 0x20E1, 0x20E5, 0x20E6,
+ 0x20E7, 0x20E8, 0x20E9, 0x20EA, 0x20EB, 0x20EC, 0x20ED, 0x20EE,
+ 0x20EF, 0x20F0, 0x2CEF, 0x2CF0, 0x2CF1, 0x2D7F, 0x2DE0, 0x2DE1,
+ 0x2DE2, 0x2DE3, 0x2DE4, 0x2DE5, 0x2DE6, 0x2DE7, 0x2DE8, 0x2DE9,
+ 0x2DEA, 0x2DEB, 0x2DEC, 0x2DED, 0x2DEE, 0x2DEF, 0x2DF0, 0x2DF1,
+ 0x2DF2, 0x2DF3, 0x2DF4, 0x2DF5, 0x2DF6, 0x2DF7, 0x2DF8, 0x2DF9,
+ 0x2DFA, 0x2DFB, 0x2DFC, 0x2DFD, 0x2DFE, 0x2DFF, 0x302A, 0x302B,
+ 0x302C, 0x302D, 0x3099, 0x309A, 0xA66F, 0xA674, 0xA675, 0xA676,
+ 0xA677, 0xA678, 0xA679, 0xA67A, 0xA67B, 0xA67C, 0xA67D, 0xA69E,
+ 0xA69F, 0xA6F0, 0xA6F1, 0xA802, 0xA806, 0xA80B, 0xA825, 0xA826,
+ 0xA8C4, 0xA8C5, 0xA8E0, 0xA8E1, 0xA8E2, 0xA8E3, 0xA8E4, 0xA8E5,
+ 0xA8E6, 0xA8E7, 0xA8E8, 0xA8E9, 0xA8EA, 0xA8EB, 0xA8EC, 0xA8ED,
+ 0xA8EE, 0xA8EF, 0xA8F0, 0xA8F1, 0xA926, 0xA927, 0xA928, 0xA929,
+ 0xA92A, 0xA92B, 0xA92C, 0xA92D, 0xA947, 0xA948, 0xA949, 0xA94A,
+ 0xA94B, 0xA94C, 0xA94D, 0xA94E, 0xA94F, 0xA950, 0xA951, 0xA980,
+ 0xA981, 0xA982, 0xA9B3, 0xA9B6, 0xA9B7, 0xA9B8, 0xA9B9, 0xA9BC,
+ 0xA9E5, 0xAA29, 0xAA2A, 0xAA2B, 0xAA2C, 0xAA2D, 0xAA2E, 0xAA31,
+ 0xAA32, 0xAA35, 0xAA36, 0xAA43, 0xAA4C, 0xAA7C, 0xAAB0, 0xAAB2,
+ 0xAAB3, 0xAAB4, 0xAAB7, 0xAAB8, 0xAABE, 0xAABF, 0xAAC1, 0xAAEC,
+ 0xAAED, 0xAAF6, 0xABE5, 0xABE8, 0xABED, 0xFB1E, 0xFE00, 0xFE01,
+ 0xFE02, 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, 0xFE08, 0xFE09,
+ 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFE20, 0xFE21,
+ 0xFE22, 0xFE23, 0xFE24, 0xFE25, 0xFE26, 0xFE27, 0xFE28, 0xFE29,
+ 0xFE2A, 0xFE2B, 0xFE2C, 0xFE2D, 0xFE2E, 0xFE2F, 0x101FD, 0x102E0,
+ 0x10376, 0x10377, 0x10378, 0x10379, 0x1037A, 0x10A01, 0x10A02, 0x10A03,
+ 0x10A05, 0x10A06, 0x10A0C, 0x10A0D, 0x10A0E, 0x10A0F, 0x10A38, 0x10A39,
+ 0x10A3A, 0x10A3F, 0x10AE5, 0x10AE6, 0x11001, 0x11038, 0x11039, 0x1103A,
+ 0x1103B, 0x1103C, 0x1103D, 0x1103E, 0x1103F, 0x11040, 0x11041, 0x11042,
+ 0x11043, 0x11044, 0x11045, 0x11046, 0x1107F, 0x11080, 0x11081, 0x110B3,
+ 0x110B4, 0x110B5, 0x110B6, 0x110B9, 0x110BA, 0x11100, 0x11101, 0x11102,
+ 0x11127, 0x11128, 0x11129, 0x1112A, 0x1112B, 0x1112D, 0x1112E, 0x1112F,
+ 0x11130, 0x11131, 0x11132, 0x11133, 0x11134, 0x11173, 0x11180, 0x11181,
+ 0x111B6, 0x111B7, 0x111B8, 0x111B9, 0x111BA, 0x111BB, 0x111BC, 0x111BD,
+ 0x111BE, 0x111CA, 0x111CB, 0x111CC, 0x1122F, 0x11230, 0x11231, 0x11234,
+ 0x11236, 0x11237, 0x1123E, 0x112DF, 0x112E3, 0x112E4, 0x112E5, 0x112E6,
+ 0x112E7, 0x112E8, 0x112E9, 0x112EA, 0x11300, 0x11301, 0x1133C, 0x11340,
+ 0x11366, 0x11367, 0x11368, 0x11369, 0x1136A, 0x1136B, 0x1136C, 0x11370,
+ 0x11371, 0x11372, 0x11373, 0x11374, 0x11438, 0x11439, 0x1143A, 0x1143B,
+ 0x1143C, 0x1143D, 0x1143E, 0x1143F, 0x11442, 0x11443, 0x11444, 0x11446,
+ 0x114B3, 0x114B4, 0x114B5, 0x114B6, 0x114B7, 0x114B8, 0x114BA, 0x114BF,
+ 0x114C0, 0x114C2, 0x114C3, 0x115B2, 0x115B3, 0x115B4, 0x115B5, 0x115BC,
+ 0x115BD, 0x115BF, 0x115C0, 0x115DC, 0x115DD, 0x11633, 0x11634, 0x11635,
+ 0x11636, 0x11637, 0x11638, 0x11639, 0x1163A, 0x1163D, 0x1163F, 0x11640,
+ 0x116AB, 0x116AD, 0x116B0, 0x116B1, 0x116B2, 0x116B3, 0x116B4, 0x116B5,
+ 0x116B7, 0x1171D, 0x1171E, 0x1171F, 0x11722, 0x11723, 0x11724, 0x11725,
+ 0x11727, 0x11728, 0x11729, 0x1172A, 0x1172B, 0x11C30, 0x11C31, 0x11C32,
+ 0x11C33, 0x11C34, 0x11C35, 0x11C36, 0x11C38, 0x11C39, 0x11C3A, 0x11C3B,
+ 0x11C3C, 0x11C3D, 0x11C3F, 0x11C92, 0x11C93, 0x11C94, 0x11C95, 0x11C96,
+ 0x11C97, 0x11C98, 0x11C99, 0x11C9A, 0x11C9B, 0x11C9C, 0x11C9D, 0x11C9E,
+ 0x11C9F, 0x11CA0, 0x11CA1, 0x11CA2, 0x11CA3, 0x11CA4, 0x11CA5, 0x11CA6,
+ 0x11CA7, 0x11CAA, 0x11CAB, 0x11CAC, 0x11CAD, 0x11CAE, 0x11CAF, 0x11CB0,
+ 0x11CB2, 0x11CB3, 0x11CB5, 0x11CB6, 0x16AF0, 0x16AF1, 0x16AF2, 0x16AF3,
+ 0x16AF4, 0x16B30, 0x16B31, 0x16B32, 0x16B33, 0x16B34, 0x16B35, 0x16B36,
+ 0x16F8F, 0x16F90, 0x16F91, 0x16F92, 0x1BC9D, 0x1BC9E, 0x1D167, 0x1D168,
+ 0x1D169, 0x1D17B, 0x1D17C, 0x1D17D, 0x1D17E, 0x1D17F, 0x1D180, 0x1D181,
+ 0x1D182, 0x1D185, 0x1D186, 0x1D187, 0x1D188, 0x1D189, 0x1D18A, 0x1D18B,
+ 0x1D1AA, 0x1D1AB, 0x1D1AC, 0x1D1AD, 0x1D242, 0x1D243, 0x1D244, 0x1DA00,
+ 0x1DA01, 0x1DA02, 0x1DA03, 0x1DA04, 0x1DA05, 0x1DA06, 0x1DA07, 0x1DA08,
+ 0x1DA09, 0x1DA0A, 0x1DA0B, 0x1DA0C, 0x1DA0D, 0x1DA0E, 0x1DA0F, 0x1DA10,
+ 0x1DA11, 0x1DA12, 0x1DA13, 0x1DA14, 0x1DA15, 0x1DA16, 0x1DA17, 0x1DA18,
+ 0x1DA19, 0x1DA1A, 0x1DA1B, 0x1DA1C, 0x1DA1D, 0x1DA1E, 0x1DA1F, 0x1DA20,
+ 0x1DA21, 0x1DA22, 0x1DA23, 0x1DA24, 0x1DA25, 0x1DA26, 0x1DA27, 0x1DA28,
+ 0x1DA29, 0x1DA2A, 0x1DA2B, 0x1DA2C, 0x1DA2D, 0x1DA2E, 0x1DA2F, 0x1DA30,
+ 0x1DA31, 0x1DA32, 0x1DA33, 0x1DA34, 0x1DA35, 0x1DA36, 0x1DA3B, 0x1DA3C,
+ 0x1DA3D, 0x1DA3E, 0x1DA3F, 0x1DA40, 0x1DA41, 0x1DA42, 0x1DA43, 0x1DA44,
+ 0x1DA45, 0x1DA46, 0x1DA47, 0x1DA48, 0x1DA49, 0x1DA4A, 0x1DA4B, 0x1DA4C,
+ 0x1DA4D, 0x1DA4E, 0x1DA4F, 0x1DA50, 0x1DA51, 0x1DA52, 0x1DA53, 0x1DA54,
+ 0x1DA55, 0x1DA56, 0x1DA57, 0x1DA58, 0x1DA59, 0x1DA5A, 0x1DA5B, 0x1DA5C,
+ 0x1DA5D, 0x1DA5E, 0x1DA5F, 0x1DA60, 0x1DA61, 0x1DA62, 0x1DA63, 0x1DA64,
+ 0x1DA65, 0x1DA66, 0x1DA67, 0x1DA68, 0x1DA69, 0x1DA6A, 0x1DA6B, 0x1DA6C,
+ 0x1DA75, 0x1DA84, 0x1DA9B, 0x1DA9C, 0x1DA9D, 0x1DA9E, 0x1DA9F, 0x1DAA1,
+ 0x1DAA2, 0x1DAA3, 0x1DAA4, 0x1DAA5, 0x1DAA6, 0x1DAA7, 0x1DAA8, 0x1DAA9,
+ 0x1DAAA, 0x1DAAB, 0x1DAAC, 0x1DAAD, 0x1DAAE, 0x1DAAF, 0x1E000, 0x1E001,
+ 0x1E002, 0x1E003, 0x1E004, 0x1E005, 0x1E006, 0x1E008, 0x1E009, 0x1E00A,
+ 0x1E00B, 0x1E00C, 0x1E00D, 0x1E00E, 0x1E00F, 0x1E010, 0x1E011, 0x1E012,
+ 0x1E013, 0x1E014, 0x1E015, 0x1E016, 0x1E017, 0x1E018, 0x1E01B, 0x1E01C,
+ 0x1E01D, 0x1E01E, 0x1E01F, 0x1E020, 0x1E021, 0x1E023, 0x1E024, 0x1E026,
+ 0x1E027, 0x1E028, 0x1E029, 0x1E02A, 0x1E8D0, 0x1E8D1, 0x1E8D2, 0x1E8D3,
+ 0x1E8D4, 0x1E8D5, 0x1E8D6, 0x1E944, 0x1E945, 0x1E946, 0x1E947, 0x1E948,
+ 0x1E949, 0x1E94A, 0xE0100, 0xE0101, 0xE0102, 0xE0103, 0xE0104, 0xE0105,
+ 0xE0106, 0xE0107, 0xE0108, 0xE0109, 0xE010A, 0xE010B, 0xE010C, 0xE010D,
+ 0xE010E, 0xE010F, 0xE0110, 0xE0111, 0xE0112, 0xE0113, 0xE0114, 0xE0115,
+ 0xE0116, 0xE0117, 0xE0118, 0xE0119, 0xE011A, 0xE011B, 0xE011C, 0xE011D,
+ 0xE011E, 0xE011F, 0xE0120, 0xE0121, 0xE0122, 0xE0123, 0xE0124, 0xE0125,
+ 0xE0126, 0xE0127, 0xE0128, 0xE0129, 0xE012A, 0xE012B, 0xE012C, 0xE012D,
+ 0xE012E, 0xE012F, 0xE0130, 0xE0131, 0xE0132, 0xE0133, 0xE0134, 0xE0135,
+ 0xE0136, 0xE0137, 0xE0138, 0xE0139, 0xE013A, 0xE013B, 0xE013C, 0xE013D,
+ 0xE013E, 0xE013F, 0xE0140, 0xE0141, 0xE0142, 0xE0143, 0xE0144, 0xE0145,
+ 0xE0146, 0xE0147, 0xE0148, 0xE0149, 0xE014A, 0xE014B, 0xE014C, 0xE014D,
+ 0xE014E, 0xE014F, 0xE0150, 0xE0151, 0xE0152, 0xE0153, 0xE0154, 0xE0155,
+ 0xE0156, 0xE0157, 0xE0158, 0xE0159, 0xE015A, 0xE015B, 0xE015C, 0xE015D,
+ 0xE015E, 0xE015F, 0xE0160, 0xE0161, 0xE0162, 0xE0163, 0xE0164, 0xE0165,
+ 0xE0166, 0xE0167, 0xE0168, 0xE0169, 0xE016A, 0xE016B, 0xE016C, 0xE016D,
+ 0xE016E, 0xE016F, 0xE0170, 0xE0171, 0xE0172, 0xE0173, 0xE0174, 0xE0175,
+ 0xE0176, 0xE0177, 0xE0178, 0xE0179, 0xE017A, 0xE017B, 0xE017C, 0xE017D,
+ 0xE017E, 0xE017F, 0xE0180, 0xE0181, 0xE0182, 0xE0183, 0xE0184, 0xE0185,
+ 0xE0186, 0xE0187, 0xE0188, 0xE0189, 0xE018A, 0xE018B, 0xE018C, 0xE018D,
+ 0xE018E, 0xE018F, 0xE0190, 0xE0191, 0xE0192, 0xE0193, 0xE0194, 0xE0195,
+ 0xE0196, 0xE0197, 0xE0198, 0xE0199, 0xE019A, 0xE019B, 0xE019C, 0xE019D,
+ 0xE019E, 0xE019F, 0xE01A0, 0xE01A1, 0xE01A2, 0xE01A3, 0xE01A4, 0xE01A5,
+ 0xE01A6, 0xE01A7, 0xE01A8, 0xE01A9, 0xE01AA, 0xE01AB, 0xE01AC, 0xE01AD,
+ 0xE01AE, 0xE01AF, 0xE01B0, 0xE01B1, 0xE01B2, 0xE01B3, 0xE01B4, 0xE01B5,
+ 0xE01B6, 0xE01B7, 0xE01B8, 0xE01B9, 0xE01BA, 0xE01BB, 0xE01BC, 0xE01BD,
+ 0xE01BE, 0xE01BF, 0xE01C0, 0xE01C1, 0xE01C2, 0xE01C3, 0xE01C4, 0xE01C5,
+ 0xE01C6, 0xE01C7, 0xE01C8, 0xE01C9, 0xE01CA, 0xE01CB, 0xE01CC, 0xE01CD,
+ 0xE01CE, 0xE01CF, 0xE01D0, 0xE01D1, 0xE01D2, 0xE01D3, 0xE01D4, 0xE01D5,
+ 0xE01D6, 0xE01D7, 0xE01D8, 0xE01D9, 0xE01DA, 0xE01DB, 0xE01DC, 0xE01DD,
+ 0xE01DE, 0xE01DF, 0xE01E0, 0xE01E1, 0xE01E2, 0xE01E3, 0xE01E4, 0xE01E5,
+ 0xE01E6, 0xE01E7, 0xE01E8, 0xE01E9, 0xE01EA, 0xE01EB, 0xE01EC, 0xE01ED,
+ 0xE01EE, 0xE01EF,
};
/// The length of the combining characters list.
-const size_t bc_history_combo_chars_len =
- sizeof(bc_history_combo_chars) / sizeof(bc_history_combo_chars[0]);
-#endif // BC_ENABLE_HISTORY
+const size_t bc_history_combo_chars_len = sizeof(bc_history_combo_chars) /
+ sizeof(bc_history_combo_chars[0]);
+#endif // BC_ENABLE_HISTORY && !BC_ENABLE_LINE_LIB
/// The human-readable name of the main function in bc source code.
const char bc_func_main[] = "(main)";
@@ -892,8 +847,8 @@ const size_t bc_lex_kws_len = sizeof(bc_lex_kws) / sizeof(BcLexKeyword);
// redefined_kws in BcVm, is correct. If it's correct under C11, it will be
// correct under C99, and I did not know any other way of ensuring they remained
// synchronized.
-static_assert(sizeof(bc_lex_kws) / sizeof(BcLexKeyword) == BC_LEX_NKWS,
- "BC_LEX_NKWS is wrong.");
+_Static_assert(sizeof(bc_lex_kws) / sizeof(BcLexKeyword) == BC_LEX_NKWS,
+ "BC_LEX_NKWS is wrong.");
#endif // BC_C11
@@ -964,23 +919,21 @@ const uint8_t bc_parse_exprs[] = {
/// An array of data for operators that correspond to token types.
const uchar bc_parse_ops[] = {
- BC_PARSE_OP(0, false), BC_PARSE_OP(0, false),
- BC_PARSE_OP(1, false), BC_PARSE_OP(1, false),
+ BC_PARSE_OP(0, false), BC_PARSE_OP(0, false), BC_PARSE_OP(1, false),
+ BC_PARSE_OP(1, false),
#if BC_ENABLE_EXTRA_MATH
BC_PARSE_OP(2, false),
#endif // BC_ENABLE_EXTRA_MATH
- BC_PARSE_OP(4, false),
- BC_PARSE_OP(5, true), BC_PARSE_OP(5, true), BC_PARSE_OP(5, true),
- BC_PARSE_OP(6, true), BC_PARSE_OP(6, true),
+ BC_PARSE_OP(4, false), BC_PARSE_OP(5, true), BC_PARSE_OP(5, true),
+ BC_PARSE_OP(5, true), BC_PARSE_OP(6, true), BC_PARSE_OP(6, true),
#if BC_ENABLE_EXTRA_MATH
- BC_PARSE_OP(3, false),
- BC_PARSE_OP(7, true), BC_PARSE_OP(7, true),
+ BC_PARSE_OP(3, false), BC_PARSE_OP(7, true), BC_PARSE_OP(7, true),
#endif // BC_ENABLE_EXTRA_MATH
- BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
- BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
- BC_PARSE_OP(11, true), BC_PARSE_OP(10, true),
- BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
+ BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
+ BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
+ BC_PARSE_OP(11, true), BC_PARSE_OP(10, true), BC_PARSE_OP(8, false),
BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
+ BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
#if BC_ENABLE_EXTRA_MATH
BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
#endif // BC_ENABLE_EXTRA_MATH
@@ -990,16 +943,19 @@ const uchar bc_parse_ops[] = {
// These identify what tokens can come after expressions in certain cases.
/// The valid next tokens for normal expressions.
-const BcParseNext bc_parse_next_expr =
- BC_PARSE_NEXT(4, BC_LEX_NLINE, BC_LEX_SCOLON, BC_LEX_RBRACE, BC_LEX_EOF);
+const BcParseNext bc_parse_next_expr = BC_PARSE_NEXT(4, BC_LEX_NLINE,
+ BC_LEX_SCOLON,
+ BC_LEX_RBRACE, BC_LEX_EOF);
/// The valid next tokens for function argument expressions.
-const BcParseNext bc_parse_next_arg =
- BC_PARSE_NEXT(2, BC_LEX_RPAREN, BC_LEX_COMMA);
+const BcParseNext bc_parse_next_arg = BC_PARSE_NEXT(2, BC_LEX_RPAREN,
+ BC_LEX_COMMA);
/// The valid next tokens for expressions in print statements.
-const BcParseNext bc_parse_next_print =
- BC_PARSE_NEXT(4, BC_LEX_COMMA, BC_LEX_NLINE, BC_LEX_SCOLON, BC_LEX_EOF);
+const BcParseNext bc_parse_next_print = BC_PARSE_NEXT(4, BC_LEX_COMMA,
+ BC_LEX_NLINE,
+ BC_LEX_SCOLON,
+ BC_LEX_EOF);
/// The valid next tokens for if statement conditions or loop conditions. This
/// is used in for loops for the update expression and for builtin function.
@@ -1017,8 +973,8 @@ const BcParseNext bc_parse_next_elem = BC_PARSE_NEXT(1, BC_LEX_RBRACKET);
const BcParseNext bc_parse_next_for = BC_PARSE_NEXT(1, BC_LEX_SCOLON);
/// The valid next tokens for read expressions.
-const BcParseNext bc_parse_next_read =
- BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF);
+const BcParseNext bc_parse_next_read = BC_PARSE_NEXT(2, BC_LEX_NLINE,
+ BC_LEX_EOF);
/// The valid next tokens for the arguments of a builtin function with multiple
/// arguments.
@@ -1030,9 +986,10 @@ const BcParseNext bc_parse_next_builtin = BC_PARSE_NEXT(1, BC_LEX_COMMA);
/// A list of instructions that need register arguments in dc.
const uint8_t dc_lex_regs[] = {
- BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE,
- BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT, BC_LEX_SCOLON, BC_LEX_COLON,
- BC_LEX_KW_ELSE, BC_LEX_LOAD, BC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN,
+ BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE,
+ BC_LEX_OP_REL_NE, BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT,
+ BC_LEX_SCOLON, BC_LEX_COLON, BC_LEX_KW_ELSE,
+ BC_LEX_LOAD, BC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN,
BC_LEX_STORE_PUSH, BC_LEX_REG_STACK_LEVEL, BC_LEX_ARRAY_LENGTH,
};
@@ -1056,26 +1013,49 @@ const uchar dc_lex_tokens[] = {
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_OP_MODULUS, BC_LEX_INVALID,
+ BC_LEX_OP_MODULUS,
+ BC_LEX_INVALID,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_RAND,
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_LPAREN, BC_LEX_RPAREN, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS,
- BC_LEX_EXEC_STACK_LENGTH, BC_LEX_OP_MINUS, BC_LEX_INVALID, BC_LEX_OP_DIVIDE,
- BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
- BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
- BC_LEX_INVALID, BC_LEX_INVALID,
- BC_LEX_COLON, BC_LEX_SCOLON, BC_LEX_OP_REL_GT, BC_LEX_OP_REL_EQ,
- BC_LEX_OP_REL_LT, BC_LEX_KW_READ,
+ BC_LEX_LPAREN,
+ BC_LEX_RPAREN,
+ BC_LEX_OP_MULTIPLY,
+ BC_LEX_OP_PLUS,
+ BC_LEX_EXEC_STACK_LENGTH,
+ BC_LEX_OP_MINUS,
+ BC_LEX_INVALID,
+ BC_LEX_OP_DIVIDE,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_COLON,
+ BC_LEX_SCOLON,
+ BC_LEX_OP_REL_GT,
+ BC_LEX_OP_REL_EQ,
+ BC_LEX_OP_REL_LT,
+ BC_LEX_KW_READ,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_OP_PLACES,
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
- BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_EQ_NO_REG,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_EQ_NO_REG,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_OP_LSHIFT,
#else // BC_ENABLE_EXTRA_MATH
@@ -1087,20 +1067,39 @@ const uchar dc_lex_tokens[] = {
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_KW_SCALE, BC_LEX_LOAD_POP, BC_LEX_OP_BOOL_AND, BC_LEX_OP_BOOL_NOT,
- BC_LEX_KW_OBASE, BC_LEX_KW_STREAM, BC_LEX_NQUIT, BC_LEX_POP,
- BC_LEX_STORE_PUSH, BC_LEX_KW_MAXIBASE, BC_LEX_KW_MAXOBASE,
+ BC_LEX_KW_SCALE,
+ BC_LEX_LOAD_POP,
+ BC_LEX_OP_BOOL_AND,
+ BC_LEX_OP_BOOL_NOT,
+ BC_LEX_KW_OBASE,
+ BC_LEX_KW_STREAM,
+ BC_LEX_NQUIT,
+ BC_LEX_POP,
+ BC_LEX_STORE_PUSH,
+ BC_LEX_KW_MAXIBASE,
+ BC_LEX_KW_MAXOBASE,
BC_LEX_KW_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_MAXRAND,
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_SCALE_FACTOR, BC_LEX_ARRAY_LENGTH, BC_LEX_KW_LENGTH,
- BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
- BC_LEX_OP_POWER, BC_LEX_NEG, BC_LEX_INVALID,
- BC_LEX_KW_ASCIIFY, BC_LEX_KW_ABS, BC_LEX_CLEAR_STACK, BC_LEX_DUPLICATE,
- BC_LEX_KW_ELSE, BC_LEX_PRINT_STACK, BC_LEX_INVALID,
+ BC_LEX_SCALE_FACTOR,
+ BC_LEX_ARRAY_LENGTH,
+ BC_LEX_KW_LENGTH,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_OP_POWER,
+ BC_LEX_NEG,
+ BC_LEX_INVALID,
+ BC_LEX_KW_ASCIIFY,
+ BC_LEX_KW_ABS,
+ BC_LEX_CLEAR_STACK,
+ BC_LEX_DUPLICATE,
+ BC_LEX_KW_ELSE,
+ BC_LEX_PRINT_STACK,
+ BC_LEX_INVALID,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_OP_RSHIFT,
#else // BC_ENABLE_EXTRA_MATH
@@ -1112,12 +1111,26 @@ const uchar dc_lex_tokens[] = {
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_LEX_STORE_SCALE, BC_LEX_LOAD,
- BC_LEX_OP_BOOL_OR, BC_LEX_PRINT_POP, BC_LEX_STORE_OBASE, BC_LEX_KW_PRINT,
- BC_LEX_KW_QUIT, BC_LEX_SWAP, BC_LEX_OP_ASSIGN, BC_LEX_INVALID,
- BC_LEX_INVALID, BC_LEX_KW_SQRT, BC_LEX_INVALID, BC_LEX_EXECUTE,
- BC_LEX_REG_STACK_LEVEL, BC_LEX_STACK_LEVEL,
- BC_LEX_LBRACE, BC_LEX_KW_MODEXP, BC_LEX_RBRACE, BC_LEX_KW_DIVMOD,
+ BC_LEX_STORE_SCALE,
+ BC_LEX_LOAD,
+ BC_LEX_OP_BOOL_OR,
+ BC_LEX_PRINT_POP,
+ BC_LEX_STORE_OBASE,
+ BC_LEX_KW_PRINT,
+ BC_LEX_KW_QUIT,
+ BC_LEX_SWAP,
+ BC_LEX_OP_ASSIGN,
+ BC_LEX_INVALID,
+ BC_LEX_INVALID,
+ BC_LEX_KW_SQRT,
+ BC_LEX_INVALID,
+ BC_LEX_EXECUTE,
+ BC_LEX_REG_STACK_LEVEL,
+ BC_LEX_STACK_LEVEL,
+ BC_LEX_LBRACE,
+ BC_LEX_KW_MODEXP,
+ BC_LEX_RBRACE,
+ BC_LEX_KW_DIVMOD,
BC_LEX_INVALID
};
@@ -1126,56 +1139,55 @@ const uchar dc_lex_tokens[] = {
/// Otherwise, the token can trivially be replaced by the entry. This needs to
/// be updated if the tokens change.
const uchar dc_parse_insts[] = {
- BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID,
#if BC_ENABLED
- BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID,
#endif // BC_ENABLED
- BC_INST_INVALID, BC_INST_BOOL_NOT,
+ BC_INST_INVALID, BC_INST_BOOL_NOT,
#if BC_ENABLE_EXTRA_MATH
BC_INST_TRUNC,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_POWER, BC_INST_MULTIPLY, BC_INST_DIVIDE, BC_INST_MODULUS,
- BC_INST_PLUS, BC_INST_MINUS,
+ BC_INST_POWER, BC_INST_MULTIPLY, BC_INST_DIVIDE,
+ BC_INST_MODULUS, BC_INST_PLUS, BC_INST_MINUS,
#if BC_ENABLE_EXTRA_MATH
- BC_INST_PLACES,
- BC_INST_LSHIFT, BC_INST_RSHIFT,
+ BC_INST_PLACES, BC_INST_LSHIFT, BC_INST_RSHIFT,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_BOOL_OR, BC_INST_BOOL_AND,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_BOOL_OR, BC_INST_BOOL_AND,
#if BC_ENABLED
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
#if BC_ENABLE_EXTRA_MATH
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
#endif // BC_ENABLED
- BC_INST_INVALID,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GT, BC_INST_REL_LT,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GE,
- BC_INST_INVALID, BC_INST_REL_LE,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_REL_GT, BC_INST_REL_LT, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GE,
+ BC_INST_INVALID, BC_INST_REL_LE, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID,
#if BC_ENABLED
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID,
#endif // BC_ENABLED
- BC_INST_IBASE, BC_INST_OBASE, BC_INST_SCALE,
+ BC_INST_IBASE, BC_INST_OBASE, BC_INST_SCALE,
#if BC_ENABLE_EXTRA_MATH
BC_INST_SEED,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_LENGTH, BC_INST_PRINT,
- BC_INST_SQRT, BC_INST_ABS,
+ BC_INST_LENGTH, BC_INST_PRINT, BC_INST_SQRT,
+ BC_INST_ABS,
#if BC_ENABLE_EXTRA_MATH
BC_INST_IRAND,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_ASCIIFY, BC_INST_MODEXP, BC_INST_DIVMOD,
- BC_INST_QUIT, BC_INST_INVALID,
+ BC_INST_ASCIIFY, BC_INST_MODEXP, BC_INST_DIVMOD,
+ BC_INST_QUIT, BC_INST_INVALID,
#if BC_ENABLE_EXTRA_MATH
BC_INST_RAND,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_MAXIBASE,
- BC_INST_MAXOBASE, BC_INST_MAXSCALE,
+ BC_INST_MAXIBASE, BC_INST_MAXOBASE, BC_INST_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH
BC_INST_MAXRAND,
#endif // BC_ENABLE_EXTRA_MATH
@@ -1184,17 +1196,17 @@ const uchar dc_parse_insts[] = {
BC_INST_INVALID,
#endif // BC_ENABLED
BC_INST_LEADING_ZERO, BC_INST_PRINT_STREAM, BC_INST_INVALID,
- BC_INST_REL_EQ, BC_INST_INVALID,
- BC_INST_EXECUTE, BC_INST_PRINT_STACK, BC_INST_CLEAR_STACK,
- BC_INST_INVALID, BC_INST_STACK_LEN, BC_INST_DUPLICATE, BC_INST_SWAP,
- BC_INST_POP,
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_REL_EQ, BC_INST_INVALID, BC_INST_EXECUTE,
+ BC_INST_PRINT_STACK, BC_INST_CLEAR_STACK, BC_INST_INVALID,
+ BC_INST_STACK_LEN, BC_INST_DUPLICATE, BC_INST_SWAP,
+ BC_INST_POP, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_INVALID,
#if BC_ENABLE_EXTRA_MATH
BC_INST_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
- BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
- BC_INST_PRINT_POP, BC_INST_NQUIT, BC_INST_EXEC_STACK_LEN,
- BC_INST_SCALE_FUNC, BC_INST_INVALID,
+ BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
+ BC_INST_PRINT_POP, BC_INST_NQUIT, BC_INST_EXEC_STACK_LEN,
+ BC_INST_SCALE_FUNC, BC_INST_INVALID,
};
#endif // DC_ENABLED
@@ -1207,6 +1219,8 @@ const BcRandState bc_rand_multiplier = BC_RAND_MULTIPLIER;
#endif // BC_ENABLE_EXTRA_MATH
+// clang-format off
+
#if BC_LONG_BIT >= 64
/// A constant array for the max of a bigdig number as a BcDig array.
@@ -1245,6 +1259,8 @@ const BcDig bc_num_bigdigMax2[] = {
#endif // BC_LONG_BIT >= 64
+// clang-format on
+
/// The size of the bigdig max array.
const size_t bc_num_bigdigMax_size = sizeof(bc_num_bigdigMax) / sizeof(BcDig);
@@ -1254,6 +1270,8 @@ const size_t bc_num_bigdigMax2_size = sizeof(bc_num_bigdigMax2) / sizeof(BcDig);
/// A string of digits for easy conversion from characters to digits.
const char bc_num_hex_digits[] = "0123456789ABCDEF";
+// clang-format off
+
/// An array for easy conversion from exponent to power of 10.
const BcBigDig bc_num_pow10[BC_BASE_DIGS + 1] = {
1,
@@ -1270,12 +1288,15 @@ const BcBigDig bc_num_pow10[BC_BASE_DIGS + 1] = {
#endif // BC_BASE_DIGS > 4
};
+// clang-format on
+
#if !BC_ENABLE_LIBRARY
/// An array of functions for binary operators corresponding to the order of
/// the instructions for the operators.
const BcNumBinaryOp bc_program_ops[] = {
- bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub,
+ bc_num_pow, bc_num_mul, bc_num_div,
+ bc_num_mod, bc_num_add, bc_num_sub,
#if BC_ENABLE_EXTRA_MATH
bc_num_places, bc_num_lshift, bc_num_rshift,
#endif // BC_ENABLE_EXTRA_MATH
@@ -1284,8 +1305,8 @@ const BcNumBinaryOp bc_program_ops[] = {
/// An array of functions for binary operators allocation requests corresponding
/// to the order of the instructions for the operators.
const BcNumBinaryOpReq bc_program_opReqs[] = {
- bc_num_powReq, bc_num_mulReq, bc_num_divReq, bc_num_divReq,
- bc_num_addReq, bc_num_addReq,
+ bc_num_powReq, bc_num_mulReq, bc_num_divReq,
+ bc_num_divReq, bc_num_addReq, bc_num_addReq,
#if BC_ENABLE_EXTRA_MATH
bc_num_placesReq, bc_num_placesReq, bc_num_placesReq,
#endif // BC_ENABLE_EXTRA_MATH
@@ -1294,7 +1315,8 @@ const BcNumBinaryOpReq bc_program_opReqs[] = {
/// An array of unary operator functions corresponding to the order of the
/// instructions.
const BcProgramUnary bc_program_unarys[] = {
- bc_program_negate, bc_program_not,
+ bc_program_negate,
+ bc_program_not,
#if BC_ENABLE_EXTRA_MATH
bc_program_trunc,
#endif // BC_ENABLE_EXTRA_MATH
diff --git a/src/dc.c b/src/dc.c
index 67bc3e16c3c2..f873241286e0 100644
--- a/src/dc.c
+++ b/src/dc.c
@@ -45,8 +45,9 @@
* @param argc The number of arguments.
* @param argv The arguments.
*/
-void dc_main(int argc, char *argv[]) {
-
+void
+dc_main(int argc, char* argv[])
+{
// All of these just set dc-specific items in BcVm.
vm.read_ret = BC_INST_POP_EXEC;
diff --git a/src/dc_lex.c b/src/dc_lex.c
index 7f2f5dedc484..b76c966f6059 100644
--- a/src/dc_lex.c
+++ b/src/dc_lex.c
@@ -40,7 +40,9 @@
#include <dc.h>
#include <vm.h>
-bool dc_lex_negCommand(BcLex *l) {
+bool
+dc_lex_negCommand(BcLex* l)
+{
char c = l->buf[l->i];
return !BC_LEX_NUM_CHAR(c, false, false);
}
@@ -50,11 +52,12 @@ bool dc_lex_negCommand(BcLex *l) {
* extended-register extension is implemented.
* @param l The lexer.
*/
-static void dc_lex_register(BcLex *l) {
-
+static void
+dc_lex_register(BcLex* l)
+{
// If extended register is enabled and the character is whitespace...
- if (DC_X && isspace(l->buf[l->i - 1])) {
-
+ if (DC_X && isspace(l->buf[l->i - 1]))
+ {
char c;
// Eat the whitespace.
@@ -63,18 +66,22 @@ static void dc_lex_register(BcLex *l) {
// Check for a letter or underscore.
if (BC_ERR(!isalpha(c) && c != '_'))
+ {
bc_lex_verr(l, BC_ERR_PARSE_CHAR, c);
+ }
// Parse a normal identifier.
l->i += 1;
bc_lex_name(l);
}
- else {
-
+ else
+ {
// I don't allow newlines because newlines are used for controlling when
// execution happens, and allowing newlines would just be complex.
if (BC_ERR(l->buf[l->i - 1] == '\n'))
+ {
bc_lex_verr(l, BC_ERR_PARSE_CHAR, l->buf[l->i - 1]);
+ }
// Set the lexer string and token.
bc_vec_popAll(&l->str);
@@ -90,8 +97,9 @@ static void dc_lex_register(BcLex *l) {
* characters. Oh, and dc strings need to check for escaped brackets.
* @param l The lexer.
*/
-static void dc_lex_string(BcLex *l) {
-
+static void
+dc_lex_string(BcLex* l)
+{
size_t depth, nls, i;
char c;
bool got_more;
@@ -100,8 +108,8 @@ static void dc_lex_string(BcLex *l) {
l->t = BC_LEX_STR;
bc_vec_popAll(&l->str);
- do {
-
+ do
+ {
depth = 1;
nls = 0;
got_more = false;
@@ -111,14 +119,16 @@ static void dc_lex_string(BcLex *l) {
// This is the meat. As long as we don't run into the NUL byte, and we
// have "depth", which means we haven't completely balanced brackets
// yet, we continue eating the string.
- for (i = l->i; (c = l->buf[i]) && depth; ++i) {
-
+ for (i = l->i; (c = l->buf[i]) && depth; ++i)
+ {
// Check for escaped brackets and set the depths as appropriate.
- if (c == '\\') {
+ if (c == '\\')
+ {
c = l->buf[++i];
if (!c) break;
}
- else {
+ else
+ {
depth += (c == '[');
depth -= (c == ']');
}
@@ -129,16 +139,20 @@ static void dc_lex_string(BcLex *l) {
if (depth) bc_vec_push(&l->str, &c);
}
- if (BC_ERR(c == '\0' && depth)) {
+ if (BC_ERR(c == '\0' && depth))
+ {
if (!vm.eof && (l->is_stdin || l->is_exprs))
+ {
got_more = bc_lex_readLine(l);
+ }
if (got_more) bc_vec_popAll(&l->str);
}
-
- } while (got_more && depth);
+ }
+ while (got_more && depth);
// Obviously, if we didn't balance, that's an error.
- if (BC_ERR(c == '\0' && depth)) {
+ if (BC_ERR(c == '\0' && depth))
+ {
l->i = i;
bc_lex_err(l, BC_ERR_PARSE_STRING);
}
@@ -153,8 +167,9 @@ static void dc_lex_string(BcLex *l) {
* Lexes a dc token. This is the dc implementation of BcLexNext.
* @param l The lexer.
*/
-void dc_lex_token(BcLex *l) {
-
+void
+dc_lex_token(BcLex* l)
+{
char c = l->buf[l->i++], c2;
size_t i;
@@ -162,10 +177,11 @@ void dc_lex_token(BcLex *l) {
// If the last token was a command that needs a register, we need to parse a
// register, so do so.
- for (i = 0; i < dc_lex_regs_len; ++i) {
-
+ for (i = 0; i < dc_lex_regs_len; ++i)
+ {
// If the token is a register token, take care of it and return.
- if (l->last == dc_lex_regs[i]) {
+ if (l->last == dc_lex_regs[i])
+ {
dc_lex_register(l);
return;
}
@@ -181,8 +197,8 @@ void dc_lex_token(BcLex *l) {
// This is the workhorse of the lexer when more complicated things are
// needed.
- switch (c) {
-
+ switch (c)
+ {
case '\0':
case '\n':
case '\t':
@@ -224,7 +240,9 @@ void dc_lex_token(BcLex *l) {
// If the character after is a number, this dot is part of a number.
// Otherwise, it's the BSD dot (equivalent to last).
if (BC_NO_ERR(BC_LEX_NUM_CHAR(c2, true, false)))
+ {
bc_lex_number(l, c);
+ }
else bc_lex_invalidChar(l, c);
break;
diff --git a/src/dc_parse.c b/src/dc_parse.c
index 26aad6796d88..d45f951bad4f 100644
--- a/src/dc_parse.c
+++ b/src/dc_parse.c
@@ -50,8 +50,9 @@
* @param p The parser.
* @param var True if the parser is for a variable, false otherwise.
*/
-static void dc_parse_register(BcParse *p, bool var) {
-
+static void
+dc_parse_register(BcParse* p, bool var)
+{
bc_lex_next(&p->l);
if (p->l.t != BC_LEX_NAME) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
@@ -62,7 +63,9 @@ static void dc_parse_register(BcParse *p, bool var) {
* Parses a dc string.
* @param p The parser.
*/
-static inline void dc_parse_string(BcParse *p) {
+static inline void
+dc_parse_string(BcParse* p)
+{
bc_parse_addString(p);
bc_lex_next(&p->l);
}
@@ -75,8 +78,9 @@ static inline void dc_parse_string(BcParse *p) {
* a global.
* @param store True if the operation is a store, false otherwise.
*/
-static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) {
-
+static void
+dc_parse_mem(BcParse* p, uchar inst, bool name, bool store)
+{
// Push the instruction.
bc_parse_push(p, inst);
@@ -85,7 +89,8 @@ static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) {
// Stores use the bc assign infrastructure, but they need to do a swap
// first.
- if (store) {
+ if (store)
+ {
bc_parse_push(p, BC_INST_SWAP);
bc_parse_push(p, BC_INST_ASSIGN_NO_VAL);
}
@@ -98,8 +103,9 @@ static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) {
* @param p The parser.
* @param inst The instruction for the condition.
*/
-static void dc_parse_cond(BcParse *p, uchar inst) {
-
+static void
+dc_parse_cond(BcParse* p, uchar inst)
+{
// Push the instruction for the condition and the conditional execution.
bc_parse_push(p, inst);
bc_parse_push(p, BC_INST_EXEC_COND);
@@ -110,7 +116,8 @@ static void dc_parse_cond(BcParse *p, uchar inst) {
bc_lex_next(&p->l);
// If the next token is an else, parse the else.
- if (p->l.t == BC_LEX_KW_ELSE) {
+ if (p->l.t == BC_LEX_KW_ELSE)
+ {
dc_parse_register(p, true);
bc_lex_next(&p->l);
}
@@ -124,13 +131,14 @@ static void dc_parse_cond(BcParse *p, uchar inst) {
* @param t The token to parse.
* @param flags The flags that say what is allowed or not.
*/
-static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
-
+static void
+dc_parse_token(BcParse* p, BcLexType t, uint8_t flags)
+{
uchar inst;
bool assign, get_token = false;
- switch (t) {
-
+ switch (t)
+ {
case BC_LEX_OP_REL_EQ:
case BC_LEX_OP_REL_LE:
case BC_LEX_OP_REL_GE:
@@ -161,16 +169,18 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
// This tells us whether or not the neg is for a command or at the
// beginning of a number. If it's a command, push it. Otherwise,
// fallthrough and parse the number.
- if (dc_lex_negCommand(&p->l)) {
+ if (dc_lex_negCommand(&p->l))
+ {
bc_parse_push(p, BC_INST_NEG);
get_token = true;
break;
}
bc_lex_next(&p->l);
+
+ // Fallthrough.
+ BC_FALLTHROUGH
}
- // Fallthrough.
- BC_FALLTHROUGH
case BC_LEX_NUMBER:
{
@@ -187,7 +197,9 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
{
// Make sure the read is not recursive.
if (BC_ERR(flags & BC_PARSE_NOREAD))
+ {
bc_parse_err(p, BC_ERR_EXEC_REC_READ);
+ }
else bc_parse_push(p, BC_INST_READ);
get_token = true;
@@ -254,8 +266,9 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
if (get_token) bc_lex_next(&p->l);
}
-void dc_parse_expr(BcParse *p, uint8_t flags) {
-
+void
+dc_parse_expr(BcParse* p, uint8_t flags)
+{
BcInst inst;
BcLexType t;
bool need_expr, have_expr = false;
@@ -267,10 +280,11 @@ void dc_parse_expr(BcParse *p, uint8_t flags) {
// designed.
// While we don't have EOF...
- while ((t = p->l.t) != BC_LEX_EOF) {
-
+ while ((t = p->l.t) != BC_LEX_EOF)
+ {
// Eat newline.
- if (t == BC_LEX_NLINE) {
+ if (t == BC_LEX_NLINE)
+ {
bc_lex_next(&p->l);
continue;
}
@@ -281,7 +295,8 @@ void dc_parse_expr(BcParse *p, uint8_t flags) {
// If the instruction is invalid, that means we have to do some harder
// parsing. So if not invalid, just push the instruction; otherwise,
// parse the token.
- if (inst != BC_INST_INVALID) {
+ if (inst != BC_INST_INVALID)
+ {
bc_parse_push(p, inst);
bc_lex_next(&p->l);
}
@@ -295,11 +310,14 @@ void dc_parse_expr(BcParse *p, uint8_t flags) {
// indicate that it is executing a string.
if (BC_ERR(need_expr && !have_expr)) bc_err(BC_ERR_EXEC_READ_EXPR);
else if (p->l.t == BC_LEX_EOF && (flags & BC_PARSE_NOCALL))
+ {
bc_parse_push(p, BC_INST_POP_EXEC);
+ }
}
-void dc_parse_parse(BcParse *p) {
-
+void
+dc_parse_parse(BcParse* p)
+{
assert(p != NULL);
BC_SETJMP_LOCKED(exit);
diff --git a/src/file.c b/src/file.c
index 627664a9c261..e5d2f6ac73d8 100644
--- a/src/file.c
+++ b/src/file.c
@@ -44,22 +44,26 @@
#include <file.h>
#include <vm.h>
+#if !BC_ENABLE_LINE_LIB
+
/**
* Translates an integer into a string.
* @param val The value to translate.
* @param buf The return parameter.
*/
-static void bc_file_ultoa(unsigned long long val, char buf[BC_FILE_ULL_LENGTH])
+static void
+bc_file_ultoa(unsigned long long val, char buf[BC_FILE_ULL_LENGTH])
{
char buf2[BC_FILE_ULL_LENGTH];
size_t i, len;
// We need to make sure the entire thing is zeroed.
+ // NOLINTNEXTLINE
memset(buf2, 0, BC_FILE_ULL_LENGTH);
// The i = 1 is to ensure that there is a null byte at the end.
- for (i = 1; val; ++i) {
-
+ for (i = 1; val; ++i)
+ {
unsigned long long mod = val % 10;
buf2[i] = ((char) mod) + '0';
@@ -69,7 +73,10 @@ static void bc_file_ultoa(unsigned long long val, char buf[BC_FILE_ULL_LENGTH])
len = i;
// Since buf2 is reversed, reverse it into buf.
- for (i = 0; i < len; ++i) buf[i] = buf2[len - i - 1];
+ for (i = 0; i < len; ++i)
+ {
+ buf[i] = buf2[len - i - 1];
+ }
}
/**
@@ -80,22 +87,23 @@ static void bc_file_ultoa(unsigned long long val, char buf[BC_FILE_ULL_LENGTH])
* @return A status indicating error or success. We could have a fatal I/O
* error or EOF.
*/
-static BcStatus bc_file_output(int fd, const char *buf, size_t n) {
-
+static BcStatus
+bc_file_output(int fd, const char* buf, size_t n)
+{
size_t bytes = 0;
sig_atomic_t lock;
BC_SIG_TRYLOCK(lock);
// While the number of bytes written is less than intended...
- while (bytes < n) {
-
+ while (bytes < n)
+ {
// Write.
ssize_t written = write(fd, buf + bytes, n - bytes);
// Check for error and return, if any.
- if (BC_ERR(written == -1)) {
-
+ if (BC_ERR(written == -1))
+ {
BC_SIG_TRYUNLOCK(lock);
return errno == EPIPE ? BC_STATUS_EOF : BC_STATUS_ERROR_FATAL;
@@ -109,20 +117,31 @@ static BcStatus bc_file_output(int fd, const char *buf, size_t n) {
return BC_STATUS_SUCCESS;
}
-BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
+#endif // !BC_ENABLE_LINE_LIB
+
+BcStatus
+bc_file_flushErr(BcFile* restrict f, BcFlushType type)
{
BcStatus s;
BC_SIG_ASSERT_LOCKED;
- // If there is stuff to output...
- if (f->len) {
+#if BC_ENABLE_LINE_LIB
+
+ // Just flush and propagate the error.
+ if (fflush(f->f) == EOF) s = BC_STATUS_ERROR_FATAL;
+ else s = BC_STATUS_SUCCESS;
+
+#else // BC_ENABLE_LINE_LIB
+ // If there is stuff to output...
+ if (f->len)
+ {
#if BC_ENABLE_HISTORY
// If history is enabled...
- if (BC_TTY) {
-
+ if (BC_TTY)
+ {
// If we have been told to save the extras, and there *are*
// extras...
if (f->buf[f->len - 1] != '\n' &&
@@ -132,7 +151,10 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
size_t i;
// Look for the last newline.
- for (i = f->len - 2; i < f->len && f->buf[i] != '\n'; --i);
+ for (i = f->len - 2; i < f->len && f->buf[i] != '\n'; --i)
+ {
+ continue;
+ }
i += 1;
@@ -140,7 +162,8 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
bc_vec_string(&vm.history.extras, f->len - i, f->buf + i);
}
// Else clear the extras if told to.
- else if (type >= BC_FLUSH_NO_EXTRAS_CLEAR) {
+ else if (type >= BC_FLUSH_NO_EXTRAS_CLEAR)
+ {
bc_vec_popAll(&vm.history.extras);
}
}
@@ -152,11 +175,14 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
}
else s = BC_STATUS_SUCCESS;
+#endif // BC_ENABLE_LINE_LIB
+
return s;
}
-void bc_file_flush(BcFile *restrict f, BcFlushType type) {
-
+void
+bc_file_flush(BcFile* restrict f, BcFlushType type)
+{
BcStatus s;
sig_atomic_t lock;
@@ -165,10 +191,11 @@ void bc_file_flush(BcFile *restrict f, BcFlushType type) {
s = bc_file_flushErr(f, type);
// If we have an error...
- if (BC_ERR(s)) {
-
+ if (BC_ERR(s))
+ {
// For EOF, set it and jump.
- if (s == BC_STATUS_EOF) {
+ if (s == BC_STATUS_EOF)
+ {
vm.status = (sig_atomic_t) s;
BC_SIG_TRYUNLOCK(lock);
BC_JMP;
@@ -180,23 +207,44 @@ void bc_file_flush(BcFile *restrict f, BcFlushType type) {
BC_SIG_TRYUNLOCK(lock);
}
-void bc_file_write(BcFile *restrict f, BcFlushType type,
- const char *buf, size_t n)
+#if !BC_ENABLE_LINE_LIB
+
+void
+bc_file_write(BcFile* restrict f, BcFlushType type, const char* buf, size_t n)
{
sig_atomic_t lock;
BC_SIG_TRYLOCK(lock);
// If we have enough to flush, do it.
- if (n > f->cap - f->len) {
+ if (n > f->cap - f->len)
+ {
bc_file_flush(f, type);
assert(!f->len);
}
// If the output is large enough to flush by itself, just output it.
// Otherwise, put it into the buffer.
- if (BC_UNLIKELY(n > f->cap - f->len)) bc_file_output(f->fd, buf, n);
- else {
+ if (BC_UNLIKELY(n > f->cap - f->len))
+ {
+ BcStatus s = bc_file_output(f->fd, buf, n);
+
+ if (BC_ERR(s))
+ {
+ // For EOF, set it and jump.
+ if (s == BC_STATUS_EOF)
+ {
+ vm.status = (sig_atomic_t) s;
+ BC_SIG_TRYUNLOCK(lock);
+ BC_JMP;
+ }
+ // Blow up on fatal error. Okay, not blow up, just quit.
+ else bc_vm_fatalError(BC_ERR_FATAL_IO_ERR);
+ }
+ }
+ else
+ {
+ // NOLINTNEXTLINE
memcpy(f->buf + f->len, buf, n);
f->len += n;
}
@@ -204,7 +252,10 @@ void bc_file_write(BcFile *restrict f, BcFlushType type,
BC_SIG_TRYUNLOCK(lock);
}
-void bc_file_printf(BcFile *restrict f, const char *fmt, ...)
+#endif // BC_ENABLE_LINE_LIB
+
+void
+bc_file_printf(BcFile* restrict f, const char* fmt, ...)
{
va_list args;
sig_atomic_t lock;
@@ -218,13 +269,24 @@ void bc_file_printf(BcFile *restrict f, const char *fmt, ...)
BC_SIG_TRYUNLOCK(lock);
}
-void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
+void
+bc_file_vprintf(BcFile* restrict f, const char* fmt, va_list args)
+{
+ BC_SIG_ASSERT_LOCKED;
- char *percent;
- const char *ptr = fmt;
- char buf[BC_FILE_ULL_LENGTH];
+#if BC_ENABLE_LINE_LIB
- BC_SIG_ASSERT_LOCKED;
+ // Just print and propagate the error.
+ if (BC_ERR(vfprintf(f->f, fmt, args) < 0))
+ {
+ bc_vm_fatalError(BC_ERR_FATAL_IO_ERR);
+ }
+
+#else // BC_ENABLE_LINE_LIB
+
+ char* percent;
+ const char* ptr = fmt;
+ char buf[BC_FILE_ULL_LENGTH];
// This is a poor man's printf(). While I could look up algorithms to make
// it as fast as possible, and should when I write the standard library for
@@ -232,13 +294,14 @@ void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
// for now.
// Find each percent sign.
- while ((percent = strchr(ptr, '%')) != NULL) {
-
+ while ((percent = strchr(ptr, '%')) != NULL)
+ {
char c;
// If the percent sign is not where we are, write what's inbetween to
// the buffer.
- if (percent != ptr) {
+ if (percent != ptr)
+ {
size_t len = (size_t) (percent - ptr);
bc_file_write(f, bc_flush_none, ptr, len);
}
@@ -247,40 +310,42 @@ void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
// We only parse some format specifiers, the ones bc uses. If you add
// more, you need to make sure to add them here.
- if (c == 'c') {
-
+ if (c == 'c')
+ {
uchar uc = (uchar) va_arg(args, int);
bc_file_putchar(f, bc_flush_none, uc);
}
- else if (c == 's') {
-
- char *s = va_arg(args, char*);
+ else if (c == 's')
+ {
+ char* s = va_arg(args, char*);
bc_file_puts(f, bc_flush_none, s);
}
#if BC_DEBUG_CODE
// We only print signed integers in debug code.
- else if (c == 'd') {
-
+ else if (c == 'd')
+ {
int d = va_arg(args, int);
// Take care of negative. Let's not worry about overflow.
- if (d < 0) {
+ if (d < 0)
+ {
bc_file_putchar(f, bc_flush_none, '-');
d = -d;
}
// Either print 0 or translate and print.
if (!d) bc_file_putchar(f, bc_flush_none, '0');
- else {
+ else
+ {
bc_file_ultoa((unsigned long long) d, buf);
bc_file_puts(f, bc_flush_none, buf);
}
}
#endif // BC_DEBUG_CODE
- else {
-
+ else
+ {
unsigned long long ull;
// These are the ones that it expects from here. Fortunately, all of
@@ -293,7 +358,8 @@ void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
// Either print 0 or translate and print.
if (!ull) bc_file_putchar(f, bc_flush_none, '0');
- else {
+ else
+ {
bc_file_ultoa(ull, buf);
bc_file_puts(f, bc_flush_none, buf);
}
@@ -306,18 +372,42 @@ void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
// If we get here, there are no more percent signs, so we just output
// whatever is left.
if (ptr[0]) bc_file_puts(f, bc_flush_none, ptr);
+
+#endif // BC_ENABLE_LINE_LIB
}
-void bc_file_puts(BcFile *restrict f, BcFlushType type, const char *str) {
+void
+bc_file_puts(BcFile* restrict f, BcFlushType type, const char* str)
+{
+#if BC_ENABLE_LINE_LIB
+ // This is used because of flushing issues with using bc_file_write() when
+ // bc is using a line library. It's also using printf() because puts()
+ // writes a newline.
+ bc_file_printf(f, "%s", str);
+#else // BC_ENABLE_LINE_LIB
bc_file_write(f, type, str, strlen(str));
+#endif // BC_ENABLE_LINE_LIB
}
-void bc_file_putchar(BcFile *restrict f, BcFlushType type, uchar c) {
-
+void
+bc_file_putchar(BcFile* restrict f, BcFlushType type, uchar c)
+{
sig_atomic_t lock;
BC_SIG_TRYLOCK(lock);
+#if BC_ENABLE_LINE_LIB
+
+ if (BC_ERR(fputc(c, f->f) == EOF))
+ {
+ // This is here to prevent a stack overflow from unbounded recursion.
+ if (f->f == stderr) exit(BC_STATUS_ERROR_FATAL);
+
+ bc_vm_fatalError(BC_ERR_FATAL_IO_ERR);
+ }
+
+#else // BC_ENABLE_LINE_LIB
+
if (f->len == f->cap) bc_file_flush(f, type);
assert(f->len < f->cap);
@@ -325,11 +415,25 @@ void bc_file_putchar(BcFile *restrict f, BcFlushType type, uchar c) {
f->buf[f->len] = (char) c;
f->len += 1;
+#endif // BC_ENABLE_LINE_LIB
+
BC_SIG_TRYUNLOCK(lock);
}
-void bc_file_init(BcFile *f, int fd, char *buf, size_t cap) {
+#if BC_ENABLE_LINE_LIB
+
+void
+bc_file_init(BcFile* f, FILE* file)
+{
+ BC_SIG_ASSERT_LOCKED;
+ f->f = file;
+}
+
+#else // BC_ENABLE_LINE_LIB
+void
+bc_file_init(BcFile* f, int fd, char* buf, size_t cap)
+{
BC_SIG_ASSERT_LOCKED;
f->fd = fd;
@@ -338,7 +442,11 @@ void bc_file_init(BcFile *f, int fd, char *buf, size_t cap) {
f->cap = cap;
}
-void bc_file_free(BcFile *f) {
+#endif // BC_ENABLE_LINE_LIB
+
+void
+bc_file_free(BcFile* f)
+{
BC_SIG_ASSERT_LOCKED;
bc_file_flush(f, bc_flush_none);
}
diff --git a/src/history.c b/src/history.c
index 74123a7c4918..0b2713857ec6 100644
--- a/src/history.c
+++ b/src/history.c
@@ -144,6 +144,236 @@
#if BC_ENABLE_HISTORY
+#if BC_ENABLE_EDITLINE
+
+#include <string.h>
+#include <errno.h>
+#include <setjmp.h>
+
+#include <history.h>
+#include <vm.h>
+
+sigjmp_buf bc_history_jmpbuf;
+volatile sig_atomic_t bc_history_inlinelib;
+
+static char* bc_history_prompt;
+static HistEvent bc_history_event;
+
+static char*
+bc_history_promptFunc(EditLine* el)
+{
+ BC_UNUSED(el);
+ return bc_history_prompt;
+}
+
+void
+bc_history_init(BcHistory* h)
+{
+ BcVec v;
+ char* home = getenv("HOME");
+
+ // This will hold the true path to the editrc.
+ bc_vec_init(&v, 1, BC_DTOR_NONE);
+
+ // Initialize the path to the editrc. This is done manually because the
+ // libedit I used to test was failing with a NULL argument for the path,
+ // which was supposed to automatically do $HOME/.editrc. But it was failing,
+ // so I set it manually.
+ if (home == NULL)
+ {
+ bc_vec_string(&v, bc_history_editrc_len - 1, bc_history_editrc + 1);
+ }
+ else
+ {
+ bc_vec_string(&v, strlen(home), home);
+ bc_vec_concat(&v, bc_history_editrc);
+ }
+
+ h->hist = history_init();
+ if (BC_ERR(h->hist == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR);
+
+ h->el = el_init(vm.name, stdin, stdout, stderr);
+ if (BC_ERR(h->el == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR);
+
+ // I want history and a prompt.
+ history(h->hist, &bc_history_event, H_SETSIZE, 100);
+ history(h->hist, &bc_history_event, H_SETUNIQUE, 1);
+ el_set(h->el, EL_EDITOR, "emacs");
+ el_set(h->el, EL_HIST, history, h->hist);
+ el_set(h->el, EL_PROMPT, bc_history_promptFunc);
+
+ // I also want to get the user's .editrc.
+ el_source(h->el, v.v);
+
+ bc_vec_free(&v);
+
+ h->badTerm = false;
+ bc_history_prompt = NULL;
+}
+
+void
+bc_history_free(BcHistory* h)
+{
+ if (bc_history_prompt != NULL) free(bc_history_prompt);
+ el_end(h->el);
+ history_end(h->hist);
+}
+
+BcStatus
+bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
+{
+ BcStatus s = BC_STATUS_SUCCESS;
+ const char* line;
+ int len;
+
+ BC_SIG_LOCK;
+
+ // If the jump happens here, then a SIGINT occurred.
+ if (sigsetjmp(bc_history_jmpbuf, 0))
+ {
+ bc_vec_string(vec, 1, "\n");
+ goto end;
+ }
+
+ // This is so the signal handler can handle line libraries properly.
+ bc_history_inlinelib = 1;
+
+ // Make sure to set the prompt.
+ if (bc_history_prompt != NULL)
+ {
+ if (strcmp(bc_history_prompt, prompt))
+ {
+ free(bc_history_prompt);
+ bc_history_prompt = bc_vm_strdup(prompt);
+ }
+ }
+ else bc_history_prompt = bc_vm_strdup(prompt);
+
+ // Get the line.
+ line = el_gets(h->el, &len);
+
+ // If there is no line...
+ if (BC_ERR(line == NULL))
+ {
+ // If this is true, there was an error. Otherwise, it's just EOF.
+ if (len == -1)
+ {
+ if (errno == ENOMEM) bc_err(BC_ERR_FATAL_ALLOC_ERR);
+ bc_err(BC_ERR_FATAL_IO_ERR);
+ }
+ else s = BC_STATUS_EOF;
+ }
+ // If there is a line...
+ else
+ {
+ bc_vec_string(vec, strlen(line), line);
+
+ if (strcmp(line, "") && strcmp(line, "\n"))
+ {
+ history(h->hist, &bc_history_event, H_ENTER, line);
+ }
+
+ s = BC_STATUS_SUCCESS;
+ }
+
+end:
+
+ bc_history_inlinelib = 0;
+
+ BC_SIG_UNLOCK;
+
+ return s;
+}
+
+#else // BC_ENABLE_EDITLINE
+
+#if BC_ENABLE_READLINE
+
+#include <assert.h>
+#include <setjmp.h>
+#include <string.h>
+
+#include <history.h>
+#include <vm.h>
+
+sigjmp_buf bc_history_jmpbuf;
+volatile sig_atomic_t bc_history_inlinelib;
+
+void
+bc_history_init(BcHistory* h)
+{
+ h->line = NULL;
+ h->badTerm = false;
+
+ // I want no tab completion.
+ rl_bind_key('\t', rl_insert);
+}
+
+void
+bc_history_free(BcHistory* h)
+{
+ if (h->line != NULL) free(h->line);
+}
+
+BcStatus
+bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
+{
+ BcStatus s = BC_STATUS_SUCCESS;
+ size_t len;
+
+ BC_SIG_LOCK;
+
+ // If the jump happens here, then a SIGINT occurred.
+ if (sigsetjmp(bc_history_jmpbuf, 0))
+ {
+ bc_vec_string(vec, 1, "\n");
+ goto end;
+ }
+
+ // This is so the signal handler can handle line libraries properly.
+ bc_history_inlinelib = 1;
+
+ // Get rid of the las