-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxconfig.h
62 lines (50 loc) · 1.49 KB
/
xconfig.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
/* evilwm - minimalist window manager for X11
* Copyright (C) 1999-2022 Ciaran Anscomb
* see README for license and other details. */
// Configuration parsing.
//
// Scans options either from an array (e.g., from command line) or file.
#ifndef EVILWM_XCONFIG_H__
#define EVILWM_XCONFIG_H__
enum xconfig_result {
XCONFIG_OK = 0,
XCONFIG_BAD_OPTION,
XCONFIG_MISSING_ARG,
XCONFIG_FILE_ERROR
};
// Option types.
enum xconfig_option_type {
XCONFIG_BOOL, // int
XCONFIG_INT, // int
XCONFIG_UINT, // unsigned
XCONFIG_DOUBLE, // double
XCONFIG_STRING, // char *
XCONFIG_STR_LIST, // char **
XCONFIG_CALL_0, // void (*)(void)
XCONFIG_CALL_1, // void (*)(const char *)
XCONFIG_END
};
// An array of struct xconfig_option passed to the parsing functions specifies
// recognised options, their type, and where to store any result. Mark the end
// of the list with entry of type XCONFIG_END.
struct xconfig_option {
enum xconfig_option_type type;
const char *name;
union {
int *i;
unsigned *u;
double *d;
char **s;
char ***sl;
void (*c0)(void);
void (*c1)(const char *);
} dest;
};
void xconfig_parse_line(struct xconfig_option *options, const char *line);
enum xconfig_result xconfig_parse_file(struct xconfig_option *options,
const char *filename);
enum xconfig_result xconfig_parse_cli(struct xconfig_option *options,
int argc, char **argv, int *argn);
// Free all allocated strings pointed to by options
void xconfig_free(struct xconfig_option *options);
#endif