OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_FREEBSD) | 10 #elif defined(OS_FREEBSD) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Lowercase a string. This is used to lowercase switch names. | 45 // Lowercase a string. This is used to lowercase switch names. |
46 // Is this what we really want? It seems crazy to me. I've left it in | 46 // Is this what we really want? It seems crazy to me. I've left it in |
47 // for backwards compatibility on Windows. | 47 // for backwards compatibility on Windows. |
48 static void Lowercase(std::string* parameter) { | 48 static void Lowercase(std::string* parameter) { |
49 transform(parameter->begin(), parameter->end(), parameter->begin(), | 49 transform(parameter->begin(), parameter->end(), parameter->begin(), |
50 tolower); | 50 tolower); |
51 } | 51 } |
52 #endif | 52 #endif |
53 | 53 |
54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 55 CommandLine::CommandLine(ArgumentsOnly args_only) { |
| 56 } |
| 57 |
55 void CommandLine::ParseFromString(const std::wstring& command_line) { | 58 void CommandLine::ParseFromString(const std::wstring& command_line) { |
56 TrimWhitespace(command_line, TRIM_ALL, &command_line_string_); | 59 TrimWhitespace(command_line, TRIM_ALL, &command_line_string_); |
57 | 60 |
58 if (command_line_string_.empty()) | 61 if (command_line_string_.empty()) |
59 return; | 62 return; |
60 | 63 |
61 int num_args = 0; | 64 int num_args = 0; |
62 wchar_t** args = NULL; | 65 wchar_t** args = NULL; |
63 | 66 |
64 args = CommandLineToArgvW(command_line_string_.c_str(), &num_args); | 67 args = CommandLineToArgvW(command_line_string_.c_str(), &num_args); |
(...skipping 29 matching lines...) Expand all Loading... |
94 LocalFree(args); | 97 LocalFree(args); |
95 } | 98 } |
96 | 99 |
97 CommandLine::CommandLine(const FilePath& program) { | 100 CommandLine::CommandLine(const FilePath& program) { |
98 if (!program.empty()) { | 101 if (!program.empty()) { |
99 program_ = program.value(); | 102 program_ = program.value(); |
100 command_line_string_ = L'"' + program.value() + L'"'; | 103 command_line_string_ = L'"' + program.value() + L'"'; |
101 } | 104 } |
102 } | 105 } |
103 | 106 |
104 // Deprecated version | 107 #elif defined(OS_POSIX) |
105 CommandLine::CommandLine(const std::wstring& program) { | 108 CommandLine::CommandLine(ArgumentsOnly args_only) { |
106 if (!program.empty()) { | 109 // Push an empty argument, because we always assume argv_[0] is a program. |
107 program_ = program; | 110 argv_.push_back(""); |
108 command_line_string_ = L'"' + program + L'"'; | |
109 } | |
110 } | 111 } |
111 #elif defined(OS_POSIX) | 112 |
112 void CommandLine::InitFromArgv(int argc, const char* const* argv) { | 113 void CommandLine::InitFromArgv(int argc, const char* const* argv) { |
113 for (int i = 0; i < argc; ++i) | 114 for (int i = 0; i < argc; ++i) |
114 argv_.push_back(argv[i]); | 115 argv_.push_back(argv[i]); |
115 InitFromArgv(argv_); | 116 InitFromArgv(argv_); |
116 } | 117 } |
117 | 118 |
118 void CommandLine::InitFromArgv(const std::vector<std::string>& argv) { | 119 void CommandLine::InitFromArgv(const std::vector<std::string>& argv) { |
119 argv_ = argv; | 120 argv_ = argv; |
120 bool parse_switches = true; | 121 bool parse_switches = true; |
121 for (size_t i = 1; i < argv_.size(); ++i) { | 122 for (size_t i = 1; i < argv_.size(); ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
138 } else { | 139 } else { |
139 loose_values_.push_back(arg); | 140 loose_values_.push_back(arg); |
140 } | 141 } |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 CommandLine::CommandLine(const FilePath& program) { | 145 CommandLine::CommandLine(const FilePath& program) { |
145 argv_.push_back(program.value()); | 146 argv_.push_back(program.value()); |
146 } | 147 } |
147 | 148 |
148 // Deprecated version | |
149 CommandLine::CommandLine(const std::wstring& program) { | |
150 argv_.push_back(base::SysWideToNativeMB(program)); | |
151 } | |
152 #endif | 149 #endif |
153 | 150 |
154 // static | 151 // static |
155 bool CommandLine::IsSwitch(const StringType& parameter_string, | 152 bool CommandLine::IsSwitch(const StringType& parameter_string, |
156 std::string* switch_string, | 153 std::string* switch_string, |
157 StringType* switch_value) { | 154 StringType* switch_value) { |
158 switch_string->clear(); | 155 switch_string->clear(); |
159 switch_value->clear(); | 156 switch_value->clear(); |
160 | 157 |
161 for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) { | 158 for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 void CommandLine::PrependWrapper(const std::wstring& wrapper_wide) { | 393 void CommandLine::PrependWrapper(const std::wstring& wrapper_wide) { |
397 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 394 // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
398 // we don't pretend to do anything fancy, we just split on spaces. | 395 // we don't pretend to do anything fancy, we just split on spaces. |
399 const std::string wrapper = base::SysWideToNativeMB(wrapper_wide); | 396 const std::string wrapper = base::SysWideToNativeMB(wrapper_wide); |
400 std::vector<std::string> wrapper_and_args; | 397 std::vector<std::string> wrapper_and_args; |
401 SplitString(wrapper, ' ', &wrapper_and_args); | 398 SplitString(wrapper, ' ', &wrapper_and_args); |
402 argv_.insert(argv_.begin(), wrapper_and_args.begin(), wrapper_and_args.end()); | 399 argv_.insert(argv_.begin(), wrapper_and_args.begin(), wrapper_and_args.end()); |
403 } | 400 } |
404 | 401 |
405 #endif | 402 #endif |
OLD | NEW |