diff options
author | Denys Vlasenko | 2023-05-27 19:11:28 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-05-27 19:11:28 +0200 |
commit | 21dce1c3c3d74a60959b6d8b0c76f38d463b8187 (patch) | |
tree | 4b43283e7110c2d18646e1c4586f83fc8106a74c /editors | |
parent | 5c8a9dfd976493e4351abadf6686b621763b564c (diff) | |
download | busybox-21dce1c3c3d74a60959b6d8b0c76f38d463b8187.zip busybox-21dce1c3c3d74a60959b6d8b0c76f38d463b8187.tar.gz |
awk: do not read ARGIND, only set it (gawk compat)
function old new delta
next_input_file 216 243 +27
evaluate 3396 3402 +6
awk_main 826 829 +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0) Total: 36 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/editors/awk.c b/editors/awk.c index 4a0eb92..77e0b0a 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -583,6 +583,7 @@ struct globals2 { /* former statics from various functions */ char *split_f0__fstrings; + unsigned next_input_file__argind; smallint next_input_file__input_file_seen; smalluint exitcode; @@ -2820,6 +2821,7 @@ static int try_to_assign(const char *expr) static int next_input_file(void) { #define input_file_seen (G.next_input_file__input_file_seen) +#define argind (G.next_input_file__argind) const char *fname; if (iF.F) { @@ -2829,17 +2831,22 @@ static int next_input_file(void) } for (;;) { - const char *ind; - - if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { + /* GNU Awk 5.1.1 does not _read_ ARGIND (but does read ARGC). + * It only sets ARGIND to 1, 2, 3... for every command-line filename + * (VAR=VAL params cause a gap in numbering). + * If there are none and stdin is used, then ARGIND is not modified: + * if it is set by e.g. 'BEGIN { ARGIND="foo" }', that value will + * still be there. + */ + argind++; + if (argind >= getvar_i(intvar[ARGC])) { if (input_file_seen) return FALSE; fname = "-"; iF.F = stdin; break; } - ind = getvar_s(incvar(intvar[ARGIND])); - fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); + fname = getvar_s(findvar(iamarray(intvar[ARGV]), utoa(argind))); if (fname && *fname) { /* "If a filename on the command line has the form * var=val it is treated as a variable assignment" @@ -2847,6 +2854,7 @@ static int next_input_file(void) if (try_to_assign(fname)) continue; iF.F = xfopen_stdin(fname); + setvar_i(intvar[ARGIND], argind); break; } } @@ -2854,6 +2862,7 @@ static int next_input_file(void) setvar_s(intvar[FILENAME], fname); input_file_seen = TRUE; return TRUE; +#undef argind #undef input_file_seen } |