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

Side by Side Diff: runtime/bin/main.cc

Issue 11275281: Update dart:io to convert strings between UTF8 and current code page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 1 month 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 | « runtime/bin/file_win.cc ('k') | runtime/bin/platform.h » ('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 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 return false; 225 return false;
226 } 226 }
227 227
228 228
229 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { 229 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) {
230 ASSERT(perf_events_symbols_file != NULL); 230 ASSERT(perf_events_symbols_file != NULL);
231 perf_events_symbols_file->WriteFully(buffer, num_bytes); 231 perf_events_symbols_file->WriteFully(buffer, num_bytes);
232 } 232 }
233 233
234 // Convert all the arguments to UTF8. On Windows, the arguments are
235 // encoded in the current code page and not UTF8.
236 //
237 // Returns true if the arguments are converted. In that case
238 // each of the arguments need to be deallocated using free.
239 static bool Utf8ConvertArgv(int argc, char** argv) {
240 bool result = false;
241 for (int i = 0; i < argc; i++) {
242 char* arg = argv[i];
243 argv[i] = StringUtils::SystemStringToUtf8(arg);
244 if (i == 0) {
245 result = argv[i] != arg;
246 } else {
247 ASSERT(result == (argv[i] != arg));
248 }
249 }
250 return result;
251 }
252
234 253
235 // Parse out the command line arguments. Returns -1 if the arguments 254 // Parse out the command line arguments. Returns -1 if the arguments
236 // are incorrect, 0 otherwise. 255 // are incorrect, 0 otherwise.
237 static int ParseArguments(int argc, 256 static int ParseArguments(int argc,
238 char** argv, 257 char** argv,
239 CommandLineOptions* vm_options, 258 CommandLineOptions* vm_options,
240 char** executable_name, 259 char** executable_name,
241 char** script_name, 260 char** script_name,
242 CommandLineOptions* dart_options, 261 CommandLineOptions* dart_options,
243 bool* print_flags_seen) { 262 bool* print_flags_seen) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 char* script_name; 649 char* script_name;
631 CommandLineOptions vm_options(argc); 650 CommandLineOptions vm_options(argc);
632 CommandLineOptions dart_options(argc); 651 CommandLineOptions dart_options(argc);
633 bool print_flags_seen = false; 652 bool print_flags_seen = false;
634 653
635 // Perform platform specific initialization. 654 // Perform platform specific initialization.
636 if (!Platform::Initialize()) { 655 if (!Platform::Initialize()) {
637 fprintf(stderr, "Initialization failed\n"); 656 fprintf(stderr, "Initialization failed\n");
638 } 657 }
639 658
659 // On Windows, the argv strings are code page encoded and not
660 // utf8. We need to convert them to utf8.
661 bool argv_converted = Utf8ConvertArgv(argc, argv);
662
640 // Parse command line arguments. 663 // Parse command line arguments.
641 if (ParseArguments(argc, 664 if (ParseArguments(argc,
642 argv, 665 argv,
643 &vm_options, 666 &vm_options,
644 &executable_name, 667 &executable_name,
645 &script_name, 668 &script_name,
646 &dart_options, 669 &dart_options,
647 &print_flags_seen) < 0) { 670 &print_flags_seen) < 0) {
648 if (has_help_option) { 671 if (has_help_option) {
649 PrintUsage(); 672 PrintUsage();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 Dart_Handle library = Dart_RootLibrary(); 740 Dart_Handle library = Dart_RootLibrary();
718 if (Dart_IsNull(library)) { 741 if (Dart_IsNull(library)) {
719 return ErrorExit("Unable to find root library for '%s'\n", 742 return ErrorExit("Unable to find root library for '%s'\n",
720 script_name); 743 script_name);
721 } 744 }
722 // Set debug breakpoint if specified on the command line. 745 // Set debug breakpoint if specified on the command line.
723 if (breakpoint_at != NULL) { 746 if (breakpoint_at != NULL) {
724 result = SetBreakpoint(breakpoint_at, library); 747 result = SetBreakpoint(breakpoint_at, library);
725 if (Dart_IsError(result)) { 748 if (Dart_IsError(result)) {
726 return ErrorExit("Error setting breakpoint at '%s': %s\n", 749 return ErrorExit("Error setting breakpoint at '%s': %s\n",
727 breakpoint_at, 750 breakpoint_at,
728 Dart_GetError(result)); 751 Dart_GetError(result));
729 } 752 }
730 } 753 }
731 754
732 // Lookup and invoke the top level main function. 755 // Lookup and invoke the top level main function.
733 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); 756 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
734 if (Dart_IsError(result)) { 757 if (Dart_IsError(result)) {
735 return ErrorExit("%s\n", Dart_GetError(result)); 758 return ErrorExit("%s\n", Dart_GetError(result));
736 } 759 }
737 // Keep handling messages until the last active receive port is closed. 760 // Keep handling messages until the last active receive port is closed.
738 result = Dart_RunLoop(); 761 result = Dart_RunLoop();
739 if (Dart_IsError(result)) { 762 if (Dart_IsError(result)) {
740 return ErrorExit("%s\n", Dart_GetError(result)); 763 return ErrorExit("%s\n", Dart_GetError(result));
741 } 764 }
742 765
743 Dart_ExitScope(); 766 Dart_ExitScope();
744 // Dump symbol information for the profiler. 767 // Dump symbol information for the profiler.
745 DumpPprofSymbolInfo(); 768 DumpPprofSymbolInfo();
746 // Shutdown the isolate. 769 // Shutdown the isolate.
747 Dart_ShutdownIsolate(); 770 Dart_ShutdownIsolate();
748 // Terminate process exit-code handler. 771 // Terminate process exit-code handler.
749 Process::TerminateExitCodeHandler(); 772 Process::TerminateExitCodeHandler();
773 // Free copied argument strings if converted.
774 if (argv_converted) {
775 for (int i = 0; i < argc; i++) free(argv[i]);
776 }
750 777
751 return 0; 778 return 0;
752 } 779 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698