OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [stdlib/] [getsubopt.3] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
.\" Copyright (c) 1990, 1991, 1993
.\" Copyright (c) 1990, 1991, 1993
.\"     The Regents of the University of California.  All rights reserved.
.\"     The Regents of the University of California.  All rights reserved.
.\"
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"    must display the following acknowledgement:
.\"     This product includes software developed by the University of
.\"     This product includes software developed by the University of
.\"     California, Berkeley and its contributors.
.\"     California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"    without specific prior written permission.
.\"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\" SUCH DAMAGE.
.\"
.\"
.\"     @(#)getsubopt.3 8.1 (Berkeley) 6/9/93
.\"     @(#)getsubopt.3 8.1 (Berkeley) 6/9/93
.\" $FreeBSD: src/lib/libc/stdlib/getsubopt.3,v 1.9 2001/09/07 14:46:35 asmodai Exp $
.\" $FreeBSD: src/lib/libc/stdlib/getsubopt.3,v 1.9 2001/09/07 14:46:35 asmodai Exp $
.\"
.\"
.Dd June 9, 1993
.Dd June 9, 1993
.Dt GETSUBOPT 3
.Dt GETSUBOPT 3
.Os
.Os
.Sh NAME
.Sh NAME
.Nm getsubopt
.Nm getsubopt
.Nd get sub options from an argument
.Nd get sub options from an argument
.Sh LIBRARY
.Sh LIBRARY
.Lb libc
.Lb libc
.Sh SYNOPSIS
.Sh SYNOPSIS
.In unistd.h
.In unistd.h
.Vt extern char *suboptarg ;
.Vt extern char *suboptarg ;
.Ft int
.Ft int
.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep"
.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep"
.Sh DESCRIPTION
.Sh DESCRIPTION
The
The
.Fn getsubopt
.Fn getsubopt
function
function
parses a string containing tokens delimited by one or more tab, space or
parses a string containing tokens delimited by one or more tab, space or
comma
comma
.Pq Ql \&,
.Pq Ql \&,
characters.
characters.
It is intended for use in parsing groups of option arguments provided
It is intended for use in parsing groups of option arguments provided
as part of a utility command line.
as part of a utility command line.
.Pp
.Pp
The argument
The argument
.Fa optionp
.Fa optionp
is a pointer to a pointer to the string.
is a pointer to a pointer to the string.
The argument
The argument
.Fa tokens
.Fa tokens
is a pointer to a
is a pointer to a
.Dv NULL Ns -terminated
.Dv NULL Ns -terminated
array of pointers to strings.
array of pointers to strings.
.Pp
.Pp
The
The
.Fn getsubopt
.Fn getsubopt
function
function
returns the zero-based offset of the pointer in the
returns the zero-based offset of the pointer in the
.Fa tokens
.Fa tokens
array referencing a string which matches the first token
array referencing a string which matches the first token
in the string, or, \-1 if the string contains no tokens or
in the string, or, \-1 if the string contains no tokens or
.Fa tokens
.Fa tokens
does not contain a matching string.
does not contain a matching string.
.Pp
.Pp
If the token is of the form ``name=value'', the location referenced by
If the token is of the form ``name=value'', the location referenced by
.Fa valuep
.Fa valuep
will be set to point to the start of the ``value'' portion of the token.
will be set to point to the start of the ``value'' portion of the token.
.Pp
.Pp
On return from
On return from
.Fn getsubopt ,
.Fn getsubopt ,
.Fa optionp
.Fa optionp
will be set to point to the start of the next token in the string,
will be set to point to the start of the next token in the string,
or the null at the end of the string if no more tokens are present.
or the null at the end of the string if no more tokens are present.
The external variable
The external variable
.Fa suboptarg
.Fa suboptarg
will be set to point to the start of the current token, or
will be set to point to the start of the current token, or
.Dv NULL
.Dv NULL
if no
if no
tokens were present.
tokens were present.
The argument
The argument
.Fa valuep
.Fa valuep
will be set to point to the ``value'' portion of the token, or
will be set to point to the ``value'' portion of the token, or
.Dv NULL
.Dv NULL
if no ``value'' portion was present.
if no ``value'' portion was present.
.Sh EXAMPLES
.Sh EXAMPLES
.Bd -literal -compact
.Bd -literal -compact
char *tokens[] = {
char *tokens[] = {
        #define ONE     0
        #define ONE     0
                "one",
                "one",
        #define TWO     1
        #define TWO     1
                "two",
                "two",
        NULL
        NULL
};
};
\&...
\&...
extern char *optarg, *suboptarg;
extern char *optarg, *suboptarg;
char *options, *value;
char *options, *value;
while ((ch = getopt(argc, argv, "ab:")) != \-1) {
while ((ch = getopt(argc, argv, "ab:")) != \-1) {
        switch(ch) {
        switch(ch) {
        case 'a':
        case 'a':
                /* process ``a'' option */
                /* process ``a'' option */
                break;
                break;
        case 'b':
        case 'b':
                options = optarg;
                options = optarg;
                while (*options) {
                while (*options) {
                        switch(getsubopt(&options, tokens, &value)) {
                        switch(getsubopt(&options, tokens, &value)) {
                        case ONE:
                        case ONE:
                                /* process ``one'' sub option */
                                /* process ``one'' sub option */
                                break;
                                break;
                        case TWO:
                        case TWO:
                                /* process ``two'' sub option */
                                /* process ``two'' sub option */
                                if (!value)
                                if (!value)
                                        error("no value for two");
                                        error("no value for two");
                                i = atoi(value);
                                i = atoi(value);
                                break;
                                break;
                        case \-1:
                        case \-1:
                                if (suboptarg)
                                if (suboptarg)
                                        error("illegal sub option %s",
                                        error("illegal sub option %s",
                                          suboptarg);
                                          suboptarg);
                                else
                                else
                                        error("missing sub option");
                                        error("missing sub option");
                                break;
                                break;
                }
                }
                break;
                break;
        }
        }
.Ed
.Ed
.Sh SEE ALSO
.Sh SEE ALSO
.Xr getopt 3 ,
.Xr getopt 3 ,
.Xr strsep 3
.Xr strsep 3
.Sh HISTORY
.Sh HISTORY
The
The
.Fn getsubopt
.Fn getsubopt
function first appeared in
function first appeared in
.Bx 4.4 .
.Bx 4.4 .
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.