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

Suboptions: -D

A number of options have values that look like the following:

       foo=bar

Consider, for example, the -D option of cc:

       cc -Dfoo=bar -Dbaz

Here the second option is actually shorthand for -Dbaz=" ".

Such option values are called ``suboptions''. To make it easy for programs to process suboptions, Args lets the user specify which options take suboptions. Such options are specified with a following `;' instead of `:' in the option string:

       Args args(argc, argv, "co:OI:D;");

In general, the value of an option taking suboptions is assumed to be a series of one or more strings separated by commas, with no intervening spaces. For example,

       cc -Dalpha=tom,beta,gamma=harry

Here -D has three suboptions. The first suboption has name alpha and value tom, the second suboption has name beta and value " " (the null string), and the third suboption has name gamma and value harry.

The following addition to our program calls a function (defined below) to process the suboptions:

       main(int argc, const char*const* argv) {
           Args args(argc, argv, "co:OI:D;");
           // ...
               switch (opt->chr()) {
               // ...
               case 'D':
                   getdefines(opt);
                   break;
               }
           }
           // ...
       }

The function getdefines() adds each <name, value> pair to some internal list by calling the function add_define():

       extern void add_define(const char* name, const char* value);
   

static void getdefines(const Opt* opt) { Suboptsiter si(*opt); const Subopt* subopt; while (si.next(subopt)) add_define(subopt->name(), subopt->value()); }

The suboptions iterator, like the arguments and options iterators, returns suboptions in the order they appeared on the command line.


Next topic: Intermixing
Previous topic: Multiple options:-I

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