aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index b22cd41f1..918cf4638 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -167,6 +167,12 @@
167# include "dc.c" 167# include "dc.c"
168#else 168#else
169 169
170#if 0
171# define dbg_lex(...) bb_error_msg(__VA_ARGS__)
172#else
173# define dbg_lex(...) ((void)0)
174#endif
175
170typedef enum BcStatus { 176typedef enum BcStatus {
171 BC_STATUS_SUCCESS = 0, 177 BC_STATUS_SUCCESS = 0,
172 BC_STATUS_FAILURE = 1, 178 BC_STATUS_FAILURE = 1,
@@ -2935,8 +2941,12 @@ static BC_STATUS zbc_lex_next(BcLex *l)
2935 // is so the parser doesn't get inundated with whitespace. 2941 // is so the parser doesn't get inundated with whitespace.
2936 s = BC_STATUS_SUCCESS; 2942 s = BC_STATUS_SUCCESS;
2937 do { 2943 do {
2944 dbg_lex("next token:'%.*s'",
2945 (int)(strchrnul(l->buf + l->i, '\n') - (l->buf + l->i)),
2946 l->buf + l->i);
2938 ERROR_RETURN(s =) zcommon_lex_token(l); 2947 ERROR_RETURN(s =) zcommon_lex_token(l);
2939 } while (!s && l->t.t == BC_LEX_WHITESPACE); 2948 } while (!s && l->t.t == BC_LEX_WHITESPACE);
2949 dbg_lex("next l->t.t:%d", l->t.t);
2940 2950
2941 RETURN_STATUS(s); 2951 RETURN_STATUS(s);
2942} 2952}
@@ -3035,15 +3045,16 @@ static BC_STATUS zbc_lex_string(BcLex *l)
3035# define zbc_lex_string(...) (zbc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS) 3045# define zbc_lex_string(...) (zbc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS)
3036#endif 3046#endif
3037 3047
3038static void bc_lex_assign(BcLex *l, BcLexType with, BcLexType without) 3048static void bc_lex_assign(BcLex *l, unsigned with_and_without)
3039{ 3049{
3040 if (l->buf[l->i] == '=') { 3050 if (l->buf[l->i] == '=') {
3041 ++l->i; 3051 ++l->i;
3042 l->t.t = with; 3052 with_and_without >>= 8; // store "with" value
3043 } 3053 } // else store "without" value
3044 else 3054 l->t.t = (with_and_without & 0xff);
3045 l->t.t = without;
3046} 3055}
3056#define bc_lex_assign(l, with, without) \
3057 bc_lex_assign(l, ((with)<<8)|(without))
3047 3058
3048static BC_STATUS zbc_lex_comment(BcLex *l) 3059static BC_STATUS zbc_lex_comment(BcLex *l)
3049{ 3060{
@@ -7523,11 +7534,11 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
7523 // 1 char wider than bc from the same package. 7534 // 1 char wider than bc from the same package.
7524 // Both default width, and xC_LINE_LENGTH=N are wider: 7535 // Both default width, and xC_LINE_LENGTH=N are wider:
7525 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: 7536 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7526 // 1234\ 7537 // |1234\ |
7527 // 56 7538 // |56 |
7528 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: 7539 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7529 // 123\ 7540 // |123\ |
7530 // 456 7541 // |456 |
7531 // Do the same, or it's a bug? 7542 // Do the same, or it's a bug?
7532 bc_vm_init("DC_LINE_LENGTH"); 7543 bc_vm_init("DC_LINE_LENGTH");
7533 7544