Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: base/command_line.cc

Issue 24613003: Allow typing label names on Windows by not treating things that start with slashes as arguments rat… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with base Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/command_line.h ('k') | tools/gn/command_desc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include <windows.h> 19 #include <windows.h>
20 #include <shellapi.h> 20 #include <shellapi.h>
21 #endif 21 #endif
22 22
23 using base::FilePath; 23 using base::FilePath;
24 24
25 CommandLine* CommandLine::current_process_commandline_ = NULL; 25 CommandLine* CommandLine::current_process_commandline_ = NULL;
26 26
27 namespace { 27 namespace {
28 const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); 28 const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--");
29 const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("="); 29 const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("=");
30
30 // Since we use a lazy match, make sure that longer versions (like "--") are 31 // Since we use a lazy match, make sure that longer versions (like "--") are
31 // listed before shorter versions (like "-") of similar prefixes. 32 // listed before shorter versions (like "-") of similar prefixes.
32 #if defined(OS_WIN) 33 #if defined(OS_WIN)
34 // By putting slash last, we can control whether it is treaded as a switch
35 // value by changing the value of switch_prefix_count to be one less than
36 // the array size.
33 const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; 37 const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"};
38 size_t switch_prefix_count = arraysize(kSwitchPrefixes);
scottmg 2013/09/25 18:20:36 nit; don't see a lot of benefit to the const for n
34 #elif defined(OS_POSIX) 39 #elif defined(OS_POSIX)
35 // Unixes don't use slash as a switch. 40 // Unixes don't use slash as a switch.
36 const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; 41 const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"};
42 const size_t switch_prefix_count = arraysize(kSwitchPrefixes);
37 #endif 43 #endif
38 44
39 size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { 45 size_t GetSwitchPrefixLength(const CommandLine::StringType& string) {
40 for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) { 46 for (size_t i = 0; i < switch_prefix_count; ++i) {
41 CommandLine::StringType prefix(kSwitchPrefixes[i]); 47 CommandLine::StringType prefix(kSwitchPrefixes[i]);
42 if (string.compare(0, prefix.length(), prefix) == 0) 48 if (string.compare(0, prefix.length(), prefix) == 0)
43 return prefix.length(); 49 return prefix.length();
44 } 50 }
45 return 0; 51 return 0;
46 } 52 }
47 53
48 // Fills in |switch_string| and |switch_value| if |string| is a switch. 54 // Fills in |switch_string| and |switch_value| if |string| is a switch.
49 // This will preserve the input switch prefix in the output |switch_string|. 55 // This will preserve the input switch prefix in the output |switch_string|.
50 bool IsSwitch(const CommandLine::StringType& string, 56 bool IsSwitch(const CommandLine::StringType& string,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 168
163 CommandLine::CommandLine(const StringVector& argv) 169 CommandLine::CommandLine(const StringVector& argv)
164 : argv_(1), 170 : argv_(1),
165 begin_args_(1) { 171 begin_args_(1) {
166 InitFromArgv(argv); 172 InitFromArgv(argv);
167 } 173 }
168 174
169 CommandLine::~CommandLine() { 175 CommandLine::~CommandLine() {
170 } 176 }
171 177
178 #if defined(OS_WIN)
179 // static
180 void CommandLine::set_slash_is_not_a_switch() {
181 // The last switch prefix should be slash, so adjust the size to skip it.
182 DCHECK(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/") == 0);
183 switch_prefix_count = arraysize(kSwitchPrefixes) - 1;
184 }
185 #endif
186
172 // static 187 // static
173 bool CommandLine::Init(int argc, const char* const* argv) { 188 bool CommandLine::Init(int argc, const char* const* argv) {
174 if (current_process_commandline_) { 189 if (current_process_commandline_) {
175 // If this is intentional, Reset() must be called first. If we are using 190 // If this is intentional, Reset() must be called first. If we are using
176 // the shared build mode, we have to share a single object across multiple 191 // the shared build mode, we have to share a single object across multiple
177 // shared libraries. 192 // shared libraries.
178 return false; 193 return false;
179 } 194 }
180 195
181 current_process_commandline_ = new CommandLine(NO_PROGRAM); 196 current_process_commandline_ = new CommandLine(NO_PROGRAM);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 int num_args = 0; 430 int num_args = 0;
416 wchar_t** args = NULL; 431 wchar_t** args = NULL;
417 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); 432 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args);
418 433
419 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " 434 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: "
420 << command_line; 435 << command_line;
421 InitFromArgv(num_args, args); 436 InitFromArgv(num_args, args);
422 LocalFree(args); 437 LocalFree(args);
423 } 438 }
424 #endif 439 #endif
OLDNEW
« no previous file with comments | « base/command_line.h ('k') | tools/gn/command_desc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698