Differences From Artifact [917ac12657]:
- File src/OFOptionsParser.m — part of check-in [1808782994] at 2016-02-28 16:08:50 on branch trunk — OFOptionsParser: Make sure _options is terminated (user: js, size: 6464) [annotate] [blame] [check-ins using]
To Artifact [69cbd54c95]:
- File
src/OFOptionsParser.m
— part of check-in
[1ba9c051a6]
at
2016-06-04 18:49:46
on branch trunk
— OFMapTable: Rename valueForKey to objectForKey
The reason for this is that -[valueForKey:] could be confused with
Key Value Coding. (user: js, size: 6476) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFApplication.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFInvalidArgumentException.h" static uint32_t | | | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFApplication.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFInvalidArgumentException.h" static uint32_t stringHash(void *object) { return [(OFString*)object hash]; } static bool stringEqual(void *object1, void *object2) { 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 |
︙ | ︙ | |||
57 58 59 60 61 62 63 | 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 }; | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 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 */ for (iter = options; iter->shortOption != '\0' || iter->longOption != nil; iter++) { if (iter->hasArgument < -1 || iter->hasArgument > 1) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
83 84 85 86 87 88 89 | *iter->argumentPtr = nil; count++; } _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions | | | | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | *iter->argumentPtr = nil; count++; } _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions]; _options = [self allocMemoryWithSize: sizeof(*_options) count: count + 1]; for (iter = options, iter2 = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++, iter2++) { iter2->shortOption = iter->shortOption; iter2->longOption = nil; iter2->hasArgument = iter->hasArgument; iter2->isSpecifiedPtr = iter->isSpecifiedPtr; iter2->argumentPtr = iter->argumentPtr; if (iter->longOption != nil) { @try { iter2->longOption = [iter->longOption copy]; if ([_longOptions objectForKey: iter2->longOption] != NULL) @throw [OFInvalidArgumentException exception]; [_longOptions setObject: iter2 forKey: iter2->longOption]; } @catch (id e) { /* * Make sure we are in a consistent * state where dealloc works. */ [iter2->longOption release]; |
︙ | ︙ | |||
205 206 207 208 209 210 211 | pos = [argument length]; _lastLongOption = [[argument substringWithRange: of_range(2, pos - 2)] copy]; objc_autoreleasePoolPop(pool); | | | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | pos = [argument length]; _lastLongOption = [[argument substringWithRange: of_range(2, pos - 2)] copy]; objc_autoreleasePoolPop(pool); option = [_longOptions objectForKey: _lastLongOption]; if (option == NULL) return '?'; if (option->hasArgument == 1 && _argument == nil) return ':'; if (option->hasArgument == 0 && _argument != nil) return '='; |
︙ | ︙ |