cvs: pecl /newt newt.c

From: Date: Mon, 16 Aug 2004 16:34:58 +0000
Subject: cvs: pecl /newt newt.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1678@lists.php.net to get a copy of this message
michael Mon Aug 16 12:34:58 2004 EDT Modified files: /pecl/newt newt.c Log: * handle first K arguments of newt_win_{message,ternary,choice,etc...} using zend_parse_parameters http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.10&r2=1.11&ty=u Index: pecl/newt/newt.c diff -u pecl/newt/newt.c:1.10 pecl/newt/newt.c:1.11 --- pecl/newt/newt.c:1.10 Sun Aug 15 16:12:36 2004 +++ pecl/newt/newt.c Mon Aug 16 12:34:58 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: newt.c,v 1.10 2004/08/15 20:12:36 michael Exp $ */ +/* $Id: newt.c,v 1.11 2004/08/16 16:34:58 michael Exp $ */ #include <newt.h> @@ -3205,6 +3205,7 @@ PHP_FUNCTION(newt_win_message) { char *title, *button_text, *text; + int title_len, button_text_len; zval ***args, *z_text = NULL; int argc = ZEND_NUM_ARGS(); @@ -3212,23 +3213,20 @@ args = (zval ***) emalloc (sizeof(zval **) * argc); - if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + if (zend_parse_parameters (2 TSRMLS_CC, "ss", &title, &title_len, + &button_text, &button_text_len) == FAILURE) { return; } - - if (Z_TYPE_PP(args[0]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "First argument must be string"); - } - title = Z_STRVAL_PP(args[0]); - if (Z_TYPE_PP(args[1]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Second argument must be string"); + if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + return; } - button_text = Z_STRVAL_PP(args[1]); newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "sprintf", &z_text, argc-2, args+2); text = Z_STRVAL_P(z_text); - newtWinMessage (title, button_text, text); + if (text) { + newtWinMessage (title, button_text, text); + } efree (args); } /* }}} */ @@ -3239,28 +3237,26 @@ PHP_FUNCTION(newt_win_messagev) { char *title, *button_text, *text; + int title_len, button_text_len; zval **args[4], *z_text = NULL; int argc = 4; if (argc != ZEND_NUM_ARGS()) { WRONG_PARAM_COUNT; } - - if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + + if (zend_parse_parameters (2 TSRMLS_CC, "ss", &title, &title_len, + &button_text, &button_text_len) == FAILURE) { return; } - - if (Z_TYPE_PP(args[0]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "First argument must be string"); - } - title = Z_STRVAL_PP(args[0]); - if (Z_TYPE_PP(args[1]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Second argument must be string"); + if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + return; } - button_text = Z_STRVAL_PP(args[1]); newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "vsprintf", &z_text, argc-2, args+2); text = Z_STRVAL_P(z_text); - newtWinMessage (title, button_text, text); + if (text) { + newtWinMessage (title, button_text, text); + } } /* }}} */ @@ -3270,35 +3266,29 @@ PHP_FUNCTION(newt_win_choice) { char *title, *button1_text, *button2_text, *text; + int title_len, button1_text_len, button2_text_len; zval ***args, *z_text = NULL; - int button_id; + int button_id = 0; int argc = ZEND_NUM_ARGS(); if (argc < 4) { WRONG_PARAM_COUNT; } args = (zval ***) emalloc (sizeof(zval **) * argc); - if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + if (zend_parse_parameters (3 TSRMLS_CC, "sss", &title, &title_len, &button1_text, &button1_text_len, + &button2_text, &button2_text_len) == FAILURE) { return; } - - if (Z_TYPE_PP(args[0]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "First argument must be string"); - } - title = Z_STRVAL_PP(args[0]); - if (Z_TYPE_PP(args[1]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Second argument must be string"); - } - button1_text = Z_STRVAL_PP(args[1]); - if (Z_TYPE_PP(args[2]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Third argument must be string"); + if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + return; } - button2_text = Z_STRVAL_PP(args[2]); newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "sprintf", &z_text, argc-3, args+3); text = Z_STRVAL_P(z_text); - button_id = newtWinChoice (title, button1_text, button2_text, text); + if (text) { + button_id = newtWinChoice (title, button1_text, button2_text, text); + } efree (args); RETURN_LONG (button_id); @@ -3311,39 +3301,29 @@ PHP_FUNCTION(newt_win_ternary) { char *title, *button1_text, *button2_text, *button3_text, *text; + int title_len, button1_text_len, button2_text_len, button3_text_len; zval ***args, *z_text = NULL; - int button_id; + int button_id = 0; int argc = ZEND_NUM_ARGS(); if (argc < 5) { WRONG_PARAM_COUNT; } args = (zval ***) emalloc (sizeof(zval **) * argc); - if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + if (zend_parse_parameters (4 TSRMLS_CC, "ssss", &title, &title_len, &button1_text, &button1_text_len, + &button2_text, &button2_text_len, &button3_text, &button3_text_len) == FAILURE) { return; } - - if (Z_TYPE_PP(args[0]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "First argument must be string"); - } - title = Z_STRVAL_PP(args[0]); - if (Z_TYPE_PP(args[1]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Second argument must be string"); - } - button1_text = Z_STRVAL_PP(args[1]); - if (Z_TYPE_PP(args[2]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Third argument must be string"); - } - button2_text = Z_STRVAL_PP(args[2]); - if (Z_TYPE_PP(args[3]) != IS_STRING) { - php_error_docref (NULL TSRMLS_CC, E_ERROR, "Fourth argument must be string"); + if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + return; } - button3_text = Z_STRVAL_PP(args[3]); newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "sprintf", &z_text, argc-4, args+4); text = Z_STRVAL_P(z_text); - button_id = newtWinTernary (title, button1_text, button2_text, button3_text, text); + if (text) { + button_id = newtWinTernary (title, button1_text, button2_text, button3_text, text); + } efree (args); RETURN_LONG (button_id);

« previous php.pecl.cvs (#1678) next »