Totally simple configuration module.

BlitzMax Forums/BlitzMax Programming/Totally simple configuration module.

Helios(Posted 2006) [#1]
Well for one of my projects i needed a system so i can load and save whole states of my games world in a single file yet allow it to modifyable, and also so i could store multiple object scripts (for a scripting language i designed called PhoenixScript) in a single object file. I though of ini but i couldnt do sub-groups, i also though of xml but didnt like the syntax myself and it didnt have a couple of things i was after; so i wrote this. Its a parser/lexer/api set for a simple configuration language i call 'Totally simple configuration' (yeh, bad title i know >_<). The syntax is designed to be easy (but please be aware these no expression handeling or anthing of that nature as it was designed wholy for configuration) heres an example;

Settings{
	Graphics{
		Resolution=640.000000,480.000000
		Depth=0.0000000
		Hertz=60.0000000
		Title="Totally simple configuration - example 01"
	}
	Application{
		ImageFile="media\\Image1.png"
	}
}


Map1{
	Settings{
		MusicFile = "media\\musicarchive.arh[Track0]"
	    Size = 200, 200
	}
	Data {
		Layer1 = "0102436234601
			  2353462436234
			  6234623462346
			  2364234623463
			  2346234634634
			  2342346324643
			  2346234634623"
              Entitys{
                    Entity001{
                         Position = 0,0
                    }
              }
	}
}


As you can see it has a couple of intresting features like mutliple values per key (eg. "Color = 255,0,255"), escape sequences (most of the C++ ones), full inheritence(no limit to how many sub-groups you have), ability to use ' or " for strings and a few other things like #Define.

And the best part is its very simple to load and save the scripts, heres a loading example...

Rem
	Create a new file
End Rem		
Local File:TTSCFile = CreateTSCFile()

	Rem
		Load file
	End Rem
	LoadTSCFile(File,"config\Example01.tsc")
	
Rem
	Setup graphics using config values
End Rem
AppTitle 		 = GetTSCStringKey(File,"Settings::Graphics","Title")
Local Width:Int  = GetTSCNumberKey(File,"Settings::Graphics","Resolution",0)
Local Height:Int = GetTSCNumberKey(File,"Settings::Graphics","Resolution",1)
Local Depth:Int  = GetTSCNumberKey(File,"Settings::Graphics","Depth")
Local Hertz:Int  = GetTSCNumberKey(File,"Settings::Graphics","Hertz")

Graphics Width, Height, Depth, Hertz
SetBlend ALPHABLEND

Rem
	Load image from url stored in config file
End Rem
Local Image:TImage = LoadImage(GetTSCStringKey(File,"Settings::Application","ImageFile"))
MidHandleImage(Image)


Anyway heres the module if anyoe wishs to use it, ive included a basic load / save example in it so you can get to know the host api.
http://www.savefile.com/files.php?fid=7115117

Please be aware its not completly bug free as i wrote most of it today, and am still fiddling with it heavly.


N(Posted 2006) [#2]
I did something like this with my Cower.SParse (Simple-Parse) module. Stuff like this is handy, thanks.