[gnumeric] Ensure that names cannot be mistaken as cell references [#409997]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Ensure that names cannot be mistaken as cell references [#409997]
- Date: Mon, 7 Jun 2010 06:56:00 +0000 (UTC)
commit 512d34b8c9a3918603fc30b45cff13a1d6492515
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Mon Jun 7 00:56:05 2010 -0600
Ensure that names cannot be mistaken as cell references [#409997]
2010-06-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/expr-name.h (expr_name_validate): drop Sheet argument
* src/commands.c (cmd_define_name): change the caller here
* src/expr-name.c (expr_name_validate): and the definition
here; use the following two functions
(expr_name_validate_r1c1): new
(expr_name_validate_a1): new
2010-06-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* dialog-define-names.c (cb_name_guru_name_edited): the
name becomes non-ediatable after it has been set.
ChangeLog | 9 +++++
NEWS | 5 ++-
src/commands.c | 2 +-
src/dialogs/ChangeLog | 5 +++
src/dialogs/dialog-define-names.c | 1 +
src/expr-name.c | 63 ++++++++++++++++++++++++++++++++++---
src/expr-name.h | 2 +-
7 files changed, 79 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2e96f15..21d0d67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-06-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/expr-name.h (expr_name_validate): drop Sheet argument
+ * src/commands.c (cmd_define_name): change the caller here
+ * src/expr-name.c (expr_name_validate): and the definition
+ here; use the following two functions
+ (expr_name_validate_r1c1): new
+ (expr_name_validate_a1): new
+
2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/expr-name.h (expr_name_in_use): new
diff --git a/NEWS b/NEWS
index 81c1eb7..b712744 100644
--- a/NEWS
+++ b/NEWS
@@ -8,7 +8,10 @@ Andreas:
* Make changing the scope of a named expression undoable.
* Add search tool to paste- and define-names dialogs. [#465840]
* Check whether defined names are in use before deleting them.
- * Add option to the regression tool to allow for multiple Y. [#620505]
+ * Add option to the regression tool to allow for multiple Y.
+ [#620505]
+ * Ensure that names cannot be mistaken as cell references.
+ [#409997]
Jean:
* Do not ungrab a not grabbed item. [#620369]
diff --git a/src/commands.c b/src/commands.c
index 8a58262..39816cc 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -5846,7 +5846,7 @@ cmd_define_name (WorkbookControl *wbc, char const *name,
}
sheet = wb_control_cur_sheet (wbc);
- if (!expr_name_validate (name, sheet)) {
+ if (!expr_name_validate (name)) {
gchar *err = g_strdup_printf
(_("'%s' is not allowed as defined name."), name);
go_cmd_context_error_invalid (GO_CMD_CONTEXT (wbc),
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index e3264f3..48313ca 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * dialog-define-names.c (cb_name_guru_name_edited): the
+ name becomes non-ediatable after it has been set.
+
2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
* regression.glade: add new checkbox and move the selectors for
diff --git a/src/dialogs/dialog-define-names.c b/src/dialogs/dialog-define-names.c
index d03a29e..b35dd0f 100644
--- a/src/dialogs/dialog-define-names.c
+++ b/src/dialogs/dialog-define-names.c
@@ -1008,6 +1008,7 @@ cb_name_guru_name_edited (G_GNUC_UNUSED GtkCellRendererText *cell,
ITEM_NAME_POINTER, nexpr,
ITEM_TYPE, type,
ITEM_PASTABLE, TRUE,
+ ITEM_NAME_IS_EDITABLE, FALSE,
-1);
name_guru_set_images (state, &iter, type, TRUE);
diff --git a/src/expr-name.c b/src/expr-name.c
index fa98d3e..06e4603 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -27,6 +27,52 @@
#include <goffice/goffice.h>
+
+static gboolean
+expr_name_validate_r1c1 (const char *name)
+{
+ const char *p = name;
+ gint i;
+
+ if (p[0] != 'R' && p[0] != 'r')
+ return TRUE;
+ p++;
+ /* no need to worry about [] since they are not alphanumeric */
+ for (i = 0; p[0] && g_ascii_isdigit (p[0]); p = g_utf8_next_char (p))
+ i++;
+ if (i==0)
+ return TRUE;
+ if (p[0] != 'C' && p[0] != 'c')
+ return TRUE;
+ p++;
+ for (i = 0; p[0] && g_ascii_isdigit (p[0]); p = g_utf8_next_char (p))
+ i++;
+ if (i==0)
+ return TRUE;
+ return (p[0] != '\0');
+}
+
+static gboolean
+expr_name_validate_a1 (const char *name)
+{
+ const char *p = name;
+ gint i;
+
+ for (i = 0; *p && g_ascii_isalpha(p[0]);
+ p = g_utf8_next_char (p))
+ i++;
+ if (i==0 || i>4) /* We want to allow "total2010" and it */
+ /* is unlikely to have more than 456976 */
+ /* columns atm */
+ return TRUE;
+ for (i = 0; *p && g_ascii_isdigit (p[0]);
+ p = g_utf8_next_char (p))
+ i++;
+ if (i==0)
+ return TRUE;
+ return (*p != '\0');
+}
+
/**
* expr_name_validate:
* @name: tentative name
@@ -34,9 +80,8 @@
* returns TRUE if the given name is valid, FALSE otherwise.
*/
gboolean
-expr_name_validate (const char *name, Sheet *sheet)
+expr_name_validate (const char *name)
{
- GnmCellPos cp;
const char *p;
g_return_val_if_fail (name != NULL, FALSE);
@@ -49,9 +94,6 @@ expr_name_validate (const char *name, Sheet *sheet)
strcmp (name, go_locale_boolean_name (FALSE)) == 0)
return FALSE;
- /* What about R1C1? */
- if (cellpos_parse (name, gnm_sheet_get_size (sheet), &cp, TRUE))
- return FALSE;
/* Hmm... Now what? */
if (!g_unichar_isalpha (g_utf8_get_char (name)) &&
@@ -64,6 +106,17 @@ expr_name_validate (const char *name, Sheet *sheet)
return FALSE;
}
+ /* Make sure it's not A1 etc.*/
+ /* Note that we can't use our regular parsers */
+ /* since we also have to avoid names that may become */
+ /* sensible when the sheet size changes. */
+ if (!expr_name_validate_a1 (name))
+ return FALSE;
+
+ /* What about R1C1? */
+ if (!expr_name_validate_r1c1 (name))
+ return FALSE;
+
return TRUE;
}
diff --git a/src/expr-name.h b/src/expr-name.h
index 438ca60..07de39a 100644
--- a/src/expr-name.h
+++ b/src/expr-name.h
@@ -23,7 +23,7 @@ struct _GnmNamedExpr {
gboolean is_editable;
};
-gboolean expr_name_validate (const char *name, Sheet *sheet);
+gboolean expr_name_validate (const char *name);
GnmNamedExpr *expr_name_lookup (GnmParsePos const *pos, char const *name);
GnmNamedExpr *expr_name_add (GnmParsePos const *pp, char const *name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]