45 struct gk_option *longopts,
int *longind,
int long_only);
201 while (top > middle && middle > bottom) {
202 if (top - middle > middle - bottom) {
204 int len = middle - bottom;
208 for (i = 0; i <
len; i++) {
209 tem = argv[bottom +
i];
210 argv[bottom +
i] = argv[top - (middle - bottom) + i];
211 argv[top - (middle - bottom) + i] = tem;
218 int len = top - middle;
222 for (i = 0; i <
len; i++) {
223 tem = argv[bottom +
i];
224 argv[bottom +
i] = argv[middle +
i];
225 argv[middle +
i] = tem;
258 if (optstring[0] ==
'-') {
262 else if (optstring[0] ==
'+') {
331 struct gk_option *longopts,
int *longind,
int long_only)
334 if (optstring[0] ==
':')
353 # define NONOPTION_P (argv[gk_optind][0] != '-' || argv[gk_optind][1] == '\0') 403 if (gk_optind == argc) {
451 for (nameend =
nextchar; *nameend && *nameend !=
'='; nameend++)
455 for (p = longopts, option_index = 0; p->
name; p++, option_index++) {
457 if ((
unsigned int) (nameend -
nextchar) == (
unsigned int) strlen (p->
name)) {
460 indfound = option_index;
464 else if (pfound ==
NULL) {
467 indfound = option_index;
475 if (ambig && !exact) {
477 fprintf(
stderr,
"%s: option `%s' is ambiguous\n", argv[0], argv[gk_optind]);
485 if (pfound !=
NULL) {
486 option_index = indfound;
494 if (argv[gk_optind - 1][1] ==
'-')
496 fprintf(
stderr,
"%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->
name);
499 fprintf(
stderr,
"%s: option `%c%s' doesn't allow an argument\n", argv[0], argv[gk_optind - 1][0], pfound->
name);
508 else if (pfound->
has_arg == 1) {
509 if (gk_optind < argc)
513 fprintf(
stderr,
"%s: option `%s' requires an argument\n", argv[0], argv[gk_optind - 1]);
516 return optstring[0] ==
':' ?
':' :
'?';
521 *longind = option_index;
532 if (!long_only || argv[gk_optind][1] ==
'-' || strchr(optstring, *
nextchar) ==
NULL) {
534 if (argv[gk_optind][1] ==
'-')
536 fprintf(
stderr,
"%s: unrecognized option `--%s'\n", argv[0],
nextchar);
539 fprintf(
stderr,
"%s: unrecognized option `%c%s'\n", argv[0], argv[gk_optind][0],
nextchar);
551 char *temp = strchr(optstring, c);
557 if (temp ==
NULL || c ==
':') {
561 fprintf(
stderr,
"%s: illegal option -- %c\n", argv[0], c);
563 fprintf(
stderr,
"%s: invalid option -- %c\n", argv[0], c);
570 if (temp[0] ==
'W' && temp[1] ==
';') {
586 else if (gk_optind == argc) {
589 fprintf(
stderr,
"%s: option requires an argument -- %c\n", argv[0], c);
592 if (optstring[0] ==
':')
608 for (p = longopts, option_index = 0; p->
name; p++, option_index++) {
610 if ((
unsigned int) (nameend -
nextchar) == strlen (p->
name)) {
613 indfound = option_index;
617 else if (pfound ==
NULL) {
620 indfound = option_index;
627 if (ambig && !exact) {
629 fprintf(
stderr,
"%s: option `-W %s' is ambiguous\n", argv[0], argv[gk_optind]);
634 if (pfound !=
NULL) {
635 option_index = indfound;
642 fprintf(
stderr,
"%s: option `-W %s' doesn't allow an argument\n", argv[0], pfound->
name);
648 else if (pfound->
has_arg == 1) {
649 if (gk_optind < argc)
653 fprintf(
stderr,
"%s: option `%s' requires an argument\n", argv[0], argv[gk_optind - 1]);
655 return optstring[0] ==
':' ?
':' :
'?';
660 *longind = option_index;
671 if (temp[1] ==
':') {
672 if (temp[2] ==
':') {
688 }
else if (gk_optind == argc) {
691 fprintf(
stderr,
"%s: option requires an argument -- %c\n", argv[0],
695 if (optstring[0] ==
':')
The structure that stores the information about the command-line options.
static int gk_getopt_internal(int argc, char **argv, char *optstring, struct gk_option *longopts, int *longind, int long_only)
static char * gk_getopt_initialize(int, char **, char *)
int gk_getopt(int argc, char **argv, char *options)
Parse command-line arguments.
int gk_optind
Index in ARGV of the next element to be scanned.
int gk_optopt
Stores unknown option characters.
static struct gk_option long_options[]
int gk_getopt_long(int argc, char **argv, char *options, struct gk_option *long_options, int *opt_index)
Parse command-line arguments with long options.
static void exchange(char **)
static enum @1107 ordering
int gk_getopt_initialized
static char * posixly_correct
int gk_opterr
Controls error reporting for unrecognized options.
char * gk_optarg
For communication arguments to the caller.
size_t len(handle h)
Get the length of a Python object.
int gk_getopt_long_only(int argc, char **argv, char *options, struct gk_option *long_options, int *opt_index)
Parse command-line arguments with only long options.