blob: bb6533c286814f3d211e0db620375501e3d56da2 (
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
|
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "readline.h"
#include "stringop.h"
#include "list.h"
#include "commands.h"
#include "config.h"
struct sway_config *read_config(FILE *file) {
struct sway_config *config = malloc(sizeof(struct sway_config));
config->symbols = create_list();
config->modes = create_list();
int temp_braces = 0; // Temporary: skip all config sections with braces
while (!feof(file)) {
int _;
char *line = read_line(file);
line = strip_whitespace(line, &_);
line = strip_comments(line);
if (!line[0]) {
goto _continue;
}
if (temp_braces && line[0] == '}') {
temp_braces--;
goto _continue;
}
handle_command(config, line);
_continue:
if (line && line[strlen(line) - 1] == '{') {
temp_braces++;
}
free(line);
}
return config;
}
|