From 08fe920a50ac54615e14c0fea14b14501d0d21a1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 20 Sep 2004 04:15:38 +0000 Subject: [PATCH 1/1] =?utf8?q?Make=20GOption=20remove=20long=20options=20c?= =?utf8?q?ompletely.=20(#153113,=20Robert=20=C3=96gren)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Mon Sep 20 00:13:48 2004 Matthias Clasen 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 | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-12 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ glib/goption.c | 2 +- tests/option-test.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 103 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 50b4964..0826a7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Sep 20 00:13:48 2004 Matthias Clasen + + 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 * glib/goption.c (g_option_context_parse): Call error_func diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 50b4964..0826a7c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Mon Sep 20 00:13:48 2004 Matthias Clasen + + 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 * glib/goption.c (g_option_context_parse): Call error_func diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 50b4964..0826a7c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,12 @@ +Mon Sep 20 00:13:48 2004 Matthias Clasen + + 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 * glib/goption.c (g_option_context_parse): Call error_func diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 50b4964..0826a7c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Mon Sep 20 00:13:48 2004 Matthias Clasen + + 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 * glib/goption.c (g_option_context_parse): Call error_func diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 50b4964..0826a7c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Mon Sep 20 00:13:48 2004 Matthias Clasen + + 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 * glib/goption.c (g_option_context_parse): Call error_func diff --git a/glib/goption.c b/glib/goption.c index a2738a7..2b70730 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -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; diff --git a/tests/option-test.c b/tests/option-test.c index 847119f..39d6688 100644 --- a/tests/option-test.c +++ b/tests/option-test.c @@ -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) @@ -360,6 +361,61 @@ ignore_test2 (void) } 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) { GOptionContext *context; @@ -460,6 +516,7 @@ main (int argc, char **argv) /* Test ignoring options */ ignore_test1 (); ignore_test2 (); + ignore_test3 (); add_test1 (); -- 2.7.4