From: John Darrington Date: Wed, 15 Oct 2008 03:02:01 +0000 (+0800) Subject: Set the DECIMAL point character from the LC_NUMERIC X-Git-Tag: v0.7.1~50^2~21^2~4 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=51996c07fc2b308ad29dcbaa93e4d5d3d21b3331 Set the DECIMAL point character from the LC_NUMERIC component of the current locale. --- diff --git a/doc/utilities.texi b/doc/utilities.texi index 35ea20e2..d825b9ab 100644 --- a/doc/utilities.texi +++ b/doc/utilities.texi @@ -414,10 +414,13 @@ default. Any real value may be assigned. @item DECIMAL @anchor{SET DECIMAL} -The default DOT setting causes the decimal point character to be -@samp{.} and the grouping character to be @samp{,}. A setting of COMMA +This value may be set to DOT or COMMA. +Setting it to DOT causes the decimal point character to be +@samp{.} and the grouping character to be @samp{,}. +Setting it to COMMA causes the decimal point character to be @samp{,} and the grouping character to be @samp{.}. +The default value is determined from the system locale. @item FORMAT Allows the default numeric input/output format to be specified. The diff --git a/src/data/settings.c b/src/data/settings.c index a87e3eff..ad509fb0 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -149,6 +149,8 @@ settings_init (int *width, int *length) settings_set_epoch (-1); i18n_init (); the_settings.styles = fmt_create (); + + settings_set_decimal_char (get_system_decimal ()); } void diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 70780eff..bda2676c 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -30,6 +30,10 @@ #include #include "xstrndup.h" +#if HAVE_NL_LANGINFO +#include +#endif + static char *locale = 0; static const char *charset; @@ -213,3 +217,32 @@ i18n_done (void) } } + + + +/* Return the system local's idea of the + decimal seperator character */ +char +get_system_decimal (void) +{ + char *radix_char = NULL; + + char *ol = setlocale (LC_NUMERIC, NULL); + setlocale (LC_NUMERIC, ""); + +#if HAVE_NL_LANGINFO + radix_char = nl_langinfo (RADIXCHAR); +#else + { + char *buf = xmalloc (10); + snprintf (buf, 10, "%f", 2.5); + radix_char = &buf[1]; + } +#endif + + /* We MUST leave LC_NUMERIC untouched, since it would + otherwise interfere with data_{in,out} */ + setlocale (LC_NUMERIC, ol); + return *radix_char; +} + diff --git a/src/libpspp/i18n.h b/src/libpspp/i18n.h index 0633ebc8..db15bad8 100644 --- a/src/libpspp/i18n.h +++ b/src/libpspp/i18n.h @@ -36,5 +36,8 @@ enum conv_id char * recode_string (enum conv_id how, const char *text, int len); +/* Return the decimal separator according to the + system locale */ +char get_system_decimal (void); #endif /* i18n.h */ diff --git a/tests/automake.mk b/tests/automake.mk index d8dd300e..082889cd 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -6,6 +6,8 @@ TESTS_ENVIRONMENT += PERL='@PERL@' PG_CONFIG='@PG_CONFIG@' # Allow locale_charset to find charset.alias before running "make install". TESTS_ENVIRONMENT += CHARSETALIASDIR='$(abs_top_builddir)/gl' +TESTS_ENVIRONMENT += LC_ALL=C + dist_TESTS = \ tests/command/aggregate.sh \ tests/command/attributes.sh \