54 lines
1.2 KiB
C
54 lines
1.2 KiB
C
#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 "";
|
|
}
|
|
|