summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-03-11 21:05:57 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-03-12 01:28:50 -0400
commitbcacef19b032d1162120c4a48412bb62b90ad61c (patch)
tree07b3ca56da1946d99e79258d4bab9276ef1e05bd /clients
parent22ba60e514e074e4bdee1529aa8d22600712f001 (diff)
Add an option parser
On one hand, getopt (in particular the -o suboption syntax) sucks on the server side, and on the client side we would like to avoid the glib dependency. We can roll out own option parser and solve both problems and save a few lines of code total.
Diffstat (limited to 'clients')
-rw-r--r--clients/Makefile.am5
-rw-r--r--clients/clickdot.c2
-rw-r--r--clients/desktop-shell.c2
-rw-r--r--clients/dnd.c2
-rw-r--r--clients/eventdemo.c47
-rw-r--r--clients/flower.c2
-rw-r--r--clients/gears.c2
-rw-r--r--clients/image.c6
-rw-r--r--clients/resizor.c2
-rw-r--r--clients/smoke.c2
-rw-r--r--clients/tablet-shell.c2
-rw-r--r--clients/terminal.c11
-rw-r--r--clients/view.c11
-rw-r--r--clients/window.c36
-rw-r--r--clients/window.h4
-rw-r--r--clients/wscreensaver.c11
16 files changed, 56 insertions, 91 deletions
diff --git a/clients/Makefile.am b/clients/Makefile.am
index d7a6cbf..eab8939 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -57,8 +57,9 @@ libtoytoolkit_a_SOURCES = \
cairo-util.c \
cairo-util.h
-toolkit_libs = \
- libtoytoolkit.a \
+toolkit_libs = \
+ libtoytoolkit.a \
+ ../shared/libconfig-parser.la \
$(CLIENT_LIBS) $(CAIRO_EGL_LIBS) -lrt -lm
flower_SOURCES = flower.c
diff --git a/clients/clickdot.c b/clients/clickdot.c
index cf35faa..3b7210e 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -164,7 +164,7 @@ main(int argc, char *argv[])
struct display *display;
struct clickdot *clickdot;
- display = display_create(&argc, &argv, NULL);
+ display = display_create(argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 15dc7ac..881bf7c 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -707,7 +707,7 @@ int main(int argc, char *argv[])
desktop.unlock_task.run = unlock_dialog_finish;
wl_list_init(&desktop.outputs);
- desktop.display = display_create(&argc, &argv, NULL);
+ desktop.display = display_create(argc, argv);
if (desktop.display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/dnd.c b/clients/dnd.c
index 5e1696b..66ba2ce 100644
--- a/clients/dnd.c
+++ b/clients/dnd.c
@@ -561,7 +561,7 @@ main(int argc, char *argv[])
{
struct display *d;
- d = display_create(&argc, &argv, NULL);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/eventdemo.c b/clients/eventdemo.c
index 7d591a7..5d0cc90 100644
--- a/clients/eventdemo.c
+++ b/clients/eventdemo.c
@@ -315,36 +315,20 @@ eventdemo_create(struct display *d)
}
/**
* \brief command line options for eventdemo
- *
- * see
- * http://developer.gimp.org/api/2.0/glib/glib-Commandline-option-parser.html
*/
-static const GOptionEntry option_entries[] = {
- {"title", 0, 0, G_OPTION_ARG_STRING,
- &title, "Set the window title to TITLE", "TITLE"},
- {"width", 'w', 0, G_OPTION_ARG_INT,
- &width, "Set the window's width to W", "W"},
- {"height", 'h', 0, G_OPTION_ARG_INT,
- &height, "Set the window's height to H", "H"},
- {"maxwidth", 0, 0, G_OPTION_ARG_INT,
- &width_max, "Set the window's maximum width to W", "W"},
- {"maxheight", 0, 0, G_OPTION_ARG_INT,
- &height_max, "Set the window's maximum height to H", "H"},
- {"noborder", 'b', 0, G_OPTION_ARG_NONE,
- &noborder, "Don't draw window borders", 0},
- {"log-redraw", 0, 0, G_OPTION_ARG_NONE,
- &log_redraw, "Log redraw events to stdout", 0},
- {"log-resize", 0, 0, G_OPTION_ARG_NONE,
- &log_resize, "Log resize events to stdout", 0},
- {"log-focus", 0, 0, G_OPTION_ARG_NONE,
- &log_focus, "Log keyboard focus events to stdout", 0},
- {"log-key", 0, 0, G_OPTION_ARG_NONE,
- &log_key, "Log key events to stdout", 0},
- {"log-button", 0, 0, G_OPTION_ARG_NONE,
- &log_button, "Log button events to stdout", 0},
- {"log-motion", 0, 0, G_OPTION_ARG_NONE,
- &log_motion, "Log motion events to stdout", 0},
- {NULL}
+static const struct weston_option eventdemo_options[] = {
+ { WESTON_OPTION_STRING, "title", 0, &title },
+ { WESTON_OPTION_INTEGER, "width", 'w', &width },
+ { WESTON_OPTION_INTEGER, "height", 'h', &height },
+ { WESTON_OPTION_INTEGER, "max-width", 0, &width_max },
+ { WESTON_OPTION_INTEGER, "max-height", 0, &height_max },
+ { WESTON_OPTION_BOOLEAN, "no-border", 'b', &noborder },
+ { WESTON_OPTION_BOOLEAN, "log-redraw", '0', &log_redraw },
+ { WESTON_OPTION_BOOLEAN, "log-resize", '0', &log_resize },
+ { WESTON_OPTION_BOOLEAN, "log-focus", '0', &log_focus },
+ { WESTON_OPTION_BOOLEAN, "log-key", '0', &log_key },
+ { WESTON_OPTION_BOOLEAN, "log-button", '0', &log_button },
+ { WESTON_OPTION_BOOLEAN, "log-motion", '0', &log_motion },
};
/**
@@ -357,8 +341,11 @@ main(int argc, char *argv[])
struct display *d;
struct eventdemo *e;
+ argc = parse_options(eventdemo_options,
+ ARRAY_LENGTH(eventdemo_options), argc, argv);
+
/* Connect to the display and have the arguments parsed */
- d = display_create(&argc, &argv, option_entries);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/flower.c b/clients/flower.c
index 0565eea..7a34616 100644
--- a/clients/flower.c
+++ b/clients/flower.c
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
struct display *d;
struct timeval tv;
- d = display_create(&argc, &argv, NULL);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/gears.c b/clients/gears.c
index 2353837..1aecd45 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -369,7 +369,7 @@ int main(int argc, char *argv[])
{
struct display *d;
- d = display_create(&argc, &argv, NULL);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/image.c b/clients/image.c
index 8f621eb..1058847 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -220,17 +220,13 @@ image_create(struct display *display, const char *filename)
return image;
}
-static const GOptionEntry option_entries[] = {
- { NULL }
-};
-
int
main(int argc, char *argv[])
{
struct display *d;
int i;
- d = display_create(&argc, &argv, option_entries);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/resizor.c b/clients/resizor.c
index 9f9e1b5..67d4899 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -242,7 +242,7 @@ main(int argc, char *argv[])
struct display *display;
struct resizor *resizor;
- display = display_create(&argc, &argv, NULL);
+ display = display_create(argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/smoke.c b/clients/smoke.c
index 6f80054..d618100 100644
--- a/clients/smoke.c
+++ b/clients/smoke.c
@@ -283,7 +283,7 @@ int main(int argc, char *argv[])
struct display *d;
int size;
- d = display_create(&argc, &argv, NULL);
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c
index fd772af..89dfc3f 100644
--- a/clients/tablet-shell.c
+++ b/clients/tablet-shell.c
@@ -316,7 +316,7 @@ int main(int argc, char *argv[])
uint32_t id;
struct tablet_shell *shell;
- display = display_create(&argc, &argv, NULL);
+ display = display_create(argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/terminal.c b/clients/terminal.c
index 65fec38..45d4f12 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -2362,10 +2362,8 @@ terminal_run(struct terminal *terminal, const char *path)
return 0;
}
-static const GOptionEntry option_entries[] = {
- { "fullscreen", 'f', 0, G_OPTION_ARG_NONE,
- &option_fullscreen, "Run in fullscreen mode" },
- { NULL }
+static const struct weston_option terminal_options[] = {
+ { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &option_fullscreen },
};
int main(int argc, char *argv[])
@@ -2374,7 +2372,10 @@ int main(int argc, char *argv[])
struct terminal *terminal;
const char *shell;
- d = display_create(&argc, &argv, option_entries);
+ argc = parse_options(terminal_options,
+ ARRAY_LENGTH(terminal_options), argc, argv);
+
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/view.c b/clients/view.c
index 918d22f..61a3d5c 100644
--- a/clients/view.c
+++ b/clients/view.c
@@ -252,10 +252,8 @@ view_create(struct display *display,
static int option_fullscreen;
-static const GOptionEntry option_entries[] = {
- { "fullscreen", 'f', 0, G_OPTION_ARG_NONE,
- &option_fullscreen, "Run in fullscreen mode" },
- { NULL }
+static const struct weston_option view_options[] = {
+ { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &option_fullscreen },
};
int
@@ -264,7 +262,10 @@ main(int argc, char *argv[])
struct display *d;
int i;
- d = display_create(&argc, &argv, option_entries);
+ argc = parse_options(view_options,
+ ARRAY_LENGTH(view_options), argc, argv);
+
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
diff --git a/clients/window.c b/clients/window.c
index 5465c2d..09d5ab1 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -231,14 +231,10 @@ const char *option_xkb_layout = "us";
const char *option_xkb_variant = "";
const char *option_xkb_options = "";
-static const GOptionEntry xkb_option_entries[] = {
- { "xkb-layout", 0, 0, G_OPTION_ARG_STRING,
- &option_xkb_layout, "XKB Layout" },
- { "xkb-variant", 0, 0, G_OPTION_ARG_STRING,
- &option_xkb_variant, "XKB Variant" },
- { "xkb-options", 0, 0, G_OPTION_ARG_STRING,
- &option_xkb_options, "XKB Options" },
- { NULL }
+static const struct weston_option xkb_options[] = {
+ { WESTON_OPTION_STRING, "xkb-layout", 0, &option_xkb_layout },
+ { WESTON_OPTION_STRING, "xkb-variant", 0, &option_xkb_variant },
+ { WESTON_OPTION_STRING, "xkb-options", 0, &option_xkb_options },
};
static const cairo_user_data_key_t surface_data_key;
@@ -2921,32 +2917,14 @@ handle_display_data(struct task *task, uint32_t events)
}
struct display *
-display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
+display_create(int argc, char *argv[])
{
struct display *d;
- GOptionContext *context;
- GOptionGroup *xkb_option_group;
- GError *error;
g_type_init();
- context = g_option_context_new(NULL);
- if (option_entries)
- g_option_context_add_main_entries(context, option_entries, "Wayland View");
-
- xkb_option_group = g_option_group_new("xkb",
- "Keyboard options",
- "Show all XKB options",
- NULL, NULL);
- g_option_group_add_entries(xkb_option_group, xkb_option_entries);
- g_option_context_add_group (context, xkb_option_group);
-
- if (!g_option_context_parse(context, argc, argv, &error)) {
- fprintf(stderr, "option parsing failed: %s\n", error->message);
- exit(EXIT_FAILURE);
- }
-
- g_option_context_free(context);
+ argc = parse_options(xkb_options,
+ ARRAY_LENGTH(xkb_options), argc, argv);
d = malloc(sizeof *d);
if (d == NULL)
diff --git a/clients/window.h b/clients/window.h
index eb33eed..e6b7b4b 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -24,9 +24,9 @@
#define _WINDOW_H_
#include <xkbcommon/xkbcommon.h>
-#include <glib.h>
#include <wayland-client.h>
#include <cairo.h>
+#include "../shared/config-parser.h"
struct window;
struct widget;
@@ -47,7 +47,7 @@ struct rectangle {
};
struct display *
-display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
+display_create(int argc, char *argv[]);
void
display_destroy(struct display *display);
diff --git a/clients/wscreensaver.c b/clients/wscreensaver.c
index 5342b33..21cc41e 100644
--- a/clients/wscreensaver.c
+++ b/clients/wscreensaver.c
@@ -296,10 +296,8 @@ global_handler(struct wl_display *display, uint32_t id,
}
}
-static const GOptionEntry option_entries[] = {
- { "demo", 0, 0, G_OPTION_ARG_NONE, &demo_mode,
- "Run as a regular application, not a screensaver.", NULL },
- { NULL }
+static const struct weston_option wscreensaver_options[] = {
+ { WESTON_OPTION_BOOLEAN, "demo", 0, &demo_mode },
};
int main(int argc, char *argv[])
@@ -309,7 +307,10 @@ int main(int argc, char *argv[])
init_frand();
- d = display_create(&argc, &argv, option_entries);
+ argc = parse_options(wscreensaver_options,
+ ARRAY_LENGTH(wscreensaver_options), argc, argv);
+
+ d = display_create(argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return EXIT_FAILURE;