Move the whole "if not blank, then add history" logic under the #ifdef,
so it can be eliminated completely if add_history is not available at
compile time.
This probably makes no major difference on GNU/Linux, since GCC knows
that strspn has no side effects and can drop the call as dead code, but
this may help with less sophisticated toolchains.
#if HAVE_READLINE_READLINE_H
# include <readline/readline.h>
#endif
#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;
static const char *progname = "cdecl99";
static bool interactive = true;
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
}
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;
static int repl_cmdline(unsigned count, char **commands)
{
int ret = 0;
if (!(*linebuf = readline("> ")))
return 0;
if (!(*linebuf = readline("> ")))
return 0;
- if (!is_blank_line(*linebuf))
- add_history(*linebuf);
+ do_add_history(*linebuf);
void print_error(const char *fmt, ...);
void print_error(const char *fmt, ...);
-#if HAVE_RL_ADD_HISTORY && HAVE_READLINE_HISTORY_H
-# include <readline/history.h>
-#else
-static inline void add_history(const char *str)
-{
-}
-#endif
-