Remove K&R cruft in getopt.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 9 Sep 2003 18:36:53 +0000 (18:36 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 9 Sep 2003 18:36:53 +0000 (18:36 +0000)
config/srclist.txt
lib/getopt.c
lib/getopt.h
lib/getopt1.c
m4/getopt.m4

index 050bde19c8ed9902ba6b54757ce63c8a02c6ce7b..c210578ae165686e973eafb2718ee2607f14d034 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: srclist.txt,v 1.23 2003-08-17 05:30:20 eggert Exp $
+# $Id: srclist.txt,v 1.24 2003-09-09 18:36:53 eggert Exp $
 # Files for which we are not the source.  See ./srclistvars.sh for the
 # variable definitions.
 
@@ -74,8 +74,6 @@ $LIBCSRC/argp/argp-pv.c                       lib gpl
 $LIBCSRC/argp/argp-pvh.c               lib gpl
 $LIBCSRC/argp/argp-xinl.c              lib gpl
 $LIBCSRC/argp/argp.h                   lib gpl
-$LIBCSRC/posix/getopt.h                        lib gpl
-$LIBCSRC/posix/getopt1.c               lib gpl
 $LIBCSRC/posix/regex.h                 lib gpl
 $LIBCSRC/string/strdup.c               lib gpl
 $LIBCSRC/sysdeps/generic/strtoll.c     lib gpl
@@ -96,6 +94,8 @@ $LIBCSRC/sysdeps/generic/strtoul.c    lib gpl
 #$LIBCSRC/posix/fnmatch.h              lib gpl (fnmatch_.h in gnulib)
 #$LIBCSRC/posix/fnmatch_loop.c         lib gpl
 #$LIBCSRC/posix/getopt.c               lib gpl
+#$LIBCSRC/posix/getopt.h               lib gpl
+#$LIBCSRC/posix/getopt1.c              lib gpl
 #$LIBCSRC/posix/tempname.c             lib gpl
 #$LIBCSRC/stdlib/rpmatch.c             lib gpl
 #$LIBCSRC/string/strndup.c             lib gpl
index 3e7928a83852f0ac02364b87e5cdb0cd0c07a8ad..6dcdbebf5e8cb433630a4a79ce83e188ad89a34b 100644 (file)
@@ -2,8 +2,11 @@
    NOTE: getopt is now part of the C library, so if you don't know what
    "Keep this file name-space clean" means, talk to drepper@gnu.org
    before changing it!
-   Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002
-       Free Software Foundation, Inc.
+
+   Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
+   Inc.
+
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
 # include <config.h>
 #endif
 
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
-   reject `defined (const)'.  */
-# ifndef const
-#  define const
-# endif
-#endif
-
 #include <stdio.h>
 
 /* Comment out all this code if we are using the GNU C Library, and are not
 # include <unistd.h>
 #endif /* GNU C library.  */
 
+#include <string.h>
+
 #ifdef VMS
 # include <unixlib.h>
-# if HAVE_STRING_H - 0
-#  include <string.h>
-# endif
 #endif
 
 #ifdef _LIBC
@@ -193,20 +187,7 @@ static enum
 /* Value of POSIXLY_CORRECT environment variable.  */
 static char *posixly_correct;
 \f
-#ifdef __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.  */
-# include <string.h>
-# define my_index      strchr
-#else
-
-# if HAVE_STRING_H
-#  include <string.h>
-# else
-#  include <strings.h>
-# endif
+#ifndef        __GNU_LIBRARY__
 
 /* Avoid depending on library functions or files
    whose names are inconsistent.  */
@@ -215,32 +196,6 @@ static char *posixly_correct;
 extern char *getenv ();
 #endif
 
-static char *
-my_index (str, chr)
-     const char *str;
-     int chr;
-{
-  while (*str)
-    {
-      if (*str == chr)
-       return (char *) str;
-      str++;
-    }
-  return 0;
-}
-
-/* If using GCC, we can safely declare strlen this way.
-   If not using GCC, it is ok not to declare it.  */
-#ifdef __GNUC__
-/* 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__ */
 \f
 /* Handle permutation of arguments.  */
@@ -294,13 +249,8 @@ static int nonoption_flags_len;
    `first_nonopt' and `last_nonopt' are relocated so that they describe
    the new indices of the non-options in ARGV after they are moved.  */
 
-#if defined __STDC__ && __STDC__
-static void exchange (char **);
-#endif
-
 static void
-exchange (argv)
-     char **argv;
+exchange (char **argv)
 {
   int bottom = first_nonopt;
   int middle = last_nonopt;
@@ -380,14 +330,8 @@ exchange (argv)
 
 /* Initialize the internal data when the first call is made.  */
 
-#if defined __STDC__ && __STDC__
-static const char *_getopt_initialize (int, char *const *, const char *);
-#endif
 static const char *
-_getopt_initialize (argc, argv, optstring)
-     int argc;
-     char *const *argv;
-     const char *optstring;
+_getopt_initialize (int argc, char *const *argv, const char *optstring)
 {
   /* Start processing options with ARGV-element 1 (since ARGV-element 0
      is the program name); the sequence of previously skipped
@@ -506,13 +450,9 @@ _getopt_initialize (argc, argv, optstring)
    long-named options.  */
 
 int
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
-     int argc;
-     char *const *argv;
-     const char *optstring;
-     const struct option *longopts;
-     int *longind;
-     int long_only;
+_getopt_internal (int argc, char *const *argv,
+                 const char *optstring, const struct option *longopts,
+                 int *longind, int long_only)
 {
   int print_errors = opterr;
   if (optstring[0] == ':')
@@ -637,7 +577,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 
   if (longopts != NULL
       && (argv[optind][1] == '-'
-         || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
+         || (long_only
+             && (argv[optind][2] || !strchr (optstring, argv[optind][1])))))
     {
       char *nameend;
       const struct option *p;
@@ -822,7 +763,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
         option, then it's an error.
         Otherwise interpret it as a short option.  */
       if (!long_only || argv[optind][1] == '-'
-         || my_index (optstring, *nextchar) == NULL)
+         || strchr (optstring, *nextchar) == NULL)
        {
          if (print_errors)
            {
@@ -877,7 +818,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 
   {
     char c = *nextchar++;
-    char *temp = my_index (optstring, c);
+    char *temp = strchr (optstring, c);
 
     /* Increment `optind' when we start to process its last character.  */
     if (*nextchar == '\0')
@@ -1187,10 +1128,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 }
 
 int
-getopt (argc, argv, optstring)
-     int argc;
-     char *const *argv;
-     const char *optstring;
+getopt (int argc, char *const *argv, const char *optstring)
 {
   return _getopt_internal (argc, argv, optstring,
                           (const struct option *) 0,
@@ -1206,9 +1144,7 @@ getopt (argc, argv, optstring)
    the above definition of `getopt'.  */
 
 int
-main (argc, argv)
-     int argc;
-     char **argv;
+main (int argc, char **argv)
 {
   int c;
   int digit_optind = 0;
index 4d6adeea0d686c9bdb983d241d93a4b69f282868..1a55babfbce5065d5bef8c1eda4dcaefec2dce0d 100644 (file)
@@ -1,5 +1,8 @@
 /* Declarations for getopt.
-   Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
+
+   Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+   1999, 2001, 2003 Free Software Foundation, Inc.
+
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
@@ -92,11 +95,7 @@ extern int optopt;
 
 struct option
 {
-# if (defined __STDC__ && __STDC__) || defined __cplusplus
   const char *name;
-# else
-  char *name;
-# endif
   /* has_arg can't be an enum because some compilers complain about
      type mismatches in all the code that assumes it is an int.  */
   int has_arg;
@@ -136,17 +135,16 @@ struct option
    arguments to the option '\0'.  This behavior is specific to the GNU
    `getopt'.  */
 
-#if (defined __STDC__ && __STDC__) || defined __cplusplus
-# ifdef __GNU_LIBRARY__
+#ifdef __GNU_LIBRARY__
 /* Many other libraries have conflicting prototypes for getopt, with
    differences in the consts, in stdlib.h.  To avoid compilation
    errors, only prototype getopt for the GNU C library.  */
 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
-# else /* not __GNU_LIBRARY__ */
+#else /* not __GNU_LIBRARY__ */
 extern int getopt ();
-# endif /* __GNU_LIBRARY__ */
+#endif /* __GNU_LIBRARY__ */
 
-# ifndef __need_getopt
+#ifndef __need_getopt
 extern int getopt_long (int ___argc, char *const *___argv,
                        const char *__shortopts,
                        const struct option *__longopts, int *__longind);
@@ -159,16 +157,7 @@ extern int _getopt_internal (int ___argc, char *const *___argv,
                             const char *__shortopts,
                             const struct option *__longopts, int *__longind,
                             int __long_only);
-# endif
-#else /* not __STDC__ */
-extern int getopt ();
-# ifndef __need_getopt
-extern int getopt_long ();
-extern int getopt_long_only ();
-
-extern int _getopt_internal ();
-# endif
-#endif /* __STDC__ */
+#endif
 
 #ifdef __cplusplus
 }
index d2759cefd8055caf41f2da3dc6e520d6eb2ac48b..3288c726134471a39e12a6e8e9f59f82dc9836a1 100644 (file)
@@ -1,6 +1,8 @@
 /* getopt_long and getopt_long_only entry points for GNU getopt.
-   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
-     Free Software Foundation, Inc.
+
+   Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996,
+   1997, 1998, 2003 Free Software Foundation, Inc.
+
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
 # include "getopt.h"
 #endif
 
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
-   reject `defined (const)'.  */
-#ifndef const
-#define const
-#endif
-#endif
-
 #include <stdio.h>
 
 /* Comment out all this code if we are using the GNU C Library, and are not
 #endif
 
 int
-getopt_long (argc, argv, options, long_options, opt_index)
-     int argc;
-     char *const *argv;
-     const char *options;
-     const struct option *long_options;
-     int *opt_index;
+getopt_long (int argc,
+            char *const *argv,
+            const char *options,
+            const struct option *long_options,
+            int *opt_index)
 {
   return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
 }
@@ -83,12 +76,11 @@ getopt_long (argc, argv, options, long_options, opt_index)
    instead.  */
 
 int
-getopt_long_only (argc, argv, options, long_options, opt_index)
-     int argc;
-     char *const *argv;
-     const char *options;
-     const struct option *long_options;
-     int *opt_index;
+getopt_long_only (int argc,
+                 char *const *argv,
+                 const char *options,
+                 const struct option *long_options,
+                 int *opt_index)
 {
   return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
 }
@@ -105,9 +97,7 @@ libc_hidden_def (getopt_long_only)
 #include <stdio.h>
 
 int
-main (argc, argv)
-     int argc;
-     char **argv;
+main (int argc, char **argv)
 {
   int c;
   int digit_optind = 0;
index 558558de4735a4408b1b866af558911144b1ef1a..df602b985fd2bde3cbb7e07e1dae33e7e81181ca 100644 (file)
@@ -1,5 +1,5 @@
-# getopt.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# getopt.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -9,5 +9,5 @@ dnl the same distribution terms as the rest of that program.
 AC_DEFUN([gl_GETOPT],
 [
   dnl Prerequisites of lib/getopt.c.
-  AC_CHECK_HEADERS_ONCE(string.h)
+  :
 ])