Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find script line for which warning message is issued

80 views
Skip to first unread message

pjfarley3

unread,
May 12, 2017, 12:30:38 AM5/12/17
to
I am testing some awk scripts with "gawk --lint --posix ..." to be transported to a system with a posix awk. For one of my scripts I get these warnings:

gawk: warning: statement may have no effect
gawk: warning: function `function1' defined but never called directly
gawk: warning: function `function2' defined but never called directly
gawk: warning: function `function3' defined but never called directly
gawk: warning: function `function4' defined but never called directly

But no indication to which line of which script the "no effect" warning refers. The command line lists two scripts using the "-f" parameter and there are no @include statements in either script.

gawk --lint --posix -f script1.awk -f script2.awk input.file > output.file

The first script listed on the command line is used elsewhere without this warning being issued so I suspect it is not a line in that script, but in the second one. However, the following warnings about defined but unused functions refer to functions all defined in the first script, so I am a bit confused about where the offending "no effect" line may be located.

Is there a way to determine the script and the line for which the "no effect" warning is issued?

TIA for any RTFM or help you can provide.

OS: Win7-64
gawk version 4.1.4 (from ezwinports)

Peter

Ed Morton

unread,
May 12, 2017, 11:49:48 AM5/12/17
to
Running lint on each file individually would seem like the obvious way to narrow
down which script has the problem. Can't help you with identifying the line or
statement, though, other than to suggest the other obvious thing of bisecting
the script till you find it.

Ed.

pjfarley3

unread,
May 13, 2017, 1:13:07 PM5/13/17
to
On Friday, May 12, 2017 at 11:49:48 AM UTC-4, Ed Morton wrote:
> On 5/11/2017 11:30 PM, pjfarley3 wrote:
<Snipped>
> > Is there a way to determine the script and the line for which the "no effect"
> > warning is issued?
>
> Running lint on each file individually would seem like the obvious way to
> narrow down which script has the problem. Can't help you with identifying the
> line or statement, though, other than to suggest the other obvious thing of
> bisecting the script till you find it.

Thanks for the suggestion, but it is far easier said than done. Script2.awk cannot execute successfully without the functions defined in Script1.awk, and Script2.awk is 300+ lines of reasonably complex code not easily decomposed into "removable" parts without destroying the functionality entirely.

It just occurred to me that combining the two scripts into one awk file may improve the lint reporting. I'll report back if it does.

Peter

Andrew Schorr

unread,
May 13, 2017, 2:49:46 PM5/13/17
to
On Friday, May 12, 2017 at 12:30:38 AM UTC-4, pjfarley3 wrote:
> I am testing some awk scripts with "gawk --lint --posix ..." to be transported to a system with a posix awk. For one of my scripts I get these warnings:
>
> gawk: warning: statement may have no effect
> gawk: warning: function `function1' defined but never called directly
> gawk: warning: function `function2' defined but never called directly
> gawk: warning: function `function3' defined but never called directly
> gawk: warning: function `function4' defined but never called directly
>

This is mysterious. I cannot duplicate the problem on Linux:

bash-4.2$ cat /tmp/test.awk
BEGIN {
print "hello"
5*2
}

function f1(x) {
print x
}

{
print
}
bash-4.2$ cat /tmp/test2.awk
function f2(x) {
print x
}
bash-4.2$ ./gawk --version | head -1
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.1, GNU MP 6.0.0)
bash-4.2$ ./gawk --posix --lint -f /tmp/test.awk /tmp/test2.awk /dev/null > /dev/null
gawk: /tmp/test.awk:3: warning: statement may have no effect
gawk: warning: function `f1' defined but never called directly

There is only one place in the code where 'statement may have no effect' is issued, it it clearly includes the line number in the message. I am at a loss.

Regards,
Andy

pjfarley3

unread,
May 14, 2017, 12:19:55 AM5/14/17
to
I rebuilt gawk 4.1.4 under Mint Linux 17 under VirtualBox on my Win7 system (old Linux version, I know) and tested with a stripped-down version of my Script2.awk with only active functions from Script1.awk included in it and the "statement may have no effect" warning still comes out without any line number.

I can report this on the bug list with my stripped-down script (~250 lines) and a stripped-down input file (~25 lines) if you think it will be useful. The script is complex because the actions it needs to perform are complex, but I have reduced it as far as I can.

Let me know what I can do to help solve this.

Peter

Andrew Schorr

unread,
May 14, 2017, 10:19:51 AM5/14/17
to
On Sunday, May 14, 2017 at 12:19:55 AM UTC-4, pjfarley3 wrote:
> I rebuilt gawk 4.1.4 under Mint Linux 17 under VirtualBox on my Win7 system (old Linux version, I know) and tested with a stripped-down version of my Script2.awk with only active functions from Script1.awk included in it and the "statement may have no effect" warning still comes out without any line number.
>
> I can report this on the bug list with my stripped-down script (~250 lines) and a stripped-down input file (~25 lines) if you think it will be useful. The script is complex because the actions it needs to perform are complex, but I have reduced it as far as I can.

Yes, please, file a bug report with the code and input attached as an example, although I don't see why the input should matter, since this is a "compile-time" error, isn't it?

Regards,
Andy

pjfarley3

unread,
May 14, 2017, 7:01:27 PM5/14/17
to
OK, I will do that. And you are right, input does not matter. The same message appears with an empty input. I had not thought to test it that way.

Peter

pjfarley3

unread,
May 15, 2017, 12:07:40 PM5/15/17
to
I have tried to subscribe to bug-gawk several times using the web interface at the url copied below and have not yet received the promised email confirmation. Is there a moderated review of subscription requests for that list?

https://lists.gnu.org/mailman/listinfo/bug-gawk

Peter

Andrew Schorr

unread,
May 15, 2017, 9:38:05 PM5/15/17
to
On Monday, May 15, 2017 at 12:07:40 PM UTC-4, pjfarley3 wrote:
> I have tried to subscribe to bug-gawk several times using the web interface at the url copied below and have not yet received the promised email confirmation. Is there a moderated review of subscription requests for that list?
>
> https://lists.gnu.org/mailman/listinfo/bug-gawk

I don't know, but I don't think you need to subscribe to send a message to the list. Did you simply try sending your message to bug-...@gnu.org?

Regards,
Andy

pjfarley3

unread,
May 15, 2017, 11:32:56 PM5/15/17
to
I did do that, sent about 38 hours ago, but it still has not shown up there.

The email address from which I sent that note has an earthlink dot net domain, is there perhaps domain filtering at gnu.org I may have tripped?

Peter

Andrew Schorr

unread,
May 16, 2017, 8:08:16 PM5/16/17
to
On Monday, May 15, 2017 at 11:32:56 PM UTC-4, pjfarley3 wrote:
> The email address from which I sent that note has an earthlink dot net domain, is there perhaps domain filtering at gnu.org I may have tripped?

I have no idea, but the message arrived on the bug list a few minutes ago. I see the problem. The problem is in the newpage() function where it says this:

if (dbg) \
print "DEBUG:maxndx=" maxndx ",allndx=" allndx \
",maxsum=" maxsum ",sumndx=" sumndx
",hx=" hx

Note the lack of the line continuation character after "sumndx". But that doesn't explain why the error message has no line info. That requires further debugging.

Regards,
Andy

pjfarley3

unread,
May 16, 2017, 11:35:44 PM5/16/17
to
Thanks Andy. My eyes just glazed past that statement and didn't see the missing continuation.

Peter
0 new messages