[polari/wip/fmuellner/ci-snapshots: 4/9] main: Split out ARGV conversion
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/ci-snapshots: 4/9] main: Split out ARGV conversion
- Date: Fri, 3 Aug 2018 20:06:32 +0000 (UTC)
commit b4314799859a23502363e7db996b495ae50936ba
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Jul 25 17:55:15 2018 +0200
main: Split out ARGV conversion
By convention (and the example set by gjs-console), the javascript
code has access to a global ARGV variable that holds the actual
command line options (that is, ARGV[0] is not the executable from
argv[0]).
We currently handle that with some pointer arithmetic on argv itself,
but as we are about to do some semi-evil command line manipulation,
it makes sense to copy the relevant elements from the original argv
into a NULL-terminated string array.
https://gitlab.gnome.org/GNOME/polari/issues/61
src/polari.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/polari.c b/src/polari.c
index eedf0a4..299f984 100644
--- a/src/polari.c
+++ b/src/polari.c
@@ -11,6 +11,19 @@ const char *src =
" prefix: '" PREFIX "',"
" libdir: '" LIBDIR "' });";
+static char **
+get_js_argv (int argc, const char * const *argv)
+{
+ char **strv;
+ int js_argc = argc - 1; // gjs doesn't do argv[0]
+ int i;
+
+ strv = g_new0 (char *, js_argc + 1);
+ for (i = 0; i < js_argc; i++)
+ strv[i] = g_strdup (argv[i + 1]);
+ return strv;
+}
+
int
main (int argc, char *argv[])
{
@@ -18,6 +31,7 @@ main (int argc, char *argv[])
g_autoptr (GOptionContext) option_context = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GjsContext) context = NULL;
+ g_auto (GStrv) js_argv = NULL;
gboolean debugger = FALSE;
int status;
@@ -43,8 +57,10 @@ main (int argc, char *argv[])
if (debugger)
gjs_context_setup_debugger_console (context);
+ js_argv = get_js_argv (argc, (const char * const *)argv);
+
if (!gjs_context_define_string_array (context, "ARGV",
- argc - 1, (const char **)argv + 1,
+ -1, (const char **)js_argv,
&error))
{
g_message ("Failed to define ARGV: %s", error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]