blob: daf97fa0166cffb5f46e9344d437dea63ee58356 (
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
|
#define _GNU_SOURCE
#include <config.h>
#include <list.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util.h>
void
config_parse(char *content)
{
list_t *keys = list_create(sizeof(char *));
list_t *values = list_create(sizeof(char *));
char *buffer = strdup(content);
char *line_internal = strtok(buffer, "\n");
while (line_internal != NULL) {
char *line = strdup(line_internal);
char *value = line;
char *key = strsep(&value, "=");
value = trim(value);
key = trim(key);
list_add(keys, strdup(key));
list_add(values, strdup(value));
free(line);
line_internal = strtok(NULL, "\n");
}
for (size_t i = 0; i < keys->size; i++) {
printf(
"%s: %s\n", (char *) list_get(keys, i), (char *) list_get(values, i));
}
free(buffer);
}
|