Documentation - C API
getopt_long.h File Reference

getopt_long More...

#include "generic.h"

Data Structures

struct  option
 getopt_long option More...

Macros

#define no_argument   0
#define required_argument   1
#define optional_argument   2

Functions

int getopt_long (int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
 Parse long options (BSD style)

Variables

int opterr
int optind
int optopt
char * optarg
int optreset

Detailed Description

Author:
Andrea Vedaldi

This is a drop-in replacament of GNU getopt_long meant to be used on platforms that do not support such functionality.

Author:
Andrea Vedaldi

Macro Definition Documentation

#define no_argument   0

option with no argument

#define optional_argument   2

option with optional argument

#define required_argument   1

option with required argument


Function Documentation

int getopt_long ( int  argc,
char *const  argv[],
const char *  optstring,
const struct option longopts,
int *  longindex 
)
Parameters:
argcnumber of arguments.
argvpointer to the vector of arguments.
optstringlist of abbreviated options
longoptslist of long options.
longindexindex of current option in longopts.
Returns:
the code of the next option.

This function extract long and short options from the argument list argv of argc entries.

A short options sequence is introduced by a single dash character -. Each short option is described by a single character in the string optstring, possibly followed by a : character to denote a (mandatory) argument of the short option. A short option with an argument cannot appear in the middle of a short option sequence, but only at the end.

A long option is introduced by a double dash . Each long option is described by an instance of the option structure in the longopts table (the last entry must be filled with zeroes to denote the end).

Illegal options and missing arguments cause the function to skip the option and return '?'. If opterr is true (default), the function prints an error message to stderr. Finally, if optstring has a leading :, then error messages are suppressed and a missing argument causes : to be returned.

Remarks:
The function is currently not thread safe.

Variable Documentation

char* optarg

argument of the current option

int opterr

code of the last error occured while parsing an option

int optind

index of the next option to process in argv

int optopt

current option

int optreset

reset flag