getopt.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* getopt.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
int optopt;
static char * next_opt; /* Next character in cluster of options */
static char done;
static char sw_char;
static char init;
static char ** options; /* List of entries which are options */
static char ** non_options; /* List of entries which are not options */
static int options_count;
static int non_options_count;
#define BEGIN do {
#define END } while (0)
if (optmode == GETOPT_ANY) \
/* Note: `argv' is not const as GETOPT_ANY reorders argv[]. */
{
char c, *q;
int i, j;
{
next_opt = "";
if (optmode == GETOPT_ANY)
{
{
exit (255);
}
options_count = 0; non_options_count = 0;
}
}
if (done)
return -1;
if (*next_opt == 0)
{
{
if (optmode == GETOPT_ANY)
{
j = 1;
for (i = 0; i < options_count; ++i)
for (i = 0; i < non_options_count; ++i)
argv[j++] = non_options[i];
}
done = 1;
return -1;
}
{
if (optmode == GETOPT_UNIX)
{
done = 1;
return -1;
}
PUT (non_options);
if (optmode == GETOPT_ANY)
goto restart;
/* optmode==GETOPT_KEEP */
return 0;
}
{
if (optmode == GETOPT_ANY)
{
j = 1;
for (i = 0; i < options_count; ++i)
for (i = 0; i < non_options_count; ++i)
argv[j++] = non_options[i];
}
++optind;
done = 1;
return -1;
}
else
{
}
}
c = *next_opt++;
if (*next_opt == 0) /* Move to next argument if end of argument reached */
++optind;
{
{
if (c < ' ' || c >= 127)
argv[0], c);
else
}
optopt = c;
return '?';
}
if (q[1] == ':')
{
if (*next_opt != 0) /* Argument given */
{
next_opt = "";
++optind;
}
else if (q[2] == ':')
{ /* Required argument missing */
optopt = c;
}
else
{
}
}
return c;
}