felipe          Wed Jun 25 15:06:58 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/readline       readline.c 
  Log:
  - New parameter parsing API
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/readline/readline.c?r1=1.42.2.3.2.3.2.2&r2=1.42.2.3.2.3.2.3&diff_format=u
Index: php-src/ext/readline/readline.c
diff -u php-src/ext/readline/readline.c:1.42.2.3.2.3.2.2 
php-src/ext/readline/readline.c:1.42.2.3.2.3.2.3
--- php-src/ext/readline/readline.c:1.42.2.3.2.3.2.2    Mon Dec 31 07:17:12 2007
+++ php-src/ext/readline/readline.c     Wed Jun 25 15:06:58 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: readline.c,v 1.42.2.3.2.3.2.2 2007/12/31 07:17:12 sebastian Exp $ */
+/* $Id: readline.c,v 1.42.2.3.2.3.2.3 2008/06/25 15:06:58 felipe Exp $ */
 
 /* {{{ includes & prototypes */
 
@@ -154,21 +154,20 @@
 
 /* }}} */
 
-/* {{{ 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 @@
                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 @@
                                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 @@
                        }
                        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 @@
 }
 
 /* }}} */
-/* {{{ 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 @@
    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 @@
 }
 #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 @@
    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 @@
        HashTable  *myht = Z_ARRVAL(_readline_array);
        zval **entry;
        
-       if (! state)    {
+       if (!state) {
                zend_hash_internal_pointer_reset(myht);
        }
        
@@ -457,8 +438,9 @@
                RETURN_FALSE;
        }
 
-       if (_readline_completion)
+       if (_readline_completion) {
                FREE_ZVAL(_readline_completion);
+       }
 
        MAKE_STD_ZVAL(_readline_completion);
        *_readline_completion = *arg;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to