aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-05-27 19:11:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-05-27 19:11:28 +0200
commit21dce1c3c3d74a60959b6d8b0c76f38d463b8187 (patch)
tree4b43283e7110c2d18646e1c4586f83fc8106a74c
parent5c8a9dfd976493e4351abadf6686b621763b564c (diff)
downloadbusybox-w32-21dce1c3c3d74a60959b6d8b0c76f38d463b8187.tar.gz
busybox-w32-21dce1c3c3d74a60959b6d8b0c76f38d463b8187.tar.bz2
busybox-w32-21dce1c3c3d74a60959b6d8b0c76f38d463b8187.zip
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>
-rw-r--r--editors/awk.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 4a0eb9281..77e0b0aab 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -583,6 +583,7 @@ struct globals2 {
583 /* former statics from various functions */ 583 /* former statics from various functions */
584 char *split_f0__fstrings; 584 char *split_f0__fstrings;
585 585
586 unsigned next_input_file__argind;
586 smallint next_input_file__input_file_seen; 587 smallint next_input_file__input_file_seen;
587 588
588 smalluint exitcode; 589 smalluint exitcode;
@@ -2820,6 +2821,7 @@ static int try_to_assign(const char *expr)
2820static int next_input_file(void) 2821static int next_input_file(void)
2821{ 2822{
2822#define input_file_seen (G.next_input_file__input_file_seen) 2823#define input_file_seen (G.next_input_file__input_file_seen)
2824#define argind (G.next_input_file__argind)
2823 const char *fname; 2825 const char *fname;
2824 2826
2825 if (iF.F) { 2827 if (iF.F) {
@@ -2829,17 +2831,22 @@ static int next_input_file(void)
2829 } 2831 }
2830 2832
2831 for (;;) { 2833 for (;;) {
2832 const char *ind; 2834 /* GNU Awk 5.1.1 does not _read_ ARGIND (but does read ARGC).
2833 2835 * It only sets ARGIND to 1, 2, 3... for every command-line filename
2834 if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { 2836 * (VAR=VAL params cause a gap in numbering).
2837 * If there are none and stdin is used, then ARGIND is not modified:
2838 * if it is set by e.g. 'BEGIN { ARGIND="foo" }', that value will
2839 * still be there.
2840 */
2841 argind++;
2842 if (argind >= getvar_i(intvar[ARGC])) {
2835 if (input_file_seen) 2843 if (input_file_seen)
2836 return FALSE; 2844 return FALSE;
2837 fname = "-"; 2845 fname = "-";
2838 iF.F = stdin; 2846 iF.F = stdin;
2839 break; 2847 break;
2840 } 2848 }
2841 ind = getvar_s(incvar(intvar[ARGIND])); 2849 fname = getvar_s(findvar(iamarray(intvar[ARGV]), utoa(argind)));
2842 fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind));
2843 if (fname && *fname) { 2850 if (fname && *fname) {
2844 /* "If a filename on the command line has the form 2851 /* "If a filename on the command line has the form
2845 * var=val it is treated as a variable assignment" 2852 * var=val it is treated as a variable assignment"
@@ -2847,6 +2854,7 @@ static int next_input_file(void)
2847 if (try_to_assign(fname)) 2854 if (try_to_assign(fname))
2848 continue; 2855 continue;
2849 iF.F = xfopen_stdin(fname); 2856 iF.F = xfopen_stdin(fname);
2857 setvar_i(intvar[ARGIND], argind);
2850 break; 2858 break;
2851 } 2859 }
2852 } 2860 }
@@ -2854,6 +2862,7 @@ static int next_input_file(void)
2854 setvar_s(intvar[FILENAME], fname); 2862 setvar_s(intvar[FILENAME], fname);
2855 input_file_seen = TRUE; 2863 input_file_seen = TRUE;
2856 return TRUE; 2864 return TRUE;
2865#undef argind
2857#undef input_file_seen 2866#undef input_file_seen
2858} 2867}
2859 2868