2 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
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, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
29 getopt_long (argc
, argv
, options
, long_options
, opt_index
)
33 const struct option
*long_options
;
38 _getopt_long_options
= long_options
;
39 val
= getopt (argc
, argv
, options
);
40 if (val
== 0 && opt_index
!= NULL
)
41 *opt_index
= option_index
;
45 /* Like getopt_long, but '-' as well as '+' can indicate a long option.
46 If an option that starts with '-' 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
;
60 _getopt_long_options
= long_options
;
61 _getopt_long_only
= 1;
62 val
= getopt (argc
, argv
, options
);
63 if (val
== 0 && opt_index
!= NULL
)
64 *opt_index
= option_index
;
83 int this_option_optind
= optind
? optind
: 1;
86 static struct option long_options
[] =
97 c
= getopt_long (argc
, argv
, "abc:d:0123456789",
98 long_options
, &option_index
);
105 printf ("option %s", (long_options
[option_index
]).name
);
107 printf (" with arg %s", optarg
);
121 if (digit_optind
!= 0 && digit_optind
!= this_option_optind
)
122 printf ("digits occur in two different argv-elements.\n");
123 digit_optind
= this_option_optind
;
124 printf ("option %c\n", c
);
128 printf ("option a\n");
132 printf ("option b\n");
136 printf ("option c with value `%s'\n", optarg
);
143 printf ("?? getopt returned character code 0%o ??\n", c
);
149 printf ("non-option ARGV-elements: ");
150 while (optind
< argc
)
151 printf ("%s ", argv
[optind
++]);