bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Fwd: why does referencing NF or different fields change $


From: Nethox
Subject: Re: [bug-gawk] Fwd: why does referencing NF or different fields change $0 after recompilation?
Date: Fri, 18 Sep 2015 15:44:44 +0200

(Somehow, the Gmail webUI did not update my opened thread with your reply in 20 minutes...)

The patch seems to work. All the tests pass (Ed's and mine) against the tarball version:
GNU Awk 4.1.3, API: 1.1
$ make check => ALL TESTS PASSED (MPFR tests not supported on this system)

In case you want to include my tests...
Copy and paste from 1 to 3 included (previous email), because those passed even with the bug.
And here are the 4th and 5th correct results after patching (take care with whitespace):
—————start—————
# $0 is evaluated after $1 and NF.
$ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{ $1=$1; print NF "    " $0 "    |" $2 "|" }' file
3    "A";"B";"C"    |"B"|
# $0 is evaluated after $1 but before NF.
$ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{ $1=$1; print $0 "    " NF "    |" $2 "|" }' file
"A";"B";"C"    3    |"B"|
—————end—————

Thanks and regards.


On Fri, Sep 18, 2015 at 1:47 PM, Aharon Robbins <address@hidden> wrote:
Hi.

Re this:

> To: address@hidden
> From: Ed Morton <address@hidden>
> Date: Thu, 17 Sep 2015 08:04:10 -0500
> Subject: [bug-gawk] Fwd: why does referencing NF or different fields change
>  $0 after recompilation?
>
> I got a couple of responses to my question below on comp.lang.awk and I'm now
> pretty confident it's a bug and not my misunderstanding of something.
>
> Josef Frank pointed out that:
>
> > Reminds me of a bug (in gawk 4.0.0) mentioned at the top of:
> > http://git.savannah.gnu.org/cgit/gawk.git/tree/test/pty1.awk
>
> Can you take a look?
>
>       Ed.
>
> -------- Forwarded Message --------
> Subject: why does referencing NF or different fields change $0 after recompilation?
> Date: Wed, 16 Sep 2015 22:15:05 -0500
> From: Ed Morton <address@hidden>
> Organization: A noiseless patient Spider
> Newsgroups: comp.lang.awk
>
> This GNU awk script is intended to replace commas with semi-colons in a CSV file
> that could contain commas in the quoted fields and could have blank fields:
>
> $ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{$1=$1}1' file
>
> Can anyone explain why the first call to awk below replaces the first comma with
> two semi-colons while the second and third (which are only different from the
> first in that they mentions NF somewhere in the action block) replace it with
> one, which is the desired result?
>
> $ cat file
> "A","B","C"
>
> $ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{$1=$1}1' file
> "A";;"B";"C"

The following patch does the trick.  I will push it, and add this
to the test suite, shortly.

Thanks,

Arnold
--------------------------------------------------
diff --git a/field.c b/field.c
index 6a7c6b1..ed31098 100644
--- a/field.c
+++ b/field.c
@@ -1598,9 +1598,8 @@ fpat_parse_field(long up_to,      /* parse only up to this field number */

        if (in_middle) {
                regex_flags |= RE_NO_BOL;
-               non_empty = rp->non_empty;
-       } else
-               non_empty = false;
+       }
+       non_empty = rp->non_empty;

        eosflag = false;
        need_to_set_sep = true;



reply via email to

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