|
NAME
LIBRARYStandard C Library (libc, -lc) SYNOPSIS
extern char *suboptarg; int
DESCRIPTIONThe
The argument optionp is a pointer to a
pointer to the string. The argument tokens is a
pointer to a The
If the token is of the form ``name=value'', the location referenced by valuep will be set to point to the start of the ``value'' portion of the token. On return from
EXAMPLESchar *tokens[] = {
#define ONE 0
"one",
#define TWO 1
"two",
NULL
};
...
extern char *optarg, *suboptarg;
char *options, *value;
while ((ch = getopt(argc, argv, "ab:")) != -1) {
switch(ch) {
case 'a':
/* process ``a'' option */
break;
case 'b':
options = optarg;
while (*options) {
switch(getsubopt(&options, tokens, &value)) {
case ONE:
/* process ``one'' sub option */
break;
case TWO:
/* process ``two'' sub option */
if (!value)
error("no value for two");
i = atoi(value);
break;
case -1:
if (suboptarg)
error("illegal sub option %s",
suboptarg);
else
error("missing sub option");
break;
}
}
break;
}
}
HISTORYThe
|