diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-02-13 21:51:50 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-02-13 21:51:50 +0200 |
commit | 4c82793760b88c55ca18cdbdfb819c3ea98cfa91 (patch) | |
tree | 6275eb83725f0fe7b0fd802365f20d662936975c | |
parent | bda8b5661127de0c16343fdfb8e4060803503d72 (diff) | |
download | egawk-4c82793760b88c55ca18cdbdfb819c3ea98cfa91.tar.gz egawk-4c82793760b88c55ca18cdbdfb819c3ea98cfa91.tar.bz2 egawk-4c82793760b88c55ca18cdbdfb819c3ea98cfa91.zip |
Fix assigning to ARGC on command line and add test.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | io.c | 5 | ||||
-rw-r--r-- | pc/ChangeLog | 4 | ||||
-rw-r--r-- | pc/Makefile.tst | 7 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 10 | ||||
-rw-r--r-- | test/Makefile.in | 10 | ||||
-rw-r--r-- | test/argcasfile.awk | 1 | ||||
-rw-r--r-- | test/argcasfile.in | 3 | ||||
-rw-r--r-- | test/argcasfile.ok | 9 |
10 files changed, 54 insertions, 7 deletions
@@ -1,3 +1,10 @@ +2021-02-13 Arnold D. Robbins <arnold@skeeve.com> + + * io.c (nextfile): Use the value of ARGC directly in the for + loop, in case it gets changed by code or by a command line + assignment. Thanks to the discussion in comp.lang.awk for + the report. + 2021-01-28 Arnold D. Robbins <arnold@skeeve.com> Fix a Day One Bug! @@ -447,7 +447,6 @@ nextfile(IOBUF **curfile, bool skipping) int fd = INVALID_HANDLE; int errcode = 0; IOBUF *iop = *curfile; - long argc; if (skipping) { /* for 'nextfile' call */ errcode = 0; @@ -469,9 +468,7 @@ nextfile(IOBUF **curfile, bool skipping) return 0; } - argc = get_number_si(ARGC_node->var_value); - - for (; i < argc; i++) { + for (; i < get_number_si(ARGC_node->var_value); i++) { tmp = make_number((AWKNUM) i); (void) force_string(tmp); arg = in_array(ARGV_node, tmp); diff --git a/pc/ChangeLog b/pc/ChangeLog index bdf1149c..399dcc90 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2021-02-13 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.tst: Rebuilt. + 2021-01-09 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Rebuilt. diff --git a/pc/Makefile.tst b/pc/Makefile.tst index 24e92863..573981fc 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -141,7 +141,7 @@ CLEANFILES = core core.* fmtspcl.ok # try to keep these sorted. each letter starts a new line BASIC_TESTS = \ - addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \ + addcomma anchgsub anchor argarray argcasfile arrayind1 arrayind2 arrayind3 arrayparm \ arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \ arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \ @@ -1241,6 +1241,11 @@ iolint: @$(AWK) -f "$(srcdir)"/$@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ @-$(RM) -f cat 'echo hello' 'exec cat' f1 f2 md5sum + +argcasfile: + @echo $@ + @$(AWK) -f "$(srcdir)"/$@.awk ARGC=1 /no/such/file < "$(srcdir)/$@.in" >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: diff --git a/test/ChangeLog b/test/ChangeLog index 9cd3edb3..53fe5627 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2021-02-13 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): argcasfile, new test. + * argcasfile.awk, argcasfile.in, argcasfile.ok: New files. + 2021-01-09 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): octdec, new test. diff --git a/test/Makefile.am b/test/Makefile.am index ce28345f..bdb8831f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -56,6 +56,9 @@ EXTRA_DIST = \ argarray.awk \ argarray.in \ argarray.ok \ + argcasfile.awk \ + argcasfile.in \ + argcasfile.ok \ argtest.awk \ argtest.ok \ arrayind1.awk \ @@ -1378,7 +1381,7 @@ CLEANFILES = core core.* fmtspcl.ok # try to keep these sorted. each letter starts a new line BASIC_TESTS = \ - addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \ + addcomma anchgsub anchor argarray argcasfile arrayind1 arrayind2 arrayind3 arrayparm \ arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \ arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \ @@ -2479,6 +2482,11 @@ iolint: @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ @-$(RM) -f cat 'echo hello' 'exec cat' f1 f2 md5sum +argcasfile: + @echo $@ + @$(AWK) -f "$(srcdir)"/$@.awk ARGC=1 /no/such/file < "$(srcdir)/$@.in" >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + # Targets generated for other tests: include Maketests diff --git a/test/Makefile.in b/test/Makefile.in index 337a48fc..92ef9d06 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -319,6 +319,9 @@ EXTRA_DIST = \ argarray.awk \ argarray.in \ argarray.ok \ + argcasfile.awk \ + argcasfile.in \ + argcasfile.ok \ argtest.awk \ argtest.ok \ arrayind1.awk \ @@ -1641,7 +1644,7 @@ CLEANFILES = core core.* fmtspcl.ok # try to keep these sorted. each letter starts a new line BASIC_TESTS = \ - addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \ + addcomma anchgsub anchor argarray argcasfile arrayind1 arrayind2 arrayind3 arrayparm \ arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \ arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \ @@ -2925,6 +2928,11 @@ iolint: @$(AWK) -f "$(srcdir)"/$@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ @-$(RM) -f cat 'echo hello' 'exec cat' f1 f2 md5sum + +argcasfile: + @echo $@ + @$(AWK) -f "$(srcdir)"/$@.awk ARGC=1 /no/such/file < "$(srcdir)/$@.in" >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: diff --git a/test/argcasfile.awk b/test/argcasfile.awk new file mode 100644 index 00000000..489f25ca --- /dev/null +++ b/test/argcasfile.awk @@ -0,0 +1 @@ +{ for (i in ARGV) print i,ARGV[i] } diff --git a/test/argcasfile.in b/test/argcasfile.in new file mode 100644 index 00000000..86e041da --- /dev/null +++ b/test/argcasfile.in @@ -0,0 +1,3 @@ +foo +bar +baz diff --git a/test/argcasfile.ok b/test/argcasfile.ok new file mode 100644 index 00000000..8b5d35b3 --- /dev/null +++ b/test/argcasfile.ok @@ -0,0 +1,9 @@ +0 gawk +1 ARGC=1 +2 /no/such/file +0 gawk +1 ARGC=1 +2 /no/such/file +0 gawk +1 ARGC=1 +2 /no/such/file |