ZEDA  1.6.18
Data Structures | Macros | Functions
command line option manipulations.

Data Structures

struct  zOption
 command line option information. More...
 

Macros

#define Z_INTRANGE_BORDER   (-1)
 
#define zIsOption(o)   ( ( (o)[0] == '-' ) && !isdigit( (o)[1] ) && (o)[1] != '-' )
 check if an argument string is an option switch. More...
 

Functions

void zOptionHelp (zOption *opts)
 display a command line help. More...
 
void zOptionDiag (zOption *opts)
 diagnose option flags. More...
 
bool zOptionRead (zOption *opts, char **argv, zStrAddrList *arglist)
 read command line options. More...
 
void zParseIntRange (char *expr, int *from, int *to)
 parse integer range notation. More...
 
char * zGetArg (char ***argv)
 get the next command line argument. More...
 

Detailed Description

command line option operations are not available in the kernel space

Macro Definition Documentation

◆ Z_INTRANGE_BORDER

#define Z_INTRANGE_BORDER   (-1)

◆ zIsOption

#define zIsOption (   o)    ( ( (o)[0] == '-' ) && !isdigit( (o)[1] ) && (o)[1] != '-' )

check if an argument string is an option switch.

zIsOption() checks if a string is an option switch or not. If o begins with '-' or '/', it regards o as a commandline option switch.

Returns
zIsOption() returns the true value if option is regarded as a commandline option switch. Otherwise, the false value is returned.

Function Documentation

◆ zOptionHelp()

void zOptionHelp ( zOption opts)

display a command line help.

zOptionHelp() displays a guidance of command line options to the standard output in the following style:

-x, –xxx [arg] description

where 'x' is the short-version option switch, and 'xxx' is the long-version option switch.

The information of option key, argument and description are stored in opts. Refer zOptionRead() for more information.

See also
zOptionRead

◆ zOptionDiag()

void zOptionDiag ( zOption opts)

diagnose option flags.

zOptionDiag() diagnoses on/off status of each command line option defined by opts. The statuses are displayed to the standard error. This function is prepared for debugs.

See also
zOptionRead

◆ zOptionRead()

bool zOptionRead ( zOption opts,
char **  argv,
zStrAddrList arglist 
)

read command line options.

zOptionRead() reads command line arguments and parse the runtime argument vector according to opts.

The command line argument vector argv is parsed and detected options are validated. If valid arguments following the options are parsed, they are pointed by the arg member of the correspoinding option instance in opts.

When arguments which do not follow any options are picked up, they are sequentially stored into a list of addresses of strings arglist. arglist is automatically initialized in zOptionRead().

Example:

zOption opts[] = { { "x", NULL, "<x val>", "x value", NULL, false }, { "y", NULL, "<y val>", "y value", NULL, false }, { "z", NULL, NULL, "z switch", NULL, false }, { NULL, NULL, NULL, NULL, NULL, false }, }; zStrList arglist;

zOptionRead( opts, argv, &arglist ); ...

% command -x 1 -y – -1 -z str1 str2

Then, the contents of opts varies as follows:

opts[] = { { "x", NULL, "<x val>", "x value", "1", true }, { "y", NULL, "<y val>", "y value", "-1", true }, { "z", NULL, NULL, "z switch", NULL, true }, { NULL, NULL, NULL, NULL, NULL, false }, };

In addition, "str1" and "str2" are stored in arglist from the head to the tail.

Note that the string "--" disables the following string to be parsed as an option even if it begins with '-'.

◆ zParseIntRange()

void zParseIntRange ( char *  expr,
int *  from,
int *  to 
)

parse integer range notation.

zParseIntRange() parses a string expr which expresses an integer range, and sets from and to for the smallest and the largest values, respectively.

The followings are examples of strings.

"3" -> from 3 to 3

"3-7" -> from 3 to 7

"3-" -> from 3 to the last

"-7" -> from the beginning to 7

"-" -> from the beginning to the last

Note that Z_INTRANGE_BORDER is set for from to represent the beginning, or for to to represent the last.

◆ zGetArg()

char* zGetArg ( char ***  argv)

get the next command line argument.

zGetArg() gets the next argument from commandline arguments. argv is a pointer to the argument vector, which is directly proceeded. An associated usage of this function is as follows:

int main(int argc, char *argv[]){ char *arg; while( ( arg = zGetArg( &argv ) ) ){ ... } }

In the above case, zGetArg() directly increments argv. Note that one can never handle to the previous arguments.

Returns
a pointer to the next argument, if it exists, is returned. Otherwise, the null pointer is returned.