libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Files
Option Parser

The option parser reads the command line as well as configuration files. More...

Collaboration diagram for Option Parser:

Files

file  sc_options.h
 Register and parse command line options and read/write configuration files.
 

Detailed Description

The option parser reads the command line as well as configuration files.

The library provides a rather flexible and powerful means for configuring a program at runtime. Configuration can be effected by parsing command line options or by reading .ini or JSON files, or a combination thereof.

The first thing to do is to allocate an empty sc_options_t object. Then one or more options can be added to it. Such an addition provides details on the option name and type, a help string, and a pointer to an existing variable in user memory that shall be updated when options are parsed or loaded. This variable must not go out of scope while the options object it has been added to is in use.

Once the desired variables have been added to the options object variables can be loaded from configuration files by calling the loader function explicitly, for example sc_options_load_json. Every variable that is found in the file is parsed and updated. Similarly, a command line can be queried by sc_options_parse. The options in an object can be saved to a file as well.

The suboptions feature allows options to be nested. To this end, any options object can be passed as suboptions to sc_options_add_suboptions, which duplicates its variable entries to the options object under construction below an option name prefix. This copies meta-data of the option but passes the same user variable, which can thus be modified by parsing either with the original suboptions or the new, hierarchical options object, or both. Suboptions are loaded from and saved to files hierarchically.

Please see the example options.c for a demonstration.