2626#include "php_readline.h"
2727#include "readline_cli.h"
2828
29- #if HAVE_LIBREADLINE || HAVE_LIBEDIT
29+ #if HAVE_LIBEDIT
3030
3131#ifndef HAVE_RL_COMPLETION_MATCHES
3232#define rl_completion_matches completion_matches
3333#endif
3434
35- #ifdef HAVE_LIBEDIT
3635#include <editline/readline.h>
37- #else
38- #include <readline/readline.h>
39- #include <readline/history.h>
40- #endif
4136
4237PHP_FUNCTION (readline );
4338PHP_FUNCTION (readline_add_history );
@@ -170,10 +165,6 @@ ZEND_GET_MODULE(readline)
170165
171166PHP_MINIT_FUNCTION (readline )
172167{
173- #if HAVE_LIBREADLINE
174- /* libedit don't need this call which set the tty in cooked mode */
175- using_history ();
176- #endif
177168 ZVAL_UNDEF (& _readline_completion );
178169#if HAVE_RL_CALLBACK_READ_CHAR
179170 ZVAL_UNDEF (& _prepped_callback );
@@ -254,21 +245,6 @@ PHP_FUNCTION(readline_info)
254245#ifndef PHP_WIN32
255246 add_assoc_long (return_value ,"end" ,rl_end );
256247#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
272248#ifndef PHP_WIN32
273249 add_assoc_string (return_value ,"library_version" ,(char * )SAFE_STRING (rl_library_version ));
274250#endif
@@ -289,51 +265,6 @@ PHP_FUNCTION(readline_info)
289265 } else if (!strcasecmp (what , "end" )) {
290266 RETVAL_LONG (rl_end );
291267#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
337268#ifndef PHP_WIN32
338269 } else if (!strcasecmp (what ,"library_version" )) {
339270 RETVAL_STRING ((char * )SAFE_STRING (rl_library_version ));
@@ -383,11 +314,9 @@ PHP_FUNCTION(readline_clear_history)
383314 return ;
384315 }
385316
386- #if HAVE_LIBEDIT
387317 /* clear_history is the only function where rl_initialize
388318 is not call to ensure correct allocation */
389319 using_history ();
390- #endif
391320 clear_history ();
392321
393322 RETURN_TRUE ;
@@ -408,7 +337,7 @@ PHP_FUNCTION(readline_list_history)
408337
409338 array_init (return_value );
410339
411- #if defined( HAVE_LIBEDIT ) && defined( PHP_WIN32 ) /* Winedit on Windows */
340+ #ifdef PHP_WIN32 /* Winedit on Windows */
412341 history = history_list ();
413342
414343 if (history ) {
@@ -418,7 +347,7 @@ PHP_FUNCTION(readline_list_history)
418347 }
419348 }
420349
421- #elif defined( HAVE_LIBEDIT ) /* libedit */
350+ #else /* libedit */
422351 {
423352 HISTORY_STATE * hs ;
424353 int i ;
@@ -434,16 +363,6 @@ PHP_FUNCTION(readline_list_history)
434363 }
435364 }
436365 }
437-
438- #else /* readline */
439- history = history_list ();
440-
441- if (history ) {
442- int i ;
443- for (i = 0 ; history [i ]; i ++ ) {
444- add_next_index_string (return_value , history [i ]-> line );
445- }
446- }
447366#endif
448367}
449368/* }}} */
@@ -669,11 +588,9 @@ PHP_FUNCTION(readline_callback_handler_remove)
669588 Ask readline to redraw the display */
670589PHP_FUNCTION (readline_redisplay )
671590{
672- #if HAVE_LIBEDIT
673591 /* seems libedit doesn't take care of rl_initialize in rl_redisplay
674592 * see bug #72538 */
675593 using_history ();
676- #endif
677594 rl_redisplay ();
678595}
679596/* }}} */
@@ -692,4 +609,4 @@ PHP_FUNCTION(readline_on_new_line)
692609#endif
693610
694611
695- #endif /* HAVE_LIBREADLINE */
612+ #endif /* HAVE_LIBEDIT */
0 commit comments