mirror of https://github.com/nirenjan/libx52.git
55 lines
1.3 KiB
C
55 lines
1.3 KiB
C
/*
|
|
* Saitek X52 Pro MFD & LED driver - Configuration parser
|
|
*
|
|
* Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include "pinelog.h"
|
|
#include "x52d_config.h"
|
|
#include "x52d_const.h"
|
|
|
|
static struct x52d_config x52d_config;
|
|
|
|
void x52d_config_load(const char *cfg_file)
|
|
{
|
|
int rc;
|
|
|
|
if (cfg_file == NULL) {
|
|
cfg_file = X52D_SYS_CFG_FILE;
|
|
}
|
|
|
|
rc = x52d_config_set_defaults(&x52d_config);
|
|
if (rc != 0) {
|
|
PINELOG_FATAL(_("Error %d setting configuration defaults: %s"),
|
|
rc, strerror(rc));
|
|
}
|
|
|
|
rc = x52d_config_load_file(&x52d_config, cfg_file);
|
|
if (rc != 0) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// Apply overrides
|
|
rc = x52d_config_apply_overrides(&x52d_config);
|
|
x52d_config_clear_overrides();
|
|
if (rc != 0) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
#define CFG(section, key, name, parser, def) \
|
|
static void x52d_cfg_set_ ## section ## _ ## key(typeof(x52d_config . name) param) \
|
|
{ \
|
|
PINELOG_TRACE("Calling set " #section ":" #key); \
|
|
}
|
|
#include "x52d_config.def"
|
|
|
|
void x52d_config_apply(void)
|
|
{
|
|
#define CFG(section, key, name, parser, def) x52d_cfg_set_ ## section ## _ ## key(x52d_config . name);
|
|
#include "x52d_config.def"
|
|
}
|