Oolite
Loading...
Searching...
No Matches
OOConvertSystemDescriptions.h File Reference
import <Foundation/Foundation.h>
Include dependency graph for OOConvertSystemDescriptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NSArray * OOConvertSystemDescriptionsToArrayFormat (NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys)
NSDictionary * OOConvertSystemDescriptionsToDictionaryFormat (NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys)
NSString * OOStringifySystemDescriptionLine (NSString *line, NSDictionary *indicesToKeys, BOOL useFallback)
void CompileSystemDescriptions (BOOL asXML)
void ExportSystemDescriptions (BOOL asXML)

Function Documentation

◆ CompileSystemDescriptions()

void CompileSystemDescriptions ( BOOL asXML)

Definition at line 45 of file OOConvertSystemDescriptions.m.

46{
47 NSDictionary* sysDescDict = nil;
48 NSArray* sysDescArray = nil;
49 NSDictionary* keyMap = nil;
50 NSData* data = nil;
51 NSString* error = nil;
52
53 sysDescDict = [ResourceManager dictionaryFromFilesNamed:@"sysdesc.plist"
54 inFolder:@"Config"
55 andMerge:NO];
56 if (sysDescDict == nil) {
57 OOLog(@"sysdesc.compile.failed.fileNotFound", @"%@", @"Could not load a dictionary from sysdesc.plist, ignoring --compile-sysdesc option.");
58 return;
59 }
60
61 keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
62 inFolder:@"Config"
63 andMerge:NO];
64 // keyMap is optional, so no nil check
65
66 sysDescArray = OOConvertSystemDescriptionsToArrayFormat(sysDescDict, keyMap);
67 if (sysDescArray == nil) {
68 OOLog(@"sysdesc.compile.failed.conversion", @"%@", @"Could not convert sysdesc.plist to descriptions.plist format for some reason.");
69 return;
70 }
71
72 sysDescDict = [NSDictionary dictionaryWithObject:sysDescArray forKey:@"system_description"];
73
74 if (asXML) {
75 data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
76 format:NSPropertyListXMLFormat_v1_0
77 errorDescription:&error];
78 } else {
79 data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
80 }
81
82 if (data == nil) {
83 OOLog(@"sysdesc.compile.failed.XML", @"Could not convert translated sysdesc.plist to property list: %@.", error);
84 return;
85 }
86
87 if ([ResourceManager writeDiagnosticData:data toFileNamed:@"sysdesc-compiled.plist"]) {
88 OOLog(@"sysdesc.compile.success", @"%@", @"Wrote translated sysdesc.plist to sysdesc-compiled.plist.");
89 } else {
90 OOLog(@"sysdesc.compile.failed.writeFailure", @"%@", @"Could not write translated sysdesc.plist to sysdesc-compiled.plist.");
91 }
92}
NSArray * OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys)
#define OOLog(class, format,...)
Definition OOLogging.h:84
return nil

References ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, nil, OOConvertSystemDescriptionsToArrayFormat(), and OOLog.

Referenced by Universe(OOPrivate)::runLocalizationTools.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExportSystemDescriptions()

void ExportSystemDescriptions ( BOOL asXML)

Definition at line 94 of file OOConvertSystemDescriptions.m.

95{
96 NSArray* sysDescArray = nil;
97 NSDictionary* sysDescDict = nil;
98 NSDictionary* keyMap = nil;
99 NSData* data = nil;
100 NSString* error = nil;
101
102 sysDescArray = [[UNIVERSE descriptions] oo_arrayForKey:@"system_description"];
103
104 keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
105 inFolder:@"Config"
106 andMerge:NO];
107 // keyMap is optional, so no nil check
108
109 sysDescDict = OOConvertSystemDescriptionsToDictionaryFormat(sysDescArray, keyMap);
110 if (sysDescArray == nil) {
111 OOLog(@"sysdesc.export.failed.conversion", @"%@", @"Could not convert system_description do sysdesc.plist format for some reason.");
112 return;
113 }
114
115 if (asXML) {
116 data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
117 format:NSPropertyListXMLFormat_v1_0
118 errorDescription:&error];
119 } else {
120 data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
121 }
122
123 if (data == nil) {
124 OOLog(@"sysdesc.export.failed.XML", @"Could not convert translated system_description to XML property list: %@.", error);
125 return;
126 }
127
128 if ([ResourceManager writeDiagnosticData:data toFileNamed:@"sysdesc.plist"]) {
129 OOLog(@"sysdesc.export.success", @"%@", @"Wrote translated system_description to sysdesc.plist.");
130 } else {
131 OOLog(@"sysdesc.export.failed.writeFailure", @"%@", @"Could not write translated system_description to sysdesc.plist.");
132 }
133}
NSDictionary * OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys)
#define UNIVERSE
Definition Universe.h:827

References ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, nil, OOConvertSystemDescriptionsToDictionaryFormat(), and OOLog.

Referenced by Universe(OOPrivate)::runLocalizationTools.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOConvertSystemDescriptionsToArrayFormat()

NSArray * OOConvertSystemDescriptionsToArrayFormat ( NSDictionary * descriptionsInDictionaryFormat,
NSDictionary * indicesToKeys )

Definition at line 135 of file OOConvertSystemDescriptions.m.

136{
137 NSMutableDictionary* result = nil;
138 NSAutoreleasePool* pool = nil;
139 NSString* key = nil;
140 NSArray* entry = nil;
141 NSMutableDictionary* keysToIndices = nil;
142 NSMutableSet* usedIndices = nil;
143 NSUInteger slotCache = 0;
144 NSNumber* index = nil;
145 NSUInteger i, count;
146 NSMutableArray* realResult = nil;
147
148 pool = [[NSAutoreleasePool alloc] init];
149
150 // Use a dictionary as a sparse array.
151 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInDictionaryFormat count]];
152
153 keysToIndices = InitKeyToIndexDict(indicesToKeys, &usedIndices);
154
155 foreachkey(key, descriptionsInDictionaryFormat)
156 {
157 entry = ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache);
158 index = KeyToIndex(key, keysToIndices, usedIndices, &slotCache);
159
160 [result setObject:entry forKey:index];
161 }
162
163 count = HighestIndex(result);
164 realResult = [NSMutableArray arrayWithCapacity:count];
165 for (i = 0; i < count; i++) {
166 entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]];
167 if (entry == nil)
168 entry = [NSArray array];
169 [realResult addObject:entry];
170 }
171
172 [realResult retain];
173 [pool release];
174 return [realResult autorelease];
175}
static NSMutableDictionary * InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices)
static NSArray * ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
static NSUInteger HighestIndex(NSMutableDictionary *sparseArray)
static NSNumber * KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache)
#define foreachkey(VAR, DICT)
unsigned count

References ConvertKeysToIndices(), count, foreachkey, HighestIndex(), InitKeyToIndexDict(), KeyToIndex(), and nil.

Referenced by CompileSystemDescriptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOConvertSystemDescriptionsToDictionaryFormat()

NSDictionary * OOConvertSystemDescriptionsToDictionaryFormat ( NSArray * descriptionsInArrayFormat,
NSDictionary * indicesToKeys )

Definition at line 177 of file OOConvertSystemDescriptions.m.

178{
179 NSMutableDictionary* result = nil;
180 NSAutoreleasePool* pool = nil;
181 NSArray* entry = nil;
182 NSString* key = nil;
183 NSUInteger i = 0;
184
185 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]];
186 pool = [[NSAutoreleasePool alloc] init];
187
188 foreach (entry, descriptionsInArrayFormat) {
189 entry = ConvertIndicesToKeys(entry, indicesToKeys);
190 key = IndexToKey(i, indicesToKeys, YES);
191 ++i;
192
193 [result setObject:entry forKey:key];
194 }
195
196 [pool release];
197 return result;
198}
static NSArray * ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys)
static NSString * IndexToKey(NSUInteger index, NSDictionary *indicesToKeys, BOOL useFallback)

References ConvertIndicesToKeys(), IndexToKey(), and nil.

Referenced by ExportSystemDescriptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOStringifySystemDescriptionLine()

NSString * OOStringifySystemDescriptionLine ( NSString * line,
NSDictionary * indicesToKeys,
BOOL useFallback )

Definition at line 200 of file OOConvertSystemDescriptions.m.

201{
202 NSUInteger p1, p2;
203 NSRange searchRange;
204 NSString *before = nil, *after = nil, *middle = nil;
205 NSString* key = nil;
206
207 searchRange.location = 0;
208 searchRange.length = [line length];
209
210 while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound) {
211 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
212 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
213
214 before = [line substringWithRange:NSMakeRange(0, p1)];
215 after = [line substringWithRange:NSMakeRange(p2, [line length] - p2)];
216 middle = [line substringWithRange:NSMakeRange(p1 + 1, p2 - p1 - 2)];
217
218 if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""] && ![middle isEqual:@""]) {
219 // Found [] around integers only
220 key = IndexToKey([middle intValue], indicesToKeys, useFallback);
221 if (key != nil) {
222 line = [NSString stringWithFormat:@"%@[#%@]%@", before, key, after];
223 }
224 }
225
226 searchRange.length -= p2 - searchRange.location;
227 searchRange.location = [line length] - searchRange.length;
228 }
229 return line;
230}

References IndexToKey(), and nil.

Here is the call graph for this function: