32#if OO_LOCALIZATION_TOOLS
39static NSMutableDictionary *
InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices);
40static NSString *
IndexToKey(NSUInteger index, NSDictionary *indicesToKeys, BOOL useFallback);
42static NSNumber *
KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache);
43static NSArray *
ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache);
44static NSUInteger
HighestIndex(NSMutableDictionary *sparseArray);
49 NSDictionary *sysDescDict =
nil;
50 NSArray *sysDescArray =
nil;
51 NSDictionary *keyMap =
nil;
53 NSString *error =
nil;
58 if (sysDescDict ==
nil)
60 OOLog(
@"sysdesc.compile.failed.fileNotFound",
@"%@",
@"Could not load a dictionary from sysdesc.plist, ignoring --compile-sysdesc option.");
70 if (sysDescArray ==
nil)
72 OOLog(
@"sysdesc.compile.failed.conversion",
@"%@",
@"Could not convert sysdesc.plist to descriptions.plist format for some reason.");
76 sysDescDict = [NSDictionary dictionaryWithObject:sysDescArray forKey:@"system_description"];
80 data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
81 format:NSPropertyListXMLFormat_v1_0
82 errorDescription:&error];
86 data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
91 OOLog(
@"sysdesc.compile.failed.XML",
@"Could not convert translated sysdesc.plist to property list: %@.", error);
95 if ([
ResourceManager writeDiagnosticData:data toFileNamed:
@"sysdesc-compiled.plist"])
97 OOLog(
@"sysdesc.compile.success",
@"%@",
@"Wrote translated sysdesc.plist to sysdesc-compiled.plist.");
101 OOLog(
@"sysdesc.compile.failed.writeFailure",
@"%@",
@"Could not write translated sysdesc.plist to sysdesc-compiled.plist.");
108 NSArray *sysDescArray =
nil;
109 NSDictionary *sysDescDict =
nil;
110 NSDictionary *keyMap =
nil;
112 NSString *error =
nil;
114 sysDescArray = [[UNIVERSE descriptions] oo_arrayForKey:@"system_description"];
122 if (sysDescArray ==
nil)
124 OOLog(
@"sysdesc.export.failed.conversion",
@"%@",
@"Could not convert system_description do sysdesc.plist format for some reason.");
130 data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
131 format:NSPropertyListXMLFormat_v1_0
132 errorDescription:&error];
136 data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
141 OOLog(
@"sysdesc.export.failed.XML",
@"Could not convert translated system_description to XML property list: %@.", error);
145 if ([
ResourceManager writeDiagnosticData:data toFileNamed:
@"sysdesc.plist"])
147 OOLog(
@"sysdesc.export.success",
@"%@",
@"Wrote translated system_description to sysdesc.plist.");
151 OOLog(
@"sysdesc.export.failed.writeFailure",
@"%@",
@"Could not write translated system_description to sysdesc.plist.");
158 NSMutableDictionary *result =
nil;
159 NSAutoreleasePool *pool =
nil;
161 NSArray *entry =
nil;
162 NSMutableDictionary *keysToIndices =
nil;
163 NSMutableSet *usedIndices =
nil;
164 NSUInteger slotCache = 0;
165 NSNumber *index =
nil;
167 NSMutableArray *realResult =
nil;
169 pool = [[NSAutoreleasePool alloc] init];
172 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInDictionaryFormat count]];
176 foreachkey (key, descriptionsInDictionaryFormat)
178 entry =
ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache);
179 index =
KeyToIndex(key, keysToIndices, usedIndices, &slotCache);
181 [result setObject:entry forKey:index];
185 realResult = [NSMutableArray arrayWithCapacity:count];
186 for (i = 0; i <
count; i++)
188 entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]];
189 if (entry ==
nil) entry = [NSArray array];
190 [realResult addObject:entry];
195 return [realResult autorelease];
201 NSMutableDictionary *result =
nil;
202 NSAutoreleasePool *pool =
nil;
203 NSArray *entry =
nil;
207 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]];
208 pool = [[NSAutoreleasePool alloc] init];
210 foreach (entry, descriptionsInArrayFormat)
216 [result setObject:entry forKey:key];
228 NSString *before =
nil, *after =
nil, *middle =
nil;
231 searchRange.location = 0;
232 searchRange.length = [line length];
234 while ([line rangeOfString:
@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
236 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
237 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
239 before = [line substringWithRange:NSMakeRange(0, p1)];
240 after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
241 middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
243 if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:
@""] && ![middle isEqual:@""])
246 key =
IndexToKey([middle intValue], indicesToKeys, useFallback);
249 line = [NSString stringWithFormat:@"%@[#%@]%@", before, key, after];
253 searchRange.length -= p2 - searchRange.location;
254 searchRange.location = [line length] - searchRange.length;
263 NSNumber *number =
nil;
264 NSMutableDictionary *result =
nil;
265 NSMutableSet *used =
nil;
267 assert(outUsedIndices != NULL);
269 result = [NSMutableDictionary dictionaryWithCapacity:[dict count]];
270 used = [NSMutableSet setWithCapacity:[dict count]];
275 number = [NSNumber numberWithInt:[key intValue]];
276 [result setObject:number forKey:[dict objectForKey:key]];
277 [used addObject:number];
280 *outUsedIndices = used;
285static NSString *
IndexToKey(NSUInteger index, NSDictionary *indicesToKeys, BOOL useFallback)
287 NSString *result = [indicesToKeys objectForKey:[NSString stringWithFormat:@"%llu", index]];
288 if (result ==
nil && useFallback) result = [NSString stringWithFormat:@"block_%llu", index];
296 NSString *line =
nil;
297 NSMutableArray *result =
nil;
299 result = [NSMutableArray arrayWithCapacity:[entry count]];
301 foreach (line, entry)
303 [result addObject:OOStringifySystemDescriptionLine(line, indicesToKeys, YES)];
310static NSNumber *
KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
312 NSNumber *result =
nil;
314 assert(ioSlotCache != NULL);
316 result = [ioKeysToIndices objectForKey:key];
322 result = [NSNumber numberWithUnsignedInteger:(*ioSlotCache)++];
324 while ([ioUsedIndicies containsObject:result]);
326 [ioKeysToIndices setObject:result forKey:key];
327 [ioUsedIndicies addObject:result];
328 OOLog(
@"sysdesc.compile.unknownKey",
@"Assigning key \"%@\
" to index %@.", key, result);
335static NSArray *
ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
337 NSString *line =
nil;
340 NSMutableArray *result =
nil;
341 NSString *before =
nil, *after =
nil, *middle =
nil;
343 result = [NSMutableArray arrayWithCapacity:[entry count]];
345 foreach (line, entry)
347 searchRange.location = 0;
348 searchRange.length = [line length];
350 while ([line rangeOfString:
@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
352 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
353 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
355 before = [line substringWithRange:NSMakeRange(0, p1)];
356 after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
357 middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
359 if ([middle length] > 1 && [middle hasPrefix:
@"#"])
362 line = [NSString stringWithFormat:@"%@[%@]%@", before, KeyToIndex([middle substringFromIndex:1], ioKeysToIndices, ioUsedIndicies, ioSlotCache), after];
365 searchRange.length -= p2 - searchRange.location;
366 searchRange.location = [line length] - searchRange.length;
369 [result addObject:line];
379 NSUInteger curr, highest = 0;
383 curr = [key intValue];
384 if (highest < curr) highest = curr;
#define foreachkey(VAR, DICT)
static NSMutableDictionary * InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices)
static NSArray * ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
static NSUInteger HighestIndex(NSMutableDictionary *sparseArray)
void CompileSystemDescriptions(BOOL asXML)
void ExportSystemDescriptions(BOOL asXML)
static NSNumber * KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
static NSArray * ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys)
NSDictionary * OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys)
NSString * OOStringifySystemDescriptionLine(NSString *line, NSDictionary *indicesToKeys, BOOL useFallback)
NSArray * OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys)
static NSString * IndexToKey(NSUInteger index, NSDictionary *indicesToKeys, BOOL useFallback)
#define OOLog(class, format,...)
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)