[gnumeric] Add new function ARRAY. [#570689]



commit 425aadada98e90f16f4eacb707ddde3ffc39578f
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jul 11 16:21:39 2010 -0600

    Add new function ARRAY. [#570689]
    
    2010-07-11  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* plugins/fn-lookup/plugin.xml.in: new function ARRAY
    	* plugins/fn-lookup/functions.c (help_array): new
    	(gnumeric_array): new
    	(callback_function_array): new
    	(lookup_functions): add new function ARRAY

 NEWS                            |    1 +
 plugins/fn-lookup/ChangeLog     |    8 +++++
 plugins/fn-lookup/functions.c   |   59 +++++++++++++++++++++++++++++++++++++++
 plugins/fn-lookup/plugin.xml.in |    1 +
 4 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 2db9e5d..ed7dd78 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ Andreas:
 	* Add menu item to autofit column width or row height based on the 
 	  selection only. [#125595]
 	* Add autofit actions to cell context menu.
+	* Add new function ARRAY. [#570689]
 
 Jean:
 	* Fix strong/weak cursor display. [#623241]
diff --git a/plugins/fn-lookup/ChangeLog b/plugins/fn-lookup/ChangeLog
index e5114af..1e7ef46 100644
--- a/plugins/fn-lookup/ChangeLog
+++ b/plugins/fn-lookup/ChangeLog
@@ -1,3 +1,11 @@
+2010-07-11  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* plugins/fn-lookup/plugin.xml.in: new function ARRAY
+	* plugins/fn-lookup/functions.c (help_array): new
+	(gnumeric_array): new
+	(callback_function_array): new
+	(lookup_functions): add new function ARRAY
+
 2010-06-28  Morten Welinder <terra gnome org>
 
 	* Release 1.10.7
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 9d9c989..611a5e8 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -30,6 +30,7 @@
 #include <parse-util.h>
 #include <dependent.h>
 #include <cell.h>
+#include <collect.h>
 #include <sheet.h>
 #include <value.h>
 #include <ranges.h>
@@ -1696,6 +1697,61 @@ gnumeric_transpose (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 }
 
 /***************************************************************************/
+static GnmFuncHelp const help_array[] = {
+        { GNM_FUNC_HELP_NAME, F_("ARRAY:vertical array of the arguments")},
+        { GNM_FUNC_HELP_ARG, F_("v:value")},
+        { GNM_FUNC_HELP_SEEALSO, "TRANSPOSE"},
+        { GNM_FUNC_HELP_END}
+};
+
+
+static GnmValue *
+callback_function_array (GnmEvalPos const *ep, GnmValue const *value, void *closure)
+{
+	GSList **list = closure;
+
+	*list = g_slist_prepend (*list, value_dup (value));
+	return NULL;
+}
+
+static GnmValue *
+gnumeric_array (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
+{
+	GSList *list = NULL, *l;
+	int len, i;
+	GnmValue *val = function_iterate_argument_values 
+		(ei->pos, callback_function_array, &list,
+		 argc, argv, FALSE, CELL_ITER_ALL);
+
+	if (val != NULL) {
+		go_slist_free_custom (list, (GFreeFunc) value_release);
+		return val;
+	}
+	list = g_slist_reverse (list);
+	len = g_slist_length (list);
+
+	if (len == 0) {
+		go_slist_free_custom (list, (GFreeFunc) value_release);
+		return value_new_error_VALUE (ei->pos);
+	}
+		
+	if (len == 1) {
+		val = list->data;
+		g_slist_free (list);
+		return val;
+	}
+
+	val = value_new_array_empty (1, len);
+	
+	for (l = list, i = 0; l != NULL; l = l->next, i++)
+		val->v_array.vals[0][i] = l->data;
+
+	g_slist_free (list);
+	return val;
+}
+
+
+/***************************************************************************/
 
 GnmFuncDescriptor const lookup_functions[] = {
 	{ "address",   "ff|fbs",
@@ -1755,6 +1811,9 @@ GnmFuncDescriptor const lookup_functions[] = {
 	{ "vlookup",   "EAf|bb",
 	  help_vlookup, gnumeric_vlookup, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+	{ "array", NULL,
+	  help_array, NULL, gnumeric_array, NULL, NULL, NULL,
+	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 
         {NULL}
 };
diff --git a/plugins/fn-lookup/plugin.xml.in b/plugins/fn-lookup/plugin.xml.in
index 99e7b62..dca7763 100644
--- a/plugins/fn-lookup/plugin.xml.in
+++ b/plugins/fn-lookup/plugin.xml.in
@@ -13,6 +13,7 @@
 			<functions textdomain="gnumeric-functions">
 				<function name="address"/>
 				<function name="areas"/>
+				<function name="array"/>
 				<function name="choose"/>
 				<function name="column"/>
 				<function name="columnnumber"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]