|
From: | Manuel Collado |
Subject: | Re: [bug-gawk] zerofile function |
Date: | Fri, 17 May 2013 10:37:56 +0200 |
User-agent: | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
First af all, some advice: - Please don't top-post.- Please respond to the bug-gawk list instead of or in addition to my personal e-mail address.
- Please post just plain text and not HTML.- Please quote the relevant parts of the original message, and not the whole stuff.
(Disclaimer: I'm quoting the full thread so others can see the whole stuff you sent just to my personal address)
Short answer: Your original code (at the end of this long post) is correct. Don't spoil it.
And now, look below to see my responses to some specific parts of your messages.
El 16/05/2013 23:32, david ward escribió:
Sorry to exhaust you with my mistakes but correcting all references TO ARGV to ARGC I still get the same errors. My main programming language is C++ hence the mistake. I have manage to find some errors in the functions presented in the manual so please don't dismiss me too lightly
Don't worry. We are always willing to help interested people.But, your original code is correct, so don't try to amend it. Doing so just makes things worse.
On Thu, May 16, 2013 at 10:09 PM, david ward <address@hidden> wrote:/gawk/awkscripts-> gawk -f ./zerofile.awk -f ./zerofile_funct.awk -f ./checkzero.awk ./tee2 ./empty ./tee3 ./empty2 gawk: ./zerofile.awk:18: zerofile(ARGC[Argind], Argind) # get syntax error for ARGV[Argind] gawk: ./zerofile.awk:18: ^ use of non-array as array gawk: ./zerofile_funct.awk:2: function zerofile(ARGC[Argind], Argind ) gawk: ./zerofile_funct.awk:2: ^ syntax error gawk: ./zerofile_funct.awk:2: error: function `zerofile': can't use special variable `ARGC' as a function parameter ~/gawk/awkscripts->
ARGC is a scalar variable (the number or arguments), ARGV is the array of arguments. So ARGV[x]is correct, but ARGC[x] doesn't makes sense.
In addition, ARGC is a special variable, so you can't use this name for a formal argument of a function.
On Thu, May 16, 2013 at 10:06 PM, david ward <address@hidden> wrote:Noticed that I did not make changes to the files correctly. Making these corrections does not alter the error message:
As said, making such corrections makes the things worse.
#!/usr/bin/gawk -f # All known awk implementations silently skip over zero-length files. This is a by-product of awk's implicit # read-a-record-and-match-against-the-rules loop: # when awk tries to read a record from an empty file, it immediately receives an end of file # indication, closes the file, and proceeds on to the next command-line data file, WITHOUT executing any # user-level awk program code. # Using gawk's ARGIND variable , it is possible to detect when an empty data file # has been skipped. # zerofile.awk --- library file to process empty input files BEGIN { Argind = 0 } ARGIND > Argind + 1 { for (Argind++; Argind < ARGIND; Argind++) zerofile(ARGC[Argind], Argind) # get syntax error for ARGV[Argind] } ARGIND != Argind { Argind = ARGIND } END { d = ARGV[Argind] if (ARGIND > Argind) for (Argind++; Argind <= ARGIND; Argind++) zerofile(ARG[Argind], Argind) } #!/usr/bin/gawk -f function zerofile(ARGC[Argind], Argind ) { print ARGIND,Argind, ARGV[Argind] } #!/usr/bin/gawk -f {print} On Thu, May 16, 2013 at 9:52 PM, david ward <address@hidden> wrote:Doesn't work with gawk 4.0.2 on Ubuntu 12.04 removing the assignment to v in the source code I get
See the previous comment
1037 16/05/13 21:45:45 history ~/gawk/awkscripts-> gawk -f ./zerofile.awk -f ./zerofile_funct.awk -f ./checkzero.awk ./tee2 ./empty ./tee3 ./empty2 gawk: ./zerofile_funct.awk:2: function zerofile(ARGC{Argind], Argind ) gawk: ./zerofile_funct.awk:2: ^ syntax error gawk: ./zerofile_funct.awk:2: error: function `zerofile': can't use special variable `ARGC' as a function parameter ~/gawk/awkscripts-> #!/usr/bin/gawk -f # All known awk implementations silently skip over zero-length files. This is a by-product of awk's implicit # read-a-record-and-match-against-the-rules loop: # when awk tries to read a record from an empty file, it immediately receives an end of file # indication, closes the file, and proceeds on to the next command-line data file, WITHOUT executing any # user-level awk program code. # Using gawk's ARGIND variable , it is possible to detect when an empty data file # has been skipped. # zerofile.awk --- library file to process empty input files BEGIN { Argind = 0 } ARGIND > Argind + 1 { # v = ARGV[Argind] for (Argind++; Argind < ARGIND; Argind++) zerofile(a, Argind) # get syntax error for ARGV[Argind] submitted bug report apparently works ok in # in 4.0.1 on windows XP } ARGIND != Argind { Argind = ARGIND } END { d = ARGV[Argind] if (ARGIND > Argind) for (Argind++; Argind <= ARGIND; Argind++) zerofile(d, Argind) } #!/usr/bin/gawk -f function zerofile(ARGC{Argind], Argind ) { print ARGIND,Argind, ARGV[Argind] } On Thu, May 16, 2013 at 3:42 PM, Manuel Collado <address@hidden>wrote:El 16/05/2013 14:23, david ward escribió: I don't know if this a bug or not but I get a syntax error when whentrying to pass ARGC[Argind] to zerofile. gawk version: 4.0.2 OS: Ubuntu 12.4 #!/usr/bin/gawk -f # All known awk implementations silently skip over zero-length files. This is a by-product of awk's implicit # read-a-record-and-match-**against-the-rules loop: # when awk tries to read a record from an empty file, it immediately receives an end of file # indication, closes the file, and proceeds on to the next command-line data file, WITHOUT executing any # user-level awk program code. # Using gawk's ARGIND variable , it is possible to detect when an empty data file # has been skipped. # zerofile.awk --- library file to process empty input files BEGIN { Argind = 0 } ARGIND > Argind + 1 { v = ARGV[Argind] for (Argind++; Argind < ARGIND; Argind++) zerofile(a, Argind) # get syntax error for ARGV[Argind] } ARGIND != Argind { Argind = ARGIND } END { d = ARGV[Argind] if (ARGIND > Argind) for (Argind++; Argind <= ARGIND; Argind++) zerofile(d, Argind) } my zerofile function #!/usr/bin/gawk -f function zerofile(a, Argind ) { print ARGIND,Argind, ARGV[Argind] } I wrote this to understand how the post increment operator took effect on the parametersWorks Ok with GNU Awk 4.0.1 on Windows XP. No syntax errors, gives expected output.
Tested also with GAWK 4.0.2. Same (good) results. Regards. -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
[Prev in Thread] | Current Thread | [Next in Thread] |