aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-06 09:07:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-06 09:07:06 +0100
commit54214c38db943e7b3541e841f5b7399e36047f70 (patch)
tree80fa5ec7811bc8cc66d8f12f2eb3cfc394cf72fc
parent1ff1c7094403fa96acce46611e7bf9534f2d8404 (diff)
downloadbusybox-w32-54214c38db943e7b3541e841f5b7399e36047f70.tar.gz
busybox-w32-54214c38db943e7b3541e841f5b7399e36047f70.tar.bz2
busybox-w32-54214c38db943e7b3541e841f5b7399e36047f70.zip
bc: fix "bc -v" printing version info twice, and not exiting
function old new delta bc_args 123 130 +7 bc_num_binary 150 148 -2 static.nullptr 4 - -4 bc_vm_run 1883 1874 -9 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/2 up/down: 7/-15) Total: -8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c94
1 files changed, 50 insertions, 44 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e9cfecccc..0943f606d 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1017,15 +1017,6 @@ static int bc_error_nested_read_call(void)
1017 return bc_error("read() call inside of a read() call"); 1017 return bc_error("read() call inside of a read() call");
1018} 1018}
1019 1019
1020static void bc_vm_info(void)
1021{
1022 printf("%s "BB_VER"\n"
1023 "Copyright (c) 2018 Gavin D. Howard and contributors\n"
1024 "Report bugs at: https://github.com/gavinhoward/bc\n"
1025 "This is free software with ABSOLUTELY NO WARRANTY\n"
1026 , applet_name);
1027}
1028
1029static void bc_vec_grow(BcVec *v, size_t n) 1020static void bc_vec_grow(BcVec *v, size_t n)
1030{ 1021{
1031 size_t cap = v->cap * 2; 1022 size_t cap = v->cap * 2;
@@ -1284,35 +1275,6 @@ static char* bc_read_file(const char *path)
1284 return buf; 1275 return buf;
1285} 1276}
1286 1277
1287static void bc_args(char **argv)
1288{
1289 unsigned opts;
1290 int i;
1291
1292 GETOPT_RESET();
1293#if ENABLE_FEATURE_BC_LONG_OPTIONS
1294 opts = option_mask32 |= getopt32long(argv, "xwvsqli",
1295 "extended-register\0" No_argument "x"
1296 "warn\0" No_argument "w"
1297 "version\0" No_argument "v"
1298 "standard\0" No_argument "s"
1299 "quiet\0" No_argument "q"
1300 "mathlib\0" No_argument "l"
1301 "interactive\0" No_argument "i"
1302 );
1303#else
1304 opts = option_mask32 |= getopt32(argv, "xwvsqli");
1305#endif
1306 if (getenv("POSIXLY_CORRECT"))
1307 option_mask32 |= BC_FLAG_S;
1308
1309///should be in bc_vm_run() instead??
1310 if (opts & BC_FLAG_V) bc_vm_info();
1311
1312 for (i = optind; argv[i]; ++i)
1313 bc_vec_push(&G.files, argv + i);
1314}
1315
1316static void bc_num_setToZero(BcNum *n, size_t scale) 1278static void bc_num_setToZero(BcNum *n, size_t scale)
1317{ 1279{
1318 n->len = 0; 1280 n->len = 0;
@@ -6866,14 +6828,53 @@ static BcStatus bc_program_exec(void)
6866 return s; 6828 return s;
6867} 6829}
6868 6830
6831static void bc_vm_info(void)
6832{
6833 printf("%s "BB_VER"\n"
6834 "Copyright (c) 2018 Gavin D. Howard and contributors\n"
6835 "Report bugs at: https://github.com/gavinhoward/bc\n"
6836 "This is free software with ABSOLUTELY NO WARRANTY\n"
6837 , applet_name);
6838}
6839
6840static void bc_args(char **argv)
6841{
6842 unsigned opts;
6843 int i;
6844
6845 GETOPT_RESET();
6846#if ENABLE_FEATURE_BC_LONG_OPTIONS
6847 opts = option_mask32 |= getopt32long(argv, "xwvsqli",
6848 "extended-register\0" No_argument "x"
6849 "warn\0" No_argument "w"
6850 "version\0" No_argument "v"
6851 "standard\0" No_argument "s"
6852 "quiet\0" No_argument "q"
6853 "mathlib\0" No_argument "l"
6854 "interactive\0" No_argument "i"
6855 );
6856#else
6857 opts = option_mask32 |= getopt32(argv, "xwvsqli");
6858#endif
6859 if (getenv("POSIXLY_CORRECT"))
6860 option_mask32 |= BC_FLAG_S;
6861
6862///should be in bc_vm_run() instead??
6863 if (opts & BC_FLAG_V) {
6864 bc_vm_info();
6865 exit(0);
6866 }
6867
6868 for (i = optind; argv[i]; ++i)
6869 bc_vec_push(&G.files, argv + i);
6870}
6871
6869#if ENABLE_BC 6872#if ENABLE_BC
6870static void bc_vm_envArgs(void) 6873static void bc_vm_envArgs(void)
6871{ 6874{
6872 static char *const nullptr = NULL;
6873
6874 BcVec v; 6875 BcVec v;
6875 char *env_args = getenv("BC_ENV_ARGS");
6876 char *buf; 6876 char *buf;
6877 char *env_args = getenv("BC_ENV_ARGS");
6877 6878
6878 if (!env_args) return; 6879 if (!env_args) return;
6879 6880
@@ -6881,7 +6882,6 @@ static void bc_vm_envArgs(void)
6881 buf = G.env_args; 6882 buf = G.env_args;
6882 6883
6883 bc_vec_init(&v, sizeof(char *), NULL); 6884 bc_vec_init(&v, sizeof(char *), NULL);
6884 bc_vec_push(&v, &nullptr);
6885 6885
6886 while (*(buf = skip_whitespace(buf)) != '\0') { 6886 while (*(buf = skip_whitespace(buf)) != '\0') {
6887 bc_vec_push(&v, &buf); 6887 bc_vec_push(&v, &buf);
@@ -6891,8 +6891,14 @@ static void bc_vm_envArgs(void)
6891 *buf++ = '\0'; 6891 *buf++ = '\0';
6892 } 6892 }
6893 6893
6894 bc_vec_push(&v, &nullptr); 6894 // NULL terminate, and pass argv[] so that first arg is argv[1]
6895 bc_args((char **) v.v); 6895 if (sizeof(int) == sizeof(char*)) {
6896 bc_vec_push(&v, &const_int_0);
6897 } else {
6898 static char *const nullptr = NULL;
6899 bc_vec_push(&v, &nullptr);
6900 }
6901 bc_args(((char **)v.v) - 1);
6896 6902
6897 bc_vec_free(&v); 6903 bc_vec_free(&v);
6898} 6904}