From: John Darrington Date: Wed, 1 Apr 2009 00:43:07 +0000 (+0800) Subject: Refactor locale initialisation. X-Git-Tag: v0.7.3~187 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be89f5708c5ab602642d3d297f84e9f32931a2f2;p=pspp-builds.git Refactor locale initialisation. Created a common i18n_init function that both the GUI and terminal can use, instead of each doing it their own way. --- diff --git a/src/data/settings.c b/src/data/settings.c index ad509fb0..94f1f09a 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -22,7 +22,6 @@ #include "format.h" #include "value.h" #include "xalloc.h" -#include #include #include @@ -147,7 +146,6 @@ settings_init (int *width, int *length) { init_viewport (width, length); settings_set_epoch (-1); - i18n_init (); the_settings.styles = fmt_create (); settings_set_decimal_char (get_system_decimal ()); @@ -157,7 +155,6 @@ void settings_done (void) { fmt_done (the_settings.styles); - i18n_done (); } /* Returns the floating-point format used for RB and RBHEX diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 1463a4ee..36215b70 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include "assertion.h" @@ -29,6 +30,8 @@ #include "i18n.h" +#include "version.h" + #include #include "xstrndup.h" @@ -182,7 +185,19 @@ recode_string (const char *to, const char *from, void i18n_init (void) { - free (default_encoding); +#if ENABLE_NLS + setlocale (LC_CTYPE, ""); +#if HAVE_LC_MESSAGES + setlocale (LC_MESSAGES, ""); +#endif +#if HAVE_LC_PAPER + setlocale (LC_PAPER, ""); +#endif + bindtextdomain (PACKAGE, locale_dir); + textdomain (PACKAGE); +#endif /* ENABLE_NLS */ + + assert (default_encoding == NULL); default_encoding = strdup (locale_charset ()); hmapx_init (&map); diff --git a/src/ui/gui/main.c b/src/ui/gui/main.c index a36e9410..71b9fbdc 100644 --- a/src/ui/gui/main.c +++ b/src/ui/gui/main.c @@ -142,6 +142,8 @@ main (int argc, char *argv[]) set_program_name (argv[0]); + gtk_disable_setlocale (); + if ( ! gtk_parse_args (&argc, &argv) ) { perror ("Error parsing arguments"); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index 3d0d8649..405e1350 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -16,7 +16,7 @@ #include -#include +#include #include #include #include @@ -89,12 +89,8 @@ initialize (struct command_line_processor *clp, int argc, char **argv) { PsppireDict *dictionary = 0; - /* gtk_init messes with the locale. - So unset the bits we want to control ourselves */ - setlocale (LC_NUMERIC, "C"); - - bindtextdomain (PACKAGE, locale_dir); + i18n_init (); preregister_widgets (); @@ -171,6 +167,7 @@ de_initialize (void) message_dialog_done (); settings_done (); outp_done (); + i18n_done (); } diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index e37cace3..a1f20169 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -16,7 +16,6 @@ #include -#include #include #include #include @@ -30,6 +29,8 @@ #include #endif + +#include #include #include #include @@ -61,7 +62,6 @@ #define _(msgid) gettext (msgid) -static void i18n_init (void); static void fpu_init (void); static void clean_up (void); @@ -166,21 +166,6 @@ main (int argc, char **argv) return any_errors (); } -static void -i18n_init (void) -{ -#if ENABLE_NLS -#if HAVE_LC_MESSAGES - setlocale (LC_MESSAGES, ""); -#endif -#if HAVE_LC_PAPER - setlocale (LC_PAPER, ""); -#endif - bindtextdomain (PACKAGE, locale_dir); - textdomain (PACKAGE); -#endif /* ENABLE_NLS */ -} - static void fpu_init (void) { @@ -234,5 +219,6 @@ clean_up (void) readln_uninitialize (); outp_done (); msg_ui_done (); + i18n_done (); } }