From: Felipe Pena Date: Wed, 25 Jun 2008 15:06:58 +0000 (+0000) Subject: - New parameter parsing API X-Git-Tag: php-5.3.0alpha1~598 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ece9a2cf6d28fc04f870af2f41796109aa6d66f;p=php - New parameter parsing API --- diff --git a/ext/readline/readline.c b/ext/readline/readline.c index d37ecaad38..7803c25ab9 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -154,21 +154,20 @@ PHP_FUNCTION(readline) /* }}} */ -/* {{{ proto mixed readline_info([string varname] [, string newvalue]) - Gets/sets various internal readline variables. */ - #define SAFE_STRING(s) ((s)?(char*)(s):"") +/* {{{ proto mixed readline_info([string varname [, string newvalue]]) + Gets/sets various internal readline variables. */ PHP_FUNCTION(readline_info) { - zval **what; + char *what; zval **value; - int oldval; + int what_len, oldval; char *oldstr; int ac = ZEND_NUM_ARGS(); - if (ac < 0 || ac > 2 || zend_get_parameters_ex(ac, &what, &value) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sZ", &what, &what_len, &value) == FAILURE) { + return; } if (ac == 0) { @@ -189,9 +188,7 @@ PHP_FUNCTION(readline_info) add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version),1); add_assoc_string(return_value,"readline_name",(char *)SAFE_STRING(rl_readline_name),1); } else { - convert_to_string_ex(what); - - if (! strcasecmp(Z_STRVAL_PP(what),"line_buffer")) { + if (!strcasecmp(what,"line_buffer")) { oldstr = rl_line_buffer; if (ac == 2) { /* XXX if (rl_line_buffer) free(rl_line_buffer); */ @@ -199,34 +196,34 @@ PHP_FUNCTION(readline_info) rl_line_buffer = strdup(Z_STRVAL_PP(value)); } RETVAL_STRING(SAFE_STRING(oldstr),1); - } else if (! strcasecmp(Z_STRVAL_PP(what),"point")) { + } else if (!strcasecmp(what, "point")) { RETVAL_LONG(rl_point); - } else if (! strcasecmp(Z_STRVAL_PP(what),"end")) { + } else if (!strcasecmp(what, "end")) { RETVAL_LONG(rl_end); #ifdef HAVE_LIBREADLINE - } else if (! strcasecmp(Z_STRVAL_PP(what),"mark")) { + } else if (!strcasecmp(what, "mark")) { RETVAL_LONG(rl_mark); - } else if (! strcasecmp(Z_STRVAL_PP(what),"done")) { + } else if (!strcasecmp(what, "done")) { oldval = rl_done; if (ac == 2) { convert_to_long_ex(value); rl_done = Z_LVAL_PP(value); } RETVAL_LONG(oldval); - } else if (! strcasecmp(Z_STRVAL_PP(what),"pending_input")) { + } else if (!strcasecmp(what, "pending_input")) { oldval = rl_pending_input; if (ac == 2) { convert_to_string_ex(value); rl_pending_input = Z_STRVAL_PP(value)[0]; } RETVAL_LONG(oldval); - } else if (! strcasecmp(Z_STRVAL_PP(what),"prompt")) { + } else if (!strcasecmp(what, "prompt")) { RETVAL_STRING(SAFE_STRING(rl_prompt),1); - } else if (! strcasecmp(Z_STRVAL_PP(what),"terminal_name")) { + } else if (!strcasecmp(what, "terminal_name")) { RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name),1); #endif #if HAVE_ERASE_EMPTY_LINE - } else if (! strcasecmp(Z_STRVAL_PP(what),"erase_empty_line")) { + } else if (!strcasecmp(what, "erase_empty_line")) { oldval = rl_erase_empty_line; if (ac == 2) { convert_to_long_ex(value); @@ -234,9 +231,9 @@ PHP_FUNCTION(readline_info) } RETVAL_LONG(oldval); #endif - } else if (! strcasecmp(Z_STRVAL_PP(what),"library_version")) { + } else if (!strcasecmp(what,"library_version")) { RETVAL_STRING((char *)SAFE_STRING(rl_library_version),1); - } else if (! strcasecmp(Z_STRVAL_PP(what),"readline_name")) { + } else if (!strcasecmp(what, "readline_name")) { oldstr = (char*)rl_readline_name; if (ac == 2) { /* XXX if (rl_readline_name) free(rl_readline_name); */ @@ -249,19 +246,18 @@ PHP_FUNCTION(readline_info) } /* }}} */ -/* {{{ proto bool readline_add_history([string prompt]) +/* {{{ proto bool readline_add_history(string prompt) Adds a line to the history */ PHP_FUNCTION(readline_add_history) { - zval **arg; - int ac = ZEND_NUM_ARGS(); + char *arg; + int arg_len; - if (ac != 1 || zend_get_parameters_ex(ac, &arg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { + return; } - convert_to_string_ex(arg); - add_history(Z_STRVAL_PP(arg)); + add_history(arg); RETURN_TRUE; } @@ -271,10 +267,8 @@ PHP_FUNCTION(readline_add_history) Clears the history */ PHP_FUNCTION(readline_clear_history) { - int ac = ZEND_NUM_ARGS(); - - if (ac != 0) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters_none() == FAILURE) { + return; } clear_history(); @@ -308,26 +302,19 @@ PHP_FUNCTION(readline_list_history) } #endif /* }}} */ -/* {{{ proto bool readline_read_history([string filename] [, int from] [,int to]) +/* {{{ proto bool readline_read_history([string filename]) Reads the history */ PHP_FUNCTION(readline_read_history) { - zval **arg; - char *filename = NULL; - int ac = ZEND_NUM_ARGS(); + char *arg = NULL; + int arg_len; - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &arg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &arg, &arg_len) == FAILURE) { + return; } /* XXX from & to NYI */ - - if (ac == 1) { - convert_to_string_ex(arg); - filename = Z_STRVAL_PP(arg); - } - - if (read_history(filename)) { + if (read_history(arg)) { RETURN_FALSE; } else { RETURN_TRUE; @@ -339,20 +326,14 @@ PHP_FUNCTION(readline_read_history) Writes the history */ PHP_FUNCTION(readline_write_history) { - zval **arg; - char *filename = NULL; - int ac = ZEND_NUM_ARGS(); - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } + char *arg = NULL; + int arg_len; - if (ac == 1) { - convert_to_string_ex(arg); - filename = Z_STRVAL_PP(arg); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &arg, &arg_len) == FAILURE) { + return; } - if (write_history(filename)) { + if (write_history(arg)) { RETURN_FALSE; } else { RETURN_TRUE; @@ -368,7 +349,7 @@ static char *_readline_command_generator(const char *text, int state) HashTable *myht = Z_ARRVAL(_readline_array); zval **entry; - if (! state) { + if (!state) { zend_hash_internal_pointer_reset(myht); } @@ -457,8 +438,9 @@ PHP_FUNCTION(readline_completion_function) RETURN_FALSE; } - if (_readline_completion) + if (_readline_completion) { FREE_ZVAL(_readline_completion); + } MAKE_STD_ZVAL(_readline_completion); *_readline_completion = *arg;