mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-15 04:05:11 +01:00
Allow G_OPTION_ARG_CALLBACK for G_OPTION_REMAINING. (#437297, Dave Benson)
2007-05-11 Matthias Clasen <mclasen@redhat.com> * glib/goption.c: Allow G_OPTION_ARG_CALLBACK for G_OPTION_REMAINING. (#437297, Dave Benson) * tests/option-test.c: Add a test for this. svn path=/trunk/; revision=5487
This commit is contained in:
parent
ec11b71411
commit
8f88ba6ffa
@ -1,3 +1,10 @@
|
|||||||
|
2007-05-11 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/goption.c: Allow G_OPTION_ARG_CALLBACK for
|
||||||
|
G_OPTION_REMAINING. (#437297, Dave Benson)
|
||||||
|
|
||||||
|
* tests/option-test.c: Add a test for this.
|
||||||
|
|
||||||
2007-05-04 Dan Winship <danw@novell.com>
|
2007-05-04 Dan Winship <danw@novell.com>
|
||||||
|
|
||||||
* glib/gkeyfile.c (g_key_file_get_boolean)
|
* glib/gkeyfile.c (g_key_file_get_boolean)
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2007-05-11 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/tmpl/option.sgml: Document new G_OPTION_ARG_REMAINING
|
||||||
|
functionality.
|
||||||
|
|
||||||
2007-05-03 Behdad Esfahbod <behdad@gnome.org>
|
2007-05-03 Behdad Esfahbod <behdad@gnome.org>
|
||||||
|
|
||||||
* glib/glib-sections.txt:
|
* glib/glib-sections.txt:
|
||||||
|
@ -378,7 +378,8 @@ Flags which modify individual options.
|
|||||||
If a long option in the main group has this name, it is not treated as a
|
If a long option in the main group has this name, it is not treated as a
|
||||||
regular option. Instead it collects all non-option arguments which would
|
regular option. Instead it collects all non-option arguments which would
|
||||||
otherwise be left in <literal>argv</literal>. The option must be of type
|
otherwise be left in <literal>argv</literal>. The option must be of type
|
||||||
%G_OPTION_ARG_STRING_ARRAY or %G_OPTION_ARG_FILENAME_ARRAY.
|
%G_OPTION_ARG_CALLBACK, %G_OPTION_ARG_STRING_ARRAY
|
||||||
|
or %G_OPTION_ARG_FILENAME_ARRAY.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -1355,7 +1355,8 @@ parse_remaining_arg (GOptionContext *context,
|
|||||||
if (group->entries[j].long_name[0])
|
if (group->entries[j].long_name[0])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_return_val_if_fail (group->entries[j].arg == G_OPTION_ARG_STRING_ARRAY ||
|
g_return_val_if_fail (group->entries[j].arg == G_OPTION_ARG_CALLBACK ||
|
||||||
|
group->entries[j].arg == G_OPTION_ARG_STRING_ARRAY ||
|
||||||
group->entries[j].arg == G_OPTION_ARG_FILENAME_ARRAY, FALSE);
|
group->entries[j].arg == G_OPTION_ARG_FILENAME_ARRAY, FALSE);
|
||||||
|
|
||||||
add_pending_null (context, &((*argv)[*index]), NULL);
|
add_pending_null (context, &((*argv)[*index]), NULL);
|
||||||
|
@ -788,6 +788,48 @@ callback_test_optional_8 (void)
|
|||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GPtrArray *callback_remaining_args;
|
||||||
|
static gboolean
|
||||||
|
callback_remaining_test1_callback (const gchar *option_name, const gchar *value,
|
||||||
|
gpointer data, GError **error)
|
||||||
|
{
|
||||||
|
g_ptr_array_add (callback_remaining_args, g_strdup (value));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
callback_remaining_test1 (void)
|
||||||
|
{
|
||||||
|
GOptionContext *context;
|
||||||
|
gboolean retval;
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar **argv;
|
||||||
|
int argc;
|
||||||
|
GOptionEntry entries [] =
|
||||||
|
{ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_CALLBACK, callback_remaining_test1_callback, NULL, NULL },
|
||||||
|
{ NULL } };
|
||||||
|
|
||||||
|
callback_remaining_args = g_ptr_array_new ();
|
||||||
|
context = g_option_context_new (NULL);
|
||||||
|
g_option_context_add_main_entries (context, entries, NULL);
|
||||||
|
|
||||||
|
/* Now try parsing */
|
||||||
|
argv = split_string ("program foo.txt blah.txt", &argc);
|
||||||
|
|
||||||
|
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||||
|
g_assert (retval);
|
||||||
|
|
||||||
|
g_assert (callback_remaining_args->len == 2);
|
||||||
|
g_assert (strcmp (callback_remaining_args->pdata[0], "foo.txt") == 0);
|
||||||
|
g_assert (strcmp (callback_remaining_args->pdata[1], "blah.txt") == 0);
|
||||||
|
|
||||||
|
g_ptr_array_foreach (callback_remaining_args, (GFunc) g_free, NULL);
|
||||||
|
g_ptr_array_free (callback_remaining_args, TRUE);
|
||||||
|
|
||||||
|
g_strfreev (argv);
|
||||||
|
g_option_context_free (context);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ignore_test1 (void)
|
ignore_test1 (void)
|
||||||
{
|
{
|
||||||
@ -1421,6 +1463,9 @@ main (int argc, char **argv)
|
|||||||
callback_test_optional_7 ();
|
callback_test_optional_7 ();
|
||||||
callback_test_optional_8 ();
|
callback_test_optional_8 ();
|
||||||
|
|
||||||
|
/* Test callback with G_OPTION_REMAINING */
|
||||||
|
callback_remaining_test1 ();
|
||||||
|
|
||||||
/* Test ignoring options */
|
/* Test ignoring options */
|
||||||
ignore_test1 ();
|
ignore_test1 ();
|
||||||
ignore_test2 ();
|
ignore_test2 ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user