Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -880,11 +880,11 @@ OBJCFLAGS="$old_OBJCFLAGS" ]) AC_CHECK_FUNCS([sysconf gmtime_r localtime_r nanosleep fcntl]) -AC_CHECK_HEADERS(xlocale.h) +AC_CHECK_HEADERS(langinfo.h xlocale.h) AC_CHECK_FUNCS([strtod_l strtof_l vasprintf_l]) AC_CHECK_FUNC(pipe, [ AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()]) ]) Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -18,10 +18,13 @@ #include #include #include +#ifdef HAVE_LANGINFO_H +# include +#endif #include #include #import "OFApplication.h" #import "OFString.h" @@ -30,10 +33,13 @@ #import "OFSystemInfo.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFThread.h" #import "OFThread+Private.h" + +#import "OFOutOfMemoryException.h" +#import "OFOutOfRangeException.h" #if defined(OF_MAC_OS_X) # include #elif defined(OF_WINDOWS) # include @@ -64,10 +70,12 @@ #endif - (void)OF_run; @end static OFApplication *app = nil; +extern of_string_encoding_t of_system_info_native_8bit_encoding; +extern OFString *of_system_info_decimal_point; static void atexitHandler(void) { id delegate = [app delegate]; @@ -99,13 +107,53 @@ id delegate; #ifdef OF_WINDOWS wchar_t **wargv, **wenvp; int wargc, si = 0; #endif +#ifdef HAVE_LANGINFO_H + char *codeset, *lowerCodeset; + size_t codesetLen; +#endif setlocale(LC_ALL, ""); +#ifdef HAVE_LANGINFO_H + codeset = nl_langinfo(CODESET); + codesetLen = strlen(codeset); + + if (SIZE_MAX - codesetLen < 1) + @throw [OFOutOfRangeException exception]; + + if ((lowerCodeset = malloc(codesetLen + 1)) == NULL) + @throw [OFOutOfMemoryException + exceptionWithRequestedSize: codesetLen + 1]; + + for (size_t i = 0; i < codesetLen; i++) + lowerCodeset[i] = of_ascii_tolower(codeset[i]); + + if (strcmp(lowerCodeset, "utf8") == 0 || + strcmp(lowerCodeset, "utf-8") == 0) + of_system_info_native_8bit_encoding = OF_STRING_ENCODING_UTF_8; + else if (strcmp(lowerCodeset, "ascii") == 0 || + strcmp(lowerCodeset, "us-ascii") == 0) + of_system_info_native_8bit_encoding = OF_STRING_ENCODING_ASCII; + else if (strcmp(lowerCodeset, "iso8859-1") == 0 || + strcmp(lowerCodeset, "iso-8859-1") == 0) + of_system_info_native_8bit_encoding = + OF_STRING_ENCODING_ISO_8859_1; + else if (strcmp(lowerCodeset, "iso8859-15") == 0 || + strcmp(lowerCodeset, "iso-8859-15") == 0) + of_system_info_native_8bit_encoding = + OF_STRING_ENCODING_ISO_8859_15; + + free(lowerCodeset); +#endif + + of_system_info_decimal_point = [[OFString alloc] + initWithCString: localeconv()->decimal_point + encoding: of_system_info_native_8bit_encoding]; + if ([cls isSubclassOfClass: [OFApplication class]]) { fprintf(stderr, "FATAL ERROR:\n Class %s is a subclass of " "class OFApplication, but class\n %s was specified as " "application delegate!\n Most likely, you wanted to " "subclass OFObject instead or specified\n the wrong class " Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -22,11 +22,10 @@ #include /* include any libc header to get the libc defines */ #ifdef __GLIBC__ # undef __USE_XOPEN #endif -#include #include #include "platform.h" #ifdef OF_MAC_OS_X @@ -64,10 +63,14 @@ }; #endif static size_t pageSize; static size_t numberOfCPUs; + +of_string_encoding_t of_system_info_native_8bit_encoding = + OF_STRING_ENCODING_UTF_8; +OFString *of_system_info_decimal_point = @"."; #if defined(OF_X86_64) || defined(OF_X86) static OF_INLINE struct x86_regs OF_CONST_FUNC x86_cpuid(uint32_t eax, uint32_t ecx) { @@ -144,17 +147,16 @@ return numberOfCPUs; } + (of_string_encoding_t)native8BitEncoding { - /* FIXME */ - return OF_STRING_ENCODING_UTF_8; + return of_system_info_native_8bit_encoding; } + (OFString*)decimalPoint { - return [OFString stringWithUTF8String: localeconv()->decimal_point]; + return of_system_info_decimal_point; } + (OFString*)userDataPath { #if defined(OF_MAC_OS_X) || defined(OF_IOS)