diff --git a/ChangeLog b/ChangeLog index 75b9aab..2be2188 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2025-04-16 Bruno Haible + + 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 first. + * src/search.cc: Likewise. + * src/bool-array.cc: Include . + * 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::read_input): Use fread_file instead of get_delim. + 2025-04-16 Bruno Haible build: Prepare for using generated .h files in lib/. diff --git a/autogen.sh b/autogen.sh index 810234e..74916ad 100755 --- a/autogen.sh +++ b/autogen.sh @@ -65,12 +65,15 @@ if test $skip_gnulib = false; then } GNULIB_MODULES=' filename + read-file package-version ' $GNULIB_TOOL --lib=libgp --source-base=lib --m4-base=lib/gnulib-m4 \ --makefile-name=Makefile.gnulib \ --import \ $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/mkinstalldirs; chmod a+x build-aux/mkinstalldirs $GNULIB_TOOL --copy-file build-aux/compile; chmod a+x build-aux/compile diff --git a/build-aux/.gitignore b/build-aux/.gitignore index 7fb1c0b..5450e5e 100644 --- a/build-aux/.gitignore +++ b/build-aux/.gitignore @@ -1,4 +1,6 @@ # Files brought in by gnulib-tool: +/config.guess +/config.sub /install-sh /mkinstalldirs /compile diff --git a/lib/.gitignore b/lib/.gitignore index b35fe1c..8193f33 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,8 +1,69 @@ # Files brought in by gnulib-tool: /gnulib-m4/ /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 +/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: /aclocal.m4 diff --git a/lib/Makefile.am b/lib/Makefile.am index e579ef0..77f262d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,8 +17,10 @@ ## Process this file with automake to produce Makefile.in. AUTOMAKE_OPTIONS = 1.11 foreign +BUILT_SOURCES = EXTRA_DIST = MOSTLYCLEANFILES = core *.stackdump +MOSTLYCLEANDIRS = noinst_LIBRARIES = libgp.a @@ -27,7 +29,6 @@ include Makefile.gnulib libgp_a_SOURCES += \ getopt.h getopt.c getopt1.c \ - getline.h getline.cc \ hash.h hash.cc # Allow users to use "gnulib-tool --update". diff --git a/lib/getline.cc b/lib/getline.cc deleted file mode 100644 index 2d97644..0000000 --- a/lib/getline.cc +++ /dev/null @@ -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 . */ - -/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ - -/* Specification. */ -#include "getline.h" - -#include -#include -#include -#include - -/* 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 . */ - -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); -} diff --git a/lib/getline.h b/lib/getline.h deleted file mode 100644 index 385dafe..0000000 --- a/lib/getline.h +++ /dev/null @@ -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 . */ - -#ifndef GETLINE_H_ -# define GETLINE_H_ 1 - -# include -# include - -/* 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_ */ diff --git a/src/bool-array.cc b/src/bool-array.cc index d678590..c181a7a 100644 --- a/src/bool-array.cc +++ b/src/bool-array.cc @@ -1,5 +1,5 @@ /* 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 and Bruno Haible . @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "bool-array.h" diff --git a/src/configure.ac b/src/configure.ac index cdbb87e..e1ce5b6 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -1,6 +1,6 @@ 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 dnl and Bruno Haible . dnl @@ -62,6 +62,16 @@ dnl AC_CHECK_LIB([m], [rand], [GPERF_LIBM="-lm"], [GPERF_LIBM=""]) AC_SUBST([GPERF_LIBM]) 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 AC_CONFIG_FILES([Makefile]) diff --git a/src/hash-table.cc b/src/hash-table.cc index 4811a6a..7bfc1bc 100644 --- a/src/hash-table.cc +++ b/src/hash-table.cc @@ -1,5 +1,5 @@ /* 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 and Bruno Haible . @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "hash-table.h" diff --git a/src/input.cc b/src/input.cc index 19b0a34..193f213 100644 --- a/src/input.cc +++ b/src/input.cc @@ -18,15 +18,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "input.h" #include -#include /* declares exit() */ +#include /* declares exit(), free() */ #include /* declares strncpy(), strchr() */ #include /* defines UCHAR_MAX etc. */ #include "options.h" -#include "getline.h" +#include "read-file.h" template Input::Input (FILE *stream, Keyword_Factory *keyword_factory) @@ -251,10 +253,9 @@ template declaration lines starting with %, we go for the first interpretation, otherwise for the second interpretation. */ - char *input = NULL; - size_t input_size = 0; - int input_length = get_delim (&input, &input_size, EOF, _stream); - if (input_length < 0) + size_t input_length; + char *input = fread_file (_stream, 0, &input_length); + if (input == NULL) { if (ferror (_stream)) fprintf (stderr, "%s: error while reading input file\n", @@ -1030,7 +1031,7 @@ template delete[] const_cast(_return_type); delete[] const_cast(_struct_tag); delete[] const_cast(_struct_decl); - delete[] _input; + free (_input); } /* ------------------------------------------------------------------------- */ diff --git a/src/keyword-list.cc b/src/keyword-list.cc index 5ab8ba4..ac6fe1e 100644 --- a/src/keyword-list.cc +++ b/src/keyword-list.cc @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "keyword-list.h" diff --git a/src/keyword.cc b/src/keyword.cc index 6d188c6..d7f096f 100644 --- a/src/keyword.cc +++ b/src/keyword.cc @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "keyword.h" diff --git a/src/main.cc b/src/main.cc index c02b147..7c40c20 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + #include #include #include diff --git a/src/options.cc b/src/options.cc index 45c6f01..acefc05 100644 --- a/src/options.cc +++ b/src/options.cc @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "options.h" diff --git a/src/output.cc b/src/output.cc index e91c85c..fa7adb3 100644 --- a/src/output.cc +++ b/src/output.cc @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "output.h" @@ -28,7 +30,6 @@ #include /* defines SCHAR_MAX etc. */ #include "options.h" #include "version.h" -#include "config.h" /* ============================== Portability ============================== */ diff --git a/src/positions.cc b/src/positions.cc index 66fe796..10f6ea7 100644 --- a/src/positions.cc +++ b/src/positions.cc @@ -1,5 +1,5 @@ /* 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 and Bruno Haible . @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "positions.h" diff --git a/src/search.cc b/src/search.cc index 92fecc1..95bfd0f 100644 --- a/src/search.cc +++ b/src/search.cc @@ -1,5 +1,5 @@ /* 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 and Bruno Haible . @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "search.h" @@ -29,7 +31,6 @@ #include /* defines INT_MIN, INT_MAX, UINT_MAX */ #include "options.h" #include "hash-table.h" -#include "config.h" /* ============================== Portability ============================== */ diff --git a/src/version.cc b/src/version.cc index bd59050..507e13d 100644 --- a/src/version.cc +++ b/src/version.cc @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + /* Specification. */ #include "version.h"