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

build: Use more gnulib modules.

* autogen.sh (GNULIB_MODULES): Add read-file.
Copy also config.guess and config.sub.
* lib/Makefile.am (BUILT_SOURCES, MOSTLYCLEANDIRS): New variables.
(libgp_a_SOURCES): Remove getline.h, getline.cc.
* lib/getline.h: Remove file.
* lib/getline.cc: Remove file.
* src/configure.ac: Change config.h to also include ../lib/config.h.
* src/output.cc: Include <config.h> first.
* src/search.cc: Likewise.
* src/bool-array.cc: Include <config.h>.
* src/keyword.cc: Likewise.
* src/keyword-list.cc: Likewise.
* src/hash-table.cc: Likewise.
* src/main.cc: Likewise.
* src/options.cc: Likewise.
* src/positions.cc: Likewise.
* src/version.cc: Likewise.
* src/input.cc: Likewise. Include read-file.h instead of getline.h.
(Input<KT>::read_input): Use fread_file instead of get_delim.
This commit is contained in:
Bruno Haible
2025-04-16 22:06:58 +02:00
parent 5533d54f9a
commit 6ca5ea1384
19 changed files with 135 additions and 172 deletions

View File

@@ -1,3 +1,26 @@
2025-04-16 Bruno Haible <bruno@clisp.org>
build: Use more gnulib modules.
* autogen.sh (GNULIB_MODULES): Add read-file.
Copy also config.guess and config.sub.
* lib/Makefile.am (BUILT_SOURCES, MOSTLYCLEANDIRS): New variables.
(libgp_a_SOURCES): Remove getline.h, getline.cc.
* lib/getline.h: Remove file.
* lib/getline.cc: Remove file.
* src/configure.ac: Change config.h to also include ../lib/config.h.
* src/output.cc: Include <config.h> first.
* src/search.cc: Likewise.
* src/bool-array.cc: Include <config.h>.
* src/keyword.cc: Likewise.
* src/keyword-list.cc: Likewise.
* src/hash-table.cc: Likewise.
* src/main.cc: Likewise.
* src/options.cc: Likewise.
* src/positions.cc: Likewise.
* src/version.cc: Likewise.
* src/input.cc: Likewise. Include read-file.h instead of getline.h.
(Input<KT>::read_input): Use fread_file instead of get_delim.
2025-04-16 Bruno Haible <bruno@clisp.org> 2025-04-16 Bruno Haible <bruno@clisp.org>
build: Prepare for using generated .h files in lib/. build: Prepare for using generated .h files in lib/.

View File

@@ -65,12 +65,15 @@ if test $skip_gnulib = false; then
} }
GNULIB_MODULES=' GNULIB_MODULES='
filename filename
read-file
package-version package-version
' '
$GNULIB_TOOL --lib=libgp --source-base=lib --m4-base=lib/gnulib-m4 \ $GNULIB_TOOL --lib=libgp --source-base=lib --m4-base=lib/gnulib-m4 \
--makefile-name=Makefile.gnulib \ --makefile-name=Makefile.gnulib \
--import \ --import \
$GNULIB_MODULES $GNULIB_MODULES
$GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess
$GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub
$GNULIB_TOOL --copy-file build-aux/install-sh; chmod a+x build-aux/install-sh $GNULIB_TOOL --copy-file build-aux/install-sh; chmod a+x build-aux/install-sh
$GNULIB_TOOL --copy-file build-aux/mkinstalldirs; chmod a+x build-aux/mkinstalldirs $GNULIB_TOOL --copy-file build-aux/mkinstalldirs; chmod a+x build-aux/mkinstalldirs
$GNULIB_TOOL --copy-file build-aux/compile; chmod a+x build-aux/compile $GNULIB_TOOL --copy-file build-aux/compile; chmod a+x build-aux/compile

View File

@@ -1,4 +1,6 @@
# Files brought in by gnulib-tool: # Files brought in by gnulib-tool:
/config.guess
/config.sub
/install-sh /install-sh
/mkinstalldirs /mkinstalldirs
/compile /compile

63
lib/.gitignore vendored
View File

@@ -1,8 +1,69 @@
# Files brought in by gnulib-tool: # Files brought in by gnulib-tool:
/gnulib-m4/ /gnulib-m4/
/Makefile.gnulib /Makefile.gnulib
/dummy.c /_Noreturn.h
/alloca.in.h
/arg-nonnull.h
/assert.in.h
/c++defs.h
/cloexec.c
/cloexec.h
/close.c
/dup2.c
/errno.in.h
/fcntl.c
/fcntl.in.h
/fd-hook.c
/fd-hook.h
/filename.h /filename.h
/fopen.c
/free.c
/fstat.c
/ftell.c
/ftello.c
/getdtablesize.c
/idx.h
/intprops-internal.h
/inttypes.in.h
/limits.in.h
/lseek.c
/malloc.c
/malloca.c
/malloca.h
/memset_explicit.c
/msvc-inval.c
/msvc-inval.h
/msvc-nothrow.c
/msvc-nothrow.h
/open.c
/pathmax.h
/read-file.c
/read-file.h
/realloc.c
/stat-time.c
/stat-time.h
/stat-w32.c
/stat-w32.h
/stat.c
/stdckdint.in.h
/stddef.in.h
/stdint.in.h
/stdio-impl.h
/stdio-read.c
/stdio-write.c
/stdio.in.h
/stdlib.c
/stdlib.in.h
/string.in.h
/sys_stat.in.h
/sys_types.in.h
/time.in.h
/unistd.c
/unistd.in.h
/verify.h
/warn-on-use.h
/wchar.in.h
/xalloc-oversized.h
# Files generated by the autotools: # Files generated by the autotools:
/aclocal.m4 /aclocal.m4

View File

@@ -17,8 +17,10 @@
## Process this file with automake to produce Makefile.in. ## Process this file with automake to produce Makefile.in.
AUTOMAKE_OPTIONS = 1.11 foreign AUTOMAKE_OPTIONS = 1.11 foreign
BUILT_SOURCES =
EXTRA_DIST = EXTRA_DIST =
MOSTLYCLEANFILES = core *.stackdump MOSTLYCLEANFILES = core *.stackdump
MOSTLYCLEANDIRS =
noinst_LIBRARIES = libgp.a noinst_LIBRARIES = libgp.a
@@ -27,7 +29,6 @@ include Makefile.gnulib
libgp_a_SOURCES += \ libgp_a_SOURCES += \
getopt.h getopt.c getopt1.c \ getopt.h getopt.c getopt1.c \
getline.h getline.cc \
hash.h hash.cc hash.h hash.cc
# Allow users to use "gnulib-tool --update". # Allow users to use "gnulib-tool --update".

View File

@@ -1,117 +0,0 @@
/* getline.c -- Replacement for GNU C library function getline
Copyright (C) 1993, 1996, 2001-2003, 2020 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */
/* Specification. */
#include "getline.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
/* Always add at least this many bytes when extending the buffer. */
#define MIN_CHUNK 64
/* Reads up to (and including) a TERMINATOR from STREAM into *LINEPTR + OFFSET
(and null-terminate it). *LINEPTR is a pointer returned from new [] (or
NULL), pointing to *N characters of space. It is realloc'd as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or immediate EOF.
NOTE: There is another getstr() function declared in <curses.h>. */
static int
getstr (char **lineptr, size_t *n, FILE *stream, char terminator, size_t offset)
{
size_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */
char *read_pos; /* Where we're reading into *LINEPTR. */
if (!lineptr || !n || !stream)
return -1;
if (!*lineptr)
{
*n = MIN_CHUNK;
*lineptr = new char[*n];
}
nchars_avail = *n - offset;
read_pos = *lineptr + offset;
for (;;)
{
int c = getc (stream);
/* We always want at least one char left in the buffer, since we
always (unless we get an error while reading the first char)
NUL-terminate the line buffer. */
assert (*n - nchars_avail == (size_t) (read_pos - *lineptr));
if (nchars_avail < 2)
{
if (*n > MIN_CHUNK)
*n *= 2;
else
*n += MIN_CHUNK;
nchars_avail = *n + *lineptr - read_pos;
char *new_line = new char[*n];
if (*lineptr)
{
memcpy (new_line, *lineptr, read_pos - *lineptr);
delete[] *lineptr;
}
*lineptr = new_line;
read_pos = *n - nchars_avail + *lineptr;
assert (*n - nchars_avail == (size_t) (read_pos - *lineptr));
}
if (c == EOF || ferror (stream))
{
/* Return partial line, if any. */
if (read_pos == *lineptr)
return -1;
else
break;
}
*read_pos++ = c;
nchars_avail--;
if (c == terminator)
/* Return the line. */
break;
}
/* Done - NUL terminate and return the number of chars read. */
*read_pos = '\0';
return read_pos - (*lineptr + offset);
}
int
get_line (char **lineptr, size_t *n, FILE *stream)
{
return getstr (lineptr, n, stream, '\n', 0);
}
int
get_delim (char **lineptr, size_t *n, int delimiter, FILE *stream)
{
return getstr (lineptr, n, stream, delimiter, 0);
}

View File

@@ -1,39 +0,0 @@
/* Copyright (C) 1995, 2000-2003 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef GETLINE_H_
# define GETLINE_H_ 1
# include <stddef.h>
# include <stdio.h>
/* Like the glibc functions get_line and get_delim, except that the result
must be freed using delete[], not free(). */
/* Reads up to (and including) a newline from STREAM into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from new [] (or
NULL), pointing to *N characters of space. It is realloc'd as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or immediate EOF. */
extern int get_line (char **lineptr, size_t *n, FILE *stream);
/* Reads up to (and including) a DELIMITER from STREAM into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from new [] (or
NULL), pointing to *N characters of space. It is realloc'd as
necessary. Returns the number of characters read (not including the
null terminator), or -1 on error or immediate EOF. */
extern int get_delim (char **lineptr, size_t *n, int delimiter, FILE *stream);
#endif /* not GETLINE_H_ */

View File

@@ -1,5 +1,5 @@
/* Fast lookup table abstraction implemented as an Iteration Number Array /* Fast lookup table abstraction implemented as an Iteration Number Array
Copyright (C) 1989-1998, 2002-2003 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2002-2003, 2025 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>.
@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "bool-array.h" #include "bool-array.h"

View File

@@ -1,6 +1,6 @@
dnl autoconf configuration for gperf/src dnl autoconf configuration for gperf/src
dnl Copyright (C) 1998-2024 Free Software Foundation, Inc. dnl Copyright (C) 1998-2025 Free Software Foundation, Inc.
dnl Written by Douglas C. Schmidt <schmidt@ics.uci.edu> dnl Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
dnl and Bruno Haible <bruno@clisp.org>. dnl and Bruno Haible <bruno@clisp.org>.
dnl dnl
@@ -62,6 +62,16 @@ dnl
AC_CHECK_LIB([m], [rand], [GPERF_LIBM="-lm"], [GPERF_LIBM=""]) AC_CHECK_LIB([m], [rand], [GPERF_LIBM="-lm"], [GPERF_LIBM=""])
AC_SUBST([GPERF_LIBM]) AC_SUBST([GPERF_LIBM])
dnl dnl
dnl Include lib/config.h through src/config.h.
dnl
AH_BOTTOM([
#undef/**/PACKAGE_NAME
#undef/**/PACKAGE_STRING
#undef/**/PACKAGE_TARNAME
#undef/**/PACKAGE_VERSION
#include "../lib/config.h"
])
dnl
dnl That's it. dnl That's it.
dnl dnl
AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([Makefile])

View File

@@ -1,5 +1,5 @@
/* Hash table for checking keyword links. Implemented using double hashing. /* Hash table for checking keyword links. Implemented using double hashing.
Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2000, 2002-2003, 2025 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>.
@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "hash-table.h" #include "hash-table.h"

View File

@@ -18,15 +18,17 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "input.h" #include "input.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* declares exit() */ #include <stdlib.h> /* declares exit(), free() */
#include <string.h> /* declares strncpy(), strchr() */ #include <string.h> /* declares strncpy(), strchr() */
#include <limits.h> /* defines UCHAR_MAX etc. */ #include <limits.h> /* defines UCHAR_MAX etc. */
#include "options.h" #include "options.h"
#include "getline.h" #include "read-file.h"
template <class KT> template <class KT>
Input<KT>::Input (FILE *stream, Keyword_Factory<KT> *keyword_factory) Input<KT>::Input (FILE *stream, Keyword_Factory<KT> *keyword_factory)
@@ -251,10 +253,9 @@ template <class KT>
declaration lines starting with %, we go for the first interpretation, declaration lines starting with %, we go for the first interpretation,
otherwise for the second interpretation. */ otherwise for the second interpretation. */
char *input = NULL; size_t input_length;
size_t input_size = 0; char *input = fread_file (_stream, 0, &input_length);
int input_length = get_delim (&input, &input_size, EOF, _stream); if (input == NULL)
if (input_length < 0)
{ {
if (ferror (_stream)) if (ferror (_stream))
fprintf (stderr, "%s: error while reading input file\n", fprintf (stderr, "%s: error while reading input file\n",
@@ -1030,7 +1031,7 @@ template <class KT>
delete[] const_cast<char*>(_return_type); delete[] const_cast<char*>(_return_type);
delete[] const_cast<char*>(_struct_tag); delete[] const_cast<char*>(_struct_tag);
delete[] const_cast<char*>(_struct_decl); delete[] const_cast<char*>(_struct_decl);
delete[] _input; free (_input);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View File

@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "keyword-list.h" #include "keyword-list.h"

View File

@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "keyword.h" #include "keyword.h"

View File

@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "options.h" #include "options.h"

View File

@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "output.h" #include "output.h"
@@ -28,7 +30,6 @@
#include <limits.h> /* defines SCHAR_MAX etc. */ #include <limits.h> /* defines SCHAR_MAX etc. */
#include "options.h" #include "options.h"
#include "version.h" #include "version.h"
#include "config.h"
/* ============================== Portability ============================== */ /* ============================== Portability ============================== */

View File

@@ -1,5 +1,5 @@
/* A set of byte positions. /* A set of byte positions.
Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2000, 2002-2003, 2025 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>.
@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "positions.h" #include "positions.h"

View File

@@ -1,5 +1,5 @@
/* Search algorithm. /* Search algorithm.
Copyright (C) 1989-1998, 2000, 2002-2003, 2009, 2016 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2000, 2002-2003, 2009, 2016, 2025 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>.
@@ -18,6 +18,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "search.h" #include "search.h"
@@ -29,7 +31,6 @@
#include <limits.h> /* defines INT_MIN, INT_MAX, UINT_MAX */ #include <limits.h> /* defines INT_MIN, INT_MAX, UINT_MAX */
#include "options.h" #include "options.h"
#include "hash-table.h" #include "hash-table.h"
#include "config.h"
/* ============================== Portability ============================== */ /* ============================== Portability ============================== */

View File

@@ -19,6 +19,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */ /* Specification. */
#include "version.h" #include "version.h"