From: Thies C. Arntzen Date: Thu, 14 Oct 1999 15:20:40 +0000 (+0000) Subject: interface to GNU-Readline! (not yet active, autoconf needs to be done) X-Git-Tag: php-4.0b3_RC2~178 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d9584c0875ba9a73f202ccc7e8885eddf73b298;p=php interface to GNU-Readline! (not yet active, autoconf needs to be done) very neat - but only usable in standalone (command-promt) mode! --- diff --git a/ext/readline/Makefile.am b/ext/readline/Makefile.am new file mode 100644 index 0000000000..75de323d35 --- /dev/null +++ b/ext/readline/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LTLIBRARIES=libphpext_readline.la +libphpext_readline_la_SOURCES=readline.c + diff --git a/ext/readline/config.h.stub b/ext/readline/config.h.stub new file mode 100644 index 0000000000..76d47f6bcd --- /dev/null +++ b/ext/readline/config.h.stub @@ -0,0 +1,3 @@ +/* define if you want to use the readline extension */ + +#undef HAVE_LIBREADLINE diff --git a/ext/readline/config.m4 b/ext/readline/config.m4 new file mode 100644 index 0000000000..530679ebc6 --- /dev/null +++ b/ext/readline/config.m4 @@ -0,0 +1,7 @@ +dnl $Id$ +dnl config.m4 for extension readline +dnl don't forget to call PHP_EXTENSION(readline) + +dnl AC_DEFINE(HAVE_LIBREADLINE, 1) +dnl PHP_EXTENSION(readline) + diff --git a/ext/readline/php_readline.h b/ext/readline/php_readline.h new file mode 100644 index 0000000000..6080489258 --- /dev/null +++ b/ext/readline/php_readline.h @@ -0,0 +1,36 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Thies C. Arntzen (thies@digicol.de) | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef _PHP_READLINE_H +#define _PHP_READLINE_H + +#if HAVE_LIBREADLINE + +extern zend_module_entry readline_module_entry; +#define phpext_readline_ptr &readline_module_entry + +#else + +#define phpext_readline_ptr NULL + +#endif /* HAVE_LIBREADLINE */ + +#endif /* _PHP_READLINE_H */ + diff --git a/ext/readline/readline.c b/ext/readline/readline.c new file mode 100644 index 0000000000..5f504a64e6 --- /dev/null +++ b/ext/readline/readline.c @@ -0,0 +1,204 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Thies C. Arntzen (thies@digicol.de) | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#include "php.h" + +#if HAVE_LIBREADLINE + +#include +#include + + +PHP_FUNCTION(readline); +PHP_FUNCTION(readline_version); + +PHP_FUNCTION(readline_add_history); +PHP_FUNCTION(readline_list_history); +PHP_FUNCTION(readline_read_history); +PHP_FUNCTION(readline_write_history); + +PHP_MINIT_FUNCTION(readline); + +static zend_function_entry php_readline_functions[] = { + PHP_FE(readline, NULL) + PHP_FE(readline_version, NULL) + PHP_FE(readline_add_history, NULL) + PHP_FE(readline_list_history, NULL) + PHP_FE(readline_read_history, NULL) + PHP_FE(readline_write_history, NULL) + {NULL, NULL, NULL} +}; + +zend_module_entry readline_module_entry = { + "PHP-Readline", + php_readline_functions, + PHP_MINIT(readline), + NULL, + NULL, + NULL, + NULL, + STANDARD_MODULE_PROPERTIES +}; + +PHP_MINIT_FUNCTION(readline) +{ + return SUCCESS; +} + +/* {{{ proto string readline([string prompt]) */ + +PHP_FUNCTION(readline) +{ + char *result; + pval **arg; + int ac = ARG_COUNT(ht); + + if (ac < 0 || ac > 1 || getParametersEx(ac, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(arg); + + result = readline((*arg)->value.str.val); + + if (! result) { + RETURN_FALSE; + } else { + RETURN_STRING(result,1); + } +} + +/* }}} */ +/* {{{ proto string readline_version() */ + +PHP_FUNCTION(readline_version) +{ + int ac = ARG_COUNT(ht); + + if (ac) { + WRONG_PARAM_COUNT; + } + + RETURN_STRING(rl_library_version?rl_library_version:"unknown",1); +} + +/* }}} */ +/* {{{ proto void readline_add_history([string prompt]) */ + +PHP_FUNCTION(readline_add_history) +{ + pval **arg; + int ac = ARG_COUNT(ht); + + if (ac < 1 || ac > 1 || getParametersEx(ac, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(arg); + + add_history((*arg)->value.str.val); + + RETURN_TRUE; +} + +/* }}} */ +/* {{{ proto array readline_list_history() */ + +PHP_FUNCTION(readline_list_history) +{ + HIST_ENTRY **history; + int ac = ARG_COUNT(ht); + + if (ac) { + WRONG_PARAM_COUNT; + } + + history = history_list(); + + array_init(return_value); + + if (history) { + int i; + for (i = 0; history[i]; i++) { + add_next_index_string(return_value,history[i]->line,1); + } + } +} + +/* }}} */ +/* {{{ proto int readline_read_history([string filename][,int from][,int to]) */ + +PHP_FUNCTION(readline_read_history) +{ + pval **arg; + char *filename = NULL; + int ac = ARG_COUNT(ht); + + if (ac < 0 || ac > 1 || getParametersEx(ac, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + /* XXX from & to NYI */ + + if (ac == 1) { + convert_to_string_ex(arg); + filename = (*arg)->value.str.val; + } + + if (read_history(filename)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} + +/* }}} */ +/* {{{ proto int readline_write_history([string filename]) */ + +PHP_FUNCTION(readline_write_history) +{ + pval **arg; + char *filename = NULL; + int ac = ARG_COUNT(ht); + + if (ac < 0 || ac > 1 || getParametersEx(ac, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (ac == 1) { + convert_to_string_ex(arg); + filename = (*arg)->value.str.val; + } + + if (write_history(filename)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} + +/* }}} */ + +#endif /* HAVE_LIBREADLINE */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/readline/setup.stub b/ext/readline/setup.stub new file mode 100644 index 0000000000..a335af80ed --- /dev/null +++ b/ext/readline/setup.stub @@ -0,0 +1,3 @@ +define_option with-readline 'GNU-Readline support?' yesnodir no \ +' Whether to build the readline extension.' +