ObjFW  Check-in [ceee745736]

Overview
Comment:objfw-new: Use proper long options
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ceee745736083f7d63cca97b4d125ead26af4951b5c921b18c25e2ca8bdce88b
User & Date: js on 2022-08-07 20:57:08
Other Links: manifest | tags
Context
2022-08-07
21:00
README.md: Use new objfw-new syntax check-in: 31066af476 user: js tags: trunk
20:57
objfw-new: Use proper long options check-in: ceee745736 user: js tags: trunk
20:46
Rewrite objfw-new in ObjC check-in: 1ad52a2f2c user: js tags: trunk
Changes

Modified utils/objfw-new/ObjFWNew.m from [aba8385948] to [6661dc925a].

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
39
40
41
42
43
44






45
46


47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFObject.h"

#import "OFStdIOStream.h"
#import "OFString.h"

@interface ObjFWNew: OFObject <OFApplicationDelegate>
@end

extern void newApp(OFString *);
extern void newClass(OFString *);

OF_APPLICATION_DELEGATE(ObjFWNew)

static void
showUsage(void)
{
	[OFStdErr writeFormat: @"Usage: %@ app|class name [properties]\n",
			       [OFApplication programName]];

	[OFApplication terminateWithStatus: 1];
}

@implementation ObjFWNew
- (void)applicationDidFinishLaunching
{
	OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments];






	OFString *type, *name;



	if (arguments.count != 2)
		showUsage();

	type = [arguments objectAtIndex: 0];
	name = [arguments objectAtIndex: 1];


	if ([type isEqual: @"app"])
		newApp(name);
	else if ([type isEqual: @"class"])
		newClass(name);
	else
		showUsage();

	[OFApplication terminate];
}
@end







>














|








|
>
>
>
>
>
>
|

>
>
|
|

|
<
>

|
|
|
|






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
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
68
69
70
71
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFObject.h"
#import "OFOptionsParser.h"
#import "OFStdIOStream.h"
#import "OFString.h"

@interface ObjFWNew: OFObject <OFApplicationDelegate>
@end

extern void newApp(OFString *);
extern void newClass(OFString *);

OF_APPLICATION_DELEGATE(ObjFWNew)

static void
showUsage(void)
{
	[OFStdErr writeFormat: @"Usage: %@ --app|--class name\n",
			       [OFApplication programName]];

	[OFApplication terminateWithStatus: 1];
}

@implementation ObjFWNew
- (void)applicationDidFinishLaunching
{
	bool app, class;
	const OFOptionsParserOption options[] = {
		{ '\0', @"app", 0, &app, NULL },
		{ '\0', @"class", 0, &class, NULL },
		{ '\0', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser;
	OFUnichar option;

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0')
		if (option == '?')
			showUsage();

	if ((app ^ class) != 1 || optionsParser.remainingArguments.count != 1)

		showUsage();

	if (app)
		newApp(optionsParser.remainingArguments.firstObject);
	else if (class)
		newClass(optionsParser.remainingArguments.firstObject);
	else
		showUsage();

	[OFApplication terminate];
}
@end