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>
This commit is contained in:
@ -730,28 +730,25 @@ static void bc_program_reset(void);
|
|||||||
#define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1)
|
#define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1)
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
|
smallint ttyin;
|
||||||
|
smallint eof;
|
||||||
char sbgn;
|
char sbgn;
|
||||||
char send;
|
char send;
|
||||||
|
|
||||||
BcParse prs;
|
BcParse prs;
|
||||||
BcProgram prog;
|
BcProgram prog;
|
||||||
|
|
||||||
unsigned flags;
|
|
||||||
BcVec files;
|
BcVec files;
|
||||||
|
|
||||||
char *env_args;
|
char *env_args;
|
||||||
|
|
||||||
smallint tty;
|
|
||||||
smallint ttyin;
|
|
||||||
smallint eof;
|
|
||||||
} FIX_ALIASING;
|
} FIX_ALIASING;
|
||||||
#define G (*ptr_to_globals)
|
#define G (*ptr_to_globals)
|
||||||
#define INIT_G() do { \
|
#define INIT_G() do { \
|
||||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define G_posix (ENABLE_BC && (G.flags & BC_FLAG_S))
|
#define G_posix (ENABLE_BC && (option_mask32 & BC_FLAG_S))
|
||||||
#define G_warn (ENABLE_BC && (G.flags & BC_FLAG_W))
|
#define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W))
|
||||||
#define G_exreg (ENABLE_DC && (G.flags & BC_FLAG_X))
|
#define G_exreg (ENABLE_DC && (option_mask32 & BC_FLAG_X))
|
||||||
#define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0)
|
#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;
|
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;
|
return BC_STATUS_SUCCESS;
|
||||||
|
|
||||||
va_start(p, fmt);
|
va_start(p, fmt);
|
||||||
@ -1020,7 +1017,7 @@ static int bc_posix_error(const char *fmt, ...)
|
|||||||
va_end(p);
|
va_end(p);
|
||||||
|
|
||||||
// Do we treat non-POSIX constructs as errors?
|
// 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
|
return BC_STATUS_SUCCESS; // no, it's a warning
|
||||||
if (!G.ttyin)
|
if (!G.ttyin)
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1262,11 +1259,12 @@ static char* bc_read_file(const char *path)
|
|||||||
|
|
||||||
static void bc_args(int argc, char **argv)
|
static void bc_args(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
unsigned opts;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
GETOPT_RESET();
|
GETOPT_RESET();
|
||||||
#if ENABLE_FEATURE_BC_LONG_OPTIONS
|
#if ENABLE_FEATURE_BC_LONG_OPTIONS
|
||||||
G.flags = getopt32long(argv, "xwvsqli",
|
opts = getopt32long(argv, "xwvsqli",
|
||||||
"extended-register\0" No_argument "x"
|
"extended-register\0" No_argument "x"
|
||||||
"warn\0" No_argument "w"
|
"warn\0" No_argument "w"
|
||||||
"version\0" No_argument "v"
|
"version\0" No_argument "v"
|
||||||
@ -1276,14 +1274,17 @@ static void bc_args(int argc, char **argv)
|
|||||||
"interactive\0" No_argument "i"
|
"interactive\0" No_argument "i"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
G.flags = getopt32(argv, "xwvsqli");
|
opts = getopt32(argv, "xwvsqli");
|
||||||
#endif
|
#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??
|
// should not be necessary, getopt32() handles this??
|
||||||
//if (argv[optind] && !strcmp(argv[optind], "--")) ++optind;
|
//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)
|
static void bc_num_setToZero(BcNum *n, size_t scale)
|
||||||
@ -6972,7 +6973,7 @@ static BcStatus bc_vm_exec(void)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
#if ENABLE_BC
|
#if ENABLE_BC
|
||||||
if (G.flags & BC_FLAG_L) {
|
if (option_mask32 & BC_FLAG_L) {
|
||||||
|
|
||||||
bc_lex_file(&G.prs.l, bc_lib_name);
|
bc_lex_file(&G.prs.l, bc_lib_name);
|
||||||
s = bc_parse_text(&G.prs, bc_lib);
|
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)
|
for (i = 0; !s && i < G.files.len; ++i)
|
||||||
s = bc_vm_file(*((char **) bc_vec_item(&G.files, i)));
|
s = bc_vm_file(*((char **) bc_vec_item(&G.files, i)));
|
||||||
if (s) {
|
if (s) {
|
||||||
if (!G.tty)
|
|
||||||
return s;
|
|
||||||
fflush_and_check();
|
fflush_and_check();
|
||||||
fputs("ready for more input\n", stderr);
|
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);
|
bc_vec_init(&G.files, sizeof(char *), NULL);
|
||||||
|
|
||||||
if (IS_BC) {
|
if (IS_BC) {
|
||||||
if (getenv("POSIXLY_CORRECT"))
|
|
||||||
G.flags |= BC_FLAG_S;
|
|
||||||
bc_vm_envArgs();
|
bc_vm_envArgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7121,13 +7118,12 @@ static BcStatus bc_vm_run(int argc, char *argv[],
|
|||||||
bc_args(argc, argv);
|
bc_args(argc, argv);
|
||||||
|
|
||||||
G.ttyin = isatty(0);
|
G.ttyin = isatty(0);
|
||||||
G.tty = G.ttyin || (G.flags & BC_FLAG_I) || isatty(1);
|
|
||||||
|
|
||||||
if (G.ttyin) {
|
if (G.ttyin) {
|
||||||
#if ENABLE_FEATURE_BC_SIGNALS
|
#if ENABLE_FEATURE_BC_SIGNALS
|
||||||
signal_no_SA_RESTART_empty_mask(SIGINT, record_signo);
|
signal_no_SA_RESTART_empty_mask(SIGINT, record_signo);
|
||||||
#endif
|
#endif
|
||||||
if (!(G.flags & BC_FLAG_Q))
|
if (!(option_mask32 & BC_FLAG_Q))
|
||||||
bc_vm_info();
|
bc_vm_info();
|
||||||
}
|
}
|
||||||
st = bc_vm_exec();
|
st = bc_vm_exec();
|
||||||
|
Reference in New Issue
Block a user