| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (strncmp(option, name, length) == 0) { | 255 if (strncmp(option, name, length) == 0) { |
| 256 return main_options[i].process(option + length); | 256 return main_options[i].process(option + length); |
| 257 } | 257 } |
| 258 i += 1; | 258 i += 1; |
| 259 name = main_options[i].option_name; | 259 name = main_options[i].option_name; |
| 260 } | 260 } |
| 261 return false; | 261 return false; |
| 262 } | 262 } |
| 263 | 263 |
| 264 | 264 |
| 265 static void* OpenFile(const char* name) { | |
| 266 File* file = File::Open(name, File::kWriteTruncate); | |
| 267 ASSERT(file != NULL); | |
| 268 return reinterpret_cast<void*>(file); | |
| 269 } | |
| 270 | |
| 271 | |
| 272 static void WriteFile(const void* buffer, intptr_t num_bytes, void* stream) { | |
| 273 ASSERT(stream != NULL); | |
| 274 File* file_stream = reinterpret_cast<File*>(stream); | |
| 275 bool bytes_written = file_stream->WriteFully(buffer, num_bytes); | |
| 276 ASSERT(bytes_written); | |
| 277 } | |
| 278 | |
| 279 | |
| 280 static void CloseFile(void* stream) { | |
| 281 delete reinterpret_cast<File*>(stream); | |
| 282 } | |
| 283 | |
| 284 | |
| 285 // Convert all the arguments to UTF8. On Windows, the arguments are | 265 // Convert all the arguments to UTF8. On Windows, the arguments are |
| 286 // encoded in the current code page and not UTF8. | 266 // encoded in the current code page and not UTF8. |
| 287 // | 267 // |
| 288 // Returns true if the arguments are converted. In that case | 268 // Returns true if the arguments are converted. In that case |
| 289 // each of the arguments need to be deallocated using free. | 269 // each of the arguments need to be deallocated using free. |
| 290 static bool Utf8ConvertArgv(int argc, char** argv) { | 270 static bool Utf8ConvertArgv(int argc, char** argv) { |
| 291 int unicode_argc = 0; | 271 int unicode_argc = 0; |
| 292 wchar_t** unicode_argv = ShellUtils::GetUnicodeArgv(&unicode_argc); | 272 wchar_t** unicode_argv = ShellUtils::GetUnicodeArgv(&unicode_argc); |
| 293 if (unicode_argv == NULL) return false; | 273 if (unicode_argv == NULL) return false; |
| 294 for (int i = 0; i < unicode_argc; i++) { | 274 for (int i = 0; i < unicode_argc; i++) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 } else { | 705 } else { |
| 726 PrintUsage(); | 706 PrintUsage(); |
| 727 return kErrorExitCode; | 707 return kErrorExitCode; |
| 728 } | 708 } |
| 729 } | 709 } |
| 730 | 710 |
| 731 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 711 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 732 | 712 |
| 733 // Initialize the Dart VM. | 713 // Initialize the Dart VM. |
| 734 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 714 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 735 OpenFile, WriteFile, CloseFile)) { | 715 DartUtils::OpenFile, |
| 716 DartUtils::ReadFile, |
| 717 DartUtils::WriteFile, |
| 718 DartUtils::CloseFile)) { |
| 736 fprintf(stderr, "%s", "VM initialization failed\n"); | 719 fprintf(stderr, "%s", "VM initialization failed\n"); |
| 737 fflush(stderr); | 720 fflush(stderr); |
| 738 return kErrorExitCode; | 721 return kErrorExitCode; |
| 739 } | 722 } |
| 740 | 723 |
| 741 DartUtils::SetOriginalWorkingDirectory(); | 724 DartUtils::SetOriginalWorkingDirectory(); |
| 742 | 725 |
| 743 // Start the debugger wire protocol handler if necessary. | 726 // Start the debugger wire protocol handler if necessary. |
| 744 if (start_debugger) { | 727 if (start_debugger) { |
| 745 ASSERT(debug_port != 0); | 728 ASSERT(debug_port != 0); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 847 |
| 865 return Process::GlobalExitCode(); | 848 return Process::GlobalExitCode(); |
| 866 } | 849 } |
| 867 | 850 |
| 868 } // namespace bin | 851 } // namespace bin |
| 869 } // namespace dart | 852 } // namespace dart |
| 870 | 853 |
| 871 int main(int argc, char** argv) { | 854 int main(int argc, char** argv) { |
| 872 return dart::bin::main(argc, argv); | 855 return dart::bin::main(argc, argv); |
| 873 } | 856 } |
| OLD | NEW |