[goffice] Formats: change _go_format_builtins from variable to function.



commit eb459693e217dc720dbd6e7a75a3759d5e295547
Author: Morten Welinder <terra gnome org>
Date:   Sun Aug 11 15:55:03 2013 -0400

    Formats: change _go_format_builtins from variable to function.
    
    This avoids foo[] in the header.  That isn't allowed in C.

 ChangeLog                   |    6 ++++++
 NEWS                        |    1 +
 goffice/gtk/go-format-sel.c |    4 ++--
 goffice/utils/formats.c     |   34 +++++++++++++++++++---------------
 goffice/utils/go-format.c   |    8 ++++----
 goffice/utils/go-format.h   |    6 +++---
 6 files changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index de9db5d..35327c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-08-11  Morten Welinder  <terra gnome org>
+
+       * goffice/utils/formats.c (_go_format_builtins): Change from
+       variable to function.  Improve C standard compliance in the
+       process.
+
 2013-08-09  Jean Brefort  <jean brefort normalesup org>
 
        * goffice/canvas/goc-graph.c: fix build without gtk.
diff --git a/NEWS b/NEWS
index 0ab1996..80a388b 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Jean:
 
 Morten:
        * Add prescaling to go_linear_regression_leverage.  [#703381]
+       * Improve C standard compliance a tiny bit.
 
 --------------------------------------------------------------------------
 goffice 0.10.4:
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index 97994e2..c04409b 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -649,7 +649,7 @@ find_builtin (const char *fmtstr, int page, gboolean def)
        if (page == GO_FORMAT_UNKNOWN)
                return NULL;
 
-       candidates = _go_format_builtins[page];
+       candidates = _go_format_builtins (page);
        if (!candidates)
                return NULL;
 
@@ -900,7 +900,7 @@ stays:
                        select.stamp = 0;
                        gtk_list_store_clear (gfs->format.formats.model);
                        for (; start <= end ; ++start)
-                               fmt_dialog_init_fmt_list (gfs, _go_format_builtins[start],
+                               fmt_dialog_init_fmt_list (gfs, _go_format_builtins (start),
                                                          &select, fhash);
 
                        if  (page == FMT_CUSTOM) {
diff --git a/goffice/utils/formats.c b/goffice/utils/formats.c
index 24f0e7b..a9bedc9 100644
--- a/goffice/utils/formats.c
+++ b/goffice/utils/formats.c
@@ -114,21 +114,25 @@ fmts_text [] = {
        NULL,
 };
 
-/* Note: there is no entry for GO_FORMAT_UNKNOWN.  */
-char const * const * const
-_go_format_builtins[] = {
-       fmts_general,
-       fmts_number,
-       fmts_currency,
-       fmts_accounting,
-       fmts_date,
-       fmts_time,
-       fmts_percentage,
-       fmts_fraction,
-       fmts_science,
-       fmts_text,
-       NULL,                     /* GO_FORMAT_SPECIAL */
-       NULL                      /* GO_FORMAT_MARKUP */
+char const * const *
+_go_format_builtins(GOFormatFamily fam)
+{
+       switch (fam) {
+       case GO_FORMAT_GENERAL: return fmts_general;
+       case GO_FORMAT_NUMBER: return fmts_number;
+       case GO_FORMAT_CURRENCY: return fmts_currency;
+       case GO_FORMAT_ACCOUNTING: return fmts_accounting;
+       case GO_FORMAT_DATE: return fmts_date;
+       case GO_FORMAT_TIME: return fmts_time;
+       case GO_FORMAT_PERCENTAGE: return fmts_percentage;
+       case GO_FORMAT_FRACTION: return fmts_fraction;
+       case GO_FORMAT_SCIENTIFIC: return fmts_science;
+       case GO_FORMAT_TEXT: return fmts_text;
+       case GO_FORMAT_SPECIAL:
+       case GO_FORMAT_MARKUP:
+       default:
+               return NULL;
+       }
 };
 
 static void
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 8994627..f35c636 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -6506,7 +6506,7 @@ go_format_general (void)
 {
        if (!default_general_fmt)
                default_general_fmt = go_format_new_from_XL (
-                       _go_format_builtins[GO_FORMAT_GENERAL][0]);
+                       _go_format_builtins (GO_FORMAT_GENERAL)[0]);
        return default_general_fmt;
 }
 #endif
@@ -6560,7 +6560,7 @@ go_format_default_percentage (void)
 {
        if (!default_percentage_fmt)
                default_percentage_fmt = go_format_new_from_XL (
-                       _go_format_builtins[GO_FORMAT_PERCENTAGE][1]);
+                       _go_format_builtins (GO_FORMAT_PERCENTAGE) [1]);
        return default_percentage_fmt;
 }
 #endif
@@ -6571,7 +6571,7 @@ go_format_default_money (void)
 {
        if (!default_money_fmt)
                default_money_fmt = go_format_new_from_XL (
-                       _go_format_builtins[GO_FORMAT_CURRENCY][2]);
+                       _go_format_builtins (GO_FORMAT_CURRENCY)[2]);
        return default_money_fmt;
 }
 #endif
@@ -6582,7 +6582,7 @@ go_format_default_accounting (void)
 {
        if (!default_accounting_fmt)
                default_accounting_fmt = go_format_new_from_XL (
-                       _go_format_builtins[GO_FORMAT_ACCOUNTING][2]);
+                       _go_format_builtins (GO_FORMAT_ACCOUNTING)[2]);
        return default_accounting_fmt;
 }
 #endif
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index 435c962..5034cd3 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -33,7 +33,7 @@ G_BEGIN_DECLS
 #define GO_SUBSCRIPT_RISE -5000
 
 
-/* Keep these sequential, they are used as the index for _go_format_builtins */
+/* Keep these sequential.  */
 typedef enum {
        GO_FORMAT_UNKNOWN       = -1,
 
@@ -272,8 +272,8 @@ void go_format_foreach (GHFunc func, gpointer user_data);
 
 /*************************************************************************/
 
-/* Indexed by GOFormatFamily */
-GO_VAR_DECL char const * const * const _go_format_builtins [];
+char const * const *_go_format_builtins(GOFormatFamily fam);
+
 GO_VAR_DECL GOFormatCurrency     const _go_format_currencies [];
 
 GOFormatCurrency const *go_format_locale_currency (void);


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