︙ | | | ︙ | |
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
|
return [(OFString *)object1 isEqual: (OFString *)object2];
}
@implementation OFOptionsParser
@synthesize lastOption = _lastOption, lastLongOption = _lastLongOption;
@synthesize argument = _argument;
+ (instancetype)parserWithOptions: (const of_options_parser_option_t *)options
{
return [[[self alloc] initWithOptions: options] autorelease];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithOptions: (const of_options_parser_option_t *)options
{
self = [super init];
@try {
size_t count = 0;
const of_options_parser_option_t *iter;
of_options_parser_option_t *iter2;
const of_map_table_functions_t keyFunctions = {
.hash = stringHash,
.equal = stringEqual
};
const of_map_table_functions_t objectFunctions = { NULL };
/* Count, sanity check, initialize pointers */
|
|
|
|
|
|
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
|
return [(OFString *)object1 isEqual: (OFString *)object2];
}
@implementation OFOptionsParser
@synthesize lastOption = _lastOption, lastLongOption = _lastLongOption;
@synthesize argument = _argument;
+ (instancetype)parserWithOptions: (const OFOptionsParserOption *)options
{
return [[[self alloc] initWithOptions: options] autorelease];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithOptions: (const OFOptionsParserOption *)options
{
self = [super init];
@try {
size_t count = 0;
const OFOptionsParserOption *iter;
OFOptionsParserOption *iter2;
const of_map_table_functions_t keyFunctions = {
.hash = stringHash,
.equal = stringEqual
};
const of_map_table_functions_t objectFunctions = { NULL };
/* Count, sanity check, initialize pointers */
|
︙ | | | ︙ | |
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
|
return self;
}
- (void)dealloc
{
if (_options != NULL)
for (of_options_parser_option_t *iter = _options;
iter->shortOption != '\0' || iter->longOption != nil;
iter++)
[iter->longOption release];
free(_options);
[_longOptions release];
[_arguments release];
[_argument release];
[super dealloc];
}
- (of_unichar_t)nextOption
{
of_options_parser_option_t *iter;
OFString *argument;
if (_done || _index >= _arguments.count)
return '\0';
[_lastLongOption release];
[_argument release];
|
|
|
|
|
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
|
return self;
}
- (void)dealloc
{
if (_options != NULL)
for (OFOptionsParserOption *iter = _options;
iter->shortOption != '\0' || iter->longOption != nil;
iter++)
[iter->longOption release];
free(_options);
[_longOptions release];
[_arguments release];
[_argument release];
[super dealloc];
}
- (OFUnichar)nextOption
{
OFOptionsParserOption *iter;
OFString *argument;
if (_done || _index >= _arguments.count)
return '\0';
[_lastLongOption release];
[_argument release];
|
︙ | | | ︙ | |
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
|
_index++;
return '\0';
}
if ([argument hasPrefix: @"--"]) {
void *pool = objc_autoreleasePoolPush();
size_t pos;
of_options_parser_option_t *option;
_lastOption = '-';
_index++;
if ((pos = [argument rangeOfString: @"="].location) !=
OF_NOT_FOUND)
_argument = [[argument
substringFromIndex: pos + 1] copy];
else
pos = argument.length;
_lastLongOption = [[argument substringWithRange:
of_range(2, pos - 2)] copy];
objc_autoreleasePoolPop(pool);
option = [_longOptions objectForKey: _lastLongOption];
if (option == NULL)
return '?';
|
|
|
|
|
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
|
_index++;
return '\0';
}
if ([argument hasPrefix: @"--"]) {
void *pool = objc_autoreleasePoolPush();
size_t pos;
OFOptionsParserOption *option;
_lastOption = '-';
_index++;
if ((pos = [argument rangeOfString: @"="].location) !=
OFNotFound)
_argument = [[argument
substringFromIndex: pos + 1] copy];
else
pos = argument.length;
_lastLongOption = [[argument substringWithRange:
OFRangeMake(2, pos - 2)] copy];
objc_autoreleasePoolPop(pool);
option = [_longOptions objectForKey: _lastLongOption];
if (option == NULL)
return '?';
|
︙ | | | ︙ | |
267
268
269
270
271
272
273
274
275
276
|
return '?';
}
- (OFArray *)remainingArguments
{
return [_arguments objectsInRange:
of_range(_index, _arguments.count - _index)];
}
@end
|
|
|
267
268
269
270
271
272
273
274
275
276
|
return '?';
}
- (OFArray *)remainingArguments
{
return [_arguments objectsInRange:
OFRangeMake(_index, _arguments.count - _index)];
}
@end
|