Index: src/OFLocalization.m ================================================================== --- src/OFLocalization.m +++ src/OFLocalization.m @@ -27,20 +27,49 @@ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFOpenItemFailedException.h" -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS4 +# define __NOLIBBASE__ +# define __NOGLOBALIFACE__ +# define __USE_INLINE__ +# endif # define BOOL EXEC_BOOL # include +# include # include # undef BOOL #endif static OFLocalization *sharedLocalization = nil; -#ifndef OF_MORPHOS +#ifdef OF_AMIGAOS4 +extern struct ExecIFace *IExec; +static struct Library *DOSBase = NULL; +static struct DOSIFace *IDOS = NULL; +static struct Library *LocaleBase = NULL; +static struct LocaleIFace *ILocale = NULL; + +OF_DESTRUCTOR() +{ + if (ILocale != NULL) + DropInterface(ILocale); + + if (LocaleBase != NULL) + CloseLibrary(LocaleBase); + + if (IDOS != NULL) + DropInterface(IDOS); + + if (DOSBase != NULL) + CloseLibrary(DOSBase); +} +#endif + +#ifndef OF_AMIGAOS static void parseLocale(char *locale, of_string_encoding_t *encoding, OFString **language, OFString **territory) { if ((locale = of_strdup(locale)) == NULL) @@ -86,10 +115,36 @@ #endif @implementation OFLocalization @synthesize language = _language, territory = _territory, encoding = _encoding; @synthesize decimalPoint = _decimalPoint; + +#ifdef OF_AMIGAOS4 ++ (void)initialize +{ + if (self != [OFLocalization class]) + return; + + if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((IDOS = (struct DOSIFace *) + GetInterface(DOSBase, "main", 1, NULL)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((LocaleBase = OpenLibrary("locale.library", 38)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((ILocale = (struct LocaleIFace *) + GetInterface(LocaleBase, "main", 1, NULL)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; +} +#endif + (OFLocalization *)sharedLocalization { return sharedLocalization; } @@ -124,11 +179,11 @@ - (instancetype)init { self = [super init]; @try { -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS char *locale, *messagesLocale = NULL; if (sharedLocalization != nil) @throw [OFInitializationFailedException exceptionWithClass: [OFLocalization class]]; @@ -168,11 +223,15 @@ * Returns an empty string on MorphOS + libnix, but still * applies it so that printf etc. work as expected. */ setlocale(LC_ALL, ""); +# ifdef OF_MORPHOS if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { +# else + if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { +# endif of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII; @try { _encoding = of_string_parse_encoding( [OFString stringWithCString: buffer @@ -196,31 +255,32 @@ if (GetVar("Language", buffer, sizeof(buffer), 0) > 0) _language = [[OFString alloc] initWithCString: buffer encoding: _encoding]; - locale = OpenLocale(NULL); - @try { - union { - uint32_t u32; - char c[4]; - } territory; - size_t length; - - territory.u32 = - OF_BSWAP32_IF_LE(locale->loc_CountryCode); - - for (length = 0; length < 4; length++) - if (territory.c[length] == 0) - break; - - _territory = [[OFString alloc] - initWithCString: territory.c - encoding: _encoding - length: length]; - } @finally { - CloseLocale(locale); + if ((locale = OpenLocale(NULL)) != NULL) { + @try { + union { + uint32_t u32; + char c[4]; + } territory; + size_t length; + + territory.u32 = + OF_BSWAP32_IF_LE(locale->loc_CountryCode); + + for (length = 0; length < 4; length++) + if (territory.c[length] == 0) + break; + + _territory = [[OFString alloc] + initWithCString: territory.c + encoding: _encoding + length: length]; + } @finally { + CloseLocale(locale); + } } objc_autoreleasePoolPop(pool); #endif } @catch (id e) {