Added config files
This commit is contained in:
53
config.c
Normal file
53
config.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <libconfig.h>
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
|
||||
config_t cfg;
|
||||
const config_setting_t *setting;
|
||||
|
||||
void cfginit(void) {
|
||||
|
||||
config_init(&cfg);
|
||||
if (!config_read_file(&cfg, "csoundbox.cfg")) {
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
//return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void cfgdestroy(void) {
|
||||
//free ram
|
||||
config_destroy(&cfg);
|
||||
}
|
||||
|
||||
void cfgreinit(void) {
|
||||
cfgdestroy();
|
||||
cfginit();
|
||||
}
|
||||
|
||||
|
||||
const char *lookupSounds(char input) {
|
||||
setting = config_lookup(&cfg, "soundmap.sounds");
|
||||
const char *temp;
|
||||
if(setting != NULL) {
|
||||
int count = config_setting_length(setting);
|
||||
int i;
|
||||
|
||||
|
||||
for(i = 0; i < count; ++i) {
|
||||
config_setting_t *sound = config_setting_get_elem(setting, i);
|
||||
|
||||
/* Only output the record if all of the expected fields are present. */
|
||||
const char *key;
|
||||
|
||||
if (config_setting_lookup_string(sound, "key", &key))
|
||||
if (key[0] == input) {
|
||||
config_setting_lookup_string(sound, "path", &temp);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
Reference in New Issue
Block a user