ObjFW  Check-in [d974e769c5]

Overview
Comment:OFLocalization: Add support for MorphOS + libnix
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d974e769c559d6aaa88985e6b7dd8ebb67656b8d4549417e71cfc360d911b3a0
User & Date: js on 2017-06-04 01:30:12
Other Links: manifest | tags
Context
2017-06-04
16:05
Add objfw-new check-in: c70b66a228 user: js tags: trunk
01:30
OFLocalization: Add support for MorphOS + libnix check-in: d974e769c5 user: js tags: trunk
2017-06-03
23:28
OFApplication: Fix MorphOS LocalVar list iteration check-in: 22b2e6ea8b user: js tags: trunk
Changes

Modified src/OFLocalization.m from [39c2a63182] to [c0aec31b97].

21
22
23
24
25
26
27







28
29
30

31
32
33
34
35
36
37
#import "OFLocalization.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"








static OFLocalization *sharedLocalization = nil;


static void
parseLocale(char *locale, of_string_encoding_t *encoding,
    OFString **language, OFString **territory)
{
	if ((locale = of_strdup(locale)) == NULL)
		return;








>
>
>
>
>
>
>



>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "OFLocalization.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# include <proto/locale.h>
# undef BOOL
#endif

static OFLocalization *sharedLocalization = nil;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
    OFString **language, OFString **territory)
{
	if ((locale = of_strdup(locale)) == NULL)
		return;

68
69
70
71
72
73
74

75
76
77
78
79
80
81
		if (language != NULL)
			*language = [OFString stringWithCString: locale
						       encoding: enc];
	} @finally {
		free(locale);
	}
}


@implementation OFLocalization
@synthesize language = _language, territory = _territory, encoding = _encoding;
@synthesize decimalPoint = _decimalPoint;

+ (instancetype)sharedLocalization
{







>







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
		if (language != NULL)
			*language = [OFString stringWithCString: locale
						       encoding: enc];
	} @finally {
		free(locale);
	}
}
#endif

@implementation OFLocalization
@synthesize language = _language, territory = _territory, encoding = _encoding;
@synthesize decimalPoint = _decimalPoint;

+ (instancetype)sharedLocalization
{
110
111
112
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
#endif

- init
{
	self = [super init];

	@try {

		char *locale, *messagesLocale = NULL;

		_encoding = OF_STRING_ENCODING_UTF_8;
		_decimalPoint = @".";
		_localizedStrings = [[OFMutableArray alloc] init];

		if ((locale = setlocale(LC_ALL, "")) != NULL)
			_decimalPoint = [[OFString alloc]
			    initWithCString: localeconv()->decimal_point
				   encoding: _encoding];

#ifdef LC_MESSAGES
		messagesLocale = setlocale(LC_MESSAGES, "");
#endif
		if (messagesLocale == NULL)
			messagesLocale = locale;

		if (messagesLocale != NULL) {
			void *pool = objc_autoreleasePoolPush();

			parseLocale(messagesLocale, &_encoding,
			    &_language, &_language);

			[_language retain];
			[_territory retain];

			objc_autoreleasePoolPop(pool);
		}
































































	} @catch (id e) {
		[self release];
		@throw e;
	}

	sharedLocalization = self;








>











|

|














>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#endif

- init
{
	self = [super init];

	@try {
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
		char *locale, *messagesLocale = NULL;

		_encoding = OF_STRING_ENCODING_UTF_8;
		_decimalPoint = @".";
		_localizedStrings = [[OFMutableArray alloc] init];

		if ((locale = setlocale(LC_ALL, "")) != NULL)
			_decimalPoint = [[OFString alloc]
			    initWithCString: localeconv()->decimal_point
				   encoding: _encoding];

# ifdef LC_MESSAGES
		messagesLocale = setlocale(LC_MESSAGES, "");
# endif
		if (messagesLocale == NULL)
			messagesLocale = locale;

		if (messagesLocale != NULL) {
			void *pool = objc_autoreleasePoolPush();

			parseLocale(messagesLocale, &_encoding,
			    &_language, &_language);

			[_language retain];
			[_territory retain];

			objc_autoreleasePoolPop(pool);
		}
#else
		void *pool = objc_autoreleasePoolPush();
		char buffer[32];
		struct Locale *locale;

		/*
		 * Returns an empty string on MorphOS + libnix, but still
		 * applies it so that printf etc. work as expected.
		 */
		setlocale(LC_ALL, "");

		if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) {
			of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII;

			@try {
				_encoding = of_string_parse_encoding(
				    [OFString stringWithCString: buffer
						       encoding: ASCII]);
			} @catch (OFInvalidEncodingException *e) {
				_encoding = OF_STRING_ENCODING_ISO_8859_1;
			}
		} else
			_encoding = OF_STRING_ENCODING_ISO_8859_1;

		/*
		 * Get it via localeconv() instead of from the Locale struct,
		 * to make sure we and printf etc. have the same expectations.
		 */
		_decimalPoint = [[OFString alloc]
		    initWithCString: localeconv()->decimal_point
			   encoding: _encoding];

		_localizedStrings = [[OFMutableArray alloc] init];

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

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

	sharedLocalization = self;

Modified utils/ofhash/OFHash.m from [7a5a5d9642] to [052fd8a01b].

86
87
88
89
90
91
92

93



94
95
96
97
98
99
100

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif


	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];




	if ([arguments count] < 2)
		help();

	if ((hash = hashForName([arguments firstObject])) == nil)
		help();








>

>
>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif

	if ([arguments count] < 2)
		help();

	if ((hash = hashForName([arguments firstObject])) == nil)
		help();

Modified utils/ofhash/lang/languages.json from [59396279d5] to [1722bb6119].

1
2
3



4
5
6
7
8
{
    "de": {
        "": "de"



    },
    "german": {
        "": "de"
    }
}



>
>
>





1
2
3
4
5
6
7
8
9
10
11
{
    "de": {
        "": "de"
    },
    "deutsch": {
        "": "de"
    },
    "german": {
        "": "de"
    }
}

Modified utils/ofhttp/OFHTTP.m from [4a96f71a53] to [144754058e].

266
267
268
269
270
271
272

273



274
275
276
277
278
279
280

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif


	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];




	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'b':
			[self setBody: [optionsParser argument]];
			break;







>

>
>
>







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'b':
			[self setBody: [optionsParser argument]];
			break;

Modified utils/ofhttp/lang/languages.json from [59396279d5] to [1722bb6119].

1
2
3



4
5
6
7
8
{
    "de": {
        "": "de"



    },
    "german": {
        "": "de"
    }
}



>
>
>





1
2
3
4
5
6
7
8
9
10
11
{
    "de": {
        "": "de"
    },
    "deutsch": {
        "": "de"
    },
    "german": {
        "": "de"
    }
}

Modified utils/ofzip/OFZIP.m from [669ef697a2] to [3560b83228].

150
151
152
153
154
155
156

157



158
159
160
161
162
163
164

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif


	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];




	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'f':
			if (_overwrite < 0)
				mutuallyExclusiveError(







>

>
>
>







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofzip/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'f':
			if (_overwrite < 0)
				mutuallyExclusiveError(

Modified utils/ofzip/lang/languages.json from [59396279d5] to [1722bb6119].

1
2
3



4
5
6
7
8
{
    "de": {
        "": "de"



    },
    "german": {
        "": "de"
    }
}



>
>
>





1
2
3
4
5
6
7
8
9
10
11
{
    "de": {
        "": "de"
    },
    "deutsch": {
        "": "de"
    },
    "german": {
        "": "de"
    }
}