From 04b440d1e7709311a32bde4bf107a7dc6a6a37a4 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 14 Nov 2019 14:25:26 +0000
Subject: [PATCH] wrap: Make GOptionEntry flags clearer

Instead of {0, 0}, represent the absence of a short option with '\0'
and the absence of flags with G_OPTION_FLAG_NONE. To support older GLib,
provide a compatibility definition for the latter.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/glib-backports.h |  4 ++++
 src/wrap.c           | 57 +++++++++++++++++++++++++++++---------------
 2 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/src/glib-backports.h b/src/glib-backports.h
index 925b30c6e..70aba6013 100644
--- a/src/glib-backports.h
+++ b/src/glib-backports.h
@@ -67,3 +67,7 @@ void my_g_ptr_array_insert (GPtrArray *arr,
                             gint index_,
                             gpointer data);
 #endif
+
+#if !GLIB_CHECK_VERSION (2, 42, 0)
+#define G_OPTION_FLAG_NONE 0
+#endif
diff --git a/src/wrap.c b/src/wrap.c
index 4bbf8470a..348494acc 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -1809,61 +1809,76 @@ opt_share_home_cb (const gchar *option_name,
 
 static GOptionEntry options[] =
 {
-  { "env-if-host", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_env_if_host,
+  { "env-if-host", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING_ARRAY, &opt_env_if_host,
     "Set VAR=VAL if COMMAND is run with /usr from the host system, "
     "but not if it is run with /usr from RUNTIME.", "VAR=VAL" },
-  { "freedesktop-app-id", 0, 0, G_OPTION_ARG_STRING, &opt_freedesktop_app_id,
+  { "freedesktop-app-id", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_freedesktop_app_id,
     "Make --unshare-home use ~/.var/app/ID as home directory, where ID "
     "is com.example.MyApp or similar. This interoperates with Flatpak. "
     "[Default: $PRESSURE_VESSEL_FDO_APP_ID if set]",
     "ID" },
-  { "steam-app-id", 0, 0, G_OPTION_ARG_STRING, &opt_steam_app_id,
+  { "steam-app-id", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_steam_app_id,
     "Make --unshare-home use ~/.var/app/com.steampowered.AppN "
     "as home directory. [Default: $SteamAppId]", "N" },
-  { "home", 0, 0, G_OPTION_ARG_FILENAME, &opt_home,
+  { "home", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_FILENAME, &opt_home,
     "Use HOME as home directory. Implies --unshare-home. "
     "[Default: $PRESSURE_VESSEL_HOME if set]", "HOME" },
-  { "host-fallback", 0, 0, G_OPTION_ARG_NONE, &opt_host_fallback,
+  { "host-fallback", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_host_fallback,
     "Run COMMAND on the host system if we cannot run it in a container.", NULL },
-  { "host-ld-preload", 0, 0, G_OPTION_ARG_CALLBACK, &opt_host_ld_preload_cb,
+  { "host-ld-preload", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, &opt_host_ld_preload_cb,
     "Add MODULE from the host system to LD_PRELOAD when executing COMMAND.",
     "MODULE" },
-  { "runtime", 0, 0, G_OPTION_ARG_FILENAME, &opt_runtime,
+  { "runtime", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_FILENAME, &opt_runtime,
     "Mount the given sysroot or merged /usr in the container, and augment "
     "it with the host system's graphics stack. The empty string "
     "means don't use a runtime. [Default: $PRESSURE_VESSEL_RUNTIME or '']",
     "RUNTIME" },
-  { "runtime-base", 0, 0, G_OPTION_ARG_FILENAME, &opt_runtime_base,
+  { "runtime-base", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_FILENAME, &opt_runtime_base,
     "If a --runtime is a relative path, look for it relative to BASE. "
     "[Default: $PRESSURE_VESSEL_RUNTIME_BASE or '.']",
     "BASE" },
-  { "share-home", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_share_home_cb,
+  { "share-home", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_share_home_cb,
     "Use the real home directory. "
     "[Default unless $PRESSURE_VESSEL_HOME is set or "
     "$PRESSURE_VESSEL_SHARE_HOME is 0]",
     NULL },
-  { "unshare-home", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_share_home_cb,
+  { "unshare-home", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_share_home_cb,
     "Use an app-specific home directory chosen according to --home, "
     "--freedesktop-app-id, --steam-app-id or $SteamAppId. "
     "[Default if $PRESSURE_VESSEL_HOME is set or "
     "$PRESSURE_VESSEL_SHARE_HOME is 0]",
     NULL },
-  { "shell", 0, 0, G_OPTION_ARG_CALLBACK, opt_shell_cb,
+  { "shell", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, opt_shell_cb,
     "--shell=after is equivalent to --shell-after, and so on. "
     "[Default: $PRESSURE_VESSEL_SHELL or 'none']",
     "{none|after|fail|instead}" },
-  { "shell-after", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
+  { "shell-after", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
     "Run an interactive shell after COMMAND. Executing \"$@\" in that "
     "shell will re-run COMMAND [ARGS].",
     NULL },
-  { "shell-fail", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
+  { "shell-fail", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
     "Run an interactive shell after COMMAND, but only if it fails.",
     NULL },
-  { "shell-instead", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
+  { "shell-instead", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_shell_cb,
     "Run an interactive shell instead of COMMAND. Executing \"$@\" in that "
     "shell will run COMMAND [ARGS].",
     NULL },
-  { "terminal", 0, 0, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
+  { "terminal", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
     "none: disable features that would use a terminal; "
     "auto: equivalent to xterm if a --shell option is used, or none; "
     "xterm: put game output (and --shell if used) in an xterm; "
@@ -1871,13 +1886,17 @@ static GOptionEntry options[] =
     "controlling tty "
     "[Default: $PRESSURE_VESSEL_TERMINAL or 'auto']",
     "{none|auto|xterm|tty}" },
-  { "tty", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
+  { "tty", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
     "Equivalent to --terminal=tty", NULL },
-  { "xterm", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
+  { "xterm", '\0',
+    G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_terminal_cb,
     "Equivalent to --terminal=xterm", NULL },
-  { "verbose", 0, 0, G_OPTION_ARG_NONE, &opt_verbose,
+  { "verbose", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_verbose,
     "Be more verbose.", NULL },
-  { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version,
+  { "version", '\0',
+    G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_version,
     "Print version number and exit.", NULL },
   { NULL }
 };
-- 
GitLab