︙ | | | ︙ | |
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
|
#import "OFDictionary.h"
#import "OFSystemInfo.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#if defined(__MACH__) && !defined(OF_IOS)
# include <crt_externs.h>
#elif defined(_WIN32)
# include <windows.h>
extern int _CRT_glob;
extern void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*);
#elif !defined(OF_IOS)
extern char **environ;
#endif
#ifdef _PSP
# include <pspkerneltypes.h>
# include <psploadexec.h>
#endif
#ifdef OF_NINTENDO_DS
# define asm __asm__
# include <nds.h>
# undef asm
#endif
@interface OFApplication (OF_PRIVATE_CATEGORY)
- (void)OF_setArgumentCount: (int*)argc
andArgumentValues: (char**[])argv;
#ifdef _WIN32
- (void)OF_setArgumentCount: (int)argc
andWideArgumentValues: (wchar_t*[])argv;
#endif
- (void)OF_run;
@end
static OFApplication *app = nil;
|
|
|
|
|
|
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
|
#import "OFDictionary.h"
#import "OFSystemInfo.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#if defined(OF_MAC_OS_X)
# include <crt_externs.h>
#elif defined(OF_WINDOWS)
# include <windows.h>
extern int _CRT_glob;
extern void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*);
#elif !defined(OF_IOS)
extern char **environ;
#endif
#ifdef OF_PSP
# include <pspkerneltypes.h>
# include <psploadexec.h>
#endif
#ifdef OF_NINTENDO_DS
# define asm __asm__
# include <nds.h>
# undef asm
#endif
@interface OFApplication (OF_PRIVATE_CATEGORY)
- (void)OF_setArgumentCount: (int*)argc
andArgumentValues: (char**[])argv;
#ifdef OF_WINDOWS
- (void)OF_setArgumentCount: (int)argc
andWideArgumentValues: (wchar_t*[])argv;
#endif
- (void)OF_run;
@end
static OFApplication *app = nil;
|
︙ | | | ︙ | |
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
|
static void \
handle##sig(int signal) \
{ \
app->_##sig##Handler(app->_delegate, \
@selector(applicationDidReceive##sig)); \
}
SIGNAL_HANDLER(SIGINT)
#ifndef _WIN32
SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
SIGNAL_HANDLER(SIGUSR2)
#endif
#undef SIGNAL_HANDLER
int
of_application_main(int *argc, char **argv[], Class cls)
{
id <OFApplicationDelegate> delegate;
#ifdef _WIN32
wchar_t **wargv, **wenvp;
int wargc, si = 0;
#endif
if ([cls isSubclassOfClass: [OFApplication class]]) {
fprintf(stderr, "FATAL ERROR:\n Class %s is a subclass of "
"class OFApplication, but class\n %s was specified as "
"application delegate!\n Most likely, you wanted to "
"subclass OFObject instead or specified\n the wrong class "
"with OF_APPLICATION_DELEGATE().\n",
class_getName(cls), class_getName(cls));
exit(1);
}
app = [[OFApplication alloc] init];
[app OF_setArgumentCount: argc
andArgumentValues: argv];
#ifdef _WIN32
__wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si);
[app OF_setArgumentCount: wargc
andWideArgumentValues: wargv];
#endif
delegate = [[cls alloc] init];
[app setDelegate: delegate];
|
|
|
|
|
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
|
static void \
handle##sig(int signal) \
{ \
app->_##sig##Handler(app->_delegate, \
@selector(applicationDidReceive##sig)); \
}
SIGNAL_HANDLER(SIGINT)
#ifndef OF_WINDOWS
SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
SIGNAL_HANDLER(SIGUSR2)
#endif
#undef SIGNAL_HANDLER
int
of_application_main(int *argc, char **argv[], Class cls)
{
id <OFApplicationDelegate> delegate;
#ifdef OF_WINDOWS
wchar_t **wargv, **wenvp;
int wargc, si = 0;
#endif
if ([cls isSubclassOfClass: [OFApplication class]]) {
fprintf(stderr, "FATAL ERROR:\n Class %s is a subclass of "
"class OFApplication, but class\n %s was specified as "
"application delegate!\n Most likely, you wanted to "
"subclass OFObject instead or specified\n the wrong class "
"with OF_APPLICATION_DELEGATE().\n",
class_getName(cls), class_getName(cls));
exit(1);
}
app = [[OFApplication alloc] init];
[app OF_setArgumentCount: argc
andArgumentValues: argv];
#ifdef OF_WINDOWS
__wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si);
[app OF_setArgumentCount: wargc
andWideArgumentValues: wargv];
#endif
delegate = [[cls alloc] init];
[app setDelegate: delegate];
|
︙ | | | ︙ | |
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
|
+ (void)terminate
{
exit(0);
}
+ (void)terminateWithStatus: (int)status
{
#ifdef _PSP
sceKernelExitGame();
abort(); /* sceKernelExitGame() is not marked noreturn */
#else
exit(status);
#endif
}
- init
{
self = [super init];
@try {
void *pool;
OFMutableDictionary *environment;
#if defined(__MACH__) && !defined(OF_IOS)
char **env = *_NSGetEnviron();
#elif defined(_WIN32)
of_char16_t *env, *env0;
#elif !defined(OF_IOS)
char **env = environ;
#else
char *env;
#endif
environment = [[OFMutableDictionary alloc] init];
atexit(atexitHandler);
#if defined(_WIN32)
env = env0 = GetEnvironmentStringsW();
while (*env != 0) {
OFString *tmp, *key, *value;
size_t length, pos;
pool = objc_autoreleasePoolPush();
|
|
|
|
|
|
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
|
+ (void)terminate
{
exit(0);
}
+ (void)terminateWithStatus: (int)status
{
#ifdef OF_PSP
sceKernelExitGame();
abort(); /* sceKernelExitGame() is not marked noreturn */
#else
exit(status);
#endif
}
- init
{
self = [super init];
@try {
void *pool;
OFMutableDictionary *environment;
#if defined(OF_MAC_OS_X)
char **env = *_NSGetEnviron();
#elif defined(OF_WINDOWS)
of_char16_t *env, *env0;
#elif !defined(OF_IOS)
char **env = environ;
#else
char *env;
#endif
environment = [[OFMutableDictionary alloc] init];
atexit(atexitHandler);
#if defined(OF_WINDOWS)
env = env0 = GetEnvironmentStringsW();
while (*env != 0) {
OFString *tmp, *key, *value;
size_t length, pos;
pool = objc_autoreleasePoolPush();
|
︙ | | | ︙ | |
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
[super dealloc];
}
- (void)OF_setArgumentCount: (int*)argc
andArgumentValues: (char***)argv
{
#ifndef _WIN32
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
int i;
of_string_encoding_t encoding;
_argc = argc;
_argv = argv;
|
|
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
[super dealloc];
}
- (void)OF_setArgumentCount: (int*)argc
andArgumentValues: (char***)argv
{
#ifndef OF_WINDOWS
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
int i;
of_string_encoding_t encoding;
_argc = argc;
_argv = argv;
|
︙ | | | ︙ | |
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
objc_autoreleasePoolPop(pool);
#else
_argc = argc;
_argv = argv;
#endif
}
#ifdef _WIN32
- (void)OF_setArgumentCount: (int)argc
andWideArgumentValues: (wchar_t**)argv
{
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
int i;
|
|
|
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
objc_autoreleasePoolPop(pool);
#else
_argc = argc;
_argv = argv;
#endif
}
#ifdef OF_WINDOWS
- (void)OF_setArgumentCount: (int)argc
andWideArgumentValues: (wchar_t**)argv
{
void *pool = objc_autoreleasePoolPush();
OFMutableArray *arguments;
int i;
|
︙ | | | ︙ | |
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
_##sig##Handler = (void(*)(id, SEL))[(id)delegate \
methodForSelector: \
@selector(applicationDidReceive##sig)]; \
signal(sig, handle##sig); \
} else \
signal(sig, SIG_DFL);
REGISTER_SIGNAL(SIGINT)
#ifndef _WIN32
REGISTER_SIGNAL(SIGHUP)
REGISTER_SIGNAL(SIGUSR1)
REGISTER_SIGNAL(SIGUSR2)
#endif
#undef REGISTER_SIGNAL
}
|
|
|
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
_##sig##Handler = (void(*)(id, SEL))[(id)delegate \
methodForSelector: \
@selector(applicationDidReceive##sig)]; \
signal(sig, handle##sig); \
} else \
signal(sig, SIG_DFL);
REGISTER_SIGNAL(SIGINT)
#ifndef OF_WINDOWS
REGISTER_SIGNAL(SIGHUP)
REGISTER_SIGNAL(SIGUSR1)
REGISTER_SIGNAL(SIGUSR2)
#endif
#undef REGISTER_SIGNAL
}
|
︙ | | | ︙ | |