Chromium Code Reviews| 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 // This class works with command lines: building and parsing. | 5 // This class works with command lines: building and parsing. |
| 6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. | 6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. |
| 7 // Switches will precede all other arguments without switch prefixes. | 7 // Switches will precede all other arguments without switch prefixes. |
| 8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". | 8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". |
| 9 // An argument of "--" will terminate switch parsing during initialization, | 9 // An argument of "--" will terminate switch parsing during initialization, |
| 10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. | 10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
| 64 // By default this class will treat command-line arguments beginning with | 64 // By default this class will treat command-line arguments beginning with |
| 65 // slashes as switches on Windows, but not other platforms. | 65 // slashes as switches on Windows, but not other platforms. |
| 66 // | 66 // |
| 67 // If this behavior is inappropriate for your application, you can call this | 67 // If this behavior is inappropriate for your application, you can call this |
| 68 // function BEFORE initializing the current process' global command line | 68 // function BEFORE initializing the current process' global command line |
| 69 // object and the behavior will be the same as Posix systems (only hyphens | 69 // object and the behavior will be the same as Posix systems (only hyphens |
| 70 // begin switches, everything else will be an arg). | 70 // begin switches, everything else will be an arg). |
| 71 static void set_slash_is_not_a_switch(); | 71 static void set_slash_is_not_a_switch(); |
| 72 | |
| 73 // Normally when the CommandLine singleton is initialized it gets the command | |
| 74 // line via the GetCommandLineW API and then uses the shell32 API | |
| 75 // CommandLineToArgVW to parse the command line and convert it back to argc | |
|
scottmg
2016/06/18 17:36:57
CommandLineToArgvW
ananta
2016/06/20 19:08:03
Done.
| |
| 76 // and argv. We may want to honor the command line arguments passed in via | |
| 77 // main for console tests. The |honor_args_for_testing| parameter controls | |
| 78 // that behavior. | |
| 79 static void set_honor_command_line_args_for_testing( | |
|
scottmg
2016/06/18 17:36:57
Maybe "set_honor_argv_for_testing" would be more a
ananta
2016/06/20 19:08:03
Done.
| |
| 80 bool honor_args_for_testing); | |
| 72 #endif | 81 #endif |
| 73 | 82 |
| 74 // Initialize the current process CommandLine singleton. On Windows, ignores | 83 // Initialize the current process CommandLine singleton. On Windows, ignores |
| 75 // its arguments (we instead parse GetCommandLineW() directly) because we | 84 // its arguments (we instead parse GetCommandLineW() directly) because we |
| 76 // don't trust the CRT's parsing of the command line, but it still must be | 85 // don't trust the CRT's parsing of the command line, but it still must be |
| 77 // called to set up the command line. Returns false if initialization has | 86 // called to set up the command line. Returns false if initialization has |
| 78 // already occurred, and true otherwise. Only the caller receiving a 'true' | 87 // already occurred, and true otherwise. Only the caller receiving a 'true' |
| 79 // return value should take responsibility for calling Reset. | 88 // return value should take responsibility for calling Reset. |
| 80 static bool Init(int argc, const char* const* argv); | 89 static bool Init(int argc, const char* const* argv); |
| 81 | 90 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 // Used for allocation-free lookups. | 251 // Used for allocation-free lookups. |
| 243 StringPieceSwitchMap switches_by_stringpiece_; | 252 StringPieceSwitchMap switches_by_stringpiece_; |
| 244 | 253 |
| 245 // The index after the program and switches, any arguments start here. | 254 // The index after the program and switches, any arguments start here. |
| 246 size_t begin_args_; | 255 size_t begin_args_; |
| 247 }; | 256 }; |
| 248 | 257 |
| 249 } // namespace base | 258 } // namespace base |
| 250 | 259 |
| 251 #endif // BASE_COMMAND_LINE_H_ | 260 #endif // BASE_COMMAND_LINE_H_ |
| OLD | NEW |