bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] zerofile function


From: Manuel Collado
Subject: Re: [bug-gawk] zerofile function
Date: Thu, 16 May 2013 16:44:56 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0

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 when
trying 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 parameters


Works Ok with GNU Awk 4.0.1 on Windows XP. No syntax errors, gives expected output.

Regards,
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

[Prev in Thread] Current Thread [Next in Thread]