X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetopt.c;h=45b16d19dd692d222dfe19a719dd7d815a82a406;hb=a5ebad6e40c4d4d2fa3034c66bea5007d6c73dc8;hp=c7fbc2d8013c5fe63bc51827a67215c402384a5a;hpb=cba9751a5c129f78d162fbe541a2f50ea1753e93;p=gnulib.git diff --git a/lib/getopt.c b/lib/getopt.c index c7fbc2d80..45b16d19d 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -27,17 +27,10 @@ #endif #ifdef HAVE_CONFIG_H -#if defined (emacs) || defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ #include -#else -#include "config.h" -#endif #endif -#ifndef __STDC__ +#if !defined (__STDC__) || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const @@ -158,6 +151,9 @@ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; #if defined (__GNU_LIBRARY__) || defined (__sgi) /* We want to avoid inclusion of string.h with non-GNU libraries @@ -192,7 +188,7 @@ my_index (str, chr) #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ -#ifndef __STDC__ +#if !defined (__STDC__) || !__STDC__ /* 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 *); @@ -289,6 +285,8 @@ _getopt_initialize (optstring) nextchar = NULL; + posixly_correct = getenv ("POSIXLY_CORRECT"); + /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') @@ -301,7 +299,7 @@ _getopt_initialize (optstring) ordering = REQUIRE_ORDER; ++optstring; } - else if (getenv ("POSIXLY_CORRECT") != NULL) + else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; @@ -480,7 +478,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; -#ifdef lint /* Suppress `used before initialized' warning. */ +#ifdef lint + /* Suppress `used before initialized' warning. */ indfound = 0; #endif @@ -609,8 +608,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { if (opterr) { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); } optopt = c; return '?';