2 |
NOTE: getopt is now part of the C library, so if you don't know what |
NOTE: getopt is now part of the C library, so if you don't know what |
3 |
"Keep this file name-space clean" means, talk to drepper@gnu.org |
"Keep this file name-space clean" means, talk to drepper@gnu.org |
4 |
before changing it! |
before changing it! |
5 |
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 |
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002 |
6 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
7 |
This file is part of the GNU C Library. |
This file is part of the GNU C Library. |
8 |
|
|
9 |
The GNU C Library is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or modify |
10 |
modify it under the terms of the GNU Lesser General Public |
it under the terms of the GNU General Public License as published by |
11 |
License as published by the Free Software Foundation; either |
the Free Software Foundation; either version 2, or (at your option) |
12 |
version 2.1 of the License, or (at your option) any later version. |
any later version. |
13 |
|
|
14 |
The GNU C Library is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
Lesser General Public License for more details. |
GNU General Public License for more details. |
18 |
|
|
19 |
You should have received a copy of the GNU Lesser General Public |
You should have received a copy of the GNU General Public License |
20 |
License along with the GNU C Library; if not, write to the Free |
along with this program; if not, write to the Free Software Foundation, |
21 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
02111-1307 USA. */ |
|
22 |
|
|
23 |
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. |
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. |
24 |
Ditto for AIX 3.2 and <stdlib.h>. */ |
Ditto for AIX 3.2 and <stdlib.h>. */ |
30 |
# include <config.h> |
# include <config.h> |
31 |
#endif |
#endif |
32 |
|
|
|
#if !defined __STDC__ || !__STDC__ |
|
|
/* This is a separate conditional since some stdc systems |
|
|
reject `defined (const)'. */ |
|
|
# ifndef const |
|
|
# define const |
|
|
# endif |
|
|
#endif |
|
|
|
|
33 |
#include <stdio.h> |
#include <stdio.h> |
34 |
|
|
35 |
/* Comment out all this code if we are using the GNU C Library, and are not |
/* Comment out all this code if we are using the GNU C Library, and are not |
51 |
#ifndef ELIDE_CODE |
#ifndef ELIDE_CODE |
52 |
|
|
53 |
|
|
54 |
/* This needs to come after some library #include |
#if HAVE_STDLIB_H || defined __GNU_LIBRARY__ |
|
to get __GNU_LIBRARY__ defined. */ |
|
|
#ifdef __GNU_LIBRARY__ |
|
|
/* Don't include stdlib.h for non-GNU C libraries because some of them |
|
|
contain conflicting prototypes for getopt. */ |
|
55 |
# include <stdlib.h> |
# include <stdlib.h> |
56 |
|
#endif |
57 |
|
#if HAVE_UNISTD_H || defined __GNU_LIBRARY__ |
58 |
# include <unistd.h> |
# include <unistd.h> |
59 |
#endif /* GNU C library. */ |
#endif |
60 |
|
|
61 |
#ifdef VMS |
#ifdef VMS |
62 |
# include <unixlib.h> |
# include <unixlib.h> |
179 |
/* Value of POSIXLY_CORRECT environment variable. */ |
/* Value of POSIXLY_CORRECT environment variable. */ |
180 |
static char *posixly_correct; |
static char *posixly_correct; |
181 |
|
|
182 |
#ifdef __GNU_LIBRARY__ |
#if HAVE_STRING_H || defined __GNU_LIBRARY__ |
|
/* We want to avoid inclusion of string.h with non-GNU libraries |
|
|
because there are many ways it can cause trouble. |
|
|
On some systems, it contains special magic macros that don't work |
|
|
in GCC. */ |
|
183 |
# include <string.h> |
# include <string.h> |
|
# define my_index strchr |
|
184 |
#else |
#else |
185 |
|
# if HAVE_STRINGS_H |
|
# if HAVE_STRING_H |
|
|
# include <string.h> |
|
|
# else |
|
186 |
# include <strings.h> |
# include <strings.h> |
187 |
# endif |
# endif |
|
|
|
|
/* Avoid depending on library functions or files |
|
|
whose names are inconsistent. */ |
|
|
|
|
|
#ifndef getenv |
|
|
extern char *getenv (); |
|
188 |
#endif |
#endif |
189 |
|
|
190 |
|
#if !HAVE_STRCHR && !defined strchr && !defined __GNU_LIBRARY__ |
191 |
|
# define strchr my_strchr |
192 |
static char * |
static char * |
193 |
my_index (str, chr) |
strchr (str, chr) |
194 |
const char *str; |
const char *str; |
195 |
int chr; |
int chr; |
196 |
{ |
{ |
202 |
} |
} |
203 |
return 0; |
return 0; |
204 |
} |
} |
205 |
|
#endif |
206 |
|
|
207 |
/* If using GCC, we can safely declare strlen this way. |
#if !HAVE_DECL_GETENV && !defined getenv && !defined __GNU_LIBRARY__ |
208 |
If not using GCC, it is ok not to declare it. */ |
char *getenv (); |
209 |
#ifdef __GNUC__ |
#endif |
|
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. |
|
|
That was relevant to code that was here before. */ |
|
|
# if (!defined __STDC__ || !__STDC__) && !defined strlen |
|
|
/* gcc with -traditional declares the built-in strlen to return int, |
|
|
and has done so at least since version 2.4.5. -- rms. */ |
|
|
extern int strlen (const char *); |
|
|
# endif /* not __STDC__ */ |
|
|
#endif /* __GNUC__ */ |
|
|
|
|
|
#endif /* not __GNU_LIBRARY__ */ |
|
210 |
|
|
211 |
/* Handle permutation of arguments. */ |
/* Handle permutation of arguments. */ |
212 |
|
|
615 |
|
|
616 |
if (longopts != NULL |
if (longopts != NULL |
617 |
&& (argv[optind][1] == '-' |
&& (argv[optind][1] == '-' |
618 |
|| (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) |
|| (long_only && (argv[optind][2] || !strchr (optstring, argv[optind][1]))))) |
619 |
{ |
{ |
620 |
char *nameend; |
char *nameend; |
621 |
const struct option *p; |
const struct option *p; |
730 |
option, then it's an error. |
option, then it's an error. |
731 |
Otherwise interpret it as a short option. */ |
Otherwise interpret it as a short option. */ |
732 |
if (!long_only || argv[optind][1] == '-' |
if (!long_only || argv[optind][1] == '-' |
733 |
|| my_index (optstring, *nextchar) == NULL) |
|| strchr (optstring, *nextchar) == NULL) |
734 |
{ |
{ |
735 |
if (print_errors) |
if (print_errors) |
736 |
{ |
{ |
754 |
|
|
755 |
{ |
{ |
756 |
char c = *nextchar++; |
char c = *nextchar++; |
757 |
char *temp = my_index (optstring, c); |
char *temp = strchr (optstring, c); |
758 |
|
|
759 |
/* Increment `optind' when we start to process its last character. */ |
/* Increment `optind' when we start to process its last character. */ |
760 |
if (*nextchar == '\0') |
if (*nextchar == '\0') |