ObjFW  Check-in [eca1f56e3d]

Overview
Comment:OFLocalization: Add support for AmigaOS 4
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: eca1f56e3d54c5344a6da6a8991933f7783da8a4223287bdb1cf263e13f940b7
User & Date: js on 2018-04-15 17:41:35
Other Links: manifest | tags
Context
2018-04-15
19:03
Use PROGDIR: as user config & data dir on AmigaOS (check-in: c712763687 user: js tags: trunk)
17:41
OFLocalization: Add support for AmigaOS 4 (check-in: eca1f56e3d user: js tags: trunk)
15:09
Print system info at the end of the tests (check-in: 7075962f87 user: js tags: trunk)
Changes

Modified src/OFLocalization.m from [c0a1c16378] to [8b387494ee].

25
26
27
28
29
30
31
32






33
34

35
36
37
38
39
40























41

42
43
44
45
46
47
48
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+
+
+
+
+
+


+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







#import "OFDictionary.h"

#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 <proto/dos.h>
# include <proto/exec.h>
# include <proto/locale.h>
# undef BOOL
#endif

static OFLocalization *sharedLocalization = nil;

#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_MORPHOS
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
    OFString **language, OFString **territory)
{
	if ((locale = of_strdup(locale)) == NULL)
		return;

84
85
86
87
88
89
90


























91
92
93
94
95
96
97
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	}
}
#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;
}

+ (OFString *)language
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191







-
+







#endif

- (instancetype)init
{
	self = [super init];

	@try {
#ifndef OF_MORPHOS
#ifndef OF_AMIGAOS
		char *locale, *messagesLocale = NULL;

		if (sharedLocalization != nil)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [OFLocalization class]];

		_encoding = OF_STRING_ENCODING_UTF_8;
166
167
168
169
170
171
172

173



174
175
176
177
178
179
180
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239







+

+
+
+








		/*
		 * 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
						       encoding: ASCII]);
			} @catch (OFInvalidEncodingException *e) {
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267







-
+







		_localizedStrings = [[OFMutableArray alloc] init];

		if (GetVar("Language", buffer, sizeof(buffer), 0) > 0)
			_language = [[OFString alloc]
			    initWithCString: buffer
				   encoding: _encoding];

		locale = OpenLocale(NULL);
		if ((locale = OpenLocale(NULL)) != NULL) {
		@try {
			union {
				uint32_t u32;
				char c[4];
			} territory;
			size_t length;

216
217
218
219
220
221
222

223
224
225
226
227
228
229
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289







+







			_territory = [[OFString alloc]
			    initWithCString: territory.c
				   encoding: _encoding
				     length: length];
		} @finally {
			CloseLocale(locale);
		}
		}

		objc_autoreleasePoolPop(pool);
#endif
	} @catch (id e) {
		[self release];
		@throw e;
	}