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)
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__])
-Subproject commit d63fa9d4fe8791bca39b5108c9970e70016e7a21
+Subproject commit 8a73c1c5c8b04143c6583f2413cc46b0035a3384
multiarch.m4
nls.m4
nocrash.m4
+off_t.m4
po.m4
printf-posix.m4
progtest.m4
stdint_h.m4
stdio_h.m4
stdlib_h.m4
+sys_types_h.m4
thread.m4
threadlib.m4
tls.m4
-# 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
gl_LIBTOOL
gl_MACRO_PREFIX([gl])
gl_PO_DOMAIN([])
-gl_WITNESS_C_DOMAIN([])
+gl_WITNESS_C_MACRO([])
gl_VC_FILES([false])
/*
- * 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 <ctype.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)
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)) {
+ if (!is_blank_line(line))
+ cdecl_add_history(line);
+
if (!run_command(line))
break;
}
--- /dev/null
+/*
+ * 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