2003-03-03 Christopher Faylor <cgf@redhat.com>
* mingwex/getopt.c: Refresh from NetBSD sources.
This commit is contained in:
parent
cffdb4b17f
commit
2b02bd3c3f
|
@ -1,9 +1,13 @@
|
||||||
|
2003-03-03 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* mingwex/getopt.c: Refresh from NetBSD sources.
|
||||||
|
|
||||||
2003-03-03 Danny Smith <dannysmith@users.sourceforge.net>
|
2003-03-03 Danny Smith <dannysmith@users.sourceforge.net>
|
||||||
|
|
||||||
* mingwex/getopt.c: New file, copied from cygwin srcs.
|
* mingwex/getopt.c: New file, copied from cygwin srcs.
|
||||||
* include/getopt.h: New file, copied from cygwin srcs.
|
* include/getopt.h: New file, copied from cygwin srcs.
|
||||||
* include/unistd.h: Include getopt.h.
|
* include/unistd.h: Include getopt.h.
|
||||||
* mingwex/Makefile.in ((DISTFILES): Add getopt.c.
|
* mingwex/Makefile.in (DISTFILES): Add getopt.c.
|
||||||
(POSIX_OBJS): Add getopt.o.
|
(POSIX_OBJS): Add getopt.o.
|
||||||
|
|
||||||
2003-03-02 Danny Smith <dannysmith@users.sourceforge.net>
|
2003-03-02 Danny Smith <dannysmith@users.sourceforge.net>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: getopt_long.c,v 1.12 2001/04/24 09:07:43 joda Exp $ */
|
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||||
|
@ -85,13 +85,13 @@ extern char __declspec(dllimport) *__progname;
|
||||||
|| (*options == ':') ? (int)':' : (int)'?')
|
|| (*options == ':') ? (int)':' : (int)'?')
|
||||||
#define INORDER (int)1
|
#define INORDER (int)1
|
||||||
|
|
||||||
#define EMSG ""
|
static char EMSG[1];
|
||||||
|
|
||||||
static int getopt_internal (int, char * const *, const char *);
|
static int getopt_internal (int, char * const *, const char *);
|
||||||
static int gcd (int, int);
|
static int gcd (int, int);
|
||||||
static void permute_args (int, int, int, char * const *);
|
static void permute_args (int, int, int, char * const *);
|
||||||
|
|
||||||
static const char *place = EMSG; /* option letter processing */
|
static char *place = EMSG; /* option letter processing */
|
||||||
|
|
||||||
/* XXX: set optreset to 1 rather than these two */
|
/* XXX: set optreset to 1 rather than these two */
|
||||||
static int nonopt_start = -1; /* first non option argument (for permute) */
|
static int nonopt_start = -1; /* first non option argument (for permute) */
|
||||||
|
@ -149,9 +149,9 @@ gcd(a, b)
|
||||||
* in each block).
|
* in each block).
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
permute_args(nonopt_start, nonopt_end, opt_end, nargv)
|
permute_args(panonopt_start, panonopt_end, opt_end, nargv)
|
||||||
int nonopt_start;
|
int panonopt_start;
|
||||||
int nonopt_end;
|
int panonopt_end;
|
||||||
int opt_end;
|
int opt_end;
|
||||||
char * const *nargv;
|
char * const *nargv;
|
||||||
{
|
{
|
||||||
|
@ -163,16 +163,16 @@ permute_args(nonopt_start, nonopt_end, opt_end, nargv)
|
||||||
/*
|
/*
|
||||||
* compute lengths of blocks and number and size of cycles
|
* compute lengths of blocks and number and size of cycles
|
||||||
*/
|
*/
|
||||||
nnonopts = nonopt_end - nonopt_start;
|
nnonopts = panonopt_end - panonopt_start;
|
||||||
nopts = opt_end - nonopt_end;
|
nopts = opt_end - panonopt_end;
|
||||||
ncycle = gcd(nnonopts, nopts);
|
ncycle = gcd(nnonopts, nopts);
|
||||||
cyclelen = (opt_end - nonopt_start) / ncycle;
|
cyclelen = (opt_end - panonopt_start) / ncycle;
|
||||||
|
|
||||||
for (i = 0; i < ncycle; i++) {
|
for (i = 0; i < ncycle; i++) {
|
||||||
cstart = nonopt_end+i;
|
cstart = panonopt_end+i;
|
||||||
pos = cstart;
|
pos = cstart;
|
||||||
for (j = 0; j < cyclelen; j++) {
|
for (j = 0; j < cyclelen; j++) {
|
||||||
if (pos >= nonopt_end)
|
if (pos >= panonopt_end)
|
||||||
pos -= nnonopts;
|
pos -= nnonopts;
|
||||||
else
|
else
|
||||||
pos += nopts;
|
pos += nopts;
|
||||||
|
@ -191,7 +191,10 @@ permute_args(nonopt_start, nonopt_end, opt_end, nargv)
|
||||||
* Returns -2 if -- is found (can be long option or end of options marker).
|
* Returns -2 if -- is found (can be long option or end of options marker).
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
getopt_internal(int nargc, char *const * nargv, const char *options)
|
getopt_internal(nargc, nargv, options)
|
||||||
|
int nargc;
|
||||||
|
char * const *nargv;
|
||||||
|
const char *options;
|
||||||
{
|
{
|
||||||
char *oli; /* option letter list index */
|
char *oli; /* option letter list index */
|
||||||
int optchar;
|
int optchar;
|
||||||
|
@ -206,7 +209,7 @@ getopt_internal(int nargc, char *const * nargv, const char *options)
|
||||||
* XXX re-initialize optind to 0 and have getopt_long(3)
|
* XXX re-initialize optind to 0 and have getopt_long(3)
|
||||||
* XXX properly function again. Work around this braindamage.
|
* XXX properly function again. Work around this braindamage.
|
||||||
*/
|
*/
|
||||||
if (optind == 0 && optreset == 0)
|
if (optind == 0)
|
||||||
optind = 1;
|
optind = 1;
|
||||||
|
|
||||||
if (optreset)
|
if (optreset)
|
||||||
|
@ -306,7 +309,7 @@ start:
|
||||||
} else { /* takes (optional) argument */
|
} else { /* takes (optional) argument */
|
||||||
optarg = NULL;
|
optarg = NULL;
|
||||||
if (*place) /* no white space */
|
if (*place) /* no white space */
|
||||||
optarg = (char *) place;
|
optarg = place;
|
||||||
/* XXX: disable test for :: if PC? (GNU doesn't) */
|
/* XXX: disable test for :: if PC? (GNU doesn't) */
|
||||||
else if (oli[1] != ':') { /* arg not optional */
|
else if (oli[1] != ':') { /* arg not optional */
|
||||||
if (++optind >= nargc) { /* no arg */
|
if (++optind >= nargc) { /* no arg */
|
||||||
|
@ -333,7 +336,10 @@ start:
|
||||||
* [eventually this will replace the real getopt]
|
* [eventually this will replace the real getopt]
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
getopt(int nargc, char * const *nargv, const char *options)
|
getopt(nargc, nargv, options)
|
||||||
|
int nargc;
|
||||||
|
char * const *nargv;
|
||||||
|
const char *options;
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -363,8 +369,12 @@ getopt(int nargc, char * const *nargv, const char *options)
|
||||||
* Parse argc/argv argument vector.
|
* Parse argc/argv argument vector.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
getopt_long(int nargc, char * const *nargv, const char *options,
|
getopt_long(nargc, nargv, options, long_options, idx)
|
||||||
const struct option *long_options, int *idx)
|
int nargc;
|
||||||
|
char * const *nargv;
|
||||||
|
const char *options;
|
||||||
|
const struct option *long_options;
|
||||||
|
int *idx;
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -378,7 +388,7 @@ getopt_long(int nargc, char * const *nargv, const char *options,
|
||||||
size_t current_argv_len;
|
size_t current_argv_len;
|
||||||
int i, match;
|
int i, match;
|
||||||
|
|
||||||
current_argv = (char *) place;
|
current_argv = place;
|
||||||
match = -1;
|
match = -1;
|
||||||
|
|
||||||
optind++;
|
optind++;
|
||||||
|
|
Loading…
Reference in New Issue