public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Asterisk expansion...
@ 1998-07-23 15:30 Robertson, Jason V
  1998-07-24 11:17 ` Matthias Morche
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Robertson, Jason V @ 1998-07-23 15:30 UTC (permalink / raw)
  To: gnu-win32

Hi,

There seems to be an inconsistency in how * is interpreted.  When you
run, say, 'echo.exe' from the commandline you get the following:
C:> echo *.*
<Contents of C: are listed>
C:> echo \*.\*
\*.\*

So why does it expand the glob in the first instance, and not unescape
them in the second?  And doesn't this mean it's impossible to echo the
string:
*.*
from cmd?

Running from sh behaves as expected:
$ echo *.*
<contents of pwd are listed>
$ echo \*.\*
*.*

Any ideas?  The reason this is causing problems is that we have a
wrapper around these binaries and it's clueless as to what's expected of
it because it seems indeterminate with respect to commandline expansion.
Is there some hook whereby the tools know if they're being run from
another Cygnus tool so they don't expand the command line?

Thanks,
Jason
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Asterisk expansion...
@ 1998-07-24 12:58 Earnie Boyd
  1998-07-25  1:22 ` Fergus Henderson
  0 siblings, 1 reply; 21+ messages in thread
From: Earnie Boyd @ 1998-07-24 12:58 UTC (permalink / raw)
  To: Robertson, Jason V, gnu-win32

---"Robertson, Jason V"  wrote:
>
> Hi,
> 
> There seems to be an inconsistency in how * is interpreted.  When you
> run, say, 'echo.exe' from the commandline you get the following:
> C:> echo *.*
> <Contents of C: are listed>
> C:> echo \*.\*
> \*.\*
> 
> So why does it expand the glob in the first instance, and not unescape
> them in the second?  And doesn't this mean it's impossible to echo the

It is the shells job to do the globbing not the programs.

the \ is not used the same way in MSDOS as it is in UNIX the program
will only output to stdout what it receives on stdin.

This is true for _ALL_ programs.

<snip>


==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd@yahoo.com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
[parent not found: <35B93BE2.2642EDA3@home.com>]
* Re: Asterisk expansion...
@ 1998-07-27  9:00 Earnie Boyd
  1998-07-27  9:00 ` Fergus Henderson
  0 siblings, 1 reply; 21+ messages in thread
From: Earnie Boyd @ 1998-07-27  9:00 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: gw32

---Fergus Henderson <fjh@cs.mu.OZ.AU> wrote:
>
> On 24-Jul-1998, Earnie Boyd <earnie_boyd@yahoo.com> wrote:
> > ---"Robertson, Jason V"  wrote:
> > >
> > > Hi,
> > > 
> > > There seems to be an inconsistency in how * is interpreted. 
When you
> > > run, say, 'echo.exe' from the commandline you get the following:
> > > C:> echo *.*
> > > <Contents of C: are listed>
> > > C:> echo \*.\*
> > > \*.\*
> > > 
> > > So why does it expand the glob in the first instance, and not
unescape
> > > them in the second?
> > 
> > It is the shells job to do the globbing not the programs.
> 
> Then why does gnu-win32 do the globbing in the case of the command
> `echo *.*'?

In the case of the DOS shell command `ECHO' or `echo' is a shell
builtin; therefore, gnu-win32 doesn't even enter the picture.  In the
case of the bash shell command `echo' is a shell builtin and globbing
happens as expected.  Yes, I know there is an echo.exe; but, unless
you explicitely execute it you execute the builtin command.

To answer your question though, gnu-win32 globs the command line again
so that the filesystem emulation can happen rather seamlessly.

You responded to Michael Hirmke:
> No; he is assuming that gnu-win32 should use \ to escape characters.
> After all, it is gnu-win32 that is doing the globbing (expanding the
> wildcards), not command.com or cmd.exe.

This is an incorrect statement due to the first fact I stated.  When
doing `echo \*.\*' within the DOS shell the globbing that occurs
within cmd.exe or command.com will not find a file and then returns
\*.\* to echo as the parameter list which it will simply write to stdout.
==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd@yahoo.com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Asterisk expansion...
@ 1998-07-27 14:23 Earnie Boyd
  1998-07-27 14:23 ` Fergus Henderson
  0 siblings, 1 reply; 21+ messages in thread
From: Earnie Boyd @ 1998-07-27 14:23 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: gw32

---Fergus Henderson <fjh@cs.mu.OZ.AU> wrote:
>
> On 27-Jul-1998, Earnie Boyd <earnie_boyd@yahoo.com> wrote:
> > 
> > ---Fergus Henderson <fjh@cs.mu.OZ.AU> wrote:
> > >
> > > On 24-Jul-1998, Earnie Boyd <earnie_boyd@yahoo.com> wrote:
> > > > ---"Robertson, Jason V"  wrote:
> > > > >
> > > > > Hi,
> > > > > 
> > > > > There seems to be an inconsistency in how * is interpreted. 
When you
> > > > > run, say, 'echo.exe' from the commandline you get the
following:
> > > > > C:> echo *.*
> > > > > <Contents of C: are listed>
> > > > > C:> echo \*.\*
> > > > > \*.\*
> > > > > 
> > > > > So why does it expand the glob in the first instance, and
not unescape
> > > > > them in the second?
> > > > 
> > > > It is the shells job to do the globbing not the programs.
> > > 
> > > Then why does gnu-win32 do the globbing in the case of the command
> > > `echo *.*'?
> >
> > In the case of the DOS shell command `ECHO' or `echo' is a shell
> > builtin; therefore, gnu-win32 doesn't even enter the picture.
> 
> Sorry, you are correct.  I forgot that echo was a builtin for
command.com.
> Let me rephrase the question: why does gnu-win32 do the globbing in
the
> case of the command `C:\bin\echo *.*'?
> 
> My point is that your statement "It is the shells job to do the
globbing
> not the programs", while valid in Unix, is not valid in DOS, and it
> is not valid in any unqualified sense in gnu-win32.
> 

I know from the experience of my mingw32-sup package that cmd.exe and
commmand.com do globbing, it is not as robust though.  For example:
`ls' doesn't do any globbing, it only reports on a list of files given
it on stdin.  I ported it to native win32 using mingw32.

Gnu-win32 reglobs in the startup of the program (none of the programs
were modified to do the globbing) in order to emulate the UNIX
environment and to serve the `mounted filesystem table'.
==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd@yahoo.com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Asterisk expansion...
@ 1998-07-28  0:57 Robertson, Jason V
  1998-07-27 15:12 ` Michael Weiser
  0 siblings, 1 reply; 21+ messages in thread
From: Robertson, Jason V @ 1998-07-28  0:57 UTC (permalink / raw)
  To: michael, Robertson, Jason V; +Cc: gnu-win32

I thought of that but didn't want to pay the performance penalty or have to
worry about yet another dependency (the Cygnus DLL).  Although that may have
helped (or it may not have) with a strange console problem I have - I have
to Wait on all children that use the console because if I don't for some
reason the child loses access to the console.  I guess 'cmd' sees that its
direct child has exited so tries to take it back over or something.

Thanks,
Jason

> -----Original Message-----
> From:	michael@weiser.saale-net.de [SMTP:michael@weiser.saale-net.de]
> Sent:	Monday, July 27, 1998 9:31 AM
> To:	Jason V Robertson
> Cc:	gnu-win32@cygnus.com
> Subject:	Re: Asterisk expansion...
> 
> Hi Jason,
> 
> You wrote:
> 
> >To get around it I have the wrapper determine if it's a Cygnus binary and
> if
> >it is it sets a variable.  If a new wrapper process sees that variable it
> >calls SetEnvironmentVariable(..) to append 'noglob' to CYGWIN32.
> Why not recompile the wrapper using cygwin's gcc so that it becomes a
> cygwin executable?
> 
> bye
> 
> Michael
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Asterisk expansion...
@ 1998-07-28  5:54 Andrew Dalgleish
  0 siblings, 0 replies; 21+ messages in thread
From: Andrew Dalgleish @ 1998-07-28  5:54 UTC (permalink / raw)
  To: earnie_boyd; +Cc: gnu-win32

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

> I know from the experience of my mingw32-sup package that cmd.exe and
> commmand.com do globbing, it is not as robust though.  For example:
> `ls' doesn't do any globbing, it only reports on a list of files given
> it on stdin.  I ported it to native win32 using mingw32.
[Andrew Dalgleish]  
cmd/command do NOT do globbing.

Some compiler/linker packages may do globbing in the run-time startup
code, so from your code it seems as if the globbing had been done by the
shell.

I can't speak for mingw32, but from the Microsoft help:

Expanding Wildcard Arguments 
Microsoft Specific ®

When running a C program, you can use either of the two wildcards - the
question mark (?) and the asterisk (*) - to specify filename and path
arguments on the command line. 

Command-line arguments are handled by a routine called _setargv (or
_wsetargv in the wide-character environment), which by default does not
expand wildcards into separate strings in the argv string array. You can
replace the normal _setargv routine with a more powerful version of
_setargv that does handle wildcards by linking with the SETARGV.OBJ
file. If your program uses a wmain function, link with WSETARGV.OBJ. 

To link with SETARGV.OBJ or WSETARGV.OBJ, use the /link option. For
example: 

cl typeit.c /link setargv.obj

The wildcards are expanded in the same manner as operating system
commands. (See your operating system user's guide if you are unfamiliar
with wildcards.) Enclosing an argument in double quotation marks (" ")
suppresses the wildcard expansion. Within quoted arguments, you can
represent quotation marks literally by preceding the
double-quotation-mark character with a backslash (\). If no matches are
found for the wildcard argument, the argument is passed literally. 

END Microsoft Specific

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Asterisk expansion...
@ 1998-07-29 17:43 Andrew Dalgleish
  0 siblings, 0 replies; 21+ messages in thread
From: Andrew Dalgleish @ 1998-07-29 17:43 UTC (permalink / raw)
  To: earnie_boyd, gnu-win32

> -----Original Message-----
> From:	Earnie Boyd [SMTP:earnie_boyd@yahoo.com]
> Sent:	1998 July 30, Thursday 00:29
> To:	Andrew Dalgleish
> Subject:	RE: Asterisk expansion...
> 
> 
> Thanks for this information.  I hate giving misinformation.  I have
> yet to find a definition of the function _setargv though.  I've built
> simple tests with both mingw32 gcc and with Jacob Navia's LCC and they
> both do the same globbing on NT 3.51.  I've searched the executables
> with `nm test.exe | less' and can only find argv as data which comes
> from the parameter definitions from main.  I've searched crtdll.dll
> with the strings command and did not find the _setargv function.
> 
> From the definition you've given below I can conclude the cmd.exe does
> infact do globbing. The statement
> 
> > The wildcards are expanded in the same manner as operating system
> > commands. (See your operating system user's guide if you are
> unfamiliar
> 
> implies to me that the * is expanded to a list of files by cmd.exe
> albeit only from the working directory.
[Andrew Dalgleish]  
cmd/command only do globbing for INTERNAL commands.
(For internal commands, it is a moot point as to whether the shell or
the command does the globbing.)

Microsoft use a function _setargv in their startup code.
The default version does NOT do any globbing.
They also offer a "more powerful version" which does do globbing, but
you need to specify the SETARGV.OBJ file in the link command.

I am not suprised you could not find any references to _setargv.
This function is Microsoft-specific, and if anyone else uses a function
with the same name it is just co-incidence.


Here is definitive proof  that cmd does NOT do globbing for external
commands unless you link with the alternative _setargv.
C:\>type ShowArgs.c
#include <stdio.h>
#include <stdlib.h>
int     main(int argc, char *argv[])
{
  int   ArgIndex;
  for (ArgIndex = 0; ArgIndex < argc; ++ArgIndex)
    printf("%d %s\n", ArgIndex, argv[ArgIndex]);
  return EXIT_SUCCESS;
}


C:\>cl ShowArgs.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for
80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

ShowArgs.c
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.

/out:ShowArgs.exe
ShowArgs.obj

C:\>ShowArgs *.c
0 ShowArgs
1 *.c

C:\>cl ShowArgs.c setargv.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for
80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

ShowArgs.c
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.

/out:ShowArgs.exe
ShowArgs.obj
setargv.obj

C:\>ShowArgs *.c
0 ShowArgs
1 SHOWARGS.C

C:\>

When linked with SETARGV.OBJ, the arguments are globbed.
When linked without SETARGV.OBJ, the arguments are NOT globbed.

Hence cmd/command do NOT do globbing for external commands

(Actually it is possible that globbing is done by the shell.
E.g. the shell could peek into the .EXE to detect which version of
SETARGV.OBJ was included.
I don't think this is very likely, but then it is Microsoft... :-)

Regards,
Andrew Dalgleish

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Asterisk expansion...
@ 1998-07-31  3:03 Earnie Boyd
  0 siblings, 0 replies; 21+ messages in thread
From: Earnie Boyd @ 1998-07-31  3:03 UTC (permalink / raw)
  To: gnu-win32, Andrew Dalgleish

---Andrew Dalgleish <andrewd@axonet.com.au> wrote:
>
> 
> 
<snip>
> 
> When linked with SETARGV.OBJ, the arguments are globbed.
> When linked without SETARGV.OBJ, the arguments are NOT globbed.
> 
> Hence cmd/command do NOT do globbing for external commands
> 
> (Actually it is possible that globbing is done by the shell.
> E.g. the shell could peek into the .EXE to detect which version of
> SETARGV.OBJ was included.
> I don't think this is very likely, but then it is Microsoft... :-)
> 

It is also possible that cmd.exe/command.com does do the globbing and
that the default _setargv reads the command line and resets the argv
array.  I would do this if I had the MS compiler; but, try with this
sample code creating your own _setargv which simply does nothing
(maybe output a message so that you know that your _setargv was called).

Colin Peters and Jacob Navia, I hope you are reading this.  With the
startup code of Mingw32 or LCC is any default globbing done?

==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd@yahoo.com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Asterisk expansion...
@ 1998-07-31 12:10 Earnie Boyd
  0 siblings, 0 replies; 21+ messages in thread
From: Earnie Boyd @ 1998-07-31 12:10 UTC (permalink / raw)
  To: Andrew Dalgleish; +Cc: gw32

---Andrew Dalgleish <andrewd@axonet.com.au> wrote:
>
> 
> 
> > -----Original Message-----
> > From:	Earnie Boyd [SMTP:earnie_boyd@yahoo.com]
> > Sent:	1998 July 30, Thursday 21:37
> > To:	gnu-win32@cygnus.com; Andrew Dalgleish
> > Subject:	RE: Asterisk expansion...
> > 
> > ---Andrew Dalgleish <andrewd@axonet.com.au> wrote:
> > >
> > > 
> > > 
> > <snip>
> > > 
> > > When linked with SETARGV.OBJ, the arguments are globbed.
> > > When linked without SETARGV.OBJ, the arguments are NOT globbed.
> > > 
> > > Hence cmd/command do NOT do globbing for external commands
> > > 
> > > (Actually it is possible that globbing is done by the shell.
> > > E.g. the shell could peek into the .EXE to detect which version of
> > > SETARGV.OBJ was included.
> > > I don't think this is very likely, but then it is Microsoft... :-)
> > > 
> > 
> > It is also possible that cmd.exe/command.com does do the globbing
and
> > that the default _setargv reads the command line and resets the argv
> > array.  I would do this if I had the MS compiler; but, try with this
> > sample code creating your own _setargv which simply does nothing
> > (maybe output a message so that you know that your _setargv was
> > called).
> [Andrew Dalgleish]  
> I've waded through Microsoft's run-time source.
> 
> SETARGV.OBJ contains a single function "_setargv".
> The default version does nothing.
> The globbing version sets a flag "_dowildcard" to one.
> 
> Later in the startup "__getmainargs" calls "__setargv".
> (It took me a while to realize this one has two leading underscores
:-)
> 
> If the flag is set "__setargv" then calls "_cwild".
> "_cwild" does some simple checks for quoted arguments (which are not
> expanded), and passes args which may be wildcards on to "tmatch".
> "tmatch" looks for the wildcard characters, then uses
> FindFirstFile/FindNextFile to build the list of files.
> 
> Most of these functions have two versions, one for char and one for
> wchar_t
> They use a single source with lots of #if's sprinkled around.
> For example "tmatch" is #defined to either "match" or "wmatch"
> 
> The bottom line - cmd/command do not glob.
> 
> 
> 

I found the following code from the init.c code for mingw32.  Note
that it has nothing to do with _setargv but it does confirm that
cmd/command _DO_NOT_GLOB_.

/* NOTE: Thanks to Pedro A. Aranda Gutiirrez <paag@tid.es> for pointing
 * this out to me. GetMainArgs (used below) takes a fourth argument
 * which is an int that controls the globbing of the command line. If
 * _CRT_glob is non-zero the command line will be globbed (e.g. *.*
 * expanded to be all files in the startup directory). In the mingw32
 * library a _CRT_glob variable is defined as being -1, enabling
 * this command line globbing by default. To turn it off and do all
 * command line processing yourself (and possibly escape bogons in
 * MS's globbing code) include a line in one of your source modules
 * defining _CRT_glob and setting it to zero, like this:
 *  int _CRT_glob = 0;
 */
extern int  _CRT_glob;

/*
 * Initialize the __argc, __argv and _environ variables.
 */
static void
_mingw32_init_mainargs ()
{
    /*
     * CRTDLL provides a nice little function for doing just that.
     * Convenient isn't it?
     * NOTE: The last
     */
    (void) __GetMainArgs(&__argc, &__argv, &_environ, _CRT_glob);
}

==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd@yahoo.com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~1998-08-02 15:23 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-23 15:30 Asterisk expansion Robertson, Jason V
1998-07-24 11:17 ` Matthias Morche
1998-07-24 12:58 ` Mike Bandy
1998-07-25  0:08 ` Michael Hirmke
1998-07-25  4:14   ` Fergus Henderson
1998-08-02 15:23 ` OT: Re: Asterisk expansion...[Was: unsubscribe] Björn Kulms
1998-07-24 12:58 Asterisk expansion Earnie Boyd
1998-07-25  1:22 ` Fergus Henderson
1998-07-25 10:30   ` Leo Mauro
     [not found] <35B93BE2.2642EDA3@home.com>
1998-07-25 18:10 ` Jason V Robertson
1998-07-27 14:23   ` Michael Weiser
1998-07-27  9:00 Earnie Boyd
1998-07-27  9:00 ` Fergus Henderson
1998-07-27 14:23 Earnie Boyd
1998-07-27 14:23 ` Fergus Henderson
1998-07-28  0:57 Robertson, Jason V
1998-07-27 15:12 ` Michael Weiser
1998-07-28  5:54 Andrew Dalgleish
1998-07-29 17:43 Andrew Dalgleish
1998-07-31  3:03 Earnie Boyd
1998-07-31 12:10 Earnie Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).