394 if (cob_optind == argc)
436 if (longopts !=
NULL && (argv[cob_optind][1] ==
'-'
437 || (long_only && !
seen_short && (argv[cob_optind][2] || !strchr (optstring, argv[cob_optind][1])))))
440 unsigned int namelen;
445 struct option_list *next;
446 } *ambig_list =
NULL;
447 struct option_list *ambig_last =
NULL;
452 for (nameend =
nextchar; *nameend && *nameend !=
'='; nameend++)
458 for (p = longopts, option_index = 0; p->
name; p++, option_index++)
459 if (!strncmp (p->
name, nextchar, namelen)) {
460 if (namelen == (
unsigned int) strlen (p->
name)) {
463 indfound = option_index;
466 }
else if (pfound ==
NULL) {
469 indfound = option_index;
473 || pfound->
val != p->
val) {
477 newp->next = ambig_list;
479 ambig_last = ambig_list;
483 if (ambig_list !=
NULL){
486 struct option_list first;
488 first.next = ambig_list;
491 fprintf (stderr,
_(
"%s: option '%s' is ambiguous; possibilities:"),
492 argv[0], argv[cob_optind]);
495 fprintf (stderr,
" '--%s'", ambig_list->p->name);
496 ambig_list = ambig_list->next;
498 while (ambig_list !=
NULL);
500 fputc (
'\n', stderr);
503 while (ambig_last !=
NULL) {
504 ambig_list = ambig_last;
505 ambig_last = ambig_last->next;
509 nextchar += strlen (nextchar);
516 if (pfound !=
NULL) {
517 option_index = indfound;
529 if (argv[cob_optind - 1][1] ==
'-')
532 fprintf (stderr,
_(
"%s: option '--%s' doesn't allow an argument"),
533 argv[0], pfound->
name);
534 fputc (
'\n', stderr);
539 fprintf (stderr,
_(
"%s: option '%c%s' doesn't allow an argument"),
540 argv[0], argv[cob_optind - 1][0], pfound->
name);
541 fputc (
'\n', stderr);
545 nextchar += strlen (nextchar);
553 if (cob_optind < argc)
559 fprintf (stderr,
_(
"%s: option '--%s' requires an argument"),
560 argv[0], argv[cob_optind - 1]);
561 fputc (
'\n', stderr);
563 nextchar += strlen (nextchar);
565 return optstring[0] ==
':' ?
':' :
'?';
568 nextchar += strlen (nextchar);
570 *longind = option_index;
583 if (!long_only || argv[cob_optind][1] ==
'-'
584 || strchr (optstring, *nextchar) ==
NULL)
588 if (argv[cob_optind][1] ==
'-')
591 fprintf (stderr,
_(
"%s: unrecognized option '--%s'"),
593 fputc (
'\n', stderr);
598 fprintf (stderr,
_(
"%s: unrecognized option '%c%s'"),
599 argv[0], argv[cob_optind][0], nextchar);
600 fputc (
'\n', stderr);
603 nextchar = (
char *)
"";
613 char c = *nextchar++;
614 char *temp = strchr (optstring, c);
617 if (*nextchar ==
'\0')
623 if (temp ==
NULL || c ==
':')
627 fprintf (stderr,
_(
"%s: invalid option -- %c"), argv[0], c);
628 fputc (
'\n', stderr);
635 if (temp[0] ==
'W' && temp[1] ==
';')
646 if (*nextchar !=
'\0')
653 else if (cob_optind == argc)
658 fprintf (stderr,
_(
"%s: option requires an argument -- %c"),
660 fputc (
'\n', stderr);
663 if (optstring[0] ==
':')
677 if (!longopts)
return '?';
678 for (nextchar = nameend =
cob_optarg; *nameend && *nameend !=
'='; nameend++)
683 for (p = longopts, option_index = 0; p->
name; p++, option_index++)
684 if (!strncmp (p->
name, nextchar, (
size_t)(nameend - nextchar)))
686 if ((
unsigned int) (nameend - nextchar) == strlen (p->
name))
690 indfound = option_index;
694 else if (pfound ==
NULL)
698 indfound = option_index;
708 fprintf (stderr,
_(
"%s: option '-W %s' is ambiguous"),
709 argv[0], argv[cob_optind]);
710 fputc (
'\n', stderr);
712 nextchar += strlen (nextchar);
719 option_index = indfound;
730 fprintf (stderr,
_(
"%s: option '-W %s' doesn't allow an argument"),
731 argv[0], pfound->
name);
732 fputc (
'\n', stderr);
735 nextchar += strlen (nextchar);
742 if (cob_optind < argc)
748 fprintf (stderr,
_(
"%s: option '%s' requires an argument"),
749 argv[0], argv[cob_optind - 1]);
750 fputc (
'\n', stderr);
752 nextchar += strlen (nextchar);
754 return optstring[0] ==
':' ?
':' :
'?';
757 nextchar += strlen (nextchar);
759 *longind = option_index;
775 if (*nextchar !=
'\0')
787 if (*nextchar !=
'\0')
794 else if (cob_optind == argc)
799 fprintf (stderr,
_(
"%s: option requires an argument -- %c"),
801 fputc (
'\n', stderr);
805 if (optstring[0] ==
':')
void cob_free(void *mptr)
static void exchange(char **argv)
static int cob_getopt_initialized
static const char * _getopt_initialize(const char *optstring)
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
void * cob_fast_malloc(const size_t size)