[PATCH weston 2/2] shared/option-parser: Add string list options
Quentin Glidic
sardemff7+wayland at sardemff7.net
Mon Jan 27 21:36:10 PST 2014
From: Quentin Glidic <sardemff7+git at sardemff7.net>
Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
man/weston.man | 6 +++---
shared/config-parser.h | 1 +
shared/option-parser.c | 15 +++++++++++++++
src/compositor.c | 27 ++++++++++++++++++++++++---
tests/weston-tests-env | 6 ++++--
5 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/man/weston.man b/man/weston.man
index 0f686dc..3727f3b 100644
--- a/man/weston.man
+++ b/man/weston.man
@@ -128,9 +128,9 @@ Append log messages to the file
.I file.log
instead of writing them to stderr.
.TP
-\fB\-\-modules\fR=\fImodule1.so,module2.so\fR
-Load the comma-separated list of modules. Only used by the test
-suite. The file is searched for in
+\fB\-\-modules\fR=\fImodule.so\fR
+Load the modules (the option may be specified multiple times).
+Only used by the test suite. The file is searched for in
.IR "__weston_modules_dir__" ,
or you can pass an absolute path.
.TP
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 745562b..4cd4c4f 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -51,6 +51,7 @@ enum weston_option_type {
WESTON_OPTION_INTEGER,
WESTON_OPTION_UNSIGNED_INTEGER,
WESTON_OPTION_STRING,
+ WESTON_OPTION_STRING_LIST,
WESTON_OPTION_BOOLEAN
};
diff --git a/shared/option-parser.c b/shared/option-parser.c
index da9c394..14ca5d4 100644
--- a/shared/option-parser.c
+++ b/shared/option-parser.c
@@ -39,6 +39,8 @@ enum state {
static enum state
handle_option(const struct weston_option *option, const char *value)
{
+ char **string_list, **str;
+ int size = 0;
switch (option->type) {
case WESTON_OPTION_INTEGER:
if (value == NULL || value[0] == '\0')
@@ -55,6 +57,19 @@ handle_option(const struct weston_option *option, const char *value)
return ERROR;
* (char **) option->data = strdup(value);
return EATEN;
+ case WESTON_OPTION_STRING_LIST:
+ if (value == NULL)
+ return ERROR;
+ string_list = * (char ***) option->data;
+ if (string_list != NULL) {
+ for (str = string_list; *str != NULL; ++str)
+ ++size;
+ }
+ string_list = realloc(string_list, (size+2) * sizeof(char *));
+ string_list[size] = strdup(value);
+ string_list[size+1] = NULL;
+ * (char ***) option->data = string_list;
+ return EATEN;
case WESTON_OPTION_BOOLEAN:
* (int32_t *) option->data = 1;
return OK;
diff --git a/src/compositor.c b/src/compositor.c
index 40e4b11..6321252 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3974,6 +3974,26 @@ load_modules(struct weston_compositor *ec, const char *modules,
return 0;
}
+static int
+load_modules_strv(struct weston_compositor *ec, char **modules,
+ int *argc, char *argv[])
+{
+ char **module;
+ int (*module_init)(struct weston_compositor *ec,
+ int *argc, char *argv[]);
+
+ if (modules == NULL)
+ return 0;
+
+ for (module = modules; *module != NULL; ++module) {
+ module_init = load_module(*module, "module_init");
+ if (module_init)
+ module_init(ec, argc, argv);
+ }
+
+ return 0;
+}
+
static const char xdg_error_message[] =
"fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
@@ -4129,7 +4149,8 @@ int main(int argc, char *argv[])
char *option_backend = NULL;
char *shell = NULL;
char *option_shell = NULL;
- char *modules, *option_modules = NULL;
+ char *modules;
+ char **option_modules = NULL;
char *log = NULL;
int32_t idle_time = 300;
int32_t help = 0;
@@ -4143,7 +4164,7 @@ int main(int argc, char *argv[])
{ WESTON_OPTION_STRING, "shell", 0, &option_shell },
{ WESTON_OPTION_STRING, "socket", 'S', &socket_name },
{ WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
- { WESTON_OPTION_STRING, "modules", 0, &option_modules },
+ { WESTON_OPTION_STRING_LIST, "modules", 0, &option_modules },
{ WESTON_OPTION_STRING, "log", 0, &log },
{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
{ WESTON_OPTION_BOOLEAN, "version", 0, &version },
@@ -4247,7 +4268,7 @@ int main(int argc, char *argv[])
}
free(modules);
- if (load_modules(ec, option_modules, &argc, argv) < 0)
+ if (load_modules_strv(ec, option_modules, &argc, argv) < 0)
goto out;
for (i = 1; i < argc; i++)
diff --git a/tests/weston-tests-env b/tests/weston-tests-env
index b732250..cd3c61d 100755
--- a/tests/weston-tests-env
+++ b/tests/weston-tests-env
@@ -29,7 +29,8 @@ case $TESTNAME in
*.la|*.so)
$WESTON --backend=$BACKEND \
--socket=test-$(basename $TESTNAME) \
- --modules=$abs_builddir/.libs/${TESTNAME/.la/.so},xwayland.so \
+ --modules=xwayland.so \
+ --modules=$abs_builddir/.libs/${TESTNAME/.la/.so} \
--log="$SERVERLOG" \
&> "$OUTLOG"
;;
@@ -38,6 +39,7 @@ case $TESTNAME in
--socket=test-$(basename $TESTNAME) \
--backend=$BACKEND \
--log="$SERVERLOG" \
- --modules=$abs_builddir/.libs/weston-test.so,xwayland.so \
+ --modules=xwayland.so \
+ --modules=$abs_builddir/.libs/weston-test.so \
&> "$OUTLOG"
esac
--
1.8.5.3
More information about the wayland-devel
mailing list