diff options
-rw-r--r-- | miscutils/bc.c | 78 |
1 files changed, 34 insertions, 44 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 2e8d04460..b22cd41f1 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -475,22 +475,18 @@ static const struct BcLexKeyword bc_lex_kws[20] = { | |||
475 | BC_LEX_KW_ENTRY("break" , 1), // 1 | 475 | BC_LEX_KW_ENTRY("break" , 1), // 1 |
476 | BC_LEX_KW_ENTRY("continue", 0), // 2 note: this one has no terminating NUL | 476 | BC_LEX_KW_ENTRY("continue", 0), // 2 note: this one has no terminating NUL |
477 | BC_LEX_KW_ENTRY("define" , 1), // 3 | 477 | BC_LEX_KW_ENTRY("define" , 1), // 3 |
478 | |||
479 | BC_LEX_KW_ENTRY("else" , 0), // 4 | 478 | BC_LEX_KW_ENTRY("else" , 0), // 4 |
480 | BC_LEX_KW_ENTRY("for" , 1), // 5 | 479 | BC_LEX_KW_ENTRY("for" , 1), // 5 |
481 | BC_LEX_KW_ENTRY("halt" , 0), // 6 | 480 | BC_LEX_KW_ENTRY("halt" , 0), // 6 |
482 | BC_LEX_KW_ENTRY("ibase" , 1), // 7 | 481 | BC_LEX_KW_ENTRY("ibase" , 1), // 7 |
483 | |||
484 | BC_LEX_KW_ENTRY("if" , 1), // 8 | 482 | BC_LEX_KW_ENTRY("if" , 1), // 8 |
485 | BC_LEX_KW_ENTRY("last" , 0), // 9 | 483 | BC_LEX_KW_ENTRY("last" , 0), // 9 |
486 | BC_LEX_KW_ENTRY("length" , 1), // 10 | 484 | BC_LEX_KW_ENTRY("length" , 1), // 10 |
487 | BC_LEX_KW_ENTRY("limits" , 0), // 11 | 485 | BC_LEX_KW_ENTRY("limits" , 0), // 11 |
488 | |||
489 | BC_LEX_KW_ENTRY("obase" , 1), // 12 | 486 | BC_LEX_KW_ENTRY("obase" , 1), // 12 |
490 | BC_LEX_KW_ENTRY("print" , 0), // 13 | 487 | BC_LEX_KW_ENTRY("print" , 0), // 13 |
491 | BC_LEX_KW_ENTRY("quit" , 1), // 14 | 488 | BC_LEX_KW_ENTRY("quit" , 1), // 14 |
492 | BC_LEX_KW_ENTRY("read" , 0), // 15 | 489 | BC_LEX_KW_ENTRY("read" , 0), // 15 |
493 | |||
494 | BC_LEX_KW_ENTRY("return" , 1), // 16 | 490 | BC_LEX_KW_ENTRY("return" , 1), // 16 |
495 | BC_LEX_KW_ENTRY("scale" , 1), // 17 | 491 | BC_LEX_KW_ENTRY("scale" , 1), // 17 |
496 | BC_LEX_KW_ENTRY("sqrt" , 1), // 18 | 492 | BC_LEX_KW_ENTRY("sqrt" , 1), // 18 |
@@ -499,30 +495,26 @@ static const struct BcLexKeyword bc_lex_kws[20] = { | |||
499 | #undef BC_LEX_KW_ENTRY | 495 | #undef BC_LEX_KW_ENTRY |
500 | enum { | 496 | enum { |
501 | POSIX_KWORD_MASK = 0 | 497 | POSIX_KWORD_MASK = 0 |
502 | | (1 << 0) | 498 | | (1 << 0) // 0 |
503 | | (1 << 1) | 499 | | (1 << 1) // 1 |
504 | | (0 << 2) | 500 | | (0 << 2) // 2 |
505 | | (1 << 3) | 501 | | (1 << 3) // 3 |
506 | \ | 502 | | (0 << 4) // 4 |
507 | | (0 << 4) | 503 | | (1 << 5) // 5 |
508 | | (1 << 5) | 504 | | (0 << 6) // 6 |
509 | | (0 << 6) | 505 | | (1 << 7) // 7 |
510 | | (1 << 7) | 506 | | (1 << 8) // 8 |
511 | \ | 507 | | (0 << 9) // 9 |
512 | | (1 << 8) | 508 | | (1 << 10) // 10 |
513 | | (0 << 9) | 509 | | (0 << 11) // 11 |
514 | | (1 << 10) | 510 | | (1 << 12) // 12 |
515 | | (0 << 11) | 511 | | (0 << 13) // 13 |
516 | \ | 512 | | (1 << 14) // 14 |
517 | | (1 << 12) | 513 | | (0 << 15) // 15 |
518 | | (0 << 13) | 514 | | (1 << 16) // 16 |
519 | | (1 << 14) | 515 | | (1 << 17) // 17 |
520 | | (0 << 15) | 516 | | (1 << 18) // 18 |
521 | \ | 517 | | (1 << 19) // 19 |
522 | | (1 << 16) | ||
523 | | (1 << 17) | ||
524 | | (1 << 18) | ||
525 | | (1 << 19) | ||
526 | }; | 518 | }; |
527 | #define bc_lex_kws_POSIX(i) ((1 << (i)) & POSIX_KWORD_MASK) | 519 | #define bc_lex_kws_POSIX(i) ((1 << (i)) & POSIX_KWORD_MASK) |
528 | #endif | 520 | #endif |
@@ -1027,7 +1019,7 @@ static void quit(void) | |||
1027 | 1019 | ||
1028 | static void bc_verror_msg(const char *fmt, va_list p) | 1020 | static void bc_verror_msg(const char *fmt, va_list p) |
1029 | { | 1021 | { |
1030 | const char *sv = sv; /* for compiler */ | 1022 | const char *sv = sv; // for compiler |
1031 | if (G.prog.file) { | 1023 | if (G.prog.file) { |
1032 | sv = applet_name; | 1024 | sv = applet_name; |
1033 | applet_name = xasprintf("%s: %s:%u", applet_name, G.prog.file, G.err_line); | 1025 | applet_name = xasprintf("%s: %s:%u", applet_name, G.prog.file, G.err_line); |
@@ -2943,7 +2935,6 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
2943 | // is so the parser doesn't get inundated with whitespace. | 2935 | // is so the parser doesn't get inundated with whitespace. |
2944 | s = BC_STATUS_SUCCESS; | 2936 | s = BC_STATUS_SUCCESS; |
2945 | do { | 2937 | do { |
2946 | //TODO: replace pointer with if(IS_BC) | ||
2947 | ERROR_RETURN(s =) zcommon_lex_token(l); | 2938 | ERROR_RETURN(s =) zcommon_lex_token(l); |
2948 | } while (!s && l->t.t == BC_LEX_WHITESPACE); | 2939 | } while (!s && l->t.t == BC_LEX_WHITESPACE); |
2949 | 2940 | ||
@@ -7395,10 +7386,10 @@ static void bc_program_init(void) | |||
7395 | size_t idx; | 7386 | size_t idx; |
7396 | BcInstPtr ip; | 7387 | BcInstPtr ip; |
7397 | 7388 | ||
7398 | /* memset(&G.prog, 0, sizeof(G.prog)); - already is */ | 7389 | // memset(&G.prog, 0, sizeof(G.prog)); - already is |
7399 | memset(&ip, 0, sizeof(BcInstPtr)); | 7390 | memset(&ip, 0, sizeof(BcInstPtr)); |
7400 | 7391 | ||
7401 | /* G.prog.nchars = G.prog.scale = 0; - already is */ | 7392 | // G.prog.nchars = G.prog.scale = 0; - already is |
7402 | bc_num_init_DEF_SIZE(&G.prog.ib); | 7393 | bc_num_init_DEF_SIZE(&G.prog.ib); |
7403 | bc_num_ten(&G.prog.ib); | 7394 | bc_num_ten(&G.prog.ib); |
7404 | G.prog.ib_t = 10; | 7395 | G.prog.ib_t = 10; |
@@ -7527,18 +7518,17 @@ int dc_main(int argc UNUSED_PARAM, char **argv) | |||
7527 | int noscript; | 7518 | int noscript; |
7528 | 7519 | ||
7529 | INIT_G(); | 7520 | INIT_G(); |
7530 | /* | 7521 | |
7531 | * TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width | 7522 | // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width |
7532 | * 1 char wider than bc from the same package. | 7523 | // 1 char wider than bc from the same package. |
7533 | * Both default width, and xC_LINE_LENGTH=N are wider: | 7524 | // Both default width, and xC_LINE_LENGTH=N are wider: |
7534 | * "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: | 7525 | // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: |
7535 | * 1234\ | 7526 | // 1234\ |
7536 | * 56 | 7527 | // 56 |
7537 | * "echo '123456' | BC_LINE_LENGTH=5 bc" prints: | 7528 | // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: |
7538 | * 123\ | 7529 | // 123\ |
7539 | * 456 | 7530 | // 456 |
7540 | * Do the same, or it's a bug? | 7531 | // Do the same, or it's a bug? |
7541 | */ | ||
7542 | bc_vm_init("DC_LINE_LENGTH"); | 7532 | bc_vm_init("DC_LINE_LENGTH"); |
7543 | 7533 | ||
7544 | // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs | 7534 | // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs |