+#if 0
+ /* #### we need to port this. */
+ /* On Windows 95, if cmdname is a DOS app, we invoke a helper
+ application to start it by specifying the helper app as cmdname,
+ while leaving the real app name as argv[0]. */
+ if (is_dos_app)
+ {
+ cmdname = (char*) alloca (MAXPATHLEN);
+ if (egetenv ("CMDPROXY"))
+ strcpy ((char*)cmdname, egetenv ("CMDPROXY"));
+ else
+ {
+ strcpy ((char*)cmdname, XSTRING_DATA (Vinvocation_directory));
+ strcat ((char*)cmdname, "cmdproxy.exe");
+ }
+ }
+#endif
+
+ /* we have to do some conjuring here to put argv and envp into the
+ form CreateProcess wants... argv needs to be a space separated/null
+ terminated list of parameters, and envp is a null
+ separated/double-null terminated list of parameters.
+
+ Additionally, zero-length args and args containing whitespace or
+ quote chars need to be wrapped in double quotes - for this to work,
+ embedded quotes need to be escaped as well. The aim is to ensure
+ the child process reconstructs the argv array we start with
+ exactly, so we treat quotes at the beginning and end of arguments
+ as embedded quotes.
+
+ The Win32 GNU-based library from Cygnus doubles quotes to escape
+ them, while MSVC uses backslash for escaping. (Actually the MSVC
+ startup code does attempt to recognize doubled quotes and accept
+ them, but gets it wrong and ends up requiring three quotes to get a
+ single embedded quote!) So by default we decide whether to use
+ quote or backslash as the escape character based on whether the
+ binary is apparently a Cygnus compiled app.
+
+ Note that using backslash to escape embedded quotes requires
+ additional special handling if an embedded quote is already
+ preceded by backslash, or if an arg requiring quoting ends with
+ backslash. In such cases, the run of escape characters needs to be
+ doubled. For consistency, we apply this special handling as long
+ as the escape character is not quote.
+
+ Since we have no idea how large argv and envp are likely to be we
+ figure out list lengths on the fly and allocate them. */
+
+ if (!NILP (Vmswindows_quote_process_args))
+ {
+ do_quoting = 1;
+ /* Override escape char by binding mswindows-quote-process-args to
+ desired character, or use t for auto-selection. */
+ if (INTP (Vmswindows_quote_process_args))
+ escape_char = (char) XINT (Vmswindows_quote_process_args);
+ else
+ escape_char = is_cygnus_app ? '"' : '\\';
+ }
+
+ /* do argv... */
+ for (i = 0; i < nargv; ++i)
+ {
+ Bufbyte *targ = XSTRING_DATA (i == 0 ? program : argv[i - 1]);
+ Bufbyte *p = targ;
+ int need_quotes = 0;
+ int escape_char_run = 0;
+ int arglen = 0;
+
+ if (*p == 0)
+ need_quotes = 1;
+ for ( ; *p; p++)
+ {
+ if (*p == '"')
+ {
+ /* allow for embedded quotes to be escaped */
+ arglen++;
+ need_quotes = 1;
+ /* handle the case where the embedded quote is already escaped */
+ if (escape_char_run > 0)
+ {
+ /* To preserve the arg exactly, we need to double the
+ preceding escape characters (plus adding one to
+ escape the quote character itself). */
+ arglen += escape_char_run;
+ }
+ }
+ else if (*p == ' ' || *p == '\t')
+ {
+ need_quotes = 1;
+ }
+
+ if (*p == escape_char && escape_char != '"')
+ escape_char_run++;
+ else
+ escape_char_run = 0;
+ }
+ if (need_quotes)
+ {
+ arglen += 2;
+ /* handle the case where the arg ends with an escape char - we
+ must not let the enclosing quote be escaped. */
+ if (escape_char_run > 0)
+ arglen += escape_char_run;
+ }
+ arglen += strlen (targ) + 1;
+
+ quoted_args[i] = alloca_array (Bufbyte, arglen);
+ }