129#define BAD_OPTION '\0'
166#ifdef __GNU_LIBRARY__
172#define my_index strchr
173#define my_strlen strlen
179#if __STDC__ || defined(PROTO)
181extern int strcmp (
const char *s1,
const char *s2);
182extern int strncmp(
const char *s1,
const char *s2,
size_t n);
185static const char *
my_index (
const char *str,
int chr);
198static const char *
my_index (
const char *str,
int chr)
203 return (
const char *) str;
239#if __STDC__ || defined(PROTO)
245 char *temp, **first, **
last;
250 while (first <
last) {
251 temp = *first; *first = *
last; *
last = temp; first++;
last--;
257 while (first <
last) {
258 temp = *first; *first = *
last; *
last = temp; first++;
last--;
265 while (first <
last) {
266 temp = *first; *first = *
last; *
last = temp; first++;
last--;
328 const char *optstring,
350 if (optstring[0] ==
'-')
355 else if (optstring[0] ==
'+')
447 && (argv[
fe_optind][1] ==
'-' || long_only))
460 while (*
s && *
s !=
'=')
464 for (
p = longopts, option_index = 0;
p->name;
472 indfound = option_index;
476 else if (pfound ==
NULL)
480 indfound = option_index;
490 fprintf (stderr,
"%s: option `%s' is ambiguous\n",
499 option_index = indfound;
514 "%s: option `--%s' doesn't allow an argument\n",
515 argv[0], pfound->
name);
519 "%s: option `%c%s' doesn't allow an argument\n",
533 fprintf (stderr,
"%s: option `%s' requires an argument\n",
536 return optstring[0] ==
':' ?
':' :
BAD_OPTION;
541 *longind = option_index;
548 if (!long_only || argv[
fe_optind][1] ==
'-'
558 fprintf (stderr,
"%s: unrecognized option `--%s'\n",
562 fprintf (stderr,
"%s: unrecognized option `%c%s'\n",
575 const char *temp =
my_index (optstring, c);
581 if (temp ==
NULL || c ==
':')
586 if (c < 040 || c >= 0177)
587 fprintf (stderr,
"%s: unrecognized option, character code 0%o\n",
590 fprintf (stderr,
"%s: unrecognized option `-%c'\n", argv[0], c);
593 fprintf (stderr,
"%s: illegal option -- %c\n", argv[0], c);
628 fprintf (stderr,
"%s: option `-%c' requires an argument\n",
632 fprintf (stderr,
"%s: option requires an argument -- %c\n",
637 if (optstring[0] ==
':')
656 const char *optstring)
689int main (
int argc,
char **argv)
692 int digit_optind = 0;
696 int this_option_optind = optind ? optind : 1;
698 c =
fe_getopt (argc, argv,
"abc:d:0123456789");
714 if (digit_optind != 0 && digit_optind != this_option_optind)
715 printf (
"digits occur in two different argv-elements.\n");
716 digit_optind = this_option_optind;
717 printf (
"option %c\n", c);
721 printf (
"option a\n");
725 printf (
"option b\n");
729 printf (
"option c with value `%s'\n",
fe_optarg);
736 printf (
"?? fe_getopt returned character code 0%o ??\n", c);
742 printf (
"non-option ARGV-elements: ");
const CanonicalForm int s
int fe_getopt(int argc, char *const *argv, const char *optstring)
int fe_getopt_long_only(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
static void exchange(char **argv)
static size_t my_strlen(const char *str)
int _fe_getopt_internal(int argc, char *const *argv, const char *optstring, const struct fe_option *longopts, int *longind, int long_only)
static const char * my_index(const char *str, int chr)
int name
New type name for int.