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.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/*-
/*-
 * Copyright (c) 1990, 1993
 * Copyright (c) 1990, 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.
 */
 */
 
 
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
#include <sys/cdefs.h>
 
 
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
 
 
/*
/*
 * The SVID interface to getsubopt provides no way of figuring out which
 * The SVID interface to getsubopt provides no way of figuring out which
 * part of the suboptions list wasn't matched.  This makes error messages
 * part of the suboptions list wasn't matched.  This makes error messages
 * tricky...  The extern variable suboptarg is a pointer to the token
 * tricky...  The extern variable suboptarg is a pointer to the token
 * which didn't match.
 * which didn't match.
 */
 */
char *suboptarg;
char *suboptarg;
 
 
int
int
getsubopt(optionp, tokens, valuep)
getsubopt(optionp, tokens, valuep)
        char **optionp, **valuep;
        char **optionp, **valuep;
        char * const *tokens;
        char * const *tokens;
{
{
        int cnt;
        int cnt;
        char *p;
        char *p;
 
 
        suboptarg = *valuep = NULL;
        suboptarg = *valuep = NULL;
 
 
        if (!optionp || !*optionp)
        if (!optionp || !*optionp)
                return(-1);
                return(-1);
 
 
        /* skip leading white-space, commas */
        /* skip leading white-space, commas */
        for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
        for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
 
 
        if (!*p) {
        if (!*p) {
                *optionp = p;
                *optionp = p;
                return(-1);
                return(-1);
        }
        }
 
 
        /* save the start of the token, and skip the rest of the token. */
        /* save the start of the token, and skip the rest of the token. */
        for (suboptarg = p;
        for (suboptarg = p;
            *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
            *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
 
 
        if (*p) {
        if (*p) {
                /*
                /*
                 * If there's an equals sign, set the value pointer, and
                 * If there's an equals sign, set the value pointer, and
                 * skip over the value part of the token.  Terminate the
                 * skip over the value part of the token.  Terminate the
                 * token.
                 * token.
                 */
                 */
                if (*p == '=') {
                if (*p == '=') {
                        *p = '\0';
                        *p = '\0';
                        for (*valuep = ++p;
                        for (*valuep = ++p;
                            *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
                            *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
                        if (*p)
                        if (*p)
                                *p++ = '\0';
                                *p++ = '\0';
                } else
                } else
                        *p++ = '\0';
                        *p++ = '\0';
                /* Skip any whitespace or commas after this token. */
                /* Skip any whitespace or commas after this token. */
                for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
                for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
        }
        }
 
 
        /* set optionp for next round. */
        /* set optionp for next round. */
        *optionp = p;
        *optionp = p;
 
 
        for (cnt = 0; *tokens; ++tokens, ++cnt)
        for (cnt = 0; *tokens; ++tokens, ++cnt)
                if (!strcmp(suboptarg, *tokens))
                if (!strcmp(suboptarg, *tokens))
                        return(cnt);
                        return(cnt);
        return(-1);
        return(-1);
}
}
 
 

powered by: WebSVN 2.1.0

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