36 #ifndef USE_GLIBC_GNUGETOPT    48 # if 0 //defined HAVE_LIBINTL_H || defined _LIBC    51 #   define _(msgid)     gettext (msgid)    54 #  define _(msgid)      (msgid)   201   while (top > middle && middle > bottom)
   203       if (top - middle > middle - bottom)
   206           int len = middle - bottom;
   210           for (i = 0; i < len; i++)
   212               tem = argv[bottom + i];
   213               argv[bottom + i] = argv[top - (middle - bottom) + i];
   214               argv[top - (middle - bottom) + i] = tem;
   222           int len = top - middle;
   226           for (i = 0; i < len; i++)
   228               tem = argv[bottom + i];
   229               argv[bottom + i] = argv[middle + i];
   230               argv[middle + i] = tem;
   264   if (optstring[0] == 
'-')
   269   else if (optstring[0] == 
'+')
   341   int print_errors = 
opterr;
   342   if (optstring[0] == 
':')
   360 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')   379             exchange (const_cast<char **>(argv));
   401             exchange (const_cast<char **>(argv));
   436                   + (longopts != NULL && argv[
optind][1] == 
'-'));
   455       && (argv[
optind][1] == 
'-'   456           || (long_only && (argv[
optind][2] || !strchr (optstring, argv[
optind][1])))))
   460       const struct option *pfound = NULL;
   466       for (nameend = 
nextchar; *nameend && *nameend != 
'='; nameend++)
   471       for (p = longopts, option_index = 0; p->
name; p++, option_index++)
   474             if (
unsigned(nameend - 
nextchar) == unsigned(strlen(p->
name)))
   478                 indfound = option_index;
   482             else if (pfound == NULL)
   486                 indfound = option_index;
   499             fprintf (stderr, 
_(
"%s: option '%s' is ambiguous\n"),
   500                      argv[0], argv[optind]);
   509           option_index = indfound;
   521                       if (argv[optind - 1][1] == 
'-')
   524                                  _(
"%s: option '--%s' doesn't allow an argument\n"),
   525                                  argv[0], pfound->
name);
   529                                  _(
"%s: option '%c%s' doesn't allow an argument\n"),
   530                                  argv[0], argv[optind - 1][0], pfound->
name);
   547                            _(
"%s: option '%s' requires an argument\n"),
   548                            argv[0], argv[optind - 1]);
   551                   return optstring[0] == 
':' ? 
':' : 
'?';
   556             *longind = option_index;
   569       if (!long_only || argv[optind][1] == 
'-'   570           || strchr (optstring, *
nextchar) == NULL)
   574               if (argv[optind][1] == 
'-')
   576                 fprintf (stderr, 
_(
"%s: unrecognized option '--%s'\n"),
   580                 fprintf (stderr, 
_(
"%s: unrecognized option '%c%s'\n"),
   581                          argv[0], argv[optind][0], 
nextchar);
   594     const char *temp = strchr (optstring, c);
   600     if (temp == NULL || c == 
':')
   606               fprintf (stderr, 
_(
"%s: illegal option -- %c\n"),
   609               fprintf (stderr, 
_(
"%s: invalid option -- %c\n"),
   616     if (temp[0] == 
'W' && temp[1] == 
';')
   620         const struct option *pfound = NULL;
   634         else if (optind == argc)
   639                 fprintf (stderr, 
_(
"%s: option requires an argument -- %c\n"),
   643             if (optstring[0] == 
':')
   657         for (
nextchar = nameend = 
optarg; *nameend && *nameend != 
'='; nameend++)
   662         for (p = longopts, option_index = 0; p->
name; p++, option_index++)
   665               if (
unsigned(nameend - 
nextchar) == 
unsigned(strlen(p->
name)))
   669                   indfound = option_index;
   673               else if (pfound == NULL)
   677                   indfound = option_index;
   686               fprintf (stderr, 
_(
"%s: option '-W %s' is ambiguous\n"),
   687                        argv[0], argv[optind]);
   694             option_index = indfound;
   704                       fprintf (stderr, 
_(
"\   705 %s: option '-W %s' doesn't allow an argument\n"),
   706                                argv[0], pfound->
name);
   720                                _(
"%s: option '%s' requires an argument\n"),
   721                                argv[0], argv[optind - 1]);
   723                     return optstring[0] == 
':' ? 
':' : 
'?';
   728               *longind = option_index;
   763             else if (optind == argc)
   769                              _(
"%s: option requires an argument -- %c\n"),
   773                 if (optstring[0] == 
':')
 Wrappers to allow GNU getopt to be used cleanly from C++ code. 
 
static int getopt_initialized
 
static void exchange(char **argv)
 
static char * posixly_correct
 
int gnu_getopt_internal_(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only)
 
static const char * getopt_initialize(int argc, char *const *argv, const char *optstring)