home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / patches / gcc-2_95_2-x86-win32-patches.zi / gcc-2.95.2-patches / broken-down / gcc-2.95.2-pexecute.diff < prev    next >
Encoding:
Text File  |  1999-11-08  |  2.3 KB  |  78 lines

  1. Fri Nov  5 03:55:13 1999  Mumit Khan  <khan@xraylith.wisc.edu>
  2.  
  3.     * pexecute.c (fix_argv): Handle embedded whitespace in args.
  4.  
  5. Index: gcc-2.95.2/libiberty/pexecute.c
  6. ===================================================================
  7. RCS file: /homes/khan/src/CVSROOT/gcc-2.95.2/libiberty/pexecute.c,v
  8. retrieving revision 1.1.1.1
  9. diff -u -3 -p -r1.1.1.1 pexecute.c
  10. --- gcc-2.95.2/libiberty/pexecute.c    1999/11/05 01:10:14    1.1.1.1
  11. +++ gcc-2.95.2/libiberty/pexecute.c    1999/11/05 23:56:15
  12. @@ -252,30 +252,44 @@ fix_argv (argvec)
  13.  {
  14.    int i;
  15.  
  16. -  for (i = 1; argvec[i] != 0; i++)
  17. +  for (i = 0; argvec[i] != 0; i++)
  18.      {
  19. -      int len, j;
  20. -      char *temp, *newtemp;
  21. -
  22. -      temp = argvec[i];
  23. -      len = strlen (temp);
  24. -      for (j = 0; j < len; j++)
  25. +      if (strpbrk (argvec[i], " \t"))
  26.          {
  27. -          if (temp[j] == '"')
  28. -            {
  29. -              newtemp = xmalloc (len + 2);
  30. -              strncpy (newtemp, temp, j);
  31. -              newtemp [j] = '\\';
  32. -              strncpy (&newtemp [j+1], &temp [j], len-j);
  33. -              newtemp [len+1] = 0;
  34. -              temp = newtemp;
  35. -              len++;
  36. -              j++;
  37. -            }
  38. -        }
  39. +      int len, trailing_backslash;
  40. +      char *temp, *newtemp;
  41. +
  42. +      len = strlen (argvec[i]);
  43. +      trailing_backslash = 0;
  44. +
  45. +      /* There is an added complication when an arg with embedded white
  46. +         space ends in a backslash (such as in the case of -iprefix arg
  47. +         passed to cpp). The resulting quoted strings gets misinterpreted
  48. +         by the command interpreter -- it thinks that the ending quote
  49. +         is escaped by the trailing backslash and things get confused. 
  50. +         We handle this case by escaping the trailing backslash, provided
  51. +         it was not escaped in the first place.  */
  52. +      if (len > 1 
  53. +          && argvec[i][len-1] == '\\' 
  54. +          && argvec[i][len-2] != '\\')
  55. +        {
  56. +          trailing_backslash = 1;
  57. +          ++len;            /* to escape the final backslash. */
  58. +        }
  59. +
  60. +      len += 2;            /* and for the enclosing quotes. */
  61. +
  62. +      temp = xmalloc (len + 1);
  63. +      temp[0] = '"';
  64. +      strcpy (temp + 1, argvec[i]);
  65. +      if (trailing_backslash)
  66. +        temp[len-2] = '\\';
  67. +      temp[len-1] = '"';
  68. +      temp[len] = '\0';
  69.  
  70. -        argvec[i] = temp;
  71. -      }
  72. +      argvec[i] = temp;
  73. +    }
  74. +    }
  75.  
  76.    return (const char * const *) argvec;
  77.  }
  78.