diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-02 18:49:16 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 15:42:48 +0100 |
commit | ef869ec7283180e3733948ae31d1016ad9da4c0d (patch) | |
tree | f06dcc0af9f53465e51196d3fb875fca0639ec2d | |
parent | 01055ba89a92470587d9012c7e8707d943ebd875 (diff) | |
download | busybox-w32-ef869ec7283180e3733948ae31d1016ad9da4c0d.tar.gz busybox-w32-ef869ec7283180e3733948ae31d1016ad9da4c0d.tar.bz2 busybox-w32-ef869ec7283180e3733948ae31d1016ad9da4c0d.zip |
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.c | 253 |
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 { | |||
173 | BC_STATUS_LEX_NO_STRING_END, | 173 | BC_STATUS_LEX_NO_STRING_END, |
174 | BC_STATUS_LEX_NO_COMMENT_END, | 174 | BC_STATUS_LEX_NO_COMMENT_END, |
175 | BC_STATUS_LEX_EOF, | 175 | BC_STATUS_LEX_EOF, |
176 | #ifdef ENABLE_DC | 176 | #if ENABLE_DC |
177 | BC_STATUS_LEX_EXTENDED_REG, | 177 | BC_STATUS_LEX_EXTENDED_REG, |
178 | #endif // ENABLE_DC | 178 | #endif |
179 | 179 | ||
180 | BC_STATUS_PARSE_BAD_TOKEN, | 180 | BC_STATUS_PARSE_BAD_TOKEN, |
181 | BC_STATUS_PARSE_BAD_EXP, | 181 | BC_STATUS_PARSE_BAD_EXP, |
@@ -213,7 +213,7 @@ typedef enum BcStatus { | |||
213 | BC_STATUS_VEC_OUT_OF_BOUNDS, | 213 | BC_STATUS_VEC_OUT_OF_BOUNDS, |
214 | BC_STATUS_VEC_ITEM_EXISTS, | 214 | BC_STATUS_VEC_ITEM_EXISTS, |
215 | 215 | ||
216 | #ifdef ENABLE_BC | 216 | #if ENABLE_BC |
217 | BC_STATUS_POSIX_NAME_LEN, | 217 | BC_STATUS_POSIX_NAME_LEN, |
218 | BC_STATUS_POSIX_COMMENT, | 218 | BC_STATUS_POSIX_COMMENT, |
219 | BC_STATUS_POSIX_BAD_KW, | 219 | BC_STATUS_POSIX_BAD_KW, |
@@ -226,7 +226,7 @@ typedef enum BcStatus { | |||
226 | BC_STATUS_POSIX_FOR2, | 226 | BC_STATUS_POSIX_FOR2, |
227 | BC_STATUS_POSIX_FOR3, | 227 | BC_STATUS_POSIX_FOR3, |
228 | BC_STATUS_POSIX_BRACE, | 228 | BC_STATUS_POSIX_BRACE, |
229 | #endif // ENABLE_BC | 229 | #endif |
230 | 230 | ||
231 | BC_STATUS_QUIT, | 231 | BC_STATUS_QUIT, |
232 | BC_STATUS_LIMITS, | 232 | BC_STATUS_LIMITS, |
@@ -241,9 +241,9 @@ typedef enum BcStatus { | |||
241 | #define BC_ERR_IDX_MATH (3) | 241 | #define BC_ERR_IDX_MATH (3) |
242 | #define BC_ERR_IDX_EXEC (4) | 242 | #define BC_ERR_IDX_EXEC (4) |
243 | #define BC_ERR_IDX_VEC (5) | 243 | #define BC_ERR_IDX_VEC (5) |
244 | #ifdef ENABLE_BC | 244 | #if ENABLE_BC |
245 | #define BC_ERR_IDX_POSIX (6) | 245 | #define BC_ERR_IDX_POSIX (6) |
246 | #endif // ENABLE_BC | 246 | #endif |
247 | 247 | ||
248 | #define BC_VEC_INVALID_IDX ((size_t) -1) | 248 | #define BC_VEC_INVALID_IDX ((size_t) -1) |
249 | #define BC_VEC_START_CAP (1 << 5) | 249 | #define BC_VEC_START_CAP (1 << 5) |
@@ -314,12 +314,12 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | |||
314 | 314 | ||
315 | typedef enum BcInst { | 315 | typedef enum BcInst { |
316 | 316 | ||
317 | #ifdef ENABLE_BC | 317 | #if ENABLE_BC |
318 | BC_INST_INC_PRE, | 318 | BC_INST_INC_PRE, |
319 | BC_INST_DEC_PRE, | 319 | BC_INST_DEC_PRE, |
320 | BC_INST_INC_POST, | 320 | BC_INST_INC_POST, |
321 | BC_INST_DEC_POST, | 321 | BC_INST_DEC_POST, |
322 | #endif // ENABLE_BC | 322 | #endif |
323 | 323 | ||
324 | BC_INST_NEG, | 324 | BC_INST_NEG, |
325 | 325 | ||
@@ -341,14 +341,14 @@ typedef enum BcInst { | |||
341 | BC_INST_BOOL_OR, | 341 | BC_INST_BOOL_OR, |
342 | BC_INST_BOOL_AND, | 342 | BC_INST_BOOL_AND, |
343 | 343 | ||
344 | #ifdef ENABLE_BC | 344 | #if ENABLE_BC |
345 | BC_INST_ASSIGN_POWER, | 345 | BC_INST_ASSIGN_POWER, |
346 | BC_INST_ASSIGN_MULTIPLY, | 346 | BC_INST_ASSIGN_MULTIPLY, |
347 | BC_INST_ASSIGN_DIVIDE, | 347 | BC_INST_ASSIGN_DIVIDE, |
348 | BC_INST_ASSIGN_MODULUS, | 348 | BC_INST_ASSIGN_MODULUS, |
349 | BC_INST_ASSIGN_PLUS, | 349 | BC_INST_ASSIGN_PLUS, |
350 | BC_INST_ASSIGN_MINUS, | 350 | BC_INST_ASSIGN_MINUS, |
351 | #endif // ENABLE_BC | 351 | #endif |
352 | BC_INST_ASSIGN, | 352 | BC_INST_ASSIGN, |
353 | 353 | ||
354 | BC_INST_NUM, | 354 | BC_INST_NUM, |
@@ -370,7 +370,7 @@ typedef enum BcInst { | |||
370 | BC_INST_STR, | 370 | BC_INST_STR, |
371 | BC_INST_PRINT_STR, | 371 | BC_INST_PRINT_STR, |
372 | 372 | ||
373 | #ifdef ENABLE_BC | 373 | #if ENABLE_BC |
374 | BC_INST_JUMP, | 374 | BC_INST_JUMP, |
375 | BC_INST_JUMP_ZERO, | 375 | BC_INST_JUMP_ZERO, |
376 | 376 | ||
@@ -380,12 +380,12 @@ typedef enum BcInst { | |||
380 | BC_INST_RET0, | 380 | BC_INST_RET0, |
381 | 381 | ||
382 | BC_INST_HALT, | 382 | BC_INST_HALT, |
383 | #endif // ENABLE_BC | 383 | #endif |
384 | 384 | ||
385 | BC_INST_POP, | 385 | BC_INST_POP, |
386 | BC_INST_POP_EXEC, | 386 | BC_INST_POP_EXEC, |
387 | 387 | ||
388 | #ifdef ENABLE_DC | 388 | #if ENABLE_DC |
389 | BC_INST_MODEXP, | 389 | BC_INST_MODEXP, |
390 | BC_INST_DIVMOD, | 390 | BC_INST_DIVMOD, |
391 | 391 | ||
@@ -409,7 +409,7 @@ typedef enum BcInst { | |||
409 | BC_INST_NQUIT, | 409 | BC_INST_NQUIT, |
410 | 410 | ||
411 | BC_INST_INVALID = -1, | 411 | BC_INST_INVALID = -1, |
412 | #endif // ENABLE_DC | 412 | #endif |
413 | 413 | ||
414 | } BcInst; | 414 | } BcInst; |
415 | 415 | ||
@@ -543,7 +543,7 @@ typedef enum BcLexType { | |||
543 | BC_LEX_KEY_SQRT, | 543 | BC_LEX_KEY_SQRT, |
544 | BC_LEX_KEY_WHILE, | 544 | BC_LEX_KEY_WHILE, |
545 | 545 | ||
546 | #ifdef ENABLE_DC | 546 | #if ENABLE_DC |
547 | BC_LEX_EQ_NO_REG, | 547 | BC_LEX_EQ_NO_REG, |
548 | BC_LEX_OP_MODEXP, | 548 | BC_LEX_OP_MODEXP, |
549 | BC_LEX_OP_DIVMOD, | 549 | BC_LEX_OP_DIVMOD, |
@@ -570,7 +570,7 @@ typedef enum BcLexType { | |||
570 | BC_LEX_PRINT_POP, | 570 | BC_LEX_PRINT_POP, |
571 | BC_LEX_NQUIT, | 571 | BC_LEX_NQUIT, |
572 | BC_LEX_SCALE_FACTOR, | 572 | BC_LEX_SCALE_FACTOR, |
573 | #endif // ENABLE_DC | 573 | #endif |
574 | 574 | ||
575 | } BcLexType; | 575 | } BcLexType; |
576 | 576 | ||
@@ -689,7 +689,7 @@ typedef struct BcParse { | |||
689 | 689 | ||
690 | } BcParse; | 690 | } BcParse; |
691 | 691 | ||
692 | #ifdef ENABLE_BC | 692 | #if ENABLE_BC |
693 | 693 | ||
694 | BcStatus bc_main(int argc, char *argv[]); | 694 | BcStatus bc_main(int argc, char *argv[]); |
695 | 695 | ||
@@ -719,7 +719,7 @@ static BcStatus bc_lex_token(BcLex *l); | |||
719 | static BcStatus bc_parse_parse(BcParse *p); | 719 | static BcStatus bc_parse_parse(BcParse *p); |
720 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next); | 720 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next); |
721 | 721 | ||
722 | #endif // ENABLE_BC | 722 | #endif |
723 | 723 | ||
724 | #ifdef ENABLE_DC | 724 | #ifdef ENABLE_DC |
725 | 725 | ||
@@ -746,9 +746,9 @@ typedef struct BcProgram { | |||
746 | 746 | ||
747 | BcNum hexb; | 747 | BcNum hexb; |
748 | 748 | ||
749 | #ifdef ENABLE_DC | 749 | #if ENABLE_DC |
750 | BcNum strmb; | 750 | BcNum strmb; |
751 | #endif // ENABLE_DC | 751 | #endif |
752 | 752 | ||
753 | BcVec results; | 753 | BcVec results; |
754 | BcVec stack; | 754 | BcVec stack; |
@@ -783,9 +783,9 @@ typedef struct BcProgram { | |||
783 | #define BC_PROG_MAIN (0) | 783 | #define BC_PROG_MAIN (0) |
784 | #define BC_PROG_READ (1) | 784 | #define BC_PROG_READ (1) |
785 | 785 | ||
786 | #ifdef ENABLE_DC | 786 | #if ENABLE_DC |
787 | #define BC_PROG_REQ_FUNCS (2) | 787 | #define BC_PROG_REQ_FUNCS (2) |
788 | #endif // ENABLE_DC | 788 | #endif |
789 | 789 | ||
790 | #define BC_PROG_STR(n) (!(n)->num && !(n)->cap) | 790 | #define BC_PROG_STR(n) (!(n)->num && !(n)->cap) |
791 | #define BC_PROG_NUM(r, n) \ | 791 | #define BC_PROG_NUM(r, n) \ |
@@ -852,16 +852,16 @@ typedef struct BcGlobals { | |||
852 | const char *name; | 852 | const char *name; |
853 | #if ENABLE_FEATURE_BC_SIGNALS | 853 | #if ENABLE_FEATURE_BC_SIGNALS |
854 | const char *sig_msg; | 854 | const char *sig_msg; |
855 | #endif // ENABLE_FEATURE_BC_SIGNALS | 855 | #endif |
856 | const char *help; | 856 | const char *help; |
857 | bool bc; | 857 | bool bc; |
858 | 858 | ||
859 | } BcGlobals; | 859 | } BcGlobals; |
860 | 860 | ||
861 | #ifdef ENABLE_BC | 861 | #if ENABLE_BC |
862 | static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line, | 862 | static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line, |
863 | const char *msg); | 863 | const char *msg); |
864 | #endif // ENABLE_BC | 864 | #endif |
865 | 865 | ||
866 | static void bc_vm_exit(BcStatus s); | 866 | static void bc_vm_exit(BcStatus s); |
867 | static void bc_vm_printf(FILE *restrict f, const char *fmt, ...); | 867 | 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, | |||
875 | 875 | ||
876 | static BcGlobals bcg; | 876 | static BcGlobals bcg; |
877 | 877 | ||
878 | #ifdef ENABLE_BC | 878 | #if ENABLE_BC |
879 | static const char bc_name[] = "bc"; | 879 | static const char bc_name[] = "bc"; |
880 | #if ENABLE_FEATURE_BC_SIGNALS | 880 | # if ENABLE_FEATURE_BC_SIGNALS |
881 | static const char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n"; | 881 | static const char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n"; |
882 | #endif // ENABLE_FEATURE_BC_SIGNALS | 882 | # endif |
883 | #endif // ENABLE_BC | 883 | #endif |
884 | 884 | ||
885 | #ifdef ENABLE_DC | 885 | #if ENABLE_DC |
886 | static const char dc_name[] = "dc"; | 886 | static const char dc_name[] = "dc"; |
887 | #if ENABLE_FEATURE_BC_SIGNALS | 887 | # if ENABLE_FEATURE_BC_SIGNALS |
888 | static const char dc_sig_msg[] = "\ninterrupt (type \"q\" to exit)\n"; | 888 | static const char dc_sig_msg[] = "\ninterrupt (type \"q\" to exit)\n"; |
889 | #endif // ENABLE_FEATURE_BC_SIGNALS | 889 | # endif |
890 | #endif // ENABLE_DC | 890 | #endif |
891 | 891 | ||
892 | static const char bc_copyright[] = | 892 | static const char bc_copyright[] = |
893 | "Copyright (c) 2018 Gavin D. Howard and contributors\n" | 893 | "Copyright (c) 2018 Gavin D. Howard and contributors\n" |
@@ -907,35 +907,35 @@ static const char *bc_errs[] = { | |||
907 | "Math", | 907 | "Math", |
908 | "Runtime", | 908 | "Runtime", |
909 | "Vector", | 909 | "Vector", |
910 | #ifdef ENABLE_BC | 910 | #if ENABLE_BC |
911 | "POSIX", | 911 | "POSIX", |
912 | #endif // ENABLE_BC | 912 | #endif |
913 | }; | 913 | }; |
914 | 914 | ||
915 | static const uint8_t bc_err_ids[] = { | 915 | static const uint8_t bc_err_ids[] = { |
916 | BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, | 916 | BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, |
917 | BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, | 917 | BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, |
918 | #ifdef ENABLE_DC | 918 | #if ENABLE_DC |
919 | BC_ERR_IDX_LEX, | 919 | BC_ERR_IDX_LEX, |
920 | #endif // ENABLE_DC | 920 | #endif |
921 | BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, | 921 | BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, |
922 | BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, | 922 | BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, |
923 | BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, | 923 | BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, |
924 | BC_ERR_IDX_MATH, | 924 | BC_ERR_IDX_MATH, |
925 | #ifdef ENABLE_DC | 925 | #if ENABLE_DC |
926 | BC_ERR_IDX_MATH, | 926 | BC_ERR_IDX_MATH, |
927 | #endif // ENABLE_DC | 927 | #endif |
928 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, | 928 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, |
929 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, | 929 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, |
930 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, | 930 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, |
931 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, | 931 | BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, |
932 | BC_ERR_IDX_EXEC, | 932 | BC_ERR_IDX_EXEC, |
933 | BC_ERR_IDX_VEC, BC_ERR_IDX_VEC, | 933 | BC_ERR_IDX_VEC, BC_ERR_IDX_VEC, |
934 | #ifdef ENABLE_BC | 934 | #if ENABLE_BC |
935 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, | 935 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, |
936 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, | 936 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, |
937 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, | 937 | BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, |
938 | #endif // ENABLE_BC | 938 | #endif |
939 | BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, | 939 | BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, |
940 | }; | 940 | }; |
941 | 941 | ||
@@ -951,9 +951,9 @@ static const char *bc_err_msgs[] = { | |||
951 | "string end could not be found", | 951 | "string end could not be found", |
952 | "comment end could not be found", | 952 | "comment end could not be found", |
953 | "end of file", | 953 | "end of file", |
954 | #ifdef ENABLE_DC | 954 | #if ENABLE_DC |
955 | "extended register", | 955 | "extended register", |
956 | #endif // ENABLE_DC | 956 | #endif |
957 | 957 | ||
958 | "bad token", | 958 | "bad token", |
959 | "bad expression", | 959 | "bad expression", |
@@ -992,7 +992,7 @@ static const char *bc_err_msgs[] = { | |||
992 | "index is out of bounds", | 992 | "index is out of bounds", |
993 | "item already exists", | 993 | "item already exists", |
994 | 994 | ||
995 | #ifdef ENABLE_BC | 995 | #if ENABLE_BC |
996 | "POSIX only allows one character names; the following is bad:", | 996 | "POSIX only allows one character names; the following is bad:", |
997 | "POSIX does not allow '#' script comments", | 997 | "POSIX does not allow '#' script comments", |
998 | "POSIX does not allow the following keyword:", | 998 | "POSIX does not allow the following keyword:", |
@@ -1005,14 +1005,14 @@ static const char *bc_err_msgs[] = { | |||
1005 | "POSIX does not allow an empty condition expression in a for loop", | 1005 | "POSIX does not allow an empty condition expression in a for loop", |
1006 | "POSIX does not allow an empty update expression in a for loop", | 1006 | "POSIX does not allow an empty update expression in a for loop", |
1007 | "POSIX requires the left brace be on the same line as the function header", | 1007 | "POSIX requires the left brace be on the same line as the function header", |
1008 | #endif // ENABLE_BC | 1008 | #endif |
1009 | 1009 | ||
1010 | }; | 1010 | }; |
1011 | 1011 | ||
1012 | static const char bc_func_main[] = "(main)"; | 1012 | static const char bc_func_main[] = "(main)"; |
1013 | static const char bc_func_read[] = "(read)"; | 1013 | static const char bc_func_read[] = "(read)"; |
1014 | 1014 | ||
1015 | #ifdef ENABLE_BC | 1015 | #if ENABLE_BC |
1016 | static const BcLexKeyword bc_lex_kws[20] = { | 1016 | static const BcLexKeyword bc_lex_kws[20] = { |
1017 | BC_LEX_KW_ENTRY("auto", 4, true), | 1017 | BC_LEX_KW_ENTRY("auto", 4, true), |
1018 | BC_LEX_KW_ENTRY("break", 5, true), | 1018 | BC_LEX_KW_ENTRY("break", 5, true), |
@@ -1075,7 +1075,7 @@ static const BcParseNext bc_parse_next_read = | |||
1075 | BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF); | 1075 | BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF); |
1076 | #endif // ENABLE_BC | 1076 | #endif // ENABLE_BC |
1077 | 1077 | ||
1078 | #ifdef ENABLE_DC | 1078 | #if ENABLE_DC |
1079 | static const BcLexType dc_lex_regs[] = { | 1079 | static const BcLexType dc_lex_regs[] = { |
1080 | BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE, | 1080 | BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE, |
1081 | BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT, BC_LEX_SCOLON, BC_LEX_COLON, | 1081 | 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[] = { | |||
1140 | }; | 1140 | }; |
1141 | #endif // ENABLE_DC | 1141 | #endif // ENABLE_DC |
1142 | 1142 | ||
1143 | static const char bc_num_hex_digits[] = "0123456789ABCDEF"; | ||
1144 | |||
1145 | static const BcNumBinaryOp bc_program_ops[] = { | 1143 | static const BcNumBinaryOp bc_program_ops[] = { |
1146 | bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub, | 1144 | bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub, |
1147 | }; | 1145 | }; |
@@ -1149,7 +1147,7 @@ static const BcNumBinaryOp bc_program_ops[] = { | |||
1149 | static const char bc_program_stdin_name[] = "<stdin>"; | 1147 | static const char bc_program_stdin_name[] = "<stdin>"; |
1150 | static const char bc_program_ready_msg[] = "ready for more input\n"; | 1148 | static const char bc_program_ready_msg[] = "ready for more input\n"; |
1151 | 1149 | ||
1152 | #ifdef ENABLE_BC | 1150 | #if ENABLE_BC |
1153 | static const char *bc_lib_name = "gen/lib.bc"; | 1151 | static const char *bc_lib_name = "gen/lib.bc"; |
1154 | 1152 | ||
1155 | static const char bc_lib[] = { | 1153 | static const char bc_lib[] = { |
@@ -1417,7 +1415,7 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt) | |||
1417 | 1415 | ||
1418 | continue; | 1416 | continue; |
1419 | } | 1417 | } |
1420 | #endif // ENABLE_FEATURE_BC_SIGNALS | 1418 | #endif |
1421 | 1419 | ||
1422 | return BC_STATUS_IO_ERR; | 1420 | return BC_STATUS_IO_ERR; |
1423 | } | 1421 | } |
@@ -1435,12 +1433,14 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt) | |||
1435 | static BcStatus bc_read_file(const char *path, char **buf) | 1433 | static BcStatus bc_read_file(const char *path, char **buf) |
1436 | { | 1434 | { |
1437 | BcStatus s = BC_STATUS_BIN_FILE; | 1435 | BcStatus s = BC_STATUS_BIN_FILE; |
1438 | size_t size = ((size_t) -1), read; | 1436 | size_t size = ((size_t) -1); |
1437 | size_t i; | ||
1439 | 1438 | ||
1440 | *buf = xmalloc_open_read_close(path, &size); | 1439 | *buf = xmalloc_open_read_close(path, &size); |
1441 | 1440 | ||
1442 | for (read = 0; read < size; ++read) { | 1441 | for (i = 0; i < size; ++i) { |
1443 | if (BC_READ_BIN_CHAR((*buf)[read])) goto read_err; | 1442 | if (BC_READ_BIN_CHAR((*buf)[i])) |
1443 | goto read_err; | ||
1444 | } | 1444 | } |
1445 | 1445 | ||
1446 | return BC_STATUS_SUCCESS; | 1446 | return BC_STATUS_SUCCESS; |
@@ -1459,7 +1459,7 @@ static const char bc_args_lopt[] ALIGN1 = | |||
1459 | "quiet\0"No_argument"q" | 1459 | "quiet\0"No_argument"q" |
1460 | "mathlib\0"No_argument"l" | 1460 | "mathlib\0"No_argument"l" |
1461 | "interactive\0"No_argument"i"; | 1461 | "interactive\0"No_argument"i"; |
1462 | #endif // ENABLE_FEATURE_BC_LONG_OPTIONS | 1462 | #endif |
1463 | 1463 | ||
1464 | static const char bc_args_opt[] ALIGN1 = "xwvsqli"; | 1464 | static const char bc_args_opt[] ALIGN1 = "xwvsqli"; |
1465 | 1465 | ||
@@ -1473,9 +1473,9 @@ static BcStatus bc_args(int argc, char *argv[], uint32_t *flags, BcVec *files) | |||
1473 | 1473 | ||
1474 | #if ENABLE_FEATURE_BC_LONG_OPTIONS | 1474 | #if ENABLE_FEATURE_BC_LONG_OPTIONS |
1475 | *flags = getopt32long(argv, bc_args_opt, bc_args_lopt); | 1475 | *flags = getopt32long(argv, bc_args_opt, bc_args_lopt); |
1476 | #else // ENABLE_FEATURE_BC_LONG_OPTIONS | 1476 | #else |
1477 | *flags = getopt32(argv, bc_args_opt); | 1477 | *flags = getopt32(argv, bc_args_opt); |
1478 | #endif // ENABLE_FEATURE_BC_LONG_OPTIONS | 1478 | #endif |
1479 | 1479 | ||
1480 | if ((*flags) & BC_FLAG_V) bc_vm_info(NULL); | 1480 | if ((*flags) & BC_FLAG_V) bc_vm_info(NULL); |
1481 | if (do_exit) exit((int) s); | 1481 | if (do_exit) exit((int) s); |
@@ -2335,7 +2335,7 @@ static void bc_num_printNewline(size_t *nchars, size_t line_len) | |||
2335 | } | 2335 | } |
2336 | } | 2336 | } |
2337 | 2337 | ||
2338 | #ifdef ENABLE_DC | 2338 | #if ENABLE_DC |
2339 | static void bc_num_printChar(size_t num, size_t width, bool radix, | 2339 | static void bc_num_printChar(size_t num, size_t width, bool radix, |
2340 | size_t *nchars, size_t line_len) | 2340 | size_t *nchars, size_t line_len) |
2341 | { | 2341 | { |
@@ -2343,25 +2343,27 @@ static void bc_num_printChar(size_t num, size_t width, bool radix, | |||
2343 | bc_vm_putchar((char) num); | 2343 | bc_vm_putchar((char) num); |
2344 | *nchars = *nchars + width; | 2344 | *nchars = *nchars + width; |
2345 | } | 2345 | } |
2346 | #endif // ENABLE_DC | 2346 | #endif |
2347 | 2347 | ||
2348 | static void bc_num_printDigits(size_t num, size_t width, bool radix, | 2348 | static void bc_num_printDigits(size_t num, size_t width, bool radix, |
2349 | size_t *nchars, size_t line_len) | 2349 | size_t *nchars, size_t line_len) |
2350 | { | 2350 | { |
2351 | size_t exp, pow, div; | 2351 | size_t exp, pow; |
2352 | 2352 | ||
2353 | bc_num_printNewline(nchars, line_len); | 2353 | bc_num_printNewline(nchars, line_len); |
2354 | bc_vm_putchar(radix ? '.' : ' '); | 2354 | bc_vm_putchar(radix ? '.' : ' '); |
2355 | ++(*nchars); | 2355 | ++(*nchars); |
2356 | 2356 | ||
2357 | bc_num_printNewline(nchars, line_len); | 2357 | bc_num_printNewline(nchars, line_len); |
2358 | for (exp = 0, pow = 1; exp < width - 1; ++exp, pow *= 10); | 2358 | for (exp = 0, pow = 1; exp < width - 1; ++exp, pow *= 10) |
2359 | continue; | ||
2359 | 2360 | ||
2360 | for (exp = 0; exp < width; pow /= 10, ++(*nchars), ++exp) { | 2361 | for (exp = 0; exp < width; pow /= 10, ++(*nchars), ++exp) { |
2362 | size_t dig; | ||
2361 | bc_num_printNewline(nchars, line_len); | 2363 | bc_num_printNewline(nchars, line_len); |
2362 | div = num / pow; | 2364 | dig = num / pow; |
2363 | num -= div * pow; | 2365 | num -= dig * pow; |
2364 | bc_vm_putchar(((char) div) + '0'); | 2366 | bc_vm_putchar(((char) dig) + '0'); |
2365 | } | 2367 | } |
2366 | } | 2368 | } |
2367 | 2369 | ||
@@ -2375,7 +2377,7 @@ static void bc_num_printHex(size_t num, size_t width, bool radix, | |||
2375 | } | 2377 | } |
2376 | 2378 | ||
2377 | bc_num_printNewline(nchars, line_len); | 2379 | bc_num_printNewline(nchars, line_len); |
2378 | bc_vm_putchar(bc_num_hex_digits[num]); | 2380 | bc_vm_putchar(bb_hexdigits_upcase[num]); |
2379 | *nchars = *nchars + width; | 2381 | *nchars = *nchars + width; |
2380 | } | 2382 | } |
2381 | 2383 | ||
@@ -2483,12 +2485,12 @@ static BcStatus bc_num_printBase(BcNum *n, BcNum *base, size_t base_t, | |||
2483 | return s; | 2485 | return s; |
2484 | } | 2486 | } |
2485 | 2487 | ||
2486 | #ifdef ENABLE_DC | 2488 | #if ENABLE_DC |
2487 | static BcStatus bc_num_stream(BcNum *n, BcNum *base, size_t *nchars, size_t len) | 2489 | static BcStatus bc_num_stream(BcNum *n, BcNum *base, size_t *nchars, size_t len) |
2488 | { | 2490 | { |
2489 | return bc_num_printNum(n, base, 1, nchars, len, bc_num_printChar); | 2491 | return bc_num_printNum(n, base, 1, nchars, len, bc_num_printChar); |
2490 | } | 2492 | } |
2491 | #endif // ENABLE_DC | 2493 | #endif |
2492 | 2494 | ||
2493 | static void bc_num_init(BcNum *n, size_t req) | 2495 | static void bc_num_init(BcNum *n, size_t req) |
2494 | { | 2496 | { |
@@ -2766,7 +2768,7 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | |||
2766 | return s; | 2768 | return s; |
2767 | } | 2769 | } |
2768 | 2770 | ||
2769 | #ifdef ENABLE_DC | 2771 | #if ENABLE_DC |
2770 | static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d) | 2772 | static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d) |
2771 | { | 2773 | { |
2772 | BcStatus s; | 2774 | BcStatus s; |
@@ -2908,7 +2910,7 @@ static void bc_string_free(void *string) | |||
2908 | free(*((char **) string)); | 2910 | free(*((char **) string)); |
2909 | } | 2911 | } |
2910 | 2912 | ||
2911 | #ifdef ENABLE_DC | 2913 | #if ENABLE_DC |
2912 | static void bc_result_copy(BcResult *d, BcResult *src) | 2914 | static void bc_result_copy(BcResult *d, BcResult *src) |
2913 | { | 2915 | { |
2914 | d->t = src->t; | 2916 | d->t = src->t; |
@@ -3111,7 +3113,7 @@ static BcStatus bc_lex_text(BcLex *l, const char *text) | |||
3111 | return bc_lex_next(l); | 3113 | return bc_lex_next(l); |
3112 | } | 3114 | } |
3113 | 3115 | ||
3114 | #ifdef ENABLE_BC | 3116 | #if ENABLE_BC |
3115 | static BcStatus bc_lex_identifier(BcLex *l) | 3117 | static BcStatus bc_lex_identifier(BcLex *l) |
3116 | { | 3118 | { |
3117 | BcStatus s; | 3119 | BcStatus s; |
@@ -3490,7 +3492,7 @@ static BcStatus bc_lex_token(BcLex *l) | |||
3490 | } | 3492 | } |
3491 | #endif // ENABLE_BC | 3493 | #endif // ENABLE_BC |
3492 | 3494 | ||
3493 | #ifdef ENABLE_DC | 3495 | #if ENABLE_DC |
3494 | static BcStatus dc_lex_register(BcLex *l) | 3496 | static BcStatus dc_lex_register(BcLex *l) |
3495 | { | 3497 | { |
3496 | BcStatus s = BC_STATUS_SUCCESS; | 3498 | BcStatus s = BC_STATUS_SUCCESS; |
@@ -3762,7 +3764,7 @@ static void bc_parse_create(BcParse *p, BcProgram *prog, size_t func, | |||
3762 | bc_parse_updateFunc(p, func); | 3764 | bc_parse_updateFunc(p, func); |
3763 | } | 3765 | } |
3764 | 3766 | ||
3765 | #ifdef ENABLE_BC | 3767 | #if ENABLE_BC |
3766 | static BcStatus bc_parse_else(BcParse *p); | 3768 | static BcStatus bc_parse_else(BcParse *p); |
3767 | static BcStatus bc_parse_stmt(BcParse *p); | 3769 | static BcStatus bc_parse_stmt(BcParse *p); |
3768 | 3770 | ||
@@ -5083,7 +5085,7 @@ static BcStatus bc_parse_expression(BcParse *p, uint8_t flags) | |||
5083 | } | 5085 | } |
5084 | #endif // ENABLE_BC | 5086 | #endif // ENABLE_BC |
5085 | 5087 | ||
5086 | #ifdef ENABLE_DC | 5088 | #if ENABLE_DC |
5087 | static BcStatus dc_parse_register(BcParse *p) | 5089 | static BcStatus dc_parse_register(BcParse *p) |
5088 | { | 5090 | { |
5089 | BcStatus s; | 5091 | BcStatus s; |
@@ -5438,10 +5440,6 @@ static BcStatus bc_program_binOpPrep(BcProgram *p, BcResult **l, BcNum **ln, | |||
5438 | return BC_STATUS_EXEC_BAD_TYPE; | 5440 | return BC_STATUS_EXEC_BAD_TYPE; |
5439 | if (!assign && !BC_PROG_NUM((*r), (*ln))) return BC_STATUS_EXEC_BAD_TYPE; | 5441 | if (!assign && !BC_PROG_NUM((*r), (*ln))) return BC_STATUS_EXEC_BAD_TYPE; |
5440 | 5442 | ||
5441 | #ifdef ENABLE_DC | ||
5442 | #else // ENABLE_DC | ||
5443 | #endif // ENABLE_DC | ||
5444 | |||
5445 | return s; | 5443 | return s; |
5446 | } | 5444 | } |
5447 | 5445 | ||
@@ -5463,9 +5461,6 @@ static BcStatus bc_program_prep(BcProgram *p, BcResult **r, BcNum **n) | |||
5463 | s = bc_program_num(p, *r, n, false); | 5461 | s = bc_program_num(p, *r, n, false); |
5464 | if (s) return s; | 5462 | if (s) return s; |
5465 | 5463 | ||
5466 | #ifdef ENABLE_DC | ||
5467 | #endif // ENABLE_DC | ||
5468 | |||
5469 | if (!BC_PROG_NUM((*r), (*n))) return BC_STATUS_EXEC_BAD_TYPE; | 5464 | if (!BC_PROG_NUM((*r), (*n))) return BC_STATUS_EXEC_BAD_TYPE; |
5470 | 5465 | ||
5471 | return s; | 5466 | return s; |
@@ -5580,12 +5575,12 @@ static void bc_program_printString(const char *str, size_t *nchars) | |||
5580 | { | 5575 | { |
5581 | size_t i, len = strlen(str); | 5576 | size_t i, len = strlen(str); |
5582 | 5577 | ||
5583 | #ifdef ENABLE_DC | 5578 | #if ENABLE_DC |
5584 | if (len == 0) { | 5579 | if (len == 0) { |
5585 | bc_vm_putchar('\0'); | 5580 | bc_vm_putchar('\0'); |
5586 | return; | 5581 | return; |
5587 | } | 5582 | } |
5588 | #endif // ENABLE_DC | 5583 | #endif |
5589 | 5584 | ||
5590 | for (i = 0; i < len; ++i, ++(*nchars)) { | 5585 | for (i = 0; i < len; ++i, ++(*nchars)) { |
5591 | 5586 | ||
@@ -5790,7 +5785,7 @@ static BcStatus bc_program_logical(BcProgram *p, char inst) | |||
5790 | return s; | 5785 | return s; |
5791 | } | 5786 | } |
5792 | 5787 | ||
5793 | #ifdef ENABLE_DC | 5788 | #if ENABLE_DC |
5794 | static BcStatus bc_program_assignStr(BcProgram *p, BcResult *r, BcVec *v, | 5789 | static BcStatus bc_program_assignStr(BcProgram *p, BcResult *r, BcVec *v, |
5795 | bool push) | 5790 | bool push) |
5796 | { | 5791 | { |
@@ -5829,10 +5824,10 @@ static BcStatus bc_program_copyToVar(BcProgram *p, char *name, bool var) | |||
5829 | if ((ptr->t == BC_RESULT_ARRAY) != !var) return BC_STATUS_EXEC_BAD_TYPE; | 5824 | if ((ptr->t == BC_RESULT_ARRAY) != !var) return BC_STATUS_EXEC_BAD_TYPE; |
5830 | bc_program_search(p, name, &v, var); | 5825 | bc_program_search(p, name, &v, var); |
5831 | 5826 | ||
5832 | #ifdef ENABLE_DC | 5827 | #if ENABLE_DC |
5833 | if (ptr->t == BC_RESULT_STR && !var) return BC_STATUS_EXEC_BAD_TYPE; | 5828 | if (ptr->t == BC_RESULT_STR && !var) return BC_STATUS_EXEC_BAD_TYPE; |
5834 | if (ptr->t == BC_RESULT_STR) return bc_program_assignStr(p, ptr, v, true); | 5829 | if (ptr->t == BC_RESULT_STR) return bc_program_assignStr(p, ptr, v, true); |
5835 | #endif // ENABLE_DC | 5830 | #endif |
5836 | 5831 | ||
5837 | s = bc_program_num(p, ptr, &n, false); | 5832 | s = bc_program_num(p, ptr, &n, false); |
5838 | if (s) return s; | 5833 | if (s) return s; |
@@ -5869,7 +5864,7 @@ static BcStatus bc_program_assign(BcProgram *p, char inst) | |||
5869 | ib = left->t == BC_RESULT_IBASE; | 5864 | ib = left->t == BC_RESULT_IBASE; |
5870 | sc = left->t == BC_RESULT_SCALE; | 5865 | sc = left->t == BC_RESULT_SCALE; |
5871 | 5866 | ||
5872 | #ifdef ENABLE_DC | 5867 | #if ENABLE_DC |
5873 | 5868 | ||
5874 | if (right->t == BC_RESULT_STR) { | 5869 | if (right->t == BC_RESULT_STR) { |
5875 | 5870 | ||
@@ -5880,12 +5875,12 @@ static BcStatus bc_program_assign(BcProgram *p, char inst) | |||
5880 | 5875 | ||
5881 | return bc_program_assignStr(p, right, v, false); | 5876 | return bc_program_assignStr(p, right, v, false); |
5882 | } | 5877 | } |
5883 | #endif // ENABLE_DC | 5878 | #endif |
5884 | 5879 | ||
5885 | if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP) | 5880 | if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP) |
5886 | return BC_STATUS_PARSE_BAD_ASSIGN; | 5881 | return BC_STATUS_PARSE_BAD_ASSIGN; |
5887 | 5882 | ||
5888 | #ifdef ENABLE_BC | 5883 | #if ENABLE_BC |
5889 | if (inst == BC_INST_ASSIGN_DIVIDE && !bc_num_cmp(r, &p->zero)) | 5884 | if (inst == BC_INST_ASSIGN_DIVIDE && !bc_num_cmp(r, &p->zero)) |
5890 | return BC_STATUS_MATH_DIVIDE_BY_ZERO; | 5885 | return BC_STATUS_MATH_DIVIDE_BY_ZERO; |
5891 | 5886 | ||
@@ -5895,9 +5890,9 @@ static BcStatus bc_program_assign(BcProgram *p, char inst) | |||
5895 | s = bc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, p->scale); | 5890 | s = bc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, p->scale); |
5896 | 5891 | ||
5897 | if (s) return s; | 5892 | if (s) return s; |
5898 | #else // ENABLE_BC | 5893 | #else |
5899 | bc_num_copy(l, r); | 5894 | bc_num_copy(l, r); |
5900 | #endif // ENABLE_BC | 5895 | #endif |
5901 | 5896 | ||
5902 | if (ib || sc || left->t == BC_RESULT_OBASE) { | 5897 | if (ib || sc || left->t == BC_RESULT_OBASE) { |
5903 | 5898 | ||
@@ -5937,17 +5932,17 @@ static BcStatus bc_program_pushVar(BcProgram *p, char *code, size_t *bgn, | |||
5937 | BcStatus s = BC_STATUS_SUCCESS; | 5932 | BcStatus s = BC_STATUS_SUCCESS; |
5938 | BcResult r; | 5933 | BcResult r; |
5939 | char *name = bc_program_name(code, bgn); | 5934 | char *name = bc_program_name(code, bgn); |
5940 | #ifdef ENABLE_DC // Exclude | 5935 | #if ENABLE_DC // Exclude |
5941 | BcNum *num; | 5936 | BcNum *num; |
5942 | BcVec *v; | 5937 | BcVec *v; |
5943 | #else // ENABLE_DC | 5938 | #else |
5944 | (void) pop, (void) copy; | 5939 | (void) pop, (void) copy; |
5945 | #endif // ENABLE_DC Exclude | 5940 | #endif |
5946 | 5941 | ||
5947 | r.t = BC_RESULT_VAR; | 5942 | r.t = BC_RESULT_VAR; |
5948 | r.d.id.name = name; | 5943 | r.d.id.name = name; |
5949 | 5944 | ||
5950 | #ifdef ENABLE_DC | 5945 | #if ENABLE_DC |
5951 | bc_program_search(p, name, &v, true); | 5946 | bc_program_search(p, name, &v, true); |
5952 | num = bc_vec_top(v); | 5947 | num = bc_vec_top(v); |
5953 | 5948 | ||
@@ -6019,7 +6014,7 @@ err: | |||
6019 | return s; | 6014 | return s; |
6020 | } | 6015 | } |
6021 | 6016 | ||
6022 | #ifdef ENABLE_BC | 6017 | #if ENABLE_BC |
6023 | static BcStatus bc_program_incdec(BcProgram *p, char inst) | 6018 | static BcStatus bc_program_incdec(BcProgram *p, char inst) |
6024 | { | 6019 | { |
6025 | BcStatus s; | 6020 | BcStatus s; |
@@ -6180,19 +6175,19 @@ static BcStatus bc_program_builtin(BcProgram *p, char inst) | |||
6180 | s = bc_program_num(p, opnd, &num, false); | 6175 | s = bc_program_num(p, opnd, &num, false); |
6181 | if (s) return s; | 6176 | if (s) return s; |
6182 | 6177 | ||
6183 | #ifdef ENABLE_DC | 6178 | #if ENABLE_DC |
6184 | if (!BC_PROG_NUM(opnd, num) && !len) return BC_STATUS_EXEC_BAD_TYPE; | 6179 | if (!BC_PROG_NUM(opnd, num) && !len) return BC_STATUS_EXEC_BAD_TYPE; |
6185 | #endif // ENABLE_DC | 6180 | #endif |
6186 | 6181 | ||
6187 | bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); | 6182 | bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); |
6188 | 6183 | ||
6189 | if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, p->scale); | 6184 | if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, p->scale); |
6190 | #ifdef ENABLE_BC | 6185 | #if ENABLE_BC |
6191 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { | 6186 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { |
6192 | s = bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len); | 6187 | s = bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len); |
6193 | } | 6188 | } |
6194 | #endif // ENABLE_BC | 6189 | #endif |
6195 | #ifdef ENABLE_DC | 6190 | #if ENABLE_DC |
6196 | else if (len != 0 && !BC_PROG_NUM(opnd, num)) { | 6191 | else if (len != 0 && !BC_PROG_NUM(opnd, num)) { |
6197 | 6192 | ||
6198 | char **str; | 6193 | char **str; |
@@ -6202,7 +6197,7 @@ static BcStatus bc_program_builtin(BcProgram *p, char inst) | |||
6202 | s = bc_num_ulong2num(&res.d.n, strlen(*str)); | 6197 | s = bc_num_ulong2num(&res.d.n, strlen(*str)); |
6203 | if (s) goto err; | 6198 | if (s) goto err; |
6204 | } | 6199 | } |
6205 | #endif // ENABLE_DC | 6200 | #endif |
6206 | else { | 6201 | else { |
6207 | BcProgramBuiltIn f = len ? bc_program_len : bc_program_scale; | 6202 | BcProgramBuiltIn f = len ? bc_program_len : bc_program_scale; |
6208 | s = bc_num_ulong2num(&res.d.n, f(num)); | 6203 | s = bc_num_ulong2num(&res.d.n, f(num)); |
@@ -6218,7 +6213,7 @@ err: | |||
6218 | return s; | 6213 | return s; |
6219 | } | 6214 | } |
6220 | 6215 | ||
6221 | #ifdef ENABLE_DC | 6216 | #if ENABLE_DC |
6222 | static BcStatus bc_program_divmod(BcProgram *p) | 6217 | static BcStatus bc_program_divmod(BcProgram *p) |
6223 | { | 6218 | { |
6224 | BcStatus s; | 6219 | BcStatus s; |
@@ -6563,9 +6558,9 @@ static void bc_program_free(BcProgram *p) | |||
6563 | bc_num_free(&p->ib); | 6558 | bc_num_free(&p->ib); |
6564 | bc_num_free(&p->ob); | 6559 | bc_num_free(&p->ob); |
6565 | bc_num_free(&p->hexb); | 6560 | bc_num_free(&p->hexb); |
6566 | #ifdef ENABLE_DC | 6561 | #if ENABLE_DC |
6567 | bc_num_free(&p->strmb); | 6562 | bc_num_free(&p->strmb); |
6568 | #endif // ENABLE_DC | 6563 | #endif |
6569 | bc_vec_free(&p->fns); | 6564 | bc_vec_free(&p->fns); |
6570 | bc_vec_free(&p->fn_map); | 6565 | bc_vec_free(&p->fn_map); |
6571 | bc_vec_free(&p->vars); | 6566 | bc_vec_free(&p->vars); |
@@ -6607,10 +6602,10 @@ static void bc_program_init(BcProgram *p, size_t line_len, BcParseInit init, | |||
6607 | bc_num_ten(&p->hexb); | 6602 | bc_num_ten(&p->hexb); |
6608 | p->hexb.num[0] = 6; | 6603 | p->hexb.num[0] = 6; |
6609 | 6604 | ||
6610 | #ifdef ENABLE_DC | 6605 | #if ENABLE_DC |
6611 | bc_num_init(&p->strmb, BC_NUM_DEF_SIZE); | 6606 | bc_num_init(&p->strmb, BC_NUM_DEF_SIZE); |
6612 | bc_num_ulong2num(&p->strmb, UCHAR_MAX + 1); | 6607 | bc_num_ulong2num(&p->strmb, UCHAR_MAX + 1); |
6613 | #endif // ENABLE_DC | 6608 | #endif |
6614 | 6609 | ||
6615 | bc_num_init(&p->last, BC_NUM_DEF_SIZE); | 6610 | bc_num_init(&p->last, BC_NUM_DEF_SIZE); |
6616 | bc_num_zero(&p->last); | 6611 | bc_num_zero(&p->last); |
@@ -6718,7 +6713,7 @@ static BcStatus bc_program_exec(BcProgram *p) | |||
6718 | 6713 | ||
6719 | switch (inst) { | 6714 | switch (inst) { |
6720 | 6715 | ||
6721 | #ifdef ENABLE_BC | 6716 | #if ENABLE_BC |
6722 | case BC_INST_JUMP_ZERO: | 6717 | case BC_INST_JUMP_ZERO: |
6723 | { | 6718 | { |
6724 | s = bc_program_prep(p, &ptr, &num); | 6719 | s = bc_program_prep(p, &ptr, &num); |
@@ -6888,20 +6883,20 @@ static BcStatus bc_program_exec(BcProgram *p) | |||
6888 | break; | 6883 | break; |
6889 | } | 6884 | } |
6890 | 6885 | ||
6891 | #ifdef ENABLE_BC | 6886 | #if ENABLE_BC |
6892 | case BC_INST_ASSIGN_POWER: | 6887 | case BC_INST_ASSIGN_POWER: |
6893 | case BC_INST_ASSIGN_MULTIPLY: | 6888 | case BC_INST_ASSIGN_MULTIPLY: |
6894 | case BC_INST_ASSIGN_DIVIDE: | 6889 | case BC_INST_ASSIGN_DIVIDE: |
6895 | case BC_INST_ASSIGN_MODULUS: | 6890 | case BC_INST_ASSIGN_MODULUS: |
6896 | case BC_INST_ASSIGN_PLUS: | 6891 | case BC_INST_ASSIGN_PLUS: |
6897 | case BC_INST_ASSIGN_MINUS: | 6892 | case BC_INST_ASSIGN_MINUS: |
6898 | #endif // ENABLE_BC | 6893 | #endif |
6899 | case BC_INST_ASSIGN: | 6894 | case BC_INST_ASSIGN: |
6900 | { | 6895 | { |
6901 | s = bc_program_assign(p, inst); | 6896 | s = bc_program_assign(p, inst); |
6902 | break; | 6897 | break; |
6903 | } | 6898 | } |
6904 | #ifdef ENABLE_DC | 6899 | #if ENABLE_DC |
6905 | case BC_INST_MODEXP: | 6900 | case BC_INST_MODEXP: |
6906 | { | 6901 | { |
6907 | s = bc_program_modexp(p); | 6902 | s = bc_program_modexp(p); |
@@ -7032,7 +7027,7 @@ static void bc_vm_sig(int sig) | |||
7032 | } | 7027 | } |
7033 | errno = err; | 7028 | errno = err; |
7034 | } | 7029 | } |
7035 | #endif // ENABLE_FEATURE_BC_SIGNALS | 7030 | #endif |
7036 | 7031 | ||
7037 | static void bc_vm_info(const char *const help) | 7032 | static void bc_vm_info(const char *const help) |
7038 | { | 7033 | { |
@@ -7052,7 +7047,7 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line) | |||
7052 | return s * (!bcg.ttyin || !!strcmp(file, bc_program_stdin_name)); | 7047 | return s * (!bcg.ttyin || !!strcmp(file, bc_program_stdin_name)); |
7053 | } | 7048 | } |
7054 | 7049 | ||
7055 | #ifdef ENABLE_BC | 7050 | #if ENABLE_BC |
7056 | static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line, | 7051 | static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line, |
7057 | const char *msg) | 7052 | const char *msg) |
7058 | { | 7053 | { |
@@ -7315,7 +7310,7 @@ static BcStatus bc_vm_exec(BcVm *vm) | |||
7315 | BcStatus s = BC_STATUS_SUCCESS; | 7310 | BcStatus s = BC_STATUS_SUCCESS; |
7316 | size_t i; | 7311 | size_t i; |
7317 | 7312 | ||
7318 | #ifdef ENABLE_BC | 7313 | #if ENABLE_BC |
7319 | if (vm->flags & BC_FLAG_L) { | 7314 | if (vm->flags & BC_FLAG_L) { |
7320 | 7315 | ||
7321 | bc_lex_file(&vm->prs.l, bc_lib_name); | 7316 | bc_lex_file(&vm->prs.l, bc_lib_name); |
@@ -7327,7 +7322,7 @@ static BcStatus bc_vm_exec(BcVm *vm) | |||
7327 | s = bc_program_exec(&vm->prog); | 7322 | s = bc_program_exec(&vm->prog); |
7328 | if (s) return s; | 7323 | if (s) return s; |
7329 | } | 7324 | } |
7330 | #endif // ENABLE_BC | 7325 | #endif |
7331 | 7326 | ||
7332 | for (i = 0; !s && i < vm->files.len; ++i) | 7327 | for (i = 0; !s && i < vm->files.len; ++i) |
7333 | s = bc_vm_file(vm, *((char **) bc_vec_item(&vm->files, i))); | 7328 | 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) | |||
7358 | sa.sa_handler = bc_vm_sig; | 7353 | sa.sa_handler = bc_vm_sig; |
7359 | sa.sa_flags = 0; | 7354 | sa.sa_flags = 0; |
7360 | sigaction(SIGINT, &sa, NULL); | 7355 | sigaction(SIGINT, &sa, NULL); |
7361 | #endif // ENABLE_FEATURE_BC_SIGNALS | 7356 | #endif |
7362 | 7357 | ||
7363 | memset(vm, 0, sizeof(BcVm)); | 7358 | memset(vm, 0, sizeof(BcVm)); |
7364 | 7359 | ||
@@ -7368,10 +7363,10 @@ static BcStatus bc_vm_init(BcVm *vm, BcVmExe exe, const char *env_len) | |||
7368 | 7363 | ||
7369 | bc_vec_init(&vm->files, sizeof(char *), NULL); | 7364 | bc_vec_init(&vm->files, sizeof(char *), NULL); |
7370 | 7365 | ||
7371 | #ifdef ENABLE_BC | 7366 | #if ENABLE_BC |
7372 | vm->flags |= BC_FLAG_S * bcg.bc * (getenv("POSIXLY_CORRECT") != NULL); | 7367 | vm->flags |= BC_FLAG_S * bcg.bc * (getenv("POSIXLY_CORRECT") != NULL); |
7373 | if (bcg.bc) s = bc_vm_envArgs(vm); | 7368 | if (bcg.bc) s = bc_vm_envArgs(vm); |
7374 | #endif // ENABLE_BC | 7369 | #endif |
7375 | 7370 | ||
7376 | bc_program_init(&vm->prog, len, exe.init, exe.exp); | 7371 | bc_program_init(&vm->prog, len, exe.init, exe.exp); |
7377 | exe.init(&vm->prs, &vm->prog, BC_PROG_MAIN); | 7372 | exe.init(&vm->prs, &vm->prog, BC_PROG_MAIN); |
@@ -7393,13 +7388,13 @@ static BcStatus bc_vm_run(int argc, char *argv[], BcVmExe exe, | |||
7393 | bcg.ttyin = isatty(0); | 7388 | bcg.ttyin = isatty(0); |
7394 | bcg.tty = bcg.ttyin || (vm.flags & BC_FLAG_I) || isatty(1); | 7389 | bcg.tty = bcg.ttyin || (vm.flags & BC_FLAG_I) || isatty(1); |
7395 | 7390 | ||
7396 | #ifdef ENABLE_BC | 7391 | #if ENABLE_BC |
7397 | bcg.posix = vm.flags & BC_FLAG_S; | 7392 | bcg.posix = vm.flags & BC_FLAG_S; |
7398 | bcg.warn = vm.flags & BC_FLAG_W; | 7393 | bcg.warn = vm.flags & BC_FLAG_W; |
7399 | #endif // ENABLE_BC | 7394 | #endif |
7400 | #ifdef ENABLE_DC | 7395 | #if ENABLE_DC |
7401 | bcg.exreg = vm.flags & BC_FLAG_X; | 7396 | bcg.exreg = vm.flags & BC_FLAG_X; |
7402 | #endif // ENABLE_DC | 7397 | #endif |
7403 | 7398 | ||
7404 | if (bcg.ttyin && !(vm.flags & BC_FLAG_Q)) bc_vm_info(NULL); | 7399 | if (bcg.ttyin && !(vm.flags & BC_FLAG_Q)) bc_vm_info(NULL); |
7405 | st = bc_vm_exec(&vm); | 7400 | st = bc_vm_exec(&vm); |
@@ -7409,16 +7404,16 @@ exit: | |||
7409 | return st; | 7404 | return st; |
7410 | } | 7405 | } |
7411 | 7406 | ||
7412 | #ifdef ENABLE_BC | 7407 | #if ENABLE_BC |
7413 | BcStatus bc_main(int argc, char *argv[]) | 7408 | BcStatus bc_main(int argc, char *argv[]) |
7414 | { | 7409 | { |
7415 | BcVmExe exec; | 7410 | BcVmExe exec; |
7416 | 7411 | ||
7417 | bcg.bc = true; | 7412 | bcg.bc = true; |
7418 | bcg.name = bc_name; | 7413 | bcg.name = bc_name; |
7419 | #if ENABLE_FEATURE_BC_SIGNALS | 7414 | # if ENABLE_FEATURE_BC_SIGNALS |
7420 | bcg.sig_msg = bc_sig_msg; | 7415 | bcg.sig_msg = bc_sig_msg; |
7421 | #endif // ENABLE_FEATURE_BC_SIGNALS | 7416 | # endif |
7422 | 7417 | ||
7423 | exec.init = bc_parse_init; | 7418 | exec.init = bc_parse_init; |
7424 | exec.exp = bc_parse_expression; | 7419 | exec.exp = bc_parse_expression; |
@@ -7426,18 +7421,18 @@ BcStatus bc_main(int argc, char *argv[]) | |||
7426 | 7421 | ||
7427 | return bc_vm_run(argc, argv, exec, "BC_LINE_LENGTH"); | 7422 | return bc_vm_run(argc, argv, exec, "BC_LINE_LENGTH"); |
7428 | } | 7423 | } |
7429 | #endif // ENABLE_BC | 7424 | #endif |
7430 | 7425 | ||
7431 | #ifdef ENABLE_DC | 7426 | #if ENABLE_DC |
7432 | BcStatus dc_main(int argc, char *argv[]) | 7427 | BcStatus dc_main(int argc, char *argv[]) |
7433 | { | 7428 | { |
7434 | BcVmExe exec; | 7429 | BcVmExe exec; |
7435 | 7430 | ||
7436 | bcg.bc = false; | 7431 | bcg.bc = false; |
7437 | bcg.name = dc_name; | 7432 | bcg.name = dc_name; |
7438 | #if ENABLE_FEATURE_BC_SIGNALS | 7433 | # if ENABLE_FEATURE_BC_SIGNALS |
7439 | bcg.sig_msg = dc_sig_msg; | 7434 | bcg.sig_msg = dc_sig_msg; |
7440 | #endif // ENABLE_FEATURE_BC_SIGNALS | 7435 | # endif |
7441 | 7436 | ||
7442 | exec.init = dc_parse_init; | 7437 | exec.init = dc_parse_init; |
7443 | exec.exp = dc_parse_expr; | 7438 | exec.exp = dc_parse_expr; |
@@ -7446,4 +7441,4 @@ BcStatus dc_main(int argc, char *argv[]) | |||
7446 | 7441 | ||
7447 | return bc_vm_run(argc, argv, exec, "DC_LINE_LENGTH"); | 7442 | return bc_vm_run(argc, argv, exec, "DC_LINE_LENGTH"); |
7448 | } | 7443 | } |
7449 | #endif // ENABLE_DC | 7444 | #endif |