28#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)
30#ifndef HAVE_RL_COMPLETION_MATCHES
31#define rl_completion_matches completion_matches
35#include <editline/readline.h>
37#include <readline/readline.h>
38#include <readline/history.h>
41#ifdef HAVE_RL_CALLBACK_READ_CHAR
43static zval _prepped_callback;
47static zval _readline_completion;
48static zval _readline_array;
71#ifdef COMPILE_DL_READLINE
77#ifdef HAVE_LIBREADLINE
82#ifdef HAVE_RL_CALLBACK_READ_CHAR
86 register_readline_symbols(module_number);
100#ifdef HAVE_RL_CALLBACK_READ_CHAR
102 rl_callback_handler_remove();
141#define SAFE_STRING(s) ((s)?(char*)(s):"")
157 add_assoc_string(
return_value,
"line_buffer",SAFE_STRING(rl_line_buffer));
162#ifdef HAVE_LIBREADLINE
165 add_assoc_long(
return_value,
"pending_input",rl_pending_input);
166 add_assoc_string(
return_value,
"prompt",SAFE_STRING(rl_prompt));
167 add_assoc_string(
return_value,
"terminal_name",(
char *)SAFE_STRING(rl_terminal_name));
168 add_assoc_str(
return_value,
"completion_append_character",
169 rl_completion_append_character == 0
171 :
ZSTR_CHAR(rl_completion_append_character));
172 add_assoc_bool(
return_value,
"completion_suppress_append",rl_completion_suppress_append);
174#ifdef HAVE_ERASE_EMPTY_LINE
175 add_assoc_long(
return_value,
"erase_empty_line",rl_erase_empty_line);
178 add_assoc_string(
return_value,
"library_version",(
char *)SAFE_STRING(rl_library_version));
180 add_assoc_string(
return_value,
"readline_name",(
char *)SAFE_STRING(rl_readline_name));
181 add_assoc_long(
return_value,
"attempted_completion_over",rl_attempted_completion_over);
184 oldstr = strdup(rl_line_buffer ? rl_line_buffer :
"");
186 if (!try_convert_to_string(
value)) {
189#if !defined(PHP_WIN32) && !defined(HAVE_LIBEDIT)
190 if (!rl_line_buffer) {
195 oldstr = strdup(rl_line_buffer ? rl_line_buffer :
"");
201 if (rl_line_buffer) {
202 free(rl_line_buffer);
204 rl_line_buffer = tmp;
207#if !defined(PHP_WIN32)
219#ifdef HAVE_LIBREADLINE
225 rl_done = zval_get_long(
value);
229 oldval = rl_pending_input;
231 if (!try_convert_to_string(
value)) {
242 oldval = rl_completion_suppress_append;
248 oldval = rl_completion_append_character;
250 if (!try_convert_to_string(
value)) {
258#ifdef HAVE_ERASE_EMPTY_LINE
260 oldval = rl_erase_empty_line;
262 rl_erase_empty_line = zval_get_long(
value);
271 oldstr = (
char*)rl_readline_name;
274 if (!try_convert_to_string(
value)) {
281 oldval = rl_attempted_completion_over;
283 rl_attempted_completion_over = zval_get_long(
value);
326#ifdef HAVE_HISTORY_LIST
330 HIST_ENTRY **history;
338#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32)
339 history = history_list();
342 int i,
n = history_length();
343 for (i = 0; i <
n; i++) {
348#elif defined(HAVE_LIBEDIT)
354 hs = history_get_history_state();
355 if (hs && hs->length) {
356 history = history_list();
358 for (i = 0; i < hs->length; i++) {
367 history = history_list();
371 for (i = 0; history[i]; i++) {
395 if (read_history(
arg)) {
418 if (write_history(
arg)) {
428static char *_readline_command_generator(
const char *
text,
int state)
434 zend_hash_internal_pointer_reset(myht);
437 while ((entry = zend_hash_get_current_data(myht)) !=
NULL) {
438 zend_hash_move_forward(myht);
449static void _readline_string_zval(
zval *
ret,
const char *str)
461 char **matches =
NULL;
463 _readline_string_zval(¶ms[0],
text);
470 if (zend_hash_num_elements(
Z_ARRVAL(_readline_array))) {
474 matches = calloc(3,
sizeof(
char *));
478 matches[0] = strdup(
"");
503 if (rl_attempted_completion_function ==
NULL) {
511#ifdef HAVE_RL_CALLBACK_READ_CHAR
513static void php_rl_callback_handler(
char *the_line)
520 _readline_string_zval(¶ms[0], the_line);
541 rl_callback_handler_remove();
547 rl_callback_handler_install(
prompt, php_rl_callback_handler);
561 rl_callback_read_char();
574 rl_callback_handler_remove();
601#ifdef HAVE_RL_ON_NEW_LINE
PHPAPI int php_check_open_basedir(const char *path)
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_RSHUTDOWN_FUNCTION
unsigned const char * end
unsigned const char * text
readline(?string $prompt=null)
readline_info(?string $var_name=null, $value=null)
readline_callback_handler_install(string $prompt, callable $callback)
readline_completion_function(callable $callback)
readline_add_history(string $prompt)
readline_callback_handler_remove()
readline_callback_read_char()
readline_read_history(?string $filename=null)
readline_write_history(?string $filename=null)
#define rl_completion_matches
char ** php_readline_completion_cb(const char *text, int start, int end)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API zend_result add_next_index_string(zval *arg, const char *str)
struct _zend_fcall_info_cache zend_fcall_info_cache
#define RETVAL_INTERNED_STR(s)
#define ZVAL_STRING(z, s)
#define ZEND_GET_MODULE(name)
#define zend_parse_parameters_none()
struct _zend_fcall_info zend_fcall_info
#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params)
strncmp(string $string1, string $string2, int $length)
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
#define SHUTDOWN_FUNC_ARGS_PASSTHRU
#define INIT_FUNC_ARGS_PASSTHRU
#define ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op)
#define convert_to_string(op)
#define ZSTR_EMPTY_ALLOC()
#define zend_string_equals_literal_ci(str, c)
#define Z_STRVAL_P(zval_p)
struct _zend_array HashTable
#define Z_STRLEN_P(zval_p)
#define SEPARATE_ARRAY(zv)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)