Where is igawk and why doesn't @include replicate this feature?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Where is igawk and why doesn't @include replicate this feature?

Troy Kenah
Hi All,

I have a large number of scripts that were using the the igawk script,
however I have updated my gawk to a newer release that has
obsoleted/removed the igawk script.

I used to embed @include junk.awk statements to reduce repetitive code but
this no longer works. These were files were not functions, simply code
snippets; this is the type of error I am now seeing:

gawk: get_FY2019Q1OIC.awk:28: @include "../inc/segments.awk"
gawk: get_FY2019Q1OIC.awk:28:  ^ syntax error
gawk: get_FY2019Q1OIC.awk:36:         fromdate=mktime("2019 09 01 00 00 00")
gawk: get_FY2019Q1OIC.awk:36:                         ^ syntax error
gawk: get_FY2019Q1OIC.awk:36:         fromdate=mktime("2019 09 01 00 00 00")
gawk: get_FY2019Q1OIC.awk:36:
 ^ 0 is invalid as number of arguments for mktime

Any help would be much appreciated!



Regards,

Troy Kenah.
0416 273 135

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: Where is igawk and why doesn't @include replicate this feature?

Steven Penny
On Wed, 11 Sep 2019 16:54:49, Troy Kenah wrote:

> I used to embed @include junk.awk statements to reduce repetitive code but
> this no longer works. These were files were not functions, simply code
> snippets; this is the type of error I am now seeing:
>
> gawk: get_FY2019Q1OIC.awk:28: @include "../inc/segments.awk"
> gawk: get_FY2019Q1OIC.awk:28:  ^ syntax error
> gawk: get_FY2019Q1OIC.awk:36:         fromdate=mktime("2019 09 01 00 00 00")
> gawk: get_FY2019Q1OIC.awk:36:                         ^ syntax error
> gawk: get_FY2019Q1OIC.awk:36:         fromdate=mktime("2019 09 01 00 00 00")
> gawk: get_FY2019Q1OIC.awk:36:
>  ^ 0 is invalid as number of arguments for mktime

Works fine here:

    $ gawk --version
    GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)

    $ cat one.awk
    function f1(n1) {
       return n1 + 10
    }

    $ cat two.awk
    @include "one.awk"
    BEGIN {
       print f1(20)
    }

    $ unset POSIXLY_CORRECT
    $ gawk -f two.awk
    30

Finally, I would make a suggestion. "@include" is not POSIX, so if you find
yourself relying on something like this more and more, it might be better to
switch to a proper programming language. Something like Perl, Lua or Tcl.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: Where is igawk and why doesn't @include replicate this feature?

ASSI
In reply to this post by Troy Kenah
Troy Kenah writes:
> I have a large number of scripts that were using the the igawk script,
> however I have updated my gawk to a newer release that has
> obsoleted/removed the igawk script.

The semantics for @include are different between igawk and "native" gawk
@include (since 4.x).  The newer gawk versions treat @include statements
like they would treat the --include option on the command line.  In
particular that means that each include is processed only once and you
should (only) use it to define functions.

The igawk script was removed from gawk in this commit

http://git.savannah.gnu.org/cgit/gawk.git/commit/?id=577ece63770a6c4b5ad00d6998127fb7e85b86b9

but left in the manual, so you can resurrect it either from there or
from Git:

http://git.savannah.gnu.org/cgit/gawk.git/plain/awklib/eg/prog/igawk.sh


Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: Where is igawk and why doesn't @include replicate this feature?

Kaz Kylheku
In reply to this post by Troy Kenah
On 2019-09-10 23:54, Troy Kenah wrote:
> Hi All,
>
> I have a large number of scripts that were using the the igawk script,
> however I have updated my gawk to a newer release that has
> obsoleted/removed the igawk script.

Gawk's build system stopped installing igawk over five years ago:

http://git.savannah.gnu.org/cgit/gawk.git/commit/?id=577ece63770a6c4b5ad00d6998127fb7e85b86b9

> I used to embed @include junk.awk statements to reduce repetitive code
> but
> this no longer works. These were files were not functions, simply code
> snippets; this is the type of error I am now seeing:

Clearly, the script is not exactly obsolete, since the @include facility
in
Gawk seems only to work with syntactically complete units, whereas
igawk performs blind textual inclusion.

If I were you, I'd just bring the igawk script into my code base and
continue that way. It's a tiny script that is licensed as
public domain; it doesn't carry much "technical debt" or licensing
debt.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: Where is igawk and why doesn't @include replicate this feature?

Brian Inglis
In reply to this post by Steven Penny
On 2019-09-11 05:52, Steven Penny wrote:
> On Wed, 11 Sep 2019 16:54:49, Troy Kenah wrote:
>> I used to embed @include junk.awk statements to reduce repetitive code but
>> this no longer works. These were files were not functions, simply code
>> snippets; this is the type of error I am now seeing:

> Works fine here:
>
>    $ gawk --version
>    GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
>
>    $ cat one.awk
>    function f1(n1) {
>       return n1 + 10
>    }
>
>    $ cat two.awk
>    @include "one.awk"
>    BEGIN {
>       print f1(20)
>    }
>
>    $ unset POSIXLY_CORRECT
>    $ gawk -f two.awk
>    30
>
> Finally, I would make a suggestion. "@include" is not POSIX, so if you find
> yourself relying on something like this more and more, it might be better to
> switch to a proper programming language. Something like Perl, Lua or Tcl.

Any number of files are supported with option -f repetition as are expressions
with option -e repetition in any order.

--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple