diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-06 12:59:40 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-06 12:59:40 +0100 |
| commit | d00d2f9603d027c30ce21ed42a951bb650a264e9 (patch) | |
| tree | d85b8b7bef44ecf297670b5c07e3b76074cf54cf | |
| parent | b6f60863cb9e0b3af3c694c282489e458822002f (diff) | |
| download | busybox-w32-d00d2f9603d027c30ce21ed42a951bb650a264e9.tar.gz busybox-w32-d00d2f9603d027c30ce21ed42a951bb650a264e9.tar.bz2 busybox-w32-d00d2f9603d027c30ce21ed42a951bb650a264e9.zip | |
bc: make keyword POSIXness check more readable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | miscutils/bc.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 6cc9fe2f7..f936ad6f3 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -508,34 +508,35 @@ typedef enum BcLexType { | |||
| 508 | struct BcLexKeyword { | 508 | struct BcLexKeyword { |
| 509 | char name8[8]; | 509 | char name8[8]; |
| 510 | }; | 510 | }; |
| 511 | #define BC_LEX_KW_ENTRY(a, b, c) \ | 511 | #define BC_LEX_KW_ENTRY(a, b) \ |
| 512 | { .name8 = a /*, .len = b, .posix = c*/ } | 512 | { .name8 = a /*, .posix = b */ } |
| 513 | static const struct BcLexKeyword bc_lex_kws[20] = { | 513 | static const struct BcLexKeyword bc_lex_kws[20] = { |
| 514 | BC_LEX_KW_ENTRY("auto" , 4, 1), // 0 | 514 | BC_LEX_KW_ENTRY("auto" , 1), // 0 |
| 515 | BC_LEX_KW_ENTRY("break" , 5, 1), // 1 | 515 | BC_LEX_KW_ENTRY("break" , 1), // 1 |
| 516 | BC_LEX_KW_ENTRY("continue", 8, 0), // 2 note: this one has no terminating NUL | 516 | BC_LEX_KW_ENTRY("continue", 0), // 2 note: this one has no terminating NUL |
| 517 | BC_LEX_KW_ENTRY("define" , 6, 1), // 3 | 517 | BC_LEX_KW_ENTRY("define" , 1), // 3 |
| 518 | 518 | ||
| 519 | BC_LEX_KW_ENTRY("else" , 4, 0), // 4 | 519 | BC_LEX_KW_ENTRY("else" , 0), // 4 |
| 520 | BC_LEX_KW_ENTRY("for" , 3, 1), // 5 | 520 | BC_LEX_KW_ENTRY("for" , 1), // 5 |
| 521 | BC_LEX_KW_ENTRY("halt" , 4, 0), // 6 | 521 | BC_LEX_KW_ENTRY("halt" , 0), // 6 |
| 522 | BC_LEX_KW_ENTRY("ibase" , 5, 1), // 7 | 522 | BC_LEX_KW_ENTRY("ibase" , 1), // 7 |
| 523 | 523 | ||
| 524 | BC_LEX_KW_ENTRY("if" , 2, 1), // 8 | 524 | BC_LEX_KW_ENTRY("if" , 1), // 8 |
| 525 | BC_LEX_KW_ENTRY("last" , 4, 0), // 9 | 525 | BC_LEX_KW_ENTRY("last" , 0), // 9 |
| 526 | BC_LEX_KW_ENTRY("length" , 6, 1), // 10 | 526 | BC_LEX_KW_ENTRY("length" , 1), // 10 |
| 527 | BC_LEX_KW_ENTRY("limits" , 6, 0), // 11 | 527 | BC_LEX_KW_ENTRY("limits" , 0), // 11 |
| 528 | 528 | ||
| 529 | BC_LEX_KW_ENTRY("obase" , 5, 1), // 12 | 529 | BC_LEX_KW_ENTRY("obase" , 1), // 12 |
| 530 | BC_LEX_KW_ENTRY("print" , 5, 0), // 13 | 530 | BC_LEX_KW_ENTRY("print" , 0), // 13 |
| 531 | BC_LEX_KW_ENTRY("quit" , 4, 1), // 14 | 531 | BC_LEX_KW_ENTRY("quit" , 1), // 14 |
| 532 | BC_LEX_KW_ENTRY("read" , 4, 0), // 15 | 532 | BC_LEX_KW_ENTRY("read" , 0), // 15 |
| 533 | 533 | ||
| 534 | BC_LEX_KW_ENTRY("return" , 6, 1), // 16 | 534 | BC_LEX_KW_ENTRY("return" , 1), // 16 |
| 535 | BC_LEX_KW_ENTRY("scale" , 5, 1), // 17 | 535 | BC_LEX_KW_ENTRY("scale" , 1), // 17 |
| 536 | BC_LEX_KW_ENTRY("sqrt" , 4, 1), // 18 | 536 | BC_LEX_KW_ENTRY("sqrt" , 1), // 18 |
| 537 | BC_LEX_KW_ENTRY("while" , 5, 1), // 19 | 537 | BC_LEX_KW_ENTRY("while" , 1), // 19 |
| 538 | }; | 538 | }; |
| 539 | #undef BC_LEX_KW_ENTRY | ||
| 539 | enum { | 540 | enum { |
| 540 | POSIX_KWORD_MASK = 0 | 541 | POSIX_KWORD_MASK = 0 |
| 541 | | (1 << 0) | 542 | | (1 << 0) |
| @@ -563,6 +564,7 @@ enum { | |||
| 563 | | (1 << 18) | 564 | | (1 << 18) |
| 564 | | (1 << 19) | 565 | | (1 << 19) |
| 565 | }; | 566 | }; |
| 567 | #define bc_lex_kws_POSIX(i) ((1 << (i)) & POSIX_KWORD_MASK) | ||
| 566 | #endif | 568 | #endif |
| 567 | 569 | ||
| 568 | struct BcLex; | 570 | struct BcLex; |
| @@ -2982,7 +2984,7 @@ static BcStatus bc_lex_identifier(BcLex *l) | |||
| 2982 | match: | 2984 | match: |
| 2983 | // buf starts with keyword bc_lex_kws[i] | 2985 | // buf starts with keyword bc_lex_kws[i] |
| 2984 | l->t.t = BC_LEX_KEY_1st_keyword + i; | 2986 | l->t.t = BC_LEX_KEY_1st_keyword + i; |
| 2985 | if (!((1 << i) & POSIX_KWORD_MASK)) { | 2987 | if (!bc_lex_kws_POSIX(i)) { |
| 2986 | s = bc_posix_error_fmt("%sthe '%.8s' keyword", "POSIX does not allow ", bc_lex_kws[i].name8); | 2988 | s = bc_posix_error_fmt("%sthe '%.8s' keyword", "POSIX does not allow ", bc_lex_kws[i].name8); |
| 2987 | if (s) return s; | 2989 | if (s) return s; |
| 2988 | } | 2990 | } |
