]> git.draconx.ca Git - cdecl99.git/commitdiff
Port to use getline.h from dxcommon. master
authorNick Bowler <nbowler@draconx.ca>
Sun, 12 May 2024 19:20:30 +0000 (15:20 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 13 May 2024 02:19:06 +0000 (22:19 -0400)
Makefile.am
NEWS
common
configure.ac
src/cdecl99.c
src/getline.h [deleted file]
t/crossparse.c
t/normalize.c
t/rendertest.c
t/test.h
t/testlib.c

index 4776ec7fdca2964d3d6c7241798db38cafa6900d..006d97f9c0560ff89ff1c2b687f1752f391caf0b 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright © 2011-2013, 2019-2024 Nick Bowler
 #
-# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
-# This is free software: you are free to do what the fuck you want to.
+# License GPLv3+: GNU General Public License version 3 or any later version.
+# This is free software: you are free to change and redistribute it.
 # There is NO WARRANTY, to the extent permitted by law.
 
 ACLOCAL_AMFLAGS = -I m4 -I common/m4
@@ -34,10 +34,11 @@ EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4 \
 
 dist_man_MANS = doc/cdecl99.1 doc/libcdecl.3
 
-noinst_HEADERS = conf_pre.h conf_post.h common/src/help.h common/src/tap.h \
-                 common/src/xtra.h src/cdecl.h src/intconv.h src/parse.h \
-                 src/scan.h src/thread-posix.h src/thread-stdc.h \
-                 src/thread-w32.h src/version.h t/declgen.h t/test.h
+noinst_HEADERS = conf_pre.h conf_post.h common/src/getline.h \
+                 common/src/help.h common/src/tap.h common/src/xtra.h \
+                 src/cdecl.h src/intconv.h src/parse.h src/scan.h \
+                 src/thread-posix.h src/thread-stdc.h src/thread-w32.h \
+                 src/version.h t/declgen.h t/test.h
 
 noinst_DATA = $(MOFILES)
 
@@ -78,7 +79,7 @@ EXTRA_libgnu_a_DEPENDENCIES = $(static_gl_objects)
 dummy $(static_gl_objects): $(gnulib_headers)
 
 bin_PROGRAMS = cdecl99
-cdecl99_SOURCES = common/src/help.c src/commands.c src/cdecl99.h src/getline.h
+cdecl99_SOURCES = common/src/help.c src/commands.c src/cdecl99.h
 EXTRA_cdecl99_DEPENDENCIES = $(libmain_a_OBJECTS) $(libexec_a_OBJECTS)
 cdecl99_LDADD = $(EXTRA_cdecl99_DEPENDENCIES) libcdecl.la libgnu.a \
                 $(LTLIBINTL) $(LTLIBREADLINE)
diff --git a/NEWS b/NEWS
index 06e6cfa1035cae6a72a89a52a749f49a70530e8d..f9fbeb3495fe99301c1ed5e3b895f7a056009870 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+Release 1.3a:
+       * Various bug fixes and improvements.
+
 Release 1.3:
        * Substantial reduction in library code size.
        * Improved portability to older C compilers.
diff --git a/common b/common
index f5df895ced92ac539cafd825efee98835d8bf0d3..27f6a9c3d4663286f1bec753fbd035ab1a6eb5de 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit f5df895ced92ac539cafd825efee98835d8bf0d3
+Subproject commit 27f6a9c3d4663286f1bec753fbd035ab1a6eb5de
index 30be7cb56702ddd7bca2c07a0be05f55454021a9..d292fcd5699c3600df03b3de314795a1a367a0b2 100644 (file)
@@ -1,13 +1,12 @@
-dnl Copyright © 2011-2013, 2020-2024 Nick Bowler
-dnl
-dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
-dnl This is free software: you are free to do what the fuck you want to.
-dnl There is NO WARRANTY, to the extent permitted by law.
+AC_COPYRIGHT([Copyright (C) 2011-2013, 2020-2024 Nick Bowler
+License GPLv3+: GNU General Public License version 3 or any later version.
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.])
 
 DX_PATCH_GNULIB
 
 AC_PREREQ([2.68])
-AC_INIT([cdecl99], [1.3], [nbowler@draconx.ca])
+AC_INIT([cdecl99], [1.3a], [nbowler@draconx.ca])
 AC_CONFIG_HEADERS([config.h])
 
 AM_INIT_AUTOMAKE([-Wall -Wno-portability foreign subdir-objects])
@@ -119,16 +118,7 @@ AH_BOTTOM([#include <conf_post.h>])
 AC_CONFIG_TESTDIR([.], [t:.])
 DX_PROG_AUTOTEST_AM
 
-AC_CACHE_CHECK([for getline], [dx_cv_have_getline],
-  [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
-], [ssize_t (*x)() = getline;
-char *p = 0;
-size_t n = 0;
-return getline(&p, &n, stdin);
-])], [dx_cv_have_getline=yes], [dx_cv_have_getline=no])])
-AS_CASE([$dx_cv_have_getline], [yes],
-  [AC_DEFINE([HAVE_GETLINE], [1],
-    [Define to 1 if the getline function is available.])])
+DX_CHECK_GETLINE
 
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
index 1d8dff0b840a3d07a596e91cc0aeedbe38f3424b..0622e6726dec5a2df183d02ff53f2facd48573da 100644 (file)
@@ -117,6 +117,21 @@ static void print_help(const struct option *lopts)
        printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
 }
 
+static int do_getline(char **linebuf, size_t *n)
+{
+       int rc;
+
+       if ((rc = dx_getline(linebuf, n, stdin)) < 0) {
+               if (rc == DX_GETLINE_ENOMEM)
+                       print_error("%s", _("failed to allocate memory"));
+               else
+                       print_error("%s", strerror(errno));
+               return 0;
+       }
+
+       return rc;
+}
+
 static int do_readline(char **linebuf, size_t *n, bool batch)
 {
 #if !HAVE_READLINE
diff --git a/src/getline.h b/src/getline.h
deleted file mode 100644 (file)
index f4116a0..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright © 2024 Nick Bowler
- *
- * getline-like function which removes trailing newline (if any), and
- * returns nonzero if and only if a line was successfully read.
- *
- * 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/>.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include <errno.h>
-
-#ifdef CDECL_TEST_H_
-/*
- * Use the minimum initial alloc size in the test programs to ensure we at
- * least are exercising the realloc path on a reasonably regular basis.
- */
-#  define CDECL99_GETLINE_INITIAL_ALLOC 1
-#else
-#  define CDECL99_GETLINE_INITIAL_ALLOC 75
-#endif
-
-static inline int do_getline(char **linebuf, size_t *n)
-{
-       extern void print_error(const char *fmt, ...);
-       const char *errmsg;
-
-#if HAVE_GETLINE
-       ssize_t rc;
-
-       if ((rc = getline(linebuf, n, stdin)) < 0) {
-               if (ferror(stdin))
-                       goto input_error;
-               return 0;
-       }
-
-       if (rc-- && (*linebuf)[rc] == '\n')
-               (*linebuf)[rc] = '\0';
-       return 1;
-#else
-       char *work = *linebuf;
-       size_t pos = 0;
-       size_t sz;
-
-       if (!work) {
-               sz = CDECL99_GETLINE_INITIAL_ALLOC;
-               goto initial_alloc;
-       }
-
-       for (sz = *n;;) {
-               if (!fgets(&work[pos], sz - pos, stdin)) {
-                       if (ferror(stdin))
-                               goto input_error;
-
-                       return !!pos;
-               }
-
-               pos += strlen(&work[pos]);
-               if (work[pos-1] == '\n') {
-                       work[pos-1] = '\0';
-                       return 1;
-               }
-
-               if (sz > INT_MAX/2 || sz > ((size_t)-1)/4)
-                       break;
-
-               sz = ((sz*4) + 2) / 3;
-initial_alloc:
-               work = realloc(work, sz);
-               if (!work)
-                       break;
-               *linebuf = work;
-               *n = sz;
-       }
-
-       errmsg = _("failed to allocate memory");
-#endif
-       if (0) input_error: errmsg = strerror(errno);
-       print_error("%s", errmsg);
-       return 0;
-}
-
index 5f7eddc1324d732cda1634039b20465b24b1f725..e143c4a4ccd1c2ab8de36b7d468e5e54cbf7383c 100644 (file)
@@ -28,7 +28,6 @@
 
 #define PROGNAME "crossparse"
 #include "test.h"
-#include "getline.h"
 
 static const char sopts[] = "f:ECVH";
 static const struct option lopts[] = {
@@ -174,7 +173,7 @@ int main(int argc, char **argv)
                char *line = NULL;
                size_t n = 0;
 
-               while (do_getline(&line, &n)) {
+               while (test_getline(&line, &n)) {
                        if (!test_crossparse(line, mode))
                                ret = EXIT_FAILURE;
                }
index e309d70ec08b9be3be1cb3c8dc423ba1a51ca336..f55501b5cf27975f2c8a18bcfb7bb64ee089822d 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <getopt.h>
 
 #include "cdecl.h"
@@ -27,7 +28,6 @@
 
 #define PROGNAME "normalize"
 #include "test.h"
-#include "getline.h"
 
 static const char sopts[] = "f:VH";
 static const struct option lopts[] = {
@@ -197,7 +197,7 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       while (do_getline(&line, &n)) {
+       while (test_getline(&line, &n)) {
                if (do_normalize(line, n) < 0)
                        ret = EXIT_FAILURE;
        }
index 00e0c59f0a7981e4d5f2b3cdc32280b4961cfc25..e64526feb84d5f2a8bdac4b9acdb44177c3cb5dd 100644 (file)
@@ -27,7 +27,6 @@
 
 #define PROGNAME "rendertest"
 #include "test.h"
-#include "getline.h"
 
 static const char sopts[] = "n:ECVH";
 static const struct option lopts[] = {
@@ -131,7 +130,7 @@ int main(int argc, char **argv)
         * will hit a bug in AIX 7.2 getline and fall into an infinite loop.
         */
        line = malloc_nofail((sz = MAX(n+1, 10)));
-       while (do_getline(&line, &sz)) {
+       while (test_getline(&line, &sz)) {
                if (do_test(line, n, mode) < 0)
                        ret = EXIT_FAILURE;
        }
index 2a872f7f22450dbfd9d557c4fefc28af552bdfe2..ad8547f4aab2e5c621e75bef5c825510e41e1735 100644 (file)
--- a/t/test.h
+++ b/t/test.h
@@ -53,6 +53,8 @@ void print_error(const char *fmt, ...);
 void *malloc_nofail(size_t size);
 void *realloc_nofail(void *ptr, size_t size);
 
+int test_getline(char **linebuf, size_t *n);
+
 bool test_strtoumax(test_uintmax *out, const char *s, test_uintmax limit);
 
 static inline bool test_strtoul(unsigned long *val, const char *str)
index c4178396b85ed5bf795a2f85ce87cda9d05e9aeb..5902e7beb3dfb5d31c958f39e79c516819a807e8 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "help.h"
 #include "test.h"
+#include "getline.h"
 #include "intconv.h"
 
 void print_error(const char *fmt, ...)
@@ -105,3 +106,18 @@ void test_print_options(const struct option *lopts)
                        putchar('\n');
        }
 }
+
+int test_getline(char **linebuf, size_t *n)
+{
+       int rc;
+
+       if ((rc = dx_getline(linebuf, n, stdin)) < 0) {
+               if (rc == DX_GETLINE_ENOMEM)
+                       print_error("%s", _("failed to allocate memory"));
+               else
+                       print_error("%s", strerror(errno));
+               abort();
+       }
+
+       return rc;
+}