Check-in [042766574f]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:042766574f00429e4fef27b6297062ec16309415
Date: 2009-06-15 19:14:29
User: stephan
Comment:Fixed a bug in the handing of -D/--debug-flags when it was the last argument. Now no longer throws error when no FS filename is given when (openMode==WHEFSApp_NoOpen).
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to WHEFSApp.c

Old (fba6a11633fc1956) New (627c6ebc7624e625)
1 /** 1 /**
2 Code which is not part of libwhefs but may be shared between vfs-related tools. 2 Code which is not part of libwhefs but may be shared between vfs-related tools.
3 It provides a very minimal app framework for whefs applications, like 'ls', 3 It provides a very minimal app framework for whefs applications, like 'ls',
4 'cp', 'mkfs' and friends. 4 'cp', 'mkfs' and friends.
5 5
498 hidden lines
504 WHEFS_MAGIC_STRING ); 504 WHEFS_MAGIC_STRING );
505 505
506 printf("libwhefs home page: %s\n", whefs_home_page_url() ); 506 printf("libwhefs home page: %s\n", whefs_home_page_url() );
507 507
508 } 508 }
> 509 /**
> 510 Initializes the app. argc and argv should come directly from main.
> 511
> 512 openMode must be one of the WHEFSApp_OpenModes values.
> 513
> 514 If gotHelp is not null then it will be set to true if this function
> 515 things that the user needs help. That is: (A) if no arguments are given
> 516 or (B) if -? or --help is given. If it sets this value to true then
> 517 it calls the built-in help system. When it shows help it returns
> 518 whefs_rc.ArgError.
> 519
> 520 argspec is an array with a terminating entry with no name. It may
> 521 be null, in which case it is ignored. If it is not null, then argv
> 522 is compared against it to look for application arguments.
> 523 */
509 int WHEFSApp_init( int argc, 524 int WHEFSApp_init( int argc,
510 char const ** argv, 525 char const ** argv,
511 int openMode /* should be from WHEFSApp_OpenModes enum */, 526 int openMode /* should be from WHEFSApp_OpenModes enum */,
512 bool * gotHelp, 527 bool * gotHelp,
513 ArgSpec * argspec ) 528 ArgSpec * argspec )
515 if( ! argc || !argv ) return whefs_rc.ArgError; 530 if( ! argc || !argv ) return whefs_rc.ArgError;
516 WHEFSApp.appName = argv[0]; 531 WHEFSApp.appName = argv[0];
517 WHEFSApp.argsSpec = argspec; 532 WHEFSApp.argsSpec = argspec;
518 WHEFSApp.debugFlags = 0; 533 WHEFSApp.debugFlags = 0;
519 atexit( WHEFSApp_atexit ); 534 atexit( WHEFSApp_atexit );
520 whefs_setup_debug( stderr, 0 ); //(unsigned int)-1 ); | 535 whefs_setup_debug( stderr, (unsigned int)-1 );
521 //whefs_setup_debug_arg( stderr, "" ); 536 //whefs_setup_debug_arg( stderr, "" );
522 if( gotHelp ) *gotHelp = false; 537 if( gotHelp ) *gotHelp = false;
523 538
524 if( 1 == argc ) 539 if( 1 == argc )
525 { 540 {
526 if( gotHelp ) *gotHelp = true; | 541 if( gotHelp )
527 WHEFSApp_show_help(); | 542 {
528 return whefs_rc.ArgError; | 543 *gotHelp = true;
| 544 WHEFSApp_show_help();
| 545 }
| 546 return whefs_rc.ArgError;
529 } 547 }
530 | 548 else
531 whargv_global_parse( argc - 1, argv + 1 ); | 549 {
| 550 whargv_global_parse( argc - 1, argv + 1 );
| 551 }
532 552
533 const size_t gac = whargv_global.argc; 553 const size_t gac = whargv_global.argc;
534 whargv_entry * garg = whargv_global.argv; 554 whargv_entry * garg = whargv_global.argv;
535 size_t i = 0; 555 size_t i = 0;
536 int rc = whefs_rc.OK; 556 int rc = whefs_rc.OK;
63 hidden lines
600 for( ; as && as->name; ++as ) 620 for( ; as && as->name; ++as )
601 { 621 {
602 gotSpec = (0 == strcmp( as->name, garg->key )); 622 gotSpec = (0 == strcmp( as->name, garg->key ));
603 //APPMSG("Trying arg [%s] vs [%s] rc=%d\n",garg->key,as->name,gotSpec); 623 //APPMSG("Trying arg [%s] vs [%s] rc=%d\n",garg->key,as->name,gotSpec);
604 if( ! gotSpec ) continue; 624 if( ! gotSpec ) continue;
605 //APPMSG("Matched arg [%s] vs [%s] rc=%d. val=[%s]\n",garg->key,as->name,rc,garg->val); | 625 APPMSG("Matched arg [%s] vs [%s] rc=%d. val=[%s]\n",garg->key,as->name,rc,garg->val);
606 rc = ArgSpec_convert( as, garg->val ); 626 rc = ArgSpec_convert( as, garg->val );
607 if( whefs_rc.OK != rc ) 627 if( whefs_rc.OK != rc )
608 { 628 {
609 APPERR("Error parsing flag '%s'!\n", garg->key ); 629 APPERR("Error parsing flag '%s'!\n", garg->key );
610 return rc; 630 return rc;
13 hidden lines
624 return whefs_rc.ArgError; 644 return whefs_rc.ArgError;
625 } 645 }
626 646
627 } 647 }
628 #undef RC 648 #undef RC
629 if( !WHEFSApp.fsName || ((openMode != WHEFSApp_NoOpen) && ! WHEFSApp.fs) ) | 649 if( !setDebug && WHEFSApp.debugFlags )
| 650 {
| 651 VERBOSE("Setting debug flags to [%s]\n",WHEFSApp.debugFlags);
| 652 whefs_setup_debug_arg( stderr, WHEFSApp.debugFlags );
| 653 setDebug = true;
| 654 }
| 655
| 656 if( !WHEFSApp.fsName )
630 { 657 {
631 APPERR("No EFS file specified! The EFS file must be the first non-flag argument.\n"); | 658 if( (openMode != WHEFSApp_NoOpen) && ! WHEFSApp.fs)
632 return whefs_rc.ArgError; | 659 {
| 660 APPERR("No EFS file specified! The EFS file must be the first non-flag argument.\n");
| 661 return whefs_rc.ArgError;
| 662 }
633 } 663 }
634 return whefs_rc.OK; 664 return whefs_rc.OK;
635 } 665 }
636 666