glib r6377 - in trunk: . glib glib/tests



Author: lminier
Date: Fri Jan 25 17:49:53 2008
New Revision: 6377
URL: http://svn.gnome.org/viewvc/glib?rev=6377&view=rev

Log:
2008-01-25  LoÃc Minier  <lool dooz org>

       * glib/goption.c: (group_has_visible_entries),
       (group_list_has_visible_entires), (g_option_context_get_help): Pass
       context down the implementation to check for the main_group.
       Bug #510292.
       * glib/tests/option-context.c:
       Don't set G_OPTION_FLAG_IN_MAIN in main_entries
       (group_captions): only create group when actually adding it to the
       context; add an exit(0) to make sure the test succeeds.


Modified:
   trunk/ChangeLog
   trunk/glib/goption.c
   trunk/glib/tests/option-context.c

Modified: trunk/glib/goption.c
==============================================================================
--- trunk/glib/goption.c	(original)
+++ trunk/glib/goption.c	Fri Jan 25 17:49:53 2008
@@ -521,12 +521,14 @@
 }
 
 static gboolean
-group_has_visible_entries (GOptionGroup *group,
+group_has_visible_entries (GOptionContext *context,
+                           GOptionGroup *group,
                            gboolean      main_entries)
 {
   GOptionFlags reject_filter = G_OPTION_FLAG_HIDDEN;
   GOptionEntry *entry;
   gint i, l;
+  gboolean main_group = group == context->main_group;
 
   if (!main_entries)
     reject_filter |= G_OPTION_FLAG_IN_MAIN;
@@ -535,7 +537,7 @@
     {
       entry = &group->entries[i];
 
-      if (main_entries && !(entry->flags & G_OPTION_FLAG_IN_MAIN))
+      if (main_entries && !main_group && !(entry->flags & G_OPTION_FLAG_IN_MAIN))
         continue;
       if (!(entry->flags & reject_filter))
         return TRUE;
@@ -545,12 +547,14 @@
 }
 
 static gboolean
-group_list_has_visible_entires (GList    *group_list,
-                                gboolean  main_entries)
+group_list_has_visible_entires (GOptionContext *context,
+                                GList          *group_list,
+                                gboolean       main_entries)
 {
   while (group_list)
     {
-      if (group_has_visible_entries (group_list->data, main_entries))
+      gboolean is_main_group = context->main_group == group_list->data;
+      if (group_has_visible_entries (context, group_list->data, main_entries))
         return TRUE;
 
       group_list = group_list->next;
@@ -726,7 +730,7 @@
 	{
 	  GOptionGroup *group = list->data;
 
-	  if (group_has_visible_entries (group, FALSE))
+	  if (group_has_visible_entries (context, group, FALSE))
 	    g_string_append_printf (string, "  --help-%-*s %s\n",
 				    max_length - 5, group->name,
 				    TRANSLATE (group, group->help_description));
@@ -741,7 +745,7 @@
     {
       /* Print a certain group */
 
-      if (group_has_visible_entries (group, FALSE))
+      if (group_has_visible_entries (context, group, FALSE))
         {
           g_string_append (string, TRANSLATE (group, group->description));
           g_string_append (string, "\n");
@@ -760,7 +764,7 @@
 	{
 	  GOptionGroup *group = list->data;
 
-	  if (group_has_visible_entries (group, FALSE))
+	  if (group_has_visible_entries (context, group, FALSE))
 	    {
 	      g_string_append (string, group->description);
 	      g_string_append (string, "\n");
@@ -777,8 +781,8 @@
   
   /* Print application options if --help or --help-all has been specified */
   if ((main_help || !group) &&
-      (group_has_visible_entries (context->main_group, TRUE) ||
-       group_list_has_visible_entires (context->groups, TRUE)))
+      (group_has_visible_entries (context, context->main_group, TRUE) ||
+       group_list_has_visible_entires (context, context->groups, TRUE)))
     {
       list = context->groups;
 

Modified: trunk/glib/tests/option-context.c
==============================================================================
--- trunk/glib/tests/option-context.c	(original)
+++ trunk/glib/tests/option-context.c	Fri Jan 25 17:49:53 2008
@@ -21,6 +21,8 @@
  */
 #include <glib/gtestutils.h>
 
+#include <stdlib.h>
+
 static void
 group_captions (void)
 {
@@ -28,7 +30,7 @@
 
   GOptionEntry main_entries[] = {
     { "main-switch", 0,
-      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_IN_MAIN,
+      G_OPTION_FLAG_NO_ARG,
       G_OPTION_ARG_NONE, NULL,
       "A switch that is in the main group", NULL },
     { NULL }
@@ -52,19 +54,20 @@
       gboolean have_test_entries = (0 != (i & 2));
 
       GOptionContext *options;
-      GOptionGroup   *group;
+      GOptionGroup   *group = NULL;
 
       options = g_option_context_new (NULL);
-      group = g_option_group_new ("test", "Test Options",
-                                  "Show all test options",
-                                  NULL, NULL);
 
       if (have_main_entries)
         g_option_context_add_main_entries (options, main_entries, NULL);
       if (have_test_entries)
-        g_option_group_add_entries (group, group_entries);
-
-      g_option_context_add_group (options, group);
+        {
+          group = g_option_group_new ("test", "Test Options",
+                                      "Show all test options",
+                                      NULL, NULL);
+          g_option_context_add_group (options, group);
+          g_option_group_add_entries (group, group_entries);
+        }
 
       for (j = 0; j < G_N_ELEMENTS (help_variants); ++j)
         {
@@ -78,9 +81,10 @@
             {
               gchar **argv = args;
               gint    argc = 2;
+              GError *error = NULL;
 
-              g_option_context_parse (options, &argc, &argv, NULL);
-              g_assert_not_reached ();
+              g_option_context_parse (options, &argc, &argv, &error);
+              exit(0);
             }
           else
             {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]