diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | lib/Makefile.in | 4 | ||||
-rw-r--r-- | lib/getopt.c | 59 | ||||
-rw-r--r-- | lib/getopt.c.patch | 25 | ||||
-rw-r--r-- | lib/getopt.h | 14 | ||||
-rw-r--r-- | lib/getopt.h.patch | 70 | ||||
-rw-r--r-- | lib/getopt1.c | 34 | ||||
-rw-r--r-- | tests/jstest1.gperf | 11 | ||||
-rw-r--r-- | tests/jstest2.gperf | 11 | ||||
-rw-r--r-- | tests/jstest3.gperf | 11 | ||||
-rw-r--r-- | tests/jstest4.gperf | 11 | ||||
-rw-r--r-- | tests/test.c | 10 | ||||
-rw-r--r-- | tests/test2.c | 10 |
13 files changed, 51 insertions, 237 deletions
@@ -1,3 +1,21 @@ +2016-11-27 Bruno Haible <bruno@clisp.org> + + Assume the available C compiler supports ANSI C. Remove K&R C cruft. + * lib/getopt.h: Assume 'const' is defined. Use ANSI C prototypes. + * lib/getopt.c: Assume 'const' is defined, 'strlen' is declared. Use + ANSI C prototypes. + * lib/getopt1.c: Assume 'const' and NULL are defined. Use ANSI C + prototypes. + * lib/getopt.h.patch: Remove file. + * lib/getopt.c.patch: Remove file. + * lib/Makefile.in (SOURCE_FILES): Remove them. + * tests/jstest*.gperf: Assume 'const' is defined. + * tests/test.c: Use ANSI C prototypes. + (in_word_set): Fix prototype. + * tests/test2.c: Use ANSI C prototypes. + (in_word_set): Fix prototype. + Reported by Erik Johansson at <https://savannah.gnu.org/patch/?7382>. + 2016-11-26 Bruno Haible <bruno@clisp.org> Drop the inline specifiers from the generated lookup function. diff --git a/lib/Makefile.in b/lib/Makefile.in index 497736e..84185fb 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,6 +1,6 @@ # Makefile for gperf/lib -# Copyright (C) 1989, 1992, 1993, 1998, 2002, 2009, 2012 Free Software Foundation, Inc. +# Copyright (C) 1989, 1992, 1993, 1998, 2002, 2009, 2012, 2016 Free Software Foundation, Inc. # Written by Douglas C. Schmidt <schmidt@ics.uci.edu> # and Bruno Haible <bruno@clisp.org>. # @@ -116,7 +116,7 @@ SOURCE_FILES = \ configure.ac Makefile.in \ getline.h getline.cc \ hash.h hash.cc \ - getopt.h getopt.h.patch getopt.c getopt.c.patch getopt1.c + getopt.h getopt.c getopt1.c # List of distributed files imported from other packages. IMPORTED_FILES = # List of distributed files generated by autotools or Makefile.devel. diff --git a/lib/getopt.c b/lib/getopt.c index e2403a8..9e7d2f4 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -3,7 +3,7 @@ "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, 97, 98, 2009 + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 2009, 2016 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -29,14 +29,6 @@ #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 @@ -203,9 +195,7 @@ extern char *getenv (); extern int strncmp (); static char * -my_index (str, chr) - const char *str; - int chr; +my_index (const char *str, int chr) { while (*str) { @@ -216,18 +206,6 @@ my_index (str, chr) 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__ -/* 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. */ @@ -288,13 +266,8 @@ text_set_element (__libc_subinit, store_args_and_env); `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; @@ -374,14 +347,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 @@ -500,13 +467,8 @@ _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) { optarg = NULL; @@ -956,10 +918,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, @@ -975,9 +934,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.c.patch b/lib/getopt.c.patch deleted file mode 100644 index 6fedd84..0000000 --- a/lib/getopt.c.patch +++ /dev/null @@ -1,25 +0,0 @@ -getopt.c is a modified version of the getopt.c found in the glibc snapshot -on 1998-04-14. Below the patch that has been applied to this file. The glibc -maintainer has been informed of these patches. - -diff -c3 getopt.c.orig getopt.c -*** getopt.c.orig Sun Mar 8 16:06:55 1998 ---- getopt.c Thu Apr 16 00:09:41 1998 -*************** -*** 201,207 **** - /* Avoid depending on library functions or files - whose names are inconsistent. */ - -! char *getenv (); - - static char * - my_index (str, chr) ---- 201,208 ---- - /* Avoid depending on library functions or files - whose names are inconsistent. */ - -! extern char *getenv (); -! extern int strncmp (); - - static char * - my_index (str, chr) diff --git a/lib/getopt.h b/lib/getopt.h index 30e69b8..6f01fc6 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -1,5 +1,5 @@ /* Declarations for getopt. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. + Copyright (C) 1989-1998, 2000, 2016 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 @@ -76,11 +76,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; @@ -94,7 +90,6 @@ struct option #define required_argument 1 #define optional_argument 2 -#if (defined (__STDC__) && __STDC__) || defined (__cplusplus) #ifdef __cplusplus /* SunOS4 declares getopt with the following prototype: extern int getopt (int argc, const char *const *argv, const char *shortopts); @@ -121,13 +116,6 @@ extern int _getopt_internal (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind, int long_only); -#else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); -#endif /* __STDC__ */ #ifdef __cplusplus } diff --git a/lib/getopt.h.patch b/lib/getopt.h.patch deleted file mode 100644 index 8094b1a..0000000 --- a/lib/getopt.h.patch +++ /dev/null @@ -1,70 +0,0 @@ -getopt.h is a modified version of the getopt.h found in the glibc snapshot -on 1998-04-14. Below the patch that has been applied to this file. The glibc -maintainer has been informed of these patches. - -diff -c3 getopt.h.orig getopt.h -*** getopt.h.orig Sat Jun 21 03:01:53 1997 ---- getopt.h Mon Aug 28 12:36:27 2000 -*************** -*** 1,5 **** - /* Declarations for getopt. -! Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or ---- 1,5 ---- - /* Declarations for getopt. -! Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or -*************** -*** 78,84 **** - - struct option - { -! #if defined (__STDC__) && __STDC__ - const char *name; - #else - char *name; ---- 78,84 ---- - - struct option - { -! #if (defined (__STDC__) && __STDC__) || defined (__cplusplus) - const char *name; - #else - char *name; -*************** -*** 96,102 **** - #define required_argument 1 - #define optional_argument 2 - -! #if defined (__STDC__) && __STDC__ - #ifdef __GNU_LIBRARY__ - /* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation ---- 96,108 ---- - #define required_argument 1 - #define optional_argument 2 - -! #if (defined (__STDC__) && __STDC__) || defined (__cplusplus) -! #ifdef __cplusplus -! /* SunOS4 declares getopt with the following prototype: -! extern int getopt (int argc, const char *const *argv, const char *shortopts); -! We cannot redeclare it when compiling C++ code. */ -! #define getopt(x,y,z) getopt_long(x, y, z, (const struct option *) 0, (int *) 0) -! #else /* not __cplusplus */ - #ifdef __GNU_LIBRARY__ - /* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation -*************** -*** 105,110 **** ---- 111,117 ---- - #else /* not __GNU_LIBRARY__ */ - extern int getopt (); - #endif /* __GNU_LIBRARY__ */ -+ #endif /* __cplusplus */ - extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); - extern int getopt_long_only (int argc, char *const *argv, diff --git a/lib/getopt1.c b/lib/getopt1.c index 06a0b66..e878e87 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98, 2016 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -22,14 +22,6 @@ #include "getopt.h" -#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 @@ -57,17 +49,9 @@ #include <stdlib.h> #endif -#ifndef NULL -#define NULL 0 -#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); } @@ -78,12 +62,8 @@ 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); } @@ -96,9 +76,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index) #include <stdio.h> int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { int c; int digit_optind = 0; diff --git a/tests/jstest1.gperf b/tests/jstest1.gperf index f6696b1..7358f3d 100644 --- a/tests/jstest1.gperf +++ b/tests/jstest1.gperf @@ -54,12 +54,7 @@ with %% #include <stdlib.h> #include <string.h> -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { +static const char* testdata[] = { "bogus", "abstract", "boolean", @@ -121,9 +116,9 @@ int main () for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) { #ifdef CPLUSPLUS_TEST - CONST char * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); + const char * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); #else - CONST char * resword = in_word_set(testdata[i],strlen(testdata[i])); + const char * resword = in_word_set(testdata[i],strlen(testdata[i])); #endif if (i > 0) { diff --git a/tests/jstest2.gperf b/tests/jstest2.gperf index ee0fa7f..68553c3 100644 --- a/tests/jstest2.gperf +++ b/tests/jstest2.gperf @@ -59,12 +59,7 @@ with, 53 %% #include <stdlib.h> #include <string.h> -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { +static const char* testdata[] = { "bogus", "abstract", "boolean", @@ -126,9 +121,9 @@ int main () for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) { #ifdef CPLUSPLUS_TEST - CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); #else - CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); #endif if (i > 0) { diff --git a/tests/jstest3.gperf b/tests/jstest3.gperf index 54d37ce..4c23eb6 100644 --- a/tests/jstest3.gperf +++ b/tests/jstest3.gperf @@ -59,12 +59,7 @@ with, 53 %% #include <stdlib.h> #include <string.h> -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { +static const char* testdata[] = { "bogus", "abstract", "boolean", @@ -126,9 +121,9 @@ int main () for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) { #ifdef CPLUSPLUS_TEST - CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); #else - CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); #endif if (i > 0) { diff --git a/tests/jstest4.gperf b/tests/jstest4.gperf index b02617c..6b30ac3 100644 --- a/tests/jstest4.gperf +++ b/tests/jstest4.gperf @@ -59,12 +59,7 @@ with, 53 %% #include <stdlib.h> #include <string.h> -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { +static const char* testdata[] = { "bogus", "abstract", "boolean", @@ -126,9 +121,9 @@ int main () for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) { #ifdef CPLUSPLUS_TEST - CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); #else - CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); + const struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); #endif if (i > 0) { diff --git a/tests/test.c b/tests/test.c index 6ee16e0..52d41d8 100644 --- a/tests/test.c +++ b/tests/test.c @@ -7,18 +7,12 @@ #include <stdio.h> #include <string.h> -#if defined __STDC__ || defined __cplusplus -extern char * in_word_set (const char *, int); -#else -extern char * in_word_set (); -#endif +extern const char * in_word_set (const char *, size_t); #define MAX_LEN 80 int -main (argc, argv) - int argc; - char *argv[]; +main (int argc, char *argv[]) { int verbose = argc > 1 ? 1 : 0; char buf[MAX_LEN]; diff --git a/tests/test2.c b/tests/test2.c index e408d45..130a0a3 100644 --- a/tests/test2.c +++ b/tests/test2.c @@ -21,18 +21,12 @@ # define SET_BINARY(f) (void)0 #endif -#if defined __STDC__ || defined __cplusplus -extern struct language * in_word_set (const char *, int); -#else -extern struct language * in_word_set (); -#endif +extern struct language * in_word_set (const char *, size_t); #define MAX_LEN 80 int -main (argc, argv) - int argc; - char *argv[]; +main (int argc, char *argv[]) { int verbose = argc > 1 ? 1 : 0; char buf[2*MAX_LEN]; |