coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
get_options.cpp File Reference
#include "get_options.h"
#include <cassert>
#include <cstring>

Go to the source code of this file.

Functions

cmd_option const * get_command_option (int argc, char *argv[], cmd_option const *commands)
 Look for a command option at the start of commandline arguments. More...
 
bool opts_are_compatible (int opt_excluder, int opt_excluded, struct exclusion_list const *exclusions, bool indexed)
 Say whether options are compatible with respect to specified incompatibilities. More...
 
int getopt_long (int argc, char *argv[], const char *optstr, const struct option *longopts, int *longind)
 Parse commandline options. More...
 
const char * get_long_opt_name (struct option const *longopts, int opt)
 Look up the long name of the an option in an array of struct option. More...
 

Variables

int optind
 Index of option parsed by getopt_long()
 
int optopt
 Unrecogised short option parsed by getopt_long()
 
char * optarg
 Argument to an option parsed by getopt_long()
 

Detailed Description

This file implements the get_options API

Definition in file get_options.cpp.

Function Documentation

cmd_option const* get_command_option ( int  argc,
char *  argv[],
cmd_option const *  commands 
)

Look for a command option at the start of commandline arguments.

Parameters
argcThe number of commandline arguments.
argvThe array of commandline arguments.
commandsAn array of valid command options.
Returns
If argc < 2 return nullptr. Else if argv[1] matches the name field in any of the command options listed in commands, return the address of that command option, else return nullptr.

Definition at line 52 of file get_options.cpp.

const char* get_long_opt_name ( struct option const *  longopts,
int  opt 
)

Look up the long name of the an option in an array of struct option.

Parameters
longoptsThe array of option info to be searched, terminated by a struct option in which the name field is nullptr.
optThe option code to be sought.
Returns
The address of the long name of the option with code opt, if found, else nullptr.

Definition at line 249 of file get_options.cpp.

int getopt_long ( int  argc,
char *  argv[],
const char *  optstr,
struct option const *  longopts,
int *  longind 
)

Parse commandline options.

We need the standard getopt_long() function, but the host implementation cannot be relied on to be re-entrant. Therefore we roll our own re-entrant version. The interface is like that of its standard namesake.

Parameters
argcThe number of commandline arguments
argvArray of pointers to the commandline arguments.
optstrA string containing the legitimate option characters.
longoptsA pointer to the first element of an array of struct option.
longindA pointer at which is stored on return the index of any long option parsed.
Returns
The character code of the option detected, if any; '?' if an unrecognized option is detected; -1 if no more options are detected.

Definition at line 97 of file get_options.cpp.

bool opts_are_compatible ( int  opt_excluder,
int  opt_excluded,
struct exclusion_list const *  exclusions,
bool  indexed 
)

Say whether options are compatible with respect to specified incompatibilities.

Parameters
opt_excluderTo be determined if this option excludes another.
opt_excludedTo be determined if this option is excluded by opt_excluder.
exclusionsAddresses an array of exclusions lists,terminated by an exclusion list in which the excluder field is 0, in which a list belonging to opt_excluder will be sought.
indexedIf true then the function may assume that opt_excluder is an index to its exclusion list in exclusions.
Returns
False if exclusions is found to contain an exclusion list whose excluder field is opt_excluder and whose excluded field is an array containing opt_excluded. Otherwise true.

Definition at line 67 of file get_options.cpp.