Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

cmdlong.h File Reference

Long command-line options. More...

#include <stdlib.h>
#include <stdio.h>

Include dependency graph for cmdlong.h:

Include dependency graph

Go to the source code of this file.

Compounds

union  Cmdlongvar_
 Cmdlongvar_: union for storing all possible option variables. More...


Functions

int cmdlong_addopts (const char *Descr)
 cmdlong_addopts(Descr): parses the long option description string Descr and adds the descriptions to the internal Opts array. More...

int cmdlong_getopts (int argc, char *argv[])
 cmdlong_getopts(argc, argv): reads the command-line argument array argv and parses all options. More...

int bool_option (const char *Optname)
 bool_option(Optname): returns 1 if the Boolean option Optname has been seen on the command line, 0 otherwise.

int yesno_option (const char *Optname, int Defval)
 TYPE_option(Optname, Defval): returns the value for the option Optname if it was correctly supplied on the command line, or the corresponding default value Defval otherwise. More...

char char_option (const char *Optname, char Defval)
long long_option (const char *Optname, long Defval)
double dbl_option (const char *Optname, double Defval)
const char* str_option (const char *Optname, const char *Defval)
int check_option (const char *Optname, Cmdlongvar_ *Value)
 check_option(Optname, Value): returns non-0 if option Optname has been seen on the command line, 0 otherwise. More...

const char* help_string (const char *Optname)
 help_string(Optname): returns a description of option Optname in a static string. More...

void remove_cmdlongs (void)
 remove_cmdlongs(): frees up the internal Opts array. More...


Detailed Description

Long command-line options.

Supports switches (-opt) and option variables (-opt=xxx) using a rather permissive syntax. Only the shortest unique option strings need to be specified.

Definition in file cmdlong.h.


Function Documentation

int cmdlong_addopts ( const char * Descr )
 

cmdlong_addopts(Descr): parses the long option description string Descr and adds the descriptions to the internal Opts array.

Descr should contain the following description tokens separated by one or more spaces or tab chars:- "opt": boolean option -opt or --opt, or "opt=x": option with a mandatory argument where the argument type is 'y' for "yes|no" switches ("on|off" also accepted, case-insensitive) 'c' for characters, 'd' for integers (actually longs), 'f' for floats (actually doubles) 's' for strings. The function may be invoked more than once (but this is unnecessary). To avoid memory leaks, call remove_cmdlongs() before exiting your program. Return value: the number of successfully added options (0 on error).

Referenced by Cmdlongvar_::Str().

int cmdlong_getopts ( int argc,
char * argv[] )
 

cmdlong_getopts(argc, argv): reads the command-line argument array argv and parses all options.

Parsing stops at "-", "--" or at the first non-option argument. Invoke once before querying the options. A warning is issued if an unknown option is detected. Malformed options (with bad or missing values etc.) will be treated as absent. Return value: the index of the argv[] element containing the first non-option value, a negative value if there are no non-options left.

Referenced by Cmdlongvar_::Str().

int bool_option ( const char * Optname )
 

bool_option(Optname): returns 1 if the Boolean option Optname has been seen on the command line, 0 otherwise.

Referenced by Cmdlongvar_::Str().

int yesno_option ( const char * Optname,
int Defval )
 

TYPE_option(Optname, Defval): returns the value for the option Optname if it was correctly supplied on the command line, or the corresponding default value Defval otherwise.

TYPE=(yesno|char|long|dbl|str).

Referenced by Cmdlongvar_::Str().

char char_option ( const char * Optname,
char Defval )
 

Referenced by Cmdlongvar_::Str().

long long_option ( const char * Optname,
long Defval )
 

Referenced by Cmdlongvar_::Str().

double dbl_option ( const char * Optname,
double Defval )
 

Referenced by Cmdlongvar_::Str().

const char* str_option ( const char * Optname,
const char * Defval )
 

Referenced by Cmdlongvar_::Str().

int check_option ( const char * Optname,
Cmdlongvar_ * Value )
 

check_option(Optname, Value): returns non-0 if option Optname has been seen on the command line, 0 otherwise.

If Value!=NULL, then the value of the option is returned in *Value. It is the caller's responsibility to convert the *Value union to something less dangerous.

Referenced by Cmdlongvar_::Str().

const char * help_string ( const char * Optname )
 

help_string(Optname): returns a description of option Optname in a static string.

Returns NULL if Optname was not found. Printing does not end w/ a newline so it can be embedded nicely. Note that only a simplified syntax is printed: options printed with a single '-' although "--" is also accepted, and the option value separator is '=' although whitespace is also OK. The returned string is overwritten between calls.

Referenced by Cmdlongvar_::Str().

void remove_cmdlongs ( void )
 

remove_cmdlongs(): frees up the internal Opts array.

Call it once before exiting to avoid memory leaks.

Referenced by Cmdlongvar_::Str().


Generated at Wed Aug 21 09:33:39 2002 for The Razorback C Library: Miscellaneous Utilities by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001