summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi Collet <remi@php.net>2019-02-19 08:51:56 +0100
committerRemi Collet <remi@php.net>2019-02-19 08:51:56 +0100
commit2850e09cbc389c0496cd24afe64029c65ebb7ca4 (patch)
tree20ba611b9e23d238e70cf3e2dcd29cd67d67850e
parenta8336fb7b91a085661acad844854b89230214acb (diff)
downloadphp-git-2850e09cbc389c0496cd24afe64029c65ebb7ca4.tar.gz
add readline_list_history with libedit >= 3.1 and mingweditline
-rw-r--r--ext/readline/config.m48
-rw-r--r--ext/readline/config.w321
-rw-r--r--ext/readline/readline.c45
-rw-r--r--ext/readline/tests/readline_read_history_001.phpt4
-rw-r--r--ext/readline/tests/readline_read_history_error_001.phpt2
5 files changed, 49 insertions, 11 deletions
diff --git a/ext/readline/config.m4 b/ext/readline/config.m4
index 0395835931..d11a2c11ec 100644
--- a/ext/readline/config.m4
+++ b/ext/readline/config.m4
@@ -72,6 +72,7 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])
+ AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])
elif test "$PHP_LIBEDIT" != "no"; then
@@ -126,6 +127,13 @@ elif test "$PHP_LIBEDIT" != "no"; then
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])
+ PHP_CHECK_LIBRARY(edit, history_list,
+ [
+ AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
+ ],[],[
+ -L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
+ ])
+
AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
fi
diff --git a/ext/readline/config.w32 b/ext/readline/config.w32
index 4e9e89c964..8f3a2db61f 100644
--- a/ext/readline/config.w32
+++ b/ext/readline/config.w32
@@ -8,6 +8,7 @@ if (PHP_READLINE != "no") {
EXTENSION("readline", "readline.c readline_cli.c");
ADD_FLAG("CFLAGS_READLINE", "/D HAVE_LIBEDIT");
ADD_FLAG("CFLAGS_READLINE", "/D HAVE_RL_COMPLETION_MATCHES");
+ ADD_FLAG("CFLAGS_READLINE", "/D HAVE_HISTORY_LIST");
} else {
WARNING("readline not enabled; libraries and headers not found");
}
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 70bfd275bd..89842b9655 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -43,7 +43,7 @@ PHP_FUNCTION(readline);
PHP_FUNCTION(readline_add_history);
PHP_FUNCTION(readline_info);
PHP_FUNCTION(readline_clear_history);
-#ifndef HAVE_LIBEDIT
+#ifdef HAVE_HISTORY_LIST
PHP_FUNCTION(readline_list_history);
#endif
PHP_FUNCTION(readline_read_history);
@@ -88,7 +88,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_readline_clear_history, 0)
ZEND_END_ARG_INFO()
-#ifndef HAVE_LIBEDIT
+#ifdef HAVE_HISTORY_LIST
ZEND_BEGIN_ARG_INFO(arginfo_readline_list_history, 0)
ZEND_END_ARG_INFO()
#endif
@@ -133,7 +133,7 @@ static const zend_function_entry php_readline_functions[] = {
PHP_FE(readline_info, arginfo_readline_info)
PHP_FE(readline_add_history, arginfo_readline_add_history)
PHP_FE(readline_clear_history, arginfo_readline_clear_history)
-#ifndef HAVE_LIBEDIT
+#ifdef HAVE_HISTORY_LIST
PHP_FE(readline_list_history, arginfo_readline_list_history)
#endif
PHP_FE(readline_read_history, arginfo_readline_read_history)
@@ -394,9 +394,10 @@ PHP_FUNCTION(readline_clear_history)
}
/* }}} */
+
+#ifdef HAVE_HISTORY_LIST
/* {{{ proto array readline_list_history(void)
Lists the history */
-#ifndef HAVE_LIBEDIT
PHP_FUNCTION(readline_list_history)
{
HIST_ENTRY **history;
@@ -405,19 +406,49 @@ PHP_FUNCTION(readline_list_history)
return;
}
+ array_init(return_value);
+
+#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32) /* Winedit on Windows */
history = history_list();
- array_init(return_value);
+ if (history) {
+ int i, n = history_length();
+ for (i = 0; i < n; i++) {
+ add_next_index_string(return_value, history[i]->line);
+ }
+ }
+
+#elif defined(HAVE_LIBEDIT) /* libedit */
+ {
+ HISTORY_STATE *hs;
+ int i;
+
+ using_history();
+ hs = history_get_history_state();
+ if (hs && hs->length) {
+ history = history_list();
+ if (history) {
+ for (i = 0; i < hs->length; i++) {
+ add_next_index_string(return_value, history[i]->line);
+ }
+ }
+ }
+ }
+
+#else /* readline */
+ history = history_list();
if (history) {
int i;
for (i = 0; history[i]; i++) {
- add_next_index_string(return_value,history[i]->line);
+ add_next_index_string(return_value, history[i]->line);
}
}
-}
#endif
+}
/* }}} */
+#endif
+
/* {{{ proto bool readline_read_history([string filename])
Reads the history */
PHP_FUNCTION(readline_read_history)
diff --git a/ext/readline/tests/readline_read_history_001.phpt b/ext/readline/tests/readline_read_history_001.phpt
index fcdb1ae325..6cabaf369b 100644
--- a/ext/readline/tests/readline_read_history_001.phpt
+++ b/ext/readline/tests/readline_read_history_001.phpt
@@ -5,9 +5,9 @@ readline_read_history(): Basic test
--FILE--
<?php
-$name = tempnam('/tmp', 'readline.tmp');
+$name = tempnam(sys_get_temp_dir(), 'readline.tmp');
-readline_add_history("foo\n");
+readline_add_history("foo");
var_dump(readline_write_history($name));
diff --git a/ext/readline/tests/readline_read_history_error_001.phpt b/ext/readline/tests/readline_read_history_error_001.phpt
index 836c83b807..0d90280d8d 100644
--- a/ext/readline/tests/readline_read_history_error_001.phpt
+++ b/ext/readline/tests/readline_read_history_error_001.phpt
@@ -8,9 +8,7 @@ Pedro Manoel Evangelista <pedro.evangelista at gmail dot com>
<?php if (!READLINE_LIB != "libedit") die('skip READLINE_LIB != "libedit"'); ?>
--FILE--
<?php
-var_dump(readline_read_history());
var_dump(readline_read_history('nofile'));
?>
--EXPECT--
bool(false)
-bool(false)