diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-29 02:32:32 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-29 02:37:10 +0200 |
commit | 926420795b4191e045d4a316bfed19f84275a185 (patch) | |
tree | 55fbafe0bb67d9e2635d8ac6ec63642b227a889d | |
parent | 9782cb7774f00a3e777e3d764ccce15055a29977 (diff) | |
download | busybox-w32-926420795b4191e045d4a316bfed19f84275a185.tar.gz busybox-w32-926420795b4191e045d4a316bfed19f84275a185.tar.bz2 busybox-w32-926420795b4191e045d4a316bfed19f84275a185.zip |
awk: simplify parsing of function declaration
function old new delta
parse_program 328 313 -15
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/editors/awk.c b/editors/awk.c index d31b97d86..08ff02adb 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -769,7 +769,7 @@ static void hash_remove(xhash *hash, const char *name) | |||
769 | 769 | ||
770 | static char *skip_spaces(char *p) | 770 | static char *skip_spaces(char *p) |
771 | { | 771 | { |
772 | while (1) { | 772 | for (;;) { |
773 | if (*p == '\\' && p[1] == '\n') { | 773 | if (*p == '\\' && p[1] == '\n') { |
774 | p++; | 774 | p++; |
775 | t_lineno++; | 775 | t_lineno++; |
@@ -1685,26 +1685,20 @@ static void parse_program(char *p) | |||
1685 | f = newfunc(t_string); | 1685 | f = newfunc(t_string); |
1686 | f->body.first = NULL; | 1686 | f->body.first = NULL; |
1687 | f->nargs = 0; | 1687 | f->nargs = 0; |
1688 | /* Match func arg list: a comma sep list of >= 0 args, and a close paren */ | 1688 | /* func arg list: comma sep list of args, and a close paren */ |
1689 | while (next_token(TC_VARIABLE | TC_RPAREN | TC_COMMA)) { | 1689 | for (;;) { |
1690 | /* Either an empty arg list, or trailing comma from prev iter | 1690 | if (next_token(TC_VARIABLE | TC_RPAREN) == TC_RPAREN) { |
1691 | * must be followed by an arg */ | 1691 | if (f->nargs == 0) |
1692 | if (f->nargs == 0 && t_tclass == TC_RPAREN) | 1692 | break; /* func() is ok */ |
1693 | break; | 1693 | /* func(a,) is not ok */ |
1694 | |||
1695 | /* TC_LPAREN/TC_COMMA must be followed by TC_VARIABLE */ | ||
1696 | if (t_tclass != TC_VARIABLE) | ||
1697 | syntax_error(EMSG_UNEXP_TOKEN); | 1694 | syntax_error(EMSG_UNEXP_TOKEN); |
1698 | 1695 | } | |
1699 | v = findvar(ahash, t_string); | 1696 | v = findvar(ahash, t_string); |
1700 | v->x.aidx = f->nargs++; | 1697 | v->x.aidx = f->nargs++; |
1701 | |||
1702 | /* Arg followed either by end of arg list or 1 comma */ | 1698 | /* Arg followed either by end of arg list or 1 comma */ |
1703 | if (next_token(TC_COMMA | TC_RPAREN) & TC_RPAREN) | 1699 | if (next_token(TC_COMMA | TC_RPAREN) == TC_RPAREN) |
1704 | break; | 1700 | break; |
1705 | //Impossible: next_token() above would error out and die | 1701 | /* it was a comma, we ate it */ |
1706 | // if (t_tclass != TC_COMMA) | ||
1707 | // syntax_error(EMSG_UNEXP_TOKEN); | ||
1708 | } | 1702 | } |
1709 | seq = &f->body; | 1703 | seq = &f->body; |
1710 | chain_group(); | 1704 | chain_group(); |