| 435 | #define ISWHITE(x) ((x)==(' ') || (x)==('\t') || (x)==('\n') || (x)==('\r') ) |
| 436 | |
| 437 | static void ParseCommandLine(LPWSTR psrc, Array<String> &out) |
| 438 | { |
| 439 | unsigned int argcount = 1; // discovery of arg0 is unconditional, below |
| 440 | |
| 441 | bool fInQuotes; |
| 442 | int iSlash; |
| 443 | |
| 444 | /* A quoted program name is handled here. The handling is much |
| 445 | simpler than for other arguments. Basically, whatever lies |
| 446 | between the leading double-quote and next one, or a terminal null |
| 447 | character is simply accepted. Fancier handling is not required |
| 448 | because the program name must be a legal NTFS/HPFS file name. |
| 449 | Note that the double-quote characters are not copied, nor do they |
| 450 | contribute to numchars. |
| 451 | |
| 452 | This "simplification" is necessary for compatibility reasons even |
| 453 | though it leads to mishandling of certain cases. For example, |
| 454 | "c:\tests\"test.exe will result in an arg0 of c:\tests\ and an |
| 455 | arg1 of test.exe. In any rational world this is incorrect, but |
| 456 | we need to preserve compatibility. |
| 457 | */ |
| 458 | |
| 459 | LPWSTR pStart = psrc; |
| 460 | bool skipQuote = false; |
| 461 | |
| 462 | // Pairs of double-quotes vanish... |
| 463 | while(psrc[0]=='\"' && psrc[1]=='\"') |
| 464 | psrc += 2; |
| 465 | |
| 466 | if (*psrc == '\"') |
| 467 | { |
| 468 | // scan from just past the first double-quote through the next |
| 469 | // double-quote, or up to a null, whichever comes first |
| 470 | psrc++; |
| 471 | while ((*psrc!= '\"') && (*psrc != '\0')) |
| 472 | { |
| 473 | psrc++; |
| 474 | // Pairs of double-quotes vanish... |
| 475 | while(psrc[0]=='\"' && psrc[1]=='\"') |
| 476 | psrc += 2; |
| 477 | } |
| 478 | |
| 479 | skipQuote = true; |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | /* Not a quoted program name */ |
| 484 | |
| 485 | while (!ISWHITE(*psrc) && *psrc != '\0') |
| 486 | psrc++; |
| 487 | } |
| 488 | |
| 489 | // We have now identified arg0 as pStart (or pStart+1 if we have a leading |
| 490 | // quote) through psrc-1 inclusive |
| 491 | if (skipQuote) |
| 492 | pStart++; |
| 493 | String arg0(""); |
| 494 | while (pStart < psrc) |
no test coverage detected