[gnumeric] xls: fix parts of pivot reading.



commit c472926f71d2e24ccf1fb5e5266d49ce6dcd3131
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 6 14:32:29 2011 -0500

    xls: fix parts of pivot reading.

 ChangeLog                      |    5 +++++
 plugins/excel/ChangeLog        |    5 +++++
 plugins/excel/ms-excel-read.c  |   10 +++++-----
 plugins/excel/ms-excel-read.h  |    2 +-
 plugins/excel/xls-read-pivot.c |   24 +++++++++---------------
 src/go-data-cache-field.c      |   17 ++++++++---------
 6 files changed, 33 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2d41320..cfdbcb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-01-06  Morten Welinder  <terra gnome org>
+
+	* src/go-data-cache-field.c (go_data_cache_field_get_val): Undo
+	previous change.
+
 2010-12-30  Morten Welinder  <terra gnome org>
 
 	* src/number-match.c (format_match_fraction): Add option for
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 5efbbc6..d83c19c 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2011-01-06  Morten Welinder  <terra gnome org>
+
+	* xls-read-pivot.c (xls_read_SXVIEW): The record contains a cache
+	index, not a cache id.
+
 2010-12-26  Jean Brefort  <jean brefort normalesup org>
 
 	* ms-chart.c (areaformat), (chart_write_LINEFORMAT): enhance color support.
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 0d60e52..7d4bfca 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -3163,7 +3163,7 @@ gnm_xl_importer_new (GOIOContext *context, WorkbookView *wb_view)
 		NULL, (GDestroyNotify)excel_font_free);
 	importer->excel_sheets     = g_ptr_array_new ();
 	importer->XF_cell_records  = g_ptr_array_new ();
-	importer->pivot.cache_by_id= g_ptr_array_new ();
+	importer->pivot.cache_by_index = g_ptr_array_new ();
 	importer->pivot.slicer= NULL;
 	importer->format_table     = g_hash_table_new_full (
 		g_direct_hash, g_direct_equal,
@@ -3231,13 +3231,13 @@ gnm_xl_importer_free (GnmXLImporter *importer)
 		g_object_unref (importer->pivot.slicer);
 		importer->pivot.slicer = NULL;
 	}
-	for (i = 0; i < importer->pivot.cache_by_id->len; i++) {
-		GObject *cache = g_ptr_array_index (importer->pivot.cache_by_id, i);
+	for (i = 0; i < importer->pivot.cache_by_index->len; i++) {
+		GObject *cache = g_ptr_array_index (importer->pivot.cache_by_index, i);
 		if (NULL != cache)
 			g_object_unref (cache);
 	}
-	g_ptr_array_free (importer->pivot.cache_by_id, TRUE);
-	importer->pivot.cache_by_id = NULL;
+	g_ptr_array_free (importer->pivot.cache_by_index, TRUE);
+	importer->pivot.cache_by_index = NULL;
 
 	for (i = 0; i < importer->XF_cell_records->len; i++)
 		biff_xf_data_destroy (g_ptr_array_index (importer->XF_cell_records, i));
diff --git a/plugins/excel/ms-excel-read.h b/plugins/excel/ms-excel-read.h
index 0d5b44b..c19b1fb 100644
--- a/plugins/excel/ms-excel-read.h
+++ b/plugins/excel/ms-excel-read.h
@@ -117,7 +117,7 @@ struct _GnmXLImporter {
 		GnmSheetSlicer	  *slicer;
 		GODataSlicerField *slicer_field;
 
-		GPtrArray	  *cache_by_id;
+		GPtrArray	  *cache_by_index;
 		unsigned int	  field_count, record_count;
 
 		unsigned int	  ivd_index; /* 0 = row, 1 = col, > 1 == err */
diff --git a/plugins/excel/xls-read-pivot.c b/plugins/excel/xls-read-pivot.c
index 4f27383..e91a129 100644
--- a/plugins/excel/xls-read-pivot.c
+++ b/plugins/excel/xls-read-pivot.c
@@ -500,20 +500,12 @@ xls_read_SXStreamID (GnmXLImporter *imp, BiffQuery *q, GsfInfile *container)
 	GODataCacheSource *cache_src = NULL;
 
 	XL_CHECK_CONDITION (q->length >= 2);
-
 	cache_id = GSF_LE_GET_GUINT16 (q->data);
 
 	s.imp = imp;
 	s.cache = NULL;
-	if (cache_id < imp->pivot.cache_by_id->len)
-		s.cache = g_ptr_array_index (imp->pivot.cache_by_id, cache_id);
-	else
-		g_ptr_array_set_size (imp->pivot.cache_by_id, cache_id+1);
-
-	if (NULL == s.cache) {
-		xls_read_pivot_cache_by_id (&s, container, cache_id);
-		g_ptr_array_index (imp->pivot.cache_by_id, cache_id) = s.cache;
-	}
+	xls_read_pivot_cache_by_id (&s, container, cache_id);
+	g_ptr_array_add (imp->pivot.cache_by_index, s.cache);
 
 	if (ms_biff_query_peek_next (q, &opcode) &&
 	    opcode == BIFF_SXVS &&
@@ -717,7 +709,7 @@ void
 xls_read_SXVIEW (BiffQuery *q, ExcelReadSheet *esheet)
 {
 	GnmXLImporter *imp = esheet->container.importer;
-	unsigned int first_header_row, cache_id, name_len, data_field_name_len,
+	unsigned int first_header_row, cache_idx, name_len, data_field_name_len,
 		     data_field_axis, data_field_pos, num_fields,
 		     num_row_fields, num_column_fields, num_page_fields,
 		     num_data_fields, num_data_rows, data_columns, flags, autoformat;
@@ -725,14 +717,14 @@ xls_read_SXVIEW (BiffQuery *q, ExcelReadSheet *esheet)
 	GOString *name = NULL, *data_field_name = NULL;
 	GnmCellPos	 first_data;
 	GnmRange	 range;
-	GODataCache	*cache = NULL;
+	GODataCache	*cache;
 
 	XL_CHECK_CONDITION (q->length >= 44);
 	xls_read_range16 (&range, q->data);
 	first_header_row	= GSF_LE_GET_GINT16 (q->data +  8);
 	first_data.row		= GSF_LE_GET_GINT16 (q->data + 10);
 	first_data.col		= GSF_LE_GET_GINT16 (q->data + 12);
-	cache_id		= GSF_LE_GET_GINT16 (q->data + 14) + 1;
+	cache_idx		= GSF_LE_GET_GINT16 (q->data + 14);
 	data_field_axis		= GSF_LE_GET_GUINT16 (q->data + 18); /* Default axis for a data field */
 	data_field_pos		= GSF_LE_GET_GUINT16 (q->data + 20); /* Default position for a data field */
 	num_fields		= GSF_LE_GET_GUINT16 (q->data + 22); /* Number of fields */
@@ -747,8 +739,10 @@ xls_read_SXVIEW (BiffQuery *q, ExcelReadSheet *esheet)
 	name_len		= GSF_LE_GET_GINT16 (q->data + 40);
 	data_field_name_len	= GSF_LE_GET_GINT16 (q->data + 42);
 
-	if (cache_id < imp->pivot.cache_by_id->len)
-		cache = g_ptr_array_index (imp->pivot.cache_by_id, cache_id);
+	cache = (cache_idx < imp->pivot.cache_by_index->len
+		 ? g_ptr_array_index (imp->pivot.cache_by_index, cache_idx)
+		 : NULL);
+
 	name = go_string_new_nocopy (
 		excel_get_text (imp, q->data + 44, name_len,
 			       &len, q->length - 44));
diff --git a/src/go-data-cache-field.c b/src/go-data-cache-field.c
index 2b0d6d9..e72c98d 100644
--- a/src/go-data-cache-field.c
+++ b/src/go-data-cache-field.c
@@ -213,21 +213,20 @@ go_data_cache_field_get_val (GODataCacheField const *field, unsigned int record_
 
 	p = go_data_cache_records_index (field->cache, record_num) + field->offset;
 	switch (field->ref_type) {
-	case GO_DATA_CACHE_FIELD_TYPE_NONE   : return NULL;
-	case GO_DATA_CACHE_FIELD_TYPE_INLINE : return *((GOVal **)p);
-	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I8  : 
-		g_return_val_if_fail (field->offset > 0, NULL);
+	case GO_DATA_CACHE_FIELD_TYPE_NONE:
+		return NULL;
+	case GO_DATA_CACHE_FIELD_TYPE_INLINE:
+		return *((GOVal **)p);
+	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I8:
 		idx = *(guint8 *)p; 
 		break;
-	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I16 : 
-		g_return_val_if_fail (field->offset > 0, NULL);
+	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I16:
 		idx = *(guint16 *)p; 
 		break;
-	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I32 : 
-		g_return_val_if_fail (field->offset > 0, NULL);
+	case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I32:
 		idx = *(guint32 *)p; 
 		break;
-	default :
+	default:
 		g_warning ("unknown field type %d", field->ref_type);
 		return NULL;
 	}



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