conf: add INT datatype

This is very similar to the UINT datatype but allows signed values. This
will be required for the coming --vt option as default value.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-09-29 11:47:42 +02:00
parent f612529141
commit a6165a03c7
2 changed files with 29 additions and 0 deletions

View File

@ -58,6 +58,17 @@ void conf_default_bool(struct conf_option *opt)
*(bool*)opt->mem = (bool)opt->def;
}
int conf_parse_int(struct conf_option *opt, bool on, const char *arg)
{
*(int*)opt->mem = atoi(arg);
return 0;
}
void conf_default_int(struct conf_option *opt)
{
*(int*)opt->mem = (int)(unsigned long)opt->def;
}
int conf_parse_uint(struct conf_option *opt, bool on, const char *arg)
{
*(unsigned int*)opt->mem = atoi(arg);
@ -143,6 +154,13 @@ const struct conf_type conf_bool = {
.set_default = conf_default_bool,
};
const struct conf_type conf_int = {
.flags = CONF_HAS_ARG,
.parse = conf_parse_int,
.free = NULL,
.set_default = conf_default_int,
};
const struct conf_type conf_uint = {
.flags = CONF_HAS_ARG,
.parse = conf_parse_uint,

View File

@ -76,6 +76,14 @@ struct conf_option {
_aftercheck, \
_mem, \
_def)
#define CONF_OPTION_INT(_short, _long, _aftercheck, _mem, _def) \
CONF_OPTION(0, \
_short, \
_long, \
&conf_int, \
_aftercheck, \
_mem, \
(void*)(unsigned long)_def)
#define CONF_OPTION_UINT(_short, _long, _aftercheck, _mem, _def) \
CONF_OPTION(0, \
_short, \
@ -104,6 +112,8 @@ struct conf_option {
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_int(struct conf_option *opt, bool on, const char *arg);
void conf_default_int(struct conf_option *opt);
int conf_parse_uint(struct conf_option *opt, bool on, const char *arg);
void conf_default_uint(struct conf_option *opt);
int conf_parse_string(struct conf_option *opt, bool on, const char *arg);
@ -112,6 +122,7 @@ int conf_parse_string_list(struct conf_option *opt, bool on, const char *arg);
void conf_default_string_list(struct conf_option *opt);
extern const struct conf_type conf_bool;
extern const struct conf_type conf_int;
extern const struct conf_type conf_uint;
extern const struct conf_type conf_string;
extern const struct conf_type conf_string_list;