From: Stanislav Malyshev Date: Thu, 18 Jan 2001 11:42:09 +0000 (+0000) Subject: Libedit readline replacement support X-Git-Tag: php-4.0.5RC1~535 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66dafaa2c5a4869787a6d304aefa2fb12c317f7a;p=php Libedit readline replacement support # Comments are very welcome! --- diff --git a/ext/readline/README.libedit b/ext/readline/README.libedit new file mode 100644 index 0000000000..a19371056e --- /dev/null +++ b/ext/readline/README.libedit @@ -0,0 +1,4 @@ +This library can be built with libedit - non-GPL drop-in readline replacement. +Libedit can be obtained from http://sourceforge.net/projects/libedit/ +It is taken from NetBSD (http://www.netbsd.org/) CVS repository and modified +to work as stand-alone library. diff --git a/ext/readline/config.m4 b/ext/readline/config.m4 index df705ea188..20cdde181b 100644 --- a/ext/readline/config.m4 +++ b/ext/readline/config.m4 @@ -2,6 +2,8 @@ dnl $Id$ dnl config.m4 for extension readline dnl don't forget to call PHP_EXTENSION(readline) +PHP_ARG_WITH(libedit,for libedit readline replacement, +[ --with-libedit[=DIR] Include libedit readline replacement.]) PHP_ARG_WITH(readline,for readline support, [ --with-readline[=DIR] Include readline support. DIR is the readline @@ -32,3 +34,28 @@ if test "$PHP_READLINE" != "no"; then AC_DEFINE(HAVE_LIBREADLINE, 1, [ ]) PHP_EXTENSION(readline, $ext_shared) fi + +if test "$PHP_LIBEDIT" != "no"; then + for i in /usr/local /usr $PHP_LIBEDIT; do + if test -f $i/include/readline/readline.h; then + LIBEDIT_DIR=$i + fi + done + + if test -z "$LIBEDIT_DIR"; then + AC_MSG_ERROR(Please reinstall libedit - I cannot find readline.h) + fi + AC_ADD_INCLUDE($LIBEDIT_DIR/include) + + AC_CHECK_LIB(ncurses, tgetent, [ + AC_ADD_LIBRARY_WITH_PATH(ncurses,,READLINE__SHARED_LIBADD)],[ + AC_CHECK_LIB(termcap, tgetent, [ + AC_ADD_LIBRARY_WITH_PATH(termcap,,READLINE_SHARED_LIBADD)]) + ]) + + AC_ADD_LIBRARY_WITH_PATH(edit, $LIBEDIT_DIR/lib, READLINE_SHARED_LIBADD) + PHP_SUBST(READLINE_SHARED_LIBADD) + + AC_DEFINE(HAVE_LIBEDIT, 1, [ ]) + PHP_EXTENSION(readline, $ext_shared) +fi \ No newline at end of file diff --git a/ext/readline/php_readline.h b/ext/readline/php_readline.h index ad15916b5a..186acf4b92 100644 --- a/ext/readline/php_readline.h +++ b/ext/readline/php_readline.h @@ -21,7 +21,7 @@ #ifndef PHP_READLINE_H #define PHP_READLINE_H -#if HAVE_LIBREADLINE +#if HAVE_LIBREADLINE || HAVE_LIBEDIT #ifdef ZTS #warning Readline module will *NEVER* be thread-safe #endif diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 1652905c8f..3061235464 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -23,10 +23,12 @@ #include "php.h" #include "php_readline.h" -#if HAVE_LIBREADLINE +#if HAVE_LIBREADLINE || HAVE_LIBEDIT #include +#ifndef HAVE_LIBEDIT #include +#endif PHP_FUNCTION(readline); PHP_FUNCTION(readline_add_history); @@ -51,7 +53,11 @@ static zend_function_entry php_readline_functions[] = { PHP_FE(readline_info, NULL) PHP_FE(readline_add_history, NULL) PHP_FE(readline_clear_history, NULL) +#ifdef HAVE_READLINE PHP_FE(readline_list_history, NULL) +#else + PHP_FALIAS(readline_list_history, warn_not_available, NULL) +#endif PHP_FE(readline_read_history, NULL) PHP_FE(readline_write_history, NULL) PHP_FE(readline_completion_function,NULL) @@ -137,15 +143,17 @@ PHP_FUNCTION(readline_info) add_assoc_string(return_value,"line_buffer",SAFE_STRING(rl_line_buffer),1); add_assoc_long(return_value,"point",rl_point); add_assoc_long(return_value,"end",rl_end); +#ifdef HAVE_READLINE add_assoc_long(return_value,"mark",rl_mark); add_assoc_long(return_value,"done",rl_done); add_assoc_long(return_value,"pending_input",rl_pending_input); + add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt),1); + add_assoc_string(return_value,"terminal_name",SAFE_STRING(rl_terminal_name),1); +#endif #if HAVE_ERASE_EMPTY_LINE add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line); #endif - add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt),1); add_assoc_string(return_value,"library_version",SAFE_STRING(rl_library_version),1); - add_assoc_string(return_value,"terminal_name",SAFE_STRING(rl_terminal_name),1); add_assoc_string(return_value,"readline_name",SAFE_STRING(rl_readline_name),1); } else { convert_to_string_ex(what); @@ -162,6 +170,7 @@ PHP_FUNCTION(readline_info) RETVAL_LONG(rl_point); } else if (! strcasecmp((*what)->value.str.val,"end")) { RETVAL_LONG(rl_end); +#ifdef HAVE_READLINE } else if (! strcasecmp((*what)->value.str.val,"mark")) { RETVAL_LONG(rl_mark); } else if (! strcasecmp((*what)->value.str.val,"done")) { @@ -178,6 +187,11 @@ PHP_FUNCTION(readline_info) rl_pending_input = (*value)->value.str.val[0]; } RETVAL_LONG(oldval); + } else if (! strcasecmp((*what)->value.str.val,"prompt")) { + RETVAL_STRING(SAFE_STRING(rl_prompt),1); + } else if (! strcasecmp((*what)->value.str.val,"terminal_name")) { + RETVAL_STRING(SAFE_STRING(rl_terminal_name),1); +#endif #if HAVE_ERASE_EMPTY_LINE } else if (! strcasecmp((*what)->value.str.val,"erase_empty_line")) { oldval = rl_erase_empty_line; @@ -187,12 +201,8 @@ PHP_FUNCTION(readline_info) } RETVAL_LONG(oldval); #endif - } else if (! strcasecmp((*what)->value.str.val,"prompt")) { - RETVAL_STRING(SAFE_STRING(rl_prompt),1); } else if (! strcasecmp((*what)->value.str.val,"library_version")) { RETVAL_STRING(SAFE_STRING(rl_library_version),1); - } else if (! strcasecmp((*what)->value.str.val,"terminal_name")) { - RETVAL_STRING(SAFE_STRING(rl_terminal_name),1); } else if (! strcasecmp((*what)->value.str.val,"readline_name")) { oldstr = rl_readline_name; if (ac == 2) { @@ -242,6 +252,7 @@ PHP_FUNCTION(readline_clear_history) /* }}} */ /* {{{ proto array readline_list_history(void) Lists the history */ +#ifdef HAVE_READLINE PHP_FUNCTION(readline_list_history) { HIST_ENTRY **history; @@ -262,7 +273,7 @@ PHP_FUNCTION(readline_list_history) } } } - +#endif /* }}} */ /* {{{ proto int readline_read_history([string filename] [, int from] [,int to]) Reads the history */