Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
Functions
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 47 of file OOConvertSystemDescriptions.m.

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

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

+ Here is the call graph for this function:

◆ ExportSystemDescriptions()

void ExportSystemDescriptions ( BOOL asXML)

Definition at line 106 of file OOConvertSystemDescriptions.m.

107{
108 NSArray *sysDescArray = nil;
109 NSDictionary *sysDescDict = nil;
110 NSDictionary *keyMap = nil;
111 NSData *data = nil;
112 NSString *error = nil;
113
114 sysDescArray = [[UNIVERSE descriptions] oo_arrayForKey:@"system_description"];
115
116 keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
117 inFolder:@"Config"
118 andMerge:NO];
119 // keyMap is optional, so no nil check
120
121 sysDescDict = OOConvertSystemDescriptionsToDictionaryFormat(sysDescArray, keyMap);
122 if (sysDescArray == nil)
123 {
124 OOLog(@"sysdesc.export.failed.conversion", @"%@", @"Could not convert system_description do sysdesc.plist format for some reason.");
125 return;
126 }
127
128 if (asXML)
129 {
130 data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
131 format:NSPropertyListXMLFormat_v1_0
132 errorDescription:&error];
133 }
134 else
135 {
136 data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
137 }
138
139 if (data == nil)
140 {
141 OOLog(@"sysdesc.export.failed.XML", @"Could not convert translated system_description to XML property list: %@.", error);
142 return;
143 }
144
145 if ([ResourceManager writeDiagnosticData:data toFileNamed:@"sysdesc.plist"])
146 {
147 OOLog(@"sysdesc.export.success", @"%@", @"Wrote translated system_description to sysdesc.plist.");
148 }
149 else
150 {
151 OOLog(@"sysdesc.export.failed.writeFailure", @"%@", @"Could not write translated system_description to sysdesc.plist.");
152 }
153}
NSDictionary * OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys)
#define UNIVERSE
Definition Universe.h:833

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

+ Here is the call graph for this function:

◆ OOConvertSystemDescriptionsToArrayFormat()

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

Definition at line 156 of file OOConvertSystemDescriptions.m.

157{
158 NSMutableDictionary *result = nil;
159 NSAutoreleasePool *pool = nil;
160 NSString *key = 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;
167 NSUInteger i, count;
168 NSMutableArray *realResult = nil;
169
170 pool = [[NSAutoreleasePool alloc] init];
171
172 // Use a dictionary as a sparse array.
173 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInDictionaryFormat count]];
174
175 keysToIndices = InitKeyToIndexDict(indicesToKeys, &usedIndices);
176
177 for (keyEnum = [descriptionsInDictionaryFormat keyEnumerator]; (key = [keyEnum nextObject]); )
178 {
179 entry = ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache);
180 index = KeyToIndex(key, keysToIndices, usedIndices, &slotCache);
181
182 [result setObject:entry forKey:index];
183 }
184
185 count = HighestIndex(result);
186 realResult = [NSMutableArray arrayWithCapacity:count];
187 for (i = 0; i < count; i++)
188 {
189 entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]];
190 if (entry == nil) entry = [NSArray array];
191 [realResult addObject:entry];
192 }
193
194 [realResult retain];
195 [pool release];
196 return [realResult autorelease];
197}
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)
unsigned count

References ConvertKeysToIndices(), count, 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 200 of file OOConvertSystemDescriptions.m.

201{
202 NSMutableDictionary *result = nil;
203 NSAutoreleasePool *pool = nil;
204 NSArray *entry = nil;
205 NSEnumerator *entryEnum = nil;
206 NSString *key = nil;
207 NSUInteger i = 0;
208
209 result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]];
210 pool = [[NSAutoreleasePool alloc] init];
211
212 for (entryEnum = [descriptionsInArrayFormat objectEnumerator]; (entry = [entryEnum nextObject]); )
213 {
214 entry = ConvertIndicesToKeys(entry, indicesToKeys);
215 key = IndexToKey(i, indicesToKeys, YES);
216 ++i;
217
218 [result setObject:entry forKey:key];
219 }
220
221 [pool release];
222 return result;
223}
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 226 of file OOConvertSystemDescriptions.m.

227{
228 NSUInteger p1, p2;
229 NSRange searchRange;
230 NSString *before = nil, *after = nil, *middle = nil;
231 NSString *key = nil;
232
233 searchRange.location = 0;
234 searchRange.length = [line length];
235
236 while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
237 {
238 p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
239 p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
240
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)];
244
245 if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""] && ![middle isEqual:@""])
246 {
247 // Found [] around integers only
248 key = IndexToKey([middle intValue], indicesToKeys, useFallback);
249 if (key != nil)
250 {
251 line = [NSString stringWithFormat:@"%@[#%@]%@", before, key, after];
252 }
253 }
254
255 searchRange.length -= p2 - searchRange.location;
256 searchRange.location = [line length] - searchRange.length;
257 }
258 return line;
259}

References IndexToKey(), and nil.

+ Here is the call graph for this function: