OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 command_line_string_.append(L" "); | 424 command_line_string_.append(L" "); |
425 command_line_string_.append(WindowsStyleQuote(value)); | 425 command_line_string_.append(WindowsStyleQuote(value)); |
426 args_.push_back(value); | 426 args_.push_back(value); |
427 } | 427 } |
428 | 428 |
429 void CommandLine::AppendArguments(const CommandLine& other, | 429 void CommandLine::AppendArguments(const CommandLine& other, |
430 bool include_program) { | 430 bool include_program) { |
431 // Verify include_program is used correctly. | 431 // Verify include_program is used correctly. |
432 // Logic could be shorter but this is clearer. | 432 // Logic could be shorter but this is clearer. |
433 DCHECK_EQ(include_program, !other.GetProgram().empty()); | 433 DCHECK_EQ(include_program, !other.GetProgram().empty()); |
434 command_line_string_ += L" " + other.command_line_string_; | 434 if (include_program) |
| 435 program_ = other.program_; |
| 436 |
| 437 if (!command_line_string_.empty()) |
| 438 command_line_string_ += L' '; |
| 439 |
| 440 command_line_string_ += other.command_line_string_; |
| 441 |
435 std::map<std::string, StringType>::const_iterator i; | 442 std::map<std::string, StringType>::const_iterator i; |
436 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) | 443 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) |
437 switches_[i->first] = i->second; | 444 switches_[i->first] = i->second; |
438 } | 445 } |
439 | 446 |
440 void CommandLine::PrependWrapper(const std::wstring& wrapper) { | 447 void CommandLine::PrependWrapper(const std::wstring& wrapper) { |
441 if (wrapper.empty()) | 448 if (wrapper.empty()) |
442 return; | 449 return; |
443 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 450 // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
444 // we don't pretend to do anything fancy, we just split on spaces. | 451 // we don't pretend to do anything fancy, we just split on spaces. |
(...skipping 30 matching lines...) Expand all Loading... |
475 void CommandLine::AppendArgNative(const std::string& value) { | 482 void CommandLine::AppendArgNative(const std::string& value) { |
476 DCHECK(IsStringUTF8(value)); | 483 DCHECK(IsStringUTF8(value)); |
477 argv_.push_back(value); | 484 argv_.push_back(value); |
478 } | 485 } |
479 | 486 |
480 void CommandLine::AppendArguments(const CommandLine& other, | 487 void CommandLine::AppendArguments(const CommandLine& other, |
481 bool include_program) { | 488 bool include_program) { |
482 // Verify include_program is used correctly. | 489 // Verify include_program is used correctly. |
483 // Logic could be shorter but this is clearer. | 490 // Logic could be shorter but this is clearer. |
484 DCHECK_EQ(include_program, !other.GetProgram().empty()); | 491 DCHECK_EQ(include_program, !other.GetProgram().empty()); |
485 size_t first_arg = include_program ? 0 : 1; | 492 |
486 for (size_t i = first_arg; i < other.argv_.size(); ++i) | 493 if (include_program) |
| 494 argv_[0] = other.argv_[0]; |
| 495 |
| 496 // Skip the first arg when copying since it's the program but push all |
| 497 // arguments to our arg vector. |
| 498 for (size_t i = 1; i < other.argv_.size(); ++i) |
487 argv_.push_back(other.argv_[i]); | 499 argv_.push_back(other.argv_[i]); |
| 500 |
488 std::map<std::string, StringType>::const_iterator i; | 501 std::map<std::string, StringType>::const_iterator i; |
489 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) | 502 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) |
490 switches_[i->first] = i->second; | 503 switches_[i->first] = i->second; |
491 } | 504 } |
492 | 505 |
493 void CommandLine::PrependWrapper(const std::string& wrapper) { | 506 void CommandLine::PrependWrapper(const std::string& wrapper) { |
494 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 507 // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
495 // we don't pretend to do anything fancy, we just split on spaces. | 508 // we don't pretend to do anything fancy, we just split on spaces. |
496 std::vector<std::string> wrapper_and_args; | 509 std::vector<std::string> wrapper_and_args; |
497 base::SplitString(wrapper, ' ', &wrapper_and_args); | 510 base::SplitString(wrapper, ' ', &wrapper_and_args); |
(...skipping 24 matching lines...) Expand all Loading... |
522 | 535 |
523 // private | 536 // private |
524 CommandLine::CommandLine() { | 537 CommandLine::CommandLine() { |
525 } | 538 } |
526 | 539 |
527 // static | 540 // static |
528 CommandLine* CommandLine::ForCurrentProcessMutable() { | 541 CommandLine* CommandLine::ForCurrentProcessMutable() { |
529 DCHECK(current_process_commandline_); | 542 DCHECK(current_process_commandline_); |
530 return current_process_commandline_; | 543 return current_process_commandline_; |
531 } | 544 } |
OLD | NEW |