I was writing a config file parser for a game I'm making in c++, and I figured i would put it in a library. I then decided to make a dbc library for it.
here is the list of functions:
cfg_New:
Params: 1 String, Name of the config file
returns a new Config parser from the specified file
cfg_NewData:
Params: 2 String/Ptr, DWORD size(or number of characters) of the data in bytes. Returns a new Config parser from the specified data
cfg_Quit:
Params: 1 DWORD, Config parser to close
cfg_GetStr:
Params: 1 DWORD, Config Handle. String Setting name, and a destenation.
returns: the string that was inputed. If the setting doesn't exist, the string is unchanged
cfg_GetInt:
Params: 3 DWORD, Config Handle. String Setting Name. Integer, default value
Returns: The integer value of that setting, or the default value
cfg_GetUint:
Same as above, but with unsigned integer
cfg_GetBool:
Params: 3. DWORD, Config handle. String, Setting name. BOOL(0 or 1) default value
Returns: 0 or 1. The config file should be true, or false. Not 0 or 1
cfg_GetFloat
Doesn't work right now. Working on it.
cfg_GetConfig
Params 2. DWORD, Config handle, String, Setting name
Returns: A new setting handle. See below for explanation
cfg_SettingExist
Params: 2. DWORD, Config handle. String, setting name
Returns: 1 if the setting exists, and 0 if it doesn't
cfg_Open
Params: 2. DWORD, Config handle, String file name
Returns: 1 or 0 specifying success. This will open a config file
The cfg_GetConfig will open a new config handle from a config setting. This means you can essentially build embeded config files. Like this:
# By the way this is a comment
#This is the main config file
embededConfig={
subItem=true; # here is a sub item
subItem2=1024; # just use subHandle=cfg_GetConfig(cfgHandle, "embededConfig")
};
This useful for things like controls. here is how I did my config file for the game i'm making:
# Game controls
controls={
left=276; # SDLK_LEFT
right=275; # SDLK_RIGHT
up=273; # SDLK_UP
down=274; # SDLK_DOWN
jump=122; # SDLK_z
run=120; # SDLK_x
pause=27; # SDLK_ESCAPE
accept=13; # SDLK_RETURN
reject=27; # SDLK_ESCAPE
};
All settings MUST havea semi-colon after it. The original Config functions, outputed error information to the console, and returned 0 for functions, but DBC doesn't have a console, so I am going to have to find a new error system.
The source, and dll is attached.
Well, I was doing some more testing, and It seems I am having problems with strings. It must have something to do with how they are allocated in dbc. Does anyone have any insight as to how they are allocated/deallocated?
New Site! Check it out \/