Make GOption remove long options completely. (#153113, Robert Ögren)
authorMatthias Clasen <maclas@gmx.de>
Mon, 20 Sep 2004 04:15:38 +0000 (04:15 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 20 Sep 2004 04:15:38 +0000 (04:15 +0000)
Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>

Make GOption remove long options completely. (#153113, Robert Ögren)

* glib/goption.c (parse_long_option): Fix a wrong index.

* tests/option-test.c (ignore_test3): Test handling of unknown
options some more.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/goption.c
tests/option-test.c

index 50b49640756a89569a74caf87fb231b1d3a5971b..0826a7c03d269e0311bc65d10968818e5422d4a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>
+
+       Make GOption remove long options completely. (#153113, Robert Ögren)
+
+       * glib/goption.c (parse_long_option): Fix a wrong index.
+
+       * tests/option-test.c (ignore_test3): Test handling of unknown
+       options some more.
+
 Sun Sep 19 23:56:15 2004  Matthias Clasen  <maclas@gmx.de>
 
        * glib/goption.c (g_option_context_parse): Call error_func
index 50b49640756a89569a74caf87fb231b1d3a5971b..0826a7c03d269e0311bc65d10968818e5422d4a7 100644 (file)
@@ -1,3 +1,12 @@
+Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>
+
+       Make GOption remove long options completely. (#153113, Robert Ögren)
+
+       * glib/goption.c (parse_long_option): Fix a wrong index.
+
+       * tests/option-test.c (ignore_test3): Test handling of unknown
+       options some more.
+
 Sun Sep 19 23:56:15 2004  Matthias Clasen  <maclas@gmx.de>
 
        * glib/goption.c (g_option_context_parse): Call error_func
index 50b49640756a89569a74caf87fb231b1d3a5971b..0826a7c03d269e0311bc65d10968818e5422d4a7 100644 (file)
@@ -1,3 +1,12 @@
+Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>
+
+       Make GOption remove long options completely. (#153113, Robert Ögren)
+
+       * glib/goption.c (parse_long_option): Fix a wrong index.
+
+       * tests/option-test.c (ignore_test3): Test handling of unknown
+       options some more.
+
 Sun Sep 19 23:56:15 2004  Matthias Clasen  <maclas@gmx.de>
 
        * glib/goption.c (g_option_context_parse): Call error_func
index 50b49640756a89569a74caf87fb231b1d3a5971b..0826a7c03d269e0311bc65d10968818e5422d4a7 100644 (file)
@@ -1,3 +1,12 @@
+Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>
+
+       Make GOption remove long options completely. (#153113, Robert Ögren)
+
+       * glib/goption.c (parse_long_option): Fix a wrong index.
+
+       * tests/option-test.c (ignore_test3): Test handling of unknown
+       options some more.
+
 Sun Sep 19 23:56:15 2004  Matthias Clasen  <maclas@gmx.de>
 
        * glib/goption.c (g_option_context_parse): Call error_func
index 50b49640756a89569a74caf87fb231b1d3a5971b..0826a7c03d269e0311bc65d10968818e5422d4a7 100644 (file)
@@ -1,3 +1,12 @@
+Mon Sep 20 00:13:48 2004  Matthias Clasen  <maclas@gmx.de>
+
+       Make GOption remove long options completely. (#153113, Robert Ögren)
+
+       * glib/goption.c (parse_long_option): Fix a wrong index.
+
+       * tests/option-test.c (ignore_test3): Test handling of unknown
+       options some more.
+
 Sun Sep 19 23:56:15 2004  Matthias Clasen  <maclas@gmx.de>
 
        * glib/goption.c (g_option_context_parse): Call error_func
index a2738a7a28dee8b9b12604a1efe756dd0a9e80dd..2b70730aaef1c6ea60e9c2f6834be7df587e266a 100644 (file)
@@ -711,7 +711,7 @@ parse_long_option (GOptionContext *context,
              gchar *value = NULL;
              gchar *option_name;
 
-             add_pending_null (context, &((*argv)[*index + 1]), NULL);
+             add_pending_null (context, &((*argv)[*index]), NULL);
              
              if (arg[len] == '=')
                value = arg + len + 1;
index 847119f0c796322c4f0a703ca5aec72dd641322a..39d6688bbd0d35c7e0b7f847dbf68036f075f73e 100644 (file)
@@ -13,6 +13,7 @@ gchar **array_test1_array;
 
 gboolean ignore_test1_boolean;
 gboolean ignore_test2_boolean;
+gchar *ignore_test3_string;
 
 gchar **
 split_string (const char *str, int *argc)
@@ -359,6 +360,61 @@ ignore_test2 (void)
   g_option_context_free (context);
 }
 
+void
+ignore_test3 (void)
+{
+  GOptionContext *context;
+  gboolean retval;
+  GError *error = NULL;
+  gchar **argv, **argv_copy;
+  int argc;
+  gchar *arg;
+  GOptionEntry entries [] =
+    { { "test", 0, 0, G_OPTION_ARG_STRING, &ignore_test3_string, NULL, NULL },
+      { NULL } };
+
+  context = g_option_context_new (NULL);
+  g_option_context_set_ignore_unknown_options (context, TRUE);
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  /* Now try parsing */
+  argv = split_string ("program --test foo --hello", &argc);
+  argv_copy = copy_stringv (argv, argc);
+  
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (retval);
+
+  /* Check array */
+  arg = join_stringv (argc, argv);
+  g_assert (strcmp (arg, "program --hello") == 0);
+
+  g_assert (strcmp (ignore_test3_string, "foo") == 0);
+  g_free (ignore_test3_string);
+
+  g_free (arg);
+  g_strfreev (argv_copy);
+  g_free (argv);
+
+  /* Try again */
+  argv = split_string ("program --test=foo --hello", &argc);
+  argv_copy = copy_stringv (argv, argc);
+  
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (retval);
+
+  /* Check array */
+  arg = join_stringv (argc, argv);
+  g_assert (strcmp (arg, "program --hello") == 0);
+
+  g_assert (strcmp (ignore_test3_string, "foo") == 0);
+  g_free (ignore_test3_string);
+
+  g_free (arg);
+  g_strfreev (argv_copy);
+  g_free (argv);
+  g_option_context_free (context);
+}
+
 void
 array_test1 (void)
 {
@@ -460,6 +516,7 @@ main (int argc, char **argv)
   /* Test ignoring options */
   ignore_test1 ();
   ignore_test2 ();
+  ignore_test3 ();
 
   add_test1 ();