[PATCH weston 2/3] editor: Add command line options for version and help
Bryce Harrington
bryce at osg.samsung.com
Sun Nov 20 22:00:24 UTC 2016
Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
clients/editor.c | 70 ++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 50 insertions(+), 20 deletions(-)
diff --git a/clients/editor.c b/clients/editor.c
index d6bf588..ead7b6f 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -1489,6 +1489,12 @@ global_handler(struct display *display, uint32_t name,
}
}
+/** Display help for command line options, and exit */
+static uint32_t opt_help = 0;
+
+/** Display the (weston) version number, and exit */
+static uint32_t opt_version = 0;
+
/** Require a distinct click to show the input panel (virtual keyboard) */
static uint32_t opt_click_to_show = 0;
@@ -1499,36 +1505,60 @@ static const char *opt_preferred_language = NULL;
* \brief command line options for editor
*/
static const struct weston_option editor_options[] = {
+ { WESTON_OPTION_BOOLEAN, "help", 'h', &opt_help },
+ { WESTON_OPTION_BOOLEAN, "version", 'V', &opt_version },
{ WESTON_OPTION_BOOLEAN, "click-to-show", 'C', &opt_click_to_show },
{ WESTON_OPTION_STRING, "preferred-language", 'L', &opt_preferred_language },
};
+static void
+version(const char *program_name, int exit_code)
+{
+ fprintf(stderr, "%s (%s)\n", program_name, VERSION);
+ exit(exit_code);
+}
+
+static void
+usage(const char *program_name, int exit_code)
+{
+ unsigned k;
+
+ fprintf(stderr, "Usage: %s [OPTIONS]\n\n", program_name);
+ for (k = 0; k < ARRAY_LENGTH(editor_options); k++) {
+ const struct weston_option *p = &editor_options[k];
+ if (p->name) {
+ fprintf(stderr, " --%s", p->name);
+ if (p->type != WESTON_OPTION_BOOLEAN)
+ fprintf(stderr, "=VALUE");
+ fprintf(stderr, "\n");
+ }
+ if (p->short_name) {
+ fprintf(stderr, " -%c", p->short_name);
+ if (p->type != WESTON_OPTION_BOOLEAN)
+ fprintf(stderr, "VALUE");
+ fprintf(stderr, "\n");
+ }
+ }
+ exit(exit_code);
+}
+
int
main(int argc, char *argv[])
{
struct editor editor;
int i;
- 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;
+ parse_options(editor_options, ARRAY_LENGTH(editor_options),
+ &argc, argv);
+ if (opt_help)
+ usage(argv[0], EXIT_SUCCESS);
+ if (opt_version)
+ version(argv[0], EXIT_SUCCESS);
+
+ if (argc > 1) {
+ usage(argv[0], EXIT_FAILURE);
+ /* FIXME: Use remaining arguments as a path/filename to load */
+ return 0;
}
memset(&editor, 0, sizeof editor);
--
1.9.1
More information about the wayland-devel
mailing list