Commit 4a4bce21 authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

Start with function name adjustments on ODF export

2009-06-17 Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* openoffice-read.c (oo_func_map_in): handle ORG.GNUMERIC. prefix
	* openoffice-write.c (odf_expr_func_handler): new
	(odf_expr_conventions_new): hook up odf_expr_func_handler

2009-06-17  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* src/expr.h (gnm_expr_list_as_string): new
	* src/expr.h (gnm_expr_list_as_string): make non-static
	(do_expr_as_string): use convs->output.func
	* src/parse-util.h (_GnmConventions): add func field
	* src/parse-util.c (std_expr_func_handler): new
	(gnm_conventions_new_full): initialize func field
parent d1314393
2009-06-17 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/expr.h (gnm_expr_list_as_string): new
* src/expr.h (gnm_expr_list_as_string): make non-static
(do_expr_as_string): use convs->output.func
* src/parse-util.h (_GnmConventions): add func field
* src/parse-util.c (std_expr_func_handler): new
(gnm_conventions_new_full): initialize func field
2009-06-17 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/commands.c (cmd_define_name_undo): we have to update the
......
2009-06-17 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* openoffice-read.c (oo_func_map_in): handle ORG.GNUMERIC. prefix
* openoffice-write.c (odf_expr_func_handler): new
(odf_expr_conventions_new): hook up odf_expr_func_handler
2009-06-16 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* openoffice-read.c (odf_annotation_start): new
......
......@@ -3610,6 +3610,7 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
{ NULL, NULL }
};
static char const OOoAnalysisPrefix[] = "com.sun.star.sheet.addin.Analysis.get";
static char const GnumericPrefix[] = "ORG.GNUMERIC.";
static GHashTable *namemap = NULL;
GnmFunc *f;
......@@ -3626,8 +3627,9 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
(gchar *) sc_func_renames[i].oo_name,
(gchar *) sc_func_renames[i].gnm_name);
}
if (0 != strncmp (name, OOoAnalysisPrefix, sizeof (OOoAnalysisPrefix)-1)) {
if (0 == strncmp (name, GnumericPrefix, sizeof (GnumericPrefix)-1)) {
f = gnm_func_lookup (name+sizeof (GnumericPrefix)-1, scope);
} else if (0 != strncmp (name, OOoAnalysisPrefix, sizeof (OOoAnalysisPrefix)-1)) {
if (NULL != namemap &&
NULL != (new_name = g_hash_table_lookup (namemap, name)))
name = new_name;
......
......@@ -1262,6 +1262,50 @@ odf_rangeref_as_string (GnmConventionsOut *out, GnmRangeRef const *ref)
g_string_append (out->accum, "]");
}
static void
odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
{
static struct {
char const *gnm_name;
char const *odf_name;
} const sc_func_renames[] = {
{ "CEIL", "CEILING" },
{ "SSMEDIAN", "ORG.GNUMERIC.SSMEDIAN" },
{ NULL, NULL }
};
static GHashTable *namemap = NULL;
char const *name = gnm_func_get_name (func->func);
char const *new_name;
GString *target = out->accum;
if (NULL == namemap) {
guint i;
namemap = g_hash_table_new (go_ascii_strcase_hash,
go_ascii_strcase_equal);
for (i = 0; sc_func_renames[i].gnm_name; i++)
g_hash_table_insert (namemap,
(gchar *) sc_func_renames[i].gnm_name,
(gchar *) sc_func_renames[i].odf_name);
}
new_name = g_hash_table_lookup (namemap, name);
if (new_name == NULL) {
char *new_u_name;
if (*(name+1) == '.')
g_string_append (target, "ORG.GNUMERIC.");
new_u_name = g_ascii_strup (name, -1);
g_string_append (target, new_u_name);
g_free (new_u_name);
} else
g_string_append (target, new_name);
gnm_expr_list_as_string (func->argc, func->argv, out);
return;
}
static GnmConventions *
odf_expr_conventions_new (void)
......@@ -1276,6 +1320,7 @@ odf_expr_conventions_new (void)
conv->decimal_sep_dot = TRUE;
conv->output.cell_ref = odf_cellref_as_string;
conv->output.range_ref = odf_rangeref_as_string;
conv->output.func = odf_expr_func_handler;
return conv;
}
......
......@@ -1543,11 +1543,6 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
return value_new_error (pos, _("Unknown evaluation error"));
}
static void
gnm_expr_list_as_string (int argc, GnmExprConstPtr const *argv,
GnmConventionsOut *out);
/*
* Converts a parsed tree into its string representation
* assuming that we are evaluating at col, row
......@@ -1650,15 +1645,9 @@ do_expr_as_string (GnmExpr const *expr, int paren_level,
return;
}
case GNM_EXPR_OP_FUNCALL: {
GnmExprFunction const *func = &expr->func;
char const *name = gnm_func_get_name (func->func);
g_string_append (target, name);
/* FIXME: possibly a space here. */
gnm_expr_list_as_string (func->argc, func->argv, out);
case GNM_EXPR_OP_FUNCALL:
out->convs->output.func (out, &expr->func);
return;
}
case GNM_EXPR_OP_NAME:
out->convs->output.name (out, &expr->name);
......@@ -2644,7 +2633,7 @@ gnm_expr_list_unref (GnmExprList *list)
gnm_expr_list_free (list);
}
static void
void
gnm_expr_list_as_string (int argc,
GnmExprConstPtr const *argv,
GnmConventionsOut *out)
......
......@@ -93,6 +93,8 @@ void gnm_expr_as_gstring (GnmExpr const *expr,
GnmConventionsOut *out);
char *gnm_expr_as_string (GnmExpr const *expr, GnmParsePos const *pp,
GnmConventions const *convs);
void gnm_expr_list_as_string (int argc, GnmExprConstPtr const *argv,
GnmConventionsOut *out);
gboolean gnm_expr_contains_subtotal (GnmExpr const *expr);
GnmValue *gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
......
......@@ -1148,6 +1148,18 @@ rangeref_parse (GnmRangeRef *res, char const *start, GnmParsePos const *pp,
/* ------------------------------------------------------------------------- */
static void
std_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
{
char const *name = gnm_func_get_name (func->func);
GString *target = out->accum;
g_string_append (target, name);
/* FIXME: possibly a space here. */
gnm_expr_list_as_string (func->argc, func->argv, out);
return;
}
static void
std_expr_name_handler (GnmConventionsOut *out, GnmExprName const *name)
{
......@@ -1338,6 +1350,7 @@ gnm_conventions_new_full (unsigned size)
convs->output.translated = TRUE;
convs->output.string = std_output_string;
convs->output.name = std_expr_name_handler;
convs->output.func = std_expr_func_handler;
convs->output.cell_ref = cellref_as_string;
convs->output.range_ref = rangeref_as_string;
convs->output.quote_sheet_name = std_sheet_name_quote;
......
......@@ -169,6 +169,8 @@ struct _GnmConventions {
void (*string) (GnmConventionsOut *out,
GOString const *str);
void (*func) (GnmConventionsOut *out,
GnmExprFunction const *func);
void (*name) (GnmConventionsOut *out,
GnmExprName const *name);
void (*cell_ref) (GnmConventionsOut *out,
......
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