ObjFW  Diff

Differences From Artifact [e8b77ada50]:

To Artifact [78ea526057]:


10
11
12
13
14
15
16

17
18
19
20
21








22
23
24
25
26
27
28
29
 */

#include "config.h"

#include <stdlib.h>

#import "OFApplication.h"

#import "OFArray.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"









OFApplication *app = nil;

static void
atexit_handler()
{
	id delegate = [app delegate];

	[delegate applicationWillTerminate];







>

|



>
>
>
>
>
>
>
>
|







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
 */

#include "config.h"

#include <stdlib.h>

#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#include <string.h>

#ifdef __MACH__
# include <crt_externs.h>
#else
 extern char **environ;
#endif

static OFApplication *app = nil;

static void
atexit_handler()
{
	id delegate = [app delegate];

	[delegate applicationWillTerminate];
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
	return [app programName];
}

+ (OFArray*)arguments
{
	return [app arguments];
}






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

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

- init
{



	self = [super init];



	atexit(atexit_handler);




























	return self;
}

- (void)setArgumentCount: (int)argc
       andArgumentValues: (char**)argv
{







>
>
>
>
>













>
>
>


>
>

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







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
	return [app programName];
}

+ (OFArray*)arguments
{
	return [app arguments];
}

+ (OFDictionary*)environment
{
	return [app environment];
}

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

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

- init
{
	OFAutoreleasePool *pool;
	char **env;

	self = [super init];

	environment = [[OFMutableDictionary alloc] init];

	atexit(atexit_handler);
#ifdef __MACH__
	env = *_NSGetEnviron();
#else
	env = environ;
#endif

	pool = [[OFAutoreleasePool alloc] init];
	for (; *env != NULL; env++) {
		OFString *key;
		OFString *value;
		char *sep;

		if ((sep = strchr(*env, '=')) == NULL) {
			fprintf(stderr, "Warning: Invalid environment "
			    "variable: %s\n", *env);
			continue;
		}

		key = [OFString stringWithCString: *env
					   length: sep - *env];
		value = [OFString stringWithCString: sep + 1];
		[environment setObject: value
				forKey: key];

		[pool releaseObjects];
	}
	[pool release];

	return self;
}

- (void)setArgumentCount: (int)argc
       andArgumentValues: (char**)argv
{
112
113
114
115
116
117
118





119
120
121
122
123
124
125
	return [[programName retain] autorelease];
}

- (OFArray*)arguments
{
	return [[arguments retain] autorelease];
}






- (id)delegate
{
	return [[delegate retain] autorelease];
}

- (void)setDelegate: (id)delegate_







>
>
>
>
>







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
	return [[programName retain] autorelease];
}

- (OFArray*)arguments
{
	return [[arguments retain] autorelease];
}

- (OFDictionary*)environment
{
	return [[environment retain] autorelease];
}

- (id)delegate
{
	return [[delegate retain] autorelease];
}

- (void)setDelegate: (id)delegate_
143
144
145
146
147
148
149

150
151
152
153
154
155
156
{
	exit(status);
}

- (void)dealloc
{
	[arguments release];

	[delegate release];

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)







>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
	exit(status);
}

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

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)