[gnumeric] solver: improve parsing consistency.



commit eb51de95ee62fee5aa1dbb3ee7f201aca5bfe70e
Author: Morten Welinder <terra gnome org>
Date:   Sat Oct 31 18:01:58 2009 -0400

    solver: improve parsing consistency.

 ChangeLog                         |    3 ++-
 src/dialogs/dialog-solver.c       |    4 ++++
 src/tools/solver/solver.c         |    7 ++++---
 src/value.c                       |   12 ++++++------
 src/value.h                       |    4 +++-
 src/widgets/gnumeric-expr-entry.c |   19 +++++++++++++++----
 src/workbook-control.c            |    3 ++-
 7 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dd53c0d..eec8850 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
 2009-10-31  Morten Welinder  <terra gnome org>
 
 	* src/value.c (value_new_cellrange_parsepos_str): Use the right
-	convensions.
+	convensions.  Add flags argument for finer control.  All callers
+	changed.
 
 2009-10-31  Andreas J. Guelzow <aguelzow pyrshep ca>
 
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index a1084fc..027c943 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -890,6 +890,7 @@ dialog_init (SolverState *state)
 	state->target_entry = gnm_expr_entry_new (state->wbcg, TRUE);
 	gnm_expr_entry_set_flags (state->target_entry,
 		GNM_EE_SINGLE_RANGE |
+		GNM_EE_FORCE_ABS_REF |
 		GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
 	gtk_table_attach (table, GTK_WIDGET (state->target_entry),
 			  1, 2, 0, 1,
@@ -907,6 +908,7 @@ dialog_init (SolverState *state)
 	state->change_cell_entry = gnm_expr_entry_new (state->wbcg, TRUE);
 	gnm_expr_entry_set_flags (state->change_cell_entry,
 		GNM_EE_SINGLE_RANGE |
+		GNM_EE_FORCE_ABS_REF |
 		GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
 	gtk_table_attach (table, GTK_WIDGET (state->change_cell_entry),
 			  1, 2, 2, 3,
@@ -969,6 +971,7 @@ dialog_init (SolverState *state)
 	state->lhs.entry = gnm_expr_entry_new (state->wbcg, TRUE);
 	gnm_expr_entry_set_flags (state->lhs.entry,
 		GNM_EE_SINGLE_RANGE |
+		GNM_EE_FORCE_ABS_REF |
 		GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
 	gtk_table_attach (table, GTK_WIDGET (state->lhs.entry),
 			  0, 1, 1, 2,
@@ -990,6 +993,7 @@ dialog_init (SolverState *state)
 	state->rhs.entry = gnm_expr_entry_new (state->wbcg, TRUE);
 	gnm_expr_entry_set_flags (state->rhs.entry,
 		GNM_EE_SINGLE_RANGE |
+		GNM_EE_FORCE_ABS_REF |
 		GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
 	gtk_table_attach (table, GTK_WIDGET (state->rhs.entry),
 			  2, 3, 1, 2,
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index 572d4ff..d2c3a1e 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -106,10 +106,11 @@ solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 	int cols = 1, rows = 1;
 	gboolean old = FALSE;
 	GnmParsePos pp;
+	GnmExprParseFlags flags = GNM_EXPR_PARSE_DEFAULT;
 
 	c = gnm_solver_constraint_new (sheet);
 
-	parse_pos_init (&pp, sheet->workbook, NULL, 0, 0);
+	parse_pos_init_sheet (&pp, sheet);
 
 	for (; attrs && attrs[0] && attrs[1] ; attrs += 2) {
 		if (gnm_xml_attr_int (attrs, "Lcol", &lhs_col) ||
@@ -123,11 +124,11 @@ solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 			; /* Nothing */
 		else if (attr_eq (attrs[0], "lhs")) {
 			GnmValue *v = value_new_cellrange_parsepos_str
-				(&pp, CXML2C (attrs[1]));
+				(&pp, CXML2C (attrs[1]), flags);
 			gnm_solver_constraint_set_lhs (c, v);
 		} else if (attr_eq (attrs[0], "rhs")) {
 			GnmValue *v = value_new_cellrange_parsepos_str
-				(&pp, CXML2C (attrs[1]));
+				(&pp, CXML2C (attrs[1]), flags);
 			gnm_solver_constraint_set_rhs (c, v);
 		}
 	}
diff --git a/src/value.c b/src/value.c
index b41d059..14bef23 100644
--- a/src/value.c
+++ b/src/value.c
@@ -359,12 +359,14 @@ GnmValue *
 value_new_cellrange_str (Sheet *sheet, char const *str)
 {
 	GnmParsePos pp;
+	GnmExprParseFlags flags = GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS |
+		GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
 
 	g_return_val_if_fail (IS_SHEET (sheet), NULL);
 	g_return_val_if_fail (str != NULL, NULL);
 
 	parse_pos_init_sheet (&pp, sheet);
-	return value_new_cellrange_parsepos_str (&pp, str);
+	return value_new_cellrange_parsepos_str (&pp, str, flags);
 }
 
 /**
@@ -378,19 +380,17 @@ value_new_cellrange_str (Sheet *sheet, char const *str)
  * succesfully parsed or NULL on failure.
  */
 GnmValue *
-value_new_cellrange_parsepos_str (GnmParsePos *pp, char const *str)
+value_new_cellrange_parsepos_str (GnmParsePos *pp, char const *str,
+				  GnmExprParseFlags flags)
 {
 	GnmExprTop const *texpr;
-	GnmExprParseFlags flags = GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS;
 	GnmConventions const *convs = NULL;
 
 	g_return_val_if_fail (pp != NULL, NULL);
 	g_return_val_if_fail (str != NULL, NULL);
 
-	if (pp->sheet) {
-		flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
+	if (pp->sheet)
 		convs = pp->sheet->convs;
-	}
 
 	texpr = gnm_expr_parse_str (str, pp, flags, convs, NULL);
 
diff --git a/src/value.h b/src/value.h
index 66bf54f..1f9a049 100644
--- a/src/value.h
+++ b/src/value.h
@@ -5,6 +5,7 @@
 #include "gnumeric.h"
 #include "position.h"
 #include "numbers.h"
+#include "parse-util.h"
 #include <glib-object.h>
 
 G_BEGIN_DECLS
@@ -119,7 +120,8 @@ GnmValue *value_new_cellrange        (GnmCellRef const *a, GnmCellRef const *b,
 				      int eval_col, int eval_row);
 GnmValue *value_new_cellrange_r      (Sheet *sheet, GnmRange const *r);
 GnmValue *value_new_cellrange_str    (Sheet *sheet, char const *str);
-GnmValue *value_new_cellrange_parsepos_str (GnmParsePos *pp, char const *str);
+GnmValue *value_new_cellrange_parsepos_str (GnmParsePos *pp, char const *str,
+					    GnmExprParseFlags flags);
 GnmValue *value_new_array            (guint cols, guint rows);
 GnmValue *value_new_array_empty      (guint cols, guint rows);
 GnmValue *value_new_array_non_init   (guint cols, guint rows);
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index e2af9bf..26760e0 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -1747,8 +1747,7 @@ gnm_expr_entry_get_text	(GnmExprEntry const *gee)
  * gnm_expr_entry_parse_as_value :
  *
  * @gee: GnmExprEntry
- * @sheet: the sheet where the cell range is evaluated. This really only needed if
- *         the range given does not include a sheet specification.
+ * @sheet: the sheet where the cell range is evaluated.
  *
  * Returns a (GnmValue *) of type VALUE_CELLRANGE if the @range was
  *	succesfully parsed or NULL on failure.
@@ -1756,10 +1755,22 @@ gnm_expr_entry_get_text	(GnmExprEntry const *gee)
 GnmValue *
 gnm_expr_entry_parse_as_value (GnmExprEntry *gee, Sheet *sheet)
 {
+	GnmParsePos pp;
+	GnmExprParseFlags flags = GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS;
+
 	g_return_val_if_fail (IS_GNM_EXPR_ENTRY (gee), NULL);
 
-	return value_new_cellrange_str (sheet,
-		gtk_entry_get_text (gnm_expr_entry_get_entry (gee)));
+	if ((gee->flags & GNM_EE_FORCE_ABS_REF))
+		flags |= GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES;
+	else if ((gee->flags & GNM_EE_FORCE_REL_REF))
+		flags |= GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES;
+	if (!(gee->flags & GNM_EE_SHEET_OPTIONAL))
+		flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
+
+	return value_new_cellrange_parsepos_str
+		(parse_pos_init_sheet (&pp, sheet),
+		 gtk_entry_get_text (gnm_expr_entry_get_entry (gee)),
+		 flags);
 }
 
 /**
diff --git a/src/workbook-control.c b/src/workbook-control.c
index 6ddc2c7..0479da2 100644
--- a/src/workbook-control.c
+++ b/src/workbook-control.c
@@ -276,7 +276,8 @@ wb_control_parse_and_jump (WorkbookControl *wbc, char const *text)
 
 	sv = wb_control_cur_sheet_view (wbc);
 	parse_pos_init_editpos (&pp, sv);
-	target = value_new_cellrange_parsepos_str (&pp, text);
+	target = value_new_cellrange_parsepos_str (&pp, text,
+						   GNM_EXPR_PARSE_DEFAULT);
 	if (target == NULL) {
 		/* Not an address; is it a name? */
 		GnmParsePos pp;



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