Skip to content

Commit e2d4973

Browse files
committed
Support readline library < 6.3
Signed-off-by: Ramon Fried <[email protected]>
1 parent 0a4e7d9 commit e2d4973

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

configure.ac

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ AC_TYPE_UINT64_T
4343
AC_FUNC_STRCOLL
4444
AC_CHECK_FUNCS([memchr memmove memset stpcpy strchr strcspn strdup strerror strpbrk strrchr strspn strstr])
4545

46+
# Then check for the variable considering both possible locations
47+
AC_CHECK_DECL([rl_change_environment],
48+
[AC_DEFINE([HAVE_RL_CHANGE_ENVIRONMENT], [1], [Define if rl_change_environment is available])],
49+
[AC_MSG_WARN([rl_change_environment not found])],
50+
[[#ifdef HAVE_READLINE_H
51+
#include <readline.h>
52+
#endif
53+
#ifdef HAVE_READLINE_READLINE_H
54+
#include <readline/readline.h>
55+
#endif
56+
]])
57+
58+
AC_CHECK_DECL([rl_input_available_hook],
59+
[AC_DEFINE([HAVE_RL_INPUT_AVAILABLE_HOOK], [1], [Define if rl_input_available_hook is available])],
60+
[AC_MSG_WARN([rl_input_available_hook not found])],
61+
[[#ifdef HAVE_READLINE_H
62+
#include <readline.h>
63+
#endif
64+
#ifdef HAVE_READLINE_READLINE_H
65+
#include <readline/readline.h>
66+
#endif
67+
]])
68+
69+
4670
AC_CONFIG_FILES([Makefile])
4771

4872
AC_ARG_ENABLE([gcov],

src/cmd.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string.h>
55
#include <inttypes.h>
66
#include <ctype.h>
7+
#include <unistd.h>
78
#include "bitwise.h"
89
#include "shunting-yard.h"
910

@@ -225,6 +226,12 @@ static int readline_input_avail(void)
225226

226227
static int readline_getc(FILE *dummy)
227228
{
229+
#ifndef HAVE_RL_INPUT_AVAILABLE_HOOK
230+
/* Block until input is available when hook is not supported */
231+
while (!g_input_avail) {
232+
usleep(1000);
233+
}
234+
#endif
228235
g_input_avail = false;
229236
return g_input;
230237
}
@@ -272,9 +279,13 @@ void init_readline(void)
272279
rl_catch_sigwinch = 0;
273280
rl_deprep_term_function = NULL;
274281
rl_prep_term_function = NULL;
282+
#ifdef HAVE_RL_CHANGE_ENVIRONMENT
275283
rl_change_environment = 0;
284+
#endif
276285
rl_getc_function = readline_getc;
286+
#ifdef HAVE_RL_INPUT_AVAILABLE_HOOK
277287
rl_input_available_hook = readline_input_avail;
288+
#endif
278289
rl_redisplay_function = readline_redisplay;
279290
//rl_bind_key('\t', rl_insert);
280291
rl_callback_handler_install(":", got_command);

0 commit comments

Comments
 (0)