Implemented --export-sysdesc and --compile-sysdesc command-line options for translators. Improved robustness of system_description parsing and allow entries with other than five elements.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1908 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
cda597ce89
commit
a00a7f495c
@ -34,7 +34,7 @@ endif
|
||||
OBJC_PROGRAM_NAME = oolite
|
||||
|
||||
oolite_C_FILES = legacy_random.c strlcpy.c OOTCPStreamDecoder.c
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OONullTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m OOFilteringEnumerator.m OOSoundSourcePool.m ShipEntityScriptMethods.m OOShipRegistry.m OOProbabilitySet.m OOJSSystemInfo.m NSDictionaryOOExtensions.m OOEquipmentType.m OOCamera.m OOJSPlayerShip.m OOSDLSound.m OOSDLConcreteSound.m OOSoundSource.m OOSDLSoundMixer.m OOSDLSoundChannel.m OOBasicSoundReferencePoint.m SDLMusic.m OOLogOutputHandler.m OOJSEquipmentInfo.m OOIsNumberLiteral.m
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OONullTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m OOFilteringEnumerator.m OOSoundSourcePool.m ShipEntityScriptMethods.m OOShipRegistry.m OOProbabilitySet.m OOJSSystemInfo.m NSDictionaryOOExtensions.m OOEquipmentType.m OOCamera.m OOJSPlayerShip.m OOSDLSound.m OOSDLConcreteSound.m OOSoundSource.m OOSDLSoundMixer.m OOSDLSoundChannel.m OOBasicSoundReferencePoint.m SDLMusic.m OOLogOutputHandler.m OOJSEquipmentInfo.m OOIsNumberLiteral.m OOConvertSystemDescriptions.m OldSchoolPropertyListWriting.m
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/objc.make
|
||||
include GNUmakefile.postamble
|
||||
|
@ -40,6 +40,10 @@
|
||||
1A047A460DCA0F4F00EE1CD0 /* NSDictionaryOOExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A047A440DCA0F4F00EE1CD0 /* NSDictionaryOOExtensions.m */; };
|
||||
1A047B7E0DCB3D7500EE1CD0 /* OOProbabilitySet.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A047B7C0DCB3D7500EE1CD0 /* OOProbabilitySet.h */; };
|
||||
1A047B7F0DCB3D7500EE1CD0 /* OOProbabilitySet.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A047B7D0DCB3D7500EE1CD0 /* OOProbabilitySet.m */; };
|
||||
1A0729D90EF56D1200B0F925 /* OOConvertSystemDescriptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A0729D70EF56D1200B0F925 /* OOConvertSystemDescriptions.h */; };
|
||||
1A0729DA0EF56D1200B0F925 /* OOConvertSystemDescriptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0729D80EF56D1200B0F925 /* OOConvertSystemDescriptions.m */; };
|
||||
1A0729FE0EF5796500B0F925 /* OldSchoolPropertyListWriting.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A0729FC0EF5796500B0F925 /* OldSchoolPropertyListWriting.h */; };
|
||||
1A0729FF0EF5796500B0F925 /* OldSchoolPropertyListWriting.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0729FD0EF5796500B0F925 /* OldSchoolPropertyListWriting.m */; };
|
||||
1A0DA2EE0D71D280009B0970 /* OOJSSpecialFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A0DA2EC0D71D280009B0970 /* OOJSSpecialFunctions.h */; };
|
||||
1A0DA2EF0D71D280009B0970 /* OOJSSpecialFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0DA2ED0D71D280009B0970 /* OOJSSpecialFunctions.m */; };
|
||||
1A1502F60C1201C30032F3E8 /* oolite-unknown-ship.dat in Copy Models */ = {isa = PBXBuildFile; fileRef = 1A1502F50C1201C30032F3E8 /* oolite-unknown-ship.dat */; };
|
||||
@ -1053,6 +1057,10 @@
|
||||
1A047B7D0DCB3D7500EE1CD0 /* OOProbabilitySet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOProbabilitySet.m; sourceTree = "<group>"; };
|
||||
1A0517D10C7B376700BA5CCA /* debug-exports.exp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.exports; path = "debug-exports.exp"; sourceTree = "<group>"; };
|
||||
1A0519340C7CCAC900BA5CCA /* DebugOXP.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = DebugOXP.xcodeproj; path = "Mac-DebugOXP/DebugOXP.xcodeproj"; sourceTree = SOURCE_ROOT; };
|
||||
1A0729D70EF56D1200B0F925 /* OOConvertSystemDescriptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOConvertSystemDescriptions.h; sourceTree = "<group>"; };
|
||||
1A0729D80EF56D1200B0F925 /* OOConvertSystemDescriptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOConvertSystemDescriptions.m; sourceTree = "<group>"; };
|
||||
1A0729FC0EF5796500B0F925 /* OldSchoolPropertyListWriting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OldSchoolPropertyListWriting.h; sourceTree = "<group>"; };
|
||||
1A0729FD0EF5796500B0F925 /* OldSchoolPropertyListWriting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OldSchoolPropertyListWriting.m; sourceTree = "<group>"; };
|
||||
1A0DA2EC0D71D280009B0970 /* OOJSSpecialFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOJSSpecialFunctions.h; sourceTree = "<group>"; };
|
||||
1A0DA2ED0D71D280009B0970 /* OOJSSpecialFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOJSSpecialFunctions.m; sourceTree = "<group>"; };
|
||||
1A1502F50C1201C30032F3E8 /* oolite-unknown-ship.dat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "oolite-unknown-ship.dat"; sourceTree = "<group>"; };
|
||||
@ -2534,6 +2542,10 @@
|
||||
1A29967D0B9F064C002D2149 /* OOCache.m */,
|
||||
1A9404640BAF42BE005F6CF3 /* OOPListParsing.h */,
|
||||
1A9404650BAF42BF005F6CF3 /* OOPListParsing.m */,
|
||||
1A0729FC0EF5796500B0F925 /* OldSchoolPropertyListWriting.h */,
|
||||
1A0729FD0EF5796500B0F925 /* OldSchoolPropertyListWriting.m */,
|
||||
1A0729D70EF56D1200B0F925 /* OOConvertSystemDescriptions.h */,
|
||||
1A0729D80EF56D1200B0F925 /* OOConvertSystemDescriptions.m */,
|
||||
);
|
||||
name = "Resource Management";
|
||||
sourceTree = "<group>";
|
||||
@ -2934,6 +2946,8 @@
|
||||
1AC27A0F0EA7E9940054E5F0 /* OOJSEquipmentInfo.h in Headers */,
|
||||
1ABDBA3C0EB365D90086BC3D /* OOIsNumberLiteral.h in Headers */,
|
||||
1A1E99B60EF04837008B48E2 /* OOProgressBar.h in Headers */,
|
||||
1A0729D90EF56D1200B0F925 /* OOConvertSystemDescriptions.h in Headers */,
|
||||
1A0729FE0EF5796500B0F925 /* OldSchoolPropertyListWriting.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -3290,6 +3304,8 @@
|
||||
1AC27A100EA7E9940054E5F0 /* OOJSEquipmentInfo.m in Sources */,
|
||||
1ABDBA3B0EB365D90086BC3D /* OOIsNumberLiteral.m in Sources */,
|
||||
1A1E99B70EF04837008B48E2 /* OOProgressBar.m in Sources */,
|
||||
1A0729DA0EF56D1200B0F925 /* OOConvertSystemDescriptions.m in Sources */,
|
||||
1A0729FF0EF5796500B0F925 /* OldSchoolPropertyListWriting.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1452,7 +1452,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
return;
|
||||
}
|
||||
|
||||
roleString = (NSString *)[tokens objectAtIndex:0];
|
||||
roleString = [tokens objectAtIndex:0];
|
||||
[tokens removeObjectAtIndex:0];
|
||||
messageString = [tokens componentsJoinedByString:@" "];
|
||||
|
||||
@ -1587,12 +1587,12 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
return;
|
||||
}
|
||||
|
||||
roleString = (NSString *)[tokens objectAtIndex:0];
|
||||
numberString = (NSString *)[tokens objectAtIndex:1];
|
||||
systemString = (NSString *)[tokens objectAtIndex:2];
|
||||
xString = (NSString *)[tokens objectAtIndex:3];
|
||||
yString = (NSString *)[tokens objectAtIndex:4];
|
||||
zString = (NSString *)[tokens objectAtIndex:5];
|
||||
roleString = [tokens objectAtIndex:0];
|
||||
numberString = [tokens objectAtIndex:1];
|
||||
systemString = [tokens objectAtIndex:2];
|
||||
xString = [tokens objectAtIndex:3];
|
||||
yString = [tokens objectAtIndex:4];
|
||||
zString = [tokens objectAtIndex:5];
|
||||
|
||||
Vector posn = make_vector( [xString floatValue], [yString floatValue], [zString floatValue]);
|
||||
|
||||
@ -1622,9 +1622,9 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
return;
|
||||
}
|
||||
|
||||
NSString* roleString = (NSString *)[tokens objectAtIndex:0];
|
||||
NSString* roleString = [tokens objectAtIndex:0];
|
||||
int number = [[tokens objectAtIndex:1] intValue];
|
||||
NSString* systemString = (NSString *)[tokens objectAtIndex:2];
|
||||
NSString* systemString = [tokens objectAtIndex:2];
|
||||
GLfloat x = [[tokens objectAtIndex:3] floatValue];
|
||||
GLfloat y = [[tokens objectAtIndex:4] floatValue];
|
||||
GLfloat z = [[tokens objectAtIndex:5] floatValue];
|
||||
@ -1829,7 +1829,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
return;
|
||||
}
|
||||
|
||||
missionVariableString = (NSString *)[tokens objectAtIndex:0];
|
||||
missionVariableString = [tokens objectAtIndex:0];
|
||||
[tokens removeObjectAtIndex:0];
|
||||
valueString = [tokens componentsJoinedByString:@" "];
|
||||
|
||||
@ -2007,7 +2007,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
|
||||
for (j = 0; j < [tokens count]; j++)
|
||||
{
|
||||
dest = [(NSString *)[tokens objectAtIndex:j] intValue];
|
||||
dest = [[tokens objectAtIndex:j] intValue];
|
||||
if (dest < 0 || dest > 255) continue;
|
||||
|
||||
removeDestination = NO;
|
||||
|
23
src/Core/OOConvertSystemDescriptions.h
Normal file
23
src/Core/OOConvertSystemDescriptions.h
Normal file
@ -0,0 +1,23 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
/* Functions to convert system descriptions between dictionary and array
|
||||
formats.
|
||||
|
||||
The array format is used in descriptions.plist. Each set of strings is an
|
||||
array, the sets are stored in a master array, and cross-references are
|
||||
indices into the master array.
|
||||
|
||||
The dictionary format is more human-friendly, with string sets identified
|
||||
by name and cross-references using names.
|
||||
|
||||
The indicesToKeys parameter is optional; if it is nil or incomplete,
|
||||
indices or (index-based) keys will be synthesized.
|
||||
*/
|
||||
NSArray *OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys);
|
||||
NSDictionary *OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys);
|
||||
|
||||
|
||||
// Higher-level functions to drive the entire conversion.
|
||||
void CompileSystemDescriptions(BOOL asXML);
|
||||
void ExportSystemDescriptions(BOOL asXML);
|
361
src/Core/OOConvertSystemDescriptions.m
Normal file
361
src/Core/OOConvertSystemDescriptions.m
Normal file
@ -0,0 +1,361 @@
|
||||
//
|
||||
// OOConvertSystemDescriptions.m
|
||||
// systemdescriptiontest
|
||||
//
|
||||
// Created by Jens Ayton on 2008-12-14.
|
||||
// Copyright 2008 Jens Ayton. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OOCocoa.h"
|
||||
#import "OOConvertSystemDescriptions.h"
|
||||
#import "OldSchoolPropertyListWriting.h"
|
||||
#import "OOCollectionExtractors.h"
|
||||
#import "ResourceManager.h"
|
||||
#import "Universe.h"
|
||||
|
||||
|
||||
static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices);
|
||||
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys);
|
||||
static NSArray *ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys);
|
||||
static NSNumber *KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache);
|
||||
static NSArray *ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache);
|
||||
static OOUInteger HighestIndex(NSMutableDictionary *sparseArray); // Actually returns highest index + 1, which is fine.
|
||||
|
||||
|
||||
void CompileSystemDescriptions(BOOL asXML)
|
||||
{
|
||||
NSDictionary *sysDescDict = nil;
|
||||
NSArray *sysDescArray = nil;
|
||||
NSDictionary *keyMap = nil;
|
||||
NSData *data = nil;
|
||||
NSString *error = nil;
|
||||
|
||||
sysDescDict = [ResourceManager dictionaryFromFilesNamed:@"sysdesc.plist"
|
||||
inFolder:@"Config"
|
||||
andMerge:NO];
|
||||
if (sysDescDict == nil)
|
||||
{
|
||||
OOLog(@"sysdesc.compile.failed.fileNotFound", @"Could not load a dictionary from sysdesc.plist, ignoring --compile-sysdesc option.");
|
||||
return;
|
||||
}
|
||||
|
||||
keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
|
||||
inFolder:@"Config"
|
||||
andMerge:NO];
|
||||
// keyMap is optional, so no nil check
|
||||
|
||||
sysDescArray = OOConvertSystemDescriptionsToArrayFormat(sysDescDict, keyMap);
|
||||
if (sysDescArray == nil)
|
||||
{
|
||||
OOLog(@"sysdesc.compile.failed.conversion", @"Could not convert sysdesc.plist do descriptions.plist format for some reason.");
|
||||
return;
|
||||
}
|
||||
|
||||
sysDescDict = [NSDictionary dictionaryWithObject:sysDescArray forKey:@"system_description"];
|
||||
|
||||
if (asXML)
|
||||
{
|
||||
data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
|
||||
format:NSPropertyListXMLFormat_v1_0
|
||||
errorDescription:&error];
|
||||
}
|
||||
else
|
||||
{
|
||||
data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
|
||||
}
|
||||
|
||||
if (data == nil)
|
||||
{
|
||||
OOLog(@"sysdesc.compile.failed.XML", @"Could not convert translated sysdesc.plist to property list: %@.", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if ([ResourceManager writeDiagnosticData:data toFileNamed:@"sysdesc-compiled.plist"])
|
||||
{
|
||||
OOLog(@"sysdesc.compile.success", @"Wrote translated sysdesc.plist to sysdesc-compiled.plist.");
|
||||
}
|
||||
else
|
||||
{
|
||||
OOLog(@"sysdesc.compile.failed.writeFailure", @"Could not write translated sysdesc.plist to sysdesc-compiled.plist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExportSystemDescriptions(BOOL asXML)
|
||||
{
|
||||
NSArray *sysDescArray = nil;
|
||||
NSDictionary *sysDescDict = nil;
|
||||
NSDictionary *keyMap = nil;
|
||||
NSData *data = nil;
|
||||
NSString *error = nil;
|
||||
|
||||
sysDescArray = [[UNIVERSE descriptions] arrayForKey:@"system_description"];
|
||||
|
||||
keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
|
||||
inFolder:@"Config"
|
||||
andMerge:NO];
|
||||
// keyMap is optional, so no nil check
|
||||
|
||||
sysDescDict = OOConvertSystemDescriptionsToDictionaryFormat(sysDescArray, keyMap);
|
||||
if (sysDescArray == nil)
|
||||
{
|
||||
OOLog(@"sysdesc.export.failed.conversion", @"Could not convert system_description do sysdesc.plist format for some reason.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asXML)
|
||||
{
|
||||
data = [NSPropertyListSerialization dataFromPropertyList:sysDescDict
|
||||
format:NSPropertyListXMLFormat_v1_0
|
||||
errorDescription:&error];
|
||||
}
|
||||
else
|
||||
{
|
||||
data = [sysDescDict oldSchoolPListFormatWithErrorDescription:&error];
|
||||
}
|
||||
|
||||
if (data == nil)
|
||||
{
|
||||
OOLog(@"sysdesc.export.failed.XML", @"Could not convert translated system_description to XML property list: %@.", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if ([ResourceManager writeDiagnosticData:data toFileNamed:@"sysdesc.plist"])
|
||||
{
|
||||
OOLog(@"sysdesc.export.success", @"Wrote translated system_description to sysdesc.plist.");
|
||||
}
|
||||
else
|
||||
{
|
||||
OOLog(@"sysdesc.export.failed.writeFailure", @"Could not write translated system_description to sysdesc.plist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NSArray *OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys)
|
||||
{
|
||||
NSMutableDictionary *result = nil;
|
||||
NSAutoreleasePool *pool = nil;
|
||||
NSString *key = nil;
|
||||
NSArray *entry = nil;
|
||||
NSEnumerator *keyEnum = nil;
|
||||
NSMutableDictionary *keysToIndices = nil;
|
||||
NSMutableSet *usedIndices = nil;
|
||||
OOUInteger slotCache = 0;
|
||||
NSNumber *index = nil;
|
||||
OOUInteger i, count;
|
||||
NSMutableArray *realResult = nil;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Use a dictionary as a sparse array.
|
||||
result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInDictionaryFormat count]];
|
||||
|
||||
keysToIndices = InitKeyToIndexDict(indicesToKeys, &usedIndices);
|
||||
|
||||
for (keyEnum = [descriptionsInDictionaryFormat keyEnumerator]; (key = [keyEnum nextObject]); )
|
||||
{
|
||||
entry = ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache);
|
||||
index = KeyToIndex(key, keysToIndices, usedIndices, &slotCache);
|
||||
|
||||
[result setObject:entry forKey:index];
|
||||
}
|
||||
|
||||
count = HighestIndex(result);
|
||||
realResult = [NSMutableArray arrayWithCapacity:count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
entry = [result objectForKey:[NSNumber numberWithUnsignedInt:i]];
|
||||
if (entry == nil) entry = [NSArray array];
|
||||
[realResult addObject:entry];
|
||||
}
|
||||
|
||||
[realResult retain];
|
||||
[pool release];
|
||||
return [realResult autorelease];
|
||||
}
|
||||
|
||||
|
||||
NSDictionary *OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys)
|
||||
{
|
||||
NSMutableDictionary *result = nil;
|
||||
NSAutoreleasePool *pool = nil;
|
||||
NSArray *entry = nil;
|
||||
NSEnumerator *entryEnum = nil;
|
||||
NSString *key = nil;
|
||||
OOUInteger i = 0;
|
||||
|
||||
result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
for (entryEnum = [descriptionsInArrayFormat objectEnumerator]; (entry = [entryEnum nextObject]); )
|
||||
{
|
||||
entry = ConvertIndicesToKeys(entry, indicesToKeys);
|
||||
key = IndexToKey(i, indicesToKeys);
|
||||
++i;
|
||||
|
||||
[result setObject:entry forKey:key];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices)
|
||||
{
|
||||
NSEnumerator *keyEnum = nil;
|
||||
NSString *key = nil;
|
||||
NSNumber *number = nil;
|
||||
NSMutableDictionary *result = nil;
|
||||
NSMutableSet *used = nil;
|
||||
|
||||
assert(outUsedIndices != NULL);
|
||||
|
||||
result = [NSMutableDictionary dictionaryWithCapacity:[dict count]];
|
||||
used = [NSMutableSet setWithCapacity:[dict count]];
|
||||
|
||||
for (keyEnum = [dict keyEnumerator]; (key = [keyEnum nextObject]); )
|
||||
{
|
||||
// Convert keys of dict to array indices
|
||||
number = [NSNumber numberWithInt:[key intValue]];
|
||||
[result setObject:number forKey:[dict objectForKey:key]];
|
||||
[used addObject:number];
|
||||
}
|
||||
|
||||
*outUsedIndices = used;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys)
|
||||
{
|
||||
NSString *result = [indicesToKeys objectForKey:[NSString stringWithFormat:@"%u", index]];
|
||||
if (result == nil) result = [NSString stringWithFormat:@"block_%u", index];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static NSArray *ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys)
|
||||
{
|
||||
NSEnumerator *lineEnum = nil;
|
||||
NSString *line = nil;
|
||||
OOUInteger p1, p2;
|
||||
NSRange searchRange;
|
||||
NSMutableArray *result = nil;
|
||||
NSString *before = nil, *after = nil, *middle = nil;
|
||||
|
||||
result = [NSMutableArray arrayWithCapacity:[entry count]];
|
||||
|
||||
for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); )
|
||||
{
|
||||
searchRange.location = 0;
|
||||
searchRange.length = [line length];
|
||||
|
||||
while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
|
||||
{
|
||||
p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
|
||||
p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
|
||||
|
||||
before = [line substringWithRange:NSMakeRange(0, p1)];
|
||||
after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
|
||||
middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
|
||||
|
||||
if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""] && ![middle isEqual:@""])
|
||||
{
|
||||
// Found [] around integers only
|
||||
line = [NSString stringWithFormat:@"%@[#%@]%@", before, IndexToKey([middle intValue], indicesToKeys), after];
|
||||
}
|
||||
|
||||
searchRange.length -= p2 - searchRange.location;
|
||||
searchRange.location = [line length] - searchRange.length;
|
||||
}
|
||||
|
||||
[result addObject:line];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static NSNumber *KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache)
|
||||
{
|
||||
NSNumber *result = nil;
|
||||
|
||||
assert(ioSlotCache != NULL);
|
||||
|
||||
result = [ioKeysToIndices objectForKey:key];
|
||||
if (result == nil)
|
||||
{
|
||||
// Search for free index
|
||||
do
|
||||
{
|
||||
result = [NSNumber numberWithUnsignedInt:(*ioSlotCache)++];
|
||||
}
|
||||
while ([ioUsedIndicies containsObject:result]);
|
||||
|
||||
[ioKeysToIndices setObject:result forKey:key];
|
||||
[ioUsedIndicies addObject:result];
|
||||
OOLog(@"sysdesc.compile.unknownKey", @"Assigning key \"%@\" to index %@.", key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static NSArray *ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache)
|
||||
{
|
||||
NSEnumerator *lineEnum = nil;
|
||||
NSString *line = nil;
|
||||
OOUInteger p1, p2;
|
||||
NSRange searchRange;
|
||||
NSMutableArray *result = nil;
|
||||
NSString *before = nil, *after = nil, *middle = nil;
|
||||
|
||||
result = [NSMutableArray arrayWithCapacity:[entry count]];
|
||||
|
||||
for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); )
|
||||
{
|
||||
searchRange.location = 0;
|
||||
searchRange.length = [line length];
|
||||
|
||||
while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
|
||||
{
|
||||
p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
|
||||
p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
|
||||
|
||||
before = [line substringWithRange:NSMakeRange(0, p1)];
|
||||
after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
|
||||
middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
|
||||
|
||||
if ([middle length] > 1 && [middle hasPrefix:@"#"])
|
||||
{
|
||||
// Found [] around key
|
||||
line = [NSString stringWithFormat:@"%@[%@]%@", before, KeyToIndex([middle substringFromIndex:1], ioKeysToIndices, ioUsedIndicies, ioSlotCache), after];
|
||||
}
|
||||
|
||||
searchRange.length -= p2 - searchRange.location;
|
||||
searchRange.location = [line length] - searchRange.length;
|
||||
}
|
||||
|
||||
[result addObject:line];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static OOUInteger HighestIndex(NSMutableDictionary *sparseArray)
|
||||
{
|
||||
NSEnumerator *keyEnum = nil;
|
||||
NSNumber *key = nil;
|
||||
OOUInteger curr, highest = 0;
|
||||
|
||||
for (keyEnum = [sparseArray keyEnumerator]; (key = [keyEnum nextObject]); )
|
||||
{
|
||||
curr = [key intValue];
|
||||
if (highest < curr) highest = curr;
|
||||
}
|
||||
|
||||
return highest;
|
||||
}
|
@ -290,8 +290,11 @@ NSString *ExpandDescriptionsWithLocalsForSystemSeed(NSString *text, Random_Seed
|
||||
NSMutableDictionary *all_descriptions = [[[UNIVERSE descriptions] mutableCopy] autorelease];
|
||||
id value = nil;
|
||||
NSString *part = nil, *before = nil, *after = nil, *middle = nil;
|
||||
int sub, rnd, opt;
|
||||
int p1, p2;
|
||||
unsigned sub, rnd, opt;
|
||||
unsigned p1, p2;
|
||||
NSArray *sysDesc = nil;
|
||||
NSArray *sysDescItem = nil;
|
||||
unsigned sysDescCount, descItemCount;
|
||||
|
||||
// add in player info if required
|
||||
// -- this is now duplicated with new commanderXXX_string and commanderYYY_number methods in PlayerEntity Additions -- GILES
|
||||
@ -328,22 +331,45 @@ NSString *ExpandDescriptionsWithLocalsForSystemSeed(NSString *text, Random_Seed
|
||||
}
|
||||
else if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""])
|
||||
{
|
||||
part = @"";
|
||||
|
||||
// if all characters are all from the set "0123456789" interpret it as a number in system_description array
|
||||
if (![middle isEqual:@""])
|
||||
{
|
||||
sub = [middle intValue];
|
||||
if (sysDesc == nil)
|
||||
{
|
||||
sysDesc = [all_descriptions arrayForKey:@"system_description"];
|
||||
sysDescCount = [sysDesc count];
|
||||
}
|
||||
|
||||
sub = [middle intValue];
|
||||
rnd = gen_rnd_number();
|
||||
|
||||
if (sub < sysDescCount)
|
||||
{
|
||||
sysDescItem = [sysDesc arrayAtIndex:sub];
|
||||
if (sysDescItem != nil)
|
||||
{
|
||||
descItemCount = [sysDescItem count];
|
||||
if (descItemCount == 5)
|
||||
{
|
||||
// Time-honoured Elite-compatible way for five items
|
||||
opt = 0;
|
||||
if (rnd >= 0x33) opt++;
|
||||
if (rnd >= 0x66) opt++;
|
||||
if (rnd >= 0x99) opt++;
|
||||
if (rnd >= 0xCC) opt++;
|
||||
|
||||
part = [[[all_descriptions objectForKey:@"system_description"] objectAtIndex:sub] objectAtIndex:opt];
|
||||
}
|
||||
else
|
||||
part = @"";
|
||||
{
|
||||
// General way
|
||||
opt = (rnd * descItemCount) / 256;
|
||||
}
|
||||
|
||||
part = [sysDescItem objectAtIndex:opt];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
56
src/Core/OldSchoolPropertyListWriting.h
Normal file
56
src/Core/OldSchoolPropertyListWriting.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
OldSchoolPropertyListWriting.h
|
||||
Copyright 2006 Jens Ayton
|
||||
|
||||
A protocol for writing property lists in the OpenStep/simple text format. Why? Because as of
|
||||
Tiger, the system functions to do write plists reject the format. I, however, like it, because
|
||||
it’s clear and legible. Fight the power!
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@protocol OldSchoolPropertyListWriting
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSObject (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSData *)oldSchoolPListFormatWithErrorDescription:(NSString **)outErrorDescription;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface NSString (OldSchoolPropertyListWriting) <OldSchoolPropertyListWriting>
|
||||
@end
|
||||
|
||||
@interface NSNumber (OldSchoolPropertyListWriting) <OldSchoolPropertyListWriting>
|
||||
@end
|
||||
|
||||
@interface NSData (OldSchoolPropertyListWriting) <OldSchoolPropertyListWriting>
|
||||
@end
|
||||
|
||||
@interface NSArray (OldSchoolPropertyListWriting) <OldSchoolPropertyListWriting>
|
||||
@end
|
||||
|
||||
@interface NSDictionary (OldSchoolPropertyListWriting) <OldSchoolPropertyListWriting>
|
||||
@end
|
339
src/Core/OldSchoolPropertyListWriting.m
Normal file
339
src/Core/OldSchoolPropertyListWriting.m
Normal file
@ -0,0 +1,339 @@
|
||||
/*
|
||||
OldSchoolPropertyListWriting.m
|
||||
Copyright 2006 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import "OldSchoolPropertyListWriting.h"
|
||||
|
||||
|
||||
static BOOL IsFloatingPoint(NSNumber *number);
|
||||
static void AppendNewLineAndIndent(NSMutableString *ioString, unsigned indentDepth);
|
||||
|
||||
|
||||
@implementation NSString (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
NSCharacterSet *charSet;
|
||||
NSRange foundRange, searchRange;
|
||||
NSString *foundString;
|
||||
NSMutableString *newString;
|
||||
unsigned length;
|
||||
|
||||
length = [self length];
|
||||
if (0 != length
|
||||
&& [self rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location == NSNotFound
|
||||
&& ![[NSCharacterSet decimalDigitCharacterSet] longCharacterIsMember:[self characterAtIndex:0]])
|
||||
{
|
||||
// This is an alphanumeric string whose first character is not a digit
|
||||
return [[self copy] autorelease];
|
||||
}
|
||||
else
|
||||
{
|
||||
charSet = [NSCharacterSet characterSetWithCharactersInString:@"\"\r\n\\"];
|
||||
foundRange = [self rangeOfCharacterFromSet:charSet options:NSLiteralSearch];
|
||||
if (NSNotFound == foundRange.location)
|
||||
{
|
||||
newString = (NSMutableString *)self;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Escape quotes, backslashes and newlines
|
||||
newString = [[self substringToIndex:foundRange.location] mutableCopy];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// Append escaped character
|
||||
foundString = [self substringWithRange:foundRange];
|
||||
if ([foundString isEqual:@"\""]) [newString appendString:@"\\\""];
|
||||
else if ([foundString isEqual:@"\n"]) [newString appendString:@"\\\n"];
|
||||
else if ([foundString isEqual:@"\r"]) [newString appendString:@"\\\r"];
|
||||
else if ([foundString isEqual:@"\\"]) [newString appendString:@"\\\\"];
|
||||
else
|
||||
{
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%s: expected \" or newline, found %@", __FUNCTION__, foundString];
|
||||
}
|
||||
|
||||
// Use rest of string…
|
||||
searchRange.location = foundRange.location + foundRange.length;
|
||||
searchRange.length = length - searchRange.location;
|
||||
|
||||
// …to search for next char needing escaping
|
||||
foundRange = [self rangeOfCharacterFromSet:charSet options:NSLiteralSearch range:searchRange];
|
||||
if (NSNotFound == foundRange.location)
|
||||
{
|
||||
[newString appendString:[self substringWithRange:searchRange]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [NSString stringWithFormat:@"\"%@\"", newString];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSNumber (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
NSString *result;
|
||||
double dVal;
|
||||
|
||||
|
||||
if (self == [NSNumber numberWithBool:YES]) result = @"true";
|
||||
else if ([NSNumber numberWithBool:NO]) result = @"false";
|
||||
else if (IsFloatingPoint(self))
|
||||
{
|
||||
dVal = [self doubleValue];
|
||||
result = [NSString stringWithFormat:@"%.8g", dVal];
|
||||
}
|
||||
else result = [NSString stringWithFormat:@"%@", self];
|
||||
|
||||
// Allow infinities, but remember that they’ll be read in as strings
|
||||
/*
|
||||
if ([result isEqual:@"inf"] || [result isEqual:@"-inf"])
|
||||
{
|
||||
*outErrorDescription = @"infinities cannot be represented in old-school property lists";
|
||||
return nil;
|
||||
}
|
||||
*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSData (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
const uint8_t *srcBytes;
|
||||
uint8_t *dstBytes, *curr;
|
||||
unsigned i, j, srcLength, dstLength;
|
||||
const char hexTable[] = "0123456789ABCDEF";
|
||||
NSString *result;
|
||||
|
||||
srcBytes = [self bytes];
|
||||
srcLength = [self length];
|
||||
|
||||
dstLength = 2 * srcLength + srcLength/8 + 2 + (srcLength/64 * (1 + inIndentation));
|
||||
|
||||
dstBytes = malloc(dstLength);
|
||||
if (nil == dstBytes)
|
||||
{
|
||||
if (NULL != outErrorDescription)
|
||||
{
|
||||
*outErrorDescription = [NSString stringWithFormat:@"failed to allocate space (%u bytes) for conversion of NSData to old-school property list representation", dstLength];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
curr = dstBytes;
|
||||
*curr++ = '<';
|
||||
for (i = 0; i != srcLength; ++i)
|
||||
{
|
||||
if (0 != i && 0 == (i & 3))
|
||||
{
|
||||
if (0 == (i & 31))
|
||||
{
|
||||
*curr++ = '\n';
|
||||
j = inIndentation;
|
||||
while (--j) *curr++ = '\t';
|
||||
}
|
||||
*curr++ = ' ';
|
||||
}
|
||||
*curr++ = hexTable[srcBytes[i] >> 4];
|
||||
*curr++ = hexTable[srcBytes[i] & 0xF];
|
||||
}
|
||||
*curr = '>';
|
||||
|
||||
assert((size_t)(curr - dstBytes) <= dstLength);
|
||||
|
||||
result = [[NSString alloc] initWithBytesNoCopy:dstBytes length:dstLength encoding:NSASCIIStringEncoding freeWhenDone:YES];
|
||||
return [result autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSArray (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
NSMutableString *result;
|
||||
unsigned i, count;
|
||||
id object;
|
||||
|
||||
result = [NSMutableString string];
|
||||
|
||||
[result appendString:@"("];
|
||||
|
||||
count = [self count];
|
||||
if (3 < count) AppendNewLineAndIndent(result, inIndentation + 1);
|
||||
|
||||
for (i = 0; i != count; ++i)
|
||||
{
|
||||
if (0 != i)
|
||||
{
|
||||
if (count <= 3) [result appendString:@", "];
|
||||
else
|
||||
{
|
||||
[result appendString:@","];
|
||||
AppendNewLineAndIndent(result, inIndentation + 1);
|
||||
}
|
||||
}
|
||||
|
||||
object = [self objectAtIndex:i];
|
||||
if (![object conformsToProtocol:@protocol (OldSchoolPropertyListWriting)])
|
||||
{
|
||||
if (nil != object && NULL != outErrorDescription)
|
||||
{
|
||||
*outErrorDescription = [NSString stringWithFormat:@"non-plist object in dictionary"];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
object = [object oldSchoolPListFormatWithIndentation:inIndentation + 1 errorDescription:outErrorDescription];
|
||||
if (nil == object) return nil;
|
||||
[result appendString:object];
|
||||
}
|
||||
if (3 < count) AppendNewLineAndIndent(result, inIndentation);
|
||||
[result appendString:@")"];
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSDictionary (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
NSMutableString *result;
|
||||
unsigned i, count;
|
||||
NSArray *allKeys;
|
||||
id key, value;
|
||||
NSString *valueDesc;
|
||||
|
||||
result = [NSMutableString string];
|
||||
allKeys = [self allKeys];
|
||||
count = [allKeys count];
|
||||
|
||||
[result appendString:@"{"];
|
||||
|
||||
if (2 < count || inIndentation == 0) AppendNewLineAndIndent(result, inIndentation + 1);
|
||||
|
||||
for (i = 0; i != count; ++i)
|
||||
{
|
||||
if (0 != i)
|
||||
{
|
||||
if (count <= 2 && 0 != inIndentation) [result appendString:@" "];
|
||||
else AppendNewLineAndIndent(result, inIndentation + 1);
|
||||
}
|
||||
|
||||
key = [allKeys objectAtIndex:i];
|
||||
if (![key isKindOfClass:[NSString class]])
|
||||
{
|
||||
if (NULL != outErrorDescription) *outErrorDescription = [NSString stringWithFormat:@"non-string key in dictionary"];
|
||||
return nil;
|
||||
}
|
||||
value = [self objectForKey:key];
|
||||
if (![value conformsToProtocol:@protocol(OldSchoolPropertyListWriting)])
|
||||
{
|
||||
if (nil != value && NULL != outErrorDescription)
|
||||
{
|
||||
*outErrorDescription = [NSString stringWithFormat:@"non-plist object in dictionary"];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
key = [key oldSchoolPListFormatWithIndentation:inIndentation + 1 errorDescription:outErrorDescription];
|
||||
if (nil == key) return nil;
|
||||
valueDesc = [value oldSchoolPListFormatWithIndentation:inIndentation + 1 errorDescription:outErrorDescription];
|
||||
if (nil == valueDesc) return nil;
|
||||
|
||||
[result appendFormat:@"%@ =", key];
|
||||
if (([value isKindOfClass:[NSArray class]] && [value count] >= 3) || ([value isKindOfClass:[NSDictionary class]] && [value count] >= 2))
|
||||
{
|
||||
AppendNewLineAndIndent(result, inIndentation + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
[result appendString:@" "];
|
||||
}
|
||||
[result appendFormat:@"%@;", valueDesc];
|
||||
}
|
||||
|
||||
if (2 < count || inIndentation == 0) AppendNewLineAndIndent(result, inIndentation);
|
||||
[result appendString:@"}"];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSObject (OldSchoolPropertyListWriting_Private)
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSObject (OldSchoolPropertyListWriting)
|
||||
|
||||
- (NSData *)oldSchoolPListFormatWithErrorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
NSString *string;
|
||||
|
||||
string = [self oldSchoolPListFormatWithIndentation:0 errorDescription:outErrorDescription];
|
||||
return [[string stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)oldSchoolPListFormatWithIndentation:(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
|
||||
{
|
||||
if (NULL != outErrorDescription)
|
||||
{
|
||||
*outErrorDescription = [NSString stringWithFormat:@"Class %@ does not support OldSchoolPropertyListWriting", [self className]];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
static BOOL IsFloatingPoint(NSNumber *number)
|
||||
{
|
||||
const char *type = [number objCType];
|
||||
if (strcmp(type, @encode(float)) == 0) return YES;
|
||||
if (strcmp(type, @encode(double)) == 0) return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
static void AppendNewLineAndIndent(NSMutableString *ioString, unsigned indentDepth)
|
||||
{
|
||||
[ioString appendString:@"\n"];
|
||||
while (indentDepth--) [ioString appendString:@"\t"];
|
||||
}
|
@ -64,6 +64,11 @@ MA 02110-1301, USA.
|
||||
#import "ParticleEntity.h"
|
||||
#import "ShipEntityAI.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#import "OOConvertSystemDescriptions.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define kOOLogUnconvertedNSLog @"unclassified.Universe"
|
||||
|
||||
#define MAX_NUMBER_OF_ENTITIES 200
|
||||
@ -102,6 +107,10 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
|
||||
- (void) dumpSystemDescriptionGraphViz;
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
- (void) runLocalizationTools;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -295,6 +304,10 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
|
||||
|
||||
[player completeInitialSetUp];
|
||||
|
||||
#ifndef NDEBUG
|
||||
[self runLocalizationTools];
|
||||
#endif
|
||||
|
||||
#if SUPPORT_GRAPHVIZ_OUT
|
||||
[self dumpDebugGraphViz];
|
||||
#endif
|
||||
@ -8142,6 +8155,12 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context)
|
||||
unsigned i, count, j, subCount;
|
||||
NSString *descLine = nil;
|
||||
NSArray *curses = nil;
|
||||
NSString *label = nil;
|
||||
NSDictionary *keyMap = nil;
|
||||
|
||||
keyMap = [ResourceManager dictionaryFromFilesNamed:@"sysdesc_key_table.plist"
|
||||
inFolder:@"Config"
|
||||
andMerge:NO];
|
||||
|
||||
graphViz = [NSMutableString stringWithString:
|
||||
@"// System description grammar:\n\n"
|
||||
@ -8191,7 +8210,12 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context)
|
||||
// Define the nodes
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
[graphViz appendFormat:@"\tsubgraph cluster_%u\n\t{\n\t\tlabel=\"[%u]\"\n", i, i];
|
||||
// Build label, using sysdesc_key_table.plist if available
|
||||
label = [keyMap objectForKey:[NSString stringWithFormat:@"%u", i]];
|
||||
if (label == nil) label = [NSString stringWithFormat:@"[%u]", i];
|
||||
else label = [NSString stringWithFormat:@"[%u] (%@)", i, label];
|
||||
|
||||
[graphViz appendFormat:@"\tsubgraph cluster_%u\n\t{\n\t\tlabel=\"%@\"\n", i, EscapedGraphVizString(label)];
|
||||
|
||||
thisDesc = [systemDescriptions arrayAtIndex:i];
|
||||
subCount = [thisDesc count];
|
||||
@ -8225,6 +8249,32 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
- (void) runLocalizationTools
|
||||
{
|
||||
// Handle command line options to transform system_description array for easier localization
|
||||
|
||||
NSArray *arguments = nil;
|
||||
NSEnumerator *argEnum = nil;
|
||||
NSString *arg = nil;
|
||||
BOOL compileSysDesc = NO, exportSysDesc = NO, xml = NO;
|
||||
|
||||
arguments = [[NSProcessInfo processInfo] arguments];
|
||||
|
||||
for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); )
|
||||
{
|
||||
if ([arg isEqual:@"--compile-sysdesc"]) compileSysDesc = YES;
|
||||
else if ([arg isEqual:@"--export-sysdesc"]) exportSysDesc = YES;
|
||||
else if ([arg isEqual:@"--xml"]) xml = YES;
|
||||
else if ([arg isEqual:@"--openstep"]) xml = NO;
|
||||
}
|
||||
|
||||
if (compileSysDesc) CompileSystemDescriptions(xml);
|
||||
if (exportSysDesc) ExportSystemDescriptions(xml);
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -90,6 +90,7 @@ void seed_RNG_only_for_planet_description(Random_Seed s_seed);
|
||||
RNG_Seed currentRandomSeed(void);
|
||||
void setRandomSeed(RNG_Seed a_seed);
|
||||
|
||||
// Range: 0..255
|
||||
int gen_rnd_number (void);
|
||||
|
||||
void make_pseudo_random_seed (Random_Seed *seed_ptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user