OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 463 |
464 static char* SkipBlackSpace(char* p) { | 464 static char* SkipBlackSpace(char* p) { |
465 while (*p != '\0' && isspace(*p) == 0) p++; | 465 while (*p != '\0' && isspace(*p) == 0) p++; |
466 return p; | 466 return p; |
467 } | 467 } |
468 | 468 |
469 | 469 |
470 // static | 470 // static |
471 int FlagList::SetFlagsFromString(const char* str, int len) { | 471 int FlagList::SetFlagsFromString(const char* str, int len) { |
472 // make a 0-terminated copy of str | 472 // make a 0-terminated copy of str |
473 char* copy0 = NewArray<char>(len + 1); | 473 ScopedVector<char> copy0(len + 1); |
474 memcpy(copy0, str, len); | 474 memcpy(copy0.start(), str, len); |
475 copy0[len] = '\0'; | 475 copy0[len] = '\0'; |
476 | 476 |
477 // strip leading white space | 477 // strip leading white space |
478 char* copy = SkipWhiteSpace(copy0); | 478 char* copy = SkipWhiteSpace(copy0.start()); |
479 | 479 |
480 // count the number of 'arguments' | 480 // count the number of 'arguments' |
481 int argc = 1; // be compatible with SetFlagsFromCommandLine() | 481 int argc = 1; // be compatible with SetFlagsFromCommandLine() |
482 for (char* p = copy; *p != '\0'; argc++) { | 482 for (char* p = copy; *p != '\0'; argc++) { |
483 p = SkipBlackSpace(p); | 483 p = SkipBlackSpace(p); |
484 p = SkipWhiteSpace(p); | 484 p = SkipWhiteSpace(p); |
485 } | 485 } |
486 | 486 |
487 // allocate argument array | 487 // allocate argument array |
488 char** argv = NewArray<char*>(argc); | 488 ScopedVector<char*> argv(argc); |
489 | 489 |
490 // split the flags string into arguments | 490 // split the flags string into arguments |
491 argc = 1; // be compatible with SetFlagsFromCommandLine() | 491 argc = 1; // be compatible with SetFlagsFromCommandLine() |
492 for (char* p = copy; *p != '\0'; argc++) { | 492 for (char* p = copy; *p != '\0'; argc++) { |
493 argv[argc] = p; | 493 argv[argc] = p; |
494 p = SkipBlackSpace(p); | 494 p = SkipBlackSpace(p); |
495 if (*p != '\0') *p++ = '\0'; // 0-terminate argument | 495 if (*p != '\0') *p++ = '\0'; // 0-terminate argument |
496 p = SkipWhiteSpace(p); | 496 p = SkipWhiteSpace(p); |
497 } | 497 } |
498 | 498 |
499 // set the flags | 499 // set the flags |
500 int result = SetFlagsFromCommandLine(&argc, argv, false); | 500 int result = SetFlagsFromCommandLine(&argc, argv.start(), false); |
501 | |
502 // cleanup | |
503 DeleteArray(argv); | |
504 DeleteArray(copy0); | |
505 | 501 |
506 return result; | 502 return result; |
507 } | 503 } |
508 | 504 |
509 | 505 |
510 // static | 506 // static |
511 void FlagList::ResetAllFlags() { | 507 void FlagList::ResetAllFlags() { |
512 for (size_t i = 0; i < num_flags; ++i) { | 508 for (size_t i = 0; i < num_flags; ++i) { |
513 flags[i].Reset(); | 509 flags[i].Reset(); |
514 } | 510 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 const char** JSArguments::argv() { return argv_; } | 542 const char** JSArguments::argv() { return argv_; } |
547 const char*& JSArguments::operator[](int idx) { return argv_[idx]; } | 543 const char*& JSArguments::operator[](int idx) { return argv_[idx]; } |
548 JSArguments& JSArguments::operator=(JSArguments args) { | 544 JSArguments& JSArguments::operator=(JSArguments args) { |
549 argc_ = args.argc_; | 545 argc_ = args.argc_; |
550 argv_ = args.argv_; | 546 argv_ = args.argv_; |
551 return *this; | 547 return *this; |
552 } | 548 } |
553 | 549 |
554 | 550 |
555 } } // namespace v8::internal | 551 } } // namespace v8::internal |
OLD | NEW |