| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 begin_args_ = 1; | 221 begin_args_ = 1; |
| 222 SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); | 222 SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); |
| 223 AppendSwitchesAndArguments(*this, argv); | 223 AppendSwitchesAndArguments(*this, argv); |
| 224 } | 224 } |
| 225 | 225 |
| 226 CommandLine::StringType CommandLine::GetCommandLineString() const { | 226 CommandLine::StringType CommandLine::GetCommandLineString() const { |
| 227 StringType string(argv_[0]); | 227 StringType string(argv_[0]); |
| 228 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| 229 string = QuoteForCommandLineToArgvW(string); | 229 string = QuoteForCommandLineToArgvW(string); |
| 230 #endif | 230 #endif |
| 231 StringType params(GetArgumentsString()); |
| 232 if (!params.empty()) { |
| 233 string.append(StringType(FILE_PATH_LITERAL(" "))); |
| 234 string.append(params); |
| 235 } |
| 236 return string; |
| 237 } |
| 238 |
| 239 CommandLine::StringType CommandLine::GetArgumentsString() const { |
| 240 StringType params; |
| 231 // Append switches and arguments. | 241 // Append switches and arguments. |
| 232 bool parse_switches = true; | 242 bool parse_switches = true; |
| 233 for (size_t i = 1; i < argv_.size(); ++i) { | 243 for (size_t i = 1; i < argv_.size(); ++i) { |
| 234 CommandLine::StringType arg = argv_[i]; | 244 StringType arg = argv_[i]; |
| 235 CommandLine::StringType switch_string; | 245 StringType switch_string; |
| 236 CommandLine::StringType switch_value; | 246 StringType switch_value; |
| 237 parse_switches &= arg != kSwitchTerminator; | 247 parse_switches &= arg != kSwitchTerminator; |
| 238 string.append(StringType(FILE_PATH_LITERAL(" "))); | 248 if (i > 1) |
| 249 params.append(StringType(FILE_PATH_LITERAL(" "))); |
| 239 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { | 250 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
| 240 string.append(switch_string); | 251 params.append(switch_string); |
| 241 if (!switch_value.empty()) { | 252 if (!switch_value.empty()) { |
| 242 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
| 243 switch_value = QuoteForCommandLineToArgvW(switch_value); | 254 switch_value = QuoteForCommandLineToArgvW(switch_value); |
| 244 #endif | 255 #endif |
| 245 string.append(kSwitchValueSeparator + switch_value); | 256 params.append(kSwitchValueSeparator + switch_value); |
| 246 } | 257 } |
| 247 } | 258 } |
| 248 else { | 259 else { |
| 249 #if defined(OS_WIN) | 260 #if defined(OS_WIN) |
| 250 arg = QuoteForCommandLineToArgvW(arg); | 261 arg = QuoteForCommandLineToArgvW(arg); |
| 251 #endif | 262 #endif |
| 252 string.append(arg); | 263 params.append(arg); |
| 253 } | 264 } |
| 254 } | 265 } |
| 255 return string; | 266 return params; |
| 256 } | 267 } |
| 257 | 268 |
| 258 FilePath CommandLine::GetProgram() const { | 269 FilePath CommandLine::GetProgram() const { |
| 259 return FilePath(argv_[0]); | 270 return FilePath(argv_[0]); |
| 260 } | 271 } |
| 261 | 272 |
| 262 void CommandLine::SetProgram(const FilePath& program) { | 273 void CommandLine::SetProgram(const FilePath& program) { |
| 263 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); | 274 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); |
| 264 } | 275 } |
| 265 | 276 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 int num_args = 0; | 407 int num_args = 0; |
| 397 wchar_t** args = NULL; | 408 wchar_t** args = NULL; |
| 398 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); | 409 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); |
| 399 | 410 |
| 400 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " | 411 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " |
| 401 << command_line; | 412 << command_line; |
| 402 InitFromArgv(num_args, args); | 413 InitFromArgv(num_args, args); |
| 403 LocalFree(args); | 414 LocalFree(args); |
| 404 } | 415 } |
| 405 #endif | 416 #endif |
| OLD | NEW |