| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "cleanup-util.h" |
| 5 |
|
| 6 |
/* Argument list for parsers of specific configuration settings. */ |
| 7 |
#define CONFIG_PARSER_ARGUMENTS \ |
| 8 |
const char *unit, \ |
| 9 |
const char *filename, \ |
| 10 |
unsigned line, \ |
| 11 |
const char *section, \ |
| 12 |
unsigned section_line, \ |
| 13 |
const char *lvalue, \ |
| 14 |
int ltype, \ |
| 15 |
const char *rvalue, \ |
| 16 |
void *data, \ |
| 17 |
void *userdata |
| 18 |
|
| 19 |
/* Prototype for a parser for a specific configuration setting */ |
| 20 |
typedef int (*ConfigParserCallback)(CONFIG_PARSER_ARGUMENTS); |
| 21 |
|
| 22 |
/* A macro declaring a function prototype, following the typedef above, simply because it's so cumbersomely long |
| 23 |
* otherwise. (And current emacs gets irritatingly slow when editing files that contain lots of very long function |
| 24 |
* prototypes on the same screen…) */ |
| 25 |
#define CONFIG_PARSER_PROTOTYPE(name) int name(CONFIG_PARSER_ARGUMENTS) |
| 26 |
|
| 27 |
typedef struct ConfigSection { |
| 28 |
unsigned line; |
| 29 |
bool invalid; |
| 30 |
char filename[]; |
| 31 |
} ConfigSection; |
| 32 |
|
| 33 |
#define DEFINE_SECTION_CLEANUP_FUNCTIONS(type, free_func) \ |
| 34 |
static inline type* free_func##_or_set_invalid(type *p) { \ |
| 35 |
assert(p); \ |
| 36 |
\ |
| 37 |
if (p->section) \ |
| 38 |
p->section->invalid = true; \ |
| 39 |
else \ |
| 40 |
free_func(p); \ |
| 41 |
return NULL; \ |
| 42 |
} \ |
| 43 |
DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \ |
| 44 |
DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid); |