home *** CD-ROM | disk | FTP | other *** search
- Fri Nov 5 03:55:13 1999 Mumit Khan <khan@xraylith.wisc.edu>
-
- * pexecute.c (fix_argv): Handle embedded whitespace in args.
-
- Index: gcc-2.95.2/libiberty/pexecute.c
- ===================================================================
- RCS file: /homes/khan/src/CVSROOT/gcc-2.95.2/libiberty/pexecute.c,v
- retrieving revision 1.1.1.1
- diff -u -3 -p -r1.1.1.1 pexecute.c
- --- gcc-2.95.2/libiberty/pexecute.c 1999/11/05 01:10:14 1.1.1.1
- +++ gcc-2.95.2/libiberty/pexecute.c 1999/11/05 23:56:15
- @@ -252,30 +252,44 @@ fix_argv (argvec)
- {
- int i;
-
- - for (i = 1; argvec[i] != 0; i++)
- + for (i = 0; argvec[i] != 0; i++)
- {
- - int len, j;
- - char *temp, *newtemp;
- -
- - temp = argvec[i];
- - len = strlen (temp);
- - for (j = 0; j < len; j++)
- + if (strpbrk (argvec[i], " \t"))
- {
- - 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++;
- - }
- - }
- + int len, trailing_backslash;
- + char *temp, *newtemp;
- +
- + len = strlen (argvec[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
- + && argvec[i][len-1] == '\\'
- + && argvec[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, argvec[i]);
- + if (trailing_backslash)
- + temp[len-2] = '\\';
- + temp[len-1] = '"';
- + temp[len] = '\0';
-
- - argvec[i] = temp;
- - }
- + argvec[i] = temp;
- + }
- + }
-
- return (const char * const *) argvec;
- }
-