Program Config File Functionsv3ConfigLoadSyntax#include "config.h" s32 v3ConfigLoad( v3_CONFIG * config, const ascii * filename ); DescriptionAttempt to open the filename and read in the config data. See v3FileOpen in cosmfile.h for how to specify the path and file name. If filename is NULL, create an empty config. A config file will look something like this. <begin file> [section1]\n key1=value1\n key2=value2\n \n [section2]\n key1=value1\n key2=value2\n \n </end file> Config files follow these conventions:
Return ValuesV3_PASS on success, or a file error code (V3_FILE_ERROR_*) on failure. ErrorsNone. Examplev3_CONFIG * config; s32 result; config = v3MemAlloc( v3u64u32( sizeof(v3_CONFIG) ), V3_MEM_NORMAL ); result = v3ConfigLoad( config, (ascii *) "program.cfg" ); if ( result != V3_PASS ) { /* error */ } v3ConfigSaveSyntax#include "config.h" s32 v3ConfigSave( const v3_CONFIG * config, const ascii * filename ); DescriptionWrite out the config data to the file specified by filename. See v3FileOpen in cosmfile.h for how to specify the path and file name. See v3ConfigLoad for more information on config files. Return ValuesV3_PASS on success, or a file error code (V3_FILE_ERROR_*) on failure. ErrorsNone. Examplev3_CONFIG * config; s32 result; config = v3MemAlloc( v3u64u32( sizeof(v3_CONFIG) ), V3_MEM_NORMAL ); result = v3ConfigLoad( config, (ascii *) "program.cfg" ); if ( result != V3_PASS ) { /* error */ } /* ... */ result = v3ConfigSave( config, (ascii *) "program.cfg" ); if ( result != V3_PASS ) { /* error */ } v3ConfigSetSyntax#include "config.h" s32 v3ConfigSet( v3_CONFIG * config, const ascii * section, const ascii * key, const ascii * value ); DescriptionSet the value for the section/key pair. If value is NULL then key is deleted. Return ValuesV3_PASS on success, or V3_FAIL on failure. ErrorsNone. Examplev3_CONFIG * config; s32 result; config = v3MemAlloc( v3u64u32( sizeof(v3_CONFIG) ), V3_MEM_NORMAL ); result = v3ConfigLoad( config, (ascii *) "program.cfg" ) if ( result != V3_PASS ) { /* error */ } result = v3ConfigSet( config, (ascii *) "Options", (ascii *) "logging", (ascii *) "1" ); if ( result != V3_PASS ) { /* error */ } v3ConfigGetSyntax#include "config.h" const ascii * v3ConfigGet( v3_CONFIG * config, const ascii * section, const ascii * key ); DescriptionGet the value of the section/key pair. The returned pointer will no longer be valid once another v3Config* call is made. Return ValuesA pointer to the value on success, or NULL on failure. ErrorsNone. Examplev3_CONFIG * config; s32 result; ascii * value; config = v3MemAlloc( v3u64u32( sizeof(v3_CONFIG) ), V3_MEM_NORMAL ); result = v3ConfigLoad( config, (ascii *) "program.cfg" ); if ( result != V3_PASS ) { /* error */ } value = v3ConfigGet( config, (ascii *) "Program", (ascii *) "interval" ); v3ConfigFreeSyntax#include "config.h" void v3ConfigFree( v3_CONFIG * config ); DescriptionFree the internal config data. Return ValuesNone. ErrorsNone. Examplev3_CONFIG * config; config = v3MemAlloc( v3u64u32( sizeof(v3_CONFIG) ), V3_MEM_NORMAL ); /* use the config */ v3ConfigFree( config ); v3MemFree( config );
© Copyright Mithral Communications & Design Inc.
1995-2003.
All rights reserved.
Mithral® and Cosm® are trademarks of
Mithral Communications & Design Inc.
|