bug-gawk
[Top][All Lists]
Advanced

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

Re: MinGw port of gawkextlib


From: Eli Zaretskii
Subject: Re: MinGw port of gawkextlib
Date: Sat, 14 May 2022 08:53:00 +0300

> Date: Fri, 13 May 2022 14:05:18 -0400
> From: "Andrew J. Schorr" <aschorr@telemetry-investments.com>
> Cc: mcollado2011@gmail.com, bug-gawk@gnu.org
> 
> > I think it is easier to ask MinGW users to run the test suite with a
> > special argument, like
> > 
> >   make check PATHSEP=';'
> > 
> > or somesuch.
> 
> Hmmm. Actually, the autoconf magic defines PATH_SEPARATOR for
> us in m4/progtest.m4. So it's easy enough to replace the ":"
> with "$(PATH_SEPARATOR)" instead in the definition of AWK
> (although you're saying that doesn't actually matter because MSYS bash
> does this for us, but it still seems more elegant to use it).
> 
> But you're saying that this doesn't fix the problem because the value of
> AWKLIBPATH reported by gawk will contain colons, and then the MSYS bash will
> mangle the value by converting the colons to semi-colons.

Yes.

> I'm guessing that ENVIRON["AWKLIBPATH"] contains colons only in
> MinGW

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.

> so might this fix the problem (where I'm using gawk gensub to
> replace the pattern "<drive letter>:/" with "/<drive letter>/")?
> 
> AWK = LC_ALL=$${GAWKLOCALE:-C} LANG=$${GAWKLOCALE:-C} 
> AWKLIBPATH=../.libs$(PATH_SEPARATOR)`$(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)
> 
> There's a bit of a quoting nightmare there with escaped backslashes, do
> I don't know if this will actually work. But it seemed like it might
> in my tests.

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?

> Also, can you please send me the actual output from this command on a MinGW
> MSYS setup?
>    gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'
> because I'm just guessing about what I'm dealing with.

See above; the "d:/usr/lib/gawk/ext-3.1" value was obtained by running
the command from the MSYS Bash prompt.

> From your "sed" command, it seems that the path looks something like
> "d:/lib/path", which surprises me, because I would have expected
> backslashes instead of forward slashes.

It could be either.  Windows understands both styles of slashes in
file names, and handles both alike.  So you could have slashes,
backslashes, or any mix thereof, and the gensub call should be
prepared to deal with X:\ and X:/ alike.

The reason why my Gawk produces forward slashes is simply because that
is how I build Gawk: the argument to -DDEFLIBPATH on the compilation
command line names a directory with forward slashes.  And that will be
so in any "usual" MinGW build of Gawk, because pc/Makefile says:

  prefix = c:/gnu
  pkgextensiondir = $(prefix)/lib/gawk
  DEFLIBPATH = "\"$(pkgextensiondir)\""

So, unless the person who builds overrides the value of DEFLIBPATH
with a different one which uses backslashes, Gawk will always report
forward slashes in the default value of AWKLIBPATH.

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.

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.

Thanks.



reply via email to

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