[Hackmeeting] ABSURD localization of the radix character in …

Delete this message

Reply to this message
Autore: jaromil
Data:  
Oggetto: [Hackmeeting] ABSURD localization of the radix character in libc !!!!
re all,

sorry for crossposting but:

i'm banging my head on an IGNOMINIOUS problem:
marshalling of numerical parameters into strings.

i used scanf/sprintf and i found a flexible and simple solution:

the parameter declarations can also include directly default min and max
as in http://livido.dyne.org/trac.cgi/file/trunk/livido/plugin_example.c
the "zahira" parameter is declared in a _very_ simple way
and then in http://livido.dyne.org/trac.cgi/file/trunk/livido/host_example.c
the get/set_parameter with va_list args is also very elegant

BUT then Andraz Tori pointed me that there is a problem in the
localisation of the radix character (decimal point)

it is HORRIBLE!

- -------------------------------------------
#include <locale.h>

#define PACKAGE "test"
#define LOCALEDIR "/usr/share/locale"

int main()
{
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
        setlocale (LC_ALL, "");
        char a[1000] = "1.234";
        float f;
        sscanf(a, "%f", &f);
        printf("read: %s -> %f\n", a, f);
}                                                                                                                                    
- -------------------------------------------


and here's where the fun begins:

$ export LANG=C
$ ./test
read: 1.234 -> 1.234000
$ export LANG=sl_SI
$ ./test
read: 1.234 -> 1,000000



i'm very disappointed at the libc at the moment!!!!!!!!!!!!!!!

i go to see the manual of printf(3) and i read:

For some numeric conversions a radix character (`decimal point') or thousands'
grouping character is used. The actual character used depends on the
LC_NUMERIC part of the locale. The POSIX locale uses `.' as radix character,
and does not have a grouping character. Thus,
printf("%'.2f", 1234567.89);
results in `1234567.89' in the POSIX locale, in `1234567,89' in the nl_NL
locale, and in `1.234.567,89' in the da_DK locale.



========================================\ O
========================================= /^ ( AAAAAAAAAAAAAAAAAAA )
========================================/ O

- --
jaromil, dyne.org rasta coder, http://rastasoft.org