The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

getsubopt - parse suboption arguments from a string

 SYNOPSIS



#include <stdlib.h>

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

 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 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 organised 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 this suboption is an error.

Additionally, when getsubopt() fails to match the suboption argument with the tokens in the tokens array, the calling program should decide if this is an error, or if the unrecognised option should be passed on to another program.

 RETURN VALUE

The getsubopt() function returns the index of the matched token string, or -1 if no token strings were matched.

 ERRORS

No errors are defined.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

getopt(), <stdlib.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]