[gnumeric] Start with function name adjustments on ODF export



commit 4a4bce216563781517f30228115547c6e68bdfb7
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Wed Jun 17 12:35:55 2009 -0600

    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

 ChangeLog                             |    9 ++++++
 plugins/openoffice/ChangeLog          |    6 ++++
 plugins/openoffice/openoffice-read.c  |    6 +++-
 plugins/openoffice/openoffice-write.c |   45 +++++++++++++++++++++++++++++++++
 src/expr.c                            |   17 ++----------
 src/expr.h                            |    2 +
 src/parse-util.c                      |   13 +++++++++
 src/parse-util.h                      |    2 +
 8 files changed, 84 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index acab870..3374563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 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 
 	  printarea menu items
 	(cmd_define_name_redo): ditto
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 559aff2..64aa31a 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 8c9dceb..73863d7 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -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;
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index a6d64d2..2d9ad8f 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -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;
 }
diff --git a/src/expr.c b/src/expr.c
index 97bb65c..e2aafdc 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -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)
diff --git a/src/expr.h b/src/expr.h
index 165d5bc..019f48a 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -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,
diff --git a/src/parse-util.c b/src/parse-util.c
index 2b57c06..14024ce 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1149,6 +1149,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)
 {
 	GnmNamedExpr const *thename = name->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;
diff --git a/src/parse-util.h b/src/parse-util.h
index df8cf3c..4da653a 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -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,



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