Merge "Sync with current upstream getopt_long.c."
This commit is contained in:
commit
4fcfd3a474
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getopt_long.c,v 1.22 2006/10/04 21:29:04 jmc Exp $ */
|
/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
|
||||||
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
|
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -248,7 +248,7 @@ parse_long_options(char * const *nargv, const char *options,
|
|||||||
if (short_too && current_argv_len == 1)
|
if (short_too && current_argv_len == 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (match == -1) /* first partial match */
|
if (match == -1) /* first partial match */
|
||||||
match = i;
|
match = i;
|
||||||
else if ((flags & FLAG_LONGONLY) ||
|
else if ((flags & FLAG_LONGONLY) ||
|
||||||
long_options[i].has_arg !=
|
long_options[i].has_arg !=
|
||||||
@ -359,30 +359,11 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
|
|||||||
{
|
{
|
||||||
char *oli; /* option letter list index */
|
char *oli; /* option letter list index */
|
||||||
int optchar, short_too;
|
int optchar, short_too;
|
||||||
int posixly_correct; /* no static, can be changed on the fly */
|
static int posixly_correct = -1;
|
||||||
|
|
||||||
if (options == NULL)
|
if (options == NULL)
|
||||||
return (-1);
|
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
|
* XXX Some GNU programs (like cvs) set optind to 0 instead of
|
||||||
* XXX using optreset. Work around this braindamage.
|
* XXX using optreset. Work around this braindamage.
|
||||||
@ -390,6 +371,19 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
|
|||||||
if (optind == 0)
|
if (optind == 0)
|
||||||
optind = optreset = 1;
|
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;
|
optarg = NULL;
|
||||||
if (optreset)
|
if (optreset)
|
||||||
nonopt_start = nonopt_end = -1;
|
nonopt_start = nonopt_end = -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user