bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] parsing column title header records


From: Assaf Gordon
Subject: Re: [bug-gawk] parsing column title header records
Date: Mon, 17 Dec 2012 18:59:50 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Andrew J. Schorr wrote, On 12/17/2012 05:44 PM:
> On Mon, Dec 17, 2012 at 05:16:57PM -0500, Assaf Gordon wrote:
>> That's exactly what I'm working on now (which is how I discovered an 
>> extension can't access "NF" and "NR" if they are not defined in the AWK 
>> source.
>>
>> Combining an AWK include and a C extension is a nice idea. Will keep you 
>> posted on progress.
>>
> 
> Hmmmm, I tried it myself, and it's strangely not working (using the gawkextlib
> "common.h" header file for some defines and adding an optional 3rd argument
> to specify if the variable should be constant).  The source code is attached.
>

I see the same with my extension (which is very similar to yours).

Arnold is likely getting tired of explaining again and again: :)
Variables created dynamically through SYMTAB can't be used as regular "global" 
AWK variables.
When created dynamically, SYMTAB behaves like an associated array, and using an 
extension doesn't bypass this limitation.


But to complicate matters, this seems to introduce one more inconsistency:

1. Using SYMTAB without referencing the variable, does not create a "global" 
instance:
    $ gawk -d/dev/stdout 'BEGIN{SYMTAB["hello"]="world" }' | grep hello
    # (no output, "hello" doesn't exist)
This is fine, and tested in test/symtab6.awk.

2. Using SYMTAB with referencing the variable, works OK:
    $ ./gawk -d/dev/stdout 'BEGIN{SYMTAB["hello"]="world" ; print hello }' | 
grep hello
    hello: "world"
This is fine, and tested in test/symtab5.awk

But,

3. Creating a variable with an extension without referencing it, does seem to 
create a "global" variable:
    $ gawk -d/dev/stdout -l extension/.libs/header.so 
'BEGIN{create_variable("hello","world")}' | grep hello
    hello: "world"
(My extension code is attached below).
Whether this is OK or NOT, depends on your POV.

4. Creating a variable with an extension *with* referencing it, makes a mess:
    $ gawk -d/dev/stdout -l extension/.libs/header.so 
'BEGIN{create_variable("hello","world") ; print hello}' | grep hello
    hello: uninitialized scalar
This is likely not OK.

5. For comparison, reading the variable through the extension works fine:
    $ gawk -d/dev/stdout -l extension/.libs/header.so 
'BEGIN{create_variable("hello","world") ; print_variable("hello")}' | grep hello
    variable(hello) = 'world'
    hello: "world"
(the debug message is from my extension).

6. And initializing the variable first, then setting its value with the 
extension also works fine:
   $ gawk -l extension/.libs/header.so 'BEGIN{ hello=1 ; 
create_variable("hello","world") ;  print hello }' 
   world


So, bottom line: I guess no easy way to implement automatic header-line 
processing, without some internal code changes.

-gordon


Attachment: header.c
Description: Text Data


reply via email to

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