-/* This is a kludge to get around the Microsoft C spawn functions' propensity
- to remove the outermost set of double quotes from all arguments. */
-
-static const char * const *
-fix_argv (char * const *argvec)
-{
- char **argv;
- int i;
- char *command0;
-
- /* See whether we need to change anything. */
- for (command0 = argvec[0]; *command0 != '\0'; command0++)
- if (*command0 == '/')
- break;
- if (*command0 == '\0')
- {
- for (i = 1; argvec[i] != NULL; i++)
- if (strpbrk (argvec[i], "\" \t") != NULL)
- break;
-
- if (argvec[i] == NULL)
- return (const char * const *) argvec;
- }
-
- for (i = 0; argvec[i] != NULL; i++)
- ;
- argv = xmalloc ((i + 1) * sizeof (char *));
- for (i = 0; argvec[i] != NULL; i++)
- argv[i] = xstrdup (argvec[i]);
- argv[i] = NULL;
-
- /* Ensure that the executable pathname uses Win32 backslashes. This
- is not necessary on NT, but on W9x, forward slashes causes
- failure of spawn* and exec* functions (and probably any function
- that calls CreateProcess) *iff* the executable pathname (argv[0])
- is a quoted string. And quoting is necessary in case a pathname
- contains embedded white space. You can't win. */
- for (command0 = argv[0]; *command0 != '\0'; command0++)
- if (*command0 == '/')
- *command0 = '\\';
-
- for (i = 1; argv[i] != 0; i++)
- {
- int len, j;
- char *temp, *newtemp;
-
- temp = argv[i];
- len = strlen (temp);
- for (j = 0; j < len; j++)
- {
- if (temp[j] == '"')
- {
- newtemp = xmalloc (len + 2);
- strncpy (newtemp, temp, j);
- newtemp [j] = '\\';
- strncpy (&newtemp [j+1], &temp [j], len-j);
- newtemp [len+1] = 0;
- temp = newtemp;
- len++;
- j++;
- }
- }
-
- if (argv[i] != temp)
- {
- free (argv[i]);
- argv[i] = temp;
- }
- }
-
- for (i = 0; argv[i] != 0; i++)
- {
- if (strpbrk (argv[i], " \t"))
- {
- int len, trailing_backslash;
- char *temp;
-
- len = strlen (argv[i]);
- trailing_backslash = 0;
-
- /* There is an added complication when an arg with embedded white
- space ends in a backslash (such as in the case of -iprefix arg
- passed to cpp). The resulting quoted strings gets misinterpreted
- by the command interpreter -- it thinks that the ending quote
- is escaped by the trailing backslash and things get confused.
- We handle this case by escaping the trailing backslash, provided
- it was not escaped in the first place. */
- if (len > 1
- && argv[i][len-1] == '\\'
- && argv[i][len-2] != '\\')
- {
- trailing_backslash = 1;
- ++len; /* to escape the final backslash. */
- }
-
- len += 2; /* and for the enclosing quotes. */
-
- temp = xmalloc (len + 1);
- temp[0] = '"';
- strcpy (temp + 1, argv[i]);
- if (trailing_backslash)
- temp[len - 2] = '\\';
- temp[len - 1] = '"';
- temp[len] = '\0';