Freeciv21
Develop your civilization from humble roots to a global empire
registry_ini.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // utility
16 #include "support.h" // bool type and fc__attribute
17 
18 #include <QString>
19 #include <QVector>
20 
21 #include <stddef.h>
22 
23 class QIODevice;
24 
25 // Opaque types.
26 struct section_file;
27 struct section;
28 struct entry;
29 
30 // Typedefs.
31 typedef const void *secfile_data_t;
32 
33 typedef bool (*secfile_enum_is_valid_fn_t)(int enumerator);
34 typedef const char *(*secfile_enum_name_fn_t)(int enumerator);
35 typedef int (*secfile_enum_by_name_fn_t)(const char *enum_name,
36  int (*strcmp_fn)(const char *,
37  const char *));
38 typedef int (*secfile_enum_iter_fn_t)();
39 typedef int (*secfile_enum_next_fn_t)(int enumerator);
40 typedef const char *(*secfile_enum_name_data_fn_t)(secfile_data_t data,
41  int enumerator);
42 
43 // Create a 'struct section_list' and related functions:
44 #define SPECLIST_TAG section
45 #include "speclist.h"
46 #define section_list_iterate(seclist, psection) \
47  TYPED_LIST_ITERATE(struct section, seclist, psection)
48 #define section_list_iterate_end LIST_ITERATE_END
49 #define section_list_iterate_rev(seclist, psection) \
50  TYPED_LIST_ITERATE_REV(struct section, seclist, psection)
51 #define section_list_iterate_rev_end LIST_ITERATE_REV_END
52 
53 // Create a 'struct entry_list' and related functions:
54 #define SPECLIST_TAG entry
55 #include "speclist.h"
56 #define entry_list_iterate(entlist, pentry) \
57  TYPED_LIST_ITERATE(struct entry, entlist, pentry)
58 #define entry_list_iterate_end LIST_ITERATE_END
59 
60 // Main functions.
61 struct section_file *secfile_load_section(const QString &filename,
62  const QString &section,
63  bool allow_duplicates);
64 struct section_file *secfile_from_stream(QIODevice *stream,
65  bool allow_duplicates);
66 
67 bool secfile_save(const struct section_file *secfile, QString filename);
68 void secfile_check_unused(const struct section_file *secfile);
69 const char *secfile_name(const struct section_file *secfile);
70 
72 
73 // Insertion functions.
75  bool value, const char *comment,
76  bool allow_replace, const char *path,
77  ...)
78  fc__attribute((__format__(__printf__, 5, 6)));
79 #define secfile_insert_bool(secfile, value, path, ...) \
80  secfile_insert_bool_full(secfile, value, nullptr, false, path, \
81  ##__VA_ARGS__)
82 #define secfile_insert_bool_comment(secfile, value, comment, path, ...) \
83  secfile_insert_bool_full(secfile, value, comment, false, path, \
84  ##__VA_ARGS__)
85 #define secfile_replace_bool(secfile, value, path, ...) \
86  secfile_insert_bool_full(secfile, value, nullptr, true, path, \
87  ##__VA_ARGS__)
88 #define secfile_replace_bool_comment(secfile, value, comment, path, ...) \
89  secfile_insert_bool_full(secfile, value, comment, true, path, \
90  ##__VA_ARGS__)
92  const bool *values, size_t dim,
93  const char *comment, bool allow_replace,
94  const char *path, ...)
95  fc__attribute((__format__(__printf__, 6, 7)));
96 #define secfile_insert_bool_vec(secfile, values, dim, path, ...) \
97  secfile_insert_bool_vec_full(secfile, values, dim, nullptr, false, path, \
98  ##__VA_ARGS__)
99 #define secfile_insert_bool_vec_comment(secfile, values, dim, comment, \
100  path, ...) \
101  secfile_insert_bool_vec_full(secfile, values, dim, comment, false, path, \
102  ##__VA_ARGS__)
103 #define secfile_replace_bool_vec(secfile, values, dim, path, ...) \
104  secfile_insert_bool_vec_full(secfile, values, dim, nullptr, true, path, \
105  ##__VA_ARGS__)
106 #define secfile_replace_bool_vec_comment(secfile, values, dim, comment, \
107  path, ...) \
108  secfile_insert_bool_vec_full(secfile, values, comment, true, path, \
109  ##__VA_ARGS__)
110 
112  int value, const char *comment,
113  bool allow_replace, const char *path,
114  ...)
115  fc__attribute((__format__(__printf__, 5, 6)));
116 #define secfile_insert_int(secfile, value, path, ...) \
117  secfile_insert_int_full(secfile, value, nullptr, false, path, \
118  ##__VA_ARGS__)
119 #define secfile_insert_int_comment(secfile, value, comment, path, ...) \
120  secfile_insert_int_full(secfile, value, comment, false, path, \
121  ##__VA_ARGS__)
122 #define secfile_replace_int(secfile, value, path, ...) \
123  secfile_insert_int_full(secfile, value, nullptr, true, path, ##__VA_ARGS__)
124 #define secfile_replace_int_comment(secfile, value, comment, path, ...) \
125  secfile_insert_int_full(secfile, value, comment, true, path, ##__VA_ARGS__)
127  const int *values, size_t dim,
128  const char *comment, bool allow_replace,
129  const char *path, ...)
130  fc__attribute((__format__(__printf__, 6, 7)));
131 #define secfile_insert_int_vec(secfile, values, dim, path, ...) \
132  secfile_insert_int_vec_full(secfile, values, dim, nullptr, false, path, \
133  ##__VA_ARGS__)
134 #define secfile_insert_int_vec_comment(secfile, values, dim, comment, path, \
135  ...) \
136  secfile_insert_int_vec_full(secfile, values, dim, comment, false, path, \
137  ##__VA_ARGS__)
138 #define secfile_replace_int_vec(secfile, values, dim, path, ...) \
139  secfile_insert_int_vec_full(secfile, values, dim, nullptr, true, path, \
140  ##__VA_ARGS__)
141 #define secfile_replace_int_vec_comment(secfile, values, dim, comment, \
142  path, ...) \
143  secfile_insert_int_vec_full(secfile, values, dim, comment, true, path, \
144  ##__VA_ARGS__)
145 
147  float value, const char *comment,
148  bool allow_replace, const char *path,
149  ...)
150  fc__attribute((__format__(__printf__, 5, 6)));
151 #define secfile_insert_float(secfile, value, path, ...) \
152  secfile_insert_float_full(secfile, value, nullptr, false, path, \
153  ##__VA_ARGS__)
154 
156  const char *filename);
157 
159  const char *comment);
160 
162  const char *str, const char *comment,
163  bool allow_replace, bool no_escape,
164  enum entry_special_type stype,
165  const char *path, ...)
166  fc__attribute((__format__(__printf__, 7, 8)));
167 #define secfile_insert_str(secfile, string, path, ...) \
168  secfile_insert_str_full(secfile, string, nullptr, false, false, \
169  EST_NORMAL, path, ##__VA_ARGS__)
170 #define secfile_insert_str_noescape(secfile, string, path, ...) \
171  secfile_insert_str_full(secfile, string, nullptr, false, true, \
172  EST_NORMAL, path, ##__VA_ARGS__)
173 #define secfile_insert_str_comment(secfile, string, comment, path, ...) \
174  secfile_insert_str_full(secfile, string, comment, false, true, \
175  EST_NORMAL, path, ##__VA_ARGS__)
176 #define secfile_insert_str_noescape_comment(secfile, string, comment, path, \
177  ...) \
178  secfile_insert_str_full(secfile, string, comment, false, true, \
179  EST_NORMAL, path, ##__VA_ARGS__)
180 #define secfile_replace_str(secfile, string, path, ...) \
181  secfile_insert_str_full(secfile, string, nullptr, true, false, \
182  EST_NORMAL, path, ##__VA_ARGS__)
183 #define secfile_replace_str_noescape(secfile, string, path, ...) \
184  secfile_insert_str_full(secfile, string, nullptr, true, true, EST_NORMAL, \
185  path, ##__VA_ARGS__)
186 #define secfile_replace_str_comment(secfile, string, comment, path, ...) \
187  secfile_insert_str_full(secfile, string, comment, true, true, EST_NORMAL, \
188  path, ##__VA_ARGS__)
189 #define secfile_replace_str_noescape_comment(secfile, string, comment, \
190  path, ...) \
191  secfile_insert_str_full(secfile, string, comment, true, true, EST_NORMAL, \
192  path, ##__VA_ARGS__)
194  const char *const *strings, size_t dim,
195  const char *comment, bool allow_replace,
196  bool no_escape, const char *path, ...)
197  fc__attribute((__format__(__printf__, 7, 8)));
199  const QVector<QString> &strings,
200  size_t dim, const char *comment,
201  bool allow_replace, bool no_escape,
202  const char *path, ...)
203  fc__attribute((__format__(__printf__, 7, 8)));
204 #define secfile_insert_str_vec(secfile, strings, dim, path, ...) \
205  secfile_insert_str_vec_full(secfile, strings, dim, nullptr, false, false, \
206  path, ##__VA_ARGS__)
207 #define secfile_insert_str_vec_noescape(secfile, strings, dim, path, ...) \
208  secfile_insert_str_vec_full(secfile, strings, dim, nullptr, false, true, \
209  path, ##__VA_ARGS__)
210 #define secfile_insert_str_vec_comment(secfile, strings, dim, comment, \
211  path, ...) \
212  secfile_insert_str_vec_full(secfile, strings, dim, comment, false, true, \
213  path, ##__VA_ARGS__)
214 #define secfile_insert_str_vec_noescape_comment(secfile, strings, dim, \
215  comment, path, ...) \
216  secfile_insert_str_vec_full(secfile, strings, dim, comment, false, true, \
217  path, ##__VA_ARGS__)
218 #define secfile_replace_str_vec(secfile, strings, dim, path, ...) \
219  secfile_insert_str_vec_full(secfile, strings, dim, nullptr, true, false, \
220  path, ##__VA_ARGS__)
221 #define secfile_replace_str_vec_noescape(secfile, strings, dim, path, ...) \
222  secfile_insert_str_vec_full(secfile, strings, dim, nullptr, true, true, \
223  path, ##__VA_ARGS__)
224 #define secfile_replace_str_vec_comment(secfile, strings, dim, comment, \
225  path, ...) \
226  secfile_insert_str_vec_full(secfile, strings, dim, comment, true, true, \
227  path, ##__VA_ARGS__)
228 #define secfile_replace_str_vec_noescape_comment(secfile, strings, dim, \
229  comment, path, ...) \
230  secfile_insert_str_vec_full(secfile, strings, dim, comment, true, true, \
231  path, ##__VA_ARGS__)
232 
234  struct section_file *secfile, int enumerator,
235  secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace,
236  const char *path, ...) fc__attribute((__format__(__printf__, 6, 7)));
238  struct section_file *secfile, int bitwise_val,
241  const char *comment, bool allow_replace, const char *path, ...)
242  fc__attribute((__format__(__printf__, 9, 10)));
243 #define secfile_insert_enum_full(secfile, enumerator, specenum_type, \
244  comment, allow_replace, path, ...) \
245  (specenum_type##_is_bitwise() \
246  ? secfile_insert_bitwise_enum_full( \
247  secfile, enumerator, \
248  (secfile_enum_name_fn_t) specenum_type##_name, \
249  (secfile_enum_iter_fn_t) specenum_type##_begin, \
250  (secfile_enum_iter_fn_t) specenum_type##_end, \
251  (secfile_enum_next_fn_t) specenum_type##_next, comment, \
252  allow_replace, path, ##__VA_ARGS__) \
253  : secfile_insert_plain_enum_full( \
254  secfile, enumerator, \
255  (secfile_enum_name_fn_t) specenum_type##_name, comment, \
256  allow_replace, path, ##__VA_ARGS__))
257 #define secfile_insert_enum(secfile, enumerator, specenum_type, path, ...) \
258  secfile_insert_enum_full(secfile, enumerator, specenum_type, nullptr, \
259  false, path, ##__VA_ARGS__)
260 #define secfile_insert_enum_comment(secfile, enumerator, specenum_type, \
261  comment, path, ...) \
262  secfile_insert_enum_full(secfile, enumerator, specenum_type, comment, \
263  false, path, ##__VA_ARGS__)
264 #define secfile_replace_enum(secfile, enumerator, specenum_type, path, ...) \
265  secfile_insert_enum_full(secfile, enumerator, specenum_type, nullptr, \
266  true, path, ##__VA_ARGS__)
267 #define secfile_replace_enum_comment(secfile, enumerator, specenum_type, \
268  comment, path, ...) \
269  secfile_insert_enum_full(secfile, enumerator, specenum_type, comment, \
270  true, path, ##__VA_ARGS__)
272  struct section_file *secfile, const int *enumurators, size_t dim,
273  secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace,
274  const char *path, ...) fc__attribute((__format__(__printf__, 7, 8)));
276  struct section_file *secfile, const int *bitwise_vals, size_t dim,
279  const char *comment, bool allow_replace, const char *path, ...)
280  fc__attribute((__format__(__printf__, 10, 11)));
281 #define secfile_insert_enum_vec_full(secfile, enumerators, dim, \
282  specenum_type, comment, allow_replace, \
283  path, ...) \
284  (specenum_type##_is_bitwise() \
285  ? secfile_insert_bitwise_enum_vec_full( \
286  secfile, (const int *) enumerators, dim, \
287  (secfile_enum_name_fn_t) specenum_type##_name, \
288  (secfile_enum_iter_fn_t) specenum_type##_begin, \
289  (secfile_enum_iter_fn_t) specenum_type##_end, \
290  (secfile_enum_next_fn_t) specenum_type##_next, comment, \
291  allow_replace, path, ##__VA_ARGS__) \
292  : secfile_insert_plain_enum_vec_full( \
293  secfile, (const int *) enumerators, dim, \
294  (secfile_enum_name_fn_t) specenum_type##_name, comment, \
295  allow_replace, path, ##__VA_ARGS__))
296 #define secfile_insert_enum_vec(secfile, enumerators, dim, specenum_type, \
297  path, ...) \
298  secfile_insert_enum_vec_full(secfile, enumerators, dim, specenum_type, \
299  nullptr, false, path, ##__VA_ARGS__)
300 #define secfile_insert_enum_vec_comment(secfile, enumerators, dim, \
301  specenum_type, comment, path, ...) \
302  secfile_insert_enum_vec_full(secfile, enumerators, dim, specenum_type, \
303  comment, false, path, ##__VA_ARGS__)
304 #define secfile_replace_enum_vec(secfile, enumerators, dim, specenum_type, \
305  path, ...) \
306  secfile_insert_enum_vec_full(secfile, enumerators, dim, specenum_type, \
307  nullptr, true, path, ##__VA_ARGS__)
308 #define secfile_replace_enum_vec_comment(secfile, enumerators, dim, \
309  specenum_type, comment, path, ...) \
310  secfile_insert_enum_vec_full(secfile, enumerators, dim, specenum_type, \
311  comment, true, path, ##__VA_ARGS__)
312 
314  struct section_file *secfile, int value, bool bitwise,
316  const char *comment, bool allow_replace, const char *path, ...)
317  fc__attribute((__format__(__printf__, 8, 9)));
318 #define secfile_insert_enum_data(secfile, value, bitwise, name_fn, data, \
319  path, ...) \
320  secfile_insert_enum_data_full(secfile, value, bitwise, name_fn, data, \
321  nullptr, false, path, ##__VA_ARGS__)
322 #define secfile_insert_enum_data_comment(secfile, value, bitwise, name_fn, \
323  data, path, ...) \
324  secfile_insert_enum_data_full(secfile, value, bitwise, name_fn, data, \
325  comment, false, path, ##__VA_ARGS__)
326 #define secfile_replace_enum_data(secfile, value, bitwise, name_fn, data, \
327  path, ...) \
328  secfile_insert_enum_data_full(secfile, value, bitwise, name_fn, data, \
329  nullptr, true, path, ##__VA_ARGS__)
330 #define secfile_replace_enum_data_comment(secfile, value, bitwise, name_fn, \
331  data, path, ...) \
332  secfile_insert_enum_data_full(secfile, value, bitwise, name_fn, data, \
333  comment, true, path, ##__VA_ARGS__)
335  struct section_file *secfile, const int *values, size_t dim,
336  bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data,
337  const char *comment, bool allow_replace, const char *path, ...)
338  fc__attribute((__format__(__printf__, 9, 10)));
339 #define secfile_insert_enum_vec_data(secfile, values, dim, bitwise, \
340  name_fn, data, path, ...) \
341  secfile_insert_enum_vec_data_full(secfile, values, dim, bitwise, name_fn, \
342  data, nullptr, false, path, \
343  ##__VA_ARGS__)
344 #define secfile_insert_enum_vec_data_comment(secfile, values, dim, bitwise, \
345  name_fn, data, path, ...) \
346  secfile_insert_enum_vec_data_full(secfile, values, dim, bitwise, name_fn, \
347  data, comment, false, path, \
348  ##__VA_ARGS__)
349 #define secfile_replace_enum_vec_data(secfile, values, dim, bitwise, \
350  name_fn, data, path, ...) \
351  secfile_insert_enum_vec_data_full(secfile, values, dim, bitwise, name_fn, \
352  data, nullptr, true, path, \
353  ##__VA_ARGS__)
354 #define secfile_replace_enum_vec_data_comment( \
355  secfile, values, dim, bitwise, name_fn, data, path, ...) \
356  secfile_insert_enum_vec_data_full(secfile, values, dim, bitwise, name_fn, \
357  data, comment, true, path, \
358  ##__VA_ARGS__)
359 
361  const char *filename,
362  const char *path, ...)
363  fc__attribute((__format__(__printf__, 3, 4)));
364 
365 // Deletion function.
366 bool secfile_entry_delete(struct section_file *secfile, const char *path,
367  ...) fc__attribute((__format__(__printf__, 2, 3)));
368 
369 // Lookup functions.
370 struct entry *secfile_entry_by_path(const struct section_file *secfile,
371  const char *path);
372 struct entry *secfile_entry_lookup(const struct section_file *secfile,
373  const char *path, ...)
374  fc__attribute((__format__(__printf__, 2, 3)));
375 
376 bool secfile_lookup_bool(const struct section_file *secfile, bool *bval,
377  const char *path, ...) fc__warn_unused_result
378  fc__attribute((__format__(__printf__, 3, 4)));
379 bool secfile_lookup_bool_default(const struct section_file *secfile,
380  bool def, const char *path,
382  fc__attribute((__format__(__printf__, 3, 4)));
383 
384 bool secfile_lookup_int(const struct section_file *secfile, int *ival,
385  const char *path, ...) fc__warn_unused_result
386  fc__attribute((__format__(__printf__, 3, 4)));
387 int secfile_lookup_int_default(const struct section_file *secfile, int def,
388  const char *path, ...) fc__warn_unused_result
389  fc__attribute((__format__(__printf__, 3, 4)));
391  int defval, int minval, int maxval,
392  const char *path,
394  fc__attribute((__format__(__printf__, 5, 6)));
395 int *secfile_lookup_int_vec(const struct section_file *secfile, size_t *dim,
396  const char *path, ...) fc__warn_unused_result
397  fc__attribute((__format__(__printf__, 3, 4)));
398 
399 const char *secfile_lookup_str(const struct section_file *secfile,
400  const char *path, ...) fc__warn_unused_result
401  fc__attribute((__format__(__printf__, 2, 3)));
402 const char *secfile_lookup_str_default(const struct section_file *secfile,
403  const char *def, const char *path,
405  fc__attribute((__format__(__printf__, 3, 4)));
406 const char **secfile_lookup_str_vec(const struct section_file *secfile,
407  size_t *dim, const char *path, ...)
408  fc__attribute((__format__(__printf__, 3, 4)));
409 
410 bool secfile_lookup_plain_enum_full(const struct section_file *secfile,
411  int *penumerator,
412  secfile_enum_is_valid_fn_t is_valid_fn,
413  secfile_enum_by_name_fn_t by_name_fn,
414  const char *path,
416  fc__attribute((__format__(__printf__, 5, 6)));
418  int *penumerator,
419  secfile_enum_is_valid_fn_t is_valid_fn,
420  secfile_enum_by_name_fn_t by_name_fn,
421  const char *path,
423  fc__attribute((__format__(__printf__, 5, 6)));
424 #define secfile_lookup_enum(secfile, enumerator, specenum_type, path, ...) \
425  (specenum_type##_is_bitwise() \
426  ? secfile_lookup_bitwise_enum_full( \
427  secfile, FC_ENUM_PTR(enumerator), \
428  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
429  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
430  ##__VA_ARGS__) \
431  : secfile_lookup_plain_enum_full( \
432  secfile, FC_ENUM_PTR(enumerator), \
433  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
434  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
435  ##__VA_ARGS__))
437  const struct section_file *secfile, int defval,
438  secfile_enum_is_valid_fn_t is_valid_fn,
439  secfile_enum_by_name_fn_t by_name_fn, const char *path,
441  fc__attribute((__format__(__printf__, 5, 6)));
443  const struct section_file *secfile, int defval,
444  secfile_enum_is_valid_fn_t is_valid_fn,
445  secfile_enum_by_name_fn_t by_name_fn, const char *path,
447  fc__attribute((__format__(__printf__, 5, 6)));
448 #define secfile_lookup_enum_default(secfile, defval, specenum_type, path, \
449  ...) \
450  (specenum_type##_is_bitwise() \
451  ? secfile_lookup_bitwise_enum_default_full( \
452  secfile, defval, \
453  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
454  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
455  ##__VA_ARGS__) \
456  : secfile_lookup_plain_enum_default_full( \
457  secfile, defval, \
458  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
459  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
460  ##__VA_ARGS__))
462  const struct section_file *secfile, size_t *dim,
463  secfile_enum_is_valid_fn_t is_valid_fn,
464  secfile_enum_by_name_fn_t by_name_fn, const char *path,
466  fc__attribute((__format__(__printf__, 5, 6)));
468  const struct section_file *secfile, size_t *dim,
469  secfile_enum_is_valid_fn_t is_valid_fn,
470  secfile_enum_by_name_fn_t by_name_fn, const char *path,
472  fc__attribute((__format__(__printf__, 5, 6)));
473 #define secfile_lookup_enum_vec(secfile, dim, specenum_type, path, ...) \
474  (specenum_type##_is_bitwise() \
475  ? (enum specenum_type *) secfile_lookup_bitwise_enum_vec_full( \
476  secfile, dim, \
477  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
478  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
479  ##__VA_ARGS__) \
480  : (enum specenum_type *) secfile_lookup_plain_enum_vec_full( \
481  secfile, dim, \
482  (secfile_enum_is_valid_fn_t) specenum_type##_is_valid, \
483  (secfile_enum_by_name_fn_t) specenum_type##_by_name, path, \
484  ##__VA_ARGS__))
485 
486 bool secfile_lookup_enum_data(const struct section_file *secfile,
487  int *pvalue, bool bitwise,
489  secfile_data_t data, const char *path,
491  fc__attribute((__format__(__printf__, 6, 7)));
493  int defval, bool bitwise,
495  secfile_data_t data, const char *path,
497  fc__attribute((__format__(__printf__, 6, 7)));
498 
499 // Sections functions.
500 struct section *secfile_section_by_name(const struct section_file *secfile,
501  const QString &section_name);
502 struct section *secfile_section_lookup(const struct section_file *secfile,
503  const char *path, ...)
504  fc__attribute((__format__(__printf__, 2, 3)));
505 const struct section_list *
506 secfile_sections(const struct section_file *secfile);
507 struct section_list *
508 secfile_sections_by_name_prefix(const struct section_file *secfile,
509  const char *prefix);
510 struct section *secfile_section_new(struct section_file *secfile,
511  const QString &section_name);
512 
513 // Independant section functions.
514 void section_destroy(struct section *psection);
515 void section_clear_all(struct section *psection);
516 
517 // Entry functions.
518 const struct entry_list *section_entries(const struct section *psection);
519 struct entry *section_entry_by_name(const struct section *psection,
520  const QString &entry_name);
522  const QString &entry_name, int value);
524  const QString &entry_name, bool value);
526  const QString &entry_name,
527  float value);
529  const QString &entry_name,
530  const QString &value, bool escaped);
531 
532 // Independant entry functions.
540 };
541 
542 void entry_destroy(struct entry *pentry);
543 
544 struct section *entry_section(const struct entry *pentry);
545 enum entry_type entry_type_get(const struct entry *pentry);
546 int entry_path(const struct entry *pentry, char *buf, size_t buf_len);
547 
548 const char *entry_name(const struct entry *pentry);
549 bool entry_set_name(struct entry *pentry, const char *entry_name);
550 
551 const char *entry_comment(const struct entry *pentry);
552 void entry_set_comment(struct entry *pentry, const QString &comment);
553 
554 bool entry_int_get(const struct entry *pentry, int *value);
555 bool entry_int_set(struct entry *pentry, int value);
556 
557 bool entry_bool_get(const struct entry *pentry, bool *value);
558 bool entry_bool_set(struct entry *pentry, bool value);
559 
560 bool entry_float_get(const struct entry *pentry, float *value);
561 bool entry_float_set(struct entry *pentry, float value);
562 
563 bool entry_str_get(const struct entry *pentry, const char **value);
564 bool entry_str_set(struct entry *pentry, const char *value);
565 bool entry_str_set_gt_marking(struct entry *pentry, bool gt_marking);
Definition: shared.h:24
const char * enum_name
Definition: events.cpp:63
const char * section_name(const struct section *psection)
Returns the section name.
bool secfile_save(const struct section_file *secfile, QString filename)
Save the previously filled in section_file to disk.
bool int secfile_lookup_enum_default_data(const struct section_file *secfile, int defval, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct entry bool bool bool int int int const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
const char * entry_comment(const struct entry *pentry)
Returns the comment associated to this entry.
struct entry bool bool bool int int int const char const char const char bool secfile_lookup_plain_enum_full(const struct section_file *secfile, int *penumerator, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct section * secfile_section_lookup(const struct section_file *secfile, const char *path,...) fc__attribute((__format__(__printf__
bool entry_bool_get(const struct entry *pentry, bool *value)
Gets an boolean value.
void section_destroy(struct section *psection)
Remove this section from the secfile.
struct section * entry_section(const struct entry *pentry)
Returns the parent section of this entry.
void secfile_check_unused(const struct section_file *secfile)
Print log messages for any entries in the file which have not been looked up – ie,...
int entry_path(const struct entry *pentry, char *buf, size_t buf_len)
Build the entry path.
size_t size_t secfile_insert_bitwise_enum_vec_full(struct section_file *secfile, const int *bitwise_vals, size_t dim, secfile_enum_name_fn_t name_fn, secfile_enum_iter_fn_t begin_fn, secfile_enum_iter_fn_t end_fn, secfile_enum_next_fn_t next_fn, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct entry bool secfile_lookup_bool(const struct section_file *secfile, bool *bval, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct entry * secfile_insert_int_full(struct section_file *secfile, int value, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct section_file * secfile_from_stream(QIODevice *stream, bool allow_duplicates)
Create a section file from a stream.
entry_type
Definition: registry_ini.h:533
@ ENTRY_FILEREFERENCE
Definition: registry_ini.h:538
@ ENTRY_INT
Definition: registry_ini.h:535
@ ENTRY_FLOAT
Definition: registry_ini.h:536
@ ENTRY_STR
Definition: registry_ini.h:537
@ ENTRY_ILLEGAL
Definition: registry_ini.h:539
@ ENTRY_BOOL
Definition: registry_ini.h:534
struct entry * secfile_insert_str_full(struct section_file *secfile, const char *str, const char *comment, bool allow_replace, bool no_escape, enum entry_special_type stype, const char *path,...) fc__attribute((__format__(__printf__
struct entry * section_entry_float_new(struct section *psection, const QString &entry_name, float value)
Returns a new entry of type ENTRY_FLOAT.
size_t secfile_insert_int_vec_full(struct section_file *secfile, const int *values, size_t dim, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct entry bool bool bool secfile_lookup_int(const struct section_file *secfile, int *ival, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
const char * entry_name(const struct entry *pentry)
Returns the name of this entry.
struct entry * secfile_insert_float_full(struct section_file *secfile, float value, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
bool entry_bool_set(struct entry *pentry, bool value)
Sets an boolean value.
struct section * secfile_section_new(struct section_file *secfile, const QString &section_name)
Create a new section in the secfile.
struct entry bool bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
bool entry_float_get(const struct entry *pentry, float *value)
Gets an floating value.
int int * secfile_lookup_bitwise_enum_vec_full(const struct section_file *secfile, size_t *dim, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
size_t secfile_insert_bool_vec_full(struct section_file *secfile, const bool *values, size_t dim, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct entry * secfile_insert_filereference(struct section_file *secfile, const char *filename, const char *path,...) fc__attribute((__format__(__printf__
bool entry_str_get(const struct entry *pentry, const char **value)
Gets an string value.
int * secfile_lookup_plain_enum_vec_full(const struct section_file *secfile, size_t *dim, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct entry * section_entry_int_new(struct section *psection, const QString &entry_name, int value)
Returns a new entry of type ENTRY_INT.
bool entry_str_set_gt_marking(struct entry *pentry, bool gt_marking)
Sets if the string should get gettext marking.
struct entry * secfile_entry_lookup(const struct section_file *secfile, const char *path,...) fc__attribute((__format__(__printf__
bool(* secfile_enum_is_valid_fn_t)(int enumerator)
Definition: registry_ini.h:33
void entry_destroy(struct entry *pentry)
Entry structure destructor.
int int secfile_lookup_bitwise_enum_default_full(const struct section_file *secfile, int defval, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
void section_clear_all(struct section *psection)
Remove all entries.
const char * secfile_name(const struct section_file *secfile)
Return the filename the section file was loaded as, or "(anonymous)" if this sectionfile was created ...
bool entry_float_set(struct entry *pentry, float value)
Sets an floating value.
bool secfile_lookup_enum_data(const struct section_file *secfile, int *pvalue, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct section_file * secfile_load_section(const QString &filename, const QString &section, bool allow_duplicates)
Create a section file from a file, read only one particular section.
struct section * secfile_insert_long_comment(struct section_file *secfile, const char *comment)
Insert a long comment entry.
bool entry_int_set(struct entry *pentry, int value)
Sets an integer value.
struct entry * secfile_insert_bool_full(struct section_file *secfile, bool value, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
entry_special_type
Definition: registry_ini.h:71
@ EST_COMMENT
Definition: registry_ini.h:71
@ EST_NORMAL
Definition: registry_ini.h:71
@ EST_INCLUDE
Definition: registry_ini.h:71
struct entry bool struct entry * secfile_entry_by_path(const struct section_file *secfile, const char *path)
Returns the entry by the name or nullptr if not matched.
struct entry bool bool bool int int int * secfile_lookup_int_vec(const struct section_file *secfile, size_t *dim, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
int secfile_lookup_plain_enum_default_full(const struct section_file *secfile, int defval, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
bool entry_int_get(const struct entry *pentry, int *value)
Gets an integer value.
bool entry_set_name(struct entry *pentry, const char *entry_name)
Sets the name of the entry.
struct entry bool bool bool int int int const char const char const char ** secfile_lookup_str_vec(const struct section_file *secfile, size_t *dim, const char *path,...) fc__attribute((__format__(__printf__
struct entry bool bool bool int int int const char const char const char bool bool secfile_lookup_bitwise_enum_full(const struct section_file *secfile, int *penumerator, secfile_enum_is_valid_fn_t is_valid_fn, secfile_enum_by_name_fn_t by_name_fn, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
size_t secfile_insert_str_vec_full(struct section_file *secfile, const char *const *strings, size_t dim, const char *comment, bool allow_replace, bool no_escape, const char *path,...) fc__attribute((__format__(__printf__
size_t secfile_insert_enum_vec_data_full(struct section_file *secfile, const int *values, size_t dim, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct section * secfile_insert_include(struct section_file *secfile, const char *filename)
Insert a include entry.
struct entry bool bool bool int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
bool entry_str_set(struct entry *pentry, const char *value)
Sets an string value.
struct entry * section_entry_str_new(struct section *psection, const QString &entry_name, const QString &value, bool escaped)
Returns a new entry of type ENTRY_STR.
struct entry bool bool bool int int secfile_lookup_int_def_min_max(const struct section_file *secfile, int defval, int minval, int maxval, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct entry * section_entry_by_name(const struct section *psection, const QString &entry_name)
Returns the first entry matching the name.
int(* secfile_enum_by_name_fn_t)(const char *enum_name, int(*strcmp_fn)(const char *, const char *))
Definition: registry_ini.h:35
struct entry * secfile_insert_enum_data_full(struct section_file *secfile, int value, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
struct entry struct entry * secfile_insert_bitwise_enum_full(struct section_file *secfile, int bitwise_val, secfile_enum_name_fn_t name_fn, secfile_enum_iter_fn_t begin_fn, secfile_enum_iter_fn_t end_fn, secfile_enum_next_fn_t next_fn, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
const char *(* secfile_enum_name_fn_t)(int enumerator)
Definition: registry_ini.h:34
size_t secfile_insert_plain_enum_vec_full(struct section_file *secfile, const int *enumurators, size_t dim, secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
bool int struct section * secfile_section_by_name(const struct section_file *secfile, const QString &section_name)
Returns the first section matching the name.
struct section_list * secfile_sections_by_name_prefix(const struct section_file *secfile, const char *prefix)
Returns the list of sections which match the name prefix.
int(* secfile_enum_iter_fn_t)()
Definition: registry_ini.h:38
const struct entry_list * section_entries(const struct section *psection)
Returns a list containing all the entries.
void entry_set_comment(struct entry *pentry, const QString &comment)
Sets a comment for the entry.
struct entry bool secfile_entry_delete(struct section_file *secfile, const char *path,...) fc__attribute((__format__(__printf__
struct entry * section_entry_bool_new(struct section *psection, const QString &entry_name, bool value)
Returns a new entry of type ENTRY_BOOL.
const char *(* secfile_enum_name_data_fn_t)(secfile_data_t data, int enumerator)
Definition: registry_ini.h:40
struct section const struct section_list * secfile_sections(const struct section_file *secfile)
Returns the list of sections.
int(* secfile_enum_next_fn_t)(int enumerator)
Definition: registry_ini.h:39
struct entry bool bool bool int int int const char const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...) fc__warn_unused_result fc__attribute((__format__(__printf__
struct entry * secfile_insert_plain_enum_full(struct section_file *secfile, int enumerator, secfile_enum_name_fn_t name_fn, const char *comment, bool allow_replace, const char *path,...) fc__attribute((__format__(__printf__
const void * secfile_data_t
Definition: registry_ini.h:28
enum entry_type entry_type_get(const struct entry *pentry)
Returns the type of this entry or ENTRY_ILLEGAL or error.
struct section * psection
bool escaped
bool value
char * comment
bool allow_duplicates
Definition: section_file.h:45
struct section_file * secfile
Definition: section_file.h:29
int fc__attribute((nonnull(1, 3)))
#define fc__warn_unused_result
Definition: support.h:41