| 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 DCHECK(program_.empty()); |
| 436 program_ = other.program_; |
| 437 } |
| 438 |
| 439 if (!command_line_string_.empty()) |
| 440 command_line_string_ += L' '; |
| 441 |
| 442 command_line_string_ += other.command_line_string_; |
| 443 |
| 435 std::map<std::string, StringType>::const_iterator i; | 444 std::map<std::string, StringType>::const_iterator i; |
| 436 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) | 445 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) |
| 437 switches_[i->first] = i->second; | 446 switches_[i->first] = i->second; |
| 438 } | 447 } |
| 439 | 448 |
| 440 void CommandLine::PrependWrapper(const std::wstring& wrapper) { | 449 void CommandLine::PrependWrapper(const std::wstring& wrapper) { |
| 441 if (wrapper.empty()) | 450 if (wrapper.empty()) |
| 442 return; | 451 return; |
| 443 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 452 // 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. | 453 // 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) { | 484 void CommandLine::AppendArgNative(const std::string& value) { |
| 476 DCHECK(IsStringUTF8(value)); | 485 DCHECK(IsStringUTF8(value)); |
| 477 argv_.push_back(value); | 486 argv_.push_back(value); |
| 478 } | 487 } |
| 479 | 488 |
| 480 void CommandLine::AppendArguments(const CommandLine& other, | 489 void CommandLine::AppendArguments(const CommandLine& other, |
| 481 bool include_program) { | 490 bool include_program) { |
| 482 // Verify include_program is used correctly. | 491 // Verify include_program is used correctly. |
| 483 // Logic could be shorter but this is clearer. | 492 // Logic could be shorter but this is clearer. |
| 484 DCHECK_EQ(include_program, !other.GetProgram().empty()); | 493 DCHECK_EQ(include_program, !other.GetProgram().empty()); |
| 485 size_t first_arg = include_program ? 0 : 1; | 494 |
| 486 for (size_t i = first_arg; i < other.argv_.size(); ++i) | 495 if (include_program) |
| 496 argv_[0] = other.argv_[0]; |
| 497 |
| 498 // Skip the first arg when copying since it's the program but push all |
| 499 // arguments to our arg vector. |
| 500 for (size_t i = 1; i < other.argv_.size(); ++i) |
| 487 argv_.push_back(other.argv_[i]); | 501 argv_.push_back(other.argv_[i]); |
| 502 |
| 488 std::map<std::string, StringType>::const_iterator i; | 503 std::map<std::string, StringType>::const_iterator i; |
| 489 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) | 504 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) |
| 490 switches_[i->first] = i->second; | 505 switches_[i->first] = i->second; |
| 491 } | 506 } |
| 492 | 507 |
| 493 void CommandLine::PrependWrapper(const std::string& wrapper) { | 508 void CommandLine::PrependWrapper(const std::string& wrapper) { |
| 494 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 509 // 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. | 510 // we don't pretend to do anything fancy, we just split on spaces. |
| 496 std::vector<std::string> wrapper_and_args; | 511 std::vector<std::string> wrapper_and_args; |
| 497 base::SplitString(wrapper, ' ', &wrapper_and_args); | 512 base::SplitString(wrapper, ' ', &wrapper_and_args); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 522 | 537 |
| 523 // private | 538 // private |
| 524 CommandLine::CommandLine() { | 539 CommandLine::CommandLine() { |
| 525 } | 540 } |
| 526 | 541 |
| 527 // static | 542 // static |
| 528 CommandLine* CommandLine::ForCurrentProcessMutable() { | 543 CommandLine* CommandLine::ForCurrentProcessMutable() { |
| 529 DCHECK(current_process_commandline_); | 544 DCHECK(current_process_commandline_); |
| 530 return current_process_commandline_; | 545 return current_process_commandline_; |
| 531 } | 546 } |
| OLD | NEW |