forked from gavin/bc
1
0
Fork 0
Browse Source

Change -f and -e to exit, unless -f - is given

This is a change requested by FreeBSD. It also makes it unnecessary for
me to keep the BC_EXPR_EXIT and DC_EXPR_EXIT environment variables.
master
Gavin Howard 2 years ago
parent
commit
26fa18a5bb
Signed by untrusted user who does not match committer: gavin
GPG Key ID: C08038BDF280D33E
  1. 3
      include/vm.h
  2. 5
      src/args.c
  3. 2
      src/bc/bc.c
  4. 2
      src/dc/dc.c
  5. 8
      src/vm.c

3
include/vm.h

@ -303,6 +303,7 @@ typedef struct BcVm {
uint16_t nchars;
uint16_t line_len;
bool no_exit_exprs;
bool eof;
BcBigDig maxes[BC_PROG_GLOBALS_LEN + BC_ENABLE_EXTRA_MATH];
@ -353,7 +354,7 @@ typedef struct BcVm {
void bc_vm_info(const char* const help);
void bc_vm_boot(int argc, char *argv[], const char *env_len,
const char* const env_args, const char* env_exp_quit);
const char* const env_args);
void bc_vm_shutdown(void);
void bc_vm_printf(const char *fmt, ...);

5
src/args.c

@ -114,7 +114,8 @@ void bc_args(int argc, char *argv[]) {
case 'f':
{
bc_args_file(opts.optarg);
if (!strcmp(opts.optarg, "-")) vm.no_exit_exprs = true;
else bc_args_file(opts.optarg);
break;
}
@ -206,7 +207,7 @@ void bc_args(int argc, char *argv[]) {
if (version) bc_vm_info(NULL);
if (do_exit) exit((int) vm.status);
if (opts.optind < (size_t) argc)
if (opts.optind < (size_t) argc && vm.files.v == NULL)
bc_vec_init(&vm.files, sizeof(char*), NULL);
for (i = opts.optind; i < (size_t) argc; ++i)

2
src/bc/bc.c

@ -52,6 +52,6 @@ void bc_main(int argc, char **argv) {
vm.parse = bc_parse_parse;
vm.expr = bc_parse_expr;
bc_vm_boot(argc, argv, "BC_LINE_LENGTH", "BC_ENV_ARGS", "BC_EXPR_EXIT");
bc_vm_boot(argc, argv, "BC_LINE_LENGTH", "BC_ENV_ARGS");
}
#endif // BC_ENABLED

2
src/dc/dc.c

@ -52,6 +52,6 @@ void dc_main(int argc, char **argv) {
vm.parse = dc_parse_parse;
vm.expr = dc_parse_expr;
bc_vm_boot(argc, argv, "DC_LINE_LENGTH", "DC_ENV_ARGS", "DC_EXPR_EXIT");
bc_vm_boot(argc, argv, "DC_LINE_LENGTH", "DC_ENV_ARGS");
}
#endif // DC_ENABLED

8
src/vm.c

@ -698,7 +698,7 @@ static void bc_vm_gettext(void) {
#endif // BC_ENABLE_NLS
}
static void bc_vm_exec(const char* env_exp_exit) {
static void bc_vm_exec(void) {
size_t i;
bool has_file = false;
@ -750,7 +750,7 @@ static void bc_vm_exec(const char* env_exp_exit) {
BC_SIG_UNLOCK;
if (getenv(env_exp_exit) != NULL) return;
if (!vm.no_exit_exprs) return;
}
for (i = 0; i < vm.files.len; ++i) {
@ -776,7 +776,7 @@ err:
}
void bc_vm_boot(int argc, char *argv[], const char *env_len,
const char* const env_args, const char* env_exp_exit)
const char* const env_args)
{
int ttyin, ttyout, ttyerr;
struct sigaction sa;
@ -857,5 +857,5 @@ void bc_vm_boot(int argc, char *argv[], const char *env_len,
BC_SIG_UNLOCK;
bc_vm_exec(env_exp_exit);
bc_vm_exec();
}

Loading…
Cancel
Save