summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorLyude Paul <lyude@redhat.com>2017-05-08 12:47:55 -0400
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-23 11:19:27 +0200
commit47bbdc72967faf1cca2ca8b8bbeefab4fee67d95 (patch)
tree6eb0c767d0695a5764734d2d0c57c7b82a202d9d /shared
parentdbfd248da4ccfffde461de856a4d8504e33d91a9 (diff)
weston: Add support for "--foo bar" style options
A little earlier today I ended up spending a lot of time trying to figure out why weston wasn't managing to launch over SSH and telling me that I did not have a --tty option specified, despite me passing the option strings ["--tty", "3"]. Turns out weston just doesn't support that. So, add support for this kind of format in addition to "--foo=bar" to save others from making the same mistake I did. Changes since v1: - Add comment about unreachable boolean check in long_option_with_arg() - Convert boolean check in long_option_with_arg() to assert Signed-off-by: Lyude <lyude@redhat.com> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'shared')
-rw-r--r--shared/option-parser.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/shared/option-parser.c b/shared/option-parser.c
index eee75468..e8d9b3b7 100644
--- a/shared/option-parser.c
+++ b/shared/option-parser.c
@@ -87,6 +87,31 @@ long_option(const struct weston_option *options, int count, char *arg)
}
static int
+long_option_with_arg(const struct weston_option *options, int count, char *arg,
+ char *param)
+{
+ int k, len;
+
+ for (k = 0; k < count; k++) {
+ if (!options[k].name)
+ continue;
+
+ len = strlen(options[k].name);
+ if (strncmp(options[k].name, arg + 2, len) != 0)
+ continue;
+
+ /* Since long_option() should handle all booleans, we should
+ * never reach this
+ */
+ assert(options[k].type != WESTON_OPTION_BOOLEAN);
+
+ return handle_option(options + k, param);
+ }
+
+ return 0;
+}
+
+static int
short_option(const struct weston_option *options, int count, char *arg)
{
int k;
@@ -148,6 +173,13 @@ parse_options(const struct weston_option *options,
if (long_option(options, count, argv[i]))
continue;
+ /* ...also handle --foo bar */
+ if (i + 1 < *argc &&
+ long_option_with_arg(options, count,
+ argv[i], argv[i+1])) {
+ i++;
+ continue;
+ }
} else {
/* Short option, e.g -f or -f42 */
if (short_option(options, count, argv[i]))