aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-02 18:49:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 15:42:48 +0100
commitef869ec7283180e3733948ae31d1016ad9da4c0d (patch)
treef06dcc0af9f53465e51196d3fb875fca0639ec2d
parent01055ba89a92470587d9012c7e8707d943ebd875 (diff)
downloadbusybox-ef869ec7283180e3733948ae31d1016ad9da4c0d.tar.gz
bc: fix warnings, initial cleanups
function old new delta bc_program_exec - 4401 +4401 bc_vm_run - 2601 +2601 bc_parse_expr - 2215 +2215 bc_parse_stmt - 2197 +2197 bc_lib - 1878 +1878 bc_lex_token - 1333 +1333 bc_program_num - 1134 +1134 bc_num_k - 1010 +1010 bc_program_modexp - 793 +793 bc_program_print - 762 +762 dc_parse_expr - 723 +723 dc_lex_token - 670 +670 bc_num_d - 614 +614 bc_parse_name - 590 +590 bc_program_execStr - 579 +579 bc_num_printNum - 572 +572 bc_num_p - 518 +518 bc_num_a - 480 +480 bc_parse_parse - 471 +471 bc_program_assign - 450 +450 bc_parse_endBody - 423 +423 bc_program_call - 371 +371 dc_lex_tokens - 364 +364 bc_vm_process - 361 +361 bc_program_copyToVar - 355 +355 dc_parse_insts - 332 +332 bc_program_read - 323 +323 bc_program_binOpPrep - 301 +301 bc_lex_number - 301 +301 bc_read_line - 297 +297 bc_num_cmp - 294 +294 bc_num_m - 287 +287 bc_parse_auto - 275 +275 bc_num_s - 258 +258 bc_program_pushVar - 236 +236 bc_num_r - 231 +231 bc_program_addFunc - 220 +220 bc_lex_kws - 220 +220 bc_err_msgs - 216 +216 bc_parse_create - 198 +198 bc_vm_posixError - 194 +194 bc_parse_reset - 194 +194 bc_parse_operator - 181 +181 bc_program_reset - 178 +178 bc_program_printStream - 176 +176 bc_num_divmod - 168 +168 bc_copyright - 155 +155 bc_program_search - 154 +154 bc_num_binary - 150 +150 bc_vm_error - 148 +148 bc_program_pushArray - 143 +143 bc_parse_text - 142 +142 bc_num_printDigits - 142 +142 bc_map_insert - 142 +142 bc_parse_else - 139 +139 bc_program_assignStr - 131 +131 bc_args - 125 +125 dc_parse_mem - 116 +116 bc_parse_body - 116 +116 bc_num_split - 113 +113 bc_num_sub - 112 +112 bc_num_add - 112 +112 packed_usage 32958 33066 +108 bc_num_rem - 104 +104 bc_parse_string - 103 +103 bc_main - 97 +97 bc_num_ulong - 95 +95 bc_func_insert - 89 +89 bc_vm_sig - 88 +88 bc_program_prep - 88 +88 bc_parse_number - 88 +88 bc_array_expand - 88 +88 bc_num_subArrays - 84 +84 bc_num_compare - 84 +84 bc_lex_name - 83 +83 bc_args_lopt - 81 +81 bc_parse_pushIndex - 80 +80 bc_num_mul - 80 +80 bc_num_mod - 80 +80 bc_num_div - 80 +80 bc_vm_info - 76 +76 bc_program_name - 75 +75 bc_map_find - 71 +71 bc_lex_next - 71 +71 bc_num_printHex - 70 +70 bc_vec_concat - 68 +68 bc_num_shift - 68 +68 bc_num_extend - 68 +68 bc_program_index - 66 +66 bc_num_ulong2num - 66 +66 bc_num_retireMul - 66 +66 bc_parse_noElse - 65 +65 bc_vec_string - 64 +64 bc_parse_pushName - 63 +63 bc_parse_exprs - 60 +60 bc_err_ids - 58 +58 bc_result_free - 57 +57 bc_vec_npop - 55 +55 dc_parse_parse - 53 +53 bc_vec_push - 53 +53 bc_parse_free - 53 +53 bc_num_inv - 53 +53 dc_parse_register - 52 +52 dc_lex_regs - 52 +52 bc_lex_whitespace - 52 +52 bc_num_copy - 51 +51 bc_program_binOpRetire - 50 +50 bc_parse_ops - 50 +50 bc_map_index - 50 +50 bcg - 48 +48 bc_num_init - 48 +48 bc_parse_startBody - 47 +47 bc_num_pow - 47 +47 bc_vm_putchar - 46 +46 bc_vm_exit - 46 +46 bc_num_clean - 45 +45 bc_parse_addFunc - 44 +44 bc_vec_grow - 42 +42 bc_program_len - 42 +42 bc_num_truncate - 42 +42 bc_array_init - 42 +42 bc_parse_expression - 39 +39 bc_lex_lineComment - 39 +39 bc_num_expand - 38 +38 bc_vec_init - 37 +37 bc_vm_printf - 36 +36 bc_num_printNewline - 36 +36 bc_func_free - 35 +35 bc_sig_msg - 34 +34 bc_program_retire - 34 +34 bc_lex_assign - 34 +34 dc_parse_init - 33 +33 bc_parse_init - 33 +33 dc_sig_msg - 31 +31 bc_vec_expand - 30 +30 bc_num_ten - 30 +30 bc_num_one - 28 +28 bc_errs - 28 +28 bc_vec_free - 27 +27 bc_program_ops - 24 +24 bc_vm_puts - 23 +23 bc_num_printChar - 23 +23 bc_program_ready_msg - 22 +22 bc_vm_fflush - 21 +21 dc_main 77 97 +20 bc_parse_next_rel - 20 +20 bc_parse_next_read - 20 +20 bc_parse_next_print - 20 +20 bc_parse_next_param - 20 +20 bc_parse_next_for - 20 +20 bc_parse_next_expr - 20 +20 bc_parse_next_elem - 20 +20 bc_warn_fmt - 17 +17 bc_vec_pushByte - 15 +15 bc_string_free - 15 +15 bc_num_setToZero - 15 +15 bc_num_free - 15 +15 bc_lex_file - 15 +15 bc_id_free - 15 +15 bc_err_fmt - 15 +15 bc_vec_item_rev - 14 +14 bc_id_cmp - 12 +12 bc_num_zero - 11 +11 bc_vec_item - 9 +9 bc_program_stdin_name - 8 +8 bc_program_scale - 8 +8 bc_args_opt - 8 +8 bc_func_read - 7 +7 bc_func_main - 7 +7 bc_err_line - 7 +7 bc_lib_name - 4 +4 bc_args_env_name - 4 +4 applet_main 1604 1608 +4 dc_name - 3 +3 bc_name - 3 +3 applet_names 2781 2784 +3 static.bases 5 - -5 check_under 20 - -20 pop 24 - -24 print_no_pop 32 - -32 sub 34 - -34 divide 34 - -34 mul 37 - -37 add 37 - -37 push 38 - -38 print_stack_no_pop 40 - -40 not 72 - -72 set_output_base 95 - -95 or 103 - -103 eor 103 - -103 and 103 - -103 mod 105 - -105 stack_machine 116 - -116 operators 144 - -144 print_base 230 - -230 ------------------------------------------------------------------------------ (add/remove: 173/20 grow/shrink: 4/0 up/down: 38089/-1372) Total: 36717 bytes text data bss dec hex filename 950181 485 7296 957962 e9e0a busybox_old 989722 485 7344 997551 f38af busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c253
1 files changed, 124 insertions, 129 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index bf0cbc397..4cbef4da6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -173,9 +173,9 @@ typedef enum BcStatus {
BC_STATUS_LEX_NO_STRING_END,
BC_STATUS_LEX_NO_COMMENT_END,
BC_STATUS_LEX_EOF,
-#ifdef ENABLE_DC
+#if ENABLE_DC
BC_STATUS_LEX_EXTENDED_REG,
-#endif // ENABLE_DC
+#endif
BC_STATUS_PARSE_BAD_TOKEN,
BC_STATUS_PARSE_BAD_EXP,
@@ -213,7 +213,7 @@ typedef enum BcStatus {
BC_STATUS_VEC_OUT_OF_BOUNDS,
BC_STATUS_VEC_ITEM_EXISTS,
-#ifdef ENABLE_BC
+#if ENABLE_BC
BC_STATUS_POSIX_NAME_LEN,
BC_STATUS_POSIX_COMMENT,
BC_STATUS_POSIX_BAD_KW,
@@ -226,7 +226,7 @@ typedef enum BcStatus {
BC_STATUS_POSIX_FOR2,
BC_STATUS_POSIX_FOR3,
BC_STATUS_POSIX_BRACE,
-#endif // ENABLE_BC
+#endif
BC_STATUS_QUIT,
BC_STATUS_LIMITS,
@@ -241,9 +241,9 @@ typedef enum BcStatus {
#define BC_ERR_IDX_MATH (3)
#define BC_ERR_IDX_EXEC (4)
#define BC_ERR_IDX_VEC (5)
-#ifdef ENABLE_BC
+#if ENABLE_BC
#define BC_ERR_IDX_POSIX (6)
-#endif // ENABLE_BC
+#endif
#define BC_VEC_INVALID_IDX ((size_t) -1)
#define BC_VEC_START_CAP (1 << 5)
@@ -314,12 +314,12 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d,
typedef enum BcInst {
-#ifdef ENABLE_BC
+#if ENABLE_BC
BC_INST_INC_PRE,
BC_INST_DEC_PRE,
BC_INST_INC_POST,
BC_INST_DEC_POST,
-#endif // ENABLE_BC
+#endif
BC_INST_NEG,
@@ -341,14 +341,14 @@ typedef enum BcInst {
BC_INST_BOOL_OR,
BC_INST_BOOL_AND,
-#ifdef ENABLE_BC
+#if ENABLE_BC
BC_INST_ASSIGN_POWER,
BC_INST_ASSIGN_MULTIPLY,
BC_INST_ASSIGN_DIVIDE,
BC_INST_ASSIGN_MODULUS,
BC_INST_ASSIGN_PLUS,
BC_INST_ASSIGN_MINUS,
-#endif // ENABLE_BC
+#endif
BC_INST_ASSIGN,
BC_INST_NUM,
@@ -370,7 +370,7 @@ typedef enum BcInst {
BC_INST_STR,
BC_INST_PRINT_STR,
-#ifdef ENABLE_BC
+#if ENABLE_BC
BC_INST_JUMP,
BC_INST_JUMP_ZERO,
@@ -380,12 +380,12 @@ typedef enum BcInst {
BC_INST_RET0,
BC_INST_HALT,
-#endif // ENABLE_BC
+#endif
BC_INST_POP,
BC_INST_POP_EXEC,
-#ifdef ENABLE_DC
+#if ENABLE_DC
BC_INST_MODEXP,
BC_INST_DIVMOD,
@@ -409,7 +409,7 @@ typedef enum BcInst {
BC_INST_NQUIT,
BC_INST_INVALID = -1,
-#endif // ENABLE_DC
+#endif
} BcInst;
@@ -543,7 +543,7 @@ typedef enum BcLexType {
BC_LEX_KEY_SQRT,
BC_LEX_KEY_WHILE,
-#ifdef ENABLE_DC
+#if ENABLE_DC
BC_LEX_EQ_NO_REG,
BC_LEX_OP_MODEXP,
BC_LEX_OP_DIVMOD,
@@ -570,7 +570,7 @@ typedef enum BcLexType {
BC_LEX_PRINT_POP,
BC_LEX_NQUIT,
BC_LEX_SCALE_FACTOR,
-#endif // ENABLE_DC
+#endif
} BcLexType;
@@ -689,7 +689,7 @@ typedef struct BcParse {
} BcParse;
-#ifdef ENABLE_BC
+#if ENABLE_BC
BcStatus bc_main(int argc, char *argv[]);
@@ -719,7 +719,7 @@ static BcStatus bc_lex_token(BcLex *l);
static BcStatus bc_parse_parse(BcParse *p);
static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next);
-#endif // ENABLE_BC
+#endif
#ifdef ENABLE_DC
@@ -746,9 +746,9 @@ typedef struct BcProgram {
BcNum hexb;
-#ifdef ENABLE_DC
+#if ENABLE_DC
BcNum strmb;
-#endif // ENABLE_DC
+#endif
BcVec results;
BcVec stack;
@@ -783,9 +783,9 @@ typedef struct BcProgram {
#define BC_PROG_MAIN (0)
#define BC_PROG_READ (1)
-#ifdef ENABLE_DC
+#if ENABLE_DC
#define BC_PROG_REQ_FUNCS (2)
-#endif // ENABLE_DC
+#endif
#define BC_PROG_STR(n) (!(n)->num && !(n)->cap)
#define BC_PROG_NUM(r, n) \
@@ -852,16 +852,16 @@ typedef struct BcGlobals {
const char *name;
#if ENABLE_FEATURE_BC_SIGNALS
const char *sig_msg;
-#endif // ENABLE_FEATURE_BC_SIGNALS
+#endif
const char *help;
bool bc;
} BcGlobals;
-#ifdef ENABLE_BC
+#if ENABLE_BC
static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
const char *msg);
-#endif // ENABLE_BC
+#endif
static void bc_vm_exit(BcStatus s);
static void bc_vm_printf(FILE *restrict f, const char *fmt, ...);
@@ -875,19 +875,19 @@ static BcStatus bc_vm_run(int argc, char *argv[], BcVmExe exe,
static BcGlobals bcg;
-#ifdef ENABLE_BC
+#if ENABLE_BC
static const char bc_name[] = "bc";
-#if ENABLE_FEATURE_BC_SIGNALS
+# if ENABLE_FEATURE_BC_SIGNALS
static const char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n";
-#endif // ENABLE_FEATURE_BC_SIGNALS
-#endif // ENABLE_BC
+# endif
+#endif
-#ifdef ENABLE_DC
+#if ENABLE_DC
static const char dc_name[] = "dc";
-#if ENABLE_FEATURE_BC_SIGNALS
+# if ENABLE_FEATURE_BC_SIGNALS
static const char dc_sig_msg[] = "\ninterrupt (type \"q\" to exit)\n";
-#endif // ENABLE_FEATURE_BC_SIGNALS
-#endif // ENABLE_DC
+# endif
+#endif
static const char bc_copyright[] =
"Copyright (c) 2018 Gavin D. Howard and contributors\n"
@@ -907,35 +907,35 @@ static const char *bc_errs[] = {
"Math",
"Runtime",
"Vector",
-#ifdef ENABLE_BC
+#if ENABLE_BC
"POSIX",
-#endif // ENABLE_BC
+#endif
};
static const uint8_t bc_err_ids[] = {
BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX,
-#ifdef ENABLE_DC
+#if ENABLE_DC
BC_ERR_IDX_LEX,
-#endif // ENABLE_DC
+#endif
BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
BC_ERR_IDX_MATH,
-#ifdef ENABLE_DC
+#if ENABLE_DC
BC_ERR_IDX_MATH,
-#endif // ENABLE_DC
+#endif
BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
BC_ERR_IDX_EXEC,
BC_ERR_IDX_VEC, BC_ERR_IDX_VEC,
-#ifdef ENABLE_BC
+#if ENABLE_BC
BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
-#endif // ENABLE_BC
+#endif
BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
};
@@ -951,9 +951,9 @@ static const char *bc_err_msgs[] = {
"string end could not be found",
"comment end could not be found",
"end of file",
-#ifdef ENABLE_DC
+#if ENABLE_DC
"extended register",
-#endif // ENABLE_DC
+#endif
"bad token",
"bad expression",
@@ -992,7 +992,7 @@ static const char *bc_err_msgs[] = {
"index is out of bounds",
"item already exists",
-#ifdef ENABLE_BC
+#if ENABLE_BC
"POSIX only allows one character names; the following is bad:",
"POSIX does not allow '#' script comments",
"POSIX does not allow the following keyword:",
@@ -1005,14 +1005,14 @@ static const char *bc_err_msgs[] = {
"POSIX does not allow an empty condition expression in a for loop",
"POSIX does not allow an empty update expression in a for loop",
"POSIX requires the left brace be on the same line as the function header",
-#endif // ENABLE_BC
+#endif
};
static const char bc_func_main[] = "(main)";
static const char bc_func_read[] = "(read)";
-#ifdef ENABLE_BC
+#if ENABLE_BC
static const BcLexKeyword bc_lex_kws[20] = {
BC_LEX_KW_ENTRY("auto", 4, true),
BC_LEX_KW_ENTRY("break", 5, true),
@@ -1075,7 +1075,7 @@ static const BcParseNext bc_parse_next_read =
BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF);
#endif // ENABLE_BC
-#ifdef ENABLE_DC
+#if ENABLE_DC
static const BcLexType dc_lex_regs[] = {
BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE,
BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT, BC_LEX_SCOLON, BC_LEX_COLON,
@@ -1140,8 +1140,6 @@ static const BcInst dc_parse_insts[] = {
};
#endif // ENABLE_DC
-static const char bc_num_hex_digits[] = "0123456789ABCDEF";
-
static const BcNumBinaryOp bc_program_ops[] = {
bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub,
};
@@ -1149,7 +1147,7 @@ static const BcNumBinaryOp bc_program_ops[] = {
static const char bc_program_stdin_name[] = "<stdin>";
static const char bc_program_ready_msg[] = "ready for more input\n";
-#ifdef ENABLE_BC
+#if ENABLE_BC
static const char *bc_lib_name = "gen/lib.bc";
static const char bc_lib[] = {
@@ -1417,7 +1415,7 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
continue;
}
-#endif // ENABLE_FEATURE_BC_SIGNALS
+#endif
return BC_STATUS_IO_ERR;
}
@@ -1435,12 +1433,14 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
static BcStatus bc_read_file(const char *path, char **buf)
{
BcStatus s = BC_STATUS_BIN_FILE;
- size_t size = ((size_t) -1), read;
+ size_t size = ((size_t) -1);
+ size_t i;
*buf = xmalloc_open_read_close(path, &size);
- for (read = 0; read < size; ++read) {
- if (BC_READ_BIN_CHAR((*buf)[read])) goto read_err;
+ for (i = 0; i < size; ++i) {
+ if (BC_READ_BIN_CHAR((*buf)[i]))
+ goto read_err;
}
return BC_STATUS_SUCCESS;
@@ -1459,7 +1459,7 @@ static const char bc_args_lopt[] ALIGN1 =
"quiet\0"No_argument"q"
"mathlib\0"No_argument"l"
"interactive\0"No_argument"i";
-#endif // ENABLE_FEATURE_BC_LONG_OPTIONS
+#endif
static const char bc_args_opt[] ALIGN1 = "xwvsqli";
@@ -1473,9 +1473,9 @@ static BcStatus bc_args(int argc, char *argv[], uint32_t *flags, BcVec *files)
#if ENABLE_FEATURE_BC_LONG_OPTIONS
*flags = getopt32long(argv, bc_args_opt, bc_args_lopt);
-#else // ENABLE_FEATURE_BC_LONG_OPTIONS
+#else
*flags = getopt32(argv, bc_args_opt);
-#endif // ENABLE_FEATURE_BC_LONG_OPTIONS
+#endif
if ((*flags) & BC_FLAG_V) bc_vm_info(NULL);
if (do_exit) exit((int) s);
@@ -2335,7 +2335,7 @@ static void bc_num_printNewline(size_t *nchars, size_t line_len)
}
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static void bc_num_printChar(size_t num, size_t width, bool radix,
size_t *nchars, size_t line_len)
{
@@ -2343,25 +2343,27 @@ static void bc_num_printChar(size_t num, size_t width, bool radix,
bc_vm_putchar((char) num);
*nchars = *nchars + width;
}
-#endif // ENABLE_DC
+#endif
static void bc_num_printDigits(size_t num, size_t width, bool radix,
size_t *nchars, size_t line_len)
{
- size_t exp, pow, div;
+ size_t exp, pow;
bc_num_printNewline(nchars, line_len);
bc_vm_putchar(radix ? '.' : ' ');
++(*nchars);
bc_num_printNewline(nchars, line_len);
- for (exp = 0, pow = 1; exp < width - 1; ++exp, pow *= 10);
+ for (exp = 0, pow = 1; exp < width - 1; ++exp, pow *= 10)
+ continue;
for (exp = 0; exp < width; pow /= 10, ++(*nchars), ++exp) {
+ size_t dig;
bc_num_printNewline(nchars, line_len);
- div = num / pow;
- num -= div * pow;
- bc_vm_putchar(((char) div) + '0');
+ dig = num / pow;
+ num -= dig * pow;
+ bc_vm_putchar(((char) dig) + '0');
}
}
@@ -2375,7 +2377,7 @@ static void bc_num_printHex(size_t num, size_t width, bool radix,
}
bc_num_printNewline(nchars, line_len);
- bc_vm_putchar(bc_num_hex_digits[num]);
+ bc_vm_putchar(bb_hexdigits_upcase[num]);
*nchars = *nchars + width;
}
@@ -2483,12 +2485,12 @@ static BcStatus bc_num_printBase(BcNum *n, BcNum *base, size_t base_t,
return s;
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus bc_num_stream(BcNum *n, BcNum *base, size_t *nchars, size_t len)
{
return bc_num_printNum(n, base, 1, nchars, len, bc_num_printChar);
}
-#endif // ENABLE_DC
+#endif
static void bc_num_init(BcNum *n, size_t req)
{
@@ -2766,7 +2768,7 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d,
return s;
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
{
BcStatus s;
@@ -2908,7 +2910,7 @@ static void bc_string_free(void *string)
free(*((char **) string));
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static void bc_result_copy(BcResult *d, BcResult *src)
{
d->t = src->t;
@@ -3111,7 +3113,7 @@ static BcStatus bc_lex_text(BcLex *l, const char *text)
return bc_lex_next(l);
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
static BcStatus bc_lex_identifier(BcLex *l)
{
BcStatus s;
@@ -3490,7 +3492,7 @@ static BcStatus bc_lex_token(BcLex *l)
}
#endif // ENABLE_BC
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus dc_lex_register(BcLex *l)
{
BcStatus s = BC_STATUS_SUCCESS;
@@ -3762,7 +3764,7 @@ static void bc_parse_create(BcParse *p, BcProgram *prog, size_t func,
bc_parse_updateFunc(p, func);
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
static BcStatus bc_parse_else(BcParse *p);
static BcStatus bc_parse_stmt(BcParse *p);
@@ -5083,7 +5085,7 @@ static BcStatus bc_parse_expression(BcParse *p, uint8_t flags)
}
#endif // ENABLE_BC
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus dc_parse_register(BcParse *p)
{
BcStatus s;
@@ -5438,10 +5440,6 @@ static BcStatus bc_program_binOpPrep(BcProgram *p, BcResult **l, BcNum **ln,
return BC_STATUS_EXEC_BAD_TYPE;
if (!assign && !BC_PROG_NUM((*r), (*ln))) return BC_STATUS_EXEC_BAD_TYPE;
-#ifdef ENABLE_DC
-#else // ENABLE_DC
-#endif // ENABLE_DC
-
return s;
}
@@ -5463,9 +5461,6 @@ static BcStatus bc_program_prep(BcProgram *p, BcResult **r, BcNum **n)
s = bc_program_num(p, *r, n, false);
if (s) return s;
-#ifdef ENABLE_DC
-#endif // ENABLE_DC
-
if (!BC_PROG_NUM((*r), (*n))) return BC_STATUS_EXEC_BAD_TYPE;
return s;
@@ -5580,12 +5575,12 @@ static void bc_program_printString(const char *str, size_t *nchars)
{
size_t i, len = strlen(str);
-#ifdef ENABLE_DC
+#if ENABLE_DC
if (len == 0) {
bc_vm_putchar('\0');
return;
}
-#endif // ENABLE_DC
+#endif
for (i = 0; i < len; ++i, ++(*nchars)) {
@@ -5790,7 +5785,7 @@ static BcStatus bc_program_logical(BcProgram *p, char inst)
return s;
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus bc_program_assignStr(BcProgram *p, BcResult *r, BcVec *v,
bool push)
{
@@ -5829,10 +5824,10 @@ static BcStatus bc_program_copyToVar(BcProgram *p, char *name, bool var)
if ((ptr->t == BC_RESULT_ARRAY) != !var) return BC_STATUS_EXEC_BAD_TYPE;
bc_program_search(p, name, &v, var);
-#ifdef ENABLE_DC
+#if ENABLE_DC
if (ptr->t == BC_RESULT_STR && !var) return BC_STATUS_EXEC_BAD_TYPE;
if (ptr->t == BC_RESULT_STR) return bc_program_assignStr(p, ptr, v, true);
-#endif // ENABLE_DC
+#endif
s = bc_program_num(p, ptr, &n, false);
if (s) return s;
@@ -5869,7 +5864,7 @@ static BcStatus bc_program_assign(BcProgram *p, char inst)
ib = left->t == BC_RESULT_IBASE;
sc = left->t == BC_RESULT_SCALE;
-#ifdef ENABLE_DC
+#if ENABLE_DC
if (right->t == BC_RESULT_STR) {
@@ -5880,12 +5875,12 @@ static BcStatus bc_program_assign(BcProgram *p, char inst)
return bc_program_assignStr(p, right, v, false);
}
-#endif // ENABLE_DC
+#endif
if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP)
return BC_STATUS_PARSE_BAD_ASSIGN;
-#ifdef ENABLE_BC
+#if ENABLE_BC
if (inst == BC_INST_ASSIGN_DIVIDE && !bc_num_cmp(r, &p->zero))
return BC_STATUS_MATH_DIVIDE_BY_ZERO;
@@ -5895,9 +5890,9 @@ static BcStatus bc_program_assign(BcProgram *p, char inst)
s = bc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, p->scale);
if (s) return s;
-#else // ENABLE_BC
+#else
bc_num_copy(l, r);
-#endif // ENABLE_BC
+#endif
if (ib || sc || left->t == BC_RESULT_OBASE) {
@@ -5937,17 +5932,17 @@ static BcStatus bc_program_pushVar(BcProgram *p, char *code, size_t *bgn,
BcStatus s = BC_STATUS_SUCCESS;
BcResult r;
char *name = bc_program_name(code, bgn);
-#ifdef ENABLE_DC // Exclude
+#if ENABLE_DC // Exclude
BcNum *num;
BcVec *v;
-#else // ENABLE_DC
+#else
(void) pop, (void) copy;
-#endif // ENABLE_DC Exclude
+#endif
r.t = BC_RESULT_VAR;
r.d.id.name = name;
-#ifdef ENABLE_DC
+#if ENABLE_DC
bc_program_search(p, name, &v, true);
num = bc_vec_top(v);
@@ -6019,7 +6014,7 @@ err:
return s;
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
static BcStatus bc_program_incdec(BcProgram *p, char inst)
{
BcStatus s;
@@ -6180,19 +6175,19 @@ static BcStatus bc_program_builtin(BcProgram *p, char inst)
s = bc_program_num(p, opnd, &num, false);
if (s) return s;
-#ifdef ENABLE_DC
+#if ENABLE_DC
if (!BC_PROG_NUM(opnd, num) && !len) return BC_STATUS_EXEC_BAD_TYPE;
-#endif // ENABLE_DC
+#endif
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE);
if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, p->scale);
-#ifdef ENABLE_BC
+#if ENABLE_BC
else if (len != 0 && opnd->t == BC_RESULT_ARRAY) {
s = bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len);
}
-#endif // ENABLE_BC
-#ifdef ENABLE_DC
+#endif
+#if ENABLE_DC
else if (len != 0 && !BC_PROG_NUM(opnd, num)) {
char **str;
@@ -6202,7 +6197,7 @@ static BcStatus bc_program_builtin(BcProgram *p, char inst)
s = bc_num_ulong2num(&res.d.n, strlen(*str));
if (s) goto err;
}
-#endif // ENABLE_DC
+#endif
else {
BcProgramBuiltIn f = len ? bc_program_len : bc_program_scale;
s = bc_num_ulong2num(&res.d.n, f(num));
@@ -6218,7 +6213,7 @@ err:
return s;
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
static BcStatus bc_program_divmod(BcProgram *p)
{
BcStatus s;
@@ -6563,9 +6558,9 @@ static void bc_program_free(BcProgram *p)
bc_num_free(&p->ib);
bc_num_free(&p->ob);
bc_num_free(&p->hexb);
-#ifdef ENABLE_DC
+#if ENABLE_DC
bc_num_free(&p->strmb);
-#endif // ENABLE_DC
+#endif
bc_vec_free(&p->fns);
bc_vec_free(&p->fn_map);
bc_vec_free(&p->vars);
@@ -6607,10 +6602,10 @@ static void bc_program_init(BcProgram *p, size_t line_len, BcParseInit init,
bc_num_ten(&p->hexb);
p->hexb.num[0] = 6;
-#ifdef ENABLE_DC
+#if ENABLE_DC
bc_num_init(&p->strmb, BC_NUM_DEF_SIZE);
bc_num_ulong2num(&p->strmb, UCHAR_MAX + 1);
-#endif // ENABLE_DC
+#endif
bc_num_init(&p->last, BC_NUM_DEF_SIZE);
bc_num_zero(&p->last);
@@ -6718,7 +6713,7 @@ static BcStatus bc_program_exec(BcProgram *p)
switch (inst) {
-#ifdef ENABLE_BC
+#if ENABLE_BC
case BC_INST_JUMP_ZERO:
{
s = bc_program_prep(p, &ptr, &num);
@@ -6888,20 +6883,20 @@ static BcStatus bc_program_exec(BcProgram *p)
break;
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
case BC_INST_ASSIGN_POWER:
case BC_INST_ASSIGN_MULTIPLY:
case BC_INST_ASSIGN_DIVIDE:
case BC_INST_ASSIGN_MODULUS:
case BC_INST_ASSIGN_PLUS:
case BC_INST_ASSIGN_MINUS:
-#endif // ENABLE_BC
+#endif
case BC_INST_ASSIGN:
{
s = bc_program_assign(p, inst);
break;
}
-#ifdef ENABLE_DC
+#if ENABLE_DC
case BC_INST_MODEXP:
{
s = bc_program_modexp(p);
@@ -7032,7 +7027,7 @@ static void bc_vm_sig(int sig)
}
errno = err;
}
-#endif // ENABLE_FEATURE_BC_SIGNALS
+#endif
static void bc_vm_info(const char *const help)
{
@@ -7052,7 +7047,7 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
return s * (!bcg.ttyin || !!strcmp(file, bc_program_stdin_name));
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
const char *msg)
{
@@ -7315,7 +7310,7 @@ static BcStatus bc_vm_exec(BcVm *vm)
BcStatus s = BC_STATUS_SUCCESS;
size_t i;
-#ifdef ENABLE_BC
+#if ENABLE_BC
if (vm->flags & BC_FLAG_L) {
bc_lex_file(&vm->prs.l, bc_lib_name);
@@ -7327,7 +7322,7 @@ static BcStatus bc_vm_exec(BcVm *vm)
s = bc_program_exec(&vm->prog);
if (s) return s;
}
-#endif // ENABLE_BC
+#endif
for (i = 0; !s && i < vm->files.len; ++i)
s = bc_vm_file(vm, *((char **) bc_vec_item(&vm->files, i)));
@@ -7358,7 +7353,7 @@ static BcStatus bc_vm_init(BcVm *vm, BcVmExe exe, const char *env_len)
sa.sa_handler = bc_vm_sig;
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
-#endif // ENABLE_FEATURE_BC_SIGNALS
+#endif
memset(vm, 0, sizeof(BcVm));
@@ -7368,10 +7363,10 @@ static BcStatus bc_vm_init(BcVm *vm, BcVmExe exe, const char *env_len)
bc_vec_init(&vm->files, sizeof(char *), NULL);
-#ifdef ENABLE_BC
+#if ENABLE_BC
vm->flags |= BC_FLAG_S * bcg.bc * (getenv("POSIXLY_CORRECT") != NULL);
if (bcg.bc) s = bc_vm_envArgs(vm);
-#endif // ENABLE_BC
+#endif
bc_program_init(&vm->prog, len, exe.init, exe.exp);
exe.init(&vm->prs, &vm->prog, BC_PROG_MAIN);
@@ -7393,13 +7388,13 @@ static BcStatus bc_vm_run(int argc, char *argv[], BcVmExe exe,
bcg.ttyin = isatty(0);
bcg.tty = bcg.ttyin || (vm.flags & BC_FLAG_I) || isatty(1);
-#ifdef ENABLE_BC
+#if ENABLE_BC
bcg.posix = vm.flags & BC_FLAG_S;
bcg.warn = vm.flags & BC_FLAG_W;
-#endif // ENABLE_BC
-#ifdef ENABLE_DC
+#endif
+#if ENABLE_DC
bcg.exreg = vm.flags & BC_FLAG_X;
-#endif // ENABLE_DC
+#endif
if (bcg.ttyin && !(vm.flags & BC_FLAG_Q)) bc_vm_info(NULL);
st = bc_vm_exec(&vm);
@@ -7409,16 +7404,16 @@ exit:
return st;
}
-#ifdef ENABLE_BC
+#if ENABLE_BC
BcStatus bc_main(int argc, char *argv[])
{
BcVmExe exec;
bcg.bc = true;
bcg.name = bc_name;
-#if ENABLE_FEATURE_BC_SIGNALS
+# if ENABLE_FEATURE_BC_SIGNALS
bcg.sig_msg = bc_sig_msg;
-#endif // ENABLE_FEATURE_BC_SIGNALS
+# endif
exec.init = bc_parse_init;
exec.exp = bc_parse_expression;
@@ -7426,18 +7421,18 @@ BcStatus bc_main(int argc, char *argv[])
return bc_vm_run(argc, argv, exec, "BC_LINE_LENGTH");
}
-#endif // ENABLE_BC
+#endif
-#ifdef ENABLE_DC
+#if ENABLE_DC
BcStatus dc_main(int argc, char *argv[])
{
BcVmExe exec;
bcg.bc = false;
bcg.name = dc_name;
-#if ENABLE_FEATURE_BC_SIGNALS
+# if ENABLE_FEATURE_BC_SIGNALS
bcg.sig_msg = dc_sig_msg;
-#endif // ENABLE_FEATURE_BC_SIGNALS
+# endif
exec.init = dc_parse_init;
exec.exp = dc_parse_expr;
@@ -7446,4 +7441,4 @@ BcStatus dc_main(int argc, char *argv[])
return bc_vm_run(argc, argv, exec, "DC_LINE_LENGTH");
}
-#endif // ENABLE_DC
+#endif