diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-14 00:12:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-14 00:12:13 +0100 |
commit | 57b6918b0a12e52207709070d0712910cb4323b9 (patch) | |
tree | b7cfa4e9a266e234a0f816cfe01d3a16ee04483e | |
parent | 5f263f406c99ebdf7d9c850c72f67ea0da095662 (diff) | |
download | busybox-w32-57b6918b0a12e52207709070d0712910cb4323b9.tar.gz busybox-w32-57b6918b0a12e52207709070d0712910cb4323b9.tar.bz2 busybox-w32-57b6918b0a12e52207709070d0712910cb4323b9.zip |
bc: group ENABLE_BC code a bit better, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 144 |
1 files changed, 71 insertions, 73 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 606037abc..a572ad30a 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -6899,78 +6899,6 @@ static BC_STATUS zbc_program_exec(void) | |||
6899 | # define zbc_program_exec(...) (zbc_program_exec(__VA_ARGS__), BC_STATUS_SUCCESS) | 6899 | # define zbc_program_exec(...) (zbc_program_exec(__VA_ARGS__), BC_STATUS_SUCCESS) |
6900 | #endif | 6900 | #endif |
6901 | 6901 | ||
6902 | #if ENABLE_BC | ||
6903 | static void bc_vm_info(void) | ||
6904 | { | ||
6905 | printf("%s "BB_VER"\n" | ||
6906 | "Copyright (c) 2018 Gavin D. Howard and contributors\n" | ||
6907 | , applet_name); | ||
6908 | } | ||
6909 | |||
6910 | static void bc_args(char **argv) | ||
6911 | { | ||
6912 | unsigned opts; | ||
6913 | int i; | ||
6914 | |||
6915 | GETOPT_RESET(); | ||
6916 | #if ENABLE_FEATURE_BC_LONG_OPTIONS | ||
6917 | opts = option_mask32 |= getopt32long(argv, "wvsqli", | ||
6918 | "warn\0" No_argument "w" | ||
6919 | "version\0" No_argument "v" | ||
6920 | "standard\0" No_argument "s" | ||
6921 | "quiet\0" No_argument "q" | ||
6922 | "mathlib\0" No_argument "l" | ||
6923 | "interactive\0" No_argument "i" | ||
6924 | ); | ||
6925 | #else | ||
6926 | opts = option_mask32 |= getopt32(argv, "wvsqli"); | ||
6927 | #endif | ||
6928 | if (getenv("POSIXLY_CORRECT")) | ||
6929 | option_mask32 |= BC_FLAG_S; | ||
6930 | |||
6931 | if (opts & BC_FLAG_V) { | ||
6932 | bc_vm_info(); | ||
6933 | exit(0); | ||
6934 | } | ||
6935 | |||
6936 | for (i = optind; argv[i]; ++i) | ||
6937 | bc_vec_push(&G.files, argv + i); | ||
6938 | } | ||
6939 | |||
6940 | static void bc_vm_envArgs(void) | ||
6941 | { | ||
6942 | BcVec v; | ||
6943 | char *buf; | ||
6944 | char *env_args = getenv("BC_ENV_ARGS"); | ||
6945 | |||
6946 | if (!env_args) return; | ||
6947 | |||
6948 | G.env_args = xstrdup(env_args); | ||
6949 | buf = G.env_args; | ||
6950 | |||
6951 | bc_vec_init(&v, sizeof(char *), NULL); | ||
6952 | |||
6953 | while (*(buf = skip_whitespace(buf)) != '\0') { | ||
6954 | bc_vec_push(&v, &buf); | ||
6955 | buf = skip_non_whitespace(buf); | ||
6956 | if (!*buf) | ||
6957 | break; | ||
6958 | *buf++ = '\0'; | ||
6959 | } | ||
6960 | |||
6961 | // NULL terminate, and pass argv[] so that first arg is argv[1] | ||
6962 | if (sizeof(int) == sizeof(char*)) { | ||
6963 | bc_vec_push(&v, &const_int_0); | ||
6964 | } else { | ||
6965 | static char *const nullptr = NULL; | ||
6966 | bc_vec_push(&v, &nullptr); | ||
6967 | } | ||
6968 | bc_args(((char **)v.v) - 1); | ||
6969 | |||
6970 | bc_vec_free(&v); | ||
6971 | } | ||
6972 | #endif // ENABLE_BC | ||
6973 | |||
6974 | static unsigned bc_vm_envLen(const char *var) | 6902 | static unsigned bc_vm_envLen(const char *var) |
6975 | { | 6903 | { |
6976 | char *lenv; | 6904 | char *lenv; |
@@ -7141,7 +7069,77 @@ static BC_STATUS zbc_vm_stdin(void) | |||
7141 | #endif | 7069 | #endif |
7142 | 7070 | ||
7143 | #if ENABLE_BC | 7071 | #if ENABLE_BC |
7144 | static const char bc_lib[] = { | 7072 | static void bc_vm_info(void) |
7073 | { | ||
7074 | printf("%s "BB_VER"\n" | ||
7075 | "Copyright (c) 2018 Gavin D. Howard and contributors\n" | ||
7076 | , applet_name); | ||
7077 | } | ||
7078 | |||
7079 | static void bc_args(char **argv) | ||
7080 | { | ||
7081 | unsigned opts; | ||
7082 | int i; | ||
7083 | |||
7084 | GETOPT_RESET(); | ||
7085 | #if ENABLE_FEATURE_BC_LONG_OPTIONS | ||
7086 | opts = option_mask32 |= getopt32long(argv, "wvsqli", | ||
7087 | "warn\0" No_argument "w" | ||
7088 | "version\0" No_argument "v" | ||
7089 | "standard\0" No_argument "s" | ||
7090 | "quiet\0" No_argument "q" | ||
7091 | "mathlib\0" No_argument "l" | ||
7092 | "interactive\0" No_argument "i" | ||
7093 | ); | ||
7094 | #else | ||
7095 | opts = option_mask32 |= getopt32(argv, "wvsqli"); | ||
7096 | #endif | ||
7097 | if (getenv("POSIXLY_CORRECT")) | ||
7098 | option_mask32 |= BC_FLAG_S; | ||
7099 | |||
7100 | if (opts & BC_FLAG_V) { | ||
7101 | bc_vm_info(); | ||
7102 | exit(0); | ||
7103 | } | ||
7104 | |||
7105 | for (i = optind; argv[i]; ++i) | ||
7106 | bc_vec_push(&G.files, argv + i); | ||
7107 | } | ||
7108 | |||
7109 | static void bc_vm_envArgs(void) | ||
7110 | { | ||
7111 | BcVec v; | ||
7112 | char *buf; | ||
7113 | char *env_args = getenv("BC_ENV_ARGS"); | ||
7114 | |||
7115 | if (!env_args) return; | ||
7116 | |||
7117 | G.env_args = xstrdup(env_args); | ||
7118 | buf = G.env_args; | ||
7119 | |||
7120 | bc_vec_init(&v, sizeof(char *), NULL); | ||
7121 | |||
7122 | while (*(buf = skip_whitespace(buf)) != '\0') { | ||
7123 | bc_vec_push(&v, &buf); | ||
7124 | buf = skip_non_whitespace(buf); | ||
7125 | if (!*buf) | ||
7126 | break; | ||
7127 | *buf++ = '\0'; | ||
7128 | } | ||
7129 | |||
7130 | // NULL terminate, and pass argv[] so that first arg is argv[1] | ||
7131 | if (sizeof(int) == sizeof(char*)) { | ||
7132 | bc_vec_push(&v, &const_int_0); | ||
7133 | } else { | ||
7134 | static char *const nullptr = NULL; | ||
7135 | bc_vec_push(&v, &nullptr); | ||
7136 | } | ||
7137 | bc_args(((char **)v.v) - 1); | ||
7138 | |||
7139 | bc_vec_free(&v); | ||
7140 | } | ||
7141 | |||
7142 | static const char bc_lib[] ALIGN1 = { | ||
7145 | "scale=20" | 7143 | "scale=20" |
7146 | "\n" "define e(x){" | 7144 | "\n" "define e(x){" |
7147 | "\n" "auto b,s,n,r,d,i,p,f,v" | 7145 | "\n" "auto b,s,n,r,d,i,p,f,v" |