commit: c7d55edad461cbf326803b3ced8b8187470f5b6a
parent 858cfd217f4db2613550379898561a41bc34e741
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 5 Mar 2019 23:58:15 -0800
bc: Replace with Gavin Howard's implementation
Diffstat:
11 files changed, 115 insertions(+), 78 deletions(-)
diff --git a/.gitmodules b/.gitmodules
@@ -14,6 +14,10 @@
path = pkg/awk/src
url = https://github.com/onetrueawk/awk
ignore = all
+[submodule "pkg/bc/src"]
+ path = pkg/bc/src
+ url = https://github.com/gavinhoward/bc
+ ignore = all
[submodule "pkg/bearssl/src"]
path = pkg/bearssl/src
url = https://www.bearssl.org/git/BearSSL
diff --git a/pkg/bc/.gitignore b/pkg/bc/.gitignore
@@ -1,2 +1 @@
-/bc-1.06.95.tar.bz2
-/src
+/tools.ninja
diff --git a/pkg/bc/config.h b/pkg/bc/config.h
@@ -1,40 +1,8 @@
-#define BC_COPYRIGHT "Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc."
-#define DC_COPYRIGHT "Copyright 1994, 1997, 1998, 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc."
-#define DC_VERSION "1.3.95"
-/* #undef HAVE_DOPRNT */
-#define HAVE_ERRNO_H 1
-#define HAVE_FSTAT 1
-#define HAVE_INTTYPES_H 1
-#define HAVE_ISGRAPH 1
-/* #undef HAVE_LIB_H */
-#define HAVE_LIMITS_H 1
-#define HAVE_MEMORY_H 1
-#define HAVE_SETVBUF 1
-#define HAVE_STDARG_H 1
-#define HAVE_STDDEF_H 1
-#define HAVE_STDINT_H 1
-#define HAVE_STDLIB_H 1
-#define HAVE_STRINGS_H 1
-#define HAVE_STRING_H 1
-#define HAVE_STRTOL 1
-#define HAVE_SYS_STAT_H 1
-#define HAVE_SYS_TYPES_H 1
-#define HAVE_UNISTD_H 1
-#define HAVE_VPRINTF 1
-/* #undef LIBEDIT */
-#define PACKAGE "bc"
-#define PACKAGE_BUGREPORT ""
-#define PACKAGE_NAME "bc"
-#define PACKAGE_STRING "bc 1.06.95"
-#define PACKAGE_TARNAME "bc"
-#define PACKAGE_VERSION "1.06.95"
-/* #undef READLINE */
-#define STDC_HEADERS 1
-#define VERSION "1.06.95"
-/* #undef YYTEXT_POINTER */
-/* #undef _MINIX */
-/* #undef _POSIX_1_SOURCE */
-/* #undef _POSIX_SOURCE */
-/* #undef const */
-/* #undef ptrdiff_t */
-/* #undef size_t */
+#define BC_ENABLED 1
+#define DC_ENABLED 0
+
+#define BC_ENABLE_EXTRA_MATH 1
+#define BC_ENABLE_HISTORY 1
+#define BC_ENABLE_REFERENCES 1
+#define BC_ENABLE_SIGNALS 1
+#define BC_NUM_KARATSUBA_LEN 32
diff --git a/pkg/bc/gen.lua b/pkg/bc/gen.lua
@@ -1,15 +1,48 @@
cflags{
- '-D HAVE_CONFIG_H',
- '-I $dir',
- '-I $srcdir/h',
+ '-D NDEBUG',
+ '-D VERSION=1.1.4',
+ '-D _POSIX_C_SOURCE=200809L',
+ '-I $srcdir/include',
+ '-include $dir/config.h',
}
-lib('libbc.a', {'lib/number.c'})
+sub('tools.ninja', function()
+ exe('strgen', {'gen/strgen.c'})
+ rule('strgen', [[$outdir/strgen $in $out.tmp $name $header '$label' '$define' $removetabs && mv $out.tmp $out]])
+ build('strgen', '$outdir/bc_help.c', {'$srcdir/gen/bc_help.txt', '|', '$outdir/strgen'}, {
+ name='bc_help', header='bc.h', label='', define='BC_ENABLED', removetabs='',
+ })
+ build('strgen', '$outdir/dc_help.c', {'$srcdir/gen/dc_help.txt', '|', '$outdir/strgen'}, {
+ name='dc_help', header='dc.h', label='', define='DC_ENABLED', removetabs='',
+ })
+ build('strgen', '$outdir/lib.c', {'$srcdir/gen/lib.bc', '|', '$outdir/strgen'}, {
+ name='bc_lib', header='bc.h', label='bc_lib_name', define='BC_ENABLED', removetabs='1',
+ })
+ build('strgen', '$outdir/lib2.c', {'$srcdir/gen/lib2.bc', '|', '$outdir/strgen'}, {
+ name='bc_lib2', header='bc.h', label='bc_lib2_name', define='BC_ENABLED && BC_ENABLE_EXTRA_MATH', removetabs='1',
+ })
+end)
+
exe('bin/bc', [[
- bc/(main.c bc.c scan.c execute.c load.c storage.c util.c global.c warranty.c)
- libbc.a
+ src/(
+ args.c
+ data.c
+ lang.c
+ lex.c
+ main.c
+ num.c
+ parse.c
+ program.c
+ read.c
+ vector.c
+ vm.c
+ bc/(bc.c lex.c parse.c)
+ dc/(dc.c lex.c parse.c)
+ history/history.c
+ )
+ $outdir/(bc_help.c dc_help.c lib.c lib2.c)
]])
file('bin/bc', '755', '$outdir/bin/bc')
-man{'doc/bc.1'}
+man{'manuals/bc.1'}
-fetch 'curl'
+fetch 'git'
diff --git a/pkg/bc/patch/0001-Fix-a-bug.patch b/pkg/bc/patch/0001-Fix-a-bug.patch
@@ -0,0 +1,25 @@
+From b8e4f427c41a66b272a04ef2506020e64504b443 Mon Sep 17 00:00:00 2001
+From: Gavin Howard <yzena.tech@gmail.com>
+Date: Wed, 20 Feb 2019 09:27:30 -0700
+Subject: [PATCH] Fix a bug
+
+---
+ src/read.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/read.c b/src/read.c
+index 43fa8e12..45237397 100644
+--- a/src/read.c
++++ b/src/read.c
+@@ -118,7 +118,7 @@ BcStatus bc_read_line(BcVec *vec, const char *prompt) {
+ if (bc_read_binary(vec->v, vec->len - 1))
+ return bc_vm_verr(BC_ERROR_VM_BIN_FILE, bc_program_stdin_name);
+
+- return BC_STATUS_SUCCESS;
++ return s;
+ }
+
+ BcStatus bc_read_file(const char *path, char **buf) {
+--
+2.21.0
+
diff --git a/pkg/bc/patch/0001-Fix-use-of-uninitialized-f_void.patch b/pkg/bc/patch/0001-Fix-use-of-uninitialized-f_void.patch
@@ -1,25 +0,0 @@
-From 359f44a3a0605c94d57f35e4de39e6028dce018f Mon Sep 17 00:00:00 2001
-From: Michael Forney <mforney@mforney.org>
-Date: Sun, 12 Jun 2016 20:12:28 -0700
-Subject: [PATCH] Fix use of uninitialized f_void
-
-See http://www.pixelbeat.org/programming/oss_bug_flow.html.
----
- bc/storage.c | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/bc/storage.c b/bc/storage.c
-index 699729a..37b4c6c 100644
---- a/bc/storage.c
-+++ b/bc/storage.c
-@@ -99,6 +99,7 @@ more_functions (VOID)
- {
- f = &functions[indx];
- f->f_defined = FALSE;
-+ f->f_void = FALSE;
- f->f_body = (char *) bc_malloc (BC_START_SIZE);
- f->f_body_size = BC_START_SIZE;
- f->f_code_size = 0;
---
-2.8.1
-
diff --git a/pkg/bc/patch/0002-Fix-EOF-behavior-in-interactive-mode-with-history.patch b/pkg/bc/patch/0002-Fix-EOF-behavior-in-interactive-mode-with-history.patch
@@ -0,0 +1,34 @@
+From bbaac8ed0fc40acc4349df837abed2af72276f52 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Wed, 6 Mar 2019 00:52:01 -0800
+Subject: [PATCH] Fix EOF behavior in interactive mode with history
+
+Previously, Ctrl-D would re-process the previous line, read one
+more line, then exit. This is because bc_history_line left the
+buffer untouched in case of EOF, and the bc_vm_stdin loop reads the
+next line before checking the `done` condition of the previous
+iteration.
+
+This fix also prevents reading passed the end of the buffer in case
+the first user input is EOF, since in that case, vec->len is still
+0, so (size_t)-1 is passed to bc_read_binary.
+---
+ src/history/history.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/history/history.c b/src/history/history.c
+index e9953ed5..d575256d 100644
+--- a/src/history/history.c
++++ b/src/history/history.c
+@@ -1229,7 +1229,7 @@ BcStatus bc_history_line(BcHistory *h, BcVec *vec, const char *prompt) {
+ if (BC_TTYIN && !vm->history.badTerm) {
+
+ s = bc_history_raw(h, prompt);
+- if (s) return s;
++ if (s && s != BC_STATUS_EOF) return s;
+
+ bc_vec_string(vec, BC_HISTORY_BUF_LEN(h), h->buf.v);
+
+--
+2.21.0
+
diff --git a/pkg/bc/rev b/pkg/bc/rev
@@ -1 +1 @@
-1
+2
diff --git a/pkg/bc/sha256 b/pkg/bc/sha256
@@ -1 +0,0 @@
-7ee4abbcfac03d8a6e1a8a3440558a3d239d6b858585063e745c760957725ecc bc-1.06.95.tar.bz2
diff --git a/pkg/bc/src b/pkg/bc/src
@@ -0,0 +1 @@
+Subproject commit 6fe912a279b71d6591a0cad1d3d8a2ce16138150
diff --git a/pkg/bc/url b/pkg/bc/url
@@ -1 +0,0 @@
-url = "http://alpha.gnu.org/gnu/bc/bc-1.06.95.tar.bz2"