[gnumeric] xlsx: code cleanup.



commit 13e296f9d6886aaaab262c962cd3881358fea889
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 15 08:06:34 2015 -0400

    xlsx: code cleanup.

 plugins/excel/ChangeLog        |    4 ++
 plugins/excel/ms-excel-util.c  |   68 ++++++++++++++++++++++++++++++++++++++++
 plugins/excel/ms-excel-util.h  |    8 +++++
 plugins/excel/ms-excel-write.c |   63 +-----------------------------------
 plugins/excel/ms-excel-write.h |    8 -----
 plugins/excel/xlsx-write.c     |    2 +-
 6 files changed, 83 insertions(+), 70 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 85ac6cf..aaa56d8 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,9 @@
 2015-04-15  Morten Welinder  <terra gnome org>
 
+       * ms-excel-util.c (xls_collect_validations): Rename from
+       excel_collect_validations and move from ms-excel-write.c.
+       Sort ranges.
+
        * xlsx-write.c (xlsx_write_validations): Impose an ordering of
        validation entries.
 
diff --git a/plugins/excel/ms-excel-util.c b/plugins/excel/ms-excel-util.c
index b5a6ba0..5da6395 100644
--- a/plugins/excel/ms-excel-util.c
+++ b/plugins/excel/ms-excel-util.c
@@ -938,4 +938,72 @@ xls_collect_hlinks (GnmStyleList *sl, int max_col, int max_row)
        return group;
 }
 
+/****************************************************************************/
+
+static guint
+vip_hash (XLValInputPair const *vip)
+{
+       /* bogus, but who cares */
+       return GPOINTER_TO_UINT (vip->v) ^ GPOINTER_TO_UINT (vip->msg);
+}
+
+static gint
+vip_equal (XLValInputPair const *a, XLValInputPair const *b)
+{
+       return a->v == b->v && a->msg == b->msg;
+}
+
+static void
+vip_free (XLValInputPair *vip)
+{
+       g_slist_free (vip->ranges);
+       g_free (vip);
+}
+
+/* We store input msg and validation as distinct items, XL merges them find the
+ * pairs, and the regions that use them */
+GHashTable *
+xls_collect_validations (GnmStyleList *ptr, int max_col, int max_row)
+{
+       GHashTable *group = g_hash_table_new_full
+               ((GHashFunc)vip_hash,
+                (GCompareFunc)vip_equal,
+                (GDestroyNotify)vip_free,
+                NULL);
+       GHashTableIter iter;
+       gpointer vip_;
+
+       for (; ptr != NULL ; ptr = ptr->next) {
+               GnmStyleRegion const *sr = ptr->data;
+               XLValInputPair key, *tmp;
+
+               /* Clip here to avoid creating a DV record if there are no regions */
+               if (sr->range.start.col >= max_col ||
+                   sr->range.start.row >= max_row) {
+                       range_dump (&sr->range, "bounds drop\n");
+                       continue;
+               }
+
+               key.v   = gnm_style_get_validation (sr->style);
+               key.msg = gnm_style_get_input_msg (sr->style);
+               tmp = g_hash_table_lookup (group, &key);
+               if (tmp == NULL) {
+                       tmp = g_new (XLValInputPair, 1);
+                       tmp->v = key.v;
+                       tmp->msg = key.msg;
+                       tmp->ranges = NULL;
+                       g_hash_table_insert (group, tmp, tmp);
+               }
+               tmp->ranges = g_slist_prepend (tmp->ranges, (gpointer)&sr->range);
+       }
+
+       g_hash_table_iter_init (&iter, group);
+       while (g_hash_table_iter_next (&iter, &vip_, NULL)) {
+               XLValInputPair *vip = vip_;
+               vip->ranges = g_slist_sort (vip->ranges, (GCompareFunc)gnm_range_compare);
+       }
+
+       return group;
+}
+
 /*****************************************************************************/
diff --git a/plugins/excel/ms-excel-util.h b/plugins/excel/ms-excel-util.h
index 9cd0341..87fb1f6 100644
--- a/plugins/excel/ms-excel-util.h
+++ b/plugins/excel/ms-excel-util.h
@@ -125,6 +125,14 @@ void xls_arrow_from_xl (GOArrow *arrow, double width,
 
 GHashTable *xls_collect_hlinks (GnmStyleList *sl, int max_col, int max_row);
 
+typedef struct {
+       GnmValidation const *v;
+       GnmInputMsg *msg;
+       GSList      *ranges;
+} XLValInputPair;
+GHashTable *xls_collect_validations  (GnmStyleList *ptr,
+                                     int max_col, int max_row);
+
 /*****************************************************************************/
 
 #endif /* GNM_MS_EXCEL_UTIL_H */
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 719cc30..acd4f1d 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -1714,7 +1714,7 @@ excel_write_DVALs (BiffPut *bp, ExcelWriteSheet *esheet)
        if (NULL == (ptr = esheet->validations))
                return;
 
-       group = excel_collect_validations (ptr,
+       group = xls_collect_validations (ptr,
                        esheet->max_col, esheet->max_row);
 
        i = g_hash_table_size (group);
@@ -6800,66 +6800,7 @@ excel_write_state_free (ExcelWriteState *ewb)
        g_free (ewb);
 }
 
-/****************************************************************************/
-
-static guint
-vip_hash (XLValInputPair const *vip)
-{
-       /* bogus, but who cares */
-       return GPOINTER_TO_UINT (vip->v) ^ GPOINTER_TO_UINT (vip->msg);
-}
-
-static gint
-vip_equal (XLValInputPair const *a, XLValInputPair const *b)
-{
-       return a->v == b->v && a->msg == b->msg;
-}
-
-static void
-vip_free (XLValInputPair *vip)
-{
-       g_slist_free (vip->ranges);
-       g_free (vip);
-}
-
-/* We store input msg and validation as distinct items, XL merges them find the
- * pairs, and the regions that use them */
-GHashTable *
-excel_collect_validations (GnmStyleList *ptr, int max_col, int max_row)
-{
-       GnmStyleRegion const *sr;
-       XLValInputPair key, *tmp;
-       GHashTable *group = g_hash_table_new_full
-               ((GHashFunc)vip_hash,
-                (GCompareFunc)vip_equal,
-                (GDestroyNotify)vip_free,
-                NULL);
-
-       for (; ptr != NULL ; ptr = ptr->next) {
-               sr = ptr->data;
-
-               /* Clip here to avoid creating a DV record if there are no regions */
-               if (sr->range.start.col >= max_col ||
-                   sr->range.start.row >= max_row) {
-                       range_dump (&sr->range, "bounds drop\n");
-                       continue;
-               }
-
-               key.v   = gnm_style_get_validation (sr->style);
-               key.msg = gnm_style_get_input_msg (sr->style);
-               tmp = g_hash_table_lookup (group, &key);
-               if (tmp == NULL) {
-                       tmp = g_new (XLValInputPair, 1);
-                       tmp->v = key.v;
-                       tmp->msg = key.msg;
-                       tmp->ranges = NULL;
-                       g_hash_table_insert (group, tmp, tmp);
-               }
-               tmp->ranges = g_slist_prepend (tmp->ranges, (gpointer)&sr->range);
-       }
-
-       return group;
-}
+/*****************************************************************************/
 
 GHashTable *
 excel_collect_pivot_caches (Workbook const *wb)
diff --git a/plugins/excel/ms-excel-write.h b/plugins/excel/ms-excel-write.h
index b274bce..f3e970d 100644
--- a/plugins/excel/ms-excel-write.h
+++ b/plugins/excel/ms-excel-write.h
@@ -158,14 +158,6 @@ int excel_write_get_externsheet_idx (ExcelWriteState *wb,
 
 int excel_write_map_errcode (GnmValue const *v);
 
-/* Shared with xlsx export */
-typedef struct {
-       GnmValidation const *v;
-       GnmInputMsg *msg;
-       GSList      *ranges;
-} XLValInputPair;
-GHashTable *excel_collect_validations  (GnmStyleList *ptr,
-                                       int max_col, int max_row);
 GHashTable *excel_collect_pivot_caches (Workbook const *wb);
 
 void excel_sheet_extent (Sheet const *sheet, GnmRange *extent, GnmStyle **col_styles,
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 704c57a..8cef02f 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -2040,7 +2040,7 @@ xlsx_write_validations (XLSXWriteState *state, GsfXMLOut *xml, G_GNUC_UNUSED Gnm
                XLSXClosure info = { state, xml };
                /* filter on logical max, not extent.  XL allows validations
                 * past the stated dimension */
-               GHashTable *group = excel_collect_validations (validations,
+               GHashTable *group = xls_collect_validations (validations,
                        XLSX_MAX_COLS, XLSX_MAX_ROWS);
 
                gsf_xml_out_start_element (xml, "dataValidations");


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