- Timestamp:
- Jan 23, 2015 12:52:55 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/redirect.c
r2728 r2747 60 60 * Arguments": http://msdn.microsoft.com/en-us/library/a1y7w461.aspx 61 61 * 62 * @param argc The argument count. 63 * @param argv The argument vector. 62 * @param argc The argument count. 63 * @param argv The argument vector. 64 * @param fWatcomBrainDamage Set if we're catering for wcc, wcc386 or similar 65 * OpenWatcom tools. They seem to follow some 66 * ancient or home made quoting convention. 64 67 */ 65 static void quoteArguments(int argc, char **argv )68 static void quoteArguments(int argc, char **argv, int fWatcomBrainDamage) 66 69 { 67 70 int i; … … 71 74 size_t cchOrg = strlen(pszOrg); 72 75 const char *pszQuotes = (const char *)memchr(pszOrg, '"', cchOrg); 76 const char *pszProblem = NULL; 73 77 if ( pszQuotes 74 78 || cchOrg == 0 75 || memchr(pszOrg, ' ', cchOrg)76 || memchr(pszOrg, '\t', cchOrg)77 || memchr(pszOrg, '\n', cchOrg)78 || memchr(pszOrg, '\r', cchOrg)79 || memchr(pszOrg, '&', cchOrg)80 || memchr(pszOrg, '>', cchOrg)81 || memchr(pszOrg, '<', cchOrg)82 || memchr(pszOrg, '|', cchOrg)83 || memchr(pszOrg, '%', cchOrg)84 || memchr(pszOrg, '\'', cchOrg)85 || memchr(pszOrg, '=', cchOrg)79 || (pszProblem = (const char *)memchr(pszOrg, ' ', cchOrg)) != NULL 80 || (pszProblem = (const char *)memchr(pszOrg, '\t', cchOrg)) != NULL 81 || (pszProblem = (const char *)memchr(pszOrg, '\n', cchOrg)) != NULL 82 || (pszProblem = (const char *)memchr(pszOrg, '\r', cchOrg)) != NULL 83 || (pszProblem = (const char *)memchr(pszOrg, '&', cchOrg)) != NULL 84 || (pszProblem = (const char *)memchr(pszOrg, '>', cchOrg)) != NULL 85 || (pszProblem = (const char *)memchr(pszOrg, '<', cchOrg)) != NULL 86 || (pszProblem = (const char *)memchr(pszOrg, '|', cchOrg)) != NULL 87 || (pszProblem = (const char *)memchr(pszOrg, '%', cchOrg)) != NULL 88 || (pszProblem = (const char *)memchr(pszOrg, '\'', cchOrg)) != NULL 89 || (pszProblem = (const char *)memchr(pszOrg, '=', cchOrg)) != NULL 86 90 ) 87 91 { … … 92 96 93 97 argv[i] = pszNew; 98 99 /* Watcom does not grok "-i=c:\program files\watcom\h", it thing 100 it's a source specification. The quote must follow the equal. */ 101 if (fWatcomBrainDamage) 102 { 103 size_t cchUnquoted = 0; 104 if (pszOrg[0] == '@') /* Response file quoting: @"file name.rsp" */ 105 cchUnquoted = 1; 106 else if (pszOrg[0] == '-' || pszOrg[0] == '/') /* Switch quoting. */ 107 { 108 const char *pszNeedQuoting = (const char *)memchr(pszOrg, '=', cchOrg); 109 if ( pszNeedQuoting == NULL 110 || (uintptr_t)pszNeedQuoting > (uintptr_t)(pszProblem ? pszProblem : pszQuotes)) 111 pszNeedQuoting = pszProblem ? pszProblem : pszQuotes; 112 else 113 pszNeedQuoting++; 114 cchUnquoted = pszNeedQuoting - pszOrg; 115 } 116 if (cchUnquoted) 117 { 118 memcpy(pszNew, pszOrg, cchUnquoted); 119 pszNew += cchUnquoted; 120 pszOrg += cchUnquoted; 121 cchOrg -= cchUnquoted; 122 } 123 } 94 124 95 125 *pszNew++ = '"'; … … 188 218 { 189 219 fprintf(pOut, 190 "usage: %s [-[rwa+tb]<fd> <file>] [-c<fd>] [-Z] [-E <var=val>] [-C <dir>] -- <program> [args]\n"220 "usage: %s [-[rwa+tb]<fd> <file>] [-c<fd>] [-Z] [-E <var=val>] [-C <dir>] [--wcc-brain-damage] -- <program> [args]\n" 191 221 " or: %s --help\n" 192 222 " or: %s --version\n" … … 208 238 "effect, so be careful where you put it.\n" 209 239 "\n" 240 "The --wcc-brain-damage switch is to work around wcc and wcc386 (Open Watcom)\n" 241 "not following normal quoting conventions on Windows, OS/2, and DOS.\n" 242 "\n" 210 243 "This command was originally just a quick hack to avoid invoking the shell\n" 211 244 "on Windows (cygwin) where forking is very expensive and has exhibited\n" … … 226 259 FILE *pStdErr = stderr; 227 260 FILE *pStdOut = stdout; 261 int fWatcomBrainDamage = 0; 228 262 229 263 /* … … 262 296 else if (!strcmp(psz, "-close")) 263 297 psz = "c"; 298 else if (!strcmp(psz, "-wcc-brain-damage")) 299 { 300 fWatcomBrainDamage = 1; 301 continue; 302 } 264 303 } 265 304 … … 710 749 711 750 /* MSC is a PITA since it refuses to quote the arguments... */ 712 quoteArguments(argc - i, &argv[i] );751 quoteArguments(argc - i, &argv[i], fWatcomBrainDamage); 713 752 rc = _spawnvp(_P_WAIT, argv[i], &argv[i]); 714 753 if (rc == -1 && pStdErr)
Note:
See TracChangeset
for help on using the changeset viewer.