Put back in getopt for MinGW

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17700 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2003-09-22 03:55:32 +00:00
parent 23990d5134
commit 0eb1091cc6
2 changed files with 70 additions and 3 deletions

View file

@ -3,9 +3,6 @@
* Tools/cvtenc.m (main): Write using local/set encoding when
EscapeIn=YES.
* Tools/gdomap.c: Remove getopt function for MinGW
(patch from Leigh Smith <leigh@leighsmith.com>).
* Documentation/coding-standards.texi: Add section about object
persistance.

View file

@ -177,6 +177,76 @@ static void queue_probe(struct in_addr* to, struct in_addr *from,
int num_extras, struct in_addr* extra, int is_reply);
#ifdef __MINGW__
/* A simple implementation of getopt() */
static int
indexof(char c, char *string)
{
int i;
for (i = 0; i < strlen(string); i++)
{
if (string[i] == c)
{
return i;
}
}
return -1;
}
static char *optarg;
static char
getopt(int argc, char **argv, char *options)
{
static int argi;
static char *arg;
int index;
char retval = '\0';
optarg = NULL;
if (argi == 0)
{
argi = 1;
}
while (argi < argc)
{
arg = argv[argi];
if (strlen(arg) == 2)
{
if (arg[0] == '-')
{
if ((index = indexof(arg[1], options)) != -1)
{
retval = arg[1];
if (index < strlen(options))
{
if (options[index+1] == ':')
{
if (argi < argc-1)
{
argi++;
optarg = argv[argi];
}
else
{
return -1; /* ':' given, but argv exhausted */
}
}
}
}
}
}
argi++;
return retval;
}
return -1;
}
#endif
static char ebuf[2048];