︙ | | | ︙ | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "unistd_wrapper.h"
#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFLocalization.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFSandbox.h"
#ifdef OF_AMIGAOS
# import "OFFile.h"
|
|
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "unistd_wrapper.h"
#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFLocale.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFSandbox.h"
#ifdef OF_AMIGAOS
# import "OFFile.h"
|
︙ | | | ︙ | |
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
id <OFApplicationDelegate> delegate)
{
#ifdef OF_WINDOWS
wchar_t **wargv, **wenvp;
int wargc, si = 0;
#endif
[[OFLocalization alloc] init];
app = [[OFApplication alloc] of_init];
[app of_setArgumentCount: argc
andArgumentValues: argv];
#ifdef OF_WINDOWS
|
|
|
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
id <OFApplicationDelegate> delegate)
{
#ifdef OF_WINDOWS
wchar_t **wargv, **wenvp;
int wargc, si = 0;
#endif
[[OFLocale alloc] init];
app = [[OFApplication alloc] of_init];
[app of_setArgumentCount: argc
andArgumentValues: argv];
#ifdef OF_WINDOWS
|
︙ | | | ︙ | |
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
FreeEnvironmentStringsW(env0);
#elif defined(OF_AMIGAOS)
void *pool = objc_autoreleasePoolPush();
OFFileManager *fileManager = [OFFileManager defaultManager];
OFArray *envContents =
[fileManager contentsOfDirectoryAtPath: @"ENV:"];
const of_string_encoding_t encoding = [OFLocalization encoding];
struct Process *proc;
struct LocalVar *firstLocalVar;
for (OFString *name in envContents) {
void *pool2 = objc_autoreleasePoolPush();
OFString *path, *value;
OFFile *file;
|
|
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
FreeEnvironmentStringsW(env0);
#elif defined(OF_AMIGAOS)
void *pool = objc_autoreleasePoolPush();
OFFileManager *fileManager = [OFFileManager defaultManager];
OFArray *envContents =
[fileManager contentsOfDirectoryAtPath: @"ENV:"];
const of_string_encoding_t encoding = [OFLocale encoding];
struct Process *proc;
struct LocalVar *firstLocalVar;
for (OFString *name in envContents) {
void *pool2 = objc_autoreleasePoolPush();
OFString *path, *value;
OFFile *file;
|
︙ | | | ︙ | |
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
char **env = environ;
# else
char **env = *_NSGetEnviron();
# endif
if (env != NULL) {
const of_string_encoding_t encoding =
[OFLocalization encoding];
for (; *env != NULL; env++) {
void *pool = objc_autoreleasePoolPush();
OFString *key, *value;
char *sep;
if ((sep = strchr(*env, '=')) == NULL) {
|
|
|
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
char **env = environ;
# else
char **env = *_NSGetEnviron();
# endif
if (env != NULL) {
const of_string_encoding_t encoding =
[OFLocale encoding];
for (; *env != NULL; env++) {
void *pool = objc_autoreleasePoolPush();
OFString *key, *value;
char *sep;
if ((sep = strchr(*env, '=')) == NULL) {
|
︙ | | | ︙ | |
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
of_string_encoding_t encoding;
_argc = argc;
_argv = argv;
encoding = [OFLocalization encoding];
# ifndef OF_NINTENDO_DS
if (*argc > 0) {
# else
if (__system_argv->argvMagic == ARGV_MAGIC &&
__system_argv->argc > 0) {
# endif
|
|
|
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
of_string_encoding_t encoding;
_argc = argc;
_argv = argv;
encoding = [OFLocale encoding];
# ifndef OF_NINTENDO_DS
if (*argc > 0) {
# else
if (__system_argv->argvMagic == ARGV_MAGIC &&
__system_argv->argc > 0) {
# endif
|
︙ | | | ︙ | |
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
#ifdef OF_HAVE_SANDBOX
- (void)activateSandbox: (OFSandbox *)sandbox
{
# ifdef OF_HAVE_PLEDGE
void *pool = objc_autoreleasePoolPush();
const char *promises = [[sandbox pledgeString]
cStringWithEncoding: [OFLocalization encoding]];
OFSandbox *oldSandbox;
if (pledge(promises, NULL) != 0)
@throw [OFSandboxActivationFailedException
exceptionWithSandbox: sandbox
errNo: errno];
|
|
|
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
#ifdef OF_HAVE_SANDBOX
- (void)activateSandbox: (OFSandbox *)sandbox
{
# ifdef OF_HAVE_PLEDGE
void *pool = objc_autoreleasePoolPush();
const char *promises = [[sandbox pledgeString]
cStringWithEncoding: [OFLocale encoding]];
OFSandbox *oldSandbox;
if (pledge(promises, NULL) != 0)
@throw [OFSandboxActivationFailedException
exceptionWithSandbox: sandbox
errNo: errno];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "unistd_wrapper.h"
#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocalization.h"
#import "OFString.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFOpenItemFailedException.h"
|
|
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "unistd_wrapper.h"
#import "OFDNSResolver.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFString.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFOpenItemFailedException.h"
|
︙ | | | ︙ | |
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
if (gethostname(hostname, 256) != 0)
return nil;
if ((domain = strchr(hostname, '.')) == NULL)
return nil;
return [OFString stringWithCString: domain + 1
encoding: [OFLocalization encoding]];
}
@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP;
|
|
|
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
if (gethostname(hostname, 256) != 0)
return nil;
if ((domain = strchr(hostname, '.')) == NULL)
return nil;
return [OFString stringWithCString: domain + 1
encoding: [OFLocale encoding]];
}
@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP;
|
︙ | | | ︙ | |
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
# endif
#endif
#ifdef OF_WINDOWS
- (void)of_parseNetworkParams
{
void *pool = objc_autoreleasePoolPush();
of_string_encoding_t encoding = [OFLocalization encoding];
OFMutableArray *nameServers;
OFString *localDomain;
/*
* We need more space than FIXED_INFO in case we have more than one
* name server, but we also want it to be properly aligned, meaning we
* can't just get a buffer of bytes. Thus, we just get space for 8.
*/
|
|
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
# endif
#endif
#ifdef OF_WINDOWS
- (void)of_parseNetworkParams
{
void *pool = objc_autoreleasePoolPush();
of_string_encoding_t encoding = [OFLocale encoding];
OFMutableArray *nameServers;
OFString *localDomain;
/*
* We need more space than FIXED_INFO in case we have more than one
* name server, but we also want it to be properly aligned, meaning we
* can't just get a buffer of bytes. Thus, we just get space for 8.
*/
|
︙ | | | ︙ | |
︙ | | | ︙ | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#endif
#import "OFArray.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocalization.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"
#import "OFChangeCurrentDirectoryPathFailedException.h"
|
|
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#endif
#import "OFArray.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"
#import "OFChangeCurrentDirectoryPathFailedException.h"
|
︙ | | | ︙ | |
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
|
if (IoErr() == ERROR_LINE_TOO_LONG)
@throw [OFOutOfRangeException exception];
return nil;
}
return [OFString stringWithCString: buffer
encoding: [OFLocalization encoding]];
#else
char buffer[PATH_MAX];
if ((getcwd(buffer, PATH_MAX)) == NULL)
@throw [OFGetCurrentDirectoryPathFailedException
exceptionWithErrNo: errno];
# ifdef OF_DJGPP
/*
* For some reason, getcwd() returns forward slashes on DJGPP, even
* though the native format is to use backwards slashes.
*/
for (char *tmp = buffer; *tmp != '\0'; tmp++)
if (*tmp == '/')
*tmp = '\\';
# endif
return [OFString stringWithCString: buffer
encoding: [OFLocalization encoding]];
#endif
}
- (OFURL *)currentDirectoryURL
{
void *pool = objc_autoreleasePoolPush();
OFURL *ret;
|
|
|
|
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
|
if (IoErr() == ERROR_LINE_TOO_LONG)
@throw [OFOutOfRangeException exception];
return nil;
}
return [OFString stringWithCString: buffer
encoding: [OFLocale encoding]];
#else
char buffer[PATH_MAX];
if ((getcwd(buffer, PATH_MAX)) == NULL)
@throw [OFGetCurrentDirectoryPathFailedException
exceptionWithErrNo: errno];
# ifdef OF_DJGPP
/*
* For some reason, getcwd() returns forward slashes on DJGPP, even
* though the native format is to use backwards slashes.
*/
for (char *tmp = buffer; *tmp != '\0'; tmp++)
if (*tmp == '/')
*tmp = '\\';
# endif
return [OFString stringWithCString: buffer
encoding: [OFLocale encoding]];
#endif
}
- (OFURL *)currentDirectoryURL
{
void *pool = objc_autoreleasePoolPush();
OFURL *ret;
|
︙ | | | ︙ | |
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
if (_wchdir([path UTF16String]) != 0)
@throw [OFChangeCurrentDirectoryPathFailedException
exceptionWithPath: path
errNo: errno];
#elif defined(OF_AMIGAOS)
BPTR lock, oldLock;
if ((lock = Lock([path cStringWithEncoding: [OFLocalization encoding]],
SHARED_LOCK)) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errNo = EBUSY;
|
|
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
if (_wchdir([path UTF16String]) != 0)
@throw [OFChangeCurrentDirectoryPathFailedException
exceptionWithPath: path
errNo: errno];
#elif defined(OF_AMIGAOS)
BPTR lock, oldLock;
if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]],
SHARED_LOCK)) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errNo = EBUSY;
|
︙ | | | ︙ | |
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
if (!dirChanged)
originalDirLock = oldLock;
else
UnLock(oldLock);
dirChanged = true;
#else
if (chdir([path cStringWithEncoding: [OFLocalization encoding]]) != 0)
@throw [OFChangeCurrentDirectoryPathFailedException
exceptionWithPath: path
errNo: errno];
#endif
}
- (void)changeCurrentDirectoryURL: (OFURL *)URL
|
|
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
if (!dirChanged)
originalDirLock = oldLock;
else
UnLock(oldLock);
dirChanged = true;
#else
if (chdir([path cStringWithEncoding: [OFLocale encoding]]) != 0)
@throw [OFChangeCurrentDirectoryPathFailedException
exceptionWithPath: path
errNo: errno];
#endif
}
- (void)changeCurrentDirectoryURL: (OFURL *)URL
|
︙ | | | ︙ | |
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
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
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#import "OFObject.h"
#import "OFString.h"
OF_ASSUME_NONNULL_BEGIN
/*! @file */
/*!
* @def OF_LOCALIZED
*
* @brief Returns the localized string for the specified ID with the specified
* arguments inserted.
*
* @param ID The ID of the localized string to retrieve
* @return The localized string with the specified arguments replaced
*/
#define OF_LOCALIZED(ID, ...) \
[[OFLocale currentLocale] localizedStringForID: ID \
fallback: __VA_ARGS__, nil]
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
/*!
* @class OFLocale OFLocale.h ObjFW/OFLocale.h
*
* @brief A class for querying the locale and retrieving localized strings.
*/
@interface OFLocale: OFObject
{
OFString *_Nullable _language, *_Nullable _territory;
of_string_encoding_t _encoding;
OFString *_decimalPoint;
OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
*_localizedStrings;
}
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nullable, nonatomic) OFLocale *currentLocale;
@property (class, readonly, nullable, nonatomic) OFString *language;
@property (class, readonly, nullable, nonatomic) OFString *territory;
@property (class, readonly, nonatomic) of_string_encoding_t encoding;
@property (class, readonly, nullable, nonatomic) OFString *decimalPoint;
#endif
/*!
* @brief The language of the locale for messages.
*
* If the language is unknown, it is `nil`.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language;
/*!
* @brief The territory of the locale for messages.
*
* If the territory is unknown, it is `nil`.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory;
/*!
* @brief The native 8-bit string encoding of the locale for messages.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*/
@property (readonly, nonatomic) of_string_encoding_t encoding;
/*!
* @brief The decimal point of the system's locale.
*/
@property (readonly, nonatomic) OFString *decimalPoint;
/*!
* @brief Returns the current OFLocale.
*
* @warning If you don't use @ref OFApplication, this might be `nil`! In this
* case, you need to manually allocate an instance and call
* @ref init once.
*
* @return The current OFLocale instance
*/
+ (nullable OFLocale *)currentLocale;
/*!
* @brief Returns the language of the locale.
*
* If the language is unknown, `nil` is returned.
*
* @return The language of the locale.
*/
+ (nullable OFString *)language;
/*!
* @brief Returns the territory of the locale.
*
* If the territory is unknown, `nil` is returned.
*
* @return The territory of the locale.
*/
+ (nullable OFString *)territory;
/*!
* @brief Returns the native 8-bit string encoding for the locale.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*
* @return The native 8-bit string encoding for the locale
*/
+ (of_string_encoding_t)encoding;
/*!
* @brief Returns the decimal point of the system's locale.
*
* @return The decimal point of the system's locale
*/
+ (nullable OFString *)decimalPoint;
#ifdef OF_HAVE_FILES
/*!
* @brief Adds a directory to scan for language files.
*
* @param path The path to the directory to scan for language files
*/
+ (void)addLanguageDirectory: (OFString *)path;
#endif
/*!
* @brief Initializes the current OFLocale.
*
* @warning This sets the locale via `setlocale()`!
*
* @warning You should never call this yourself, except if you do not use
* @ref OFApplication. In this case, you need to allocate exactly one
* instance of OFLocale, which will be come the current locale, and
* call this method.
*/
- (instancetype)init;
#ifdef OF_HAVE_FILES
/*!
* @brief Adds a directory to scan for language files.
*
* @param path The path to the directory to scan for language files
*/
- (void)addLanguageDirectory: (OFString *)path;
#endif
/*!
* @brief Returns the localized string for the specified ID, using the fallback
* string if it cannot be looked up or is missing.
*
* @note This takes a variadic argument, terminated by `nil`, that consists of
* pairs of variable names and variable values, which will be replaced
* inside the localized string. For example, you can pass
* `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in
* the localized string.
*
* @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes
* care of the `nil` sentinel automatically.
*
* @param ID The ID for the localized string
* @param fallback The fallback to use in case the localized string cannot be
* looked up or is missing
* @return The localized string
*/
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback, ...
OF_SENTINEL;
/*!
* @brief Returns the localized string for the specified ID, using the fallback
* string if it cannot be looked up or is missing.
*
* @note This takes a variadic argument, terminated by `nil` and passed as
* va_list, that consists of pairs of variable names and variable values,
* which will be replaced inside the localized string. For example, you
* can pass `@"name", @"foo", nil`, causing `%[name]` to be replaced with
* `foo` in the localized string.
*
* @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes
* care of the `nil` sentinel automatically.
*
* @param ID The ID for the localized string
* @param fallback The fallback to use in case the localized string cannot be
* looked up or is missing
* @param arguments A va_list of arguments, consisting of pairs of variable
* names and values to replace in the localized string,
* terminated with `nil`
* @return The localized string
*/
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback
arguments: (va_list)arguments;
@end
OF_ASSUME_NONNULL_END
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <locale.h>
#import "OFLocale.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFOpenItemFailedException.h"
#ifdef OF_AMIGAOS
# ifdef OF_AMIGAOS4
# define __NOLIBBASE__
# define __NOGLOBALIFACE__
# define __USE_INLINE__
# endif
# include <proto/dos.h>
# include <proto/exec.h>
# include <proto/locale.h>
#endif
static OFLocale *currentLocale = 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_AMIGAOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
OFString **language, OFString **territory)
{
if ((locale = of_strdup(locale)) == NULL)
return;
@try {
const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII;
char *tmp;
/* We don't care for extras behind the @ */
if ((tmp = strrchr(locale, '@')) != NULL)
*tmp = '\0';
/* Encoding */
if ((tmp = strrchr(locale, '.')) != NULL) {
*tmp++ = '\0';
@try {
if (encoding != NULL)
*encoding = of_string_parse_encoding(
[OFString stringWithCString: tmp
encoding: enc]);
} @catch (OFInvalidEncodingException *e) {
}
}
/* Territory */
if ((tmp = strrchr(locale, '_')) != NULL) {
*tmp++ = '\0';
if (territory != NULL)
*territory = [OFString stringWithCString: tmp
encoding: enc];
}
if (language != NULL)
*language = [OFString stringWithCString: locale
encoding: enc];
} @finally {
free(locale);
}
}
#endif
@implementation OFLocale
@synthesize language = _language, territory = _territory, encoding = _encoding;
@synthesize decimalPoint = _decimalPoint;
#ifdef OF_AMIGAOS4
+ (void)initialize
{
if (self != [OFLocale 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
+ (OFLocale *)currentLocale
{
return currentLocale;
}
+ (OFString *)language
{
return [currentLocale language];
}
+ (OFString *)territory
{
return [currentLocale territory];
}
+ (of_string_encoding_t)encoding
{
return [currentLocale encoding];
}
+ (OFString *)decimalPoint
{
return [currentLocale decimalPoint];
}
#ifdef OF_HAVE_FILES
+ (void)addLanguageDirectory: (OFString *)path
{
[currentLocale addLanguageDirectory: path];
}
#endif
- (instancetype)init
{
self = [super init];
@try {
#ifndef OF_AMIGAOS
char *locale, *messagesLocale = NULL;
if (currentLocale != nil)
@throw [OFInitializationFailedException
exceptionWithClass: [OFLocale class]];
_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, &_territory);
[_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 defined(OF_MORPHOS)
if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) {
# elif defined(OF_AMIGAOS4)
if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) {
# else
if (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) {
_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];
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) {
[self release];
@throw e;
}
currentLocale = self;
return self;
}
- (void)dealloc
{
[_language release];
[_territory release];
[_decimalPoint release];
[_localizedStrings release];
[super dealloc];
}
#ifdef OF_HAVE_FILES
- (void)addLanguageDirectory: (OFString *)path
{
void *pool;
OFString *mapPath, *language, *territory, *languageFile;
OFDictionary *map;
if (_language == nil)
return;
pool = objc_autoreleasePoolPush();
mapPath = [path stringByAppendingPathComponent: @"languages.json"];
@try {
map = [[OFString stringWithContentsOfFile: mapPath] JSONValue];
} @catch (OFOpenItemFailedException *e) {
objc_autoreleasePoolPop(pool);
return;
}
language = [_language lowercaseString];
territory = [_territory lowercaseString];
if (territory == nil)
territory = @"";
languageFile = [[map objectForKey: language] objectForKey: territory];
if (languageFile == nil)
languageFile = [[map objectForKey: language]
objectForKey: @""];
if (languageFile == nil) {
objc_autoreleasePoolPop(pool);
return;
}
languageFile = [path stringByAppendingPathComponent:
[languageFile stringByAppendingString: @".json"]];
[_localizedStrings addObject:
[[OFString stringWithContentsOfFile: languageFile] JSONValue]];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback, ...
{
OFString *ret;
va_list args;
va_start(args, fallback);
ret = [self localizedStringForID: ID
fallback: fallback
arguments: args];
va_end(args);
return ret;
}
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback
arguments: (va_list)arguments
{
OFMutableString *ret = [OFMutableString string];
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = NULL;
size_t last, UTF8StringLength;
int state = 0;
for (OFDictionary *strings in _localizedStrings) {
id string = [strings objectForKey: ID];
if (string == nil)
continue;
if ([string isKindOfClass: [OFArray class]])
string = [string componentsJoinedByString: @""];
UTF8String = [string UTF8String];
UTF8StringLength = [string UTF8StringLength];
break;
}
if (UTF8String == NULL) {
UTF8String = [fallback UTF8String];
UTF8StringLength = [fallback UTF8StringLength];
}
state = 0;
last = 0;
for (size_t i = 0; i < UTF8StringLength; i++) {
switch (state) {
case 0:
if (UTF8String[i] == '%') {
[ret appendUTF8String: UTF8String + last
length: i - last];
last = i + 1;
state = 1;
}
break;
case 1:
if (UTF8String[i] == '[') {
last = i + 1;
state = 2;
} else {
[ret appendString: @"%"];
state = 0;
}
break;
case 2:
if (UTF8String[i] == ']') {
va_list argsCopy;
OFConstantString *name;
OFString *var = [OFString
stringWithUTF8String: UTF8String + last
length: i - last];
/*
* We loop, as most of the time, we only have
* one or maybe two variables, meaning looping
* is faster than constructing a dictionary.
*/
va_copy(argsCopy, arguments);
while ((name = va_arg(argsCopy,
OFConstantString *)) != nil) {
id value = va_arg(argsCopy, id);
if (value == nil)
@throw
[OFInvalidArgumentException
exception];
if ([name isEqual: var]) {
[ret appendString:
[value description]];
break;
}
}
last = i + 1;
state = 0;
}
break;
}
}
switch (state) {
case 1:
[ret appendString: @"%"];
/* Explicit fall-through */
case 0:
[ret appendUTF8String: UTF8String + last
length: UTF8StringLength - last];
break;
}
objc_autoreleasePoolPop(pool);
[ret makeImmutable];
return ret;
}
@end
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
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
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#import "OFObject.h"
#import "OFString.h"
OF_ASSUME_NONNULL_BEGIN
/*! @file */
/*!
* @def OF_LOCALIZED
*
* @brief Returns the localized string for the specified ID with the specified
* arguments inserted.
*
* @param ID The ID of the localized string to retrieve
* @return The localized string with the specified arguments replaced
*/
#define OF_LOCALIZED(ID, ...) \
[[OFLocalization sharedLocalization] \
localizedStringForID: ID \
fallback: __VA_ARGS__, nil]
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
/*!
* @class OFLocalization OFLocalization.h ObjFW/OFLocalization.h
*
* @brief A class for querying the locale and retrieving localized strings.
*/
@interface OFLocalization: OFObject
{
OFString *_Nullable _language, *_Nullable _territory;
of_string_encoding_t _encoding;
OFString *_decimalPoint;
OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
*_localizedStrings;
}
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nullable, nonatomic)
OFLocalization *sharedLocalization;
@property (class, readonly, nullable, nonatomic) OFString *language;
@property (class, readonly, nullable, nonatomic) OFString *territory;
@property (class, readonly, nonatomic) of_string_encoding_t encoding;
@property (class, readonly, nullable, nonatomic) OFString *decimalPoint;
#endif
/*!
* @brief The language of the locale for messages.
*
* If the language is unknown, it is `nil`.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language;
/*!
* @brief The territory of the locale for messages.
*
* If the territory is unknown, it is `nil`.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory;
/*!
* @brief The native 8-bit string encoding of the locale for messages.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*/
@property (readonly, nonatomic) of_string_encoding_t encoding;
/*!
* @brief The decimal point of the system's locale.
*/
@property (readonly, nonatomic) OFString *decimalPoint;
/*!
* @brief Returns the shared OFLocalization instance.
*
* @warning If you don't use @ref OFApplication, this might be `nil`! In this
* case, you need to manually allocate an instance and call
* @ref init once.
*
* @return The shared OFLocalization instance
*/
+ (nullable OFLocalization *)sharedLocalization;
/*!
* @brief Returns the language of the locale.
*
* If the language is unknown, `nil` is returned.
*
* @return The language of the locale.
*/
+ (nullable OFString *)language;
/*!
* @brief Returns the territory of the locale.
*
* If the territory is unknown, `nil` is returned.
*
* @return The territory of the locale.
*/
+ (nullable OFString *)territory;
/*!
* @brief Returns the native 8-bit string encoding for the locale.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*
* @return The native 8-bit string encoding for the locale
*/
+ (of_string_encoding_t)encoding;
/*!
* @brief Returns the decimal point of the system's locale.
*
* @return The decimal point of the system's locale
*/
+ (nullable OFString *)decimalPoint;
#ifdef OF_HAVE_FILES
/*!
* @brief Adds a directory to scan for language files.
*
* @param path The path to the directory to scan for language files
*/
+ (void)addLanguageDirectory: (OFString *)path;
#endif
/*!
* @brief Initializes the OFLocalization singleton with the specified locale.
*
* @warning This sets the locale via `setlocale()`!
*
* @warning You should never call this yourself, except if you do not use
* @ref OFApplication. In this case, you need to allocate exactly one
* instance of OFLocalization, which will be come the singleton, and
* call this method.
*/
- (instancetype)init;
#ifdef OF_HAVE_FILES
/*!
* @brief Adds a directory to scan for language files.
*
* @param path The path to the directory to scan for language files
*/
- (void)addLanguageDirectory: (OFString *)path;
#endif
/*!
* @brief Returns the localized string for the specified ID, using the fallback
* string if it cannot be looked up or is missing.
*
* @note This takes a variadic argument, terminated by `nil`, that consists of
* pairs of variable names and variable values, which will be replaced
* inside the localized string. For example, you can pass
* `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in
* the localized string.
*
* @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes
* care of the `nil` sentinel automatically.
*
* @param ID The ID for the localized string
* @param fallback The fallback to use in case the localized string cannot be
* looked up or is missing
* @return The localized string
*/
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback, ...
OF_SENTINEL;
/*!
* @brief Returns the localized string for the specified ID, using the fallback
* string if it cannot be looked up or is missing.
*
* @note This takes a variadic argument, terminated by `nil` and passed as
* va_list, that consists of pairs of variable names and variable values,
* which will be replaced inside the localized string. For example, you
* can pass `@"name", @"foo", nil`, causing `%[name]` to be replaced with
* `foo` in the localized string.
*
* @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes
* care of the `nil` sentinel automatically.
*
* @param ID The ID for the localized string
* @param fallback The fallback to use in case the localized string cannot be
* looked up or is missing
* @param arguments A va_list of arguments, consisting of pairs of variable
* names and values to replace in the localized string,
* terminated with `nil`
* @return The localized string
*/
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback
arguments: (va_list)arguments;
@end
OF_ASSUME_NONNULL_END
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <locale.h>
#import "OFLocalization.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFOpenItemFailedException.h"
#ifdef OF_AMIGAOS
# ifdef OF_AMIGAOS4
# define __NOLIBBASE__
# define __NOGLOBALIFACE__
# define __USE_INLINE__
# endif
# include <proto/dos.h>
# include <proto/exec.h>
# include <proto/locale.h>
#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_AMIGAOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
OFString **language, OFString **territory)
{
if ((locale = of_strdup(locale)) == NULL)
return;
@try {
const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII;
char *tmp;
/* We don't care for extras behind the @ */
if ((tmp = strrchr(locale, '@')) != NULL)
*tmp = '\0';
/* Encoding */
if ((tmp = strrchr(locale, '.')) != NULL) {
*tmp++ = '\0';
@try {
if (encoding != NULL)
*encoding = of_string_parse_encoding(
[OFString stringWithCString: tmp
encoding: enc]);
} @catch (OFInvalidEncodingException *e) {
}
}
/* Territory */
if ((tmp = strrchr(locale, '_')) != NULL) {
*tmp++ = '\0';
if (territory != NULL)
*territory = [OFString stringWithCString: tmp
encoding: enc];
}
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;
#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
{
return [sharedLocalization language];
}
+ (OFString *)territory
{
return [sharedLocalization territory];
}
+ (of_string_encoding_t)encoding
{
return [sharedLocalization encoding];
}
+ (OFString *)decimalPoint
{
return [sharedLocalization decimalPoint];
}
#ifdef OF_HAVE_FILES
+ (void)addLanguageDirectory: (OFString *)path
{
[sharedLocalization addLanguageDirectory: path];
}
#endif
- (instancetype)init
{
self = [super init];
@try {
#ifndef OF_AMIGAOS
char *locale, *messagesLocale = NULL;
if (sharedLocalization != nil)
@throw [OFInitializationFailedException
exceptionWithClass: [OFLocalization class]];
_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, &_territory);
[_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 defined(OF_MORPHOS)
if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) {
# elif defined(OF_AMIGAOS4)
if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) {
# else
if (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) {
_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];
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) {
[self release];
@throw e;
}
sharedLocalization = self;
return self;
}
- (void)dealloc
{
[_language release];
[_territory release];
[_decimalPoint release];
[_localizedStrings release];
[super dealloc];
}
#ifdef OF_HAVE_FILES
- (void)addLanguageDirectory: (OFString *)path
{
void *pool;
OFString *mapPath, *language, *territory, *languageFile;
OFDictionary *map;
if (_language == nil)
return;
pool = objc_autoreleasePoolPush();
mapPath = [path stringByAppendingPathComponent: @"languages.json"];
@try {
map = [[OFString stringWithContentsOfFile: mapPath] JSONValue];
} @catch (OFOpenItemFailedException *e) {
objc_autoreleasePoolPop(pool);
return;
}
language = [_language lowercaseString];
territory = [_territory lowercaseString];
if (territory == nil)
territory = @"";
languageFile = [[map objectForKey: language] objectForKey: territory];
if (languageFile == nil)
languageFile = [[map objectForKey: language]
objectForKey: @""];
if (languageFile == nil) {
objc_autoreleasePoolPop(pool);
return;
}
languageFile = [path stringByAppendingPathComponent:
[languageFile stringByAppendingString: @".json"]];
[_localizedStrings addObject:
[[OFString stringWithContentsOfFile: languageFile] JSONValue]];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback, ...
{
OFString *ret;
va_list args;
va_start(args, fallback);
ret = [self localizedStringForID: ID
fallback: fallback
arguments: args];
va_end(args);
return ret;
}
- (OFString *)localizedStringForID: (OFConstantString *)ID
fallback: (OFConstantString *)fallback
arguments: (va_list)arguments
{
OFMutableString *ret = [OFMutableString string];
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = NULL;
size_t last, UTF8StringLength;
int state = 0;
for (OFDictionary *strings in _localizedStrings) {
id string = [strings objectForKey: ID];
if (string == nil)
continue;
if ([string isKindOfClass: [OFArray class]])
string = [string componentsJoinedByString: @""];
UTF8String = [string UTF8String];
UTF8StringLength = [string UTF8StringLength];
break;
}
if (UTF8String == NULL) {
UTF8String = [fallback UTF8String];
UTF8StringLength = [fallback UTF8StringLength];
}
state = 0;
last = 0;
for (size_t i = 0; i < UTF8StringLength; i++) {
switch (state) {
case 0:
if (UTF8String[i] == '%') {
[ret appendUTF8String: UTF8String + last
length: i - last];
last = i + 1;
state = 1;
}
break;
case 1:
if (UTF8String[i] == '[') {
last = i + 1;
state = 2;
} else {
[ret appendString: @"%"];
state = 0;
}
break;
case 2:
if (UTF8String[i] == ']') {
va_list argsCopy;
OFConstantString *name;
OFString *var = [OFString
stringWithUTF8String: UTF8String + last
length: i - last];
/*
* We loop, as most of the time, we only have
* one or maybe two variables, meaning looping
* is faster than constructing a dictionary.
*/
va_copy(argsCopy, arguments);
while ((name = va_arg(argsCopy,
OFConstantString *)) != nil) {
id value = va_arg(argsCopy, id);
if (value == nil)
@throw
[OFInvalidArgumentException
exception];
if ([name isEqual: var]) {
[ret appendString:
[value description]];
break;
}
}
last = i + 1;
state = 0;
}
break;
}
}
switch (state) {
case 1:
[ret appendString: @"%"];
/* Explicit fall-through */
case 0:
[ret appendUTF8String: UTF8String + last
length: UTF8StringLength - last];
break;
}
objc_autoreleasePoolPop(pool);
[ret makeImmutable];
return ret;
}
@end
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
︙ | | | ︙ | |
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# include <grp.h>
#endif
#import "OFURLHandler_file.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFFile.h"
#import "OFLocalization.h"
#import "OFNumber.h"
#import "OFURL.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif
|
|
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# include <grp.h>
#endif
#import "OFURLHandler_file.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFURL.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif
|
︙ | | | ︙ | |
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
return _wstat64([path UTF16String], buffer);
#elif defined(OF_AMIGAOS)
BPTR lock;
struct FileInfoBlock fib;
of_time_interval_t timeInterval;
struct Locale *locale;
if ((lock = Lock([path cStringWithEncoding: [OFLocalization encoding]],
SHARED_LOCK)) == 0) {
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errno = EBUSY;
break;
case ERROR_OBJECT_NOT_FOUND:
|
|
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
return _wstat64([path UTF16String], buffer);
#elif defined(OF_AMIGAOS)
BPTR lock;
struct FileInfoBlock fib;
of_time_interval_t timeInterval;
struct Locale *locale;
if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]],
SHARED_LOCK)) == 0) {
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errno = EBUSY;
break;
case ERROR_OBJECT_NOT_FOUND:
|
︙ | | | ︙ | |
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
|
timeInterval +=
fib.fib_Date.ds_Tick / (of_time_interval_t)TICKS_PER_SECOND;
buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval;
return 0;
#elif defined(OF_HAVE_OFF64_T)
return stat64([path cStringWithEncoding: [OFLocalization encoding]],
buffer);
#else
return stat([path cStringWithEncoding: [OFLocalization encoding]],
buffer);
#endif
}
static int
of_lstat(OFString *path, of_stat_t *buffer)
{
#if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)
# ifdef OF_HAVE_OFF64_T
return lstat64([path cStringWithEncoding: [OFLocalization encoding]],
buffer);
# else
return lstat([path cStringWithEncoding: [OFLocalization encoding]],
buffer);
# endif
#else
return of_stat(path, buffer);
#endif
}
static void
|
|
<
|
<
|
<
|
<
|
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
|
timeInterval +=
fib.fib_Date.ds_Tick / (of_time_interval_t)TICKS_PER_SECOND;
buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval;
return 0;
#elif defined(OF_HAVE_OFF64_T)
return stat64([path cStringWithEncoding: [OFLocale encoding]], buffer);
#else
return stat([path cStringWithEncoding: [OFLocale encoding]], buffer);
#endif
}
static int
of_lstat(OFString *path, of_stat_t *buffer)
{
#if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)
# ifdef OF_HAVE_OFF64_T
return lstat64([path cStringWithEncoding: [OFLocale encoding]], buffer);
# else
return lstat([path cStringWithEncoding: [OFLocale encoding]], buffer);
# endif
#else
return of_stat(path, buffer);
#endif
}
static void
|
︙ | | | ︙ | |
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
[attributes setObject: [NSNumber numberWithUInt16: s->st_gid]
forKey: of_file_attribute_key_posix_gid];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
of_string_encoding_t encoding = [OFLocalization encoding];
struct passwd *passwd = getpwuid(s->st_uid);
struct group *group_ = getgrgid(s->st_gid);
if (passwd != NULL) {
OFString *owner = [OFString
stringWithCString: passwd->pw_name
encoding: encoding];
|
|
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
[attributes setObject: [NSNumber numberWithUInt16: s->st_gid]
forKey: of_file_attribute_key_posix_gid];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
of_string_encoding_t encoding = [OFLocale encoding];
struct passwd *passwd = getpwuid(s->st_uid);
struct group *group_ = getgrgid(s->st_gid);
if (passwd != NULL) {
OFString *owner = [OFString
stringWithCString: passwd->pw_name
encoding: encoding];
|
︙ | | | ︙ | |
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
of_stat_t *s, OFURL *URL)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
OFString *path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
if (S_ISLNK(s->st_mode)) {
of_string_encoding_t encoding = [OFLocalization encoding];
char destinationC[PATH_MAX];
ssize_t length;
OFString *destination;
of_file_attribute_key_t key;
length = readlink([path cStringWithEncoding: encoding],
destinationC, PATH_MAX);
|
|
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
of_stat_t *s, OFURL *URL)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
OFString *path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
if (S_ISLNK(s->st_mode)) {
of_string_encoding_t encoding = [OFLocale encoding];
char destinationC[PATH_MAX];
ssize_t length;
OFString *destination;
of_file_attribute_key_t key;
length = readlink([path cStringWithEncoding: encoding],
destinationC, PATH_MAX);
|
︙ | | | ︙ | |
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
attributes: (of_file_attributes_t)attributes
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
uint16_t mode = [permissions uInt16Value] & 0777;
OFString *path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
if (chmod([path cStringWithEncoding: [OFLocalization encoding]],
mode) != 0)
# else
if (_wchmod([path UTF16String], mode) != 0)
# endif
@throw [OFSetItemAttributesFailedException
exceptionWithURL: URL
attributes: attributes
failedAttribute: of_file_attribute_key_posix_permissions
|
|
<
|
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
attributes: (of_file_attributes_t)attributes
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
uint16_t mode = [permissions uInt16Value] & 0777;
OFString *path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
if (chmod([path cStringWithEncoding: [OFLocale encoding]], mode) != 0)
# else
if (_wchmod([path UTF16String], mode) != 0)
# endif
@throw [OFSetItemAttributesFailedException
exceptionWithURL: URL
attributes: attributes
failedAttribute: of_file_attribute_key_posix_permissions
|
︙ | | | ︙ | |
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
uid_t uid = -1;
gid_t gid = -1;
of_string_encoding_t encoding;
if (owner == nil && group == nil)
@throw [OFInvalidArgumentException exception];
encoding = [OFLocalization encoding];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
if (owner != nil) {
struct passwd *passwd;
|
|
|
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
uid_t uid = -1;
gid_t gid = -1;
of_string_encoding_t encoding;
if (owner == nil && group == nil)
@throw [OFInvalidArgumentException exception];
encoding = [OFLocale encoding];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
if (owner != nil) {
struct passwd *passwd;
|
︙ | | | ︙ | |
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errno];
#elif defined(OF_AMIGAOS)
BPTR lock;
if ((lock = CreateDir(
[path cStringWithEncoding: [OFLocalization encoding]])) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_NO_FREE_STORE:
case ERROR_DISK_FULL:
errNo = ENOSPC;
break;
|
|
|
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errno];
#elif defined(OF_AMIGAOS)
BPTR lock;
if ((lock = CreateDir(
[path cStringWithEncoding: [OFLocale encoding]])) == 0) {
int errNo;
switch (IoErr()) {
case ERROR_NO_FREE_STORE:
case ERROR_DISK_FULL:
errNo = ENOSPC;
break;
|
︙ | | | ︙ | |
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errNo];
}
UnLock(lock);
#else
if (mkdir([path cStringWithEncoding: [OFLocalization encoding]],
0777) != 0)
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errno];
#endif
objc_autoreleasePoolPop(pool);
}
|
|
<
|
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
|
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errNo];
}
UnLock(lock);
#else
if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0)
@throw [OFCreateDirectoryFailedException
exceptionWithURL: URL
errNo: errno];
#endif
objc_autoreleasePoolPop(pool);
}
|
︙ | | | ︙ | |
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
|
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
FindClose(handle);
}
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocalization encoding];
BPTR lock;
struct FileInfoBlock fib;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0) {
int errNo;
|
|
|
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
|
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
FindClose(handle);
}
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocale encoding];
BPTR lock;
struct FileInfoBlock fib;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0) {
int errNo;
|
︙ | | | ︙ | |
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
|
exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
UnLock(lock);
}
#else
of_string_encoding_t encoding = [OFLocalization encoding];
DIR *dir;
if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errno];
|
|
|
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
exceptionWithObject: self
requestedLength: 0
errNo: EIO];
} @finally {
UnLock(lock);
}
#else
of_string_encoding_t encoding = [OFLocale encoding];
DIR *dir;
if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errno];
|
︙ | | | ︙ | |
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
|
[path stringByAppendingPathComponent: item]]];
objc_autoreleasePoolPop(pool2);
}
#ifndef OF_AMIGAOS
# ifndef OF_WINDOWS
if (rmdir([path cStringWithEncoding:
[OFLocalization encoding]]) != 0)
# else
if (_wrmdir([path UTF16String]) != 0)
# endif
@throw [OFRemoveItemFailedException
exceptionWithURL: URL
errNo: errno];
} else {
# ifndef OF_WINDOWS
if (unlink([path cStringWithEncoding:
[OFLocalization encoding]]) != 0)
# else
if (_wunlink([path UTF16String]) != 0)
# endif
@throw [OFRemoveItemFailedException
exceptionWithURL: URL
errNo: errno];
#endif
}
#ifdef OF_AMIGAOS
if (!DeleteFile(
[path cStringWithEncoding: [OFLocalization encoding]])) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errNo = EBUSY;
break;
|
|
<
|
|
<
|
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
|
[path stringByAppendingPathComponent: item]]];
objc_autoreleasePoolPop(pool2);
}
#ifndef OF_AMIGAOS
# ifndef OF_WINDOWS
if (rmdir([path cStringWithEncoding: [OFLocale encoding]]) != 0)
# else
if (_wrmdir([path UTF16String]) != 0)
# endif
@throw [OFRemoveItemFailedException
exceptionWithURL: URL
errNo: errno];
} else {
# ifndef OF_WINDOWS
if (unlink([path cStringWithEncoding:
[OFLocale encoding]]) != 0)
# else
if (_wunlink([path UTF16String]) != 0)
# endif
@throw [OFRemoveItemFailedException
exceptionWithURL: URL
errNo: errno];
#endif
}
#ifdef OF_AMIGAOS
if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) {
int errNo;
switch (IoErr()) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errNo = EBUSY;
break;
|
︙ | | | ︙ | |
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
![[destination scheme] isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
sourcePath = [source fileSystemRepresentation];
destinationPath = [destination fileSystemRepresentation];
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocalization encoding];
if (link([sourcePath cStringWithEncoding: encoding],
[destinationPath cStringWithEncoding: encoding]) != 0)
@throw [OFLinkFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
|
|
|
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
![[destination scheme] isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
sourcePath = [source fileSystemRepresentation];
destinationPath = [destination fileSystemRepresentation];
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocale encoding];
if (link([sourcePath cStringWithEncoding: encoding],
[destinationPath cStringWithEncoding: encoding]) != 0)
@throw [OFLinkFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
|
︙ | | | ︙ | |
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
|
if (![[URL scheme] isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocalization encoding];
if (symlink([target cStringWithEncoding: encoding],
[path cStringWithEncoding: encoding]) != 0)
@throw [OFCreateSymbolicLinkFailedException
exceptionWithURL: URL
target: target
errNo: errno];
|
|
|
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
|
if (![[URL scheme] isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
path = [URL fileSystemRepresentation];
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocale encoding];
if (symlink([target cStringWithEncoding: encoding],
[path cStringWithEncoding: encoding]) != 0)
@throw [OFCreateSymbolicLinkFailedException
exceptionWithURL: URL
target: target
errNo: errno];
|
︙ | | | ︙ | |
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
|
if (_wrename([[source fileSystemRepresentation] UTF16String],
[[destination fileSystemRepresentation] UTF16String]) != 0)
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocalization encoding];
if (!Rename([[source fileSystemRepresentation]
cStringWithEncoding: encoding],
[[destination fileSystemRepresentation]
cStringWithEncoding: encoding])) {
int errNo;
|
|
|
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
|
if (_wrename([[source fileSystemRepresentation] UTF16String],
[[destination fileSystemRepresentation] UTF16String]) != 0)
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocale encoding];
if (!Rename([[source fileSystemRepresentation]
cStringWithEncoding: encoding],
[[destination fileSystemRepresentation]
cStringWithEncoding: encoding])) {
int errNo;
|
︙ | | | ︙ | |
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errNo];
}
#else
of_string_encoding_t encoding = [OFLocalization encoding];
if (rename([[source fileSystemRepresentation]
cStringWithEncoding: encoding],
[[destination fileSystemRepresentation]
cStringWithEncoding: encoding]) != 0)
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
|
|
|
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
|
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errNo];
}
#else
of_string_encoding_t encoding = [OFLocale encoding];
if (rename([[source fileSystemRepresentation]
cStringWithEncoding: encoding],
[[destination fileSystemRepresentation]
cStringWithEncoding: encoding]) != 0)
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
|
︙ | | | ︙ | |
︙ | | | ︙ | |
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifdef OF_NINTENDO_3DS
# include <malloc.h> /* For memalign() */
#endif
#include <errno.h>
#import "OFLocalization.h"
#import "OFException.h" /* For some E* -> WSAE* defines */
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"
|
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifdef OF_NINTENDO_3DS
# include <malloc.h> /* For memalign() */
#endif
#include <errno.h>
#import "OFLocale.h"
#import "OFException.h" /* For some E* -> WSAE* defines */
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"
|
︙ | | | ︙ | |
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
memset(&ret, '\0', sizeof(ret));
ret.length = sizeof(struct sockaddr_in);
sin->sin_family = AF_INET;
sin->sin_port = OF_BSWAP16_IF_LE(port);
if (inet_pton(AF_INET, [IPv4 cStringWithEncoding:
[OFLocalization encoding]], &sin->sin_addr) != 1)
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return ret;
}
|
|
|
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
memset(&ret, '\0', sizeof(ret));
ret.length = sizeof(struct sockaddr_in);
sin->sin_family = AF_INET;
sin->sin_port = OF_BSWAP16_IF_LE(port);
if (inet_pton(AF_INET, [IPv4 cStringWithEncoding: [OFLocale encoding]],
&sin->sin_addr) != 1)
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return ret;
}
|
︙ | | | ︙ | |
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
memset(&ret, '\0', sizeof(ret));
ret.length = sizeof(struct sockaddr_in6);
sin6->sin6_family = AF_INET6;
sin6->sin6_port = OF_BSWAP16_IF_LE(port);
if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding:
[OFLocalization encoding]], &sin6->sin_addr6) != 1)
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return ret;
}
#endif
|
|
|
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
memset(&ret, '\0', sizeof(ret));
ret.length = sizeof(struct sockaddr_in6);
sin6->sin6_family = AF_INET6;
sin6->sin6_port = OF_BSWAP16_IF_LE(port);
if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding: [OFLocale encoding]],
&sin6->sin_addr6) != 1)
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return ret;
}
#endif
|
︙ | | | ︙ | |
︙ | | | ︙ | |
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <string.h>
#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocalization.h"
#import "OFOptionsParser.h"
#import "OFSandbox.h"
#import "OFStdIOStream.h"
#import "OFURL.h"
#import "OFArc.h"
#import "GZIPArchive.h"
|
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <string.h>
#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFOptionsParser.h"
#import "OFSandbox.h"
#import "OFStdIOStream.h"
#import "OFURL.h"
#import "OFArc.h"
#import "GZIPArchive.h"
|
︙ | | | ︙ | |
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
[OFApplication activateSandbox: sandbox];
} @finally {
[sandbox release];
}
#endif
#ifndef OF_AMIGAOS
[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif
optionsParser = [OFOptionsParser parserWithOptions: options];
while ((option = [optionsParser nextOption]) != '\0') {
switch (option) {
case 'f':
if (_overwrite < 0)
|
|
|
|
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
[OFApplication activateSandbox: sandbox];
} @finally {
[sandbox release];
}
#endif
#ifndef OF_AMIGAOS
[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif
optionsParser = [OFOptionsParser parserWithOptions: options];
while ((option = [optionsParser nextOption]) != '\0') {
switch (option) {
case 'f':
if (_overwrite < 0)
|
︙ | | | ︙ | |
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
of_range(1, [remainingArguments count] - 1)];
@try {
[archive extractFiles: files];
} @catch (OFCreateDirectoryFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_create_directory",
@"Failed to create directory %[dir]: %[error]",
@"dir", [[e URL] fileSystemRepresentation],
@"error", error)];
_exitStatus = 1;
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
_exitStatus = 1;
|
|
|
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
of_range(1, [remainingArguments count] - 1)];
@try {
[archive extractFiles: files];
} @catch (OFCreateDirectoryFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_create_directory",
@"Failed to create directory %[dir]: %[error]",
@"dir", [[e URL] fileSystemRepresentation],
@"error", error)];
_exitStatus = 1;
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
_exitStatus = 1;
|
︙ | | | ︙ | |
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
@try {
file = [OFFile fileWithPath: path
mode: fileModeString];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
[OFApplication terminateWithStatus: 1];
|
|
|
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
@try {
file = [OFFile fileWithPath: path
mode: fileModeString];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
[OFApplication terminateWithStatus: 1];
|
︙ | | | ︙ | |
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
goto error;
}
@throw e;
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFSeekFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file",
@"Failed to seek in file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFInvalidFormatException *e) {
[of_stderr writeLine: OF_LOCALIZED(
|
|
|
|
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
goto error;
}
@throw e;
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFSeekFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file",
@"Failed to seek in file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFInvalidFormatException *e) {
[of_stderr writeLine: OF_LOCALIZED(
|
︙ | | | ︙ | |
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
@try {
length = [input readIntoBuffer: buffer
length: BUFFER_SIZE];
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
@try {
[output writeBuffer: buffer
length: length];
} @catch (OFWriteFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_write_file",
@"Failed to write file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
|
|
|
|
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
@try {
length = [input readIntoBuffer: buffer
length: BUFFER_SIZE];
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
@try {
[output writeBuffer: buffer
length: length];
} @catch (OFWriteFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_write_file",
@"Failed to write file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFStdIOStream.h"
#import "OFLocalization.h"
#import "OFSandbox.h"
#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"
@interface OFHash: OFObject <OFApplicationDelegate>
@end
|
|
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFStdIOStream.h"
#import "OFLocale.h"
#import "OFSandbox.h"
#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"
@interface OFHash: OFObject <OFApplicationDelegate>
@end
|
︙ | | | ︙ | |
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
[OFApplication activateSandbox: sandbox];
} @finally {
[sandbox release];
}
#endif
#ifndef OF_AMIGAOS
[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif
if ([arguments count] < 2)
help();
if ((hash = hashForName([arguments firstObject])) == nil)
help();
|
|
|
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
[OFApplication activateSandbox: sandbox];
} @finally {
[sandbox release];
}
#endif
#ifndef OF_AMIGAOS
[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif
if ([arguments count] < 2)
help();
if ((hash = hashForName([arguments firstObject])) == nil)
help();
|
︙ | | | ︙ | |
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
else {
@try {
file = [OFFile fileWithPath: path
mode: @"r"];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization
encoding]];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
|
|
<
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
else {
@try {
file = [OFFile fileWithPath: path
mode: @"r"];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", [e path],
@"error", error)];
|
︙ | | | ︙ | |
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
@try {
length = [file readIntoBuffer: buffer
length: 1024];
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocalization
encoding]];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_read_file",
@"Failed to read %[file]: %[error]",
@"file", path,
@"error", error)];
|
|
<
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
@try {
length = [file readIntoBuffer: buffer
length: 1024];
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror([e errNo])
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(
@"failed_to_read_file",
@"Failed to read %[file]: %[error]",
@"file", path,
@"error", error)];
|
︙ | | | ︙ | |