summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Prakash Jana <engineerarun@gmail.com>2018-10-02 20:52:17 +0530
committerArun Prakash Jana <engineerarun@gmail.com>2018-10-02 20:52:17 +0530
commit5f6a41f5fcb408878a65ed348d643d63e74f97c6 (patch)
treefe0f16b85335ff8550505c568f936718cff55b59
parentc0957f914d6833f99031405945e2fef099dd8021 (diff)
Enter bc mode with -b sans argsv2.0
-rw-r--r--README.md4
-rw-r--r--bcal.16
-rw-r--r--src/bcal.c19
3 files changed, 18 insertions, 11 deletions
diff --git a/README.md b/README.md
index 6958c1f..7fed722 100644
--- a/README.md
+++ b/README.md
@@ -114,7 +114,7 @@ $ make strip install
```
usage: bcal [-c N] [-f FORMAT] [-s bytes] [expr]
- [N [unit]] [-b expr] [-m] [-d] [-h]
+ [N [unit]] [-b [expr]] [-m] [-d] [-h]
Storage expression calculator.
@@ -148,7 +148,7 @@ optional arguments:
LBA = 50, MH = 0x12, MS = 0
default MAX_HEAD: 16, default MAX_SECTOR: 63
-s bytes sector size [default 512]
- -b expr evaluate expression in bc
+ -b [expr] enter bc mode or evaluate expression in bc
-m show minimal output (e.g. decimal bytes)
-d enable debug information and logs
-h show this help, storage sizes and exit
diff --git a/bcal.1 b/bcal.1
index 860946a..57c01bd 100644
--- a/bcal.1
+++ b/bcal.1
@@ -2,7 +2,7 @@
.SH NAME
bcal \- Storage expression calculator.
.SH SYNOPSIS
-.B bcal [-c N] [-f FORMAT] [-s bytes] [expr] [N [unit]] [-b expr] [-m] [-d] [-h]
+.B bcal [-c N] [-f FORMAT] [-s bytes] [expr] [N [unit]] [-b [expr]] [-m] [-d] [-h]
.SH DESCRIPTION
.B bcal
(Byte CALculator) is a command-line utility to help with numerical calculations and expressions involving data storage units, addressing, base conversion etc. It invokes GNU \fBbc\fR for non-storage expressions.
@@ -79,8 +79,8 @@ Omitted values, (other than MAX_HEAD and MAX_SECTOR) are considered 0. Default M
.BI "-s=" bytes
Sector size in bytes. Default value is 512.
.TP
-.BI "-b=" expr
-Evaluate expression in bc.
+.BI "-b=" [expr]
+Start in \fIbc\fR mode. If expression is provided, evaluate in \fIbc\fR and quit.
.TP
.BI "-m"
Show minimal output (e.g. decimal bytes).
diff --git a/src/bcal.c b/src/bcal.c
index d761c43..6eae9f2 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -1076,7 +1076,7 @@ static void prompt_help()
static void usage()
{
printf("usage: bcal [-c N] [-f FORMAT] [-s bytes] [expr]\n\
- [N [unit]] [-b expr] [-m] [-d] [-h]\n\n\
+ [N [unit]] [-b [expr]] [-m] [-d] [-h]\n\n\
Storage expression calculator.\n\n\
positional arguments:\n\
expr evaluate storage arithmetic expression\n\
@@ -1107,7 +1107,7 @@ optional arguments:\n\
LBA = 50, MH = 0x12, MS = 0\n\
default MAX_HEAD: 16, default MAX_SECTOR: 63\n\
-s bytes sector size [default 512]\n\
- -b expr evaluate expression in bc\n\
+ -b [expr] enter bc mode or evaluate expression in bc\n\
-m show minimal output (e.g. decimal bytes)\n\
-d enable debug information and logs\n\
-h show this help, storage sizes and exit\n\n");
@@ -1936,7 +1936,7 @@ int main(int argc, char **argv)
opterr = 0;
rl_bind_key('\t', rl_insert);
- while ((opt = getopt(argc, argv, "b:c:df:hms:")) != -1) {
+ while ((opt = getopt(argc, argv, "bc:df:hms:")) != -1) {
switch (opt) {
case 'c':
{
@@ -1980,7 +1980,9 @@ int main(int argc, char **argv)
sectorsz = strtoul_b(optarg);
break;
case 'b':
- return try_bc(optarg);
+ cfg.bcmode = 1;
+ strncpy(prompt, "bc> ", 5);
+ break;
case 'd':
cfg.loglvl = DEBUG;
log(DEBUG, "bcal v%s\n", VERSION);
@@ -1991,6 +1993,7 @@ int main(int argc, char **argv)
usage();
return 0;
default:
+ log(ERROR, "invalid option \'%c\'\n\n", (char)optopt);
usage();
return -1;
}
@@ -2108,8 +2111,12 @@ int main(int argc, char **argv)
/*Arithmetic operation*/
if (argc - optind == 1) {
- curexpr = argv[optind];
- return evaluate(argv[optind], sectorsz);
+ if (cfg.bcmode)
+ return try_bc(argv[optind]);
+ else {
+ curexpr = argv[optind];
+ return evaluate(argv[optind], sectorsz);
+ }
}
return -1;