* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)getsubopt.c 5.2 (Berkeley) %G%";
* The SVID interface to getsubopt provides no way of figuring out which
* part of the suboptions list wasn't matched. This makes error messages
* tricky... The extern variable suboptarg is a pointer to the token
getsubopt(optionp
, tokens
, valuep
)
register char **optionp
, **valuep
;
register char * const *tokens
;
suboptarg
= *valuep
= NULL
;
if (!optionp
|| !*optionp
)
/* skip leading white-space, commas */
for (p
= *optionp
; *p
&& (*p
== ',' || *p
== ' ' || *p
== '\t'); ++p
);
/* save the start of the token, and skip the rest of the token. */
*++p
&& *p
!= ',' && *p
!= '=' && *p
!= ' ' && *p
!= '\t';);
* If there's an equals sign, set the value pointer, and
* skip over the value part of the token. Terminate the
*p
&& *p
!= ',' && *p
!= ' ' && *p
!= '\t'; ++p
);
/* Skip any whitespace or commas after this token. */
for (; *p
&& (*p
== ',' || *p
== ' ' || *p
== '\t'); ++p
);
/* set optionp for next round. */
for (cnt
= 0; *tokens
; ++tokens
, ++cnt
)
if (!strcmp(suboptarg
, *tokens
))