[PATCH weston 2/2] shared/option-parser: Add string list options

Quentin Glidic sardemff7+wayland at sardemff7.net
Mon Jul 8 15:18:00 PDT 2013


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       | 31 ++++++++++++++++++++++++++-----
 tests/weston-tests-env |  6 ++++--
 5 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/man/weston.man b/man/weston.man
index 79d4588..6175b0e 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 794e09c..113fb38 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -59,6 +59,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 92d89a7..4ce13e8 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3002,7 +3002,7 @@ print_backtrace(void)
 			filename = dlinfo.dli_fname;
 		else
 			filename = "?";
-		
+
 		weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
 			   ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off));
 
@@ -3116,6 +3116,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";
 
@@ -3261,7 +3281,8 @@ int main(int argc, char *argv[])
 				 struct weston_config *config);
 	int i, config_fd;
 	char *backend = NULL;
-	char *modules, *option_modules = NULL;
+	char *modules;
+	char **option_modules = NULL;
 	char *log = NULL;
 	int32_t idle_time = 300;
 	int32_t help = 0;
@@ -3274,7 +3295,7 @@ int main(int argc, char *argv[])
 		{ WESTON_OPTION_STRING, "backend", 'B', &backend },
 		{ 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 },
@@ -3291,7 +3312,7 @@ int main(int argc, char *argv[])
 	}
 
 	weston_log_file_open(log);
-	
+
 	weston_log("%s\n"
 		   STAMP_SPACE "%s\n"
 		   STAMP_SPACE "Bug reports to: %s\n"
@@ -3352,7 +3373,7 @@ int main(int argc, char *argv[])
 
 	if (load_modules(ec, modules, &argc, argv) < 0)
 		goto out;
-	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 2e5fa95..1bc06be 100755
--- a/tests/weston-tests-env
+++ b/tests/weston-tests-env
@@ -22,7 +22,8 @@ case $1 in
 	*.la|*.so)
 		$WESTON --backend=$BACKEND \
 			--socket=test-$(basename $1) \
-			--modules=$abs_builddir/.libs/${1/.la/.so},xwayland.so \
+			--modules=xwayland.so \
+			--modules=$abs_builddir/.libs/${1/.la/.so} \
 			--log="$SERVERLOG" \
 			&> "$OUTLOG"
 		;;
@@ -31,6 +32,7 @@ case $1 in
 			--socket=test-$(basename $1) \
 			--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.3.2



More information about the wayland-devel mailing list