63 #ifdef __GNU_LIBRARY__ 131 #define BAD_OPTION '\0' 168 #ifdef __GNU_LIBRARY__ 174 #define my_index strchr 175 #define my_strlen strlen 181 #if __STDC__ || defined(PROTO) 183 extern int strcmp (
const char *s1,
const char *s2);
184 extern int strncmp(
const char *s1,
const char *s2,
size_t n);
187 static const char *
my_index (
const char *str,
int chr);
200 static const char *
my_index (
const char *str,
int chr)
205 return (
const char *) str;
241 #if __STDC__ || defined(PROTO) 247 char *temp, **first, **
last;
252 while (first < last) {
253 temp = *first; *first = *
last; *last = temp; first++; last--;
259 while (first < last) {
260 temp = *first; *first = *
last; *last = temp; first++; last--;
267 while (first < last) {
268 temp = *first; *first = *
last; *last = temp; first++; last--;
330 const char *optstring,
352 if (optstring[0] ==
'-')
357 else if (optstring[0] ==
'+')
415 if (fe_optind == argc)
427 if ((argv[fe_optind][0] !=
'-' || argv[fe_optind][1] ==
'\0')
430 || argv[fe_optind][0] !=
'+' || argv[fe_optind][1] ==
'\0')
449 && (argv[
fe_optind][1] ==
'-' || long_only))
462 while (*s && *s !=
'=')
466 for (p = longopts, option_index = 0; p->
name;
474 indfound = option_index;
478 else if (pfound ==
NULL)
482 indfound = option_index;
492 fprintf (stderr,
"%s: option `%s' is ambiguous\n",
501 option_index = indfound;
516 "%s: option `--%s' doesn't allow an argument\n",
517 argv[0], pfound->
name);
521 "%s: option `%c%s' doesn't allow an argument\n",
535 fprintf (stderr,
"%s: option `%s' requires an argument\n",
538 return optstring[0] ==
':' ?
':' :
BAD_OPTION;
543 *longind = option_index;
550 if (!long_only || argv[
fe_optind][1] ==
'-' 560 fprintf (stderr,
"%s: unrecognized option `--%s'\n",
564 fprintf (stderr,
"%s: unrecognized option `%c%s'\n",
577 const char *temp =
my_index (optstring, c);
583 if (temp ==
NULL || c ==
':')
588 if (c < 040 || c >= 0177)
589 fprintf (stderr,
"%s: unrecognized option, character code 0%o\n",
592 fprintf (stderr,
"%s: unrecognized option `-%c'\n", argv[0], c);
595 fprintf (stderr,
"%s: illegal option -- %c\n", argv[0], c);
630 fprintf (stderr,
"%s: option `-%c' requires an argument\n",
634 fprintf (stderr,
"%s: option requires an argument -- %c\n",
639 if (optstring[0] ==
':')
658 const char *optstring)
691 int main (
int argc,
char **argv)
694 int digit_optind = 0;
698 int this_option_optind = optind ? optind : 1;
700 c =
fe_getopt (argc, argv,
"abc:d:0123456789");
716 if (digit_optind != 0 && digit_optind != this_option_optind)
717 printf (
"digits occur in two different argv-elements.\n");
718 digit_optind = this_option_optind;
719 printf (
"option %c\n", c);
723 printf (
"option a\n");
727 printf (
"option b\n");
731 printf (
"option c with value `%s'\n",
fe_optarg);
738 printf (
"?? fe_getopt returned character code 0%o ??\n", c);
744 printf (
"non-option ARGV-elements: ");
const CanonicalForm int s
int fe_getopt(int argc, char *const *argv, const char *optstring)
int main(int argc, char *argv[])
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)
int _fe_getopt_internal(int argc, char *const *argv, const char *optstring, const struct fe_option *longopts, int *longind, int long_only)
char name(const Variable &v)
static void exchange(char **argv)
static const char * my_index(const char *str, int chr)
static size_t my_strlen(const char *str)