Chromium Code Reviews| 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_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 ASSERT(arg != NULL); | 275 ASSERT(arg != NULL); |
| 276 if (*arg == '\0') { | 276 if (*arg == '\0') { |
| 277 // Ignore empty -D option. | 277 // Ignore empty -D option. |
| 278 Log::PrintErr("No arguments given to -D option\n"); | 278 Log::PrintErr("No arguments given to -D option\n"); |
| 279 return true; | 279 return true; |
| 280 } | 280 } |
| 281 if (environment == NULL) { | 281 if (environment == NULL) { |
| 282 environment = new HashMap(&HashMap::SameStringValue, 4); | 282 environment = new HashMap(&HashMap::SameStringValue, 4); |
| 283 } | 283 } |
| 284 // Split the name=value part of the -Dname=value argument. | 284 // Split the name=value part of the -Dname=value argument. |
| 285 char* name; | |
| 286 char* value = NULL; | |
| 287 const char* equals_pos = strchr(arg, '='); | 285 const char* equals_pos = strchr(arg, '='); |
| 288 if (equals_pos == NULL) { | 286 if (equals_pos == NULL) { |
| 289 // No equal sign (name without value) currently not supported. | 287 // No equal sign (name without value) currently not supported. |
| 290 Log::PrintErr("No value given to -D option\n"); | 288 Log::PrintErr("No value given to -D option\n"); |
| 291 return false; | 289 return false; |
| 292 } else { | |
| 293 int name_len = equals_pos - arg; | |
| 294 if (name_len == 0) { | |
| 295 Log::PrintErr("No name given to -D option\n"); | |
| 296 return false; | |
| 297 } | |
| 298 // Split name=value into name and value. | |
| 299 name = reinterpret_cast<char*>(malloc(name_len + 1)); | |
| 300 strncpy(name, arg, name_len); | |
| 301 name[name_len] = '\0'; | |
| 302 value = strdup(equals_pos + 1); | |
| 303 } | 290 } |
| 291 | |
| 292 char* name; | |
| 293 char* value = NULL; | |
| 294 int name_len = equals_pos - arg; | |
| 295 if (name_len == 0) { | |
| 296 Log::PrintErr("No name given to -D option\n"); | |
| 297 return false; | |
| 298 } | |
| 299 // Split name=value into name and value. | |
| 300 name = reinterpret_cast<char*>(malloc(name_len + 1)); | |
| 301 strncpy(name, arg, name_len); | |
| 302 name[name_len] = '\0'; | |
| 303 value = strdup(equals_pos + 1); | |
| 304 HashMap::Entry* entry = environment->Lookup( | 304 HashMap::Entry* entry = environment->Lookup( |
| 305 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); | 305 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); |
| 306 ASSERT(entry != NULL); // Lookup adds an entry if key not found. | 306 ASSERT(entry != NULL); // Lookup adds an entry if key not found. |
| 307 entry->value = value; | 307 if (entry->value == NULL) { |
| 308 entry->value = value; | |
| 309 } else { | |
| 310 free(name); | |
| 311 free(entry->value); | |
| 312 entry->value = value; | |
| 313 } | |
|
siva
2016/08/08 19:41:05
how about
if (entry->value != NULL) {
free(name
zra
2016/08/08 19:53:13
Done.
| |
| 308 return true; | 314 return true; |
| 309 } | 315 } |
| 310 | 316 |
| 311 | 317 |
| 312 static bool ProcessCompileAllOption(const char* arg, | 318 static bool ProcessCompileAllOption(const char* arg, |
| 313 CommandLineOptions* vm_options) { | 319 CommandLineOptions* vm_options) { |
| 314 ASSERT(arg != NULL); | 320 ASSERT(arg != NULL); |
| 315 if (*arg != '\0') { | 321 if (*arg != '\0') { |
| 316 return false; | 322 return false; |
| 317 } | 323 } |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1787 Platform::Exit(Process::GlobalExitCode()); | 1793 Platform::Exit(Process::GlobalExitCode()); |
| 1788 } | 1794 } |
| 1789 | 1795 |
| 1790 } // namespace bin | 1796 } // namespace bin |
| 1791 } // namespace dart | 1797 } // namespace dart |
| 1792 | 1798 |
| 1793 int main(int argc, char** argv) { | 1799 int main(int argc, char** argv) { |
| 1794 dart::bin::main(argc, argv); | 1800 dart::bin::main(argc, argv); |
| 1795 UNREACHABLE(); | 1801 UNREACHABLE(); |
| 1796 } | 1802 } |
| OLD | NEW |