diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2018-10-02 20:52:17 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2018-10-02 20:52:17 +0530 |
commit | 5f6a41f5fcb408878a65ed348d643d63e74f97c6 (patch) | |
tree | fe0f16b85335ff8550505c568f936718cff55b59 | |
parent | c0957f914d6833f99031405945e2fef099dd8021 (diff) |
Enter bc mode with -b sans argsv2.0
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | bcal.1 | 6 | ||||
-rw-r--r-- | src/bcal.c | 19 |
3 files changed, 18 insertions, 11 deletions
@@ -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 @@ -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). @@ -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; |