24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-
+
+
|
#include <signal.h>
#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFNotImplementedException.h"
#import "autorelease.h"
#if defined(__MACH__) && !defined(OF_IOS)
# include <crt_externs.h>
#elif !defined(OF_IOS)
extern char **environ;
#endif
|
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
|
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
|
-
+
-
-
+
+
-
+
+
+
+
+
-
-
+
-
+
|
}
- init
{
self = [super init];
@try {
OFAutoreleasePool *pool;
void *pool;
#if defined(__MACH__) && !defined(OF_IOS)
char **env = *_NSGetEnviron();
#elif !defined(OF_IOS)
char **env = environ;
#else
char *env;
#endif
environment = [[OFMutableDictionary alloc] init];
atexit(atexit_handler);
pool = [[OFAutoreleasePool alloc] init];
#ifndef OF_IOS
for (; *env != NULL; env++) {
OFString *key;
OFString *value;
char *sep;
pool = objc_autoreleasePoolPush();
if ((sep = strchr(*env, '=')) == NULL) {
fprintf(stderr, "Warning: Invalid environment "
"variable: %s\n", *env);
continue;
}
key = [OFString
stringWithCString: *env
encoding: OF_STRING_ENCODING_NATIVE
length: sep - *env];
value = [OFString
stringWithCString: sep + 1
encoding: OF_STRING_ENCODING_NATIVE];
[environment setObject: value
forKey: key];
[pool releaseObjects];
objc_autoreleasePoolPop(pool);
}
#else
/*
* iOS does not provide environ and Apple does not allow using
* _NSGetEnviron on iOS. Therefore, we just get a few common
* variables from the environment which applications might
* expect.
*/
pool = objc_autoreleasePoolPush();
if ((env = getenv("HOME")) != NULL)
[environment
setObject: [OFString stringWithUTF8String: env]
forKey: @"HOME"];
if ((env = getenv("PATH")) != NULL)
[environment
setObject: [OFString stringWithUTF8String: env]
forKey: @"PATH"];
if ((env = getenv("SHELL")) != NULL)
[environment
setObject: [OFString stringWithUTF8String: env]
forKey: @"SHELL"];
if ((env = getenv("TMPDIR")) != NULL)
[environment
setObject: [OFString stringWithUTF8String: env]
forKey: @"TMPDIR"];
if ((env = getenv("USER")) != NULL)
[environment
setObject: [OFString stringWithUTF8String: env]
forKey: @"USER"];
objc_autoreleasePoolPop(pool);
#endif
[pool release];
[environment makeImmutable];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)setArgumentCount: (int*)argc_
andArgumentValues: (char***)argv_
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
void *pool = objc_autoreleasePoolPush();
int i;
[programName release];
[arguments release];
argc = argc_;
argv = argv_;
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];
[pool release];
objc_autoreleasePoolPop(pool);
}
- (void)getArgumentCount: (int**)argc_
andArgumentValues: (char****)argv_
{
*argc_ = argc;
*argv_ = argv;
|