Text config file support
[hdmi-switcher.git] / config.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "config.h"
5
6 static int handler(void* user, const char* section, const char* name, const char* value)
7 {
8 configuration* pconfig = (configuration*)user;
9
10 #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
11 if (MATCH("global", "credit_value")) {
12 pconfig->credit_value = atoi(value);
13 //}else if (MATCH("user", "name")) {
14 // pconfig->name = strdup(value);
15 //} else if (MATCH("user", "email")) {
16 // pconfig->email = strdup(value);
17 } else {
18 return 0; /* unknown section/name, error */
19 }
20 return 1;
21 }
22
23 int init_config(configuration *config)
24 {
25 return ini_parse("config.ini", handler, config) >= 0;
26 }