Go to the first, previous, next, last section, table of contents.


CNGetOpt -- Interface to GNU getopt()

SYNOPSIS

#include <CNCL/GetOpt.h>

TYPE

CN_GETOPT

BASE CLASSES

CNObject

DERIVED CLASSES

None

RELATED CLASSES

None

DESCRIPTION

This class manages the interface to the GNU getopt() functionality. As an example for its use please see the file tGetOpt.c at the directory CNCL/lib/misc/test.


Constructors:

CNGetOpt();
CNGetOpt(CNParam *);
CNGetOpt(int argc, char **argv, char *copts=NIL);


In addition to the member functions required by CNCL, CNGetOpt provides:

enum ParamType { NOPARAM=0, WPARAM=1, OPTPARAM=2 };
struct option { char *name; int has_arg; int *flag; int val; };
Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is zero. has_arg is NOPARAM (0) if the option does not take an argument, WPARAM (1) if the option requires an argument, or OPTPARAM (2) if the option takes an optional argument. If flag is not NULL, it points to a variable that is set to the value given in val when the option is found, but left unchanged if the option is not found. To have a long-named option do something other than set an `int' to a compiled-in constant, such as set a value from `optarg', set flag to zero and val to a nonzero value (the equivalent single-letter option character, if there is one). For long options that have a zero flag, GetOpt returns the contents of val.
void set_args(int argc, char **argv);
Set the argc and argv options.
void set_char_options(char *copts);
Set the single character option.
void set_long_options(option *lopts);
Set the long options array.
void add_long_option (char *lopt, ParamType pt, char copt);
Adds one long option to the current array (up to a total size of 32 elements). An example for one array entry could be:
{ "help", 0, 0, 'h'},   /* Help */
int getopt();
int getopt(int argc, char *const *argv, const char *optstring);
int operator() ();
Return the (short) getopt() value.
int getopt_long(int argc, char *const *argv, const char *options, const struct option *long_options,
int *opt_index);
Handles both short and long options.
int getopt_long_only(int argc, char *const *argv, const char *options, const struct option *long_options,
int *opt_index);
Handles only long options.
char *optarg();
double optarg_double();
int optarg_int()
int optind();
int optopt();
void opterr(int err);
These functions return the internal argument, index, unrecognized option character or error value. These values are taken from the original getopt.[h,c] files.


Go to the first, previous, next, last section, table of contents.