[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_9_1-60-g751791e

Rémi Cardona nobody at users.sourceforge.net
Sun May 22 02:11:08 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grisbi".

The branch, master has been updated
       via  751791e2919e321d19436a922aebc5ccd09d501b (commit)
       via  7847f9f1d8c89f2e1ebb731f5bf0dfa9dac1df89 (commit)
       via  d07218c9f81d5731a02569eda7272077b537de39 (commit)
       via  03836d27d0f652c8c678830404cd98ab4e13cf99 (commit)
       via  3073528a03dd163bed483cc4664a2aa202167009 (commit)
       via  fd6e85321417ee54b09d6c02fb24c3b06d214c05 (commit)
       via  434af00f9272345f1705fad7a101183892eee024 (commit)
       via  2e6ab292989a34df99ee2dc28ea0926a41d8253e (commit)
       via  e1adb1127f9409fe2989eb83da1ecbf6a11693a3 (commit)
       via  84ce96eae483d4f7b84d7c70034b5eb071e4ce61 (commit)
      from  93db2a5e7da540c0691664779c6e67bdd440dad8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 751791e2919e321d19436a922aebc5ccd09d501b
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 18:23:22 2011 +0200

    gsb_real: delete wrapper functions gsb_real_{get,set}_{decimal_point,thousands_sep}

commit 7847f9f1d8c89f2e1ebb731f5bf0dfa9dac1df89
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 09:03:10 2011 +0200

    gsb_real: remove the 2 static variables, everything is now stored using gsb_locale

commit d07218c9f81d5731a02569eda7272077b537de39
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 09:12:23 2011 +0200

    gsb_real: fix gsb_real_raw_format_string() to get all the locale-specific info from the given locale argument
    
    Since the previous commit (22558e88c2ac), gsb_locale_get_locale() returns
    whatever thousands_sep/decimal_point was chosen using the
    gsb_locale_get/set functions.
    
    The overall behavior of grisbi is unchanged but this fixes a number of
    issues, including that of testability. gsb_real_raw_format_string() now
    behaves as intended - it respects its 'locale' argument - and no longer
    depends on outside variables to do its job properly.

commit 03836d27d0f652c8c678830404cd98ab4e13cf99
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 09:01:03 2011 +0200

    gsb_real: save the locale changes using gsb_locale
    
    The 2 static variables in gsb_real.c are still updated as the rest of the
    code that uses them is not yet using gsb_locale.
    
    Right now, this doesn't change anything for the rest of grisbi as nothing
    reads decimal_point or thousands_sep using gsb_locale_get_locale().

commit 3073528a03dd163bed483cc4664a2aa202167009
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 01:07:15 2011 +0200

    gsb_locale: allow getting/setting the monetary decimal point and thousands separator characters

commit fd6e85321417ee54b09d6c02fb24c3b06d214c05
Author: Rémi Cardona <remi at gentoo.org>
Date:   Thu May 19 11:42:59 2011 +0200

    Rename variables 'conv' to 'locale'

commit 434af00f9272345f1705fad7a101183892eee024
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 10:59:22 2011 +0200

    Use gsb_locale_get_locale() instead of localeconv()

commit 2e6ab292989a34df99ee2dc28ea0926a41d8253e
Author: Rémi Cardona <remi at gentoo.org>
Date:   Fri May 20 10:59:15 2011 +0200

    Add new gsb_locale files which will hold all locale-related functions, unused for now

commit e1adb1127f9409fe2989eb83da1ecbf6a11693a3
Author: Rémi Cardona <remi at gentoo.org>
Date:   Thu May 19 18:58:55 2011 +0200

    gsb_real: simplify gsb_real_set_decimal_point() and gsb_real_set_thousands_sep()
    
    Both g_free() and g_strdup() are NULL-safe. Further more, this fixes a
    potential memory leak if either function was called with a zero-length
    string.

commit 84ce96eae483d4f7b84d7c70034b5eb071e4ce61
Author: Rémi Cardona <remi at gentoo.org>
Date:   Thu May 19 10:04:52 2011 +0200

    gsb_real: use NULL instead of FALSE in gsb_real_get_string()
    
    Both mean 0 but since the 3rd argument of the called function is a pointer
    type, FALSE is semantically wrong.

-----------------------------------------------------------------------

Changes:
diff --git a/src/Makefile.am b/src/Makefile.am
index 1c25d53..25e21c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -101,6 +101,7 @@ libgrisbi_la_SOURCES = \
 	gsb_form_widget.c	\
 	gsb_fyear.c		\
 	gsb_fyear_config.c	\
+	gsb_locale.c	\
 	gsb_payment_method.c	\
 	gsb_payment_method_config.c	\
 	gsb_plugins.c		\
@@ -237,6 +238,7 @@ libgrisbi_la_SOURCES = \
 	gsb_form_widget.h	\
 	gsb_fyear.h		\
 	gsb_fyear_config.h	\
+	gsb_locale.h	\
 	gsb_payment_method.h	\
 	gsb_payment_method_config.h	\
     gsb_plugins.h           \
diff --git a/src/gsb_assistant_account.c b/src/gsb_assistant_account.c
index 40dcc0f..77bcc88 100644
--- a/src/gsb_assistant_account.c
+++ b/src/gsb_assistant_account.c
@@ -44,6 +44,7 @@
 #include "gsb_data_account.h"
 #include "gsb_data_bank.h"
 #include "gsb_data_currency.h"
+#include "gsb_locale.h"
 #include "gsb_real.h"
 #include "gsb_select_icon.h"
 #include "utils.h"
@@ -224,7 +225,7 @@ static GtkWidget *gsb_assistant_account_page_3 ( GtkWidget *assistant )
     GtkWidget *page, *label, *button, *table;
     GtkWidget *align;
     GtkWidget *image;
-    struct lconv * conv = localeconv();
+    struct lconv *locale = gsb_locale_get_locale ( );
 
     page = gtk_hbox_new (FALSE, 15);
     gtk_container_set_border_width ( GTK_CONTAINER (page),
@@ -250,7 +251,7 @@ static GtkWidget *gsb_assistant_account_page_3 ( GtkWidget *assistant )
      * this would confuse US folks while rest of the world is used to
      * configure stuff to their locale.  */
     if ( ! gsb_data_currency_get_default_currency () &&
-	 ! gsb_currency_config_create_currency_from_iso4217list ( conv -> int_curr_symbol ) )
+	 ! gsb_currency_config_create_currency_from_iso4217list ( locale -> int_curr_symbol ) )
     {
 	gsb_currency_config_create_currency_from_iso4217list ( "USD" );
     }
diff --git a/src/gsb_currency_config.c b/src/gsb_currency_config.c
index b54ba22..babb8b7 100644
--- a/src/gsb_currency_config.c
+++ b/src/gsb_currency_config.c
@@ -43,6 +43,7 @@
 #include "gsb_data_currency.h"
 #include "gsb_data_scheduled.h"
 #include "gsb_data_transaction.h"
+#include "gsb_locale.h"
 #include "main.h"
 #include "traitement_variables.h"
 #include "utils.h"
@@ -1376,7 +1377,7 @@ gboolean gsb_currency_config_select_currency_popup ( GtkTreeSelection *selection
 gboolean gsb_currency_config_select_default ( GtkTreeModel * tree_model, GtkTreePath * path,
                         GtkTreeIter * iter, GtkTreeView * tree_view )
 {
-    struct lconv * conv = localeconv();
+    struct lconv *locale = gsb_locale_get_locale ( );
     gchar * code, * symbol, * country;
     gboolean good = FALSE, main_currency;
 
@@ -1385,9 +1386,9 @@ gboolean gsb_currency_config_select_default ( GtkTreeModel * tree_model, GtkTree
 			 COUNTRY_NAME_COLUMN, &country,
 			 CURRENCY_MAIN_CURRENCY_COLUMN, &main_currency,
 			 -1 );
-    if ( conv && conv -> int_curr_symbol && strlen ( conv -> int_curr_symbol ) )
+    if ( locale && locale -> int_curr_symbol && strlen ( locale -> int_curr_symbol ) )
     {
-	symbol = g_strdup ( conv -> int_curr_symbol );
+	symbol = g_strdup ( locale -> int_curr_symbol );
 	g_strstrip ( symbol );
 	/* When matching, weed out currencies that are not "main"
 	 * currency, that is for example, do not match USD on Panama
@@ -1411,7 +1412,7 @@ gboolean gsb_currency_config_select_default ( GtkTreeModel * tree_model, GtkTree
     if ( good )
     {
         gchar* tmpstr = g_strdup_printf ( "found '%s'",
-					conv -> int_curr_symbol );
+					locale -> int_curr_symbol );
 	devel_debug ( tmpstr );
 	g_free ( tmpstr );
 	gtk_tree_selection_select_path ( gtk_tree_view_get_selection ( tree_view ), path );
diff --git a/src/gsb_file_load.c b/src/gsb_file_load.c
index 80f437a..afaff6e 100644
--- a/src/gsb_file_load.c
+++ b/src/gsb_file_load.c
@@ -65,6 +65,7 @@
 #include "gsb_data_transaction.h"
 #include "gsb_file.h"
 #include "gsb_file_util.h"
+#include "gsb_locale.h"
 #include "gsb_plugins.h"
 #include "gsb_real.h"
 #include "gsb_select_icon.h"
@@ -794,15 +795,15 @@ void gsb_file_load_general_part ( const gchar **attribute_names,
 
     else if ( !strcmp ( attribute_names[i], "Decimal_point" ) )
     {
-        gsb_real_set_decimal_point ( attribute_values[i] );
+        gsb_locale_set_mon_decimal_point ( attribute_values[i] );
     }
 
     else if ( !strcmp ( attribute_names[i], "Thousands_separator" ) )
     {
         if ( !strcmp ( attribute_values[i], "empty" ) )
-            gsb_real_set_thousands_sep ( NULL );
+            gsb_locale_set_mon_thousands_sep ( NULL );
         else
-            gsb_real_set_thousands_sep ( attribute_values[i] );
+            gsb_locale_set_mon_thousands_sep ( attribute_values[i] );
     }
 
     else if ( !strcmp ( attribute_names[i],
diff --git a/src/gsb_file_save.c b/src/gsb_file_save.c
index 4e11752..8ae9f83 100644
--- a/src/gsb_file_save.c
+++ b/src/gsb_file_save.c
@@ -69,6 +69,7 @@
 #include "gsb_file.h"
 #include "utils_dates.h"
 #include "navigation.h"
+#include "gsb_locale.h"
 #include "gsb_plugins.h"
 #include "gsb_real.h"
 #include "gsb_select_icon.h"
@@ -712,8 +713,8 @@ gulong gsb_file_save_general_part ( gulong iterator,
 
     /* save localization data */
     date_format = gsb_date_get_format_date ( );
-    mon_decimal_point = gsb_real_get_decimal_point ( );
-    mon_thousands_sep = gsb_real_get_thousands_sep ( );
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
+    mon_thousands_sep = gsb_locale_get_mon_thousands_sep ( );
     if ( mon_thousands_sep == NULL )
         mon_thousands_sep = g_strdup ( "empty" );
 
diff --git a/src/gsb_form.c b/src/gsb_form.c
index 85eb89f..82da854 100644
--- a/src/gsb_form.c
+++ b/src/gsb_form.c
@@ -60,6 +60,7 @@
 #include "gsb_form_transaction.h"
 #include "gsb_form_widget.h"
 #include "gsb_fyear.h"
+#include "gsb_locale.h"
 #include "navigation.h"
 #include "menu.h"
 #include "tiers_onglet.h"
@@ -1836,7 +1837,7 @@ void gsb_form_check_auto_separator ( GtkWidget *entry )
     account_number = gsb_form_get_account_number ();
     floating_point = gsb_data_currency_get_floating_point (gsb_data_account_get_currency (account_number));
 
-    mon_decimal_point = gsb_real_get_decimal_point ( );
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
     decimal_point = g_utf8_get_char_validated ( mon_decimal_point, -1 );
 
     if ( g_utf8_strchr (string, -1, decimal_point ) )
diff --git a/src/gsb_form_widget.c b/src/gsb_form_widget.c
index c41e07f..094740e 100644
--- a/src/gsb_form_widget.c
+++ b/src/gsb_form_widget.c
@@ -46,6 +46,7 @@
 #include "gsb_form.h"
 #include "gsb_form_transaction.h"
 #include "gsb_fyear.h"
+#include "gsb_locale.h"
 #include "gsb_payment_method.h"
 #include "gtk_combofix.h"
 #include "gsb_data_payment.h"
@@ -988,9 +989,9 @@ gboolean gsb_form_widget_get_valide_amout_entry ( const gchar *string )
      ( g_utf8_strchr ( ptr, -1, '*' ) && g_utf8_strchr ( ptr, -1, '-' ) ) )
         return FALSE;
 
-    mon_decimal_point = gsb_real_get_decimal_point ( );
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
     decimal_point = g_utf8_get_char_validated ( mon_decimal_point, -1 );
-    mon_thousands_sep = gsb_real_get_thousands_sep ( );
+    mon_thousands_sep = gsb_locale_get_mon_thousands_sep ( );
     if ( mon_thousands_sep )
         thousands_sep = g_utf8_get_char_validated ( mon_thousands_sep, -1 );
 
@@ -1214,8 +1215,8 @@ gboolean gsb_form_widget_amount_entry_validate ( gint element_number )
         return TRUE;
     }
 
-    mon_decimal_point = gsb_real_get_decimal_point ( );
-    if ( g_strrstr ( text, gsb_real_get_decimal_point ( ) ) == NULL )
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
+    if ( g_strrstr ( text, gsb_locale_get_mon_decimal_point ( ) ) == NULL )
         tmp_str = g_strconcat ( text, mon_decimal_point, NULL );
     else
         tmp_str= g_strdup ( text );
diff --git a/src/gsb_locale.c b/src/gsb_locale.c
new file mode 100644
index 0000000..6f2b121
--- /dev/null
+++ b/src/gsb_locale.c
@@ -0,0 +1,106 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*     Copyright (C)         2011 Grisbi Development Team                     */
+/*             http://www.grisbi.org                                          */
+/*                                                                            */
+/*  This program is free software; you can redistribute it and/or modify      */
+/*  it under the terms of the GNU General Public License as published by      */
+/*  the Free Software Foundation; either version 2 of the License, or         */
+/*  (at your option) any later version.                                       */
+/*                                                                            */
+/*  This program is distributed in the hope that it will be useful,           */
+/*  but WITHOUT ANY WARRANTY; without even the implied warranty of            */
+/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
+/*  GNU General Public License for more details.                              */
+/*                                                                            */
+/*  You should have received a copy of the GNU General Public License         */
+/*  along with this program; if not, write to the Free Software               */
+/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include "include.h"
+#include "gsb_locale.h"
+
+static struct lconv *_locale = NULL;
+
+
+void gsb_locale_init ( void )
+{
+    struct lconv *locale;
+
+    locale = localeconv ( );
+
+    _locale = g_malloc ( sizeof (*_locale) );
+    _locale -> decimal_point     = g_strdup ( locale -> decimal_point );
+    _locale -> thousands_sep     = g_strdup ( locale -> thousands_sep );
+    _locale -> grouping          = g_strdup ( locale -> grouping );
+    _locale -> int_curr_symbol   = g_strdup ( locale -> int_curr_symbol );
+    _locale -> currency_symbol   = g_strdup ( locale -> currency_symbol );
+    _locale -> mon_decimal_point = g_strdup ( locale -> mon_decimal_point );
+    _locale -> mon_thousands_sep = g_strdup ( locale -> mon_thousands_sep );
+    _locale -> mon_grouping      = g_strdup ( locale -> mon_grouping );
+    _locale -> positive_sign     = g_strdup ( locale -> positive_sign );
+    _locale -> negative_sign     = g_strdup ( locale -> negative_sign );
+    _locale -> int_frac_digits   = locale -> int_frac_digits;
+    _locale -> frac_digits       = locale -> frac_digits;
+    _locale -> p_cs_precedes     = locale -> p_cs_precedes;
+    _locale -> p_sep_by_space    = locale -> p_sep_by_space;
+    _locale -> n_cs_precedes     = locale -> n_cs_precedes;
+    _locale -> n_sep_by_space    = locale -> n_sep_by_space;
+    _locale -> p_sign_posn       = locale -> p_sign_posn;
+    _locale -> n_sign_posn       = locale -> n_sign_posn;
+}
+
+
+void gsb_locale_shutdown ( void )
+{
+    g_free ( _locale -> decimal_point );
+    g_free ( _locale -> thousands_sep );
+    g_free ( _locale -> grouping );
+    g_free ( _locale -> int_curr_symbol );
+    g_free ( _locale -> currency_symbol );
+    g_free ( _locale -> mon_decimal_point );
+    g_free ( _locale -> mon_thousands_sep );
+    g_free ( _locale -> mon_grouping );
+    g_free ( _locale -> positive_sign );
+    g_free ( _locale -> negative_sign );
+    g_free ( _locale );
+}
+
+
+struct lconv *gsb_locale_get_locale ( void )
+{
+    return _locale;
+}
+
+
+gchar *gsb_locale_get_mon_decimal_point ( void )
+{
+    return g_strdup ( _locale -> mon_decimal_point );
+}
+
+
+void gsb_locale_set_mon_decimal_point ( const gchar *decimal_point )
+{
+    g_free ( _locale -> mon_decimal_point );
+    _locale -> mon_decimal_point = g_strdup ( decimal_point );
+}
+
+
+gchar *gsb_locale_get_mon_thousands_sep ( void )
+{
+    return g_strdup ( _locale -> mon_thousands_sep );
+}
+
+
+void gsb_locale_set_mon_thousands_sep ( const gchar *thousands_sep )
+{
+    g_free ( _locale -> mon_thousands_sep );
+    _locale -> mon_thousands_sep = g_strdup ( thousands_sep );
+}
diff --git a/src/gsb_locale.h b/src/gsb_locale.h
new file mode 100644
index 0000000..d6f99de
--- /dev/null
+++ b/src/gsb_locale.h
@@ -0,0 +1,15 @@
+#ifndef _GSB_LOCALE_H
+#define _GSB_LOCALE_H
+
+#include <locale.h>
+#include <glib.h>
+
+void          gsb_locale_init       ( void );
+void          gsb_locale_shutdown   ( void );
+struct lconv *gsb_locale_get_locale ( void );
+gchar        *gsb_locale_get_mon_decimal_point ( void );
+void          gsb_locale_set_mon_decimal_point ( const gchar *decimal_point );
+gchar        *gsb_locale_get_mon_thousands_sep ( void );
+void          gsb_locale_set_mon_thousands_sep ( const gchar *thousands_sep );
+
+#endif
diff --git a/src/gsb_real.c b/src/gsb_real.c
index 4e4b0e5..ef7efe3 100644
--- a/src/gsb_real.c
+++ b/src/gsb_real.c
@@ -41,15 +41,13 @@
 #include <assert.h>
 
 /*START_INCLUDE*/
+#include "gsb_locale.h"
 #include "gsb_real.h"
 /*END_INCLUDE*/
 
 gsb_real null_real = { 0 , 0 };
 gsb_real error_real = { G_MININT64, 0 };
 
-static gchar *gsb_thousands_sep;
-static gchar *gsb_decimal_point;
-
 glong gsb_real_power_10[] = { 1, 10, 100, 1000, 10000, 100000,
                             1000000, 10000000, 100000000, 1000000000 };
 
@@ -85,9 +83,9 @@ static gboolean gsb_real_raw_truncate_number ( gint64 *mantissa, gint *exponent
 */
 gchar *gsb_real_get_string ( gsb_real number )
 {
-    struct lconv *conv = localeconv ();
+    struct lconv *locale = gsb_locale_get_locale ();
 
-    return gsb_real_raw_format_string ( number, conv, FALSE );
+    return gsb_real_raw_format_string ( number, locale, NULL );
 }
 
 
@@ -97,14 +95,14 @@ gchar *gsb_real_get_string ( gsb_real number )
  * thousands separator and positive or negative sign.
  * 
  * \param number		    Number to format.
- * \param conv      		the locale obtained with localeconv(), or built manually
+ * \param locale      		the locale obtained with localeconv(), or built manually
  * \param currency_symbol 	the currency symbol
  *
  * \return		A newly allocated string of the number (this
  *			function will never return NULL) 
  */
 gchar *gsb_real_raw_format_string (gsb_real number,
-                        struct lconv *conv,
+                        struct lconv *locale,
                         const gchar *currency_symbol )
 {
     gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
@@ -119,12 +117,12 @@ gchar *gsb_real_raw_format_string (gsb_real number,
     gint nbre_char;
 	lldiv_t units;
 /*printf ("currency_symbol = %s\n", currency_symbol);*/
-    cs_start = (currency_symbol && conv->p_cs_precedes) ? currency_symbol : "";
-    cs_start_space = (currency_symbol && conv->p_cs_precedes && conv->p_sep_by_space) ? " " : "";
-    sign = (number.mantissa < 0) ? conv->negative_sign : conv->positive_sign;
-    mon_decimal_point = gsb_decimal_point;
-    cs_end_space = (currency_symbol && !conv->p_cs_precedes && conv->p_sep_by_space) ? " " : "";
-    cs_end = (currency_symbol && !conv->p_cs_precedes) ? currency_symbol : "";
+    cs_start = (currency_symbol && locale->p_cs_precedes) ? currency_symbol : "";
+    cs_start_space = (currency_symbol && locale->p_cs_precedes && locale->p_sep_by_space) ? " " : "";
+    sign = (number.mantissa < 0) ? locale->negative_sign : locale->positive_sign;
+    mon_decimal_point = locale->mon_decimal_point && *locale->mon_decimal_point ? locale->mon_decimal_point : "";
+    cs_end_space = (currency_symbol && !locale->p_cs_precedes && locale->p_sep_by_space) ? " " : "";
+    cs_end = (currency_symbol && !locale->p_cs_precedes) ? currency_symbol : "";
     
     units = lldiv ( llabs (number.mantissa), gsb_real_power_10[number.exponent] );
 
@@ -134,7 +132,7 @@ gchar *gsb_real_raw_format_string (gsb_real number,
 
     if ( units.quot >= 1000 )
     {
-        temp = gsb_real_add_thousands_sep ( temp, gsb_thousands_sep );
+        temp = gsb_real_add_thousands_sep ( temp, locale->mon_thousands_sep );
     }
 
     g_snprintf ( format, sizeof ( format ), "%s%d%s",
@@ -175,8 +173,13 @@ gchar *gsb_real_raw_format_string (gsb_real number,
 gsb_real gsb_real_get_from_string ( const gchar *string )
 {
     gsb_real result;
+    gchar *thousands_sep = gsb_locale_get_mon_thousands_sep ( );
+    gchar *decimal_point = gsb_locale_get_mon_decimal_point ( );
+
+    result =  gsb_real_raw_get_from_string ( string, thousands_sep, decimal_point );
 
-    result =  gsb_real_raw_get_from_string ( string, gsb_thousands_sep, gsb_decimal_point );
+    g_free ( decimal_point );
+    g_free ( thousands_sep );
 
     return result;
 }
@@ -992,67 +995,6 @@ gchar *gsb_real_add_thousands_sep ( gchar *str_number, const gchar *thousands_se
 }
 
 
-/**
- *
- * The returned string should be freed with g_free() when no longer needed.
- *
- *
- * */
-gchar *gsb_real_get_decimal_point ( void )
-{
-    return g_strdup ( gsb_decimal_point );
-}
-
-
-/**
- *
- *
- *
- *
- * */
-void gsb_real_set_decimal_point ( const gchar *decimal_point )
-{
-    if ( gsb_decimal_point && strlen ( gsb_decimal_point ) )
-        g_free ( gsb_decimal_point );
-
-    if ( decimal_point == NULL )
-        gsb_decimal_point = NULL;
-    else
-		gsb_decimal_point = g_strdup ( decimal_point );
-}
-
-
-/**
- *
- * The returned string should be freed with g_free() when no longer needed.
- *
- *
- * */
-gchar *gsb_real_get_thousands_sep ( void )
-{
-    return g_strdup ( gsb_thousands_sep );
-}
-
-
-/**
- *
- *
- *
- *
- * */
-void gsb_real_set_thousands_sep ( const gchar *thousands_sep )
-{
-    if ( gsb_thousands_sep && strlen ( gsb_thousands_sep ) )
-        g_free ( gsb_thousands_sep );
-
-    if ( thousands_sep == NULL )
-        gsb_thousands_sep = NULL;
-    else
-        gsb_thousands_sep = g_strdup ( thousands_sep );
-}
-
-
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */
-
diff --git a/src/gsb_real.h b/src/gsb_real.h
index aef8982..b57811a 100644
--- a/src/gsb_real.h
+++ b/src/gsb_real.h
@@ -32,17 +32,15 @@ G_MODULE_EXPORT gint gsb_real_cmp ( gsb_real number_1,
 gsb_real gsb_real_div ( gsb_real number_1,
                         gsb_real number_2 );
 G_MODULE_EXPORT gsb_real gsb_real_double_to_real ( gdouble number );
-gchar *gsb_real_get_decimal_point ( void );
 gsb_real gsb_real_get_from_string ( const gchar *string );
 gchar *gsb_real_get_string ( gsb_real number );
-gchar *gsb_real_get_thousands_sep ( void );
 gsb_real gsb_real_mul ( gsb_real number_1,
                         gsb_real number_2 );
 gsb_real gsb_real_new ( gint64 mantissa, gint exponent );
 gboolean gsb_real_normalize ( gsb_real *number_1, gsb_real *number_2 );
 G_MODULE_EXPORT gsb_real gsb_real_opposite ( gsb_real number );
 gchar *gsb_real_raw_format_string (gsb_real number,
-                        struct lconv *conv,
+                        struct lconv *locale,
                         const gchar *currency_symbol );
 gsb_real gsb_real_raw_get_from_string ( const gchar *string,
                                         const gchar *mon_thousands_sep,
@@ -50,8 +48,6 @@ gsb_real gsb_real_raw_get_from_string ( const gchar *string,
 gdouble gsb_real_real_to_double ( gsb_real number );
 gsb_real gsb_real_safe_real_from_string ( const gchar *string );
 gchar *gsb_real_safe_real_to_string ( gsb_real number, gint default_exponent );
-void gsb_real_set_decimal_point ( const gchar *decimal_point );
-void gsb_real_set_thousands_sep ( const gchar *thousands_sep );
 gsb_real gsb_real_sub ( gsb_real number_1,
                         gsb_real number_2 );
 /* END_DECLARATION */
diff --git a/src/main.c b/src/main.c
index 019c4c1..9089145 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,6 +43,7 @@
 #include "gsb_dirs.h"
 #include "gsb_file.h"
 #include "gsb_file_config.h"
+#include "gsb_locale.h"
 #include "gsb_plugins.h"
 #include "gsb_status.h"
 #include "import.h"
@@ -143,6 +144,7 @@ int main ( int argc, char **argv )
         main_linux ( argc, argv );
     #endif /* GTKOSXAPPLICATION || linux */
 #endif /* _WIN32 */
+    gsb_locale_shutdown ( );
     gsb_dirs_shutdown ( );
 
 #if GSB_GMEMPROFILE
@@ -173,6 +175,8 @@ void main_linux ( int argc, char **argv )
     /* Setup locale/gettext */
     setlocale (LC_ALL, "");
 
+    gsb_locale_init ( );
+
 #if IS_DEVELOPMENT_VERSION == 1
     gsb_grisbi_print_environment_var ( );
 #endif
@@ -249,6 +253,8 @@ void main_mac_osx ( int argc, char **argv )
     /* Setup locale/gettext */
     setlocale (LC_ALL, "");
 
+    gsb_locale_init ( );
+
     /* on commence par détourner le signal SIGSEGV */
     gsb_grisbi_trappe_signal_sigsegv ( );
 
@@ -352,6 +358,8 @@ void main_win_32 (  int argc, char **argv )
     /* Setup locale/gettext */
     setlocale( LC_ALL, NULL );
 
+    gsb_locale_init ( );
+
     gtk_init ( &argc, &argv );
 
     win32_parse_gtkrc ( "gtkrc" );
diff --git a/src/parametres.c b/src/parametres.c
index 4fe38ae..f0b7d1c 100644
--- a/src/parametres.c
+++ b/src/parametres.c
@@ -53,6 +53,7 @@
 #include "gsb_file.h"
 #include "gsb_form_config.h"
 #include "gsb_fyear_config.h"
+#include "gsb_locale.h"
 #include "gsb_payment_method_config.h"
 #include "gsb_real.h"
 #include "gsb_reconcile_config.h"
@@ -1410,14 +1411,14 @@ GtkWidget *gsb_config_number_format_chosen ( GtkWidget *parent, gint sens )
         gtk_box_pack_start ( GTK_BOX ( hbox ), thou_hbox, FALSE, FALSE, 0 );
     }
 
-    mon_decimal_point = gsb_real_get_decimal_point ( );
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
     if ( strcmp ( mon_decimal_point, "," ) == 0 )
         gtk_combo_box_set_active ( GTK_COMBO_BOX ( dec_sep ), 1 );
     else
         gtk_combo_box_set_active ( GTK_COMBO_BOX ( dec_sep ), 0 );
     g_free ( mon_decimal_point );
 
-    mon_thousands_sep = gsb_real_get_thousands_sep ( );
+    mon_thousands_sep = gsb_locale_get_mon_thousands_sep ( );
     if ( mon_thousands_sep == NULL )
         gtk_combo_box_set_active ( GTK_COMBO_BOX ( thou_sep ), 3 );
     else if ( strcmp ( mon_thousands_sep, "." ) == 0 )
@@ -1464,20 +1465,20 @@ void gsb_localisation_decimal_point_changed ( GtkComboBox *widget, gpointer user
 
     if ( g_strcmp0 ( text, "," ) == 0 )
     {
-        gsb_real_set_decimal_point ( "," );
+        gsb_locale_set_mon_decimal_point ( "," );
 
         if ( g_strcmp0 ( gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combo_box ) ), "," ) == 0 )
         {
-            gsb_real_set_thousands_sep ( " " );
+            gsb_locale_set_mon_thousands_sep ( " " );
             gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ), 0 );
         }
     }
     else
     {
-        gsb_real_set_decimal_point ( "." );
+        gsb_locale_set_mon_decimal_point ( "." );
         if ( g_strcmp0 ( gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combo_box ) ), "." ) == 0 )
         {
-            gsb_real_set_thousands_sep ( "," );
+            gsb_locale_set_mon_thousands_sep ( "," );
             gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ), 2 );
         }
     }
@@ -1517,30 +1518,30 @@ void gsb_localisation_thousands_sep_changed ( GtkComboBox *widget, gpointer user
     
     if ( g_strcmp0 ( text, "' '" ) == 0 )
     {
-        gsb_real_set_thousands_sep ( " " );
+        gsb_locale_set_mon_thousands_sep ( " " );
     }
     else if ( g_strcmp0 ( text, "." ) == 0 )
     {
 
-        gsb_real_set_thousands_sep ( "." );
+        gsb_locale_set_mon_thousands_sep ( "." );
         if ( g_strcmp0 ( gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combo_box ) ), "." ) == 0 )
         {
-            gsb_real_set_decimal_point ( "," );
+            gsb_locale_set_mon_decimal_point ( "," );
             gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ), 1 );
         }
     }
     else if ( g_strcmp0 ( text, "," ) == 0 )
     {
 
-        gsb_real_set_thousands_sep ( "," );
+        gsb_locale_set_mon_thousands_sep ( "," );
         if ( g_strcmp0 ( gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combo_box ) ), "," ) == 0 )
         {
-            gsb_real_set_decimal_point ( "." );
+            gsb_locale_set_mon_decimal_point ( "." );
             gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo_box ), 0 );
         }
     }
     else
-        gsb_real_set_thousands_sep ( NULL );
+        gsb_locale_set_mon_thousands_sep ( NULL );
 
     /* reset capital */
     entry = bet_finance_get_capital_entry ( );
diff --git a/src/tests/gsb_real_cunit.c b/src/tests/gsb_real_cunit.c
index 3f61668..a35406a 100644
--- a/src/tests/gsb_real_cunit.c
+++ b/src/tests/gsb_real_cunit.c
@@ -37,6 +37,7 @@
 
 /* START_INCLUDE */
 #include "gsb_real_cunit.h"
+#include "gsb_locale.h"
 #include "gsb_real.h"
 #include "utils_str.h"
 /* END_INCLUDE */
@@ -88,6 +89,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
         result = setlocale(LC_MONETARY, "C");
         if (result != NULL)
         {
+            gsb_locale_init();
+
             gsb_real val = gsb_real_get_from_string("123.45");
             CU_ASSERT_EQUAL(12345, val.mantissa);
             CU_ASSERT_EQUAL(2, val.exponent);
@@ -95,6 +98,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
             val = gsb_real_get_from_string("21000000");
             CU_ASSERT_EQUAL(21000000, val.mantissa);
             CU_ASSERT_EQUAL(0, val.exponent);
+
+            gsb_locale_shutdown();
         }
 
         /* French test */
@@ -105,6 +110,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
             result = setlocale(LC_MONETARY, "fr_FR");
         if (result != NULL)
         {
+            gsb_locale_init();
+
             gsb_real val = gsb_real_get_from_string("123,45");
             CU_ASSERT_EQUAL(12345, val.mantissa);
             CU_ASSERT_EQUAL(2, val.exponent);
@@ -112,6 +119,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
             val = gsb_real_get_from_string("21000000");
             CU_ASSERT_EQUAL(21000000, val.mantissa);
             CU_ASSERT_EQUAL(0, val.exponent);
+
+            gsb_locale_shutdown();
         }
 
         /* English test */
@@ -124,6 +133,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
             result = setlocale(LC_MONETARY, "en_GB");
         if (result != NULL)
         {
+            gsb_locale_init();
+
             gsb_real val = gsb_real_get_from_string("123.45");
             CU_ASSERT_EQUAL(12345, val.mantissa);
             CU_ASSERT_EQUAL(2, val.exponent);
@@ -131,6 +142,8 @@ void gsb_real_cunit__gsb_real_get_from_string ( void )
             val = gsb_real_get_from_string("21 000 000");
             CU_ASSERT_EQUAL(21000000, val.mantissa);
             CU_ASSERT_EQUAL(0, val.exponent);
+
+            gsb_locale_shutdown();
         }
 
         /* Restore current locale and free memory */
diff --git a/src/traitement_variables.c b/src/traitement_variables.c
index aca0d45..526f463 100644
--- a/src/traitement_variables.c
+++ b/src/traitement_variables.c
@@ -65,6 +65,7 @@
 #include "gsb_form_scheduler.h"
 #include "gsb_form_widget.h"
 #include "gsb_fyear.h"
+#include "gsb_locale.h"
 #include "gsb_real.h"
 #include "gsb_report.h"
 #include "gsb_scheduler_list.h"
@@ -821,22 +822,22 @@ void initialise_number_separators ( void )
     struct lconv *conv;
     gchar *dec_point = NULL, *thousand_sep = NULL;
 
-    gsb_real_set_decimal_point ( NULL );
-    gsb_real_set_thousands_sep ( NULL );
+    gsb_locale_set_mon_decimal_point ( NULL );
+    gsb_locale_set_mon_thousands_sep ( NULL );
 
     conv = localeconv();
 
     if ( conv->mon_decimal_point && strlen ( conv->mon_decimal_point ) )
     {
         dec_point = g_locale_to_utf8 ( conv->mon_decimal_point, -1, NULL, NULL, NULL );
-        gsb_real_set_decimal_point ( dec_point );
+        gsb_locale_set_mon_decimal_point ( dec_point );
         g_free ( dec_point );
     }
     else
-        gsb_real_set_decimal_point ( "." );
+        gsb_locale_set_mon_decimal_point ( "." );
 
     thousand_sep = g_locale_to_utf8 ( conv->mon_thousands_sep, -1, NULL, NULL, NULL );
-    gsb_real_set_thousands_sep ( thousand_sep );
+    gsb_locale_set_mon_thousands_sep ( thousand_sep );
     g_free ( thousand_sep );
 }
 
diff --git a/src/utils_str.c b/src/utils_str.c
index a69e079..df0536b 100644
--- a/src/utils_str.c
+++ b/src/utils_str.c
@@ -36,6 +36,7 @@
 #include "utils_str.h"
 #include "gsb_data_report.h"
 #include "gsb_data_currency.h"
+#include "gsb_locale.h"
 /*END_INCLUDE*/
 
 /*START_STATIC*/
@@ -182,8 +183,8 @@ gchar *utils_str_localise_decimal_point_from_string ( const gchar *string )
     gchar *mon_separateur;
     gchar **tab;
 
-    mon_decimal_point = gsb_real_get_decimal_point ( );
-    mon_separateur = gsb_real_get_thousands_sep ( );
+    mon_decimal_point = gsb_locale_get_mon_decimal_point ( );
+    mon_separateur = gsb_locale_get_mon_thousands_sep ( );
 
     if ( ( ptr_1 = g_strstr_len ( string, -1, "," ) )
      &&
@@ -1036,7 +1037,7 @@ gchar *gsb_real_get_string_with_currency ( gsb_real number,
                         gint currency_number,
                         gboolean show_symbol )
 {
-    struct lconv *conv = localeconv ();
+    struct lconv *locale = gsb_locale_get_locale ( );
     gint floating_point;
 
     const gchar *currency_symbol = (currency_number && show_symbol)
@@ -1046,9 +1047,9 @@ gchar *gsb_real_get_string_with_currency ( gsb_real number,
     /* First of all if number = 0 I return 0 with the symbol of the currency if necessary */
     if (number.mantissa == 0)
     {
-        if (currency_symbol && conv -> p_cs_precedes)
+        if (currency_symbol && locale -> p_cs_precedes)
             return g_strdup_printf ( "%s %s", currency_symbol, "0" );
-        else if (currency_symbol && ! conv -> p_cs_precedes)
+        else if (currency_symbol && ! locale -> p_cs_precedes)
             return g_strdup_printf ( "%s %s", "0", currency_symbol );
         else
             return g_strdup ("0");
@@ -1064,7 +1065,7 @@ gchar *gsb_real_get_string_with_currency ( gsb_real number,
     if ( currency_number && number.exponent != floating_point )
         number = gsb_real_adjust_exponent ( number, floating_point );
 
-    return gsb_real_raw_format_string ( number, conv, currency_symbol );
+    return gsb_real_raw_format_string ( number, locale, currency_symbol );
 }
 
 


hooks/post-receive
-- 
grisbi


More information about the cvs mailing list