help-gawk
[Top][All Lists]
Advanced

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

Re: How to make "division by zero attempted" error message more informat


From: Andrew J. Schorr
Subject: Re: How to make "division by zero attempted" error message more informative?
Date: Thu, 3 Mar 2022 17:03:15 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Mar 03, 2022 at 01:55:23PM -0600, Neil R. Ormos wrote:
> There is no magic way for Gawk to know what should be printed in the error 
> message to distinguish a particular call.

Well, the truth is that it wouldn't be hard to add such a feature. When gawk 
starts up,
it parses the name by which it was invoked to extract the name to use at the 
start
of error messages:

const char *myname;
...
int
main(int argc, char **argv)
{
...
        myname = gawk_name(argv[0]);

So it would be fairly simple to add an environment variable to override this.
For example, one might test for an environment variable "GAWK_ERROR_NAME"
and use that instead if present and not empty:

        if (!(myname = getenv("GAWK_ERROR_NAME")) || !*myname)
                myname = gawk_name(argv[0]);

Now whether to patch the code in that fashion is a good idea is an entirely
different question. But anybody who needs that feature can easily
apply this patch. Or one could add a command-line option to accomplish
the same thing.

bash-4.2$ GAWK_ERROR_NAME=fubar ./gawk 'BEGIN {print 10/0}'
fubar: cmd. line:1: error: division by zero attempted
bash-4.2$ 

Regards,
Andy

Attachment: err_name.patch
Description: Text document


reply via email to

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