4 * Ripped from GLIBC - original copyright follows
6 * NOTE: Changed to make dependencies work better:
7 * * <config.h> changed to "config.h"
9 * $Id: getopt1.c,v 1.1.1.1 2002/06/21 08:51:58 fenix_nl Exp $
12 /* getopt_long and getopt_long_only entry points for GNU getopt.
13 Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
14 Free Software Foundation, Inc.
15 This file is part of the GNU C Library.
17 The GNU C Library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public License as
19 published by the Free Software Foundation; either version 2 of the
20 License, or (at your option) any later version.
22 The GNU C Library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Library General Public License for more details.
27 You should have received a copy of the GNU Library General Public
28 License along with the GNU C Library; see the file COPYING.LIB. If not,
29 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. */
36 #include "our_getopt.h"
38 #if !defined __STDC__ || !__STDC__
39 /* This is a separate conditional since some stdc systems
40 reject `defined (const)'. */
48 /* Comment out all this code if we are using the GNU C Library, and are not
49 actually compiling the library itself. This code is part of the GNU C
50 Library, but also included in many other GNU distributions. Compiling
51 and linking in this code is a waste when using the GNU C library
52 (especially if it is a shared library). Rather than having every GNU
53 program understand `configure --with-gnu-libc' and omit the object files,
54 it is simpler to just do this in the source for each such file. */
56 #define GETOPT_INTERFACE_VERSION 2
57 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
58 #include <gnu-versions.h>
59 #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
67 /* This needs to come after some library #include
68 to get __GNU_LIBRARY__ defined. */
69 #ifdef __GNU_LIBRARY__
78 getopt_long (argc
, argv
, options
, long_options
, opt_index
)
82 const struct option
*long_options
;
85 return _getopt_internal (argc
, argv
, options
, long_options
, opt_index
, 0);
88 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
89 If an option that starts with '-' (not '--') doesn't match a long option,
90 but does match a short option, it is parsed as a short option
94 getopt_long_only (argc
, argv
, options
, long_options
, opt_index
)
98 const struct option
*long_options
;
101 return _getopt_internal (argc
, argv
, options
, long_options
, opt_index
, 1);
105 #endif /* Not ELIDE_CODE. */
117 int digit_optind
= 0;
121 int this_option_optind
= optind
? optind
: 1;
122 int option_index
= 0;
123 static struct option long_options
[] =
128 {"verbose", 0, 0, 0},
134 c
= getopt_long (argc
, argv
, "abc:d:0123456789",
135 long_options
, &option_index
);
142 printf ("option %s", long_options
[option_index
].name
);
144 printf (" with arg %s", optarg
);
158 if (digit_optind
!= 0 && digit_optind
!= this_option_optind
)
159 printf ("digits occur in two different argv-elements.\n");
160 digit_optind
= this_option_optind
;
161 printf ("option %c\n", c
);
165 printf ("option a\n");
169 printf ("option b\n");
173 printf ("option c with value `%s'\n", optarg
);
177 printf ("option d with value `%s'\n", optarg
);
184 printf ("?? getopt returned character code 0%o ??\n", c
);
190 printf ("non-option ARGV-elements: ");
191 while (optind
< argc
)
192 printf ("%s ", argv
[optind
++]);