From 6d2408b771040e07ec34443db9c61e48e1f00db7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 9 Sep 2003 18:36:53 +0000 Subject: [PATCH] Remove K&R cruft in getopt. --- config/srclist.txt | 6 ++-- lib/getopt.c | 102 ++++++++++------------------------------------------- lib/getopt.h | 29 +++++---------- lib/getopt1.c | 40 ++++++++------------- m4/getopt.m4 | 6 ++-- 5 files changed, 49 insertions(+), 134 deletions(-) diff --git a/config/srclist.txt b/config/srclist.txt index 050bde19c..c210578ae 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -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 diff --git a/lib/getopt.c b/lib/getopt.c index 3e7928a83..6dcdbebf5 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -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 @@ -30,14 +33,6 @@ # include #endif -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -# ifndef const -# define const -# endif -#endif - #include /* Comment out all this code if we are using the GNU C Library, and are not @@ -68,11 +63,10 @@ # include #endif /* GNU C library. */ +#include + #ifdef VMS # include -# if HAVE_STRING_H - 0 -# include -# endif #endif #ifdef _LIBC @@ -193,20 +187,7 @@ static enum /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; -#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 -# define my_index strchr -#else - -# if HAVE_STRING_H -# include -# else -# include -# 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__ */ /* 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; diff --git a/lib/getopt.h b/lib/getopt.h index 4d6adeea0..1a55babfb 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -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 } diff --git a/lib/getopt1.c b/lib/getopt1.c index d2759cefd..3288c7261 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -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 @@ -27,14 +29,6 @@ # 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 /* Comment out all this code if we are using the GNU C Library, and are not @@ -67,12 +61,11 @@ #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 int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { int c; int digit_optind = 0; diff --git a/m4/getopt.m4 b/m4/getopt.m4 index 558558de4..df602b985 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -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) + : ]) -- 2.11.0