Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
xenomai
xenomai
Commits
59492a1e
Commit
59492a1e
authored
Apr 23, 2018
by
Philippe Gerum
Browse files
smokey: add helper to retrieve size expr
parent
59ba26a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/smokey/smokey.h
View file @
59492a1e
...
...
@@ -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
);
...
...
lib/smokey/helpers.c
View file @
59492a1e
...
...
@@ -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
[])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment