* removed Darwin/Solaris-specific code and fixed all issues by calling

setlocale(LC_ALL,'') per POSIX, which initialises the langinfo stuff
    based on the environment variables (some OS'es do that automatically,
    but at least Darwin and Solaris don't)

git-svn-id: trunk@7672 -
This commit is contained in:
Jonas Maebe 2007-06-15 18:51:06 +00:00
parent 62b3b307e0
commit 7b47ebff6b

View File

@ -58,27 +58,32 @@ function towlower(__wc:wint_t):wint_t;cdecl;external libiconvname name 'towlower
function towupper(__wc:wint_t):wint_t;cdecl;external libiconvname name 'towupper';
function wcscoll (__s1:pwchar_t; __s2:pwchar_t):cint;cdecl;external libiconvname name 'wcscoll';
function strcoll (__s1:pchar; __s2:pchar):cint;cdecl;external libiconvname name 'strcoll';
function setlocale(category: cint; locale: pchar): pchar; cdecl; external clib name 'setlocale';
const
{$ifdef linux}
__LC_CTYPE = 0;
LC_ALL = 6;
_NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
_NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
CODESET = _NL_CTYPE_CODESET_NAME;
{$else linux}
{$ifdef darwin}
CODESET = 0;
LC_ALL = 0;
{$else darwin}
{$ifdef FreeBSD} // actually FreeBSD5. internationalisation is afaik not default on 4.
__LC_CTYPE = 0;
LC_ALL = 0;
_NL_CTYPE_CLASS = (__LC_CTYPE shl 16);
_NL_CTYPE_CODESET_NAME = (_NL_CTYPE_CLASS)+14;
CODESET = 0; // _NL_CTYPE_CODESET_NAME;
{$else freebsd}
{$ifdef solaris}
CODESET=49;
LC_ALL = 6;
{$else}
{$error lookup the value of CODESET in /usr/include/langinfo.h for your OS }
{$error lookup the value of CODESET in /usr/include/langinfo.h, and the value of LC_ALL in /usr/include/locale.h for your OS }
// and while doing it, check if iconv is in libc, and if the symbols are prefixed with iconv_ or libiconv_
{$endif solaris}
{$endif FreeBSD}
@ -372,18 +377,17 @@ end;
initialization
SetCWideStringManager;
initcriticalsection(iconv_lock);
{ you have to call setlocale(LC_ALL,'') to initialise the langinfo stuff }
{ with the information from the environment variables according to POSIX }
{ (some OSes do this automatically, but e.g. Darwin and Solaris don't) }
setlocale(LC_ALL,'');
{ init conversion tables }
{$if not defined(darwin) and not defined(solaris)}
iconv_wide2ansi:=iconv_open(nl_langinfo(CODESET),unicode_encoding);
iconv_ansi2wide:=iconv_open(unicode_encoding,nl_langinfo(CODESET));
iconv_ucs42ansi:=iconv_open(nl_langinfo(CODESET),'UCS4');
iconv_ansi2ucs4:=iconv_open('UCS4',nl_langinfo(CODESET));
{$else darwin or solaris}
iconv_wide2ansi:=iconv_open('UTF-8',unicode_encoding);
iconv_ansi2wide:=iconv_open(unicode_encoding,'UTF-8');
iconv_ucs42ansi:=iconv_open('UTF-8','UCS4');
iconv_ansi2ucs4:=iconv_open('UCS4','UTF-8');
{$endif darwin or solaris}
finalization
donecriticalsection(iconv_lock);
iconv_close(iconv_ansi2wide);