mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 08:30:59 +00:00
New file for porting to migw32, copied from base/Testing/wgetopt.h
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11119 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3167715eae
commit
8da9730c75
1 changed files with 65 additions and 0 deletions
65
Tools/wgetopt.h
Normal file
65
Tools/wgetopt.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#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
|
Loading…
Reference in a new issue