cvs: pecl /newt newt.c
| From: | Michael Spector | Date: | Fri, 13 Aug 2004 12:59:40 +0000 |
| Subject: | cvs: pecl /newt newt.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1641@lists.php.net to get a copy of this message | ||
michael Fri Aug 13 08:59:40 2004 EDT
Modified files:
/pecl/newt newt.c
Log:
added functions
http://cvs.php.net/diff.php/pecl/newt/newt.c?r1=1.3&r2=1.4&ty=u
Index: pecl/newt/newt.c
diff -u pecl/newt/newt.c:1.3 pecl/newt/newt.c:1.4
--- pecl/newt/newt.c:1.3 Fri Aug 13 08:08:09 2004
+++ pecl/newt/newt.c Fri Aug 13 08:59:40 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: newt.c,v 1.3 2004/08/13 12:08:09 michael Exp $ */
+/* $Id: newt.c,v 1.4 2004/08/13 12:59:40 michael Exp $ */
#include <newt.h>
@@ -340,7 +340,7 @@
/* }}} */
/* {{{
- * proto newt_entry_filter_callback_wrapper (newtComponent entry, void * data, int ch, int cursor)
+ * proto newt_suspend_callback_wrapper (void * data)
*/
void newt_suspend_callback_wrapper (newt_data_st * cb)
{
@@ -1005,7 +1005,7 @@
{
zval * z_checkbox;
newtComponent checkbox;
- char ret_value[1];
+ char ret_value[2];
int argc = ZEND_NUM_ARGS();
if (argc != 1) { WRONG_PARAM_COUNT; }
@@ -1015,7 +1015,8 @@
ZEND_FETCH_RESOURCE(checkbox, newtComponent, &z_checkbox, -1, le_newt_comp_name,
le_newt_comp);
- *ret_value = newtCheckboxGetValue(checkbox);
+ ret_value[0] = newtCheckboxGetValue(checkbox);
+ ret_value[1] = '\0';
RETURN_STRING(ret_value, 1);
}
/* }}} */
@@ -1824,30 +1825,144 @@
/* }}} */
/* {{{
+ * proto array newt_checkbox_tree_get_selection (resource checkboxtree)
*/
PHP_FUNCTION(newt_checkbox_tree_get_selection)
{
+ zval * z_checkboxtree;
+ newtComponent checkboxtree;
+ char **retval;
+ zval * z_val;
+ int num_items;
+ php_unserialize_data_t var_hash;
+ int i;
+ const char *p;
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 1) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "z", &z_checkboxtree) == FAILURE) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+ retval = (char **)newtCheckboxTreeGetSelection (checkboxtree, &num_items);
+
+ array_init (return_value);
+ MAKE_STD_ZVAL (z_val);
+
+ if (retval) {
+ PHP_VAR_UNSERIALIZE_INIT (var_hash);
+ for (i=0; i < num_items; i++ ) {
+ p = retval[i];
+ php_var_unserialize(&z_val, &p, p + strlen(p), &var_hash TSRMLS_CC);
+ zval_add_ref (&z_val);
+ zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), NULL);
+ SEPARATE_ZVAL (&z_val);
+ }
+ PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+ free (retval);
+ }
}
/* }}} */
/* {{{
+ * proto mixed newt_checkbox_tree_get_current (resource checkboxtree)
*/
PHP_FUNCTION(newt_checkbox_tree_get_current)
{
+ zval * z_checkboxtree;
+ newtComponent checkboxtree;
+ php_unserialize_data_t var_hash;
+ const char *current;
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 1) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "z", &z_checkboxtree) == FAILURE) {
+ return;
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+ current = (char *)newtCheckboxTreeGetCurrent (checkboxtree);
+
+ if (current) {
+ PHP_VAR_UNSERIALIZE_INIT (var_hash);
+ php_var_unserialize(&return_value, ¤t, current + strlen(current), &var_hash
TSRMLS_CC);
+ PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+ }
}
/* }}} */
/* {{{
+ * proto newt_checkbox_tree_set_current (resource checkboxtree, mixed data)
*/
PHP_FUNCTION(newt_checkbox_tree_set_current)
{
+ zval * z_checkboxtree, * z_data;
+ newtComponent checkboxtree;
+ char * data = NULL;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 2) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "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);
+
+ newtCheckboxTreeSetCurrent (checkboxtree, buf.c);
}
/* }}} */
/* {{{
+ * proto array newt_checkbox_tree_get_multi_selection (resource checkboxtree, string seqnum)
*/
PHP_FUNCTION(newt_checkbox_tree_get_multi_selection)
{
+ zval * z_checkboxtree;
+ newtComponent checkboxtree;
+ char **retval;
+ zval * z_val;
+ int num_items;
+ php_unserialize_data_t var_hash;
+ int i;
+ const char *p;
+ char * seqnum = NULL;
+ int seqnum_len;
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 2) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "zs!", &z_checkboxtree, &seqnum,
&seqnum_len) == FAILURE) {
+ return;
+ }
+
+ if (seqnum_len > 0 && seqnum_len != 1) {
+ zend_error (E_ERROR, "Second argument must be a single character");
+ }
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+ retval = (char **)newtCheckboxTreeGetMultiSelection (checkboxtree, &num_items, (seqnum ?
*seqnum : 0));
+
+ array_init (return_value);
+ MAKE_STD_ZVAL (z_val);
+
+ if (retval) {
+ PHP_VAR_UNSERIALIZE_INIT (var_hash);
+ for (i=0; i < num_items; i++ ) {
+ p = retval[i];
+ php_var_unserialize(&z_val, &p, p + strlen(p), &var_hash TSRMLS_CC);
+ zval_add_ref (&z_val);
+ zend_hash_next_index_insert (Z_ARRVAL_P(return_value), &z_val, sizeof(zval *), NULL);
+ SEPARATE_ZVAL (&z_val);
+ }
+ PHP_VAR_UNSERIALIZE_DESTROY (var_hash);
+ free (retval);
+ }
}
/* }}} */
@@ -1923,16 +2038,64 @@
/* }}} */
/* {{{
+ * proto string newt_checkbox_tree_get_entry_value (resource checkboxtree, mixed data)
*/
PHP_FUNCTION(newt_checkbox_tree_get_entry_value)
{
+ zval * z_checkboxtree;
+ newtComponent checkboxtree;
+ zval * z_data;
+ char ret_value[2];
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 2) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "zz!", &z_checkboxtree, &z_data) == FAILURE) {
+ return;
+ }
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+ ret_value[0] = newtCheckboxTreeGetEntryValue (checkboxtree, buf.c);
+ ret_value[1] = '\0';
+
+ RETURN_STRING (ret_value, 1);
}
/* }}} */
/* {{{
+ * proto newt_checkbox_tree_set_entry_value (resource checkboxtree, mixed data, string value)
*/
PHP_FUNCTION(newt_checkbox_tree_set_entry_value)
{
+ zval * z_checkboxtree;
+ newtComponent checkboxtree;
+ zval * z_data;
+ char * value;
+ int value_len;
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ int argc = ZEND_NUM_ARGS();
+ if (argc != 3) { WRONG_PARAM_COUNT; }
+ if (zend_parse_parameters (argc, "zz!s", &z_checkboxtree, &z_data, &value,
&value_len) == FAILURE) {
+ return;
+ }
+
+ if (value_len != 1) {
+ zend_error (E_ERROR, "Third argument must be a single character");
+ }
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &z_data, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ ZEND_FETCH_RESOURCE(checkboxtree, newtComponent, &z_checkboxtree, -1, le_newt_comp_name,
le_newt_comp);
+ newtCheckboxTreeSetEntryValue (checkboxtree, buf.c, *value);
}
/* }}} */