| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // lookup the flag | 310 // lookup the flag |
| 311 Flag* flag = FindFlag(name); | 311 Flag* flag = FindFlag(name); |
| 312 if (flag == NULL) { | 312 if (flag == NULL) { |
| 313 if (remove_flags) { | 313 if (remove_flags) { |
| 314 // We don't recognize this flag but since we're removing | 314 // We don't recognize this flag but since we're removing |
| 315 // the flags we recognize we assume that the remaining flags | 315 // the flags we recognize we assume that the remaining flags |
| 316 // will be processed somewhere else so this flag might make | 316 // will be processed somewhere else so this flag might make |
| 317 // sense there. | 317 // sense there. |
| 318 continue; | 318 continue; |
| 319 } else { | 319 } else { |
| 320 fprintf(stderr, "Error: unrecognized flag %s\n", arg); | 320 fprintf(stderr, "Error: unrecognized flag %s\n" |
| 321 "Try --help for options\n", arg); |
| 321 return j; | 322 return j; |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 // if we still need a flag value, use the next argument if available | 326 // if we still need a flag value, use the next argument if available |
| 326 if (flag->type() != Flag::TYPE_BOOL && value == NULL) { | 327 if (flag->type() != Flag::TYPE_BOOL && value == NULL) { |
| 327 if (i < *argc) { | 328 if (i < *argc) { |
| 328 value = argv[i++]; | 329 value = argv[i++]; |
| 329 } else { | 330 } else { |
| 330 fprintf(stderr, "Error: missing value for flag %s of type %s\n", | 331 fprintf(stderr, "Error: missing value for flag %s of type %s\n" |
| 332 "Try --help for options\n", |
| 331 arg, Type2String(flag->type())); | 333 arg, Type2String(flag->type())); |
| 332 return j; | 334 return j; |
| 333 } | 335 } |
| 334 } | 336 } |
| 335 | 337 |
| 336 // set the flag | 338 // set the flag |
| 337 char* endp = const_cast<char*>(""); // *endp is only read | 339 char* endp = const_cast<char*>(""); // *endp is only read |
| 338 switch (flag->type()) { | 340 switch (flag->type()) { |
| 339 case Flag::TYPE_BOOL: | 341 case Flag::TYPE_BOOL: |
| 340 *flag->bool_variable() = !is_bool; | 342 *flag->bool_variable() = !is_bool; |
| 341 break; | 343 break; |
| 342 case Flag::TYPE_INT: | 344 case Flag::TYPE_INT: |
| 343 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT | 345 *flag->int_variable() = strtol(value, &endp, 10); // NOLINT |
| 344 break; | 346 break; |
| 345 case Flag::TYPE_FLOAT: | 347 case Flag::TYPE_FLOAT: |
| 346 *flag->float_variable() = strtod(value, &endp); | 348 *flag->float_variable() = strtod(value, &endp); |
| 347 break; | 349 break; |
| 348 case Flag::TYPE_STRING: | 350 case Flag::TYPE_STRING: |
| 349 *flag->string_variable() = value; | 351 *flag->string_variable() = value; |
| 350 break; | 352 break; |
| 351 } | 353 } |
| 352 | 354 |
| 353 // handle errors | 355 // handle errors |
| 354 if ((flag->type() == Flag::TYPE_BOOL && value != NULL) || | 356 if ((flag->type() == Flag::TYPE_BOOL && value != NULL) || |
| 355 (flag->type() != Flag::TYPE_BOOL && is_bool) || | 357 (flag->type() != Flag::TYPE_BOOL && is_bool) || |
| 356 *endp != '\0') { | 358 *endp != '\0') { |
| 357 fprintf(stderr, "Error: illegal value for flag %s of type %s\n", | 359 fprintf(stderr, "Error: illegal value for flag %s of type %s\n" |
| 360 "Try --help for options\n", |
| 358 arg, Type2String(flag->type())); | 361 arg, Type2String(flag->type())); |
| 359 return j; | 362 return j; |
| 360 } | 363 } |
| 361 | 364 |
| 362 // remove the flag & value from the command | 365 // remove the flag & value from the command |
| 363 if (remove_flags) | 366 if (remove_flags) |
| 364 while (j < i) | 367 while (j < i) |
| 365 argv[j++] = NULL; | 368 argv[j++] = NULL; |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 369 // shrink the argument list | 372 // shrink the argument list |
| 370 if (remove_flags) { | 373 if (remove_flags) { |
| 371 int j = 1; | 374 int j = 1; |
| 372 for (int i = 1; i < *argc; i++) { | 375 for (int i = 1; i < *argc; i++) { |
| 373 if (argv[i] != NULL) | 376 if (argv[i] != NULL) |
| 374 argv[j++] = argv[i]; | 377 argv[j++] = argv[i]; |
| 375 } | 378 } |
| 376 *argc = j; | 379 *argc = j; |
| 377 } | 380 } |
| 378 | 381 |
| 382 if (FLAG_help) { |
| 383 PrintHelp(); |
| 384 } |
| 379 // parsed all flags successfully | 385 // parsed all flags successfully |
| 380 return 0; | 386 return 0; |
| 381 } | 387 } |
| 382 | 388 |
| 383 | 389 |
| 384 static char* SkipWhiteSpace(char* p) { | 390 static char* SkipWhiteSpace(char* p) { |
| 385 while (*p != '\0' && isspace(*p) != 0) p++; | 391 while (*p != '\0' && isspace(*p) != 0) p++; |
| 386 return p; | 392 return p; |
| 387 } | 393 } |
| 388 | 394 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // static | 446 // static |
| 441 void FlagList::ResetAllFlags() { | 447 void FlagList::ResetAllFlags() { |
| 442 for (size_t i = 0; i < num_flags; ++i) { | 448 for (size_t i = 0; i < num_flags; ++i) { |
| 443 flags[i].Reset(); | 449 flags[i].Reset(); |
| 444 } | 450 } |
| 445 } | 451 } |
| 446 | 452 |
| 447 | 453 |
| 448 // static | 454 // static |
| 449 void FlagList::PrintHelp() { | 455 void FlagList::PrintHelp() { |
| 456 printf("Usage:\n"); |
| 457 printf(" shell [options] -e string\n"); |
| 458 printf(" execute string in V8\n"); |
| 459 printf(" shell [options] file1 file2 ... filek\n"); |
| 460 printf(" run JavaScript scripts in file1, file2, ..., filek\n"); |
| 461 printf(" shell [options]\n"); |
| 462 printf(" shell [options] --shell\n"); |
| 463 printf(" run an interactive JavaScript shell"); |
| 464 printf(" d8 [options] file\n"); |
| 465 printf(" d8 [options]\n"); |
| 466 printf(" run the new debugging shell\n\n"); |
| 467 printf("Options:\n"); |
| 450 for (size_t i = 0; i < num_flags; ++i) { | 468 for (size_t i = 0; i < num_flags; ++i) { |
| 451 Flag* f = &flags[i]; | 469 Flag* f = &flags[i]; |
| 452 char* value = ToString(f); | 470 char* value = ToString(f); |
| 453 printf(" --%s (%s) type: %s default: %s\n", | 471 printf(" --%s (%s)\n type: %s default: %s\n", |
| 454 f->name(), f->comment(), Type2String(f->type()), value); | 472 f->name(), f->comment(), Type2String(f->type()), value); |
| 455 DeleteArray(value); | 473 DeleteArray(value); |
| 456 } | 474 } |
| 457 } | 475 } |
| 458 | 476 |
| 459 } } // namespace v8::internal | 477 } } // namespace v8::internal |
| OLD | NEW |