[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] Option Equivalence Class

Generally, when several options are mutually exclusive and basically serve the purpose of selecting one of several processing modes, specify the equivalence attribute. These options will be considered an equivalence class. Sometimes, it is just easier to deal with them as such. All members of the equivalence class must contain the same equivalenced-to option, including the equivalenced-to option itself. Thus, it must be a class member.

For an option equivalence class, there is a single occurrence counter for the class. It can be referenced with the interface macro, COUNT_OPT(BASE_OPTION), where BASE_OPTION is the equivalenced-to option name.

Also, please take careful note: since the options are mapped to the equivalenced-to option descriptor, any option argument values are mapped to that descriptor also. Be sure you know which “equivalent option” was selected before getting an option argument value!

During the presetting phase of option processing (see section Configuring your program), equivalenced options may be specified. However, if different equivalenced members are specified, only the last instance will be recognized and the others will be discarded. A conflict error is indicated only when multiple different members appear on the command line itself.

As an example of where equivalenced options might be useful, cpio(1) has three options ‘-o’, ‘-i’, and ‘-p’ that define the operational mode of the program (create, extract and pass-through, respectively). They form an equivalence class from which one and only one member must appear on the command line. If cpio were an AutoOpt-ed program, then each of these option definitions would contain:

equivalence = create;

and the program would be able to determine the operating mode with code that worked something like this:

case INDEX_OPT_CREATE:       ...
case INDEX_OPT_EXTRACT:      ...
default:    /* cannot happen */

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on August 21, 2015 using texi2html 1.82.