Skip to content

Commit 8afc9a1

Browse files
committed
add readline_list_history with libedit >= 3.1
1 parent 56dba3f commit 8afc9a1

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

ext/readline/config.m4

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
7474
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
7575
])
7676

77+
AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
7778
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])
7879

7980
elif test "$PHP_LIBEDIT" != "no"; then
@@ -128,6 +129,13 @@ elif test "$PHP_LIBEDIT" != "no"; then
128129
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
129130
])
130131

132+
PHP_CHECK_LIBRARY(edit, history_list,
133+
[
134+
AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
135+
],[],[
136+
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
137+
])
138+
131139
AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
132140
fi
133141

ext/readline/readline.c

+18-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PHP_FUNCTION(readline);
4545
PHP_FUNCTION(readline_add_history);
4646
PHP_FUNCTION(readline_info);
4747
PHP_FUNCTION(readline_clear_history);
48-
#ifndef HAVE_LIBEDIT
48+
#ifdef HAVE_HISTORY_LIST
4949
PHP_FUNCTION(readline_list_history);
5050
#endif
5151
PHP_FUNCTION(readline_read_history);
@@ -90,7 +90,7 @@ ZEND_END_ARG_INFO()
9090
ZEND_BEGIN_ARG_INFO(arginfo_readline_clear_history, 0)
9191
ZEND_END_ARG_INFO()
9292

93-
#ifndef HAVE_LIBEDIT
93+
#ifdef HAVE_HISTORY_LIST
9494
ZEND_BEGIN_ARG_INFO(arginfo_readline_list_history, 0)
9595
ZEND_END_ARG_INFO()
9696
#endif
@@ -135,7 +135,7 @@ static const zend_function_entry php_readline_functions[] = {
135135
PHP_FE(readline_info, arginfo_readline_info)
136136
PHP_FE(readline_add_history, arginfo_readline_add_history)
137137
PHP_FE(readline_clear_history, arginfo_readline_clear_history)
138-
#ifndef HAVE_LIBEDIT
138+
#ifdef HAVE_HISTORY_LIST
139139
PHP_FE(readline_list_history, arginfo_readline_list_history)
140140
#endif
141141
PHP_FE(readline_read_history, arginfo_readline_read_history)
@@ -379,22 +379,35 @@ PHP_FUNCTION(readline_clear_history)
379379
/* }}} */
380380
/* {{{ proto array readline_list_history(void)
381381
Lists the history */
382-
#ifndef HAVE_LIBEDIT
382+
#ifdef HAVE_HISTORY_LIST
383383
PHP_FUNCTION(readline_list_history)
384384
{
385385
HIST_ENTRY **history;
386+
#ifdef HAVE_LIBEDIT
387+
HISTORY_STATE *hs;
388+
#endif
386389

387390
if (zend_parse_parameters_none() == FAILURE) {
388391
return;
389392
}
390393

394+
array_init(return_value);
395+
396+
#ifdef HAVE_LIBEDIT
397+
using_history();
391398
history = history_list();
399+
hs = history_get_history_state();
392400

393-
array_init(return_value);
401+
if (history && hs) {
402+
int i;
403+
for (i = 0; i < hs->length; i++) {
404+
#else
405+
history = history_list();
394406

395407
if (history) {
396408
int i;
397409
for (i = 0; history[i]; i++) {
410+
#endif
398411
add_next_index_string(return_value,history[i]->line);
399412
}
400413
}

0 commit comments

Comments
 (0)