Documentation - C API

getopt_long.c File Reference

getopt_long - Definition More...

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "generic.h"
#include "getopt_long.h"

Go to the source code of this file.

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 optind = 1
 option parsing last error
int optopt
 index of option to process in argv
char * optarg
 current option
int optreset
 argument of current option

Detailed Description

Author:
Andrea Vedaldi

Definition in file getopt_long.c.


Function Documentation

int getopt_long ( int  argc,
char *const   argv[],
const char *  optstring,
const struct option longopts,
int *  longindex 
)
Parameters:
argc 
argv 
optstring abbreviated options
longopts list of long options.
longindex index of current option in longopts.

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

A short options sequence is introduced by a singe dash -. Each short option is described by a single character in the 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).

Returns:
the code of the next option. 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.

Definition at line 66 of file getopt_long.c.

References option::flag, option::name, optarg, optind, optional_argument, optopt, optreset, required_argument, and option::val.