Commit 41d82db0 authored by Jody Goldberg's avatar Jody Goldberg

cleanup the function categories

parent 23c3803d
......@@ -135,12 +135,12 @@ register_function(name, args, named_args, help, subref)
SV *subref
PREINIT:
FunctionCategory *fncat;
GnmFuncGroup *fncat;
GnmFuncDescriptor desc;
GnmFunc *func;
CODE:
fncat = function_get_category ("Perl plugin");
fncat = gnm_func_group_fetch ("Perl plugin");
desc.fn_name = name;
desc.args = args;;
desc.arg_names = named_args;
......
......@@ -194,7 +194,7 @@ dialog_function_select_load_tree (FunctionSelectState *state)
{
int i = 0;
GtkTreeIter p_iter;
FunctionCategory const * cat;
GnmFuncGroup const * cat;
gtk_tree_store_clear (state->model);
......@@ -204,7 +204,7 @@ dialog_function_select_load_tree (FunctionSelectState *state)
CATEGORY, NULL,
-1);
while ((cat = function_category_get_nth (i++)) != NULL) {
while ((cat = gnm_func_group_get_nth (i++)) != NULL) {
gtk_tree_store_append (state->model, &p_iter, NULL);
gtk_tree_store_set (state->model, &p_iter,
CAT_NAME, _(cat->display_name->str),
......@@ -332,7 +332,7 @@ cb_dialog_function_select_cat_selection_changed (GtkTreeSelection *the_selection
{
GtkTreeIter iter;
GtkTreeModel *model;
FunctionCategory const * cat;
GnmFuncGroup const * cat;
GList *funcs, *this_func;
gtk_list_store_clear (state->model_f);
......
......@@ -134,28 +134,28 @@ func_builtin_init (void)
static GnmFuncDescriptor const builtins [] = {
{ "sum", NULL, N_("number,number,"),
&help_sum, NULL, gnumeric_sum,
NULL, NULL, NULL, 0,
NULL, NULL, NULL, GNM_FUNC_SIMPLE,
GNM_FUNC_IMPL_STATUS_COMPLETE,
GNM_FUNC_TEST_STATUS_BASIC
},
{ "product", NULL, N_("number,number,"),
&help_product, NULL, gnumeric_product,
NULL, NULL, NULL, 0,
NULL, NULL, NULL, GNM_FUNC_SIMPLE,
GNM_FUNC_IMPL_STATUS_COMPLETE,
GNM_FUNC_TEST_STATUS_BASIC
},
{ "gnumeric_version", "", "",
&help_gnumeric_version, gnumeric_version, NULL,
NULL, NULL, NULL, 0,
GNM_FUNC_IMPL_STATUS_COMPLETE,
GNM_FUNC_TEST_STATUS_BASIC
&help_gnumeric_version, gnumeric_version,
NULL, NULL, NULL, NULL, GNM_FUNC_SIMPLE,
GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
GNM_FUNC_TEST_STATUS_EXHAUSTIVE
},
{ NULL }
};
GnmFunc *func;
FunctionCategory *mathcat = function_get_category (mathcatname);
FunctionCategory *gnumericcat = function_get_category (gnumericcatname);
GnmFuncGroup *mathcat = gnm_func_group_fetch (mathcatname);
GnmFuncGroup *gnumericcat = gnm_func_group_fetch (gnumericcatname);
func = gnm_func_add (mathcat, builtins + 0);
auto_format_function_result (func, AF_FIRST_ARG_FORMAT);
......@@ -172,7 +172,7 @@ static void
shutdown_cat (const char *catname, GSList **funcs)
{
GSList *tmp;
FunctionCategory *cat = function_get_category (catname);
GnmFuncGroup *cat = gnm_func_group_fetch (catname);
for (tmp = *funcs; tmp; tmp = tmp->next) {
GnmFunc *def = tmp->data;
......
......@@ -36,7 +36,7 @@
static GList *categories;
static SymbolTable *global_symbol_table;
static FunctionCategory *unknown_cat;
static GnmFuncGroup *unknown_cat;
static GSList *unknown_functions;
void
......@@ -82,6 +82,12 @@ func_def_cmp (gconstpointer a, gconstpointer b)
g_return_val_if_fail (fda->name != NULL, 0);
g_return_val_if_fail (fdb->name != NULL, 0);
if (fda->fn_group != NULL && fdb->fn_group != NULL) {
int res = strcmp (fda->fn_group->display_name->str, fdb->fn_group->display_name->str);
if (res != 0)
return res;
}
return g_ascii_strcasecmp (fda->name, fdb->name);
}
......@@ -91,6 +97,7 @@ function_dump_defs (char const *filename, gboolean as_def)
FILE *output_file;
unsigned i;
GPtrArray *ordered;
GnmFuncGroup const *group = NULL;
g_return_if_fail (filename != NULL);
......@@ -99,7 +106,7 @@ function_dump_defs (char const *filename, gboolean as_def)
exit (1);
}
/* TODO : Use the translated names and split by category. */
/* TODO : Use the translated names and split by fn_group. */
ordered = g_ptr_array_new ();
g_hash_table_foreach (global_symbol_table->hash,
copy_hash_table_to_ptr_array, ordered);
......@@ -139,8 +146,13 @@ function_dump_defs (char const *filename, gboolean as_def)
{ "Under development", "FF6C00" },
{ "Unique to Gnumeric", "44BE18" },
};
if (group != fd->fn_group) {
group = fd->fn_group;
fprintf (output_file, "<tr><td><h1>%s</h1></td></tr>\n", group->display_name->str);
}
fprintf (output_file, "<tr><td></td>\n");
fprintf (output_file,
"<tr>\n <td><a href =\"doc/gnumeric-%s.html\">%s</a></td>\n", fd->name, fd->name);
" <td><a href =\"doc/gnumeric-%s.html\">%s</a></td>\n", fd->name, fd->name);
fprintf (output_file,
" <td bgcolor=#%s><a href=\"mailto:gnumeric-list@gnome.org?subject=Re: %s implementation\">%s</a></td>\n",
implementation[fd->impl_status].colour_str, fd->name, implementation[fd->impl_status].name);
......@@ -159,11 +171,22 @@ testing[fd->test_status].colour_str, fd->name, testing[fd->test_status].name);
/* ------------------------------------------------------------------------- */
static void
gnm_func_group_free (GnmFuncGroup *fn_group)
{
g_return_if_fail (fn_group != NULL);
g_return_if_fail (fn_group->functions == NULL);
string_unref (fn_group->internal_name);
string_unref (fn_group->display_name);
g_free (fn_group);
}
static gint
function_category_compare (gconstpointer a, gconstpointer b)
{
FunctionCategory const *cat_a = a;
FunctionCategory const *cat_b = b;
GnmFuncGroup const *cat_a = a;
GnmFuncGroup const *cat_b = b;
char *str_a, *str_b;
g_return_val_if_fail (cat_a->display_name != NULL, 0);
......@@ -182,17 +205,17 @@ function_category_compare (gconstpointer a, gconstpointer b)
return strcoll (str_a, str_b);
}
FunctionCategory *
function_get_category (char const *name)
GnmFuncGroup *
gnm_func_group_fetch (char const *name)
{
return function_get_category_with_translation (name, _(name));
return gnm_func_group_fetch_with_translation (name, _(name));
}
FunctionCategory *
function_get_category_with_translation (char const *name,
GnmFuncGroup *
gnm_func_group_fetch_with_translation (char const *name,
char const *translation)
{
FunctionCategory *cat = NULL;
GnmFuncGroup *cat = NULL;
char *int_name;
GList *l;
......@@ -208,7 +231,7 @@ function_get_category_with_translation (char const *name,
}
if (l == NULL) {
cat = g_new (FunctionCategory, 1);
cat = g_new (GnmFuncGroup, 1);
cat->internal_name = string_get (int_name);
if (translation != NULL) {
cat->display_name = string_get (translation);
......@@ -234,44 +257,32 @@ function_get_category_with_translation (char const *name,
return cat;
}
FunctionCategory *
function_category_get_nth (int n)
GnmFuncGroup *
gnm_func_group_get_nth (int n)
{
return g_list_nth_data (categories, n);
}
void
function_category_add_func (FunctionCategory *category,
GnmFunc *fn_def)
{
g_return_if_fail (category != NULL);
g_return_if_fail (fn_def != NULL);
category->functions = g_list_append (category->functions, fn_def);
}
static void
function_category_free (FunctionCategory *category)
gnm_func_group_add_func (GnmFuncGroup *fn_group,
GnmFunc *fn_def)
{
g_return_if_fail (category != NULL);
g_return_if_fail (category->functions == NULL);
g_return_if_fail (fn_group != NULL);
g_return_if_fail (fn_def != NULL);
string_unref (category->internal_name);
string_unref (category->display_name);
g_free (category);
fn_group->functions = g_list_append (fn_group->functions, fn_def);
}
void
function_category_remove_func (FunctionCategory *category,
GnmFunc *fn_def)
gnm_func_group_remove_func (GnmFuncGroup *fn_group, GnmFunc *func)
{
g_return_if_fail (category != NULL);
g_return_if_fail (fn_def != NULL);
g_return_if_fail (fn_group != NULL);
g_return_if_fail (func != NULL);
category->functions = g_list_remove (category->functions, fn_def);
if (category->functions == NULL) {
categories = g_list_remove (categories, category);
function_category_free (category);
fn_group->functions = g_list_remove (fn_group->functions, func);
if (fn_group->functions == NULL) {
categories = g_list_remove (categories, fn_group);
gnm_func_group_free (fn_group);
}
}
......@@ -368,7 +379,7 @@ gnm_func_lookup (char const *name, Workbook const *optional_scope)
}
void
function_remove (FunctionCategory *category, char const *name)
function_remove (GnmFuncGroup *fn_group, char const *name)
{
GnmFunc *func;
Symbol *sym;
......@@ -379,7 +390,7 @@ function_remove (FunctionCategory *category, char const *name)
g_return_if_fail (func->ref_count == 0);
function_category_remove_func (category, func);
gnm_func_group_remove_func (fn_group, func);
sym = symbol_lookup (global_symbol_table, name);
symbol_unref (sym);
......@@ -399,14 +410,14 @@ function_add_args
function_add_nodes
#endif
GnmFunc *
gnm_func_add (FunctionCategory *category,
gnm_func_add (GnmFuncGroup *fn_group,
GnmFuncDescriptor const *desc)
{
static char const valid_tokens[] = "fsbraAES?|";
GnmFunc *func;
char const *ptr;
g_return_val_if_fail (category != NULL, NULL);
g_return_val_if_fail (fn_group != NULL, NULL);
g_return_val_if_fail (desc != NULL, NULL);
func = g_new (GnmFunc, 1);
......@@ -450,8 +461,9 @@ gnm_func_add (FunctionCategory *category,
return NULL;
}
if (category != NULL)
function_category_add_func (category, func);
func->fn_group = fn_group;
if (fn_group != NULL)
gnm_func_group_add_func (fn_group, func);
symbol_install (global_symbol_table, func->name, SYMBOL_FUNCTION, func);
return func;
......@@ -465,7 +477,7 @@ unknownFunctionHandler (FunctionEvalInfo *ei, GnmExprList *expr_node_list)
}
GnmFunc *
gnm_func_add_stub (FunctionCategory *category,
gnm_func_add_stub (GnmFuncGroup *fn_group,
char const *name,
GnmFuncLoadDesc load_desc,
GnmFuncRefNotify opt_ref_notify)
......@@ -479,8 +491,9 @@ gnm_func_add_stub (FunctionCategory *category,
func->fn_type = GNM_FUNC_TYPE_STUB;
func->fn.load_desc = load_desc;
if (category != NULL)
function_category_add_func (category, func);
func->fn_group = fn_group;
if (fn_group != NULL)
gnm_func_group_add_func (fn_group, func);
symbol_install (global_symbol_table, func->name, SYMBOL_FUNCTION, func);
return func;
......@@ -505,7 +518,7 @@ gnm_func_add_placeholder (char const *name, char const *type,
g_return_val_if_fail (func == NULL, func);
if (!unknown_cat)
unknown_cat = function_get_category (unknown_cat_name);
unknown_cat = gnm_func_group_fetch (unknown_cat_name);
memset (&desc, 0, sizeof (GnmFuncDescriptor));
desc.name = copy_name ? g_strdup (name) : name;
......@@ -546,16 +559,16 @@ gnm_func_set_user_data (GnmFunc *func, gpointer user_data)
}
char const *
gnm_func_get_name (GnmFunc const *fn_def)
gnm_func_get_name (GnmFunc const *func)
{
g_return_val_if_fail (fn_def != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
return fn_def->name;
return func->name;
}
/**
* function_def_count_args:
* @fn_def: pointer to function definition
* @func: pointer to function definition
* @min: pointer to min. args
* @max: pointer to max. args
*
......
......@@ -12,21 +12,19 @@ void functions_shutdown (void);
void function_dump_defs (char const *filename, gboolean def_or_state);
/******************************************************************************/
/* Function category support */
/* Function group support */
typedef struct _FunctionCategory FunctionCategory;
struct _FunctionCategory {
typedef struct _GnmFuncGroup GnmFuncGroup;
struct _GnmFuncGroup {
String *internal_name, *display_name;
gboolean has_translation;
GList *functions;
};
FunctionCategory *function_get_category (char const *name);
FunctionCategory *function_get_category_with_translation (char const *name,
char const *translation);
FunctionCategory *function_category_get_nth (gint n);
void function_category_add_func (FunctionCategory *, GnmFunc *);
void function_category_remove_func (FunctionCategory *category, GnmFunc *fn_def);
GnmFuncGroup *gnm_func_group_get_nth (gint n);
GnmFuncGroup *gnm_func_group_fetch (char const *name);
GnmFuncGroup *gnm_func_group_fetch_with_translation (char const *name,
char const *translation);
/******************************************************************************/
......@@ -150,15 +148,16 @@ struct _GnmFunc {
} args;
GnmFuncLoadDesc load_desc;
} fn;
GnmFuncLink linker;
GnmFuncUnlink unlinker;
GnmFuncRefNotify ref_notify;
GnmFuncImplStatus impl_status;
GnmFuncTestStatus test_status;
GnmFuncFlags flags;
gint ref_count;
gpointer user_data;
GnmFuncGroup *fn_group; /* most recent it was assigned to */
GnmFuncLink linker;
GnmFuncUnlink unlinker;
GnmFuncRefNotify ref_notify;
GnmFuncImplStatus impl_status;
GnmFuncTestStatus test_status;
GnmFuncFlags flags;
gint ref_count;
gpointer user_data;
};
struct _FunctionEvalInfo {
......@@ -173,9 +172,9 @@ char const *gnm_func_get_name (GnmFunc const *fn_def);
gpointer gnm_func_get_user_data (GnmFunc const *func);
void gnm_func_set_user_data (GnmFunc *func, gpointer user_data);
GnmFunc *gnm_func_lookup (char const *name, Workbook const *scope);
GnmFunc *gnm_func_add (FunctionCategory *category,
GnmFunc *gnm_func_add (GnmFuncGroup *group,
GnmFuncDescriptor const *descriptor);
GnmFunc *gnm_func_add_stub (FunctionCategory *category,
GnmFunc *gnm_func_add_stub (GnmFuncGroup *group,
char const *name,
GnmFuncLoadDesc load_desc,
GnmFuncRefNotify opt_ref_notify);
......@@ -183,7 +182,7 @@ GnmFunc *gnm_func_add_placeholder (char const *name, char const *type,
gboolean copy_name);
/* TODO */
void function_remove (FunctionCategory *category,
void function_remove (GnmFuncGroup *group,
char const *name);
void function_def_count_args (GnmFunc const *fn_def,
......
......@@ -941,7 +941,7 @@ struct _PluginServiceFunctionGroup {
gchar *category_name, *translated_category_name;
GSList *function_name_list;
FunctionCategory *category;
GnmFuncGroup *func_group;
PluginServiceFunctionGroupCallbacks cbs;
};
......@@ -955,7 +955,7 @@ plugin_service_function_group_init (GObject *obj)
service_function_group->category_name = NULL;
service_function_group->translated_category_name = NULL;
service_function_group->function_name_list = NULL;
service_function_group->category = NULL;
service_function_group->func_group = NULL;
}
static void
......@@ -1094,14 +1094,14 @@ plugin_service_function_group_activate (PluginService *service, ErrorInfo **ret_
PluginServiceFunctionGroup *service_function_group = GNM_PLUGIN_SERVICE_FUNCTION_GROUP (service);
GNM_INIT_RET_ERROR_INFO (ret_error);
service_function_group->category = function_get_category_with_translation (
service_function_group->func_group = gnm_func_group_fetch_with_translation (
service_function_group->category_name,
service_function_group->translated_category_name);
GNM_SLIST_FOREACH (service_function_group->function_name_list, char, fname,
GnmFunc *fn_def;
fn_def = gnm_func_add_stub (
service_function_group->category, fname,
service_function_group->func_group, fname,
plugin_service_function_group_func_desc_load,
plugin_service_function_group_func_ref_notify);
gnm_func_set_user_data (fn_def, service);
......@@ -1116,7 +1116,7 @@ plugin_service_function_group_deactivate (PluginService *service, ErrorInfo **re
GNM_INIT_RET_ERROR_INFO (ret_error);
GNM_SLIST_FOREACH (service_function_group->function_name_list, char, fname,
function_remove (service_function_group->category, fname);
function_remove (service_function_group->func_group, fname);
);
service->is_active = FALSE;
}
......
......@@ -28,6 +28,7 @@
#include "workbook-view.h"
#include "workbook.h"
#include "sheet.h"
#include "sheet-view.h"
#include "selection.h"
#include "commands.h"
#include "value.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment