delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/05/25/06:39:46

Date: Sun, 25 May 1997 13:38:34 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "John M. Aldrich" <fighteer AT cs DOT com>
cc: Robert Hoehne <robert DOT hoehne AT mathematik DOT tu-chemnitz DOT de>,
DJGPP Workers Mailing List <djgpp-workers AT delorie DOT com>
Subject: Re: Bugfix for redir.c
In-Reply-To: <338492EF.FDD@cs.com>
Message-ID: <Pine.SUN.3.91.970525133545.4960J-100000@is>
MIME-Version: 1.0

On Thu, 22 May 1997, John M. Aldrich wrote:

> Interesting.  This code would have to deal with such things as nested
> quotes, escaped quotes, and other such nastiness.  For example, it would
> have to reconstruct the argument 'He said "This is great"' with single
> quotes instead of double quotes, or the command line will be even more
> messed up than it was before.

I originally fell into this same trap, which caused me to rewrite
large parts of `system' and `dosexec' a couple of times, until it hit
me that most of these problems are already taken care for you by
whoever put together the original command line.  If they wanted the
string in your example above to be a single argument, *they* must have
quoted it properly, or be prepared for the shock of their lives.  So
you can safely assume that the command line as passed to `redir' was
either
		'He said "This is great"'
or
		"He said \"This is great\""
or even
		"He said ""This is great"

or anything else that the program you are going to invoke can grok
(non-DJGPP programs typically don't know about single quotes, and
COMMAND.COM doesn't even know about escaping double quotes).

It seems to me that the easiest way to make `redir' right is to write
custom `__crt0_setup_arguments' that processes the !proxy stuff for
long command lines, but doesn't unquote the arguments and doesn't
expand wildcards (i.e., don't call the `parse_bytes' function).  This
way, you get the original command line and can safely pass it to
`system'.  See src/libc/crt0/c1args.c for the details.

> This is probably why dosexec.c is so messy.  ;)

Tell me about it ;-).  Each time I need to look there, it takes me
about 20 minutes to recall what's going on, and I wrote large parts of
that stuff.  Maybe it's my messy coding style...

However, most of the mess is for the case you DON'T need to handle:
when the program is invoked by `spawnXX' (as opposed to `system'),
because the arguments in that case are NOT quoted.  For example, they
can say this:

 spawnlp (P_WAIT, "foobar", "foobar", "He said \"this is great\"", NULL);

and spawn needs to quote any argumets with whitespace when it constructs
the DOS Exec command tail, or if you need to call the shell (like if it's
a built-in command). 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019