diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-04 20:58:40 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 15:43:35 +0100 |
commit | d70d4a023586b9e9835258acda58cdfaf9131e5e (patch) | |
tree | af53570442e7c12ada4f62acb076084a98a12450 /miscutils | |
parent | 9b70f197b4dd5be47c5d0d4479525efe012964ee (diff) | |
download | busybox-d70d4a023586b9e9835258acda58cdfaf9131e5e.tar.gz |
bc: get rid of G.tty and G.flags
G.flags == option_mask32
function old new delta
bc_args 97 120 +23
dc_main 48 49 +1
bc_main 48 49 +1
bc_error 42 38 -4
bc_posix_error 65 60 -5
bc_read_line 325 317 -8
dc_lex_token 714 705 -9
bc_vm_run 2039 1942 -97
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/5 up/down: 25/-123) Total: -98 bytes
text data bss dec hex filename
987717 485 7296 995498 f30aa busybox_old
987619 485 7296 995400 f3048 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index bc5501d91..15089314f 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -730,28 +730,25 @@ static void bc_program_reset(void); #define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1) struct globals { + smallint ttyin; + smallint eof; char sbgn; char send; BcParse prs; BcProgram prog; - unsigned flags; BcVec files; char *env_args; - - smallint tty; - smallint ttyin; - smallint eof; } FIX_ALIASING; #define G (*ptr_to_globals) #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) -#define G_posix (ENABLE_BC && (G.flags & BC_FLAG_S)) -#define G_warn (ENABLE_BC && (G.flags & BC_FLAG_W)) -#define G_exreg (ENABLE_DC && (G.flags & BC_FLAG_X)) +#define G_posix (ENABLE_BC && (option_mask32 & BC_FLAG_S)) +#define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W)) +#define G_exreg (ENABLE_DC && (option_mask32 & BC_FLAG_X)) #define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0) @@ -1012,7 +1009,7 @@ static int bc_posix_error(const char *fmt, ...) { va_list p; - if (!(G.flags & (BC_FLAG_S|BC_FLAG_W))) + if (!(option_mask32 & (BC_FLAG_S|BC_FLAG_W))) return BC_STATUS_SUCCESS; va_start(p, fmt); @@ -1020,7 +1017,7 @@ static int bc_posix_error(const char *fmt, ...) va_end(p); // Do we treat non-POSIX constructs as errors? - if (!(G.flags & BC_FLAG_S)) + if (!(option_mask32 & BC_FLAG_S)) return BC_STATUS_SUCCESS; // no, it's a warning if (!G.ttyin) exit(1); @@ -1262,11 +1259,12 @@ static char* bc_read_file(const char *path) static void bc_args(int argc, char **argv) { + unsigned opts; int i; GETOPT_RESET(); #if ENABLE_FEATURE_BC_LONG_OPTIONS - G.flags = getopt32long(argv, "xwvsqli", + opts = getopt32long(argv, "xwvsqli", "extended-register\0" No_argument "x" "warn\0" No_argument "w" "version\0" No_argument "v" @@ -1276,14 +1274,17 @@ static void bc_args(int argc, char **argv) "interactive\0" No_argument "i" ); #else - G.flags = getopt32(argv, "xwvsqli"); + opts = getopt32(argv, "xwvsqli"); #endif + if (getenv("POSIXLY_CORRECT")) + option_mask32 |= BC_FLAG_S; - if (G.flags & BC_FLAG_V) bc_vm_info(); + if (opts & BC_FLAG_V) bc_vm_info(); // should not be necessary, getopt32() handles this?? //if (argv[optind] && !strcmp(argv[optind], "--")) ++optind; - for (i = optind; i < argc; ++i) bc_vec_push(&G.files, argv + i); + for (i = optind; i < argc; ++i) + bc_vec_push(&G.files, argv + i); } static void bc_num_setToZero(BcNum *n, size_t scale) @@ -6972,7 +6973,7 @@ static BcStatus bc_vm_exec(void) size_t i; #if ENABLE_BC - if (G.flags & BC_FLAG_L) { + if (option_mask32 & BC_FLAG_L) { bc_lex_file(&G.prs.l, bc_lib_name); s = bc_parse_text(&G.prs, bc_lib); @@ -6989,8 +6990,6 @@ static BcStatus bc_vm_exec(void) for (i = 0; !s && i < G.files.len; ++i) s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); if (s) { - if (!G.tty) - return s; fflush_and_check(); fputs("ready for more input\n", stderr); } @@ -7099,8 +7098,6 @@ static void bc_vm_init(const char *env_len) bc_vec_init(&G.files, sizeof(char *), NULL); if (IS_BC) { - if (getenv("POSIXLY_CORRECT")) - G.flags |= BC_FLAG_S; bc_vm_envArgs(); } @@ -7121,13 +7118,12 @@ static BcStatus bc_vm_run(int argc, char *argv[], bc_args(argc, argv); G.ttyin = isatty(0); - G.tty = G.ttyin || (G.flags & BC_FLAG_I) || isatty(1); if (G.ttyin) { #if ENABLE_FEATURE_BC_SIGNALS signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); #endif - if (!(G.flags & BC_FLAG_Q)) + if (!(option_mask32 & BC_FLAG_Q)) bc_vm_info(); } st = bc_vm_exec(); |