ObjFW  Diff

Differences From Artifact [af4f6fe02e]:

To Artifact [10883a3ba0]:


51
52
53
54
55
56
57
58

59
60
61
62
63
64
65

66
67
68
69
70
71
72
51
52
53
54
55
56
57

58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-
+






-
+







atexit_handler(void)
{
	id <OFApplicationDelegate> delegate = [app delegate];

	if ([delegate respondsToSelector: @selector(applicationWillTerminate)])
		[delegate applicationWillTerminate];

	[(id)delegate release];
	[delegate release];
}

#define SIGNAL_HANDLER(sig)					\
	static void						\
	handle##sig(int signal)					\
	{							\
		app->sig##Handler(app->delegate,		\
		app->_##sig##Handler(app->_delegate,		\
		    @selector(applicationDidReceive##sig));	\
	}
SIGNAL_HANDLER(SIGINT)
#ifndef _WIN32
SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
SIGNAL_HANDLER(SIGUSR2)
135
136
137
138
139
140
141

142
143
144
145
146
147
148
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149







+








- init
{
	self = [super init];

	@try {
		void *pool;
		OFMutableDictionary *environment;
#if defined(__MACH__) && !defined(OF_IOS)
		char **env = *_NSGetEnviron();
#elif defined(__WIN32)
		uint16_t *env;
#elif !defined(OF_IOS)
		char **env = environ;
#else
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
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







+








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



+


-
-
+
+

-
+










+



-
-
+
+




-
-
+
+


+


-
+


-
+

-
+


+





-
-
+
+

-
-
+
+




-
+




-
+




-
+




-
+


-
+

-
+




-
+







					forKey: @"USER"];
		}

		objc_autoreleasePoolPop(pool);
#endif

		[environment makeImmutable];
		_environment = environment;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_arguments release];
	[_environment release];

	[super dealloc];
}

- (void)OF_setArgumentCount: (int*)argc_
	  andArgumentValues: (char***)argv_
- (void)OF_setArgumentCount: (int*)argc
	  andArgumentValues: (char***)argv
{
#ifndef _WIN32
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *arguments;
	int i;

	argc = argc_;
	argv = argv_;
	_argc = argc;
	_argv = argv;

	programName = [[OFString alloc]
	_programName = [[OFString alloc]
	    initWithCString: (*argv)[0]
		   encoding: OF_STRING_ENCODING_NATIVE];
	arguments = [[OFMutableArray alloc] init];

	for (i = 1; i < *argc; i++)
		[arguments addObject:
		    [OFString stringWithCString: (*argv)[i]
				       encoding: OF_STRING_ENCODING_NATIVE]];

	[arguments makeImmutable];
	_arguments = arguments;

	objc_autoreleasePoolPop(pool);
#else
	argc = argc_;
	argv = argv_;
	_argc = argc;
	_argv = argv;
#endif
}

#ifdef _WIN32
- (void)OF_setArgumentCount: (int)argc_
      andWideArgumentValues: (wchar_t**)argv_
- (void)OF_setArgumentCount: (int)argc
      andWideArgumentValues: (wchar_t**)argv
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *arguments;
	int i;

	programName = [[OFString alloc] initWithUTF16String: argv_[0]];
	_programName = [[OFString alloc] initWithUTF16String: argv[0]];
	arguments = [[OFMutableArray alloc] init];

	for (i = 1; i < argc_; i++)
	for (i = 1; i < argc; i++)
		[arguments addObject:
		    [OFString stringWithUTF16String: argv_[i]]];
		    [OFString stringWithUTF16String: argv[i]]];

	[arguments makeImmutable];
	_arguments = arguments;

	objc_autoreleasePoolPop(pool);
}
#endif

- (void)getArgumentCount: (int**)argc_
       andArgumentValues: (char****)argv_
- (void)getArgumentCount: (int**)argc
       andArgumentValues: (char****)argv
{
	*argc_ = argc;
	*argv_ = argv;
	*argc = _argc;
	*argv = _argv;
}

- (OFString*)programName
{
	OF_GETTER(programName, NO)
	OF_GETTER(_programName, NO)
}

- (OFArray*)arguments
{
	OF_GETTER(arguments, NO)
	OF_GETTER(_arguments, NO)
}

- (OFDictionary*)environment
{
	OF_GETTER(environment, NO)
	OF_GETTER(_environment, NO)
}

- (id <OFApplicationDelegate>)delegate
{
	return delegate;
	return _delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
- (void)setDelegate: (id <OFApplicationDelegate>)delegate
{
	delegate = delegate_;
	_delegate = delegate;

#define REGISTER_SIGNAL(sig)						\
	if ([delegate respondsToSelector:				\
	    @selector(applicationDidReceive##sig)]) {			\
		sig##Handler = (void(*)(id, SEL))[(id)delegate		\
		_##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
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
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







+
+
+
+
+
+

-
+














-
-
-
-
-
-
-
-

	runLoop = [[[OFRunLoop alloc] init] autorelease];
#endif

	[OFRunLoop OF_setMainRunLoop: runLoop];

	objc_autoreleasePoolPop(pool);

	/*
	 * Note: runLoop is still valid after the release of the pool, as
	 * OF_setMainRunLoop: retained it. However, we only have a weak
	 * reference to it now, whereas we had a strong reference before.
	 */

	pool = objc_autoreleasePoolPush();
	[delegate applicationDidFinishLaunching];
	[_delegate applicationDidFinishLaunching];
	objc_autoreleasePoolPop(pool);

	[runLoop run];
}

- (void)terminate
{
	exit(0);
}

- (void)terminateWithStatus: (int)status
{
	exit(status);
}

- (void)dealloc
{
	[arguments release];
	[environment release];

	[super dealloc];
}
@end