bug-gawk
[Top][All Lists]
Advanced

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

Re: MinGw port of gawkextlib


From: Andrew J. Schorr
Subject: Re: MinGw port of gawkextlib
Date: Mon, 16 May 2022 11:55:31 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Sat, May 14, 2022 at 08:53:00AM +0300, Eli Zaretskii wrote:
> This is what I get:
> 
>   $ gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'
>   d:/usr/lib/gawk/ext-3.1
> 
> However, AWKLIBPATH is a path, not a single file name, so we could
> have several directories in it, as in /foo/bar/:/baz/quux:whatever.
> It is, indeed, rather unusual to have the first directory in
> AWKLIBPATH to be a single letter, but it's possible at least in
> principle.

In reality, gawk puts only a single path in the default AWKLIBPATH. And I think
what we really want here is the built-in AWKLIBPATH, not what the user has in
the environment. So we can protect by unsetting it.

> In my tests I needed to remove one backslash from the "\\\1" part, and
> then I get the expected:
> 
>   $ gawk 'BEGIN {print gensub(/\<([[:alpha:]]):\//, "/\\1/", "g", 
> ENVIRON["AWKLIBPATH"])}'
>   /d/usr/lib/gawk/ext-3.1
> 
> With 3 backslashes, I get a funny face (binary 01 character) instead
> of 'd' in "/d/".  I needed to make the same change on GNU/Linux, to
> get this to DTRT.  Any idea why the difference vs your system?  What
> kind of shell are you using?

I could be wrong, but I think you're missing another level of back quotes
for the command substitution. In test.makefile, we've got:

AWK = LC_ALL=$${GAWKLOCALE:-C} LANG=$${GAWKLOCALE:-C} 
AWKLIBPATH=../.libs$(PATH_SEPARATOR)`unset AWKLIBPATH && $(GAWKPROG) 'BEGIN 
{print gensub(/\<([[:alpha:]]):\//, "/\\\1/", "g", ENVIRON["AWKLIBPATH"])}'` 
PATH=$(GEBINPFX)$$PATH LD_LIBRARY_PATH=$(GELIBPFX)$$LD_LIBRARY_PATH 
DYLD_LIBRARY_PATH=$(GELIBPFX)$$DYLD_LIBRARY_PATH $(VALGRIND) $(GAWKPROG)

So please try this:

echo `unset AWKLIBPATH && gawk 'BEGIN {print gensub(/\<([[:alpha:]]):\//, 
"/\\\1/", "g", ENVIRON["AWKLIBPATH"])}'`

For me, that seems to work, but maybe I'm confused about how GNU make is
going to run this. My test case:

bash-4.2$ export AWKLIBPATH=d:/usr/lib/gawk/ext-3.1

# with 3 backslashes:
bash-4.2$ echo `unset FUBAR && gawk 'BEGIN {print gensub(/\<([[:alpha:]]):\//, 
"/\\\1/", "g", ENVIRON["AWKLIBPATH"])}'`
/d/usr/lib/gawk/ext-3.1

# with 2 backslashes:
bash-4.2$ echo `unset FUBAR && gawk 'BEGIN {print gensub(/\<([[:alpha:]]):\//, 
"/\\1/", "g", ENVIRON["AWKLIBPATH"])}'`
//usr/lib/gawk/ext-3.1

> However, the default value of AWKLIBPATH can be overridden by setting
> AWKLIBPATH in the environment:
> 
>   $ AWKLIBPATH="C:\\foo\\bar" gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'
>   C:\foo\bar
> 
> Thus the conclusion that the gensub invocation should be prepared to
> handle any style of slashes.

As I mentioned above, I propose to ignore the AWKLIBPATH value in the
environment. Can you think of a reason we would need that? I think it
would be helpful only in the case where the installer had chosen to install
previous gawk libraries in a non-default location. That seems like a corner
case.

> And, of course, your suggestion, if you intend to use it on all
> platforms, assumes no AWKLIBPATH on Unix will ever begin with a
> one-letter directory.

I think this is all covered by the 'unset AWKLIBPATH'. I am able to
build successfully on linux with AWK as defined above. Are you able to
test with the attached patch to test.makefile?

Thanks,
Andy

Attachment: test.makefile.patch
Description: Text document


reply via email to

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