DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
A Flexible UNIX Command Line Processing Facility - Args(3C++)

Multiple options:-I

Args normally treats the rightmost instance of an option as the significant one. For example, given the following invocation,

       cc -o bar -o foo foo.c

the value return by args.value('o'); will be foo. For some options, the program must process every instance. Consider the -I option to cc:

       cc -I foo -I bar -I baz foo.c

Here cc must know about every include directory, and not just the rightmost one.

In order to process all the instances of an option, an ``options iterator'' is provided. Its interface is analogous to the arguments iterator. The following code adds each include directory to some internal list by calling the function add_includedir():

       extern void add_includedir(const char* dir);
   

main(int argc, const char*const* argv) { Args args(argc, argv, "co:OI:"); // ... Optsiter oi(args); const Opt* opt; while (oi.next(opt)) if (opt->chr() == 'I') add_includedir(opt->value()); // ... }

The function next() returns (via its reference parameter) pointers to Opt objects describing each option. Options are returned in the order they appeared on the command line. The Opt object can be inquired to find out information about the option:

       opt->flag();    // option flag (normally `-',
                       //   but see below)
       opt->chr();     // option letter
       opt->keyword(); // option keyword (see below)
       opt->value();   // option value (NULL if no value)

Next topic: Suboptions: -D
Previous topic: Args

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004