diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-20 04:02:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-20 04:02:19 +0000 |
commit | a1e70df20cae2626fb6865651bf880c5efc935b0 (patch) | |
tree | cc74cde42b14f94eec31767889c44cc44958f1ea /lib/libc/gen | |
parent | 67eccf19d86af151b84fdf0a25a8e721bb0ad0e2 (diff) |
Move getsubopt(3) to stdlib like lite2 and XPG4.2 say...
Update man page from lite2 while I'm at it.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/gen/getsubopt.3 | 144 | ||||
-rw-r--r-- | lib/libc/gen/getsubopt.c | 100 |
3 files changed, 3 insertions, 247 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 1d7a9745697..e1783fa9989 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.12 1997/08/17 21:31:19 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.13 1997/08/20 04:02:15 millert Exp $ # gen sources .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/gen ${.CURDIR}/gen @@ -8,7 +8,7 @@ SRCS+= alarm.c assert.c basename.c clock.c closedir.c confstr.c ctermid.c \ errx.c errlist.c errno.c exec.c fnmatch.c fstab.c ftok.c fts.c \ getbsize.c getcap.c getcwd.c getdomainname.c getgrent.c \ getgrouplist.c gethostname.c getloadavg.c getlogin.c getmntinfo.c \ - getnetgrent.c getpagesize.c getpass.c getpwent.c getsubopt.c \ + getnetgrent.c getpagesize.c getpass.c getpwent.c \ getttyent.c getusershell.c glob.c initgroups.c isatty.c isctype.c \ nice.c nlist.c opendir.c pause.c popen.c psignal.c pwcache.c raise.c \ readdir.c rewinddir.c scandir.c seekdir.c setdomainname.c \ @@ -47,7 +47,7 @@ MAN+= alarm.3 basename.3 clock.3 confstr.3 ctermid.3 ctype.3 daemon.3 \ getbsize.3 getcap.3 getcwd.3 getdomainname.3 getdiskbyname.3 \ getfsent.3 getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ getmntinfo.3 getnetgrent.3 getpagesize.3 getpass.3 getpwent.3 \ - getsubopt.3 getttyent.3 getusershell.3 glob.3 initgroups.3 isalnum.3 \ + getttyent.3 getusershell.3 glob.3 initgroups.3 isalnum.3 \ isalpha.3 isascii.3 isblank.3 iscntrl.3 isdigit.3 isgraph.3 isinf.3 \ islower.3 isprint.3 ispunct.3 isspace.3 isupper.3 isxdigit.3 \ ldexp.3 modf.3 nice.3 nlist.3 pause.3 popen.3 psignal.3 pwcache.3 \ diff --git a/lib/libc/gen/getsubopt.3 b/lib/libc/gen/getsubopt.3 deleted file mode 100644 index ac3ee0b5d4a..00000000000 --- a/lib/libc/gen/getsubopt.3 +++ /dev/null @@ -1,144 +0,0 @@ -.\" $OpenBSD: getsubopt.3,v 1.2 1996/08/19 08:24:04 tholo Exp $ -.\" -.\" Copyright (c) 1990, 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and 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 -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" 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 -.\" SUCH DAMAGE. -.\" -.Dd July 31, 1991 -.Dt GETSUBOPT 3 -.Os -.Sh NAME -.Nm getsubopt -.Nd get sub options from an argument -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep" -.Sh DESCRIPTION -The -.Fn getsubopt -parses a string containing tokens delimited by one or more tab, space or -comma -.Pq Ql \&, -characters. -It is intended for use in parsing groups of option arguments provided -as part of a utility command line. -.Pp -The argument -.Fa optionp -is a pointer to a pointer to the string. -The argument -.Fa tokens -is a pointer to a -.Dv NULL Ns -terminated -array of pointers to strings. -.Pp -The -.Fn getsubopt -function -returns the zero-based offset of the pointer in the -.Fa tokens -array referencing a string which matches the first token -in the string, or, \-1 if the string contains no tokens or -.Fa tokens -does not contain a matching string. -.Pp -If the token is of the form ``name=value'', the location referenced by -.Fa valuep -will be set to point to the start of the ``value'' portion of the token. -.Pp -On return from -.Fn getsubopt , -.Fa optionp -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. -The external variable -.Fa suboptarg -will be set to point to the start of the current token, or -.Dv NULL -if no -tokens were present. -The argument -.Fa valuep -will be set to point to the ``value'' portion of the token, or -.Dv NULL -if no ``value'' portion was present. -.Sh EXAMPLE -.Bd -literal -compact -char *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; - } -.Ed -.Sh SEE ALSO -.Xr getopt 3 , -.Xr strsep 3 -.Sh HISTORY -The -.Fn getsubopt -function is -.Ud . diff --git a/lib/libc/gen/getsubopt.c b/lib/libc/gen/getsubopt.c deleted file mode 100644 index b5933ae3390..00000000000 --- a/lib/libc/gen/getsubopt.c +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and 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 - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * 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 - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getsubopt.c,v 1.2 1996/08/19 08:24:06 tholo Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <unistd.h> -#include <stdlib.h> -#include <string.h> - -/* - * 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 - * which didn't match. - */ -char *suboptarg; - -int -getsubopt(optionp, tokens, valuep) - register char **optionp, **valuep; - register char * const *tokens; -{ - register int cnt; - register char *p; - - suboptarg = *valuep = NULL; - - if (!optionp || !*optionp) - return(-1); - - /* skip leading white-space, commas */ - for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - - if (!*p) { - *optionp = p; - return(-1); - } - - /* save the start of the token, and skip the rest of the token. */ - for (suboptarg = p; - *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); - - if (*p) { - /* - * If there's an equals sign, set the value pointer, and - * skip over the value part of the token. Terminate the - * token. - */ - if (*p == '=') { - *p = '\0'; - for (*valuep = ++p; - *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); - if (*p) - *p++ = '\0'; - } else - *p++ = '\0'; - /* Skip any whitespace or commas after this token. */ - for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - } - - /* set optionp for next round. */ - *optionp = p; - - for (cnt = 0; *tokens; ++tokens, ++cnt) - if (!strcmp(suboptarg, *tokens)) - return(cnt); - return(-1); -} |