lib/kuhl-config.c
/** Gets the value for a given key in the config file.

    @param key The key to look up in the config file.

    @return The value of the key as a string. If the key is missing,
    or if the key is present but its value is the empty string, return
    NULL.
*/
Gets the value for a given key in the config file.
Gets the value for a given key in the config file .
const char* kuhl_config_get(const char *key)
{
	if(cfg == NULL)
	{
		int using_defaultFile = 0;
		if(cfg_filename == NULL)
		{
			cfg_filename = "settings.ini";
			using_defaultFile = 1;
		}
		cfg = cfg_init();
		char *filename = kuhl_find_file(cfg_filename);
		if(cfg_load(cfg, filename, 1) == EXIT_FAILURE)
		{
			if(using_defaultFile)
				msg(MSG_DEBUG, "Can't read/find default config file: %s\n", filename);
			else
				msg(MSG_ERROR, "Failed to read user-specified config file: %s\n", filename);
		}
		else
			msg(MSG_DEBUG, "Using settings file at: %s\n", filename);
		free(filename);
		while(cfg_get(cfg, "include") != NULL)
		{
			const char *include = cfg_get(cfg, "include");
			filename = kuhl_find_file(include);
			cfg_delete(cfg, "include");
			if(kuhl_can_read_file(filename))
			{
				msg(MSG_DEBUG, "Config file '%s' included '%s'.", cfg_filename, filename);
				cfg_load(cfg, filename, 0); 
			}
			else
			{
				msg(MSG_ERROR, "Config file '%s' included '%s', but it doesn't exist or isn't readable.", cfg_filename, filename);
			}
			free(filename);
		}
	}
	const char *value = cfg_get(cfg, key);
	if(value != NULL && strlen(value) == 0)
		value = NULL;
	return value;
}
const char * kuhl_config_get ( const char * key ) { if ( cfg == NULL ) { int using_defaultFile = 0 ; if ( cfg_filename == NULL ) { cfg_filename = " " ; using_defaultFile = 1 ; } cfg = cfg_init ( ) ; char * filename = kuhl_find_file ( cfg_filename ) ; if ( cfg_load ( cfg , filename , 1 ) == EXIT_FAILURE ) { if ( using_defaultFile ) msg ( MSG_DEBUG , " \n " , filename ) ; else msg ( MSG_ERROR , " \n " , filename ) ; } else msg ( MSG_DEBUG , " \n " , filename ) ; free ( filename ) ; while ( cfg_get ( cfg , " " ) != NULL ) { const char * include = cfg_get ( cfg , " " ) ; filename = kuhl_find_file ( include ) ; cfg_delete ( cfg , " " ) ; if ( kuhl_can_read_file ( filename ) ) { msg ( MSG_DEBUG , " " , cfg_filename , filename ) ; cfg_load ( cfg , filename , 0 ) ; } else { msg ( MSG_ERROR , " " , cfg_filename , filename ) ; } free ( filename ) ; } } const char * value = cfg_get ( cfg , key ) ; if ( value != NULL && strlen ( value ) == 0 ) value = NULL ; return value ; }
Gets the value for a given key in the config file.
Gets the value for a given key in the config file .
// don't overwrite