Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.1971
diff -u -r1.1971 ChangeLog
--- ChangeLog	10 Jun 2005 16:06:40 -0000	1.1971
+++ ChangeLog	10 Jun 2005 18:53:56 -0000
@@ -1,3 +1,12 @@
+2005-06-10  Dan Winship  <danw@novell.com>
+
+	* glib/goption.h: 
+	* glib/goption.c: Add G_OPTION_FLAG_NO_ARG and
+	G_OPTION_FLAG_FILENAME to allow greater control of
+	G_OPTION_ARG_CALLBACK options. (#302632)
+
+	* tests/option-test.c: test callback args
+
 2005-06-10  Matthias Clasen  <mclasen@redhat.com>
 
 	* configure.in: Bump version
Index: glib/goption.c
===================================================================
RCS file: /cvs/gnome/glib/glib/goption.c,v
retrieving revision 1.40
diff -u -r1.40 goption.c
--- glib/goption.c	9 Jun 2005 15:39:29 -0000	1.40
+++ glib/goption.c	10 Jun 2005 18:53:57 -0000
@@ -33,6 +33,8 @@
 
 #define TRANSLATE(group, str) (((group)->translate_func ? (* (group)->translate_func) ((str), (group)->translate_data) : (str)))
 
+#define NO_ARG(entry) ((entry)->arg == G_OPTION_ARG_NONE || ((entry)->flags & G_OPTION_FLAG_NO_ARG))
+
 typedef struct 
 {
   GOptionArg arg_type;
@@ -393,7 +395,7 @@
       if (entry->short_name)
 	len += 4;
       
-      if (entry->arg != G_OPTION_ARG_NONE && entry->arg_description)
+      if (!NO_ARG (entry) && entry->arg_description)
 	len += 1 + g_utf8_strlen (TRANSLATE (group, entry->arg_description), -1);
       
       max_length = MAX (max_length, len);
@@ -847,17 +849,28 @@
       }
     case G_OPTION_ARG_CALLBACK:
       {
-	gchar *tmp;
+	gchar *data;
 	gboolean retval;
 	
-	tmp = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+	if (entry->flags & G_OPTION_FLAG_NO_ARG)
+	  data = NULL;
+	else if (entry->flags & G_OPTION_FLAG_FILENAME)
+	  {
+#ifdef G_OS_WIN32
+	    data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+#else
+	    data = g_strdup (value);
+#endif
+	  }
+	else
+	  data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
 
-	if (!value)
+	if (!(entry->flags & G_OPTION_FLAG_NO_ARG) && !data)
 	  return FALSE;
 
-	retval = (* (GOptionArgFunc) entry->arg_data) (option_name, tmp, group->user_data, error);
+	retval = (* (GOptionArgFunc) entry->arg_data) (option_name, data, group->user_data, error);
 	
-	g_free (tmp);
+	g_free (data);
 	
 	return retval;
 	
@@ -887,7 +900,7 @@
     {
       if (arg == group->entries[j].short_name)
 	{
-	  if (group->entries[j].arg == G_OPTION_ARG_NONE)
+	  if (NO_ARG (&group->entries[j]))
 	    {
 	      parse_arg (context, group, &group->entries[j],
 			 NULL, NULL, error);
@@ -954,7 +967,7 @@
       if (*index >= *argc)
 	return TRUE;
 
-      if (group->entries[j].arg == G_OPTION_ARG_NONE &&
+      if (NO_ARG (&group->entries[j]) &&
 	  strcmp (arg, group->entries[j].long_name) == 0)
 	{
 	  parse_arg (context, group, &group->entries[j],
Index: glib/goption.h
===================================================================
RCS file: /cvs/gnome/glib/glib/goption.h,v
retrieving revision 1.8
diff -u -r1.8 goption.h
--- glib/goption.h	23 Nov 2004 18:22:55 -0000	1.8
+++ glib/goption.h	10 Jun 2005 18:53:57 -0000
@@ -34,7 +34,9 @@
 {
   G_OPTION_FLAG_HIDDEN       = 1 << 0,
   G_OPTION_FLAG_IN_MAIN      = 1 << 1,
-  G_OPTION_FLAG_REVERSE	     = 1 << 2
+  G_OPTION_FLAG_REVERSE      = 1 << 2,
+  G_OPTION_FLAG_NO_ARG       = 1 << 3,
+  G_OPTION_FLAG_FILENAME     = 1 << 4
 } GOptionFlags;
 
 typedef enum
Index: tests/option-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/option-test.c,v
retrieving revision 1.12
diff -u -r1.12 option-test.c
--- tests/option-test.c	27 May 2005 18:30:34 -0000	1.12
+++ tests/option-test.c	10 Jun 2005 18:53:57 -0000
@@ -9,6 +9,9 @@
 gchar *arg_test2_string;
 gchar *arg_test3_filename;
 
+gchar *callback_test1_string;
+gboolean callback_test2_int;
+
 gchar **array_test1_array;
 
 gboolean ignore_test1_boolean;
@@ -324,6 +327,78 @@
   g_option_context_free (context);
 }
 
+static gboolean
+callback_parse1 (const gchar *option_name, const gchar *value,
+		 gpointer data, GError **error)
+{
+	callback_test1_string = g_strdup (value);
+	return TRUE;
+}
+
+void
+callback_test1 (void)
+{
+  GOptionContext *context;
+  gboolean retval;
+  GError *error = NULL;
+  gchar **argv;
+  int argc;
+  GOptionEntry entries [] =
+    { { "test", 0, 0, G_OPTION_ARG_CALLBACK, callback_parse1, NULL, NULL },
+      { NULL } };
+  
+  context = g_option_context_new (NULL);
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  /* Now try parsing */
+  argv = split_string ("program --test foo.txt", &argc);
+  
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (retval);
+
+  g_assert (strcmp (callback_test1_string, "foo.txt") == 0);
+
+  g_free (callback_test1_string);
+  
+  g_strfreev (argv);
+  g_option_context_free (context);
+}
+
+static gboolean
+callback_parse2 (const gchar *option_name, const gchar *value,
+		 gpointer data, GError **error)
+{
+	callback_test2_int++;
+	return TRUE;
+}
+
+void
+callback_test2 (void)
+{
+  GOptionContext *context;
+  gboolean retval;
+  GError *error = NULL;
+  gchar **argv;
+  int argc;
+  GOptionEntry entries [] =
+    { { "test", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, callback_parse2, NULL, NULL },
+      { NULL } };
+  
+  context = g_option_context_new (NULL);
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  /* Now try parsing */
+  argv = split_string ("program --test --test", &argc);
+  
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (retval);
+
+  g_assert (callback_test2_int == 2);
+  
+  g_strfreev (argv);
+  g_option_context_free (context);
+}
+
 void
 ignore_test1 (void)
 {
@@ -936,6 +1011,10 @@
 
   /* Test string arrays */
   array_test1 ();
+
+  /* Test callback args */
+  callback_test1 ();
+  callback_test2 ();
 
   /* Test ignoring options */
   ignore_test1 ();
Index: docs/reference/ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/ChangeLog,v
retrieving revision 1.369
diff -u -r1.369 ChangeLog
--- docs/reference/ChangeLog	10 Jun 2005 15:48:21 -0000	1.369
+++ docs/reference/ChangeLog	10 Jun 2005 18:53:57 -0000
@@ -1,3 +1,8 @@
+2005-06-10  Dan Winship  <danw@novell.com>
+
+	* glib/tmpl/option.sgml (GOptionFlags): document
+	G_OPTION_FLAG_NO_ARG and G_OPTION_FLAG_FILENAME
+
 2005-06-10  Matthias Clasen  <mclasen@redhat.com>
 
 	* === Released 2.7.0 ===
Index: docs/reference/glib/tmpl/option.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/option.sgml,v
retrieving revision 1.9
diff -u -r1.9 option.sgml
--- docs/reference/glib/tmpl/option.sgml	5 May 2005 14:57:27 -0000	1.9
+++ docs/reference/glib/tmpl/option.sgml	10 Jun 2005 18:53:57 -0000
@@ -269,6 +269,12 @@
    <option>--help</option> output, even if it is defined in a group.
 @G_OPTION_FLAG_REVERSE: For options of the G_OPTION_ARG_NONE kind, this flag
    indicates that the sense of the option is reversed.
+@G_OPTION_FLAG_NO_ARG: For options of the G_OPTION_ARG_CALLBACK kind,
+   this flag indicates that the callback does not take any argument
+   (like a G_OPTION_ARG_NONE option).
+@G_OPTION_FLAG_FILENAME: For options of the G_OPTION_ARG_CALLBACK
+   kind, this flag indicates that the argument should be passed to the
+   callback in the GLib filename encoding rather than UTF-8.
 
 <!-- ##### MACRO G_OPTION_REMAINING ##### -->
 <para>
