cvs: pecl /newt newt.c php_newt.h

From: Date: Sun, 15 Aug 2004 15:34:16 +0000
Subject: cvs: pecl /newt newt.c php_newt.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1663@lists.php.net to get a copy of this message
michael Sun Aug 15 11:34:16 2004 EDT Modified files: /pecl/newt newt.c php_newt.h Log: * zend_error() -> php_error_docref() * implemented newt_win_message(...), accepting variable number of arguments via calling to PHP functions: sprintf and svprintf

http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.6&r2=1.7&ty=u Index: pecl/newt/newt.c diff -u pecl/newt/newt.c:1.6 pecl/newt/newt.c:1.7 --- pecl/newt/newt.c:1.6 Fri Aug 13 16:35:54 2004 +++ pecl/newt/newt.c Sun Aug 15 11:34:16 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: newt.c,v 1.6 2004/08/13 20:35:54 michael Exp $ */ +/* $Id: newt.c,v 1.7 2004/08/15 15:34:16 michael Exp $ */ #include <newt.h> @@ -259,7 +259,7 @@ const char *p; if (!cb) { - zend_error (E_ERROR, "Null data has been passed to the newt callback wrapper"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt callback wrapper"); } MAKE_STD_ZVAL (z_func_name); @@ -268,7 +268,7 @@ /* First argument is component resource */ MAKE_STD_ZVAL (args[0]); if (NEWT_GET_RESOURCE_BY_DATA (args[0], component) == FAILURE) { - zend_error (E_WARNING, "Unable to find component in the global list of resources"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the global list of resources"); } /* Second argument is mixed data */ @@ -281,7 +281,7 @@ if (call_user_function(EG(function_table), NULL, z_func_name, &retval, 2, args TSRMLS_CC) == SUCCESS ) { zval_dtor(&retval); } else { - zend_error (E_WARNING, "Unable to call user function: %s(component, data)", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: %s(component, data)", cb->func_name); } zval_dtor (z_func_name); zval_dtor (args[0]); @@ -301,7 +301,7 @@ const char *p; if (!cb) { - zend_error (E_ERROR, "Null data has been passed to the newt callback wrapper"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt callback wrapper"); } MAKE_STD_ZVAL (z_func_name); @@ -310,7 +310,7 @@ /* First argument is component resource */ MAKE_STD_ZVAL (args[0]); if (NEWT_GET_RESOURCE_BY_DATA (args[0], entry) == FAILURE) { - zend_error (E_WARNING, "Unable to find component in the global list of resources"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the global list of resources"); } /* Second argument is mixed data */ @@ -330,7 +330,7 @@ if (call_user_function(EG(function_table), NULL, z_func_name, &retval, 4, args TSRMLS_CC) == SUCCESS ) { zval_dtor(&retval); } else { - zend_error (E_WARNING, "Unable to call user function: %s(component, data, ch, cursor)", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: %s(component, data, ch, cursor)", cb->func_name); } zval_dtor (z_func_name); zval_dtor (args[0]); @@ -352,7 +352,7 @@ const char *p; if (!cb) { - zend_error (E_ERROR, "Null data has been passed to the newt callback wrapper"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Null data has been passed to the newt callback wrapper"); } MAKE_STD_ZVAL (z_func_name); @@ -368,7 +368,7 @@ if (call_user_function(EG(function_table), NULL, z_func_name, &retval, 1, args TSRMLS_CC) == SUCCESS ) { zval_dtor(&retval); } else { - zend_error (E_WARNING, "Unable to call user function: %s(data)", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: %s(data)", cb->func_name); } zval_dtor (z_func_name); zval_dtor (args[0]); @@ -392,7 +392,7 @@ /* First argument is component resource */ MAKE_STD_ZVAL (args[0]); if (NEWT_GET_RESOURCE_BY_DATA (args[0], form) == FAILURE) { - zend_error (E_WARNING, "Unable to find component in the global list of resources"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find component in the global list of resources"); } /* Second argument is string */ @@ -402,7 +402,7 @@ if (call_user_function(EG(function_table), NULL, z_func_name, &retval, 2, args TSRMLS_CC) == SUCCESS ) { zval_dtor(&retval); } else { - zend_error (E_WARNING, "Unable to call user function: %s(form, help)", NEWT_G(newt_help_callback)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call user function: %s(form, help)", NEWT_G(newt_help_callback)); } zval_dtor (z_func_name); zval_dtor (args[0]); @@ -410,6 +410,24 @@ } /* }}} */ +/* {{{ + * proto newt_call_php_function + */ +void newt_call_php_function (INTERNAL_FUNCTION_PARAMETERS, const char *func_name, zval **ret_val, int argc, zval ***args) +{ + zval *z_func_name; + + MAKE_STD_ZVAL(z_func_name); + ZVAL_STRING(z_func_name, func_name, 1); + + if (call_user_function_ex(EG(function_table), NULL, z_func_name, ret_val, argc, args, 0, NULL TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "function '%s' not found", Z_STRVAL_P(z_func_name)); + } + zval_dtor(z_func_name); + FREE_ZVAL(z_func_name); +} +/* }}} */ + /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(newt) @@ -770,7 +788,7 @@ cb = emalloc (sizeof(newt_data_st)); if (!zend_is_callable(z_func_name, 0, &cb->func_name)) { - zend_error (E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); efree (cb->func_name); efree (cb); RETURN_NULL(); @@ -806,7 +824,7 @@ } if (!zend_is_callable(z_func_name, 0, &func_name)) { - zend_error (E_ERROR, "First argument is expected to be a valid callback", func_name); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "First argument is expected to be a valid callback", func_name); efree (func_name); RETURN_NULL(); } @@ -989,7 +1007,7 @@ } else { WRONG_PARAM_COUNT; } if (def_val_len != 1) { - zend_error (E_ERROR, "fourth argument must be single character"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "fourth argument must be single character"); } checkbox = newtCheckbox(left, top, text, *def_val, seq, NULL); @@ -1039,7 +1057,7 @@ } if (value_len != 1) { - zend_error (E_ERROR, "second argument must be single character"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "second argument must be single character"); } ZEND_FETCH_RESOURCE(checkbox, newtComponent, &z_checkbox, -1, le_newt_comp_name, le_newt_comp); @@ -1943,7 +1961,7 @@ } if (seqnum_len > 0 && seqnum_len != 1) { - zend_error (E_ERROR, "Second argument must be a single character"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument must be a single character"); } ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name, le_newt_comp); @@ -2088,7 +2106,7 @@ } if (value_len != 1) { - zend_error (E_ERROR, "Third argument must be a single character"); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Third argument must be a single character"); } PHP_VAR_SERIALIZE_INIT(var_hash); @@ -2343,7 +2361,7 @@ newtFormWatchFd (form, fd, flags); } else { - zend_error (E_WARNING, "Could not cast stream to a file descriptor"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream to a file descriptor"); } } /* }}} */ @@ -2713,7 +2731,7 @@ cb = emalloc (sizeof(newt_data_st)); if (!zend_is_callable(z_func_name, 0, &cb->func_name)) { - zend_error (E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); efree (cb->func_name); efree (cb); RETURN_NULL(); @@ -2841,7 +2859,7 @@ cb = emalloc (sizeof(newt_data_st)); if (!zend_is_callable(z_func_name, 0, &cb->func_name)) { - zend_error (E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Second argument is expected to be a valid callback", cb->func_name); efree (cb->func_name); efree (cb); RETURN_NULL(); @@ -3173,16 +3191,59 @@ /* }}} */ /* {{{ + * proto newt_win_message (string title, string button_text, string format [, mixed args [, mixed...]]) */ PHP_FUNCTION(newt_win_message) { + char *title, *button_text, *text; + zval ***args, *z_text = NULL; + + int argc = ZEND_NUM_ARGS(); + if (argc < 3) { WRONG_PARAM_COUNT; } + + args = (zval **) emalloc (sizeof(zval **) * argc); + + if (zend_get_parameters_array_ex (argc, args) == FAILURE) { + return; + } + + title = Z_STRVAL_PP(args[0]); + button_text = Z_STRVAL_PP(args[1]); + + newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "sprintf", &z_text, argc-2, args+2); + + if(z_text) { + text = Z_STRVAL_P(z_text); + } + newtWinMessage (title, button_text, text); + efree (args); } /* }}} */ /* {{{ + * proto newt_win_message (string title, string button_text, string format, array args) */ PHP_FUNCTION(newt_win_messagev) { + char *title, *button_text, *text; + 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) { + return; + } + + title = Z_STRVAL_PP(args[0]); + button_text = Z_STRVAL_PP(args[1]); + + newt_call_php_function (INTERNAL_FUNCTION_PARAM_PASSTHRU, "vsprintf", &z_text, argc-2, args+2); + + if(z_text) { + text = Z_STRVAL_P(z_text); + } + newtWinMessage (title, button_text, text); } /* }}} */ http://cvs.php.net/diff.php/pecl/newt/php_newt.h?r1=1.1.1.1&r2=1.2&ty=u Index: pecl/newt/php_newt.h diff -u pecl/newt/php_newt.h:1.1.1.1 pecl/newt/php_newt.h:1.2 --- pecl/newt/php_newt.h:1.1.1.1 Thu Aug 12 17:30:16 2004 +++ pecl/newt/php_newt.h Sun Aug 15 11:34:16 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_newt.h,v 1.1.1.1 2004/08/12 21:30:16 michael Exp $ */ +/* $Id: php_newt.h,v 1.2 2004/08/15 15:34:16 michael Exp $ */ #include <newt.h> @@ -202,6 +202,7 @@ void newt_entry_filter_callback_wrapper (newtComponent entry, newt_data_st * cb, int ch, int cursor); void newt_suspend_callback_wrapper (newt_data_st * cb); void newt_help_callback_wrapper (newtComponent form, char *help); +void newt_call_php_function (INTERNAL_FUNCTION_PARAMETERS, const char *func_name, zval **ret_val, int argc, zval ***args); #ifdef ZTS #define NEWT_G(v) TSRMG(newt_globals_id, zend_newt_globals *, v)
« previous php.pecl.cvs (#1663) next »