]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl99.c
cdecl99: Don't check blank lines if no history support.
[cdecl99.git] / src / cdecl99.c
index d7ddd77960a284fa07844a5bf67331b1453ae36a..f7eed62acbd94bf0a74dc7d0d73398dc6dc05704 100644 (file)
 #if HAVE_READLINE_READLINE_H
 #  include <readline/readline.h>
 #endif
+#if HAVE_RL_ADD_HISTORY && HAVE_READLINE_HISTORY_H
+#  include <readline/history.h>
+
+/* call add_history only if the line is non-blank */
+static void do_add_history(const char *line)
+{
+       if (line[strspn(line, " \t")])
+               add_history(line);
+}
+#else
+static void do_add_history(const char *line)
+{
+}
+#endif
 
 static const char *progname = "cdecl99";
 static bool interactive = true;
@@ -110,11 +124,6 @@ static void print_help(const struct option *lopts)
        printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
 }
 
-static int is_blank_line(const char *line)
-{
-       return !line[strspn(line, " \t")];
-}
-
 static int repl_cmdline(unsigned count, char **commands)
 {
        int ret = 0;
@@ -163,8 +172,7 @@ static int do_readline(char **linebuf, size_t *n, int interactive)
        if (!(*linebuf = readline("> ")))
                return 0;
 
-       if (!is_blank_line(*linebuf))
-               add_history(*linebuf);
+       do_add_history(*linebuf);
        return 1;
 #endif
 }