ObjFW  Diff

Differences From Artifact [28e90aedf9]:

To Artifact [620606a28a]:


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
72
73
74
75
76
77
#import "OFStdIOStream.h"
#import "OFString.h"

@interface ObjFWNew: OFObject <OFApplicationDelegate>
@end

extern void newApp(OFString *);
extern void newClass(OFString *, 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;
	OFString *superclass = nil;

	const OFOptionsParserOption options[] = {
		{ '\0', @"app", 0, &app, NULL },
		{ '\0', @"class", 0, &class, NULL },
		{ '\0', @"superclass", 1, NULL, &superclass },

		{ '\0', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser;
	OFUnichar option;

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






		if (option == '?' || option == ':' || option == '=')






			showUsage();




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

	if (superclass && !class)
		showUsage();

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

	[OFApplication terminate];
}
@end







|

















>




>






|
>
>
>
>
>
>
|
>
>
>
>
>
>

>
>
>




|






|






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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#import "OFStdIOStream.h"
#import "OFString.h"

@interface ObjFWNew: OFObject <OFApplicationDelegate>
@end

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

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;
	OFString *superclass = nil;
	OFMutableArray OF_GENERIC(OFString *) *properties = nil;
	const OFOptionsParserOption options[] = {
		{ '\0', @"app", 0, &app, NULL },
		{ '\0', @"class", 0, &class, NULL },
		{ '\0', @"superclass", 1, NULL, &superclass },
		{ '\0', @"property", 1, NULL, NULL },
		{ '\0', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser;
	OFUnichar option;

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case '-':;
			if ([optionsParser.lastLongOption
			    isEqual: @"property"]) {
				if (properties == nil)
					properties = [OFMutableArray array];

				[properties addObject: optionsParser.argument];
			}
			break;
		case '?':
		case ':':
		case '=':
			showUsage();
			break;
		}
	}

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

	if ((superclass && !class)  || (properties != nil && !class))
		showUsage();

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

	[OFApplication terminate];
}
@end