1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Assume the available C compiler supports ANSI C. Remove K&R C cruft.

This commit is contained in:
Bruno Haible
2016-11-27 18:18:00 +01:00
parent a705809f3d
commit cabd2af10e
13 changed files with 51 additions and 237 deletions

View File

@@ -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> 2016-11-26 Bruno Haible <bruno@clisp.org>
Drop the inline specifiers from the generated lookup function. Drop the inline specifiers from the generated lookup function.

View File

@@ -1,6 +1,6 @@
# Makefile for gperf/lib # 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> # Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
# and Bruno Haible <bruno@clisp.org>. # and Bruno Haible <bruno@clisp.org>.
# #
@@ -116,7 +116,7 @@ SOURCE_FILES = \
configure.ac Makefile.in \ configure.ac Makefile.in \
getline.h getline.cc \ getline.h getline.cc \
hash.h hash.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. # List of distributed files imported from other packages.
IMPORTED_FILES = IMPORTED_FILES =
# List of distributed files generated by autotools or Makefile.devel. # List of distributed files generated by autotools or Makefile.devel.

View File

@@ -3,7 +3,7 @@
"Keep this file name-space clean" means, talk to drepper@gnu.org "Keep this file name-space clean" means, talk to drepper@gnu.org
before changing it! 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. Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@@ -29,14 +29,6 @@
#include <config.h> #include <config.h>
#endif #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> #include <stdio.h>
/* 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
@@ -203,9 +195,7 @@ extern char *getenv ();
extern int strncmp (); extern int strncmp ();
static char * static char *
my_index (str, chr) my_index (const char *str, int chr)
const char *str;
int chr;
{ {
while (*str) while (*str)
{ {
@@ -216,18 +206,6 @@ my_index (str, chr)
return 0; 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__ */ #endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */ /* 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 `first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */ the new indices of the non-options in ARGV after they are moved. */
#if defined __STDC__ && __STDC__
static void exchange (char **);
#endif
static void static void
exchange (argv) exchange (char **argv)
char **argv;
{ {
int bottom = first_nonopt; int bottom = first_nonopt;
int middle = last_nonopt; int middle = last_nonopt;
@@ -374,14 +347,8 @@ exchange (argv)
/* Initialize the internal data when the first call is made. */ /* 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 * static const char *
_getopt_initialize (argc, argv, optstring) _getopt_initialize (int argc, char *const *argv, const char *optstring)
int argc;
char *const *argv;
const char *optstring;
{ {
/* Start processing options with ARGV-element 1 (since ARGV-element 0 /* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped is the program name); the sequence of previously skipped
@@ -500,13 +467,8 @@ _getopt_initialize (argc, argv, optstring)
long-named options. */ long-named options. */
int int
_getopt_internal (argc, argv, optstring, longopts, longind, long_only) _getopt_internal (int argc, char *const *argv, const char *optstring,
int argc; const struct option *longopts, int *longind, int long_only)
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
{ {
optarg = NULL; optarg = NULL;
@@ -956,10 +918,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
} }
int int
getopt (argc, argv, optstring) getopt (int argc, char *const *argv, const char *optstring)
int argc;
char *const *argv;
const char *optstring;
{ {
return _getopt_internal (argc, argv, optstring, return _getopt_internal (argc, argv, optstring,
(const struct option *) 0, (const struct option *) 0,
@@ -975,9 +934,7 @@ getopt (argc, argv, optstring)
the above definition of `getopt'. */ the above definition of `getopt'. */
int int
main (argc, argv) main (int argc, char **argv)
int argc;
char **argv;
{ {
int c; int c;
int digit_optind = 0; int digit_optind = 0;

View File

@@ -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)

View File

@@ -1,5 +1,5 @@
/* Declarations for getopt. /* 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 file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@@ -76,11 +76,7 @@ extern int optopt;
struct option struct option
{ {
#if (defined (__STDC__) && __STDC__) || defined (__cplusplus)
const char *name; const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about /* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */ type mismatches in all the code that assumes it is an int. */
int has_arg; int has_arg;
@@ -94,7 +90,6 @@ struct option
#define required_argument 1 #define required_argument 1
#define optional_argument 2 #define optional_argument 2
#if (defined (__STDC__) && __STDC__) || defined (__cplusplus)
#ifdef __cplusplus #ifdef __cplusplus
/* SunOS4 declares getopt with the following prototype: /* SunOS4 declares getopt with the following prototype:
extern int getopt (int argc, const char *const *argv, const char *shortopts); 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 char *shortopts,
const struct option *longopts, int *longind, const struct option *longopts, int *longind,
int long_only); 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 #ifdef __cplusplus
} }

View File

@@ -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,

View File

@@ -1,5 +1,5 @@
/* getopt_long and getopt_long_only entry points for GNU getopt. /* 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. Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
@@ -22,14 +22,6 @@
#include "getopt.h" #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> #include <stdio.h>
/* 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
@@ -57,17 +49,9 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifndef NULL
#define NULL 0
#endif
int int
getopt_long (argc, argv, options, long_options, opt_index) getopt_long (int argc, char *const *argv, const char *options,
int argc; const struct option *long_options, int *opt_index)
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); 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. */ instead. */
int int
getopt_long_only (argc, argv, options, long_options, opt_index) getopt_long_only (int argc, char *const *argv, const char *options,
int argc; const struct option *long_options, int *opt_index)
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); 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> #include <stdio.h>
int int
main (argc, argv) main (int argc, char **argv)
int argc;
char **argv;
{ {
int c; int c;
int digit_optind = 0; int digit_optind = 0;

View File

@@ -54,12 +54,7 @@ with
%% %%
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(__STDC__) || defined(__cplusplus) static const char* testdata[] = {
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus", "bogus",
"abstract", "abstract",
"boolean", "boolean",
@@ -121,9 +116,9 @@ int main ()
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{ {
#ifdef CPLUSPLUS_TEST #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 #else
CONST char * resword = in_word_set(testdata[i],strlen(testdata[i])); const char * resword = in_word_set(testdata[i],strlen(testdata[i]));
#endif #endif
if (i > 0) if (i > 0)
{ {

View File

@@ -59,12 +59,7 @@ with, 53
%% %%
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(__STDC__) || defined(__cplusplus) static const char* testdata[] = {
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus", "bogus",
"abstract", "abstract",
"boolean", "boolean",
@@ -126,9 +121,9 @@ int main ()
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{ {
#ifdef CPLUSPLUS_TEST #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 #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 #endif
if (i > 0) if (i > 0)
{ {

View File

@@ -59,12 +59,7 @@ with, 53
%% %%
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(__STDC__) || defined(__cplusplus) static const char* testdata[] = {
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus", "bogus",
"abstract", "abstract",
"boolean", "boolean",
@@ -126,9 +121,9 @@ int main ()
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{ {
#ifdef CPLUSPLUS_TEST #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 #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 #endif
if (i > 0) if (i > 0)
{ {

View File

@@ -59,12 +59,7 @@ with, 53
%% %%
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(__STDC__) || defined(__cplusplus) static const char* testdata[] = {
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus", "bogus",
"abstract", "abstract",
"boolean", "boolean",
@@ -126,9 +121,9 @@ int main ()
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{ {
#ifdef CPLUSPLUS_TEST #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 #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 #endif
if (i > 0) if (i > 0)
{ {

View File

@@ -7,18 +7,12 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined __STDC__ || defined __cplusplus extern const char * in_word_set (const char *, size_t);
extern char * in_word_set (const char *, int);
#else
extern char * in_word_set ();
#endif
#define MAX_LEN 80 #define MAX_LEN 80
int int
main (argc, argv) main (int argc, char *argv[])
int argc;
char *argv[];
{ {
int verbose = argc > 1 ? 1 : 0; int verbose = argc > 1 ? 1 : 0;
char buf[MAX_LEN]; char buf[MAX_LEN];

View File

@@ -21,18 +21,12 @@
# define SET_BINARY(f) (void)0 # define SET_BINARY(f) (void)0
#endif #endif
#if defined __STDC__ || defined __cplusplus extern struct language * in_word_set (const char *, size_t);
extern struct language * in_word_set (const char *, int);
#else
extern struct language * in_word_set ();
#endif
#define MAX_LEN 80 #define MAX_LEN 80
int int
main (argc, argv) main (int argc, char *argv[])
int argc;
char *argv[];
{ {
int verbose = argc > 1 ? 1 : 0; int verbose = argc > 1 ? 1 : 0;
char buf[2*MAX_LEN]; char buf[2*MAX_LEN];