[gnumeric] xls: cleanup.



commit 06b203ebb3c2d5bb7ee2717a17620261d6765775
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 3 11:35:53 2013 -0500

    xls: cleanup.

 plugins/excel/ChangeLog         |    6 ++++++
 plugins/excel/ms-excel-read.c   |   12 ++++++------
 plugins/excel/ms-excel-read.h   |    4 ++++
 plugins/excel/ms-formula-read.c |    9 +++++----
 4 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index d0fcbc7..780b006 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,9 @@
+2013-01-03  Morten Welinder  <terra gnome org>
+
+	* ms-excel-read.h (XL_EXTERNSHEET_MAGIC_SELFREF)
+	(XL_EXTERNSHEET_MAGIC_DELETED): Intorduce symbolic names for magic
+	constants.  All users changed.
+
 2013-01-01  Morten Welinder  <terra gnome org>
 
 	* ms-excel-write.c (excel_font_overlay_pango): Don't use
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index b190c2a..f404767 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -5965,11 +5965,11 @@ excel_read_SCL (BiffQuery *q, Sheet *sheet)
  * WARNING WARNING WARNING
  *
  * This function can and will return intentionally INVALID pointers in some
- * cases.  You need to check for (Sheet *)1
+ * cases.  You need to check for XL_EXTERNSHEET_MAGIC_SELFREF
  * It should only happen for external names to deal with 'reference self'
  * supbook entries.  However, you never know.
  *
- * you also need to check for (Sheet *)2 which indicates deleted
+ * you also need to check for XL_EXTERNSHEET_MAGIC_DELETED which indicates deleted
  *
  * WARNING WARNING WARNING
  **/
@@ -5998,11 +5998,11 @@ supbook_get_sheet (GnmXLImporter *importer, gint16 sup_index, unsigned i)
 
 	/* 0xffff == deleted */
 	if (i >= 0xffff)
-		return (Sheet *)2; /* magic value */
+		return XL_EXTERNSHEET_MAGIC_DELETED; /* magic value */
 
 	/* WARNING : 0xfffe record for local names kludge a solution */
 	if (i == 0xfffe)
-		return (Sheet *)1; /* magic value */
+		return XL_EXTERNSHEET_MAGIC_SELFREF; /* magic value */
 
 	g_return_val_if_fail ((unsigned)sup_index < importer->v8.supbook->len, NULL);
 
@@ -6022,7 +6022,7 @@ supbook_get_sheet (GnmXLImporter *importer, gint16 sup_index, unsigned i)
 		break;
 	}
 
-	return (Sheet *)2; /* pretend "deleted" */
+	return XL_EXTERNSHEET_MAGIC_DELETED; /* pretend "deleted" */
 }
 
 static void
@@ -6142,7 +6142,7 @@ excel_read_EXTERNSHEET_v7 (BiffQuery const *q, MSContainer *container)
 		break;
 	}
 	case 4: /* undocumented.  Seems to be used as a placeholder for names */
-		sheet = (Sheet *)1;
+		sheet = XL_EXTERNSHEET_MAGIC_SELFREF;
 		break;
 
 	case 0x3a : /* undocumented magic.  seems to indicate the sheet for an
diff --git a/plugins/excel/ms-excel-read.h b/plugins/excel/ms-excel-read.h
index f6a27a8..0795485 100644
--- a/plugins/excel/ms-excel-read.h
+++ b/plugins/excel/ms-excel-read.h
@@ -25,6 +25,10 @@ typedef struct {
 	Sheet	  *first, *last;
 	unsigned   supbook;
 } ExcelExternSheetV8;
+
+#define XL_EXTERNSHEET_MAGIC_SELFREF ((Sheet *)1)
+#define XL_EXTERNSHEET_MAGIC_DELETED ((Sheet *)2)
+
 typedef enum {
 	EXCEL_SUP_BOOK_STD,
 	EXCEL_SUP_BOOK_SELFREF,
diff --git a/plugins/excel/ms-formula-read.c b/plugins/excel/ms-formula-read.c
index 9db3fce..fe082bb 100644
--- a/plugins/excel/ms-formula-read.c
+++ b/plugins/excel/ms-formula-read.c
@@ -769,7 +769,8 @@ excel_formula_parses_ref_sheets (MSContainer const *container, guint8 const *dat
 			excel_externsheet_v8 (container->importer, GSF_LE_GET_GUINT16 (data));
 
 		if (es != NULL) {
-			if (es->first == (Sheet *)2 || es->last == (Sheet *)2) /* deleted sheets */
+			if (es->first == XL_EXTERNSHEET_MAGIC_DELETED ||
+			    es->last == XL_EXTERNSHEET_MAGIC_DELETED)
 				return TRUE;
 			*first = es->first;
 			*last = es->last;
@@ -811,10 +812,10 @@ excel_formula_parses_ref_sheets (MSContainer const *container, guint8 const *dat
 		}
 	}
 
-	if (*first == (Sheet *)1) {
+	if (*first == XL_EXTERNSHEET_MAGIC_SELFREF) {
 		*first = *last = NULL;
 		g_warning ("So much for that theory.  Please send us a copy of this workbook");
-	} else if (*last == (Sheet *)1) {
+	} else if (*last == XL_EXTERNSHEET_MAGIC_SELFREF) {
 		*last = *first;
 		g_warning ("so much for that theory.  Please send us a copy of this workbook");
 	} else if (*first != NULL && *last == NULL)
@@ -1606,7 +1607,7 @@ excel_parse_formula1 (MSContainer const *container,
 					value_new_error_REF (NULL));
 			} else {
 				/* See supbook_get_sheet for details */
-				if (sheet == (Sheet *)1) {
+				if (sheet == XL_EXTERNSHEET_MAGIC_SELFREF) {
 					sheet = nexpr->pos.sheet;
 					if (sheet == NULL)
 						sheet = ms_container_sheet (container);



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