4 #define MAXLINESIZE 16384
24 enum opt_types opt_type
;
27 unsigned int str_size
;
40 void (*process_fn
)(const char *token
, char *value
, void *setting
, FILE *config_file
);
41 void (*process_fn_extra
)(const char *token
, char *value
, void *setting
, long extra
, FILE *config_file
);
42 bool (*should_save_fn
)(void *var
);
43 void (*fixup_fn
)(void *var
);
46 void (*free_value
)(void *setting
);
49 #define DEF_OPT_INT8(__name, __var_ofs, __default) \
51 .opt_type = OPT_INT8, \
52 .config_name = __name, \
53 .var_offset = __var_ofs, \
54 .def.d_int8 = __default \
57 #define DEF_OPT_UINT8(__name, __var_ofs, __default) \
59 .opt_type = OPT_UINT8, \
60 .config_name = __name, \
61 .var_offset = __var_ofs, \
62 .def.d_uint8 = __default \
65 #define DEF_OPT_INT32(__name, __var_ofs, __default) \
67 .opt_type = OPT_INT32, \
68 .config_name = __name, \
69 .var_offset = __var_ofs, \
70 .def.d_int32 = __default \
73 #define DEF_OPT_UINT32(__name, __var_ofs, __default) \
75 .opt_type = OPT_UINT32, \
76 .config_name = __name, \
77 .var_offset = __var_ofs, \
78 .def.d_uint32 = __default \
81 #define DEF_OPT_STR(__name, __var_ofs, __default) \
83 .opt_type = OPT_STRING, \
84 .config_name = __name, \
85 .var_offset = __var_ofs, \
86 .def.d_char = __default \
89 #define DEF_OPT_SSTR(__name, __var_ofs, __default, __str_size) \
91 .opt_type = OPT_SSTRING, \
92 .config_name = __name, \
93 .var_offset = __var_ofs, \
94 .str_size = __str_size, \
95 .def.d_char = __default \
98 #define DEF_OPT_HEX(__name, __var_ofs, __array_size) \
100 .opt_type = OPT_HEX_ARRAY, \
101 .config_name = __name, \
102 .var_offset = __var_ofs, \
103 .def.array_size = __array_size \
106 #define DEF_OPT_FUNC(__name, __var_ofs, __process_fn, ...) \
108 .opt_type = OPT_FUNC, \
109 .config_name = __name, \
110 .var_offset = __var_ofs, \
111 .ops.process_fn = __process_fn, \
115 #define DEF_OPT_FUNC_X(__name, __var_ofs, __process_fn_extra, __extra, ...) \
117 .opt_type = OPT_FUNC_EXTRA, \
118 .config_name = __name, \
119 .var_offset = __var_ofs, \
120 .ops.process_fn_extra = __process_fn_extra, \
121 .def.d_extra = __extra, \
125 #define DEF_OPT_SAVE_FUNC(__fn) \
127 .opt_type = OPT_SAVE_FUNC, \
128 .ops.should_save_fn = __fn \
131 #define DEF_OPT_FIXUP_FUNC(__fn) \
133 .opt_type = OPT_FIXUP_FUNC, \
134 .ops.fixup_fn = __fn \
137 #define DEF_LAST_OPT \
139 .opt_type = OPT_UNKNOWN \
142 struct config_sections
145 const struct config_list
*config
;
148 int32_t strToIntVal(char *value
, int32_t defaultvalue
);
149 uint32_t strToUIntVal(char *value
, uint32_t defaultvalue
);
151 void fprintf_conf(FILE *f
, const char *varname
, const char *fmt
, ...) __attribute__ ((format (printf
, 3, 4)));
153 int config_list_parse(const struct config_list
*clist
, const char *token
, char *value
, void *config_data
);
154 void config_list_save_ex(FILE *f
, const struct config_list
*clist
, void *config_data
, int save_all
,
155 bool (*check_func
)(const struct config_list
*clist
, void *config_data
, const char *setting
)
157 static inline void config_list_save(FILE *f
, const struct config_list
*clist
, void *config_data
, int save_all
)
159 config_list_save_ex(f
, clist
, config_data
, save_all
, NULL
);
161 void config_list_apply_fixups(const struct config_list
*clist
, void *var
);
162 bool config_list_should_be_saved(const struct config_list
*clist
, void *var
);
163 void config_list_set_defaults(const struct config_list
*clist
, void *config_data
);
164 void config_list_free_values(const struct config_list
*clist
, void *config_data
);
165 void config_list_gc_values(const struct config_list
*clist
, void *config_data
);
167 int config_section_is_active(const struct config_sections
*sec
);
168 const struct config_sections
*config_find_section(const struct config_sections
*conf
, char *section_name
);
169 void config_sections_save(const struct config_sections
*conf
, FILE *f
, void *var
);
170 void config_sections_set_defaults(const struct config_sections
*conf
, void *var
);
171 void config_sections_free(const struct config_sections
*conf
, void *var
);
173 void config_set_value(const struct config_sections
*conf
, char *section
, const char *token
, char *value
, void *var
);
175 FILE *open_config_file(const char *conf_filename
);
176 FILE *open_config_file_or_die(const char *conf_filename
);
177 FILE *create_config_file(const char *conf_filename
);
178 bool flush_config_file(FILE *f
, const char *conf_filename
);