[gnumeric] solver: read the new format.



commit c45441ccbe799036298268650b015a3909b9ec2b
Author: Morten Welinder <terra gnome org>
Date:   Sat Oct 31 11:51:37 2009 -0400

    solver: read the new format.

 ChangeLog                  |    5 +++++
 src/tools/solver/ChangeLog |    4 ++++
 src/tools/solver/solver.c  |   35 ++++++++++++++++++++++++++---------
 src/value.c                |   12 ++++++++----
 4 files changed, 43 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7c45464..dd53c0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-31  Morten Welinder  <terra gnome org>
+
+	* src/value.c (value_new_cellrange_parsepos_str): Use the right
+	convensions.
+
 2009-10-31  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/wbc-gtk-actions.c (cb_format_preferences): delete
diff --git a/src/tools/solver/ChangeLog b/src/tools/solver/ChangeLog
index d1ef312..117100b 100644
--- a/src/tools/solver/ChangeLog
+++ b/src/tools/solver/ChangeLog
@@ -1,3 +1,7 @@
+2009-10-31  Morten Welinder  <terra gnome org>
+
+	* solver.c (solver_constr_start): Read the new format.
+
 2009-10-29  Morten Welinder  <terra gnome org>
 
 	* solver.c (solver_run): Avoid UMRs on Win32.
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index a7ad30d..572d4ff 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -56,6 +56,12 @@
 #define GNM 100
 #define CXML2C(s) ((char const *)(s))
 
+static inline gboolean
+attr_eq (const xmlChar *a, const char *s)
+{
+	return !strcmp (CXML2C (a), s);
+}
+
 /* ------------------------------------------------------------------------- */
 
 
@@ -94,25 +100,36 @@ solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	int type = 0;
 	SolverConstraint *c;
-	int i;
 	Sheet *sheet = gnm_xml_in_cur_sheet (xin);
 	SolverParameters *sp = sheet->solver_parameters;
 	int lhs_col = 0, lhs_row = 0, rhs_col = 0, rhs_row = 0;
 	int cols = 1, rows = 1;
 	gboolean old = FALSE;
+	GnmParsePos pp;
 
 	c = gnm_solver_constraint_new (sheet);
 
-	for (i = 0; attrs != NULL && attrs[i] && attrs[i + 1] ; i += 2) {
-		if (gnm_xml_attr_int (attrs+i, "Lcol", &lhs_col) ||
-		    gnm_xml_attr_int (attrs+i, "Lrow", &lhs_row) ||
-		    gnm_xml_attr_int (attrs+i, "Rcol", &rhs_col) ||
-		    gnm_xml_attr_int (attrs+i, "Rrow", &rhs_row) ||
-		    gnm_xml_attr_int (attrs+i, "Cols", &cols) ||
-		    gnm_xml_attr_int (attrs+i, "Rows", &rows))
+	parse_pos_init (&pp, sheet->workbook, NULL, 0, 0);
+
+	for (; attrs && attrs[0] && attrs[1] ; attrs += 2) {
+		if (gnm_xml_attr_int (attrs, "Lcol", &lhs_col) ||
+		    gnm_xml_attr_int (attrs, "Lrow", &lhs_row) ||
+		    gnm_xml_attr_int (attrs, "Rcol", &rhs_col) ||
+		    gnm_xml_attr_int (attrs, "Rrow", &rhs_row) ||
+		    gnm_xml_attr_int (attrs, "Cols", &cols) ||
+		    gnm_xml_attr_int (attrs, "Rows", &rows))
 			old = TRUE;
-		else if (gnm_xml_attr_int (attrs+i, "Type", &type))
+		else if (gnm_xml_attr_int (attrs, "Type", &type))
 			; /* Nothing */
+		else if (attr_eq (attrs[0], "lhs")) {
+			GnmValue *v = value_new_cellrange_parsepos_str
+				(&pp, CXML2C (attrs[1]));
+			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]));
+			gnm_solver_constraint_set_rhs (c, v);
+		}
 	}
 
 	switch (type) {
diff --git a/src/value.c b/src/value.c
index de2a08a..b41d059 100644
--- a/src/value.c
+++ b/src/value.c
@@ -381,14 +381,18 @@ GnmValue *
 value_new_cellrange_parsepos_str (GnmParsePos *pp, char const *str)
 {
 	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);
 
-	texpr = gnm_expr_parse_str (str, pp,
-		GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES |
-		GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS,
-		NULL, NULL);
+	if (pp->sheet) {
+		flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
+		convs = pp->sheet->convs;
+	}
+
+	texpr = gnm_expr_parse_str (str, pp, flags, convs, NULL);
 
 	if (texpr != NULL)  {
 		GnmValue *value = gnm_expr_top_get_range (texpr);



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