26
26
#include "php_readline.h"
27
27
#include "readline_cli.h"
28
28
29
- #if HAVE_LIBREADLINE || HAVE_LIBEDIT
30
-
31
29
#ifndef HAVE_RL_COMPLETION_MATCHES
32
30
#define rl_completion_matches completion_matches
33
31
#endif
34
32
35
- #ifdef HAVE_LIBEDIT
36
33
#include <editline/readline.h>
37
- #else
38
- #include <readline/readline.h>
39
- #include <readline/history.h>
40
- #endif
41
34
42
35
PHP_FUNCTION (readline );
43
36
PHP_FUNCTION (readline_add_history );
44
37
PHP_FUNCTION (readline_info );
45
38
PHP_FUNCTION (readline_clear_history );
46
- #ifndef HAVE_LIBEDIT
39
+ #ifdef HAVE_HISTORY_LIST
47
40
PHP_FUNCTION (readline_list_history );
48
41
#endif
49
42
PHP_FUNCTION (readline_read_history );
@@ -88,7 +81,7 @@ ZEND_END_ARG_INFO()
88
81
ZEND_BEGIN_ARG_INFO (arginfo_readline_clear_history , 0 )
89
82
ZEND_END_ARG_INFO ()
90
83
91
- #ifndef HAVE_LIBEDIT
84
+ #ifdef HAVE_HISTORY_LIST
92
85
ZEND_BEGIN_ARG_INFO (arginfo_readline_list_history , 0 )
93
86
ZEND_END_ARG_INFO ()
94
87
#endif
@@ -133,7 +126,7 @@ static const zend_function_entry php_readline_functions[] = {
133
126
PHP_FE (readline_info , arginfo_readline_info )
134
127
PHP_FE (readline_add_history , arginfo_readline_add_history )
135
128
PHP_FE (readline_clear_history , arginfo_readline_clear_history )
136
- #ifndef HAVE_LIBEDIT
129
+ #ifdef HAVE_HISTORY_LIST
137
130
PHP_FE (readline_list_history , arginfo_readline_list_history )
138
131
#endif
139
132
PHP_FE (readline_read_history , arginfo_readline_read_history )
@@ -170,10 +163,8 @@ ZEND_GET_MODULE(readline)
170
163
171
164
PHP_MINIT_FUNCTION (readline )
172
165
{
173
- #if HAVE_LIBREADLINE
174
- /* libedit don't need this call which set the tty in cooked mode */
175
- using_history ();
176
- #endif
166
+ /* libedit don't need "using_history" call which set the tty in cooked mode */
167
+
177
168
ZVAL_UNDEF (& _readline_completion );
178
169
#if HAVE_RL_CALLBACK_READ_CHAR
179
170
ZVAL_UNDEF (& _prepped_callback );
@@ -254,21 +245,6 @@ PHP_FUNCTION(readline_info)
254
245
#ifndef PHP_WIN32
255
246
add_assoc_long (return_value ,"end" ,rl_end );
256
247
#endif
257
- #ifdef HAVE_LIBREADLINE
258
- add_assoc_long (return_value ,"mark" ,rl_mark );
259
- add_assoc_long (return_value ,"done" ,rl_done );
260
- add_assoc_long (return_value ,"pending_input" ,rl_pending_input );
261
- add_assoc_string (return_value ,"prompt" ,SAFE_STRING (rl_prompt ));
262
- add_assoc_string (return_value ,"terminal_name" ,(char * )SAFE_STRING (rl_terminal_name ));
263
- add_assoc_str (return_value , "completion_append_character" ,
264
- rl_completion_append_character == 0
265
- ? ZSTR_EMPTY_ALLOC ()
266
- : ZSTR_CHAR (rl_completion_append_character ));
267
- add_assoc_bool (return_value ,"completion_suppress_append" ,rl_completion_suppress_append );
268
- #endif
269
- #if HAVE_ERASE_EMPTY_LINE
270
- add_assoc_long (return_value ,"erase_empty_line" ,rl_erase_empty_line );
271
- #endif
272
248
#ifndef PHP_WIN32
273
249
add_assoc_string (return_value ,"library_version" ,(char * )SAFE_STRING (rl_library_version ));
274
250
#endif
@@ -289,51 +265,6 @@ PHP_FUNCTION(readline_info)
289
265
} else if (!strcasecmp (what , "end" )) {
290
266
RETVAL_LONG (rl_end );
291
267
#endif
292
- #ifdef HAVE_LIBREADLINE
293
- } else if (!strcasecmp (what , "mark" )) {
294
- RETVAL_LONG (rl_mark );
295
- } else if (!strcasecmp (what , "done" )) {
296
- oldval = rl_done ;
297
- if (value ) {
298
- convert_to_long_ex (value );
299
- rl_done = Z_LVAL_P (value );
300
- }
301
- RETVAL_LONG (oldval );
302
- } else if (!strcasecmp (what , "pending_input" )) {
303
- oldval = rl_pending_input ;
304
- if (value ) {
305
- convert_to_string_ex (value );
306
- rl_pending_input = Z_STRVAL_P (value )[0 ];
307
- }
308
- RETVAL_LONG (oldval );
309
- } else if (!strcasecmp (what , "prompt" )) {
310
- RETVAL_STRING (SAFE_STRING (rl_prompt ));
311
- } else if (!strcasecmp (what , "terminal_name" )) {
312
- RETVAL_STRING ((char * )SAFE_STRING (rl_terminal_name ));
313
- } else if (!strcasecmp (what , "completion_suppress_append" )) {
314
- oldval = rl_completion_suppress_append ;
315
- if (value ) {
316
- rl_completion_suppress_append = zend_is_true (value );
317
- }
318
- RETVAL_BOOL (oldval );
319
- } else if (!strcasecmp (what , "completion_append_character" )) {
320
- oldval = rl_completion_append_character ;
321
- if (value ) {
322
- convert_to_string_ex (value )
323
- rl_completion_append_character = (int )Z_STRVAL_P (value )[0 ];
324
- }
325
- RETVAL_INTERNED_STR (
326
- oldval == 0 ? ZSTR_EMPTY_ALLOC () : ZSTR_CHAR (oldval ));
327
- #endif
328
- #if HAVE_ERASE_EMPTY_LINE
329
- } else if (!strcasecmp (what , "erase_empty_line" )) {
330
- oldval = rl_erase_empty_line ;
331
- if (value ) {
332
- convert_to_long_ex (value );
333
- rl_erase_empty_line = Z_LVAL_P (value );
334
- }
335
- RETVAL_LONG (oldval );
336
- #endif
337
268
#ifndef PHP_WIN32
338
269
} else if (!strcasecmp (what ,"library_version" )) {
339
270
RETVAL_STRING ((char * )SAFE_STRING (rl_library_version ));
@@ -383,41 +314,43 @@ PHP_FUNCTION(readline_clear_history)
383
314
return ;
384
315
}
385
316
386
- #if HAVE_LIBEDIT
387
317
/* clear_history is the only function where rl_initialize
388
318
is not call to ensure correct allocation */
389
319
using_history ();
390
- #endif
391
320
clear_history ();
392
321
393
322
RETURN_TRUE ;
394
323
}
395
324
396
325
/* }}} */
326
+
327
+ #ifdef HAVE_HISTORY_LIST
397
328
/* {{{ proto array readline_list_history(void)
398
329
Lists the history */
399
- #ifndef HAVE_LIBEDIT
400
330
PHP_FUNCTION (readline_list_history )
401
331
{
402
332
HIST_ENTRY * * history ;
333
+ HISTORY_STATE * hs ;
403
334
404
335
if (zend_parse_parameters_none () == FAILURE ) {
405
336
return ;
406
337
}
407
338
339
+ using_history ();
408
340
history = history_list ();
409
-
341
+ hs = history_get_history_state ();
410
342
array_init (return_value );
411
343
412
- if (history ) {
344
+ if (history && hs ) {
413
345
int i ;
414
- for (i = 0 ; history [ i ] ; i ++ ) {
415
- add_next_index_string (return_value ,history [i ]-> line );
346
+ for (i = 0 ; i < hs -> length ; i ++ ) {
347
+ add_next_index_string (return_value , history [i ]-> line );
416
348
}
417
349
}
418
350
}
419
- #endif
420
351
/* }}} */
352
+ #endif
353
+
421
354
/* {{{ proto bool readline_read_history([string filename])
422
355
Reads the history */
423
356
PHP_FUNCTION (readline_read_history )
@@ -638,11 +571,9 @@ PHP_FUNCTION(readline_callback_handler_remove)
638
571
Ask readline to redraw the display */
639
572
PHP_FUNCTION (readline_redisplay )
640
573
{
641
- #if HAVE_LIBEDIT
642
574
/* seems libedit doesn't take care of rl_initialize in rl_redisplay
643
575
* see bug #72538 */
644
576
using_history ();
645
- #endif
646
577
rl_redisplay ();
647
578
}
648
579
/* }}} */
@@ -660,5 +591,3 @@ PHP_FUNCTION(readline_on_new_line)
660
591
661
592
#endif
662
593
663
-
664
- #endif /* HAVE_LIBREADLINE */
0 commit comments