PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/readline - readline.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 122 213 57.3 %
Date: 2014-07-13 Functions: 11 20 55.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2013 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Thies C. Arntzen <thies@thieso.net>                          |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : /* {{{ includes & prototypes */
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "php.h"
      28             : #include "php_readline.h"
      29             : 
      30             : #if HAVE_LIBREADLINE || HAVE_LIBEDIT
      31             : 
      32             : #ifndef HAVE_RL_COMPLETION_MATCHES
      33             : #define rl_completion_matches completion_matches
      34             : #endif
      35             : 
      36             : #ifdef HAVE_LIBEDIT
      37             : #include <editline/readline.h>
      38             : #else
      39             : #include <readline/readline.h>
      40             : #include <readline/history.h>
      41             : #endif
      42             : 
      43             : PHP_FUNCTION(readline);
      44             : PHP_FUNCTION(readline_add_history);
      45             : PHP_FUNCTION(readline_info);
      46             : PHP_FUNCTION(readline_clear_history);
      47             : #ifndef HAVE_LIBEDIT
      48             : PHP_FUNCTION(readline_list_history);
      49             : #endif
      50             : PHP_FUNCTION(readline_read_history);
      51             : PHP_FUNCTION(readline_write_history);
      52             : PHP_FUNCTION(readline_completion_function);
      53             : 
      54             : #if HAVE_RL_CALLBACK_READ_CHAR
      55             : PHP_FUNCTION(readline_callback_handler_install);
      56             : PHP_FUNCTION(readline_callback_read_char);
      57             : PHP_FUNCTION(readline_callback_handler_remove);
      58             : PHP_FUNCTION(readline_redisplay);
      59             : PHP_FUNCTION(readline_on_new_line);
      60             : 
      61             : static zval *_prepped_callback = NULL;
      62             : 
      63             : #endif
      64             : 
      65             : static zval *_readline_completion = NULL;
      66             : static zval _readline_array;
      67             : 
      68             : PHP_MINIT_FUNCTION(readline);
      69             : PHP_RSHUTDOWN_FUNCTION(readline);
      70             : 
      71             : /* }}} */
      72             : 
      73             : /* {{{ arginfo */
      74             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline, 0, 0, 0)
      75             :         ZEND_ARG_INFO(0, prompt)
      76             : ZEND_END_ARG_INFO()
      77             : 
      78             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_info, 0, 0, 0)
      79             :         ZEND_ARG_INFO(0, varname)
      80             :         ZEND_ARG_INFO(0, newvalue)
      81             : ZEND_END_ARG_INFO()
      82             : 
      83             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_add_history, 0, 0, 1)
      84             :         ZEND_ARG_INFO(0, prompt)
      85             : ZEND_END_ARG_INFO()
      86             : 
      87             : ZEND_BEGIN_ARG_INFO(arginfo_readline_clear_history, 0)
      88             : ZEND_END_ARG_INFO()
      89             : 
      90             : #ifndef HAVE_LIBEDIT
      91             : ZEND_BEGIN_ARG_INFO(arginfo_readline_list_history, 0)
      92             : ZEND_END_ARG_INFO()
      93             : #endif
      94             : 
      95             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_read_history, 0, 0, 0)
      96             :         ZEND_ARG_INFO(0, filename)
      97             : ZEND_END_ARG_INFO()
      98             : 
      99             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_write_history, 0, 0, 0)
     100             :         ZEND_ARG_INFO(0, filename)
     101             : ZEND_END_ARG_INFO()
     102             : 
     103             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_completion_function, 0, 0, 1)
     104             :         ZEND_ARG_INFO(0, funcname)
     105             : ZEND_END_ARG_INFO()
     106             : 
     107             : #if HAVE_RL_CALLBACK_READ_CHAR
     108             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_callback_handler_install, 0, 0, 2)
     109             :         ZEND_ARG_INFO(0, prompt)
     110             :         ZEND_ARG_INFO(0, callback)
     111             : ZEND_END_ARG_INFO()
     112             : 
     113             : ZEND_BEGIN_ARG_INFO(arginfo_readline_callback_read_char, 0)
     114             : ZEND_END_ARG_INFO()
     115             : 
     116             : ZEND_BEGIN_ARG_INFO(arginfo_readline_callback_handler_remove, 0)
     117             : ZEND_END_ARG_INFO()
     118             : 
     119             : ZEND_BEGIN_ARG_INFO(arginfo_readline_redisplay, 0)
     120             : ZEND_END_ARG_INFO()
     121             : 
     122             : ZEND_BEGIN_ARG_INFO(arginfo_readline_on_new_line, 0)
     123             : ZEND_END_ARG_INFO()
     124             : #endif
     125             : /* }}} */
     126             : 
     127             : /* {{{ module stuff */
     128             : static const zend_function_entry php_readline_functions[] = {
     129             :         PHP_FE(readline,                                arginfo_readline)
     130             :         PHP_FE(readline_info,               arginfo_readline_info)
     131             :         PHP_FE(readline_add_history,            arginfo_readline_add_history)
     132             :         PHP_FE(readline_clear_history,          arginfo_readline_clear_history)
     133             : #ifndef HAVE_LIBEDIT
     134             :         PHP_FE(readline_list_history,           arginfo_readline_list_history)
     135             : #endif
     136             :         PHP_FE(readline_read_history,           arginfo_readline_read_history)
     137             :         PHP_FE(readline_write_history,          arginfo_readline_write_history)
     138             :         PHP_FE(readline_completion_function,arginfo_readline_completion_function)
     139             : #if HAVE_RL_CALLBACK_READ_CHAR
     140             :         PHP_FE(readline_callback_handler_install, arginfo_readline_callback_handler_install)
     141             :         PHP_FE(readline_callback_read_char,                     arginfo_readline_callback_read_char)
     142             :         PHP_FE(readline_callback_handler_remove,        arginfo_readline_callback_handler_remove)
     143             :         PHP_FE(readline_redisplay, arginfo_readline_redisplay)
     144             :         PHP_FE(readline_on_new_line, arginfo_readline_on_new_line)
     145             : #endif
     146             :         PHP_FE_END
     147             : };
     148             : 
     149             : zend_module_entry readline_module_entry = { 
     150             :         STANDARD_MODULE_HEADER,
     151             :         "readline", 
     152             :         php_readline_functions, 
     153             :         PHP_MINIT(readline), 
     154             :         NULL,
     155             :         NULL,
     156             :         PHP_RSHUTDOWN(readline),
     157             :         NULL, 
     158             :         NO_VERSION_YET,
     159             :         STANDARD_MODULE_PROPERTIES
     160             : };
     161             : 
     162             : #ifdef COMPILE_DL_READLINE
     163             : ZEND_GET_MODULE(readline)
     164             : #endif
     165             : 
     166       19341 : PHP_MINIT_FUNCTION(readline)
     167             : {
     168       19341 :         using_history();
     169       19341 :         return SUCCESS;
     170             : }
     171             : 
     172       19362 : PHP_RSHUTDOWN_FUNCTION(readline)
     173             : {
     174       19362 :         if (_readline_completion) {
     175           1 :                 zval_dtor(_readline_completion);
     176           1 :                 FREE_ZVAL(_readline_completion);
     177             :         }
     178             : #if HAVE_RL_CALLBACK_READ_CHAR
     179       19362 :         if (_prepped_callback) {
     180           1 :                 rl_callback_handler_remove();
     181           1 :                 zval_ptr_dtor(&_prepped_callback);
     182           1 :                 _prepped_callback = 0;
     183             :         }
     184             : #endif
     185             : 
     186       19362 :         return SUCCESS;
     187             : }
     188             : 
     189             : /* }}} */
     190             : 
     191             : /* {{{ proto string readline([string prompt]) 
     192             :    Reads a line */
     193           0 : PHP_FUNCTION(readline)
     194             : {
     195           0 :         char *prompt = NULL;
     196             :         int prompt_len;
     197             :         char *result;
     198             : 
     199           0 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &prompt, &prompt_len)) {
     200           0 :                 RETURN_FALSE;
     201             :         }
     202             : 
     203           0 :         result = readline(prompt);
     204             : 
     205           0 :         if (! result) {
     206           0 :                 RETURN_FALSE;
     207             :         } else {
     208           0 :                 RETVAL_STRING(result,1);
     209           0 :                 free(result);
     210             :         }
     211             : }
     212             : 
     213             : /* }}} */
     214             : 
     215             : #define SAFE_STRING(s) ((s)?(char*)(s):"")
     216             : 
     217             : /* {{{ proto mixed readline_info([string varname [, string newvalue]]) 
     218             :    Gets/sets various internal readline variables. */
     219           9 : PHP_FUNCTION(readline_info)
     220             : {
     221           9 :         char *what = NULL;
     222           9 :         zval **value = NULL;
     223             :         int what_len, oldval;
     224             :         char *oldstr;
     225             : 
     226           9 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sZ", &what, &what_len, &value) == FAILURE) {
     227           0 :                 return;
     228             :         }
     229             : 
     230           9 :         if (!what) {
     231           1 :                 array_init(return_value);
     232           1 :                 add_assoc_string(return_value,"line_buffer",SAFE_STRING(rl_line_buffer),1);
     233           1 :                 add_assoc_long(return_value,"point",rl_point);
     234           1 :                 add_assoc_long(return_value,"end",rl_end);
     235             : #ifdef HAVE_LIBREADLINE
     236           1 :                 add_assoc_long(return_value,"mark",rl_mark);
     237           1 :                 add_assoc_long(return_value,"done",rl_done);
     238           1 :                 add_assoc_long(return_value,"pending_input",rl_pending_input);
     239           1 :                 add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt),1);
     240           1 :                 add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name),1);
     241             : #endif
     242             : #if HAVE_ERASE_EMPTY_LINE
     243             :                 add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line);
     244             : #endif
     245           1 :                 add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version),1);
     246           1 :                 add_assoc_string(return_value,"readline_name",(char *)SAFE_STRING(rl_readline_name),1);
     247             :         } else {
     248           8 :                 if (!strcasecmp(what,"line_buffer")) {
     249           1 :                         oldstr = rl_line_buffer;
     250           1 :                         if (value) {
     251             :                                 /* XXX if (rl_line_buffer) free(rl_line_buffer); */
     252           0 :                                 convert_to_string_ex(value);
     253           0 :                                 rl_line_buffer = strdup(Z_STRVAL_PP(value));
     254             :                         }
     255           1 :                         RETVAL_STRING(SAFE_STRING(oldstr),1);
     256           7 :                 } else if (!strcasecmp(what, "point")) {
     257           0 :                         RETVAL_LONG(rl_point);
     258           7 :                 } else if (!strcasecmp(what, "end")) {
     259           0 :                         RETVAL_LONG(rl_end);
     260             : #ifdef HAVE_LIBREADLINE
     261           7 :                 } else if (!strcasecmp(what, "mark")) {
     262           0 :                         RETVAL_LONG(rl_mark);
     263           7 :                 } else if (!strcasecmp(what, "done")) {
     264           2 :                         oldval = rl_done;
     265           2 :                         if (value) {
     266           0 :                                 convert_to_long_ex(value);
     267           0 :                                 rl_done = Z_LVAL_PP(value);
     268             :                         }
     269           2 :                         RETVAL_LONG(oldval);
     270           5 :                 } else if (!strcasecmp(what, "pending_input")) {
     271           0 :                         oldval = rl_pending_input;
     272           0 :                         if (value) {
     273           0 :                                 convert_to_string_ex(value);
     274           0 :                                 rl_pending_input = Z_STRVAL_PP(value)[0];
     275             :                         }
     276           0 :                         RETVAL_LONG(oldval);
     277           5 :                 } else if (!strcasecmp(what, "prompt")) {
     278           0 :                         RETVAL_STRING(SAFE_STRING(rl_prompt),1);
     279           5 :                 } else if (!strcasecmp(what, "terminal_name")) {
     280           0 :                         RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name),1);
     281             : #endif
     282             : #if HAVE_ERASE_EMPTY_LINE
     283             :                 } else if (!strcasecmp(what, "erase_empty_line")) {
     284             :                         oldval = rl_erase_empty_line;
     285             :                         if (value) {
     286             :                                 convert_to_long_ex(value);
     287             :                                 rl_erase_empty_line = Z_LVAL_PP(value);
     288             :                         }
     289             :                         RETVAL_LONG(oldval);
     290             : #endif
     291           5 :                 } else if (!strcasecmp(what,"library_version")) {
     292           0 :                         RETVAL_STRING((char *)SAFE_STRING(rl_library_version),1);
     293           5 :                 } else if (!strcasecmp(what, "readline_name")) {
     294           3 :                         oldstr = (char*)rl_readline_name;
     295           3 :                         if (value) {
     296             :                                 /* XXX if (rl_readline_name) free(rl_readline_name); */
     297           4 :                                 convert_to_string_ex(value);
     298           1 :                                 rl_readline_name = strdup(Z_STRVAL_PP(value));;
     299             :                         }
     300           3 :                         RETVAL_STRING(SAFE_STRING(oldstr),1);
     301             :                 } 
     302             :         }
     303             : }
     304             : 
     305             : /* }}} */
     306             : /* {{{ proto bool readline_add_history(string prompt) 
     307             :    Adds a line to the history */
     308           8 : PHP_FUNCTION(readline_add_history)
     309             : {
     310             :         char *arg;
     311             :         int arg_len;
     312             : 
     313           8 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
     314           1 :                 return;
     315             :         }
     316             : 
     317           7 :         add_history(arg);
     318             : 
     319           7 :         RETURN_TRUE;
     320             : }
     321             : 
     322             : /* }}} */
     323             : /* {{{ proto bool readline_clear_history(void) 
     324             :    Clears the history */
     325           4 : PHP_FUNCTION(readline_clear_history)
     326             : {
     327           4 :         if (zend_parse_parameters_none() == FAILURE) {
     328           1 :                 return;
     329             :         }
     330             : 
     331           3 :         clear_history();
     332             : 
     333           3 :         RETURN_TRUE;
     334             : }
     335             : 
     336             : /* }}} */
     337             : /* {{{ proto array readline_list_history(void) 
     338             :    Lists the history */
     339             : #ifndef HAVE_LIBEDIT
     340           5 : PHP_FUNCTION(readline_list_history)
     341             : {
     342             :         HIST_ENTRY **history;
     343             : 
     344           5 :         if (zend_parse_parameters_none() == FAILURE) {
     345           1 :                 return;
     346             :         }
     347             :         
     348           4 :         history = history_list();
     349             :         
     350           4 :         array_init(return_value);
     351             : 
     352           4 :         if (history) {
     353             :                 int i;
     354           7 :                 for (i = 0; history[i]; i++) {
     355           4 :                         add_next_index_string(return_value,history[i]->line,1);
     356             :                 }
     357             :         }
     358             : }
     359             : #endif
     360             : /* }}} */
     361             : /* {{{ proto bool readline_read_history([string filename]) 
     362             :    Reads the history */
     363           1 : PHP_FUNCTION(readline_read_history)
     364             : {
     365           1 :         char *arg = NULL;
     366             :         int arg_len;
     367             : 
     368           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &arg, &arg_len) == FAILURE) {
     369           0 :                 return;
     370             :         }
     371             : 
     372           1 :         if (php_check_open_basedir(arg TSRMLS_CC)) {
     373           0 :                 RETURN_FALSE;
     374             :         }
     375             : 
     376             :         /* XXX from & to NYI */
     377           1 :         if (read_history(arg)) {
     378           0 :                 RETURN_FALSE;
     379             :         } else {
     380           1 :                 RETURN_TRUE;
     381             :         }
     382             : }
     383             : 
     384             : /* }}} */
     385             : /* {{{ proto bool readline_write_history([string filename]) 
     386             :    Writes the history */
     387           2 : PHP_FUNCTION(readline_write_history)
     388             : {
     389           2 :         char *arg = NULL;
     390             :         int arg_len;
     391             : 
     392           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &arg, &arg_len) == FAILURE) {
     393           0 :                 return;
     394             :         }
     395             : 
     396           2 :         if (php_check_open_basedir(arg TSRMLS_CC)) {
     397           0 :                 RETURN_FALSE;
     398             :         }
     399             : 
     400           2 :         if (write_history(arg)) {
     401           0 :                 RETURN_FALSE;
     402             :         } else {
     403           2 :                 RETURN_TRUE;
     404             :         }
     405             : }
     406             : 
     407             : /* }}} */
     408             : /* {{{ proto bool readline_completion_function(string funcname) 
     409             :    Readline completion function? */
     410             : 
     411           0 : static char *_readline_command_generator(const char *text, int state)
     412             : {
     413           0 :         HashTable  *myht = Z_ARRVAL(_readline_array);
     414             :         zval **entry;
     415             :         
     416           0 :         if (!state) {
     417           0 :                 zend_hash_internal_pointer_reset(myht);
     418             :         }
     419             :         
     420           0 :         while (zend_hash_get_current_data(myht, (void **)&entry) == SUCCESS) {
     421           0 :                 zend_hash_move_forward(myht);
     422             : 
     423           0 :                 convert_to_string_ex(entry);
     424           0 :                 if (strncmp (Z_STRVAL_PP(entry), text, strlen(text)) == 0) {
     425           0 :                         return (strdup(Z_STRVAL_PP(entry)));
     426             :                 }
     427             :         }
     428             : 
     429           0 :         return NULL;
     430             : }
     431             : 
     432           0 : static zval *_readline_string_zval(const char *str)
     433             : {
     434             :         zval *ret;
     435             :         int len;
     436             :         
     437           0 :         MAKE_STD_ZVAL(ret);
     438             :         
     439           0 :         if (str) {
     440           0 :                 len = strlen(str);
     441           0 :                 ZVAL_STRINGL(ret, (char*)str, len, 1);
     442             :         } else {
     443           0 :                 ZVAL_NULL(ret);
     444             :         }
     445             : 
     446           0 :         return ret;
     447             : }
     448             : 
     449           0 : static zval *_readline_long_zval(long l)
     450             : {
     451             :         zval *ret;
     452           0 :         MAKE_STD_ZVAL(ret);
     453             : 
     454           0 :         Z_TYPE_P(ret) = IS_LONG;
     455           0 :         Z_LVAL_P(ret) = l;
     456           0 :         return ret;
     457             : }
     458             : 
     459           0 : static char **_readline_completion_cb(const char *text, int start, int end)
     460             : { 
     461             :         zval *params[3];
     462             :         int i;
     463           0 :         char **matches = NULL;
     464             :         TSRMLS_FETCH();
     465             : 
     466           0 :         params[0]=_readline_string_zval(text);
     467           0 :         params[1]=_readline_long_zval(start);
     468           0 :         params[2]=_readline_long_zval(end);
     469             : 
     470           0 :         if (call_user_function(CG(function_table), NULL, _readline_completion, &_readline_array, 3, params TSRMLS_CC) == SUCCESS) {
     471           0 :                 if (Z_TYPE(_readline_array) == IS_ARRAY) {
     472           0 :                         if (zend_hash_num_elements(Z_ARRVAL(_readline_array))) {
     473           0 :                                 matches = rl_completion_matches(text,_readline_command_generator);
     474             :                         } else {
     475           0 :                                 matches = malloc(sizeof(char *) * 2);
     476           0 :                                 if (!matches) {
     477           0 :                                         return NULL;
     478             :                                 }
     479           0 :                                 matches[0] = strdup("");
     480           0 :                                 matches[1] = '\0';
     481             :                         }
     482             :                 }
     483             :         }
     484             :         
     485           0 :         for (i = 0; i < 3; i++) {
     486           0 :                 zval_ptr_dtor(&params[i]);
     487             :         }
     488           0 :         zval_dtor(&_readline_array);
     489             :         
     490           0 :         return matches; 
     491             : }
     492             : 
     493           4 : PHP_FUNCTION(readline_completion_function)
     494             : {
     495           4 :         zval *arg = NULL;
     496           4 :         char *name = NULL;
     497             : 
     498           4 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg)) {
     499           0 :                 RETURN_FALSE;
     500             :         }
     501             : 
     502           4 :         if (!zend_is_callable(arg, 0, &name TSRMLS_CC)) {
     503           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not callable", name);
     504           2 :                 efree(name);
     505           2 :                 RETURN_FALSE;
     506             :         }
     507           2 :         efree(name);
     508             : 
     509           2 :         if (_readline_completion) {
     510           1 :                 zval_dtor(_readline_completion);
     511           1 :                 FREE_ZVAL(_readline_completion);
     512             :         }
     513             : 
     514           2 :         MAKE_STD_ZVAL(_readline_completion);
     515           2 :         *_readline_completion = *arg;
     516           2 :         zval_copy_ctor(_readline_completion);
     517             : 
     518           2 :         rl_attempted_completion_function = _readline_completion_cb;
     519           2 :         if (rl_attempted_completion_function == NULL) {
     520           0 :                 efree(name);
     521           0 :                 RETURN_FALSE;
     522             :         }
     523           2 :         RETURN_TRUE;
     524             : }
     525             : 
     526             : /* }}} */
     527             : 
     528             : #if HAVE_RL_CALLBACK_READ_CHAR
     529             : 
     530           0 : static void php_rl_callback_handler(char *the_line)
     531             : {
     532             :         zval *params[1];
     533             :         zval dummy;
     534             :         TSRMLS_FETCH();
     535             : 
     536           0 :         ZVAL_NULL(&dummy);
     537             : 
     538           0 :         params[0] = _readline_string_zval(the_line);
     539             : 
     540           0 :         call_user_function(CG(function_table), NULL, _prepped_callback, &dummy, 1, params TSRMLS_CC);
     541             : 
     542           0 :         zval_ptr_dtor(&params[0]);
     543           0 :         zval_dtor(&dummy);
     544           0 : }
     545             : 
     546             : /* {{{ proto void readline_callback_handler_install(string prompt, mixed callback)
     547             :    Initializes the readline callback interface and terminal, prints the prompt and returns immediately */
     548           5 : PHP_FUNCTION(readline_callback_handler_install)
     549             : {
     550             :         zval *callback;
     551           5 :         char *name = NULL;
     552             :         char *prompt;
     553             :         int prompt_len;
     554             : 
     555           5 :         if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &prompt, &prompt_len, &callback)) {
     556           1 :                 return;
     557             :         }
     558             : 
     559           4 :         if (!zend_is_callable(callback, 0, &name TSRMLS_CC)) {
     560           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not callable", name);
     561           1 :                 efree(name);
     562           1 :                 RETURN_FALSE;
     563             :         }
     564           3 :         efree(name);
     565             : 
     566           3 :         if (_prepped_callback) {
     567           1 :                 rl_callback_handler_remove();
     568           1 :                 zval_dtor(_prepped_callback);
     569           1 :                 FREE_ZVAL(_prepped_callback);
     570             :         }
     571             : 
     572           3 :         ALLOC_ZVAL(_prepped_callback);
     573           3 :         MAKE_COPY_ZVAL(&callback, _prepped_callback);
     574             : 
     575           3 :         rl_callback_handler_install(prompt, php_rl_callback_handler);
     576             : 
     577           3 :         RETURN_TRUE;
     578             : }
     579             : /* }}} */
     580             : 
     581             : /* {{{ proto void readline_callback_read_char()
     582             :    Informs the readline callback interface that a character is ready for input */
     583           0 : PHP_FUNCTION(readline_callback_read_char)
     584             : {
     585           0 :         if (_prepped_callback) {
     586           0 :                 rl_callback_read_char();
     587             :         }
     588           0 : }
     589             : /* }}} */
     590             : 
     591             : /* {{{ proto bool readline_callback_handler_remove()
     592             :    Removes a previously installed callback handler and restores terminal settings */
     593           2 : PHP_FUNCTION(readline_callback_handler_remove)
     594             : {
     595           2 :         if (_prepped_callback) {
     596           1 :                 rl_callback_handler_remove();
     597           1 :                 zval_dtor(_prepped_callback);
     598           1 :                 FREE_ZVAL(_prepped_callback);
     599           1 :                 _prepped_callback = 0;
     600           1 :                 RETURN_TRUE;
     601             :         }
     602           1 :         RETURN_FALSE;
     603             : }
     604             : /* }}} */
     605             : 
     606             : /* {{{ proto void readline_redisplay(void)
     607             :    Ask readline to redraw the display */
     608           0 : PHP_FUNCTION(readline_redisplay)
     609             : {
     610           0 :         rl_redisplay();
     611           0 : }
     612             : /* }}} */
     613             : 
     614             : /* {{{ proto void readline_on_new_line(void)
     615             :    Inform readline that the cursor has moved to a new line */
     616           0 : PHP_FUNCTION(readline_on_new_line)
     617             : {
     618           0 :         rl_on_new_line();
     619           0 : }
     620             : /* }}} */
     621             : 
     622             : #endif
     623             : 
     624             : 
     625             : #endif /* HAVE_LIBREADLINE */
     626             : 
     627             : /*
     628             :  * Local variables:
     629             :  * tab-width: 4
     630             :  * c-basic-offset: 4
     631             :  * End:
     632             :  */

Generated by: LCOV version 1.10

Generated at Sun, 13 Jul 2014 23:57:55 +0000 (8 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.