[gnumeric] some applix fixes



commit 12dad1e57a1621b16e6fd26914009c3fc5370bbb
Author: Jody Goldberg <jody gnome org>
Date:   Sat Sep 20 15:23:06 2008 -0400

    some applix fixes
---
 plugins/applix/ChangeLog     |    8 +++++
 plugins/applix/applix-read.c |   68 ++++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/plugins/applix/ChangeLog b/plugins/applix/ChangeLog
index 7e1dc51..97eabb5 100644
--- a/plugins/applix/ChangeLog
+++ b/plugins/applix/ChangeLog
@@ -1,3 +1,11 @@
+2008-09-19  Jody Goldberg <jody gnome org>
+
+	* applix-read.c (applix_parse_style) : clean up the switch.  There's
+	  no need to use convoluted logic to fallthrough a series of cases
+	  just to share some code. [Coverity 93,92,91]
+	(applix_rangeref_parse) : no point checking invariants. [Klocwork]
+	(applix_parse_style) : already checked in style_ref. [Klocwork]
+
 2009-04-28  Morten Welinder  <terra gnome org>
 
 	* applix-read.c (applix_fetch_sheet): Make sheet big enough to
diff --git a/plugins/applix/applix-read.c b/plugins/applix/applix-read.c
index e0e59c7..2c0ab3d 100644
--- a/plugins/applix/applix-read.c
+++ b/plugins/applix/applix-read.c
@@ -257,9 +257,6 @@ applix_rangeref_parse (GnmRangeRef *res, char const *start, GnmParsePos const *p
 	char const *ptr = start, *tmp1, *tmp2;
 	Workbook *wb = pp->wb;
 
-	g_return_val_if_fail (start != NULL, start);
-	g_return_val_if_fail (pp != NULL, start);
-
 	/* TODO : Does not handle external references */
 
 	ptr = applix_sheetref_parse (start, &res->a.sheet, wb);
@@ -547,7 +544,9 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 				sep += 2;
 				break;
 			} else {
+				gboolean get_precision = FALSE;
 				char const *format = NULL;
+
 				switch (*sep) {
 				case 'D' : {
 					int id = 0;
@@ -588,8 +587,8 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 					sep = end;
 					break;
 				}
+
 				case 'T' :
-				{
 					switch (sep[1]) {
 					case '0' : format = "hh:mm:ss AM/PM";	break;
 					case '1' : format = "hh:mm AM/PM";	break;
@@ -601,7 +600,7 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 					}
 					sep += 2;
 					break;
-				}
+
 				case 'G' : /* general */
 					gnm_style_set_format (style, go_format_general ());
 
@@ -622,35 +621,22 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 						format_prefix = "$ #,##0";
 
 					format_suffix = "";
+					get_precision = TRUE;
+					break;
 
 				case 'S' : /* scientific */
-					if (!format_suffix)
-						format_suffix = "E+00";
-				case 'P' : /* percentage */
-					if (!format_suffix)
-						format_suffix = "%";
-
-				case 'F' : { /* fixed */
-					static char const *zeros = "000000000";
-					char *format;
-					char const *prec = "", *decimal = "";
-					int n_prec = applix_get_precision (++sep);
-
-					sep++;
-					if (n_prec > 0) {
-						prec = zeros + 9 - n_prec;
-						decimal = ".";
-					}
+					format_suffix = "E+00";
+					get_precision = TRUE;
+					break;
 
-					if (!format_prefix)
-						format_prefix = "0";
-					format = g_strconcat (format_prefix, decimal, prec,
-							      format_suffix, NULL);
+				case 'P' : /* percentage */
+					format_suffix = "%";
+					get_precision = TRUE;
+					break;
 
-					gnm_style_set_format_text (style, format);
-					g_free (format);
+				case 'F' : /* fixed */
+					get_precision = TRUE;
 					break;
-				}
 
 #if 0
 				/* FIXME : Add these to gnumeric ? */
@@ -668,7 +654,27 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 					applix_parse_error (state, "Unknown format '%c'", *sep);
 					return NULL;
 				}
-				if (format)
+
+				if (get_precision) {
+					static char const *zeros = "000000000";
+					char *format;
+					char const *prec = "", *decimal = "";
+					int n_prec = applix_get_precision (++sep);
+
+					sep++;
+					if (n_prec > 0) {
+						prec = zeros + 9 - n_prec;
+						decimal = ".";
+					}
+
+					if (!format_prefix)
+						format_prefix = "0";
+					tmp_format = g_strconcat (format_prefix, decimal, prec,
+								  format_suffix, NULL);
+
+					gnm_style_set_format_text (style, tmp_format);
+					g_free (tmp_format);
+				} else if (NULL != format)
 					gnm_style_set_format_text (style, format);
 			}
 		}
@@ -862,8 +868,6 @@ applix_parse_style (ApplixReadState *state, unsigned char **buffer)
 		g_hash_table_insert (state->styles, g_strdup (start), style);
 	}
 
-	g_return_val_if_fail (style != NULL, NULL);
-
 	*buffer = tmp + 2;
 	gnm_style_ref (style);
 	return style;



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