aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-14 23:32:51 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-14 23:32:51 +0100
commit0154d78738da5f56c09665e804d94fdcd31cb081 (patch)
tree0005c7a14979e8904564be69338eb3b6abcbe4dd /miscutils
parent7b1df3db975c97799a23cf0699d8f0fd1d046f22 (diff)
downloadbusybox-w32-0154d78738da5f56c09665e804d94fdcd31cb081.tar.gz
busybox-w32-0154d78738da5f56c09665e804d94fdcd31cb081.tar.bz2
busybox-w32-0154d78738da5f56c09665e804d94fdcd31cb081.zip
bc: shorten one message, make defines more readable
text data bss dec hex filename 979916 485 7296 987697 f1231 busybox_old 979893 485 7296 987674 f121a busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c89
1 files changed, 38 insertions, 51 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e1a4b8f52..9a501a25e 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -566,48 +566,37 @@ typedef struct BcLex {
566 566
567} BcLex; 567} BcLex;
568 568
569#define BC_PARSE_STREND ((char) UCHAR_MAX) 569#define BC_PARSE_STREND ((char) UCHAR_MAX)
570 570
571#define BC_PARSE_REL (1 << 0) 571#define BC_PARSE_REL (1 << 0)
572#define BC_PARSE_PRINT (1 << 1) 572#define BC_PARSE_PRINT (1 << 1)
573#define BC_PARSE_NOCALL (1 << 2) 573#define BC_PARSE_NOCALL (1 << 2)
574#define BC_PARSE_NOREAD (1 << 3) 574#define BC_PARSE_NOREAD (1 << 3)
575#define BC_PARSE_ARRAY (1 << 4) 575#define BC_PARSE_ARRAY (1 << 4)
576 576
577#define BC_PARSE_TOP_FLAG_PTR(parse) ((uint8_t *) bc_vec_top(&(parse)->flags)) 577#define BC_PARSE_TOP_FLAG_PTR(parse) ((uint8_t *) bc_vec_top(&(parse)->flags))
578#define BC_PARSE_TOP_FLAG(parse) (*(BC_PARSE_TOP_FLAG_PTR(parse))) 578#define BC_PARSE_TOP_FLAG(parse) (*(BC_PARSE_TOP_FLAG_PTR(parse)))
579 579
580#define BC_PARSE_FLAG_FUNC_INNER (1 << 0) 580#define BC_PARSE_FLAG_FUNC_INNER (1 << 0)
581#define BC_PARSE_FUNC_INNER(parse) \ 581#define BC_PARSE_FLAG_FUNC (1 << 1)
582 (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_FUNC_INNER) 582#define BC_PARSE_FLAG_BODY (1 << 2)
583 583#define BC_PARSE_FLAG_LOOP (1 << 3)
584#define BC_PARSE_FLAG_FUNC (1 << 1) 584#define BC_PARSE_FLAG_LOOP_INNER (1 << 4)
585#define BC_PARSE_FUNC(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_FUNC) 585#define BC_PARSE_FLAG_IF (1 << 5)
586 586#define BC_PARSE_FLAG_ELSE (1 << 6)
587#define BC_PARSE_FLAG_BODY (1 << 2) 587#define BC_PARSE_FLAG_IF_END (1 << 7)
588#define BC_PARSE_BODY(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_BODY) 588
589 589// If we have none of the above bits, we can stop parsing and execute already parsed chunk
590#define BC_PARSE_FLAG_LOOP (1 << 3) 590#define BC_PARSE_CAN_EXEC(parse) (BC_PARSE_TOP_FLAG(parse) == 0)
591#define BC_PARSE_LOOP(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_LOOP) 591
592 592#define BC_PARSE_FUNC_INNER(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_FUNC_INNER)
593#define BC_PARSE_FLAG_LOOP_INNER (1 << 4) 593#define BC_PARSE_FUNC(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_FUNC)
594#define BC_PARSE_LOOP_INNER(parse) \ 594#define BC_PARSE_BODY(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_BODY)
595 (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_LOOP_INNER) 595#define BC_PARSE_LOOP(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_LOOP)
596 596#define BC_PARSE_LOOP_INNER(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_LOOP_INNER)
597#define BC_PARSE_FLAG_IF (1 << 5) 597#define BC_PARSE_IF(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_IF)
598#define BC_PARSE_IF(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_IF) 598#define BC_PARSE_ELSE(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_ELSE)
599 599#define BC_PARSE_IF_END(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_IF_END)
600#define BC_PARSE_FLAG_ELSE (1 << 6)
601#define BC_PARSE_ELSE(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_ELSE)
602
603#define BC_PARSE_FLAG_IF_END (1 << 7)
604#define BC_PARSE_IF_END(parse) (BC_PARSE_TOP_FLAG(parse) & BC_PARSE_FLAG_IF_END)
605
606#define BC_PARSE_CAN_EXEC(parse) \
607 (!(BC_PARSE_TOP_FLAG(parse) & \
608 (BC_PARSE_FLAG_FUNC_INNER | BC_PARSE_FLAG_FUNC | BC_PARSE_FLAG_BODY | \
609 BC_PARSE_FLAG_LOOP | BC_PARSE_FLAG_LOOP_INNER | BC_PARSE_FLAG_IF | \
610 BC_PARSE_FLAG_ELSE | BC_PARSE_FLAG_IF_END)))
611 600
612struct BcParse; 601struct BcParse;
613 602
@@ -3611,7 +3600,7 @@ static void bc_parse_create(BcParse *p, size_t func)
3611// We can calculate the conversion between tokens and exprs by subtracting the 3600// We can calculate the conversion between tokens and exprs by subtracting the
3612// position of the first operator in the lex enum and adding the position of the 3601// position of the first operator in the lex enum and adding the position of the
3613// first in the expr enum. Note: This only works for binary operators. 3602// first in the expr enum. Note: This only works for binary operators.
3614#define BC_PARSE_TOKEN_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG)) 3603#define BC_TOKEN_2_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG))
3615 3604
3616static BC_STATUS zbc_parse_else(BcParse *p); 3605static BC_STATUS zbc_parse_else(BcParse *p);
3617static BC_STATUS zbc_parse_stmt(BcParse *p); 3606static BC_STATUS zbc_parse_stmt(BcParse *p);
@@ -3636,7 +3625,7 @@ static void bc_parse_operator(BcParse *p, BcLexType type, size_t start,
3636 l = bc_parse_op_PREC(t - BC_LEX_OP_INC); 3625 l = bc_parse_op_PREC(t - BC_LEX_OP_INC);
3637 if (l >= r && (l != r || !left)) break; 3626 if (l >= r && (l != r || !left)) break;
3638 3627
3639 bc_parse_push(p, BC_PARSE_TOKEN_INST(t)); 3628 bc_parse_push(p, BC_TOKEN_2_INST(t));
3640 bc_vec_pop(&p->ops); 3629 bc_vec_pop(&p->ops);
3641 *nexprs -= (t != BC_LEX_OP_BOOL_NOT && t != BC_LEX_NEG); 3630 *nexprs -= (t != BC_LEX_OP_BOOL_NOT && t != BC_LEX_NEG);
3642 } 3631 }
@@ -3653,7 +3642,7 @@ static BC_STATUS zbc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs)
3653 top = BC_PARSE_TOP_OP(p); 3642 top = BC_PARSE_TOP_OP(p);
3654 3643
3655 while (top != BC_LEX_LPAREN) { 3644 while (top != BC_LEX_LPAREN) {
3656 bc_parse_push(p, BC_PARSE_TOKEN_INST(top)); 3645 bc_parse_push(p, BC_TOKEN_2_INST(top));
3657 3646
3658 bc_vec_pop(&p->ops); 3647 bc_vec_pop(&p->ops);
3659 *nexs -= top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG; 3648 *nexs -= top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG;
@@ -3948,7 +3937,7 @@ static BC_STATUS zbc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
3948 (etype >= BC_INST_NUM && etype <= BC_INST_SQRT) ? 3937 (etype >= BC_INST_NUM && etype <= BC_INST_SQRT) ?
3949 BC_LEX_OP_MINUS : 3938 BC_LEX_OP_MINUS :
3950 BC_LEX_NEG; 3939 BC_LEX_NEG;
3951 *prev = BC_PARSE_TOKEN_INST(type); 3940 *prev = BC_TOKEN_2_INST(type);
3952 3941
3953 // We can just push onto the op stack because this is the largest 3942 // We can just push onto the op stack because this is the largest
3954 // precedence operator that gets pushed. Inc/dec does not. 3943 // precedence operator that gets pushed. Inc/dec does not.
@@ -4747,10 +4736,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne
4747 prev != BC_INST_OBASE && prev != BC_INST_LAST) 4736 prev != BC_INST_OBASE && prev != BC_INST_LAST)
4748 { 4737 {
4749 s = bc_error("bad assignment:" 4738 s = bc_error("bad assignment:"
4750 " left side must be scale," 4739 " left side must be variable"
4751 " ibase, obase, last, var,"
4752 " or array element" 4740 " or array element"
4753 ); 4741 ); // note: shared string
4754 break; 4742 break;
4755 } 4743 }
4756 } 4744 }
@@ -4777,7 +4765,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne
4777 } 4765 }
4778 4766
4779 nrelops += t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT; 4767 nrelops += t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT;
4780 prev = BC_PARSE_TOKEN_INST(t); 4768 prev = BC_TOKEN_2_INST(t);
4781 bc_parse_operator(p, t, ops_bgn, &nexprs); 4769 bc_parse_operator(p, t, ops_bgn, &nexprs);
4782 s = zbc_lex_next(&p->l); 4770 s = zbc_lex_next(&p->l);
4783 rprn = get_token = false; 4771 rprn = get_token = false;
@@ -4926,7 +4914,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne
4926 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN) 4914 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN)
4927 return bc_error_bad_expression(); 4915 return bc_error_bad_expression();
4928 4916
4929 bc_parse_push(p, BC_PARSE_TOKEN_INST(top)); 4917 bc_parse_push(p, BC_TOKEN_2_INST(top));
4930 4918
4931 nexprs -= top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG; 4919 nexprs -= top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG;
4932 bc_vec_pop(&p->ops); 4920 bc_vec_pop(&p->ops);
@@ -5977,10 +5965,9 @@ static BC_STATUS zbc_program_assign(char inst)
5977 5965
5978 if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP) 5966 if (left->t == BC_RESULT_CONSTANT || left->t == BC_RESULT_TEMP)
5979 RETURN_STATUS(bc_error("bad assignment:" 5967 RETURN_STATUS(bc_error("bad assignment:"
5980 " left side must be scale," 5968 " left side must be variable"
5981 " ibase, obase, last, var,"
5982 " or array element" 5969 " or array element"
5983 )); 5970 )); // note: shared string
5984 5971
5985#if ENABLE_BC 5972#if ENABLE_BC
5986 if (inst == BC_INST_ASSIGN_DIVIDE && !bc_num_cmp(r, &G.prog.zero)) 5973 if (inst == BC_INST_ASSIGN_DIVIDE && !bc_num_cmp(r, &G.prog.zero))