2 Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC)
26 #else /* STDC_HEADERS or __GNU_LIBRARY__ */
28 #endif /* STDC_HEADERS or __GNU_LIBRARY__ */
35 getopt_long (argc, argv, options, long_options, opt_index)
39 const struct option *long_options;
42 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
45 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
46 If an option that starts with '-' (not '--') doesn't match a long option,
47 but does match a short option, it is parsed as a short option
51 getopt_long_only (argc, argv, options, long_options, opt_index)
55 const struct option *long_options;
58 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
75 int this_option_optind = optind ? optind : 1;
77 static struct option long_options[] =
88 c = getopt_long (argc, argv, "abc:d:0123456789",
89 long_options, &option_index);
96 printf ("option %s", long_options[option_index].name);
98 printf (" with arg %s", optarg);
112 if (digit_optind != 0 && digit_optind != this_option_optind)
113 printf ("digits occur in two different argv-elements.\n");
114 digit_optind = this_option_optind;
115 printf ("option %c\n", c);
119 printf ("option a\n");
123 printf ("option b\n");
127 printf ("option c with value `%s'\n", optarg);
131 printf ("option d with value `%s'\n", optarg);
138 printf ("?? getopt returned character code 0%o ??\n", c);
144 printf ("non-option ARGV-elements: ");
145 while (optind < argc)
146 printf ("%s ", argv[optind++]);