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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 return &flags[i]; | 336 return &flags[i]; |
337 } | 337 } |
338 return NULL; | 338 return NULL; |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 // static | 342 // static |
343 int FlagList::SetFlagsFromCommandLine(int* argc, | 343 int FlagList::SetFlagsFromCommandLine(int* argc, |
344 char** argv, | 344 char** argv, |
345 bool remove_flags) { | 345 bool remove_flags) { |
| 346 int return_code = 0; |
346 // parse arguments | 347 // parse arguments |
347 for (int i = 1; i < *argc;) { | 348 for (int i = 1; i < *argc;) { |
348 int j = i; // j > 0 | 349 int j = i; // j > 0 |
349 const char* arg = argv[i++]; | 350 const char* arg = argv[i++]; |
350 | 351 |
351 // split arg into flag components | 352 // split arg into flag components |
352 char buffer[1*KB]; | 353 char buffer[1*KB]; |
353 const char* name; | 354 const char* name; |
354 const char* value; | 355 const char* value; |
355 bool is_bool; | 356 bool is_bool; |
356 SplitArgument(arg, buffer, sizeof buffer, &name, &value, &is_bool); | 357 SplitArgument(arg, buffer, sizeof buffer, &name, &value, &is_bool); |
357 | 358 |
358 if (name != NULL) { | 359 if (name != NULL) { |
359 // lookup the flag | 360 // lookup the flag |
360 Flag* flag = FindFlag(name); | 361 Flag* flag = FindFlag(name); |
361 if (flag == NULL) { | 362 if (flag == NULL) { |
362 if (remove_flags) { | 363 if (remove_flags) { |
363 // We don't recognize this flag but since we're removing | 364 // We don't recognize this flag but since we're removing |
364 // the flags we recognize we assume that the remaining flags | 365 // the flags we recognize we assume that the remaining flags |
365 // will be processed somewhere else so this flag might make | 366 // will be processed somewhere else so this flag might make |
366 // sense there. | 367 // sense there. |
367 continue; | 368 continue; |
368 } else { | 369 } else { |
369 fprintf(stderr, "Error: unrecognized flag %s\n" | 370 fprintf(stderr, "Error: unrecognized flag %s\n" |
370 "Try --help for options\n", arg); | 371 "Try --help for options\n", arg); |
371 return j; | 372 return_code = j; |
| 373 break; |
372 } | 374 } |
373 } | 375 } |
374 | 376 |
375 // if we still need a flag value, use the next argument if available | 377 // if we still need a flag value, use the next argument if available |
376 if (flag->type() != Flag::TYPE_BOOL && | 378 if (flag->type() != Flag::TYPE_BOOL && |
377 flag->type() != Flag::TYPE_ARGS && | 379 flag->type() != Flag::TYPE_ARGS && |
378 value == NULL) { | 380 value == NULL) { |
379 if (i < *argc) { | 381 if (i < *argc) { |
380 value = argv[i++]; | 382 value = argv[i++]; |
381 } else { | 383 } else { |
382 fprintf(stderr, "Error: missing value for flag %s of type %s\n" | 384 fprintf(stderr, "Error: missing value for flag %s of type %s\n" |
383 "Try --help for options\n", | 385 "Try --help for options\n", |
384 arg, Type2String(flag->type())); | 386 arg, Type2String(flag->type())); |
385 return j; | 387 return_code = j; |
| 388 break; |
386 } | 389 } |
387 } | 390 } |
388 | 391 |
389 // set the flag | 392 // set the flag |
390 char* endp = const_cast<char*>(""); // *endp is only read | 393 char* endp = const_cast<char*>(""); // *endp is only read |
391 switch (flag->type()) { | 394 switch (flag->type()) { |
392 case Flag::TYPE_BOOL: | 395 case Flag::TYPE_BOOL: |
393 *flag->bool_variable() = !is_bool; | 396 *flag->bool_variable() = !is_bool; |
394 break; | 397 break; |
395 case Flag::TYPE_INT: | 398 case Flag::TYPE_INT: |
(...skipping 21 matching lines...) Expand all Loading... |
417 } | 420 } |
418 } | 421 } |
419 | 422 |
420 // handle errors | 423 // handle errors |
421 if ((flag->type() == Flag::TYPE_BOOL && value != NULL) || | 424 if ((flag->type() == Flag::TYPE_BOOL && value != NULL) || |
422 (flag->type() != Flag::TYPE_BOOL && is_bool) || | 425 (flag->type() != Flag::TYPE_BOOL && is_bool) || |
423 *endp != '\0') { | 426 *endp != '\0') { |
424 fprintf(stderr, "Error: illegal value for flag %s of type %s\n" | 427 fprintf(stderr, "Error: illegal value for flag %s of type %s\n" |
425 "Try --help for options\n", | 428 "Try --help for options\n", |
426 arg, Type2String(flag->type())); | 429 arg, Type2String(flag->type())); |
427 return j; | 430 return_code = j; |
| 431 break; |
428 } | 432 } |
429 | 433 |
430 // remove the flag & value from the command | 434 // remove the flag & value from the command |
431 if (remove_flags) { | 435 if (remove_flags) { |
432 while (j < i) { | 436 while (j < i) { |
433 argv[j++] = NULL; | 437 argv[j++] = NULL; |
434 } | 438 } |
435 } | 439 } |
436 } | 440 } |
437 } | 441 } |
438 | 442 |
439 // shrink the argument list | 443 // shrink the argument list |
440 if (remove_flags) { | 444 if (remove_flags) { |
441 int j = 1; | 445 int j = 1; |
442 for (int i = 1; i < *argc; i++) { | 446 for (int i = 1; i < *argc; i++) { |
443 if (argv[i] != NULL) | 447 if (argv[i] != NULL) |
444 argv[j++] = argv[i]; | 448 argv[j++] = argv[i]; |
445 } | 449 } |
446 *argc = j; | 450 *argc = j; |
447 } | 451 } |
448 | 452 |
449 if (FLAG_help) { | 453 if (FLAG_help) { |
450 PrintHelp(); | 454 PrintHelp(); |
451 exit(0); | 455 exit(0); |
452 } | 456 } |
453 // parsed all flags successfully | 457 // parsed all flags successfully |
454 return 0; | 458 return return_code; |
455 } | 459 } |
456 | 460 |
457 | 461 |
458 static char* SkipWhiteSpace(char* p) { | 462 static char* SkipWhiteSpace(char* p) { |
459 while (*p != '\0' && isspace(*p) != 0) p++; | 463 while (*p != '\0' && isspace(*p) != 0) p++; |
460 return p; | 464 return p; |
461 } | 465 } |
462 | 466 |
463 | 467 |
464 static char* SkipBlackSpace(char* p) { | 468 static char* SkipBlackSpace(char* p) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 538 } |
535 } | 539 } |
536 | 540 |
537 | 541 |
538 void FlagList::EnforceFlagImplications() { | 542 void FlagList::EnforceFlagImplications() { |
539 #define FLAG_MODE_DEFINE_IMPLICATIONS | 543 #define FLAG_MODE_DEFINE_IMPLICATIONS |
540 #include "flag-definitions.h" | 544 #include "flag-definitions.h" |
541 } | 545 } |
542 | 546 |
543 } } // namespace v8::internal | 547 } } // namespace v8::internal |
OLD | NEW |