revert breaks some stupid old compilers
[oscam.git] / oscam-conf.h
blob3e0e49629de988ef9b5ba5fd77a2e1405acc1482
1 #ifndef OSCAM_CONF_H
2 #define OSCAM_CONF_H
4 #define MAXLINESIZE 16384
6 enum opt_types {
7 OPT_UNKNOWN = 0,
8 OPT_INT8,
9 OPT_UINT8,
10 OPT_INT32,
11 OPT_UINT32,
12 OPT_STRING,
13 OPT_SSTRING,
14 OPT_HEX_ARRAY,
15 OPT_FUNC,
16 OPT_FUNC_EXTRA,
17 OPT_SAVE_FUNC,
18 OPT_FIXUP_FUNC,
21 struct config_list {
22 enum opt_types opt_type;
23 char *config_name;
24 size_t var_offset;
25 unsigned int str_size;
26 union {
27 int8_t d_int8;
28 uint8_t d_uint8;
29 int32_t d_int32;
30 uint32_t d_uint32;
31 char *d_char;
32 long d_extra;
33 uint32_t array_size;
34 } def;
35 union {
36 void (*process_fn)(const char *token, char *value, void *setting, FILE *config_file);
37 void (*process_fn_extra)(const char *token, char *value, void *setting, long extra, FILE *config_file);
38 bool (*should_save_fn)(void *var);
39 void (*fixup_fn)(void *var);
40 } ops;
41 void (*free_value)(void *setting);
44 #define DEF_OPT_INT8(__name, __var_ofs, __default) \
45 { \
46 .opt_type = OPT_INT8, \
47 .config_name = __name, \
48 .var_offset = __var_ofs, \
49 .def.d_int8 = __default \
52 #define DEF_OPT_UINT8(__name, __var_ofs, __default) \
53 { \
54 .opt_type = OPT_UINT8, \
55 .config_name = __name, \
56 .var_offset = __var_ofs, \
57 .def.d_uint8 = __default \
60 #define DEF_OPT_INT32(__name, __var_ofs, __default) \
61 { \
62 .opt_type = OPT_INT32, \
63 .config_name = __name, \
64 .var_offset = __var_ofs, \
65 .def.d_int32 = __default \
68 #define DEF_OPT_UINT32(__name, __var_ofs, __default) \
69 { \
70 .opt_type = OPT_UINT32, \
71 .config_name = __name, \
72 .var_offset = __var_ofs, \
73 .def.d_uint32 = __default \
76 #define DEF_OPT_STR(__name, __var_ofs, __default) \
77 { \
78 .opt_type = OPT_STRING, \
79 .config_name = __name, \
80 .var_offset = __var_ofs, \
81 .def.d_char = __default \
84 #define DEF_OPT_SSTR(__name, __var_ofs, __default, __str_size) \
85 { \
86 .opt_type = OPT_SSTRING, \
87 .config_name = __name, \
88 .var_offset = __var_ofs, \
89 .str_size = __str_size, \
90 .def.d_char = __default \
93 #define DEF_OPT_HEX(__name, __var_ofs, __array_size) \
94 { \
95 .opt_type = OPT_HEX_ARRAY, \
96 .config_name = __name, \
97 .var_offset = __var_ofs, \
98 .def.array_size = __array_size \
101 #define DEF_OPT_FUNC(__name, __var_ofs, __process_fn, ...) \
103 .opt_type = OPT_FUNC, \
104 .config_name = __name, \
105 .var_offset = __var_ofs, \
106 .ops.process_fn = __process_fn, \
107 ##__VA_ARGS__ \
110 #define DEF_OPT_FUNC_X(__name, __var_ofs, __process_fn_extra, __extra, ...) \
112 .opt_type = OPT_FUNC_EXTRA, \
113 .config_name = __name, \
114 .var_offset = __var_ofs, \
115 .ops.process_fn_extra = __process_fn_extra, \
116 .def.d_extra = __extra, \
117 ##__VA_ARGS__ \
120 #define DEF_OPT_SAVE_FUNC(__fn) \
122 .opt_type = OPT_SAVE_FUNC, \
123 .ops.should_save_fn = __fn \
126 #define DEF_OPT_FIXUP_FUNC(__fn) \
128 .opt_type = OPT_FIXUP_FUNC, \
129 .ops.fixup_fn = __fn \
132 #define DEF_LAST_OPT \
134 .opt_type = OPT_UNKNOWN \
137 struct config_sections {
138 const char *section;
139 const struct config_list *config;
142 int32_t strToIntVal(char *value, int32_t defaultvalue);
143 uint32_t strToUIntVal(char *value, uint32_t defaultvalue);
145 void fprintf_conf(FILE *f, const char *varname, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
147 int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data);
148 void config_list_save_ex(FILE *f, const struct config_list *clist, void *config_data, int save_all,
149 bool (*check_func)(const struct config_list *clist, void *config_data, const char *setting)
151 static inline void config_list_save(FILE *f, const struct config_list *clist, void *config_data, int save_all) {
152 config_list_save_ex(f, clist, config_data, save_all, NULL);
154 void config_list_apply_fixups(const struct config_list *clist, void *var);
155 bool config_list_should_be_saved(const struct config_list *clist, void *var);
156 void config_list_set_defaults(const struct config_list *clist, void *config_data);
157 void config_list_free_values(const struct config_list *clist, void *config_data);
158 void config_list_gc_values(const struct config_list *clist, void *config_data);
160 int config_section_is_active(const struct config_sections *sec);
161 const struct config_sections *config_find_section(const struct config_sections *conf, char *section_name);
162 void config_sections_save(const struct config_sections *conf, FILE *f, void *var);
163 void config_sections_set_defaults(const struct config_sections *conf, void *var);
164 void config_sections_free(const struct config_sections *conf, void *var);
166 void config_set_value(const struct config_sections *conf, char *section, const char *token, char *value, void *var);
168 FILE *open_config_file(const char *conf_filename);
169 FILE *open_config_file_or_die(const char *conf_filename);
170 FILE *create_config_file(const char *conf_filename);
171 bool flush_config_file(FILE *f, const char *conf_filename);
173 #endif