![]() |
SLJ Test
1.0
System Latency Jitter Test
|
Parse command line options. More...
Go to the source code of this file.
Typedefs | |
typedef enum GETOPT_ORDERING_T | GETOPT_ORDERING_T |
Enumerations | |
enum | GETOPT_ORDERING_T { PERMUTE, RETURN_IN_ORDER, REQUIRE_ORDER } |
Functions | |
int | getopt_long (int argc, char **argv, const char *shortopts, const struct option *longopts, int *longind) |
int | getopt_long_only (int argc, char **argv, const char *shortopts, const struct option *longopts, int *longind) |
Variables | |
char * | optarg = NULL |
int | optind = 0 |
int | opterr = 1 |
int | optopt = '?' |
Parse command line options.
AUTHOR: Gregory Pietsch CREATED Fri Jan 10 21:13:05 1997
DESCRIPTION:
The getopt() function parses the command line arguments. Its arguments argc and argv are the argument count and array as passed to the main() function on program invocation. The argument optstring is a list of available option characters. If such a character is followed by a colon (`:'), the option takes an argument, which is placed in optarg. If such a character is followed by two colons, the option takes an optional argument, which is placed in optarg. If the option does not take an argument, optarg is NULL.
The external variable optind is the index of the next array element of argv to be processed; it communicates from one call to the next which element to process.
The getopt_long() function works like getopt() except that it also accepts long options started by two dashes `–'. If these take values, it is either in the form
–arg=value
or
–arg value
It takes the additional arguments longopts which is a pointer to the first element of an array of type option. The last element of the array has to be filled with NULL for the name field.
The longind pointer points to the index of the current long option relative to longopts if it is non-NULL.
The getopt() function returns the option character if the option was found successfully, `:' if there was a missing parameter for one of the options, `?' for an unknown option character, and EOF for the end of the option list.
The getopt_long() function's return value is described in the header file.
The function getopt_long_only() is identical to getopt_long(), except that a plus sign `+' can introduce long options as well as `–'.
The following describes how to deal with options that follow non-option argv-elements.
If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the optstring parameter.
PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were written to expect options and other argv-elements in any order and that care about the ordering of the two. We describe each non-option argv-element as if it were the argument of an option with character code 1. Using `-' as the first character of the optstring parameter selects this mode of operation.
The special argument `–' forces an end of option-scanning regardless of the value of ordering. In the case of RETURN_IN_ORDER, only `–' can cause getopt() and friends to return EOF with optind != argc.
COPYRIGHT NOTICE AND DISCLAIMER:
Copyright (C) 1997 Gregory Pietsch
This file and the accompanying getopt.h header file are hereby placed in the public domain without restrictions. Just give the author credit, don't claim you wrote it or prevent anyone else from using it.
Gregory Pietsch's current e-mail address: gpiet sch@ comca st.n et
Definition in file getopt.c.
typedef enum GETOPT_ORDERING_T GETOPT_ORDERING_T |
enum GETOPT_ORDERING_T |
int getopt_long | ( | int | argc, |
char ** | argv, | ||
const char * | shortopts, | ||
const struct option * | longopts, | ||
int * | longind | ||
) |
int getopt_long_only | ( | int | argc, |
char ** | argv, | ||
const char * | shortopts, | ||
const struct option * | longopts, | ||
int * | longind | ||
) |