getsubopt()

parse suboption arguments 

Function


SYNOPSIS

#include <stdlib.h>

int getsubopt(char **optionp, char * const *tokens, char **valuep);

extern char *suboptarg;


DESCRIPTION

The getsubopt() function parses suboption arguments in a flag argument that was initially parsed by getopt(). These suboption arguments must be separated by commas and may consist of either a single token, or a token-value pair separated by an equal sign. Because commas delimit suboption arguments in the option string, they are not allowed to be part of the suboption arguments or the value of a suboption argument. Similarly, because the equal sign separates a token from its value, a token must not contain an equal sign.

The getsubopt() function takes the address of a pointer to the option argument string, a vector of possible tokens, and the address of a value string pointer. If the option argument string at *optionp contains only one suboption argument, getsubopt() updates *optionp to point to the null separator at the end of the string. Otherwise, it isolates the suboption argument by replacing the comma separator with a null, and updates *optionp to point to the start of the next suboption argument. If the suboption argument has an associated value, getsubopt() updates *valuep to point to the value's first character. Otherwise it sets *valuep to a null pointer.

The token vector is organized as a series of pointers to strings. The end of the token vector is identified by a null pointer.

When getsubopt() returns, if *valuep is not a null pointer, then the suboption argument processed included a value. The calling program may use this information to determine if the presence or lack of a value for the suboption is an error.

Additionally, when getsubopt() fails to match a suboption argument with the tokens in the tokens array, the calling program should decide if this is an error, or if the unrecognized option should be passed on for other handling. In this case, the suboptarg variable points to the suboption for which a matching token could not be found.


PARAMETERS

optionp 

Points to the suboption list. This pointer is updated to point to the next suboption, or to the end-of-string null character.

tokens 

Is an array of token strings to match against suboptions. This array must be terminated by a null pointer.

valuep 

Points to the value associated with a suboption, or is a null pointer if there is no such value.


RETURN VALUES

The getsubopt() function returns the index of the matched token string, or -1 if no token string was matched. In addition, optionp, valuep and suboptarg are updated as described in the DESCRIPTION section.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The suboptarg variable is a non-portable extension to the UNIX 98 specification found on some systems.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
getopt()

Miscellaneous:
suboptarg


PTC MKS Toolkit 10.5 Documentation Build 40.