Object
|
+---DArguments
The DArguments class implements methods for parsing the arguments of a
program. After adding the definition of the arguments, the arguments
are parsed. The results are stored in boolean objects, parsable objects and a list of
texts.
Some notes:
#include <stdio.h>
#include "ofc/DArguments.h"
#include "ofc/DBool.h"
#include "ofc/DText.h"
int main(int argc, char *argv[])
{
DArguments *args = [DArguments new]; // the argument parser
DBool *verbose = [DBool new]; // the argument destination objects
DText *date = [DText new];
DList *extra; // the list with non options
// add the -d or --date option
[args option :"date=DATE" :'d' :"change default data" :date];
// add the -v or --verbose switch
[args option :"verbose" :'v' :"be verbose" :verbose];
// parse the arguments
extra = [args parse :"example"
:"Usage: example [OPTION] ... [FILES]"
:"example v1.7\n\n(c) 2008 Example soft"
:"Report bugs to bugs@example.com"
:argv
:argc];
// Process the result
if ([verbose get])
printf("Verbose!!\n");
if ([date length] > 0)
printf("Date=%s\n", [date cstring]);
printf("There are %ld non-options\n", (extra != nil ? [extra length] : 0));
[args free]; // Cleanup
[verbose free];
[date free];
[extra free];
return 0;
}