39 #define _(msgid) ("\n" msgid)
56 #include <lal/LALgetopt.h>
147 # define my_index strchr
163 #define SWAP_FLAGS(ch1, ch2)
167 const char *shortopts,
168 const struct LALoption *longopts,
int *longind,
172 LALgetopt (
int argc,
char *
const *argv,
const char *optstring)
179 const struct LALoption *long_options,
int *opt_index)
191 const struct LALoption *long_options,
int *opt_index)
220 while (top > middle && middle > bottom)
222 if (top - middle > middle - bottom)
225 int len = middle - bottom;
229 for (i = 0; i < len; i++)
231 tem = argv[bottom + i];
232 argv[bottom + i] = argv[top - (middle - bottom) + i];
233 argv[top - (middle - bottom) + i] = tem;
234 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
242 int len = top - middle;
246 for (i = 0; i < len; i++)
248 tem = argv[bottom + i];
249 argv[bottom + i] = argv[middle + i];
250 argv[middle + i] = tem;
286 if (optstring[0] ==
'-')
291 else if (optstring[0] ==
'+')
364 const struct LALoption *longopts,
int *longind,
int long_only)
367 if (optstring[0] ==
':')
387 # define NONOPTION_P (argv[LALoptind][0] != '-' || argv[LALoptind][1] == '\0')
404 union {
char *
const *pcs;
char **ps;} bad = { argv };
426 union {
char *
const *pcs;
char **ps;} bad = { argv };
465 + (longopts != NULL && argv[
LALoptind][1] ==
'-'));
495 for (nameend =
nextchar; *nameend && *nameend !=
'='; nameend++)
500 for (
p = longopts, option_index = 0;
p->name;
p++, option_index++)
503 if ((
unsigned int) (nameend -
nextchar)
504 == (
unsigned int) strlen (
p->name))
508 indfound = option_index;
512 else if (pfound == NULL)
516 indfound = option_index;
520 || pfound->
flag !=
p->flag
521 || pfound->
val !=
p->val)
529 fprintf (stderr,
_(
"%s: option `%s' is ambiguous\n"),
539 option_index = indfound;
554 _(
"%s: option `--%s' doesn't allow an argument\n"),
555 argv[0], pfound->
name);
559 _(
"%s: option `%c%s' doesn't allow an argument\n"),
577 _(
"%s: option `%s' requires an argument\n"),
581 return optstring[0] ==
':' ?
':' :
'?';
586 *longind = option_index;
599 if (!long_only || argv[
LALoptind][1] ==
'-'
602 union {
const char *cs;
char *c; } wtf = {
"" };
607 fprintf (stderr,
_(
"%s: unrecognized option `--%s'\n"),
611 fprintf (stderr,
_(
"%s: unrecognized option `%c%s'\n"),
625 const char *temp =
my_index (optstring, c);
631 if (temp == NULL || c ==
':')
637 fprintf (stderr,
_(
"%s: illegal option -- %c\n"),
640 fprintf (stderr,
_(
"%s: invalid option -- %c\n"),
647 if (temp[0] ==
'W' && temp[1] ==
';')
670 fprintf (stderr,
_(
"%s: option requires an argument -- %c\n"),
674 if (optstring[0] ==
':')
693 for (
p = longopts, option_index = 0;
p->name;
p++, option_index++)
696 if ((
unsigned int) (nameend -
nextchar) == strlen (
p->name))
700 indfound = option_index;
704 else if (pfound == NULL)
708 indfound = option_index;
717 fprintf (stderr,
_(
"%s: option `-W %s' is ambiguous\n"),
725 option_index = indfound;
736 %s: option `-W %s' doesn't allow an argument\n"),
737 argv[0], pfound->
name);
751 _(
"%s: option `%s' requires an argument\n"),
754 return optstring[0] ==
':' ?
':' :
'?';
759 *longind = option_index;
800 _(
"%s: option requires an argument -- %c\n"),
804 if (optstring[0] ==
':')
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
static int __getopt_initialized
int LALgetopt(int argc, char *const *argv, const char *optstring)
#define SWAP_FLAGS(ch1, ch2)
static char * posixly_correct
static void exchange(char **)
static const char * _getopt_initialize(int, char *const *, const char *)
static int _getopt_internal(int argc, char *const *argv, const char *shortopts, const struct LALoption *longopts, int *longind, int long_only)