Reading a config file is now working.
This commit is contained in:
parent
cfd80b839b
commit
5e88e7c2c3
75
get_artist_art.c
Normal file
75
get_artist_art.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <libconfig.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define conf_file "config.ini"
|
||||
|
||||
const char *get_conf_str(char set_key[10]) {
|
||||
const char *prog_conf = malloc(10 * sizeof(char));
|
||||
config_t cfg;
|
||||
config_setting_t *setting;
|
||||
|
||||
config_init(&cfg);
|
||||
|
||||
if (!config_read_file(&cfg, conf_file)) {
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
|
||||
config_error_line(&cfg), config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
return "";
|
||||
}
|
||||
|
||||
setting = config_lookup(&cfg, set_key);
|
||||
|
||||
prog_conf = config_setting_get_string(setting);
|
||||
|
||||
config_destroy(&cfg);
|
||||
return prog_conf;
|
||||
}
|
||||
|
||||
int get_conf_int(char set_key[10]) {
|
||||
int set_int;
|
||||
config_t cfg;
|
||||
config_setting_t *setting;
|
||||
|
||||
config_init(&cfg);
|
||||
|
||||
if (!config_read_file(&cfg, conf_file)) {
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
|
||||
config_error_line(&cfg), config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
setting = config_lookup(&cfg, set_key);
|
||||
set_int = config_setting_get_int(setting);
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
return set_int;
|
||||
}
|
||||
|
||||
void print_conf(const char m_dir[20], const int mb_conf,
|
||||
const char ftv_api_key[32]) {
|
||||
if (m_dir != NULL) {
|
||||
printf("The music directory is: %s\n", m_dir);
|
||||
}
|
||||
if (mb_conf != 1) {
|
||||
printf("The lower limit for MB confidence is: %d\n", mb_conf);
|
||||
}
|
||||
if (ftv_api_key != NULL) {
|
||||
printf("Your API key is: %s\n", ftv_api_key);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int mb_conf;
|
||||
const char *m_dir, *ftv_api_key;
|
||||
|
||||
m_dir = get_conf_str("dir");
|
||||
mb_conf = get_conf_int("confidence");
|
||||
ftv_api_key = get_conf_str("api_key");
|
||||
|
||||
print_conf(m_dir, mb_conf, ftv_api_key);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user