Loading...
--- Libc/Libc-1725.40.4/stdlib/FreeBSD/getopt_long.c
+++ Libc/Libc-391/stdlib/FreeBSD/getopt_long.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.17 2004/06/03 18:46:52 millert Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
@@ -35,6 +35,13 @@
* 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 NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -55,7 +62,7 @@
#endif /* LIBC_SCCS and not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.12 2004/07/06 13:58:45 ache Exp $");
#include <err.h>
#include <errno.h>
@@ -65,7 +72,7 @@
#define GNU_COMPATIBLE /* Be more compatible, configure's use us! */
-#if 0 /* we prefer to keep our getopt(3) */
+#ifndef GNU_COMPATIBLE
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
#endif
@@ -88,7 +95,7 @@
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
#define INORDER (int)1
-static char EMSG[] = "";
+#define EMSG ""
#ifdef GNU_COMPATIBLE
#define NO_PREFIX (-1)
@@ -194,7 +201,7 @@
{
char *current_argv, *has_equal;
#ifdef GNU_COMPATIBLE
- const char *current_dash;
+ char *current_dash;
#endif
size_t current_argv_len;
int i, match, exact_match, second_partial_match;
@@ -248,7 +255,7 @@
if (short_too && current_argv_len == 1)
continue;
- if (match == -1) /* first partial match */
+ if (match == -1) /* first partial match */
match = i;
else if ((flags & FLAG_LONGONLY) ||
long_options[i].has_arg !=
@@ -359,10 +366,29 @@
{
char *oli; /* option letter list index */
int optchar, short_too;
- static int posixly_correct = -1;
+ int posixly_correct;
if (options == NULL)
return (-1);
+
+ /*
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+#ifdef GNU_COMPATIBLE
+ if (*options == '-')
+ flags |= FLAG_ALLARGS;
+ else if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+#else
+ if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+ else if (*options == '-')
+ flags |= FLAG_ALLARGS;
+#endif
+ if (*options == '+' || *options == '-')
+ options++;
/*
* XXX Some GNU programs (like cvs) set optind to 0 instead of
@@ -370,19 +396,6 @@
*/
if (optind == 0)
optind = optreset = 1;
-
- /*
- * Disable GNU extensions if POSIXLY_CORRECT is set or options
- * string begins with a '+'.
- */
- if (posixly_correct == -1 || optreset)
- posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
- if (*options == '-')
- flags |= FLAG_ALLARGS;
- else if (posixly_correct || *options == '+')
- flags &= ~FLAG_PERMUTE;
- if (*options == '+' || *options == '-')
- options++;
optarg = NULL;
if (optreset)
@@ -481,8 +494,6 @@
#endif
if (*place == '-') {
place++; /* --foo long option */
- if (*place == '\0')
- return (BADARG); /* malformed option */
#ifdef GNU_COMPATIBLE
dash_prefix = DD_PREFIX;
#endif
@@ -547,6 +558,7 @@
optarg = NULL;
if (*place) /* no white space */
optarg = place;
+ /* XXX: disable test for :: if PC? (GNU doesn't) */
else if (oli[1] != ':') { /* arg not optional */
if (++optind >= nargc) { /* no arg */
place = EMSG;
@@ -556,6 +568,14 @@
return (BADARG);
} else
optarg = nargv[optind];
+ } else if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If permutation is disabled, we can accept an
+ * optional arg separated by whitespace so long
+ * as it does not start with a dash (-).
+ */
+ if (optind + 1 < nargc && *nargv[optind + 1] != '-')
+ optarg = nargv[++optind];
}
place = EMSG;
++optind;
@@ -592,8 +612,12 @@
* Parse argc/argv argument vector.
*/
int
-getopt_long(int nargc, char * const *nargv, const char *options,
- const struct option *long_options, int *idx)
+getopt_long(nargc, nargv, options, long_options, idx)
+ int nargc;
+ char * const *nargv;
+ const char *options;
+ const struct option *long_options;
+ int *idx;
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
@@ -605,8 +629,12 @@
* Parse argc/argv argument vector.
*/
int
-getopt_long_only(int nargc, char * const *nargv, const char *options,
- const struct option *long_options, int *idx)
+getopt_long_only(nargc, nargv, options, long_options, idx)
+ int nargc;
+ char * const *nargv;
+ const char *options;
+ const struct option *long_options;
+ int *idx;
{
return (getopt_internal(nargc, nargv, options, long_options, idx,