cvs: pecl /newt newt.c
| From: | Michael Spector | Date: | Sun, 22 Aug 2004 19:35:09 +0000 |
| Subject: | cvs: pecl /newt newt.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1701@lists.php.net to get a copy of this message | ||
michael Sun Aug 22 15:35:09 2004 EDT
Modified files:
/pecl/newt newt.c
Log:
* implemented more functions
http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.16&r2=1.17&ty=u
Index: pecl/newt/newt.c
diff -u pecl/newt/newt.c:1.16 pecl/newt/newt.c:1.17
--- pecl/newt/newt.c:1.16 Sun Aug 22 03:08:01 2004
+++ pecl/newt/newt.c Sun Aug 22 15:35:09 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: newt.c,v 1.16 2004/08/22 07:08:01 michael Exp $ */
+/* $Id: newt.c,v 1.17 2004/08/22 19:35:09 michael Exp $ */
#include <newt.h>
@@ -1927,23 +1927,145 @@
*/
PHP_FUNCTION(newt_checkbox_tree_add_item)
{
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "This function is not implemented yet");
+ zval *z_checkboxtree, *z_data, ***args;
+ newtComponent checkboxtree;
+ char * text;
+ int text_len, flags, i;
+ void **newt_args = NULL;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc < 5) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "zszl", &z_checkboxtree, &text, &text_len,
&z_data, &flags) == FAILURE) {
+ return;
+ }
+
+ args = (zval ***) emalloc (sizeof(zval **) * argc);
+ if (zend_get_parameters_array_ex (argc, args) == FAILURE) {
+ efree (args);
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ newt_args = (void **) emalloc (sizeof(void *) * argc);
+ newt_args[0] = (void *)checkboxtree;
+ newt_args[1] = (void *)text;
+ newt_args[2] = (void *)buf.c;
+ newt_args[3] = (void *)flags;
+
+ for (i=4; i<argc; i++) {
+ if (Z_TYPE_PP(args[i]) != IS_LONG) {
+ efree (newt_args);
+ efree (args);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Arguments starting from fifth must be
integers");
+ }
+ newt_args[i] = (void *)Z_LVAL_PP(args[i]);
+ }
+
+ newt_vcall ((void *)newtCheckboxTreeAddItem, newt_args, argc);
+
+ efree (newt_args);
+ efree (args);
}
/* }}} */
/* {{{
- */
+ * proto newt_checkbox_tree_add_item(resource checkboxtree, string text, mixed data, int flags,
array indexes)
+ * */
PHP_FUNCTION(newt_checkbox_tree_add_array)
{
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "This function is not implemented yet");
+ zval *z_checkboxtree, *z_data, *z_indexes, *z_index;
+ newtComponent checkboxtree;
+ char * text;
+ int text_len, flags, *indexes, indexes_num, i;
+ void **newt_args = NULL;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ if (5 != ZEND_NUM_ARGS()) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (5, "zszla", &z_checkboxtree, &text, &text_len,
&z_data, &flags, &z_indexes) == FAILURE) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ indexes_num = zend_hash_num_elements (Z_ARRVAL_P(z_indexes));
+ indexes = (int *) emalloc (sizeof(int) * (indexes_num+1));
+
+ zend_hash_internal_pointer_reset (Z_ARRVAL_P(z_indexes));
+ i=0;
+ while (zend_hash_get_current_data (Z_ARRVAL_P(z_indexes), (void **)&z_index) == SUCCESS) {
+ if (Z_TYPE_P(z_index) != IS_LONG) {
+ efree (indexes);
+ efree (newt_args);
+ php_error_docref (NULL TSRMLS_CC, E_ERROR, "Array must contain integers only");
+ }
+ indexes[i] = Z_LVAL_P(z_index);
+ i++;
+ zend_hash_move_forward(Z_ARRVAL_P(z_indexes));
+ }
+ indexes[i] = NEWT_ARG_LAST;
+
+ newt_args = (void **) emalloc (sizeof(void *) * 5);
+ newt_args[0] = (void *)checkboxtree;
+ newt_args[1] = (void *)text;
+ newt_args[2] = (void *)buf.c;
+ newt_args[3] = (void *)flags;
+ newt_args[4] = (void *)indexes;
+
+ newt_vcall ((void *)newtCheckboxTreeAddArray, newt_args, 5);
+
+ efree (indexes);
+ efree (newt_args);
}
/* }}} */
/* {{{
+ * proto array newt_checkbox_tree_find_item (resource checkboxtree, mixed data)
*/
PHP_FUNCTION(newt_checkbox_tree_find_item)
{
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "This function is not implemented yet");
+ zval *z_checkboxtree, *z_data, *z_val;
+ newtComponent checkboxtree;
+ int *path, i;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ if (2 != ZEND_NUM_ARGS()) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (2, "zz", &z_checkboxtree, &z_data) != FAILURE) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ path = newtCheckboxTreeFindItem (checkboxtree, buf.c);
+
+ array_init (return_value);
+ if (path) {
+ MAKE_STD_ZVAL (z_val);
+ i=0;
+ while (path[i] != NEWT_ARG_LAST) {
+ ZVAL_LONG (z_val, path[i]);
+ zval_add_ref (&z_val);
+ zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), NULL);
+ SEPARATE_ZVAL (&z_val);
+ }
+ free (path);
+ }
}
/* }}} */