]> git.draconx.ca Git - cdecl99.git/commitdiff
Add basic readline history support.
authorNick Bowler <nbowler@draconx.ca>
Thu, 30 Aug 2012 00:29:03 +0000 (20:29 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 30 Aug 2012 00:29:03 +0000 (20:29 -0400)
Bump gnulib as later versions include a free check for history.h
already, then implement a wrapper for add_history that should work
even when support is not available.

Makefile.am
configure.ac
gnulib
m4/.gitignore
m4/gnulib-cache.m4
src/cdecl99.c
src/history.h [new file with mode: 0644]

index 8634a09fb05992844431cc758f2ccef26f9d82bd..ecfba9be3e1a8003e91940d4b8e52bb0655c1d8d 100644 (file)
@@ -35,8 +35,8 @@ dist_man_MANS = doc/man/cdecl99.1 doc/man/libcdecl.3
 
 include_HEADERS = src/cdecl.h
 noinst_HEADERS = conf_pre.h conf_post.h src/typemap.h src/output.h src/scan.h \
 
 include_HEADERS = src/cdecl.h
 noinst_HEADERS = conf_pre.h conf_post.h src/typemap.h src/output.h src/scan.h \
-       src/parse.h src/i18n.h src/normalize.h src/error.h test/declgen.h \
-       test/test.h
+       src/parse.h src/i18n.h src/normalize.h src/error.h src/history.h \
+       test/declgen.h test/test.h
 
 noinst_DATA = $(MOFILES)
 
 
 noinst_DATA = $(MOFILES)
 
index 3be31270ae2ccd41e0f60d1e12d020116ab57696..0b9bab10e6fd10134028855e7edc06f60d57a0ab 100644 (file)
@@ -18,6 +18,25 @@ gl_EARLY
 LT_INIT
 gl_INIT
 
 LT_INIT
 gl_INIT
 
+AC_CACHE_CHECK([if readline supports add_history], [dx_cv_rl_add_history], [dnl
+dx_cv_rl_add_history=no
+dx_save_libs=$LIBS
+LIBS="$LIBS $LIBREADLINE"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
+#include <stdio.h>
+#if HAVE_READLINE_HISTORY_H
+#  include <readline/history.h>
+#endif
+], [dnl
+(*add_history)("");
+])], [dx_cv_rl_add_history=yes], [dx_cv_rl_add_history=no])
+LIBS=$dx_save_libs
+])
+
+AS_IF([test x"$dx_cv_rl_add_history" = x"yes"],
+       [AC_DEFINE([HAVE_RL_ADD_HISTORY], [1],
+               [Define to 1 if readline supports add_history.])])
+
 m4_include([lib/gnulib.mk])
 DX_GLSYM_PREFIX([cdecl__])
 
 m4_include([lib/gnulib.mk])
 DX_GLSYM_PREFIX([cdecl__])
 
diff --git a/gnulib b/gnulib
index d63fa9d4fe8791bca39b5108c9970e70016e7a21..8a73c1c5c8b04143c6583f2413cc46b0035a3384 160000 (submodule)
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit d63fa9d4fe8791bca39b5108c9970e70016e7a21
+Subproject commit 8a73c1c5c8b04143c6583f2413cc46b0035a3384
index ae8c6f2a8a59d31cb2aad96326507632d0b09a5d..18e8714a1b91cb1698fb66c2692f008e203943f2 100644 (file)
@@ -37,6 +37,7 @@ malloc.m4
 multiarch.m4
 nls.m4
 nocrash.m4
 multiarch.m4
 nls.m4
 nocrash.m4
+off_t.m4
 po.m4
 printf-posix.m4
 progtest.m4
 po.m4
 printf-posix.m4
 progtest.m4
@@ -49,6 +50,7 @@ stdint.m4
 stdint_h.m4
 stdio_h.m4
 stdlib_h.m4
 stdint_h.m4
 stdio_h.m4
 stdlib_h.m4
+sys_types_h.m4
 thread.m4
 threadlib.m4
 tls.m4
 thread.m4
 threadlib.m4
 tls.m4
index 05cb7ff02a480eae704e0ff5b457510c8825fceb..f5b9f5aeb804f4b64009d087083b52dcfd53e56c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2011 Free Software Foundation, Inc.
+# Copyright (C) 2002-2012 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -50,5 +50,5 @@ gl_CONDITIONAL_DEPENDENCIES
 gl_LIBTOOL
 gl_MACRO_PREFIX([gl])
 gl_PO_DOMAIN([])
 gl_LIBTOOL
 gl_MACRO_PREFIX([gl])
 gl_PO_DOMAIN([])
-gl_WITNESS_C_DOMAIN([])
+gl_WITNESS_C_MACRO([])
 gl_VC_FILES([false])
 gl_VC_FILES([false])
index d58433ba15e68774eadfb3549d8f73583102fc5a..99b5d63eaed47bcc2c197117ae95beb7cd89d1ef 100644 (file)
@@ -1,31 +1,33 @@
 /*
 /*
- *  Command line utility for making sense of C declarations.
- *  Copyright © 2011 Nick Bowler
+ * Command line utility for making sense of C declarations.
+ * Copyright © 2011-2012 Nick Bowler
  *
  *
- *  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 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.
+ * 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 <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
  */
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
+#include <ctype.h>
 #include <errno.h>
 #include <locale.h>
 #include <getopt.h>
 #include <gettext.h>
 #include <assert.h>
 #include "readline.h"
 #include <errno.h>
 #include <locale.h>
 #include <getopt.h>
 #include <gettext.h>
 #include <assert.h>
 #include "readline.h"
+#include "history.h"
 #include "cdecl.h"
 
 #define _(x) gettext(x)
 #include "cdecl.h"
 
 #define _(x) gettext(x)
@@ -398,11 +400,24 @@ static int run_command(const char *line)
        return -1;
 }
 
        return -1;
 }
 
+static bool is_blank_line(const char *line)
+{
+       for (size_t i = 0; line[i]; i++) {
+               if (!isblank((unsigned char)line[i]))
+                       return false;
+       }
+
+       return true;
+}
+
 static int repl(void)
 {
        char *line;
 
        for (; (line = readline("> ")); free(line)) {
 static int repl(void)
 {
        char *line;
 
        for (; (line = readline("> ")); free(line)) {
+               if (!is_blank_line(line))
+                       cdecl_add_history(line);
+
                if (!run_command(line))
                        break;
        }
                if (!run_command(line))
                        break;
        }
diff --git a/src/history.h b/src/history.h
new file mode 100644 (file)
index 0000000..2d519ee
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Simple wrappers around libhistory to stub out unavailable functions.
+ * Copyright © 2012 Nick Bowler
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#if HAVE_READLINE_HISTORY_H
+#  include <readline/history.h>
+#endif
+
+#if HAVE_RL_ADD_HISTORY
+static inline void cdecl_add_history(const char *str)
+{
+       add_history(str);
+}
+#else
+static inline void cdecl_add_history(const char *str)
+{
+}
+#endif