summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Prakash Jana <engineerarun@gmail.com>2019-10-13 20:49:16 +0530
committerArun Prakash Jana <engineerarun@gmail.com>2019-10-13 20:49:16 +0530
commit223fc512428797cb55e8891740ac13b798d65200 (patch)
tree4bd92d3630062d6e212903eb3dfa8d2b44287241
parentecebd9f55983bca6beb883314fff888b04eab914 (diff)
Sync r even in bc
-rw-r--r--README.md2
-rw-r--r--bcal.12
-rw-r--r--src/bcal.c63
3 files changed, 18 insertions, 49 deletions
diff --git a/README.md b/README.md
index 870e5ea..6a128b2 100644
--- a/README.md
+++ b/README.md
@@ -170,7 +170,7 @@ prompt keys:
- sector size: 0x200 (512)
- max heads per cylinder: 0x10 (16)
- max sectors per track: 0x3f (63)
-- **bc variables**: `scale` = 10, `ibase` = 10. `last` is synced to `r` when toggling from `bc` to `bcal`. Syncing `r` to `last` works with GNU `bc`. `bc` is not called in minimal output mode. Note that `r` works as usual with `calc`.
+- **bc variables**: `scale` = 10, `ibase` = 10. `r` is synced and can be used in expressions. `bc` is not called in minimal output mode.
### Examples
diff --git a/bcal.1 b/bcal.1
index c6ec5cf..a9e1658 100644
--- a/bcal.1
+++ b/bcal.1
@@ -63,7 +63,7 @@ bcal \- Storage expression calculator.
- max sectors per track: 0x3f (63)
.PP
.IP 10. 4
-\fBbc variables\fR: \fIscale\fR = 10, \fIibase\fR = 10. \fIlast\fR is synced to \fBr\fR when toggling from \fBbc\fR to \fBbcal\fR. Syncing \fBr\fR to \fIlast\fR works with GNU \fBbc\fR. \fBbc\fR is not called in minimal output mode. Note that \fBr\fR works as usual with \fBcalc\fR. To use \fBcalc\fR, \fIexport BCAL_USE_CALC=1\fR.
+\fBbc variables\fR: \fIscale\fR = 10, \fIibase\fR = 10. \fBr\fR is synced and can be used in expressions. \fBbc\fR is not called in minimal output mode. To use \fBcalc\fR instead of \fBbc\fR, \fIexport BCAL_USE_CALC=1\fR.
.SH OPTIONS
.TP
.BI "-c=" N
diff --git a/src/bcal.c b/src/bcal.c
index 97cfaf2..8d38b63 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -219,54 +219,29 @@ static int try_bc(char *expr)
log(ERROR, "write(1)! [%s]\n", strerror(errno));
exit(-1);
}
+ }
-#ifdef __GNU_LIBRARY__
- if (write(pipe_pc[1], "last=", 5) != 5) {
- log(ERROR, "write(2)! [%s]\n", strerror(errno));
- exit(-1);
- }
-
- if (lastres.p[0]) {
- ret = (ssize_t)strlen(lastres.p);
- if (write(pipe_pc[1], lastres.p, ret) != ret) {
- log(ERROR, "write(3)! [%s]\n", strerror(errno));
- exit(-1);
- }
- } else {
- if (write(pipe_pc[1], "0", 1) != 1) {
- log(ERROR, "write(4)! [%s]\n", strerror(errno));
- exit(-1);
- }
- }
+ if (write(pipe_pc[1], "r=", 2) != 2) {
+ log(ERROR, "write(2)! [%s]\n", strerror(errno));
+ exit(-1);
+ }
- if (write(pipe_pc[1], "\n", 1) != 1) {
- log(ERROR, "write(5)! [%s]\n", strerror(errno));
+ if (lastres.p[0]) {
+ ret = (ssize_t)strlen(lastres.p);
+ if (write(pipe_pc[1], lastres.p, ret) != ret) {
+ log(ERROR, "write(3)! [%s]\n", strerror(errno));
exit(-1);
}
-#endif
} else {
- if (write(pipe_pc[1], "r=", 2) != 2) {
- log(ERROR, "write(2)! [%s]\n", strerror(errno));
+ if (write(pipe_pc[1], "0", 1) != 1) {
+ log(ERROR, "write(4)! [%s]\n", strerror(errno));
exit(-1);
}
+ }
- if (lastres.p[0]) {
- ret = (ssize_t)strlen(lastres.p);
- if (write(pipe_pc[1], lastres.p, ret) != ret) {
- log(ERROR, "write(3)! [%s]\n", strerror(errno));
- exit(-1);
- }
- } else {
- if (write(pipe_pc[1], "0", 1) != 1) {
- log(ERROR, "write(4)! [%s]\n", strerror(errno));
- exit(-1);
- }
- }
-
- if (write(pipe_pc[1], "\n", 1) != 1) {
- log(ERROR, "write(5)! [%s]\n", strerror(errno));
- exit(-1);
- }
+ if (write(pipe_pc[1], "\n", 1) != 1) {
+ log(ERROR, "write(5)! [%s]\n", strerror(errno));
+ exit(-1);
}
ret = (ssize_t)strlen(expr);
@@ -2181,13 +2156,7 @@ int main(int argc, char **argv)
if (cfg.calc)
strncpy(prompt, "calc> ", 7);
else {
-#ifdef __GNU_LIBRARY__
- printf("bc vars: scale = 10, \
- ibase = 10, last = r\n");
-#else
- printf("bc vars: scale = 10, \
- ibase = 10, last = 0\n");
-#endif
+ printf("bc vars: scale = 10, ibase = 10\n");
strncpy(prompt, "bc> ", 5);
}
} else