[<--] Indice [-->]

From jaromil <jaromil@dyne.org>
Date Thu, 11 Nov 2004 23:46:13 +0100
Subject [Hackmeeting] ABSURD localization of the radix character in libc!!!!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Cryptographically signed mail, see http://gnupg.org

iD8DBQFBk+u1WLCC1ltubZcRAm0qAJ9inN3o5G+f9O01A2755SD5G9aQXwCfZIWB
c4+zHAB4nNWg7oc20kYDVmw=
=cThu
-----END PGP SIGNATURE-----
_______________________________________________
Hackmeeting mailing list
Hackmeeting@kyuzz.org
https://inventati.org/mailman/listinfo/hackmeeting

[<--] Indice [-->]