conf: add "file" callback

The "file" callback is used to parse configuration files. If it is not
given, the string is parsed via "parse".

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-10-23 11:41:34 +02:00
parent 8a4ddda742
commit 6aeae8be93
3 changed files with 22 additions and 7 deletions

View File

@ -338,6 +338,18 @@ static int parse_kv_pair(struct conf_option *opts, size_t len,
else
continue;
/* ignore if already set by command-line arguments */
if (opt->flags & CONF_LOCKED)
return 0;
if (opt->file) {
ret = opt->file(opt, set, value);
if (ret)
return ret;
opt->flags |= CONF_DONE;
return 0;
}
if (opt->type->flags & CONF_HAS_ARG && !value) {
log_error("config option '%s' requires an argument",
key);
@ -348,10 +360,6 @@ static int parse_kv_pair(struct conf_option *opts, size_t len,
return -EFAULT;
}
/* ignore if already set by command-line arguments */
if (opt->flags & CONF_LOCKED)
return 0;
if (opt->type->parse) {
ret = opt->type->parse(opt, set, value);
if (ret)

View File

@ -161,12 +161,13 @@ struct conf_option {
int (*aftercheck) (struct conf_option *opt, int argc,
char **argv, int idx);
int (*copy) (struct conf_option *opt, const struct conf_option *src);
int (*file) (struct conf_option *opt, bool on, const char *arg);
void *mem;
void *def;
};
#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _copy, _mem, _def) \
{ _flags, _short, "no-" _long, _type, _aftercheck, _copy, _mem, _def }
#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _copy, _file, _mem, _def) \
{ _flags, _short, "no-" _long, _type, _aftercheck, _copy, _file, _mem, _def }
#define CONF_OPTION_BOOL(_short, _long, _aftercheck, _copy, _mem, _def) \
CONF_OPTION(0, \
_short, \
@ -174,6 +175,7 @@ struct conf_option {
&conf_bool, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
_def)
#define CONF_OPTION_INT(_short, _long, _aftercheck, _copy, _mem, _def) \
@ -183,6 +185,7 @@ struct conf_option {
&conf_int, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
(void*)(unsigned long)_def)
#define CONF_OPTION_UINT(_short, _long, _aftercheck, _copy, _mem, _def) \
@ -192,6 +195,7 @@ struct conf_option {
&conf_uint, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
(void*)(unsigned long)_def)
#define CONF_OPTION_STRING(_short, _long, _aftercheck, _copy, _mem, _def) \
@ -201,6 +205,7 @@ struct conf_option {
&conf_string, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
_def)
#define CONF_OPTION_STRING_LIST(_short, _long, _aftercheck, _copy, _mem, _def) \
@ -210,6 +215,7 @@ struct conf_option {
&conf_string_list, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
_def)
#define CONF_OPTION_GRAB(_short, _long, _aftercheck, _copy, _mem, _def) \
@ -219,6 +225,7 @@ struct conf_option {
&conf_grab, \
_aftercheck, \
_copy, \
NULL, \
_mem, \
_def)

View File

@ -357,7 +357,7 @@ int kmscon_conf_new(struct conf_ctx **out)
CONF_OPTION_BOOL(0, "silent", NULL, NULL, &conf->silent, false),
/* Seat Options */
CONF_OPTION(0, 0, "vt", &conf_vt, NULL, NULL, &conf->vt, NULL),
CONF_OPTION(0, 0, "vt", &conf_vt, NULL, NULL, NULL, &conf->vt, NULL),
CONF_OPTION_BOOL('s', "switchvt", NULL, NULL, &conf->switchvt, false),
CONF_OPTION_STRING_LIST(0, "seats", aftercheck_seats, copy_seats, &conf->seats, def_seats),