cvs: pecl /newt newt.c
| From: | Michael Spector | Date: | Mon, 23 Aug 2004 20:23:11 +0000 |
| Subject: | cvs: pecl /newt newt.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1711@lists.php.net to get a copy of this message | ||
michael Mon Aug 23 16:23:11 2004 EDT
Modified files:
/pecl/newt newt.c
Log:
added function: newt_win_entries (didn't finished)
http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.18&r2=1.19&ty=u
Index: pecl/newt/newt.c
diff -u pecl/newt/newt.c:1.18 pecl/newt/newt.c:1.19
--- pecl/newt/newt.c:1.18 Mon Aug 23 04:43:37 2004
+++ pecl/newt/newt.c Mon Aug 23 16:23:11 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: newt.c,v 1.18 2004/08/23 08:43:37 michael Exp $ */
+/* $Id: newt.c,v 1.19 2004/08/23 20:23:11 michael Exp $ */
#include <newt.h>
@@ -3625,11 +3625,116 @@
/* }}} */
/* {{{
- * proto int newt_win_entries (string title, string text, int suggested_width, int flex_down, int
flex_up, int data_width, struct newtWinEntry * items, char * button1, ...
+ * proto int newt_win_entries (string title, string text, int suggested_width, int flex_down, int
flex_up, int data_width, array items, string button1 [, string button2 [,...]])
*/
PHP_FUNCTION(newt_win_entries)
{
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "This function is not implemented yet");
+ char *title, *text;
+ int title_len, text_len, suggested_width, flex_down, flex_up, data_width;
+ zval ***args, *z_items, **z_item;
+ void **newt_args = NULL;
+ struct newtWinEntry *items = NULL;
+ int num_items, i;
+ char **buttons = NULL;
+ int num_buttons;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+ int rc;
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc < 8) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (7, "sslllla", &title, &title_len, &text,
&text_len,
+ &suggested_width, &flex_down, &flex_up, &data_width, &z_items) == FAILURE)
{
+ return;
+ }
+
+ args = (zval ***) emalloc (sizeof(zval **) * argc);
+ if (zend_get_parameters_array_ex (argc, args) == FAILURE) {
+ efree (args);
+ return;
+ }
+
+ num_items = zend_hash_num_elements (Z_ARRVAL_P(z_items));
+ items = (struct newtWinEntry *) emalloc (sizeof(struct newtWinEntry) * (num_items+1));
+
+ zend_hash_internal_pointer_reset (Z_ARRVAL_P(z_items));
+ i=0;
+ PHP_VAR_SERIALIZE_INIT (var_hash);
+
+ while (zend_hash_get_current_data (Z_ARRVAL_P(z_items), (void **)&z_item) == SUCCESS) {
+ zval **z_item_text, **z_item_value, **z_item_flags;
+
+ if(Z_TYPE_PP(z_item) != IS_ARRAY) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Seventh argument must be array containing
arrays");
+ }
+ if(zend_hash_find (Z_ARRVAL_PP(z_item), "text", sizeof("text"), (void
**)&z_item_text) == FAILURE) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Sub-array must have key:
\"text\"");
+ }
+ if(zend_hash_find (Z_ARRVAL_PP(z_item), "value", sizeof("value"), (void
**)&z_item_value) == FAILURE) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Sub-array must have key:
\"value\"");
+ }
+ if(zend_hash_find (Z_ARRVAL_PP(z_item), "flags", sizeof("flags"), (void
**)&z_item_flags) == FAILURE) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Sub-array must have key:
\"flags\"");
+ }
+
+ if(Z_TYPE_PP(z_item_text) != IS_STRING) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Value associated with key: \"text\"
must be string");
+ }
+ if(Z_TYPE_PP(z_item_flags) != IS_LONG) {
+ efree (args);
+ efree (items);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Value associated with key: \"flags\"
must be integer");
+ }
+
+ items[i].text = Z_STRVAL_PP(z_item_text);
+ php_var_serialize(&buf, z_item_value, &var_hash TSRMLS_CC);
+ items[i].value = &buf.c;
+ items[i].flags = Z_LVAL_PP(z_item_flags);
+
+ i++;
+ zend_hash_move_forward(Z_ARRVAL_P(z_items));
+ }
+ PHP_VAR_SERIALIZE_DESTROY (var_hash);
+ items[i].text = NULL; // original function finished processing items on null text entry
+
+ newt_args = (void **) emalloc (sizeof(void *) * argc);
+ newt_args[0] = (void *)title;
+ newt_args[1] = (void *)text;
+ newt_args[2] = (void *)suggested_width;
+ newt_args[3] = (void *)flex_down;
+ newt_args[4] = (void *)flex_up;
+ newt_args[5] = (void *)data_width;
+ newt_args[6] = (void *)items;
+
+ for(i=7; i<argc; i++) {
+ if(Z_TYPE_PP(args[i]) != IS_STRING) {
+ efree (args);
+ efree (items);
+ efree (newt_args);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Arguments starting from eighth must be
strings");
+ }
+ newt_args[7] = (void *)Z_STRVAL_PP(args[i]);
+ }
+
+ rc = (int)newt_vcall ((void *)newtWinEntries, newt_args, argc);
+
+ /* FIXME: return back all values passed by reference in a structure */
+
+ efree (args);
+ efree (items);
+ efree (newt_args);
+
+ RETURN_LONG (rc);
}
/* }}} */