2525#include "readline_cli.h"
2626#include "readline_arginfo.h"
2727
28- #if HAVE_LIBREADLINE || HAVE_LIBEDIT
28+ #ifdef HAVE_LIBEDIT
2929
3030#ifndef HAVE_RL_COMPLETION_MATCHES
3131#define rl_completion_matches completion_matches
3232#endif
3333
34- #ifdef HAVE_LIBEDIT
3534#include <editline/readline.h>
36- #else
37- #include <readline/readline.h>
38- #include <readline/history.h>
39- #endif
4035
4136#if HAVE_RL_CALLBACK_READ_CHAR
4237
@@ -74,10 +69,6 @@ ZEND_GET_MODULE(readline)
7469
7570PHP_MINIT_FUNCTION (readline )
7671{
77- #if HAVE_LIBREADLINE
78- /* libedit don't need this call which set the tty in cooked mode */
79- using_history ();
80- #endif
8172 ZVAL_UNDEF (& _readline_completion );
8273#if HAVE_RL_CALLBACK_READ_CHAR
8374 ZVAL_UNDEF (& _prepped_callback );
@@ -158,23 +149,6 @@ PHP_FUNCTION(readline_info)
158149 add_assoc_long (return_value ,"point" ,rl_point );
159150#ifndef PHP_WIN32
160151 add_assoc_long (return_value ,"end" ,rl_end );
161- #endif
162- #ifdef HAVE_LIBREADLINE
163- add_assoc_long (return_value ,"mark" ,rl_mark );
164- add_assoc_long (return_value ,"done" ,rl_done );
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
170- ? ZSTR_EMPTY_ALLOC ()
171- : ZSTR_CHAR (rl_completion_append_character ));
172- add_assoc_bool (return_value ,"completion_suppress_append" ,rl_completion_suppress_append );
173- #endif
174- #if HAVE_ERASE_EMPTY_LINE
175- add_assoc_long (return_value ,"erase_empty_line" ,rl_erase_empty_line );
176- #endif
177- #ifndef PHP_WIN32
178152 add_assoc_string (return_value ,"library_version" ,(char * )SAFE_STRING (rl_library_version ));
179153#endif
180154 add_assoc_string (return_value ,"readline_name" ,(char * )SAFE_STRING (rl_readline_name ));
@@ -195,55 +169,6 @@ PHP_FUNCTION(readline_info)
195169#ifndef PHP_WIN32
196170 } else if (zend_string_equals_literal_ci (what , "end" )) {
197171 RETVAL_LONG (rl_end );
198- #endif
199- #ifdef HAVE_LIBREADLINE
200- } else if (zend_string_equals_literal_ci (what , "mark" )) {
201- RETVAL_LONG (rl_mark );
202- } else if (zend_string_equals_literal_ci (what , "done" )) {
203- oldval = rl_done ;
204- if (value ) {
205- rl_done = zval_get_long (value );
206- }
207- RETVAL_LONG (oldval );
208- } else if (zend_string_equals_literal_ci (what , "pending_input" )) {
209- oldval = rl_pending_input ;
210- if (value ) {
211- if (!try_convert_to_string (value )) {
212- RETURN_THROWS ();
213- }
214- rl_pending_input = Z_STRVAL_P (value )[0 ];
215- }
216- RETVAL_LONG (oldval );
217- } else if (zend_string_equals_literal_ci (what , "prompt" )) {
218- RETVAL_STRING (SAFE_STRING (rl_prompt ));
219- } else if (zend_string_equals_literal_ci (what , "terminal_name" )) {
220- RETVAL_STRING ((char * )SAFE_STRING (rl_terminal_name ));
221- } else if (zend_string_equals_literal_ci (what , "completion_suppress_append" )) {
222- oldval = rl_completion_suppress_append ;
223- if (value ) {
224- rl_completion_suppress_append = zend_is_true (value );
225- }
226- RETVAL_BOOL (oldval );
227- } else if (zend_string_equals_literal_ci (what , "completion_append_character" )) {
228- oldval = rl_completion_append_character ;
229- if (value ) {
230- if (!try_convert_to_string (value )) {
231- RETURN_THROWS ();
232- }
233- rl_completion_append_character = (int )Z_STRVAL_P (value )[0 ];
234- }
235- RETVAL_INTERNED_STR (
236- oldval == 0 ? ZSTR_EMPTY_ALLOC () : ZSTR_CHAR (oldval ));
237- #endif
238- #if HAVE_ERASE_EMPTY_LINE
239- } else if (zend_string_equals_literal_ci (what , "erase_empty_line" )) {
240- oldval = rl_erase_empty_line ;
241- if (value ) {
242- rl_erase_empty_line = zval_get_long (value );
243- }
244- RETVAL_LONG (oldval );
245- #endif
246- #ifndef PHP_WIN32
247172 } else if (zend_string_equals_literal_ci (what ,"library_version" )) {
248173 RETVAL_STRING ((char * )SAFE_STRING (rl_library_version ));
249174#endif
@@ -291,11 +216,9 @@ PHP_FUNCTION(readline_clear_history)
291216 RETURN_THROWS ();
292217 }
293218
294- #if HAVE_LIBEDIT
295219 /* clear_history is the only function where rl_initialize
296220 is not call to ensure correct allocation */
297221 using_history ();
298- #endif
299222 clear_history ();
300223
301224 RETURN_TRUE ;
@@ -315,7 +238,7 @@ PHP_FUNCTION(readline_list_history)
315238
316239 array_init (return_value );
317240
318- #if defined( HAVE_LIBEDIT ) && defined( PHP_WIN32 ) /* Winedit on Windows */
241+ #ifdef PHP_WIN32 /* Winedit on Windows */
319242 history = history_list ();
320243
321244 if (history ) {
@@ -325,7 +248,7 @@ PHP_FUNCTION(readline_list_history)
325248 }
326249 }
327250
328- #elif defined( HAVE_LIBEDIT ) /* libedit */
251+ #else
329252 {
330253 HISTORY_STATE * hs ;
331254 int i ;
@@ -342,16 +265,6 @@ PHP_FUNCTION(readline_list_history)
342265 }
343266 free (hs );
344267 }
345-
346- #else /* readline */
347- history = history_list ();
348-
349- if (history ) {
350- int i ;
351- for (i = 0 ; history [i ]; i ++ ) {
352- add_next_index_string (return_value , history [i ]-> line );
353- }
354- }
355268#endif
356269}
357270/* }}} */
@@ -572,11 +485,9 @@ PHP_FUNCTION(readline_redisplay)
572485 RETURN_THROWS ();
573486 }
574487
575- #if HAVE_LIBEDIT
576488 /* seems libedit doesn't take care of rl_initialize in rl_redisplay
577489 * see bug #72538 */
578490 using_history ();
579- #endif
580491 rl_redisplay ();
581492}
582493/* }}} */
@@ -598,4 +509,4 @@ PHP_FUNCTION(readline_on_new_line)
598509#endif
599510
600511
601- #endif /* HAVE_LIBREADLINE */
512+ #endif /* HAVE_LIBEDIT */
0 commit comments