git: f4ff1c300ef4 - main - vendor/bc: import of version 5.2.5

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Tue, 10 May 2022 12:50:46 UTC
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=f4ff1c300ef4081696bdd6ad34547be9242e419c

commit f4ff1c300ef4081696bdd6ad34547be9242e419c
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2022-05-10 12:47:43 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2022-05-10 12:50:29 +0000

    vendor/bc: import of version 5.2.5
    
    This is a production release that fixes this bc's behavior on ^D to
    match GNU bc.
    
    (cherry picked from commit ed0603704174b01c25b49efc08c82e1532dc5622)
---
 contrib/bc/NEWS.md            |  5 +++++
 contrib/bc/include/version.h  |  2 +-
 contrib/bc/scripts/package.sh | 13 +++++++++++++
 contrib/bc/scripts/release.sh |  1 +
 contrib/bc/src/history.c      | 16 ++++++++++++----
 contrib/bc/tests/history.py   |  7 +++++--
 6 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/contrib/bc/NEWS.md b/contrib/bc/NEWS.md
index 3a388b0dc316..1a8a5dd31ad8 100644
--- a/contrib/bc/NEWS.md
+++ b/contrib/bc/NEWS.md
@@ -1,5 +1,10 @@
 # News
 
+## 5.2.5
+
+This is a production release that fixes this `bc`'s behavior on `^D` to match
+GNU `bc`.
+
 ## 5.2.4
 
 This is a production release that fixes two bugs in history:
diff --git a/contrib/bc/include/version.h b/contrib/bc/include/version.h
index 4621b50bcbeb..da98b30bb767 100644
--- a/contrib/bc/include/version.h
+++ b/contrib/bc/include/version.h
@@ -37,6 +37,6 @@
 #define BC_VERSION_H
 
 /// The current version.
-#define VERSION 5.2.4
+#define VERSION 5.2.5
 
 #endif // BC_VERSION_H
diff --git a/contrib/bc/scripts/package.sh b/contrib/bc/scripts/package.sh
index 34692f7ab20a..e3a35b0fe65d 100755
--- a/contrib/bc/scripts/package.sh
+++ b/contrib/bc/scripts/package.sh
@@ -35,6 +35,7 @@
 # * git
 # * stat
 # * tar
+# * gzip
 # * xz
 # * sha512sum
 # * sha256sum
@@ -182,6 +183,14 @@ cd ..
 parent="$repo/.."
 
 # Cleanup old stuff.
+if [ -f "$projver.tar.gz" ]; then
+	rm -rf "$projver.tar.gz"
+fi
+
+if [ -f "$projver.tar.gz.sig" ]; then
+	rm -rf "$projver.tar.gz.sig"
+fi
+
 if [ -f "$projver.tar.xz" ]; then
 	rm -rf "$projver.tar.xz"
 fi
@@ -192,6 +201,8 @@ fi
 
 # Tar and compress and move into the parent directory of the repo.
 tar cf "$projver.tar" "$projver/"
+gzip -k "$projver.tar"
+mv "$projver.tar.gz" "$parent"
 xz -z -v -9 -e "$projver.tar" > /dev/null 2> /dev/null
 mv "$projver.tar.xz" "$parent"
 
@@ -242,6 +253,8 @@ rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.vcxproj.FileListA
 # Zip the Windows stuff.
 zip -r $projver-windows.zip windows > /dev/null
 
+printf '\n'
+shasum "$projver.tar.gz"
 printf '\n'
 shasum "$projver.tar.xz"
 printf '\n'
diff --git a/contrib/bc/scripts/release.sh b/contrib/bc/scripts/release.sh
index 12097b1cc8b9..02d3dd5dae24 100755
--- a/contrib/bc/scripts/release.sh
+++ b/contrib/bc/scripts/release.sh
@@ -601,6 +601,7 @@ clang_flags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral"
 clang_flags="$clang_flags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion"
 clang_flags="$clang_flags -Wno-unreachable-code -Wno-unreachable-code-return"
 clang_flags="$clang_flags -Wno-implicit-fallthrough -Wno-unused-macros -Wno-gnu-label-as-value"
+clang_flags="$clang_flags -Wno-declaration-after-statement"
 # -Wno-undef is here because Clang seems to think BC_C11 is undefined, when it's defined.
 clang_flags="$clang_flags -Wno-undef"
 gcc_flags="-Wno-maybe-uninitialized -Wno-clobbered"
diff --git a/contrib/bc/src/history.c b/contrib/bc/src/history.c
index 7e2661486a8b..74123a7c4918 100644
--- a/contrib/bc/src/history.c
+++ b/contrib/bc/src/history.c
@@ -1535,12 +1535,20 @@ static BcStatus bc_history_edit(BcHistory *h, const char *prompt) {
 			}
 
 #ifndef _WIN32
-			// Act as end-of-file.
+			// Act as end-of-file or delete-forward-char.
 			case BC_ACTION_CTRL_D:
 			{
-				bc_history_printCtrl(h, c);
-				BC_SIG_UNLOCK;
-				return BC_STATUS_EOF;
+				// Act as EOF if there's no chacters, otherwise emulate Emacs
+				// delete next character to match historical gnu bc behavior.
+				if (BC_HIST_BUF_LEN(h) == 0) {
+					bc_history_printCtrl(h, c);
+					BC_SIG_UNLOCK;
+					return BC_STATUS_EOF;
+				}
+
+				bc_history_edit_delete(h);
+
+				break;
 			}
 #endif // _WIN32
 
diff --git a/contrib/bc/tests/history.py b/contrib/bc/tests/history.py
index 84e32f9612c4..c74dfd72f0a7 100755
--- a/contrib/bc/tests/history.py
+++ b/contrib/bc/tests/history.py
@@ -282,8 +282,11 @@ def test_eof(exe, args, env):
 	child = pexpect.spawn(exe, args=args, env=env)
 
 	try:
-		send(child, "\t")
-		expect(child, "        ")
+		send(child, "123")
+		expect(child, "123")
+		send(child, "\x01")
+		send(child, "\x04")
+		send(child, "\x04")
 		send(child, "\x04")
 		wait(child)
 	except pexpect.TIMEOUT: