commit 41883950c9421cdb8fac18f5dd3dab8f7e2463e5
parent 2544b70216bb71aec663a9657142e13ad0c6ac41
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sat, 17 Jan 2026 18:09:57 +0100
bc: Add -p to change the dc executable
This option is mainly added to make easier testing and enabling
using bc with custom dc versions.
Diffstat:
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/bc.1 b/bc.1
@@ -1,4 +1,4 @@
-.Dd December 31, 2025
+.Dd December 17, 2026
.Dt BC 1
.Os sbase
.Sh NAME
@@ -6,6 +6,7 @@
.Nd arbitrary-precision arithmetic language
.Sh SYNOPSIS
.Nm
+.Op Fl p Ar dc
.Op Fl cdls
.Op Ar file ...
.Sh DESCRIPTION
@@ -23,6 +24,12 @@ After all the files are loaded and executed then
it reads from stdin.
.Sh OPTIONS
.Bl -tag -width Ds
+.It Fl p Ar dc
+Dc program spawned to run the translated code generated by
+.Ar bc .
+By default,
+it is
+.Ar dc .
.It Fl c
Compile only mode.
Generate dc code without spawning a dc subprocess.
diff --git a/bc.y b/bc.y
@@ -59,6 +59,8 @@ static int nested, inhome;
static Macro macros[NESTED_MAX];
int cflag, dflag, lflag, sflag;
+static char *dcprog = "dc";
+
%}
%union {
@@ -803,7 +805,7 @@ spawn(void)
dup(fds[0]);
close(fds[0]);
close(fds[1]);
- execlp("dc", "dc", (char *) NULL);
+ execlp(dcprog, "dc", (char *) NULL);
/* it shouldn't happen */
write(3, errmsg, sizeof(errmsg)-1);
@@ -848,13 +850,16 @@ bc(char *fname)
static void
usage(void)
{
- eprintf("usage: %s [-cdls]\n", argv0);
+ eprintf("usage: %s [-p dc][-cdls]\n", argv0);
}
int
main(int argc, char *argv[])
{
ARGBEGIN {
+ case 'p':
+ dcprog = EARGF(usage);
+ break;
case 'c':
cflag = 1;
break;
diff --git a/tests/0010-bc.sh b/tests/0010-bc.sh
@@ -21,7 +21,7 @@ cat <<EOF >$tmp
.48609126058589107690
EOF
-$EXEC ../bc ../bc.library <<EOF | diff -u $tmp -
+$EXEC ../bc -p ../dc ../bc.library <<EOF | diff -u $tmp -
a(0)
a(1)
a(2)