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-w32-d70d4a023586b9e9835258acda58cdfaf9131e5e.tar.gz busybox-w32-d70d4a023586b9e9835258acda58cdfaf9131e5e.tar.bz2 busybox-w32-d70d4a023586b9e9835258acda58cdfaf9131e5e.zip | |
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); | |||
| 730 | #define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1) | 730 | #define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1) |
| 731 | 731 | ||
| 732 | struct globals { | 732 | struct globals { |
| 733 | smallint ttyin; | ||
| 734 | smallint eof; | ||
| 733 | char sbgn; | 735 | char sbgn; |
| 734 | char send; | 736 | char send; |
| 735 | 737 | ||
| 736 | BcParse prs; | 738 | BcParse prs; |
| 737 | BcProgram prog; | 739 | BcProgram prog; |
| 738 | 740 | ||
| 739 | unsigned flags; | ||
| 740 | BcVec files; | 741 | BcVec files; |
| 741 | 742 | ||
| 742 | char *env_args; | 743 | char *env_args; |
| 743 | |||
| 744 | smallint tty; | ||
| 745 | smallint ttyin; | ||
| 746 | smallint eof; | ||
| 747 | } FIX_ALIASING; | 744 | } FIX_ALIASING; |
| 748 | #define G (*ptr_to_globals) | 745 | #define G (*ptr_to_globals) |
| 749 | #define INIT_G() do { \ | 746 | #define INIT_G() do { \ |
| 750 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 747 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
| 751 | } while (0) | 748 | } while (0) |
| 752 | #define G_posix (ENABLE_BC && (G.flags & BC_FLAG_S)) | 749 | #define G_posix (ENABLE_BC && (option_mask32 & BC_FLAG_S)) |
| 753 | #define G_warn (ENABLE_BC && (G.flags & BC_FLAG_W)) | 750 | #define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W)) |
| 754 | #define G_exreg (ENABLE_DC && (G.flags & BC_FLAG_X)) | 751 | #define G_exreg (ENABLE_DC && (option_mask32 & BC_FLAG_X)) |
| 755 | #define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0) | 752 | #define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0) |
| 756 | 753 | ||
| 757 | 754 | ||
| @@ -1012,7 +1009,7 @@ static int bc_posix_error(const char *fmt, ...) | |||
| 1012 | { | 1009 | { |
| 1013 | va_list p; | 1010 | va_list p; |
| 1014 | 1011 | ||
| 1015 | if (!(G.flags & (BC_FLAG_S|BC_FLAG_W))) | 1012 | if (!(option_mask32 & (BC_FLAG_S|BC_FLAG_W))) |
| 1016 | return BC_STATUS_SUCCESS; | 1013 | return BC_STATUS_SUCCESS; |
| 1017 | 1014 | ||
| 1018 | va_start(p, fmt); | 1015 | va_start(p, fmt); |
| @@ -1020,7 +1017,7 @@ static int bc_posix_error(const char *fmt, ...) | |||
| 1020 | va_end(p); | 1017 | va_end(p); |
| 1021 | 1018 | ||
| 1022 | // Do we treat non-POSIX constructs as errors? | 1019 | // Do we treat non-POSIX constructs as errors? |
| 1023 | if (!(G.flags & BC_FLAG_S)) | 1020 | if (!(option_mask32 & BC_FLAG_S)) |
| 1024 | return BC_STATUS_SUCCESS; // no, it's a warning | 1021 | return BC_STATUS_SUCCESS; // no, it's a warning |
| 1025 | if (!G.ttyin) | 1022 | if (!G.ttyin) |
| 1026 | exit(1); | 1023 | exit(1); |
| @@ -1262,11 +1259,12 @@ static char* bc_read_file(const char *path) | |||
| 1262 | 1259 | ||
| 1263 | static void bc_args(int argc, char **argv) | 1260 | static void bc_args(int argc, char **argv) |
| 1264 | { | 1261 | { |
| 1262 | unsigned opts; | ||
| 1265 | int i; | 1263 | int i; |
| 1266 | 1264 | ||
| 1267 | GETOPT_RESET(); | 1265 | GETOPT_RESET(); |
| 1268 | #if ENABLE_FEATURE_BC_LONG_OPTIONS | 1266 | #if ENABLE_FEATURE_BC_LONG_OPTIONS |
| 1269 | G.flags = getopt32long(argv, "xwvsqli", | 1267 | opts = getopt32long(argv, "xwvsqli", |
| 1270 | "extended-register\0" No_argument "x" | 1268 | "extended-register\0" No_argument "x" |
| 1271 | "warn\0" No_argument "w" | 1269 | "warn\0" No_argument "w" |
| 1272 | "version\0" No_argument "v" | 1270 | "version\0" No_argument "v" |
| @@ -1276,14 +1274,17 @@ static void bc_args(int argc, char **argv) | |||
| 1276 | "interactive\0" No_argument "i" | 1274 | "interactive\0" No_argument "i" |
| 1277 | ); | 1275 | ); |
| 1278 | #else | 1276 | #else |
| 1279 | G.flags = getopt32(argv, "xwvsqli"); | 1277 | opts = getopt32(argv, "xwvsqli"); |
| 1280 | #endif | 1278 | #endif |
| 1279 | if (getenv("POSIXLY_CORRECT")) | ||
| 1280 | option_mask32 |= BC_FLAG_S; | ||
| 1281 | 1281 | ||
| 1282 | if (G.flags & BC_FLAG_V) bc_vm_info(); | 1282 | if (opts & BC_FLAG_V) bc_vm_info(); |
| 1283 | // should not be necessary, getopt32() handles this?? | 1283 | // should not be necessary, getopt32() handles this?? |
| 1284 | //if (argv[optind] && !strcmp(argv[optind], "--")) ++optind; | 1284 | //if (argv[optind] && !strcmp(argv[optind], "--")) ++optind; |
| 1285 | 1285 | ||
| 1286 | for (i = optind; i < argc; ++i) bc_vec_push(&G.files, argv + i); | 1286 | for (i = optind; i < argc; ++i) |
| 1287 | bc_vec_push(&G.files, argv + i); | ||
| 1287 | } | 1288 | } |
| 1288 | 1289 | ||
| 1289 | static void bc_num_setToZero(BcNum *n, size_t scale) | 1290 | static void bc_num_setToZero(BcNum *n, size_t scale) |
| @@ -6972,7 +6973,7 @@ static BcStatus bc_vm_exec(void) | |||
| 6972 | size_t i; | 6973 | size_t i; |
| 6973 | 6974 | ||
| 6974 | #if ENABLE_BC | 6975 | #if ENABLE_BC |
| 6975 | if (G.flags & BC_FLAG_L) { | 6976 | if (option_mask32 & BC_FLAG_L) { |
| 6976 | 6977 | ||
| 6977 | bc_lex_file(&G.prs.l, bc_lib_name); | 6978 | bc_lex_file(&G.prs.l, bc_lib_name); |
| 6978 | s = bc_parse_text(&G.prs, bc_lib); | 6979 | s = bc_parse_text(&G.prs, bc_lib); |
| @@ -6989,8 +6990,6 @@ static BcStatus bc_vm_exec(void) | |||
| 6989 | for (i = 0; !s && i < G.files.len; ++i) | 6990 | for (i = 0; !s && i < G.files.len; ++i) |
| 6990 | s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); | 6991 | s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); |
| 6991 | if (s) { | 6992 | if (s) { |
| 6992 | if (!G.tty) | ||
| 6993 | return s; | ||
| 6994 | fflush_and_check(); | 6993 | fflush_and_check(); |
| 6995 | fputs("ready for more input\n", stderr); | 6994 | fputs("ready for more input\n", stderr); |
| 6996 | } | 6995 | } |
| @@ -7099,8 +7098,6 @@ static void bc_vm_init(const char *env_len) | |||
| 7099 | bc_vec_init(&G.files, sizeof(char *), NULL); | 7098 | bc_vec_init(&G.files, sizeof(char *), NULL); |
| 7100 | 7099 | ||
| 7101 | if (IS_BC) { | 7100 | if (IS_BC) { |
| 7102 | if (getenv("POSIXLY_CORRECT")) | ||
| 7103 | G.flags |= BC_FLAG_S; | ||
| 7104 | bc_vm_envArgs(); | 7101 | bc_vm_envArgs(); |
| 7105 | } | 7102 | } |
| 7106 | 7103 | ||
| @@ -7121,13 +7118,12 @@ static BcStatus bc_vm_run(int argc, char *argv[], | |||
| 7121 | bc_args(argc, argv); | 7118 | bc_args(argc, argv); |
| 7122 | 7119 | ||
| 7123 | G.ttyin = isatty(0); | 7120 | G.ttyin = isatty(0); |
| 7124 | G.tty = G.ttyin || (G.flags & BC_FLAG_I) || isatty(1); | ||
| 7125 | 7121 | ||
| 7126 | if (G.ttyin) { | 7122 | if (G.ttyin) { |
| 7127 | #if ENABLE_FEATURE_BC_SIGNALS | 7123 | #if ENABLE_FEATURE_BC_SIGNALS |
| 7128 | signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); | 7124 | signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); |
| 7129 | #endif | 7125 | #endif |
| 7130 | if (!(G.flags & BC_FLAG_Q)) | 7126 | if (!(option_mask32 & BC_FLAG_Q)) |
| 7131 | bc_vm_info(); | 7127 | bc_vm_info(); |
| 7132 | } | 7128 | } |
| 7133 | st = bc_vm_exec(); | 7129 | st = bc_vm_exec(); |
