conf: make important symbols global
In order to make the conf subsystem more open we need to make all important symbols visible so others can include them. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
c52df82033
commit
09e2c17336
71
src/conf.c
71
src/conf.c
@ -42,37 +42,9 @@
|
|||||||
|
|
||||||
#define LOG_SUBSYSTEM "config"
|
#define LOG_SUBSYSTEM "config"
|
||||||
|
|
||||||
struct conf_type;
|
|
||||||
struct conf_option;
|
|
||||||
|
|
||||||
struct conf_obj conf_global;
|
struct conf_obj conf_global;
|
||||||
static char *def_argv[] = { NULL, "-i", NULL };
|
static char *def_argv[] = { NULL, "-i", NULL };
|
||||||
|
|
||||||
/* config option flags */
|
|
||||||
#define CONF_DONE 0x0001
|
|
||||||
#define CONF_LOCKED 0x0002
|
|
||||||
|
|
||||||
/* config type flags */
|
|
||||||
#define CONF_HAS_ARG 0x0001
|
|
||||||
|
|
||||||
struct conf_type {
|
|
||||||
unsigned int flags;
|
|
||||||
int (*parse) (struct conf_option *opt, bool on, const char *arg);
|
|
||||||
void (*free) (struct conf_option *opt);
|
|
||||||
void (*set_default) (struct conf_option *opt);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct conf_option {
|
|
||||||
unsigned int flags;
|
|
||||||
char short_name;
|
|
||||||
const char *long_name;
|
|
||||||
const struct conf_type *type;
|
|
||||||
int (*aftercheck) (struct conf_option *opt, int argc,
|
|
||||||
char **argv, int idx);
|
|
||||||
void *mem;
|
|
||||||
void *def;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void print_help()
|
static void print_help()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -136,24 +108,24 @@ static void print_help()
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_value(struct conf_option *opt)
|
void conf_free_value(struct conf_option *opt)
|
||||||
{
|
{
|
||||||
if (*(void**)opt->mem != opt->def)
|
if (*(void**)opt->mem != opt->def)
|
||||||
free(*(void**)opt->mem);
|
free(*(void**)opt->mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_bool(struct conf_option *opt, bool on, const char *arg)
|
int conf_parse_bool(struct conf_option *opt, bool on, const char *arg)
|
||||||
{
|
{
|
||||||
*(bool*)opt->mem = on;
|
*(bool*)opt->mem = on;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void default_bool(struct conf_option *opt)
|
void conf_default_bool(struct conf_option *opt)
|
||||||
{
|
{
|
||||||
*(bool*)opt->mem = (bool)opt->def;
|
*(bool*)opt->mem = (bool)opt->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_string(struct conf_option *opt, bool on, const char *arg)
|
int conf_parse_string(struct conf_option *opt, bool on, const char *arg)
|
||||||
{
|
{
|
||||||
char *val = strdup(arg);
|
char *val = strdup(arg);
|
||||||
if (!val)
|
if (!val)
|
||||||
@ -164,44 +136,25 @@ static int parse_string(struct conf_option *opt, bool on, const char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void default_string(struct conf_option *opt)
|
void conf_default_string(struct conf_option *opt)
|
||||||
{
|
{
|
||||||
*(void**)opt->mem = opt->def;
|
*(void**)opt->mem = opt->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct conf_type conf_bool = {
|
const struct conf_type conf_bool = {
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.parse = parse_bool,
|
.parse = conf_parse_bool,
|
||||||
.free = NULL,
|
.free = NULL,
|
||||||
.set_default = default_bool,
|
.set_default = conf_default_bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct conf_type conf_string = {
|
const struct conf_type conf_string = {
|
||||||
.flags = CONF_HAS_ARG,
|
.flags = CONF_HAS_ARG,
|
||||||
.parse = parse_string,
|
.parse = conf_parse_string,
|
||||||
.free = free_value,
|
.free = conf_free_value,
|
||||||
.set_default = default_string,
|
.set_default = conf_default_string,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _mem, _def) \
|
|
||||||
{ _flags, _short, "no-" _long, _type, _aftercheck, _mem, _def }
|
|
||||||
#define CONF_OPTION_BOOL(_short, _long, _aftercheck, _mem, _def) \
|
|
||||||
CONF_OPTION(0, \
|
|
||||||
_short, \
|
|
||||||
_long, \
|
|
||||||
&conf_bool, \
|
|
||||||
_aftercheck, \
|
|
||||||
_mem, \
|
|
||||||
_def)
|
|
||||||
#define CONF_OPTION_STRING(_short, _long, _aftercheck, _mem, _def) \
|
|
||||||
CONF_OPTION(0, \
|
|
||||||
_short, \
|
|
||||||
_long, \
|
|
||||||
&conf_string, \
|
|
||||||
_aftercheck, \
|
|
||||||
_mem, \
|
|
||||||
_def)
|
|
||||||
|
|
||||||
static int aftercheck_debug(struct conf_option *opt, int argc, char **argv,
|
static int aftercheck_debug(struct conf_option *opt, int argc, char **argv,
|
||||||
int idx)
|
int idx)
|
||||||
{
|
{
|
||||||
|
58
src/conf.h
58
src/conf.h
@ -80,6 +80,64 @@ struct conf_obj {
|
|||||||
|
|
||||||
extern struct conf_obj conf_global;
|
extern struct conf_obj conf_global;
|
||||||
|
|
||||||
|
/* configuration parser */
|
||||||
|
|
||||||
|
struct conf_type;
|
||||||
|
struct conf_option;
|
||||||
|
|
||||||
|
/* config option flags */
|
||||||
|
#define CONF_DONE 0x0001
|
||||||
|
#define CONF_LOCKED 0x0002
|
||||||
|
|
||||||
|
/* config type flags */
|
||||||
|
#define CONF_HAS_ARG 0x0001
|
||||||
|
|
||||||
|
struct conf_type {
|
||||||
|
unsigned int flags;
|
||||||
|
int (*parse) (struct conf_option *opt, bool on, const char *arg);
|
||||||
|
void (*free) (struct conf_option *opt);
|
||||||
|
void (*set_default) (struct conf_option *opt);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct conf_option {
|
||||||
|
unsigned int flags;
|
||||||
|
char short_name;
|
||||||
|
const char *long_name;
|
||||||
|
const struct conf_type *type;
|
||||||
|
int (*aftercheck) (struct conf_option *opt, int argc,
|
||||||
|
char **argv, int idx);
|
||||||
|
void *mem;
|
||||||
|
void *def;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CONF_OPTION(_flags, _short, _long, _type, _aftercheck, _mem, _def) \
|
||||||
|
{ _flags, _short, "no-" _long, _type, _aftercheck, _mem, _def }
|
||||||
|
#define CONF_OPTION_BOOL(_short, _long, _aftercheck, _mem, _def) \
|
||||||
|
CONF_OPTION(0, \
|
||||||
|
_short, \
|
||||||
|
_long, \
|
||||||
|
&conf_bool, \
|
||||||
|
_aftercheck, \
|
||||||
|
_mem, \
|
||||||
|
_def)
|
||||||
|
#define CONF_OPTION_STRING(_short, _long, _aftercheck, _mem, _def) \
|
||||||
|
CONF_OPTION(0, \
|
||||||
|
_short, \
|
||||||
|
_long, \
|
||||||
|
&conf_string, \
|
||||||
|
_aftercheck, \
|
||||||
|
_mem, \
|
||||||
|
_def)
|
||||||
|
|
||||||
|
void conf_free_value(struct conf_option *opt);
|
||||||
|
int conf_parse_bool(struct conf_option *opt, bool on, const char *arg);
|
||||||
|
void conf_default_bool(struct conf_option *opt);
|
||||||
|
int conf_parse_string(struct conf_option *opt, bool on, const char *arg);
|
||||||
|
void conf_default_string(struct conf_option *opt);
|
||||||
|
|
||||||
|
extern const struct conf_type conf_bool;
|
||||||
|
extern const struct conf_type conf_string;
|
||||||
|
|
||||||
void conf_free(void);
|
void conf_free(void);
|
||||||
int conf_parse_argv(int argc, char **argv);
|
int conf_parse_argv(int argc, char **argv);
|
||||||
int conf_parse_file(const char *path);
|
int conf_parse_file(const char *path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user