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 NSEnumerator *keyEnum =
nil;
163 NSMutableDictionary *keysToIndices =
nil;
164 NSMutableSet *usedIndices =
nil;
165 NSUInteger slotCache = 0;
166 NSNumber *index =
nil;
168 NSMutableArray *realResult =
nil;
170 pool = [[NSAutoreleasePool alloc] init];
173 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInDictionaryFormat count]];
177 for (keyEnum = [descriptionsInDictionaryFormat keyEnumerator]; (key = [keyEnum nextObject]); )
179 entry =
ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache);
180 index =
KeyToIndex(key, keysToIndices, usedIndices, &slotCache);
182 [result setObject:entry forKey:index];
186 realResult = [NSMutableArray arrayWithCapacity:count];
187 for (i = 0; i <
count; i++)
189 entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]];
190 if (entry ==
nil) entry = [NSArray array];
191 [realResult addObject:entry];
196 return [realResult autorelease];
202 NSMutableDictionary *result =
nil;
203 NSAutoreleasePool *pool =
nil;
204 NSArray *entry =
nil;
205 NSEnumerator *entryEnum =
nil;
209 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]];
210 pool = [[NSAutoreleasePool alloc] init];
212 for (entryEnum = [descriptionsInArrayFormat objectEnumerator]; (entry = [entryEnum nextObject]); )
218 [result setObject:entry forKey:key];
230 NSString *before =
nil, *after =
nil, *middle =
nil;
233 searchRange.location = 0;
234 searchRange.length = [line length];
236 while ([line rangeOfString:
@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
238 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
239 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
241 before = [line substringWithRange:NSMakeRange(0, p1)];
242 after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
243 middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
245 if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:
@"0123456789"]] isEqual:
@""] && ![middle isEqual:
@""])
248 key =
IndexToKey([middle intValue], indicesToKeys, useFallback);
251 line = [NSString stringWithFormat:@"%@[#%@]%@", before, key, after];
255 searchRange.length -= p2 - searchRange.location;
256 searchRange.location = [line length] - searchRange.length;
264 NSEnumerator *keyEnum =
nil;
266 NSNumber *number =
nil;
267 NSMutableDictionary *result =
nil;
268 NSMutableSet *used =
nil;
270 assert(outUsedIndices != NULL);
272 result = [NSMutableDictionary dictionaryWithCapacity:[dict count]];
273 used = [NSMutableSet setWithCapacity:[dict count]];
275 for (keyEnum = [dict keyEnumerator]; (key = [keyEnum nextObject]); )
278 number = [NSNumber numberWithInt:[key intValue]];
279 [result setObject:number forKey:[dict objectForKey:key]];
280 [used addObject:number];
283 *outUsedIndices = used;
288static NSString *
IndexToKey(NSUInteger index, NSDictionary *indicesToKeys, BOOL useFallback)
290 NSString *result = [indicesToKeys objectForKey:[NSString stringWithFormat:@"%lu", index]];
291 if (result ==
nil && useFallback) result = [NSString stringWithFormat:@"block_%lu", index];
299 NSEnumerator *lineEnum =
nil;
300 NSString *line =
nil;
301 NSMutableArray *result =
nil;
303 result = [NSMutableArray arrayWithCapacity:[entry count]];
305 for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); )
307 [result addObject:OOStringifySystemDescriptionLine(line, indicesToKeys, YES)];
314static NSNumber *
KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
316 NSNumber *result =
nil;
318 assert(ioSlotCache != NULL);
320 result = [ioKeysToIndices objectForKey:key];
326 result = [NSNumber numberWithUnsignedInteger:(*ioSlotCache)++];
328 while ([ioUsedIndicies containsObject:result]);
330 [ioKeysToIndices setObject:result forKey:key];
331 [ioUsedIndicies addObject:result];
332 OOLog(
@"sysdesc.compile.unknownKey",
@"Assigning key \"%@\
" to index %@.", key, result);
339static NSArray *
ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
341 NSEnumerator *lineEnum =
nil;
342 NSString *line =
nil;
345 NSMutableArray *result =
nil;
346 NSString *before =
nil, *after =
nil, *middle =
nil;
348 result = [NSMutableArray arrayWithCapacity:[entry count]];
350 for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); )
352 searchRange.location = 0;
353 searchRange.length = [line length];
355 while ([line rangeOfString:
@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
357 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
358 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
360 before = [line substringWithRange:NSMakeRange(0, p1)];
361 after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
362 middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
364 if ([middle length] > 1 && [middle hasPrefix:
@"#"])
367 line = [NSString stringWithFormat:@"%@[%@]%@", before, KeyToIndex([middle substringFromIndex:1], ioKeysToIndices, ioUsedIndicies, ioSlotCache), after];
370 searchRange.length -= p2 - searchRange.location;
371 searchRange.location = [line length] - searchRange.length;
374 [result addObject:line];
383 NSEnumerator *keyEnum =
nil;
385 NSUInteger curr, highest = 0;
387 for (keyEnum = [sparseArray keyEnumerator]; (key = [keyEnum nextObject]); )
389 curr = [key intValue];
390 if (highest < curr) highest = curr;
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)