[gnumeric] From ODF also import named expressions with illegal name. [#650125]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] From ODF also import named expressions with illegal name. [#650125]
- Date: Wed, 18 May 2011 00:11:36 +0000 (UTC)
commit 130565c67975605187e85fc0c65a7f76bb5335b7
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Tue May 17 18:11:01 2011 -0600
From ODF also import named expressions with illegal name. [#650125]
2011-05-17 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/parse-util.h (_GnmConventions): add name_validate field
* src/parse-util.c (gnm_conventions_new_full): initialize name_validate
* src/parser.y (parser_simple_val_or_name): use
state->convs->input.name_validate
2011-05-17 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (odf_fix_expr_names): new stub
(odf_expr_name_validate): new
(oo_conventions_new): connect odf_expr_name_validate
(openoffice_file_open): connect odf_fix_expr_names
ChangeLog | 7 ++++
NEWS | 1 +
plugins/openoffice/ChangeLog | 9 ++++-
plugins/openoffice/openoffice-read.c | 61 +++++++++++++++++++++++++++++++++-
src/parse-util.c | 1 +
src/parse-util.h | 2 +
src/parser.y | 2 +-
7 files changed, 80 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d585654..174fe19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-17 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/parse-util.h (_GnmConventions): add name_validate field
+ * src/parse-util.c (gnm_conventions_new_full): initialize name_validate
+ * src/parser.y (parser_simple_val_or_name): use
+ state->convs->input.name_validate
+
2011-05-17 Morten Welinder <terra gnome org>
* src/sheet.c (sheet_colrow_optimize): Use sheet_get_cells_extent.
diff --git a/NEWS b/NEWS
index a29bd1d..299a962 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ Andreas:
* Import more validations from ODF.
* Export all validations to ODF.
* Fix printing of background colours. [#650261]
+ * From ODF also import named expressions with illegal name. [#650125]
Jean:
* Fixed critical. [#649901]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 3bf0f7c..b5bd77c 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,6 +1,13 @@
+2011-05-17 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-read.c (odf_fix_expr_names): new stub
+ (odf_expr_name_validate): new
+ (oo_conventions_new): connect odf_expr_name_validate
+ (openoffice_file_open): connect odf_fix_expr_names
+
2011-05-16 Andreas J. Guelzow <aguelzow pyrshep ca>
- * openoffice-write.c (odf_write_named_expression): avoid writing some
+ * openoffice-write.c (odf_write_named_expression): avoid writing some
placeholder names
2011-05-16 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 1dc8756..0d3a94b 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1210,6 +1210,63 @@ odf_strunescape (char const *string, GString *target,
return NULL;
}
+/**
+ * When we initialy validate names we have to accept every ODF name
+ * in odf_fix_expr_names we fix them.
+ *
+ *
+ */
+
+static void
+odf_fix_expr_names (OOParseState *state)
+{
+#warning We need to implement this
+}
+
+/**
+ * odf_expr_name_validate:
+ * @name: tentative name
+ *
+ * returns TRUE if the given name is valid, FALSE otherwise.
+ *
+ * We are accepting names here that contain periods or look like addresses.
+ * They need to be replaced when we have finished parsing the file since
+ * they are not allowed inside Gnumeric.
+ */
+static gboolean
+odf_expr_name_validate (const char *name)
+{
+ const char *p;
+ GnmValue *v;
+
+ g_return_val_if_fail (name != NULL, FALSE);
+
+ if (name[0] == 0)
+ return FALSE;
+
+ v = value_new_from_string (VALUE_BOOLEAN, name, NULL, TRUE);
+ if (!v)
+ v = value_new_from_string (VALUE_BOOLEAN, name, NULL, FALSE);
+ if (v) {
+ value_release (v);
+ return FALSE;
+ }
+
+ /* Hmm... Now what? */
+ if (!g_unichar_isalpha (g_utf8_get_char (name)) &&
+ name[0] != '_')
+ return FALSE;
+
+ for (p = name; *p; p = g_utf8_next_char (p)) {
+ if (!g_unichar_isalnum (g_utf8_get_char (p)) &&
+ p[0] != '_' && p[0] != '.')
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
static GnmExpr const *
oo_func_map_in (GnmConventions const *convs, Workbook *scope,
char const *name, GnmExprList *args);
@@ -1231,6 +1288,7 @@ oo_conventions_new (void)
conv->input.string = odf_strunescape;
conv->input.func = oo_func_map_in;
conv->input.range_ref = oo_expr_rangeref_parse;
+ conv->input.name_validate = odf_expr_name_validate;
conv->sheet_name_sep = '.';
return conv;
@@ -8772,7 +8830,6 @@ determine_oo_version (GsfInfile *zip, OOVer def)
return OOO_VER_UNKNOWN;
}
-
void
openoffice_file_open (GOFileOpener const *fo, GOIOContext *io_context,
WorkbookView *wb_view, GsfInput *input);
@@ -8974,6 +9031,8 @@ openoffice_file_open (GOFileOpener const *fo, GOIOContext *io_context,
workbook_sheet_reorder (state.pos.wb, state.sheet_order);
g_slist_free (state.sheet_order);
+ odf_fix_expr_names (&state);
+
/* look for the view settings */
state.settings.settings
= g_hash_table_new_full (g_str_hash, g_str_equal,
diff --git a/src/parse-util.c b/src/parse-util.c
index 5a704d2..16028dc 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1367,6 +1367,7 @@ gnm_conventions_new_full (unsigned size)
convs->input.range_ref = rangeref_parse;
convs->input.string = std_string_parser;
convs->input.name = std_name_parser;
+ convs->input.name_validate = expr_name_validate;
convs->input.func = std_func_map;
convs->input.external_wb = std_external_wb;
diff --git a/src/parse-util.h b/src/parse-util.h
index cbe4b05..1b0b39c 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -159,6 +159,8 @@ struct _GnmConventions {
* defined name. */
char const *(*name) (char const *in,
GnmConventions const *convs);
+ /* Returns true if a tentative expression name is legal. */
+ gboolean (*name_validate) (const char *name);
/* Must return non-NULL, and absorb the args, including the list. */
GnmExpr const *(*func) (GnmConventions const *convs,
diff --git a/src/parser.y b/src/parser.y
index 1944056..15f5f9b 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -511,7 +511,7 @@ parser_simple_val_or_name (GnmExpr *str_expr)
res = NULL;
} else if (state->flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS) {
res = gnm_expr_new_constant (value_new_string (str));
- } else if (expr_name_validate (str)) {
+ } else if (state->convs->input.name_validate (str)) {
GnmParsePos pp = *state->pos;
pp.sheet = NULL;
/* Create a place holder */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]