-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.h
64 lines (50 loc) · 1.26 KB
/
config.h
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
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: MIT */
/* SPDX-FileCopyrightText: (c) Copyright 2024 Andrew Bower <andrew@bower.uk> */
#ifndef _CONFIG_H
#define _CONFIG_H
#include "unhtml.h"
#include <uchar.h>
#include <libxml/xmlstring.h>
enum spacing {
SPACING_NONE,
SPACING_PARA,
SPACING_NEWLINE,
SPACING_SPACE,
};
enum op {
OP_ADD,
OP_REPLACE,
};
struct render_elem {
enum spacing spacing;
bool skip;
xmlChar tag[];
};
struct config {
void *elements;
};
struct config_dir {
char *dir;
struct config_dir *next;
bool name_needs_free:1;
bool node_needs_free:1;
};
static struct config_dir defconf_package = { PREFIX "/share/" UNHTML, nullptr };
static struct config_dir defconf_system = { "/etc/" UNHTML, &defconf_package };
static struct config_dir defconf_user = { NULL, &defconf_system };
static inline struct config_dir *get_defconf(void) {
const char *dir = getenv("XDG_CONFIG_HOME");
if (dir) {
char *path = NULL;
asprintf(&path, "%s/" UNHTML, dir);
defconf_user.dir = strdup(path);
defconf_user.name_needs_free = true;
return &defconf_user;
} else {
return &defconf_system;
}
}
extern struct config config;
extern int load_config(struct config_dir *dirs);
extern struct render_elem *get_rendering(const char8_t *tag);
#endif