blob: 9335813b7204e1e4391eb065b89258e3dd87ee29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include "config-load.h"
#include "config-ini.h"
#include "types.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char * simple_basename(const char *path) {
const char *slash = strrchr(path, '/');
return slash ? (slash+1) : path;
}
static const char * extname(const char *filename) {
const char *dot = strrchr(filename, '.');
return dot ? (dot+1) : NULL;
}
static interface_config_t * read_interface_config(const char *path) {
ini_file_t *file = read_ini_file(path);
ini_section_t *section;
ini_field_t *field;
list_for_each_entry(section, &file->sections, node) {
printf("%s\n", section->name);
list_for_each_entry(field, §ion->fields, node)
printf("%s.%s=%s\n", section->name, field->key, field->value);
}
free_ini_file(file);
return NULL;
}
bool read_config_file(const char *path) {
const char *filename = simple_basename(path);
const char *ext = extname(filename);
if (!ext) {
errno = EINVAL;
return false;
}
char *name = strndup(filename, (ext - filename) - 1);
if (strcmp(ext, "interface") == 0) {
interface_config_t *iface = read_interface_config(path);
free(iface);
}
free(name);
return true;
}
|