Skip to content

Commit 5136141

Browse files
committed
add readline_list_history with libedit >= 3.1 and mingweditline
1 parent 56dba3f commit 5136141

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

ext/readline/config.m4

Lines changed: 8 additions & 0 deletions
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/config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (PHP_READLINE != "no") {
99
EXTENSION("readline", "readline.c readline_cli.c");
1010
ADD_FLAG("CFLAGS_READLINE", "/D HAVE_LIBEDIT");
1111
ADD_FLAG("CFLAGS_READLINE", "/D HAVE_RL_COMPLETION_MATCHES");
12+
ADD_FLAG("CFLAGS_READLINE", "/D HAVE_HISTORY_LIST");
1213
} else {
1314
WARNING("readline not enabled; libraries and headers not found");
1415
}

ext/readline/readline.c

Lines changed: 37 additions & 7 deletions
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)
@@ -377,9 +377,10 @@ PHP_FUNCTION(readline_clear_history)
377377
}
378378

379379
/* }}} */
380+
381+
#ifdef HAVE_HISTORY_LIST
380382
/* {{{ proto array readline_list_history(void)
381383
Lists the history */
382-
#ifndef HAVE_LIBEDIT
383384
PHP_FUNCTION(readline_list_history)
384385
{
385386
HIST_ENTRY **history;
@@ -388,19 +389,48 @@ PHP_FUNCTION(readline_list_history)
388389
return;
389390
}
390391

392+
array_init(return_value);
393+
394+
#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32) /* Winedit on Windows */
391395
history = history_list();
392396

393-
array_init(return_value);
397+
if (history) {
398+
int i, n = history_length();
399+
for (i = 0; i < n; i++) {
400+
add_next_index_string(return_value, history[i]->line);
401+
}
402+
}
403+
404+
#elif defined(HAVE_LIBEDIT) /* libedit */
405+
{
406+
HISTORY_STATE *hs;
407+
int i;
408+
409+
using_history();
410+
history = history_list();
411+
hs = history_get_history_state();
412+
413+
if (history && hs) {
414+
for (i = 0; i < hs->length; i++) {
415+
add_next_index_string(return_value, history[i]->line);
416+
}
417+
}
418+
}
419+
420+
#else /* readline */
421+
history = history_list();
394422

395423
if (history) {
396424
int i;
397425
for (i = 0; history[i]; i++) {
398-
add_next_index_string(return_value,history[i]->line);
426+
add_next_index_string(return_value, history[i]->line);
399427
}
400428
}
401-
}
402429
#endif
430+
}
403431
/* }}} */
432+
#endif
433+
404434
/* {{{ proto bool readline_read_history([string filename])
405435
Reads the history */
406436
PHP_FUNCTION(readline_read_history)

0 commit comments

Comments
 (0)