diff options
author | Gavin Howard <yzena.tech@gmail.com> | 2021-03-31 09:44:57 -0600 |
---|---|---|
committer | Gavin Howard <yzena.tech@gmail.com> | 2021-03-31 09:44:57 -0600 |
commit | b1317b88ac3e674145b94092347619d4c35a153e (patch) | |
tree | 7575566c2b8b1d818440d62fcaf5ad715dee6d1f | |
parent | 4e257c8ae68a8af80801ebe0c7d298e7a6b24a4e (diff) | |
download | bc-b1317b88ac3e674145b94092347619d4c35a153e.tar.gz |
Add a command-line option to turn off the read prompt
-rw-r--r-- | include/vm.h | 6 | ||||
-rw-r--r-- | src/args.c | 7 | ||||
-rw-r--r-- | src/program.c | 4 |
3 files changed, 14 insertions, 3 deletions
diff --git a/include/vm.h b/include/vm.h index 80a060ed..1c1cd938 100644 --- a/include/vm.h +++ b/include/vm.h @@ -110,8 +110,9 @@ #define BC_FLAG_I (UINTMAX_C(1)<<5) #define BC_FLAG_P (UINTMAX_C(1)<<6) -#define BC_FLAG_TTYIN (UINTMAX_C(1)<<7) -#define BC_FLAG_TTY (UINTMAX_C(1)<<8) +#define BC_FLAG_R (UINTMAX_C(1)<<7) +#define BC_FLAG_TTYIN (UINTMAX_C(1)<<8) +#define BC_FLAG_TTY (UINTMAX_C(1)<<9) #define BC_TTYIN (vm.flags & BC_FLAG_TTYIN) #define BC_TTY (vm.flags & BC_FLAG_TTY) @@ -130,6 +131,7 @@ #define BC_I (vm.flags & BC_FLAG_I) #define BC_P (vm.flags & BC_FLAG_P) +#define BC_R (vm.flags & BC_FLAG_R) #if BC_ENABLED @@ -53,6 +53,7 @@ static const BcOptLong bc_args_lopt[] = { { "help", BC_OPT_NONE, 'h' }, { "interactive", BC_OPT_NONE, 'i' }, { "no-prompt", BC_OPT_NONE, 'P' }, + { "no-read-prompt", BC_OPT_NONE, 'R' }, #if BC_ENABLED { "global-stacks", BC_OPT_BC_ONLY, 'g' }, { "mathlib", BC_OPT_BC_ONLY, 'l' }, @@ -144,6 +145,12 @@ void bc_args(int argc, char *argv[], bool exit_exprs) { break; } + case 'R': + { + vm.flags |= BC_FLAG_R; + break; + } + #if BC_ENABLED case 'g': { diff --git a/src/program.c b/src/program.c index 6ab79473..4ea635b2 100644 --- a/src/program.c +++ b/src/program.c @@ -456,7 +456,9 @@ static void bc_program_read(BcProgram *p) { bc_lex_file(&parse.l, bc_program_stdin_name); bc_vec_popAll(&f->code); - s = bc_read_line(&buf, BC_IS_BC ? "read> " : "?> "); + if (BC_R) s = bc_read_line(&buf, ""); + else s = bc_read_line(&buf, BC_IS_BC ? "read> " : "?> "); + if (s == BC_STATUS_EOF) bc_vm_err(BC_ERR_EXEC_READ_EXPR); bc_parse_text(&parse, buf.v); |