[PATCH 3/3] compositor: dump command line options

Tiago Vignatti tiago.vignatti at intel.com
Mon Mar 12 15:06:40 PDT 2012


Use it with --help or -h.

Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 shared/config-parser.h   |    3 +++
 shared/option-parser.c   |   13 +++++++++++++
 src/compositor-drm.c     |    7 ++++++-
 src/compositor-openwfd.c |    7 ++++++-
 src/compositor-wayland.c |    8 +++++++-
 src/compositor-x11.c     |    8 +++++++-
 src/compositor.c         |    8 ++++++++
 7 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/shared/config-parser.h b/shared/config-parser.h
index 6403947..4792bcb 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -67,6 +67,9 @@ struct weston_option {
 	void *data;
 };
 
+void
+dump_options(const struct weston_option *option, int count);
+
 int
 parse_options(const struct weston_option *options,
 	      int count, int argc, char *argv[]);
diff --git a/shared/option-parser.c b/shared/option-parser.c
index 8b16b5d..bc977c1 100644
--- a/shared/option-parser.c
+++ b/shared/option-parser.c
@@ -70,6 +70,19 @@ check_uint(const char *value)
 	}
 }
 
+void
+dump_options(const struct weston_option *option, int count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		fprintf(stderr, "--%s", option[i].name);
+		if (option[i].short_name)
+			fprintf(stderr, ", -%c", option[i].short_name);
+		fprintf(stderr, "\n", option[i].name);
+	}
+}
+
 static void
 handle_option(const struct weston_option *option, char *value)
 {
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 8feb769..748ef60 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1642,16 +1642,21 @@ drm_compositor_create(struct wl_display *display,
 WL_EXPORT struct weston_compositor *
 backend_init(struct wl_display *display, int argc, char *argv[])
 {
-	int connector = 0, tty = 0;
+	int connector = 0, tty = 0, help = 0;
 	const char *seat = default_seat;
 
 	const struct weston_option drm_options[] = {
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "connector", 0, &connector },
 		{ WESTON_OPTION_STRING, "seat", 0, &seat },
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "tty", 0, &tty },
+		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 	};
 
 	parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv);
+	if (help) {
+		dump_options(drm_options, ARRAY_LENGTH(drm_options) - 1);
+		exit (EXIT_SUCCESS);
+	}
 
 	return drm_compositor_create(display, connector, seat, tty);
 }
diff --git a/src/compositor-openwfd.c b/src/compositor-openwfd.c
index 72c25a6..ee35d81 100644
--- a/src/compositor-openwfd.c
+++ b/src/compositor-openwfd.c
@@ -666,16 +666,21 @@ wfd_compositor_create(struct wl_display *display,
 WL_EXPORT struct weston_compositor *
 backend_init(struct wl_display *display, int argc, char *argv[])
 {
-	int connector = 0, tty = 0;
+	int connector = 0, tty = 0, help = 0;
 	const char *seat;
 
 	const struct weston_option wfd_options[] = {
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "connector", 0, &connector },
 		{ WESTON_OPTION_STRING, "seat", 0, &seat },
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "tty", 0, &tty },
+		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 	};
 
 	parse_options(&wfd_options, ARRAY_LENGTH(wfd_options), argc, argv);
+	if (help) {
+		dump_options(wfd_options, ARRAY_LENGTH(wfd_options) - 1);
+		exit (EXIT_SUCCESS);
+	}
 
 	return wfd_compositor_create(display, connector, seat, tty);
 }
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 2ffe374..1d61140 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -724,17 +724,23 @@ wayland_compositor_create(struct wl_display *display,
 WL_EXPORT struct weston_compositor *
 backend_init(struct wl_display *display, int argc, char *argv[])
 {
-	int width = 1024, height = 640;
+	int width = 1024, height = 640, help = 0;
 	char *display_name = NULL;
 
 	const struct weston_option wayland_options[] = {
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "width", 0, &width },
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "height", 0, &height },
 		{ WESTON_OPTION_STRING, "display", 0, &display_name },
+		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 	};
 
 	parse_options(wayland_options,
 		      ARRAY_LENGTH(wayland_options), argc, argv);
+	if (help) {
+		dump_options(wayland_options,
+			     ARRAY_LENGTH(wayland_options) - 1);
+		exit (EXIT_SUCCESS);
+	}
 
 	return wayland_compositor_create(display, width, height, display_name);
 }
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index b6b28de..baa1f40 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -824,16 +824,22 @@ x11_compositor_create(struct wl_display *display,
 WL_EXPORT struct weston_compositor *
 backend_init(struct wl_display *display, int argc, char *argv[])
 {
-	int width = 1024, height = 640, fullscreen = 0, count = 1;
+	int width = 1024, height = 640, fullscreen = 0, count = 1, help = 0;
 
 	const struct weston_option x11_options[] = {
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "width", 0, &width },
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "height", 0, &height },
 		{ WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fullscreen },
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "output-count", 0, &count },
+		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 	};
 
 	parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
+	if (help) {
+		dump_options(x11_options, ARRAY_LENGTH(x11_options) - 1);
+		exit (EXIT_SUCCESS);
+	}
+
 
 	return x11_compositor_create(display,
 				     width, height, count, fullscreen);
diff --git a/src/compositor.c b/src/compositor.c
index a832d3f..c50fa3d 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2467,6 +2467,7 @@ int main(int argc, char *argv[])
 	char *shell = NULL;
 	int32_t idle_time = 300;
 	int32_t xserver;
+	int32_t help = 0;
 	char *socket_name = NULL;
 
 	const struct weston_option core_options[] = {
@@ -2475,6 +2476,7 @@ int main(int argc, char *argv[])
 		{ WESTON_OPTION_UNSIGNED_INTEGER, "idle-time", 'i', &idle_time },
 		{ WESTON_OPTION_STRING, "shell", 's', &shell },
 		{ WESTON_OPTION_BOOLEAN, "xserver", 0, &xserver },
+		{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
 	};
 
 	argc = parse_options(core_options,
@@ -2499,6 +2501,12 @@ int main(int argc, char *argv[])
 	sigemptyset(&segv_action.sa_mask);
 	sigaction(SIGSEGV, &segv_action, NULL);
 
+	if (help) {
+		dump_options(core_options, ARRAY_LENGTH(core_options));
+		argv[argc] = strdup("--help");
+		argc++;
+	}
+
 	if (!backend) {
 		if (getenv("WAYLAND_DISPLAY"))
 			backend = "wayland-backend.so";
-- 
1.7.5.4



More information about the wayland-devel mailing list