mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 05:30:54 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21393 72102866-910b-0410-8b05-ffd578937521
85 lines
1.8 KiB
C
85 lines
1.8 KiB
C
/* wgetopt
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
This file is part of the GNU Objective C User Interface library.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; if not, write to the Free
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
|
*/
|
|
#if (defined __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 int optind;
|
|
static char
|
|
getopt(int argc, char **argv, char *options)
|
|
{
|
|
static char *arg;
|
|
int index;
|
|
char retval = '\0';
|
|
|
|
optarg = NULL;
|
|
if (optind == 0)
|
|
{
|
|
optind = 1;
|
|
}
|
|
while (optind < argc)
|
|
{
|
|
arg = argv[optind];
|
|
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 (optind < argc-1)
|
|
{
|
|
optind++;
|
|
optarg = argv[optind];
|
|
}
|
|
else
|
|
{
|
|
return -1; /* ':' given, but argv exhausted */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
optind++;
|
|
return retval;
|
|
}
|
|
return -1;
|
|
}
|
|
#endif
|