| 
       Program Config File FunctionsCosmConfigLoadSyntax#include "config.h" s32 CosmConfigLoad( cosm_CONFIG * config, const ascii * filename ); DescriptionAttempt to open the filename and read in the config data. See CosmFileOpen in os_file.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 ValuesCOSM_PASS on success, or a file error code (COSM_FILE_ERROR_*) on failure. ErrorsNone. Example
  cosm_CONFIG * config;
  s32 result;
  config = CosmMemAlloc( sizeof( cosm_CONFIG ) );
  result = CosmConfigLoad( config, "program.cfg" );
  if ( result != COSM_PASS )
  {
    /* error */
  }
CosmConfigSaveSyntax#include "config.h" s32 CosmConfigSave( const cosm_CONFIG * config, const ascii * filename ); DescriptionWrite out the config data to the file specified by filename. See CosmFileOpen in os_file.h for how to specify the path and file name. See CosmConfigLoad for more information on config files. Return ValuesCOSM_PASS on success, or a file error code (COSM_FILE_ERROR_*) on failure. ErrorsNone. Example
  cosm_CONFIG * config;
  s32 result;
  config = CosmMemAlloc( sizeof( cosm_CONFIG ) );
  result = CosmConfigLoad( config, "program.cfg" );
  if ( result != COSM_PASS )
  {
    /* error */
  }
  /* ... */
  result = CosmConfigSave( config, "program.cfg" );
  if ( result != COSM_PASS )
  {
    /* error */
  }
CosmConfigSetSyntax#include "config.h" s32 CosmConfigSet( cosm_CONFIG * config, const utf8 * section, const utf8 * key, const utf8 * value ); DescriptionSet the value for the section/key pair. If value is NULL then key is deleted. Return ValuesCOSM_PASS on success, or COSM_FAIL on failure. ErrorsNone. Example
  cosm_CONFIG * config;
  s32 result;
  config = CosmMemAlloc( sizeof( cosm_CONFIG ) );
  result = CosmConfigLoad( config, "program.cfg" )
  if ( result != COSM_PASS )
  {
    /* error */
  }
  result = CosmConfigSet( config, "Options",
     "logging", "1" );
  if ( result != COSM_PASS )
  {
    /* error */
  }
CosmConfigGetSyntax#include "config.h" const utf8 * CosmConfigGet( cosm_CONFIG * config, const utf8 * section, const utf8 * key ); DescriptionGet the value of the section/key pair. The returned pointer will no longer be valid once another CosmConfig* call is made. Return ValuesA pointer to the value on success, or NULL on failure. ErrorsNone. Example
  cosm_CONFIG * config;
  s32 result;
  utf8 * value;
  config = CosmMemAlloc( sizeof( cosm_CONFIG ) );
  result = CosmConfigLoad( config, "program.cfg" );
  if ( result != COSM_PASS )
  {
    /* error */
  }
  value = CosmConfigGet( config, "Program",
     "interval" );
CosmConfigFreeSyntax#include "config.h" void CosmConfigFree( cosm_CONFIG * config ); DescriptionFree the internal config data. Return ValuesNone. ErrorsNone. Examplecosm_CONFIG * config; config = CosmMemAlloc( sizeof( cosm_CONFIG ) ); /* use the config */ CosmConfigFree( config ); CosmMemFree( config ); 
    © Copyright Mithral Communications & Design Inc.
    
    1995-2025.
    All rights reserved.
    Mithral® and Cosm® are trademarks of
    Mithral Communications & Design Inc.
     |