-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.c
More file actions
54 lines (45 loc) · 1.52 KB
/
Copy pathexample.c
File metadata and controls
54 lines (45 loc) · 1.52 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
int
main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "Error: missing config file\n");
return 1;
}
int capacity = 64;
CfgEntry *entries = malloc(capacity * sizeof(CfgEntry));
if (entries == NULL) {
fprintf(stderr, "Error: memory allocation failed\n");
return 1;
}
CfgError err;
Cfg cfg = {.entries = entries, .capacity = capacity};
int res = cfg_parse_file(argv[1], &cfg, &err);
if (res != 0) {
cfg_fprint_error(stderr, &err);
free(entries);
return 1;
}
char *font = cfg_get_string(&cfg, "font", "Noto Sans Mono");
int font_size = cfg_get_int(&cfg, "font.size", 12);
float zoom = cfg_get_float(&cfg, "zoom", 1.0);
bool line_num = cfg_get_bool(&cfg, "lineNumbers", true);
CfgColor bg = cfg_get_color(&cfg, "bg.color",
(CfgColor){
.r = 255,
.g = 255,
.b = 255,
.a = 1,
});
fprintf(stdout, "font: %s\n", font);
fprintf(stdout, "font.size: %d\n", font_size);
fprintf(stdout, "zoom: %f\n", zoom);
fprintf(stdout, "lineNumbers: %s\n", line_num ? "true" : "false");
fprintf(stdout, "bg.color: rgba(%d, %d, %d, %d)\n", bg.r, bg.g, bg.b, bg.a);
// cfg_fprint(stdout, &cfg);
free(entries);
return 0;
}