? tests/hum
Index: docs/reference/glib/tmpl/option.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/option.sgml,v
retrieving revision 1.10
diff -u -r1.10 option.sgml
--- docs/reference/glib/tmpl/option.sgml	18 Jun 2005 04:55:26 -0000	1.10
+++ docs/reference/glib/tmpl/option.sgml	26 Jun 2005 15:28:04 -0000
@@ -266,13 +266,7 @@
    <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). Since 2.8
-@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. Since 2.8
-
+   
 <!-- ##### MACRO G_OPTION_REMAINING ##### -->
 <para>
 If a long option in the main group has this name, it is not treated as a 
Index: glib/goption.c
===================================================================
RCS file: /cvs/gnome/glib/glib/goption.c,v
retrieving revision 1.43
diff -u -r1.43 goption.c
--- glib/goption.c	22 Jun 2005 17:09:31 -0000	1.43
+++ glib/goption.c	26 Jun 2005 15:28:06 -0000
@@ -33,10 +33,6 @@
 
 #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)->arg == G_OPTION_ARG_CALLBACK &&  \
-                        ((entry)->flags & G_OPTION_FLAG_NO_ARG)))
-
 typedef struct 
 {
   GOptionArg arg_type;
@@ -397,7 +393,7 @@
       if (entry->short_name)
 	len += 4;
       
-      if (!NO_ARG (entry) && entry->arg_description)
+      if (entry->arg != G_OPTION_ARG_NONE && entry->arg_description)
 	len += 1 + g_utf8_strlen (TRANSLATE (group, entry->arg_description), -1);
       
       max_length = MAX (max_length, len);
@@ -728,7 +724,7 @@
     case G_OPTION_ARG_STRING:
       {
 	gchar *data;
-
+	
 	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
 
 	if (!data)
@@ -747,7 +743,7 @@
     case G_OPTION_ARG_STRING_ARRAY:
       {
 	gchar *data;
-	
+
 	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
 
 	if (!data)
@@ -853,22 +849,11 @@
       {
 	gchar *data;
 	gboolean retval;
-	
-	if (entry->flags & G_OPTION_FLAG_NO_ARG)
+
+	if (!value)
 	  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 (!(entry->flags & G_OPTION_FLAG_NO_ARG) && !data)
-	  return FALSE;
+	  data = g_strdup (value);
 
 	retval = (* (GOptionArgFunc) entry->arg_data) (option_name, data, group->user_data, error);
 	
@@ -902,15 +887,11 @@
     {
       if (arg == group->entries[j].short_name)
 	{
-	  if (NO_ARG (&group->entries[j]))
-	    {
-	      gchar *option_name;
+	  if (group->entries[j].arg == G_OPTION_ARG_NONE)
 
-	      option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
+	    {
 	      parse_arg (context, group, &group->entries[j],
-			 NULL, option_name, error);
-	      g_free (option_name);
-	      
+			 NULL, NULL, error);
 	      *parsed = TRUE;
 	    }
 	  else
@@ -929,9 +910,39 @@
 	      
 	      if (index < *argc - 1)
 		{
-		  value = (*argv)[index + 1];
-		  add_pending_null (context, &((*argv)[index + 1]), NULL);
-		  *new_index = index + 1;
+		  if (!group->entries[j].arg == G_OPTION_ARG_CALLBACK)	
+		    {    
+		      value = (*argv)[index + 1];
+		      add_pending_null (context, &((*argv)[index + 1]), NULL);
+		      *new_index = index+1;
+		    }
+		  else
+		    {
+                      if (strncmp ((*argv)[index + 1],"-",1) == 0) 
+		        {
+		          gboolean retval;
+		          retval = parse_arg (context, group, &group->entries[j],
+		              NULL, option_name, error);
+	  	          *parsed = TRUE;
+		          g_free (option_name);
+	   	          return retval;
+		        }
+		      else
+		        {
+		          value = (*argv)[index + 1];
+		          add_pending_null (context, &((*argv)[index + 1]), NULL);
+		          *new_index = index + 1;
+			}
+	            }
+		}
+	      else if (index >= *argc - 1 && group->entries[j].arg == G_OPTION_ARG_CALLBACK)
+		{
+		    gboolean retval;
+		    retval = parse_arg (context, group, &group->entries[j],
+		          NULL, option_name, error);
+	  	    *parsed = TRUE;
+		    g_free (option_name);
+	   	    return retval;
 		}
 	      else
 		{
@@ -974,16 +985,12 @@
       if (*index >= *argc)
 	return TRUE;
 
-      if (NO_ARG (&group->entries[j]) &&
+      if (group->entries[j].arg == G_OPTION_ARG_NONE &&
 	  strcmp (arg, group->entries[j].long_name) == 0)
 	{
-	  gchar *option_name;
 
-	  option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
 	  parse_arg (context, group, &group->entries[j],
-		     NULL, option_name, error);
-	  g_free(option_name);
-	  
+		     NULL, NULL, error);
 	  add_pending_null (context, &((*argv)[*index]), NULL);
 	  *parsed = TRUE;
 	}
@@ -1002,11 +1009,42 @@
 
 	      if (arg[len] == '=')
 		value = arg + len + 1;
-	      else if (*index < *argc - 1)
+	      else if (*index < *argc - 1) 
+		{
+		  if (!group->entries[j].arg == G_OPTION_ARG_CALLBACK)	
+		    {    
+		      value = (*argv)[*index + 1];
+		      add_pending_null (context, &((*argv)[*index + 1]), NULL);
+		      (*index)++;
+		    }
+		  else
+		    {
+                      if (strncmp ((*argv)[*index + 1],"-",1) == 0) 
+		        {
+		          gboolean retval;
+		          retval = parse_arg (context, group, &group->entries[j],
+		              NULL, option_name, error);
+	  	          *parsed = TRUE;
+		          g_free (option_name);
+	   	          return retval;
+		        }
+		      else
+		        {
+		          value = (*argv)[*index + 1];
+		          add_pending_null (context, &((*argv)[*index + 1]), NULL);
+		          (*index)++;
+			}
+	            }
+		}
+	      else if (*index >= *argc - 1 &&
+		       group->entries[j].arg == G_OPTION_ARG_CALLBACK)
 		{
-		  value = (*argv)[*index + 1];
-		  add_pending_null (context, &((*argv)[*index + 1]), NULL);
-		  (*index)++;
+		    gboolean retval;
+		    retval = parse_arg (context, group, &group->entries[j],
+		          NULL, option_name, error);
+	  	    *parsed = TRUE;
+		    g_free (option_name);
+	   	    return retval;
 		}
 	      else
 		{
@@ -1025,7 +1063,7 @@
 
 	      g_free (option_name);
 	      *parsed = TRUE;
-	    }
+	    } 
 	}
     }
   
Index: glib/goption.h
===================================================================
RCS file: /cvs/gnome/glib/glib/goption.h,v
retrieving revision 1.9
diff -u -r1.9 goption.h
--- glib/goption.h	18 Jun 2005 04:55:25 -0000	1.9
+++ glib/goption.h	26 Jun 2005 15:28:06 -0000
@@ -32,11 +32,9 @@
 
 typedef enum
 {
-  G_OPTION_FLAG_HIDDEN       = 1 << 0,
-  G_OPTION_FLAG_IN_MAIN      = 1 << 1,
-  G_OPTION_FLAG_REVERSE      = 1 << 2,
-  G_OPTION_FLAG_NO_ARG       = 1 << 3,
-  G_OPTION_FLAG_FILENAME     = 1 << 4
+  G_OPTION_FLAG_HIDDEN		= 1 << 0,
+  G_OPTION_FLAG_IN_MAIN		= 1 << 1,
+  G_OPTION_FLAG_REVERSE		= 1 << 2,
 } GOptionFlags;
 
 typedef enum
Index: tests/option-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/option-test.c,v
retrieving revision 1.13
diff -u -r1.13 option-test.c
--- tests/option-test.c	18 Jun 2005 04:55:26 -0000	1.13
+++ tests/option-test.c	26 Jun 2005 15:28:08 -0000
@@ -9,8 +9,9 @@
 gchar *arg_test2_string;
 gchar *arg_test3_filename;
 
-gchar *callback_test1_string;
-gboolean callback_test2_int;
+gboolean callback_test_int;
+gchar *callback_test_string;
+gboolean callback_test_boolean;
 
 gchar **array_test1_array;
 
@@ -331,7 +332,7 @@
 callback_parse1 (const gchar *option_name, const gchar *value,
 		 gpointer data, GError **error)
 {
-	callback_test1_string = g_strdup (value);
+	callback_test_int++;
 	return TRUE;
 }
 
@@ -351,14 +352,12 @@
   g_option_context_add_main_entries (context, entries, NULL);
 
   /* Now try parsing */
-  argv = split_string ("program --test foo.txt", &argc);
+  argv = split_string ("program --test --test", &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_assert (callback_test_int == 2);
   
   g_strfreev (argv);
   g_option_context_free (context);
@@ -368,7 +367,11 @@
 callback_parse2 (const gchar *option_name, const gchar *value,
 		 gpointer data, GError **error)
 {
-	callback_test2_int++;
+	callback_test_boolean = TRUE;
+	if (value)
+		callback_test_string = g_strdup (value);
+	else
+		callback_test_string = NULL;
 	return TRUE;
 }
 
@@ -381,19 +384,54 @@
   gchar **argv;
   int argc;
   GOptionEntry entries [] =
-    { { "test", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, callback_parse2, NULL, NULL },
+    { { "test", 0, 0, 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);
+  argv = split_string ("program --test foo.txt", &argc);
   
   retval = g_option_context_parse (context, &argc, &argv, &error);
   g_assert (retval);
 
-  g_assert (callback_test2_int == 2);
+  g_assert (strcmp (callback_test_string, "foo.txt") == 0);
+  
+  g_assert (callback_test_boolean);
+
+  g_free (callback_test_string);
+  
+  g_strfreev (argv);
+  g_option_context_free (context);
+}
+
+void
+callback_test3 (void)
+{
+  GOptionContext *context;
+  gboolean retval;
+  GError *error = NULL;
+  gchar **argv;
+  int argc;
+  GOptionEntry entries [] =
+    { { "test", 0, 0, 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", &argc);
+  
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (retval);
+
+  g_assert (callback_test_string == NULL);
+  
+  g_assert (callback_test_boolean);
+
+  g_free (callback_test_string);
   
   g_strfreev (argv);
   g_option_context_free (context);
@@ -1015,6 +1053,7 @@
   /* Test callback args */
   callback_test1 ();
   callback_test2 ();
+  callback_test3 ();
 
   /* Test ignoring options */
   ignore_test1 ();
