coan 4.2.4
The Get Options component interface.
Collaboration diagram for The Get Options component interface.:

Data Structures

struct  option
struct  cmd_option
struct  exclusion_list

Files

file  get_options.c
file  get_options.h

Typedefs

typedef struct cmd_option cmd_option_t

Enumerations

enum  { no_argument, required_argument, optional_argument }

Functions

cmd_option_t const * get_command_option (int argc, char *argv[], cmd_option_t const *commands)
bool opts_are_compatible (int opt_excluder, int opt_excluded, struct exclusion_list const *exclusions, bool indexed)
int getopt_long (int argc, char *argv[], const char *optstr, struct option const *longopts, int *longind)
const char * get_long_opt_name (struct option const *longopts, int opt)

Variables

int optind
int optopt
char * optarg

Typedef Documentation

typedef struct cmd_option cmd_option_t

Info structure for a command option for get_command()


Enumeration Type Documentation

anonymous enum

Possible values of the has_arg field in an option structure

Enumerator:
no_argument 

The option cannot have an argument

required_argument 

The option must have an argument

optional_argument 

The option mat or may not have an argument

Definition at line 83 of file get_options.h.


Function Documentation

cmd_option_t const* get_command_option ( int  argc,
char *  argv[],
cmd_option_t 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 NULL. 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 NULL.

Definition at line 56 of file get_options.c.

References commands, and cmd_option::name.

Referenced by parse_args().

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 NULL.
optThe option code to be sought.
Returns:
The address of the long name of the option with code opt, if found, else NULL.

Definition at line 253 of file get_options.c.

References option::name, and option::val.

Referenced by error_invalid_opt().

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

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.

Definition at line 101 of file get_options.c.

References eq(), option::flag, getopt_long(), option::name, no_argument, optarg, optind, optional_argument, optopt, required_argument, and option::val.

Referenced by getopt_long(), and parse_command_args().

Here is the call graph for this function:

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 incompatbilities.

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 71 of file get_options.c.

References exclusion_list::excluded, and exclusion_list::excluder.

Referenced by parse_command_args().


Variable Documentation

char* optarg

Argument to an option parsed by getopt_long()

Definition at line 53 of file get_options.c.

Referenced by getopt_long(), and parse_command_args().

int optind

Index of option parsed by getopt_long()

Definition at line 51 of file get_options.c.

Referenced by getopt_long(), and parse_command_args().

int optopt

Unrecogised short option parsed by getopt_long()

Definition at line 52 of file get_options.c.

Referenced by getopt_long().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines