[Top][All Lists]

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

[Groff] Re: MSVC Port--Behavior of spawn and exec functions

From: MARSHALL Keith
Subject: [Groff] Re: MSVC Port--Behavior of spawn and exec functions
Date: Fri, 16 Jan 2004 11:48:03 +0000

Hi Jeff,

> Using cmd.exe won't work with a spooler interface that's a shell script,
> however.

Agreed.  Is 'lp' implemented as a shell script in MKS?  I know Solaris,
(and probably most other *nixes that use lp/lpsched), implement their
printer interfaces as shell scripts, but these are invoked indirectly,
by 'lp' via 'lpsched'; 'lp' and 'lpsched' themselves are ELF executables.

> The handling of double quotes by CreateProcess() (or perhaps by crt0) 
> largely undocumented, so I hate to rely on its behavior; however, I'm 
> sure there's a good alternative.

I fully agree that it is not a good idea to rely on undocumented M$
behaviour; who knows when they may decide that it is a bug, and fix it,
(without telling anyone, of course)!

> My preference is to have groff quote arguments that might contain 
> using a function such as
>    void possible_command::append_arg_quoted(const char *s, const char 
>    {
>      args += '"';
>      args += s;
>      if (t)
>        args += t;
>      args += '"';
>      args += '\0';
>    }

I found a (rather long winded) description of how MSVC applications
parse their command lines at

which basically says that only the double quote character receives
*any* special consideration during argv[] reconstruction, and then only
when it is *not* immediately preceded by an *odd* number or backslashes;
the backslash is not treated specially, unless immediately followed by
a double quote, in which case a contiguous even numbered sequence of 2N
backslashes is reduced to N backslashes, with the following double quote
retaining its quoting property, while a contiguous odd numbered sequence
of 2N+1 backslashes is reduced to N backslashes, followed by an escaped
(i.e. literal) double quote character, which loses its quoting property.

Using 'append_arg_quoted' looks like a reasonable solution, for the
"native" Windows builds, where we need to group arguments in the 'argv[]'
which will eventually get rebuilt by the MSVC startup code, in the spawned
process; however, it needs careful consideration as to *when* to use it --
indiscriminate use could break an 'exec' or 'spawn' call in the *nix,
Cygwin, and possibly some other builds, where

    execlp( "sh", "sh", "-c", "\"lp -l\"", NULL )

results in the error

    sh: lp -l: command not found

We would also need to pay particular attention to *how* we use
'append_arg_quoted' to group args -- basically *all* args which need to
be grouped need to be passed at once, in the same call -- perhaps we
should consider using *two* functions, e.g.

    void possible_command::append_arg_quoted_begin(const char *s, const 
char *t)
      args += '"';
      args += s;
      if (t)
        args += t;
      args += '\0';

    void possible_command::append_arg_quoted_end(const char *s, const char 
      args += s;
      if (t)
        args += t;
      args += '"';
      args += '\0';

which would allow us to construct arbitrary groupings, with
multiple function calls?

Best regards,

reply via email to

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