Better support configurations

This commit is contained in:
Kamil Trzcinski
2022-04-05 20:29:47 +02:00
parent 7f14b60ba3
commit 65c0639cc5
6 changed files with 81 additions and 23 deletions

View File

@ -2,16 +2,24 @@
#include <stdbool.h>
typedef struct option_value_s {
const char *name;
unsigned value;
} option_value_t;
typedef struct options_s {
const char *name;
void *ptr;
char *value_string;
union {
unsigned *value;
unsigned *value_uint;
unsigned *value_hex;
bool *value_bool;
float *value_float;
};
const char *format;
const char *help;
option_value_t *value_mapping;
unsigned size;
} option_t;
@ -21,8 +29,11 @@ typedef struct options_s {
__fn__; \
})
#define OPTION_FORMAT_uint "%d"
#define OPTION_FORMAT_bool "%d"
#define OPTION_FORMAT_uint "%d"
#define OPTION_FORMAT_hex "%08x"
#define OPTION_FORMAT_bool "%d"
#define OPTION_FORMAT_float "%.1f"
#define OPTION_FORMAT_string "%s"
#define DEFINE_OPTION(_section, _name, _type) \
{ \
@ -32,11 +43,20 @@ typedef struct options_s {
.size = sizeof(_section##_options._name), \
}
#define DEFINE_OPTION_PTR(_section, _name, _format) \
#define DEFINE_OPTION_VALUES(_section, _name, _value_mapping) \
{ \
.name = #_section "-" #_name, \
.ptr = _section##_options._name, \
.format = _format, \
.value_hex = &_section##_options._name, \
.format = OPTION_FORMAT_hex, \
.value_mapping = _value_mapping, \
.size = sizeof(_section##_options._name), \
}
#define DEFINE_OPTION_PTR(_section, _name, _type) \
{ \
.name = #_section "-" #_name, \
.value_##_type = _section##_options._name, \
.format = OPTION_FORMAT_##_type, \
.size = sizeof(_section##_options._name), \
}