[PATCH weston 1/3] editor: Use parse_options() from shared for command line options

Bryce Harrington bryce at osg.samsung.com
Sun Nov 20 22:00:23 UTC 2016


Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 clients/editor.c | 59 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 6805d8a..d6bf588 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -37,6 +37,7 @@
 
 #include <pango/pangocairo.h>
 
+#include "shared/config-parser.h"
 #include "shared/helpers.h"
 #include "shared/xalloc.h"
 #include "window.h"
@@ -1488,28 +1489,46 @@ global_handler(struct display *display, uint32_t name,
 	}
 }
 
+/** Require a distinct click to show the input panel (virtual keyboard) */
+static uint32_t opt_click_to_show = 0;
+
+/** Set a specific (RFC-3066) language.  Used for the virtual keyboard, etc. */
+static const char *opt_preferred_language = NULL;
+
+/**
+ * \brief command line options for editor
+ */
+static const struct weston_option editor_options[] = {
+	{ WESTON_OPTION_BOOLEAN, "click-to-show", 'C', &opt_click_to_show },
+	{ WESTON_OPTION_STRING, "preferred-language", 'L', &opt_preferred_language },
+};
+
 int
 main(int argc, char *argv[])
 {
 	struct editor editor;
 	int i;
-	uint32_t click_to_show = 0;
-	const char *preferred_language = NULL;
-
-	for (i = 1; i < argc; i++) {
-		if (strcmp("--click-to-show", argv[i]) == 0)
-			click_to_show = 1;
-		else if (strcmp("--preferred-language", argv[i]) == 0 &&
-			 i + 1 < argc) {
-			preferred_language = argv[i + 1];
-			i++;
-		} else {
-			printf("Usage: %s [OPTIONS]\n"
-			       "  --click-to-show\n"
-			       "  --preferred-language LANGUAGE\n",
-			       argv[0]);
-			return 1;
+
+	if (parse_options(editor_options, ARRAY_LENGTH(editor_options),
+			  &argc, argv) > 1) {
+		unsigned k;
+		printf("Usage: %s [OPTIONS]\n\n", argv[0]);
+		for (k = 0; k < ARRAY_LENGTH(editor_options); k++) {
+			const struct weston_option *p = &editor_options[k];
+			if (p->name) {
+				printf("  --%s", p->name);
+				if (p->type != WESTON_OPTION_BOOLEAN)
+					printf("=VALUE");
+				putchar('\n');
+			}
+			if (p->short_name) {
+				printf("  -%c", p->short_name);
+				if (p->type != WESTON_OPTION_BOOLEAN)
+					printf("VALUE");
+				putchar('\n');
+			}
 		}
+		return 1;
 	}
 
 	memset(&editor, 0, sizeof editor);
@@ -1536,12 +1555,12 @@ main(int argc, char *argv[])
 	editor.widget = window_frame_create(editor.window, &editor);
 
 	editor.entry = text_entry_create(&editor, "Entry");
-	editor.entry->click_to_show = click_to_show;
-	if (preferred_language)
-		editor.entry->preferred_language = strdup(preferred_language);
+	editor.entry->click_to_show = opt_click_to_show;
+	if (opt_preferred_language)
+		editor.entry->preferred_language = strdup(opt_preferred_language);
 	editor.editor = text_entry_create(&editor, "Numeric");
 	editor.editor->content_purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER;
-	editor.editor->click_to_show = click_to_show;
+	editor.editor->click_to_show = opt_click_to_show;
 	editor.selection = NULL;
 	editor.selected_text = NULL;
 
-- 
1.9.1



More information about the wayland-devel mailing list