Commit 130565c6 authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

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
parent 903956a0
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.
......
......@@ -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]
......
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>
......
......@@ -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,
......
......@@ -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;
......
......@@ -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,
......
......@@ -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 */
......
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