Commit 59492a1e authored by Philippe Gerum's avatar Philippe Gerum
Browse files

smokey: add helper to retrieve size expr

parent 59ba26a8
......@@ -49,6 +49,12 @@
.matched = 0, \
}
#define SMOKEY_SIZE(__name) { \
.name = # __name, \
.parser = smokey_size, \
.matched = 0, \
}
#define SMOKEY_ARGLIST(__args...) ((struct smokey_arg[]){ __args })
#define SMOKEY_NOARGS (((struct smokey_arg[]){ { .name = NULL } }))
......@@ -60,6 +66,7 @@ struct smokey_arg {
union {
int n_val;
char *s_val;
size_t l_val;
} u;
int matched;
};
......@@ -104,11 +111,13 @@ struct smokey_test {
#define SMOKEY_ARG_INT(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.n_val)
#define SMOKEY_ARG_BOOL(__plugin, __arg) (!!SMOKEY_ARG_INT(__plugin, __arg))
#define SMOKEY_ARG_STRING(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.s_val)
#define SMOKEY_ARG_SIZE(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.l_val)
#define smokey_arg_isset(__t, __name) (smokey_lookup_arg(__t, __name)->matched)
#define smokey_arg_int(__t, __name) (smokey_lookup_arg(__t, __name)->u.n_val)
#define smokey_arg_bool(__t, __name) (!!smokey_arg_int(__t, __name))
#define smokey_arg_string(__t, __name) (smokey_lookup_arg(__t, __name)->u.s_val)
#define smokey_arg_size(__t, __name) (smokey_lookup_arg(__t, __name)->u.l_val)
#define smokey_check_errno(__expr) \
({ \
......@@ -216,6 +225,8 @@ int smokey_bool(const char *s, struct smokey_arg *arg);
int smokey_string(const char *s, struct smokey_arg *arg);
int smokey_size(const char *s, struct smokey_arg *arg);
struct smokey_arg *smokey_lookup_arg(struct smokey_test *t,
const char *arg);
......
......@@ -85,6 +85,28 @@ int smokey_string(const char *s, struct smokey_arg *arg)
return ret;
}
int smokey_size(const char *s, struct smokey_arg *arg)
{
char *name, *p;
int ret;
ret = sscanf(s, "%m[_a-z]=%m[^\n]", &name, &p);
if (ret != 2)
return 0;
ret = !strcmp(name, arg->name);
if (ret) {
arg->u.l_val = get_mem_size(p);
if (arg->u.l_val == 0)
ret = 0;
}
free(p);
free(name);
return ret;
}
int smokey_parse_args(struct smokey_test *t,
int argc, char *const argv[])
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment