diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-10 06:58:51 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-10 06:58:51 +0200 |
commit | 2eea3494f160da7640813bef1e276f806452148f (patch) | |
tree | 9c16aebcb3cadfb5a13be21595822a6c4c7bb69b | |
parent | 45d471d435a335b172724c53fff41957adb22885 (diff) | |
download | busybox-w32-2eea3494f160da7640813bef1e276f806452148f.tar.gz busybox-w32-2eea3494f160da7640813bef1e276f806452148f.tar.bz2 busybox-w32-2eea3494f160da7640813bef1e276f806452148f.zip |
awk: improve comments and constants, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/editors/awk.c b/editors/awk.c index cf5173938..d4491d3e7 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -307,13 +307,13 @@ static void debug_parse_print_tc(uint32_t n) | |||
307 | | TC_LENGTH) | 307 | | TC_LENGTH) |
308 | #define TS_CONCAT_R (TS_OPERAND | TS_UOPPRE) | 308 | #define TS_CONCAT_R (TS_OPERAND | TS_UOPPRE) |
309 | 309 | ||
310 | #define OF_RES1 0x010000 | 310 | #define OF_RES1 0x010000 /* evaluate(left_node) */ |
311 | #define OF_RES2 0x020000 | 311 | #define OF_RES2 0x020000 /* evaluate(right_node) */ |
312 | #define OF_STR1 0x040000 | 312 | #define OF_STR1 0x040000 /* ...and use its string value */ |
313 | #define OF_STR2 0x080000 | 313 | #define OF_STR2 0x080000 /* ...and use its string value */ |
314 | #define OF_NUM1 0x100000 | 314 | #define OF_NUM1 0x100000 /* ...and use its numeric value */ |
315 | #define OF_CHECKED 0x200000 | 315 | #define OF_REQUIRED 0x200000 /* left_node must not be NULL */ |
316 | #define OF_REQUIRED 0x400000 | 316 | #define OF_CHECKED 0x400000 /* range pattern flip-flop bit */ |
317 | 317 | ||
318 | /* combined operator flags */ | 318 | /* combined operator flags */ |
319 | #define xx 0 | 319 | #define xx 0 |
@@ -331,17 +331,18 @@ static void debug_parse_print_tc(uint32_t n) | |||
331 | #define OPCLSMASK 0xFF00 | 331 | #define OPCLSMASK 0xFF00 |
332 | #define OPNMASK 0x007F | 332 | #define OPNMASK 0x007F |
333 | 333 | ||
334 | /* operator priority is a highest byte (even: r->l, odd: l->r grouping) | 334 | /* operator precedence is the highest byte (even: r->l, odd: l->r grouping) |
335 | * (for builtins it has different meaning) | 335 | * (for builtins the byte has a different meaning) |
336 | */ | 336 | */ |
337 | #undef P | 337 | #undef P |
338 | #undef PRIMASK | 338 | #undef PRIMASK |
339 | #undef PRIMASK2 | 339 | #undef PRIMASK2 |
340 | #define PRIMASK 0x7F000000 | ||
341 | #define PRIMASK2 0x7E000000 | ||
340 | /* Smaller 'x' means _higher_ operator precedence */ | 342 | /* Smaller 'x' means _higher_ operator precedence */ |
341 | #define PRECEDENCE(x) (x << 24) | 343 | #define PRECEDENCE(x) (x << 24) |
342 | #define P(x) PRECEDENCE(x) | 344 | #define P(x) PRECEDENCE(x) |
343 | #define PRIMASK 0x7F000000 | 345 | #define LOWEST_PRECEDENCE PRIMASK |
344 | #define PRIMASK2 0x7E000000 | ||
345 | 346 | ||
346 | /* Operation classes */ | 347 | /* Operation classes */ |
347 | #define SHIFT_TIL_THIS 0x0600 | 348 | #define SHIFT_TIL_THIS 0x0600 |
@@ -1424,7 +1425,7 @@ static node *parse_expr(uint32_t term_tc) | |||
1424 | debug_parse_print_tc(term_tc); | 1425 | debug_parse_print_tc(term_tc); |
1425 | debug_printf_parse("\n"); | 1426 | debug_printf_parse("\n"); |
1426 | 1427 | ||
1427 | sn.info = PRIMASK; | 1428 | sn.info = LOWEST_PRECEDENCE; |
1428 | sn.r.n = sn.a.n = getline_node = NULL; | 1429 | sn.r.n = sn.a.n = getline_node = NULL; |
1429 | expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP | term_tc; | 1430 | expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP | term_tc; |
1430 | 1431 | ||
@@ -1443,7 +1444,7 @@ static node *parse_expr(uint32_t term_tc) | |||
1443 | if (tc & (TS_BINOP | TC_UOPPOST)) { | 1444 | if (tc & (TS_BINOP | TC_UOPPOST)) { |
1444 | debug_printf_parse("%s: TS_BINOP | TC_UOPPOST tc:%x\n", __func__, tc); | 1445 | debug_printf_parse("%s: TS_BINOP | TC_UOPPOST tc:%x\n", __func__, tc); |
1445 | /* for binary and postfix-unary operators, jump back over | 1446 | /* for binary and postfix-unary operators, jump back over |
1446 | * previous operators with higher priority */ | 1447 | * previous operators with higher precedence */ |
1447 | vn = cn; | 1448 | vn = cn; |
1448 | while (((t_info & PRIMASK) > (vn->a.n->info & PRIMASK2)) | 1449 | while (((t_info & PRIMASK) > (vn->a.n->info & PRIMASK2)) |
1449 | || (t_info == vn->info && t_info == TI_COLON) | 1450 | || (t_info == vn->info && t_info == TI_COLON) |
@@ -1451,7 +1452,7 @@ static node *parse_expr(uint32_t term_tc) | |||
1451 | vn = vn->a.n; | 1452 | vn = vn->a.n; |
1452 | if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN); | 1453 | if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN); |
1453 | } | 1454 | } |
1454 | if (t_info == TI_TERNARY) /* "?" operator */ | 1455 | if (t_info == TI_TERNARY) /* "?" token */ |
1455 | //TODO: why? | 1456 | //TODO: why? |
1456 | t_info += PRECEDENCE(6); | 1457 | t_info += PRECEDENCE(6); |
1457 | cn = vn->a.n->r.n = new_node(t_info); | 1458 | cn = vn->a.n->r.n = new_node(t_info); |
@@ -1483,11 +1484,10 @@ static node *parse_expr(uint32_t term_tc) | |||
1483 | } | 1484 | } |
1484 | 1485 | ||
1485 | expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP; | 1486 | expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP; |
1486 | if (t_info == TI_PGETLINE) { | 1487 | if (t_info == TI_PGETLINE) { /* "|" token */ |
1487 | /* it's a pipe token "|" */ | 1488 | next_token(TC_GETLINE); /* must be folowed by "getline" */ |
1488 | next_token(TC_GETLINE); | 1489 | /* give maximum precedence to this pipe */ |
1489 | /* give maximum priority to this pipe */ | 1490 | cn->info &= ~PRIMASK; /* sets PRECEDENCE(0) */ |
1490 | cn->info &= ~PRIMASK; | ||
1491 | expected_tc = TS_OPERAND | TS_UOPPRE | TS_BINOP | term_tc; | 1491 | expected_tc = TS_OPERAND | TS_UOPPRE | TS_BINOP | term_tc; |
1492 | } | 1492 | } |
1493 | } else { | 1493 | } else { |
@@ -1498,7 +1498,7 @@ static node *parse_expr(uint32_t term_tc) | |||
1498 | vn->a.n = cn; | 1498 | vn->a.n = cn; |
1499 | continue; | 1499 | continue; |
1500 | } | 1500 | } |
1501 | /* It wasn't a binary or unary_postfix operator */ | 1501 | /* It wasn't a binary or postfix-unary operator */ |
1502 | 1502 | ||
1503 | debug_printf_parse("%s: other, t_info:%x\n", __func__, t_info); | 1503 | debug_printf_parse("%s: other, t_info:%x\n", __func__, t_info); |
1504 | /* for operands and prefix-unary operators, attach them | 1504 | /* for operands and prefix-unary operators, attach them |
@@ -1572,6 +1572,13 @@ static node *parse_expr(uint32_t term_tc) | |||
1572 | break; | 1572 | break; |
1573 | 1573 | ||
1574 | case TC_GETLINE: | 1574 | case TC_GETLINE: |
1575 | /* "getline" is a function, not a statement. | ||
1576 | * Works in gawk: | ||
1577 | * r = ["SHELL CMD" | ] getline [VAR] [<"FILE"] | ||
1578 | * if (getline <"FILE" < 0) print "Can't read FILE" | ||
1579 | * while ("SHELL CMD" | getline > 0) ... | ||
1580 | * Returns: 1 successful read, 0 EOF, -1 error (sets ERRNO) | ||
1581 | */ | ||
1575 | debug_printf_parse("%s: TC_GETLINE\n", __func__); | 1582 | debug_printf_parse("%s: TC_GETLINE\n", __func__); |
1576 | getline_node = cn; | 1583 | getline_node = cn; |
1577 | expected_tc = TS_OPERAND | TS_UOPPRE | TS_BINOP | term_tc; | 1584 | expected_tc = TS_OPERAND | TS_UOPPRE | TS_BINOP | term_tc; |