ObjFW  Check-in [fb1f29bd30]

Overview
Comment:OFApplication: Get Unicode arguments on Win32.

It still stores the normal argc/argv for compatibility, however, the
argument array is created from the Unicode arguments instead.

This also makes -[OFApplication setArgumentCount:andArgumentValues:]
private.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fb1f29bd309e1783ec7d95dcbaff48f93bf889af0aba19e8fc1a97e255f6933e
User & Date: js on 2013-01-08 03:13:34
Original User & Date: js on 2013-01-08 03:13:35
Other Links: manifest | tags
Context
2013-01-08
03:13
Win32: Allow Unicode filenames in file operations. check-in: 94a9a18106 user: js tags: trunk
03:13
OFApplication: Get Unicode arguments on Win32. check-in: fb1f29bd30 user: js tags: trunk
03:13
OFProcess: Correctly handle Unicode env on Win32. check-in: 52f2c17f55 user: js tags: trunk
Changes

Modified src/OFApplication.h from [e7a89febd1] to [24a84dfbfd].

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175




176
177
178
179
180
181
182
/*!
 * @brief Terminates the application with the specified status.
 *
 * @param status The status with which the application will terminate
 */
+ (void)terminateWithStatus: (int)status;

/*!
 * @brief Sets argc and argv.
 *
 * You should not call this directly, but use OF_APPLICATION_DELEGATE instead!
 *
 * @param argc The number of arguments
 * @param argv The argument values
 */
- (void)setArgumentCount: (int*)argc
       andArgumentValues: (char**[])argv;





/*!
 * @brief Gets args and argv.
 *
 * @param argc A pointer where a pointer to argc should be stored
 * @param argv A pointer where a pointer to argv should be stored
 */







<
<
<
<
<
<
<
<
|
|
>
>
>
>







159
160
161
162
163
164
165








166
167
168
169
170
171
172
173
174
175
176
177
178
/*!
 * @brief Terminates the application with the specified status.
 *
 * @param status The status with which the application will terminate
 */
+ (void)terminateWithStatus: (int)status;









- (void)OF_setArgumentCount: (int*)argc
	  andArgumentValues: (char**[])argv;
#ifdef _WIN32
- (void)OF_setArgumentCount: (int)argc
      andWideArgumentValues: (wchar_t*[])argv;
#endif

/*!
 * @brief Gets args and argv.
 *
 * @param argc A pointer where a pointer to argc should be stored
 * @param argv A pointer where a pointer to argv should be stored
 */

Modified src/OFApplication.m from [30420d2d38] to [09b9e89928].

31
32
33
34
35
36
37



38
39
40
41
42
43
44

#import "autorelease.h"

#if defined(__MACH__) && !defined(OF_IOS)
# include <crt_externs.h>
#elif defined(_WIN32)
# include <windows.h>



#elif !defined(OF_IOS)
extern char **environ;
#endif

static OFApplication *app = nil;

static void







>
>
>







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

#import "autorelease.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

static OFApplication *app = nil;

static void
68
69
70
71
72
73
74




75
76
77






78
79
80
81
82
83
84
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];





	[app setArgumentCount: argc
	    andArgumentValues: argv];







	[app setDelegate: delegate];

	[app run];

	return 0;
}







>
>
>
>

|
|
>
>
>
>
>
>







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
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];
#ifdef _WIN32
	wchar_t **wargv, **wenvp;
	int wargc, si = 0;
#endif

	[app OF_setArgumentCount: argc
	       andArgumentValues: argv];

#ifdef _WIN32
	__wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si);
	[app OF_setArgumentCount: wargc
	   andWideArgumentValues: wargv];
#endif

	[app setDelegate: delegate];

	[app run];

	return 0;
}
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
		[self release];
		@throw e;
	}

	return self;
}

- (void)setArgumentCount: (int*)argc_
       andArgumentValues: (char***)argv_
{

	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];

	objc_autoreleasePoolPop(pool);




}





















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







|
|

>



<
<
<
















>
>
>
>

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







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
		[self release];
		@throw e;
	}

	return self;
}

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




	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];

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

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

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

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

	[arguments makeImmutable];

	objc_autoreleasePoolPop(pool);
}
#endif

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