OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 delete reinterpret_cast<File*>(stream); | 247 delete reinterpret_cast<File*>(stream); |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 // Convert all the arguments to UTF8. On Windows, the arguments are | 251 // Convert all the arguments to UTF8. On Windows, the arguments are |
252 // encoded in the current code page and not UTF8. | 252 // encoded in the current code page and not UTF8. |
253 // | 253 // |
254 // Returns true if the arguments are converted. In that case | 254 // Returns true if the arguments are converted. In that case |
255 // each of the arguments need to be deallocated using free. | 255 // each of the arguments need to be deallocated using free. |
256 static bool Utf8ConvertArgv(int argc, char** argv) { | 256 static bool Utf8ConvertArgv(int argc, char** argv) { |
257 bool result = false; | 257 int unicode_argc = 0; |
258 for (int i = 0; i < argc; i++) { | 258 wchar_t** unicode_argv = ShellUtils::GetUnicodeArgv(&unicode_argc); |
259 char* arg = argv[i]; | 259 if (unicode_argv == NULL) return false; |
260 argv[i] = StringUtils::ConsoleStringToUtf8(arg); | 260 for (int i = 0; i < unicode_argc; i++) { |
261 if (i == 0) { | 261 wchar_t* arg = unicode_argv[i]; |
262 result = argv[i] != arg; | 262 argv[i] = StringUtils::WideToUtf8(arg); |
263 } else { | |
264 ASSERT(result == (argv[i] != arg)); | |
265 } | |
266 } | 263 } |
267 return result; | 264 ShellUtils::FreeUnicodeArgv(unicode_argv); |
| 265 return true; |
268 } | 266 } |
269 | 267 |
270 | 268 |
271 // Parse out the command line arguments. Returns -1 if the arguments | 269 // Parse out the command line arguments. Returns -1 if the arguments |
272 // are incorrect, 0 otherwise. | 270 // are incorrect, 0 otherwise. |
273 static int ParseArguments(int argc, | 271 static int ParseArguments(int argc, |
274 char** argv, | 272 char** argv, |
275 CommandLineOptions* vm_options, | 273 CommandLineOptions* vm_options, |
276 char** executable_name, | 274 char** executable_name, |
277 char** script_name, | 275 char** script_name, |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 Dart_ShutdownIsolate(); | 787 Dart_ShutdownIsolate(); |
790 // Terminate process exit-code handler. | 788 // Terminate process exit-code handler. |
791 Process::TerminateExitCodeHandler(); | 789 Process::TerminateExitCodeHandler(); |
792 // Free copied argument strings if converted. | 790 // Free copied argument strings if converted. |
793 if (argv_converted) { | 791 if (argv_converted) { |
794 for (int i = 0; i < argc; i++) free(argv[i]); | 792 for (int i = 0; i < argc; i++) free(argv[i]); |
795 } | 793 } |
796 | 794 |
797 return 0; | 795 return 0; |
798 } | 796 } |
OLD | NEW |