g_option_group_set_translation_domain (context->main_group, translation_domain);
}
+static gint
+calculate_max_length (GOptionGroup *group)
+{
+ GOptionEntry *entry;
+ gint i, len, max_length;
+
+ max_length = 0;
+
+ for (i = 0; i < group->n_entries; i++)
+ {
+ entry = &group->entries[i];
+
+ if (entry->flags & G_OPTION_FLAG_HIDDEN)
+ continue;
+
+ len = g_utf8_strlen (entry->long_name, -1);
+
+ if (entry->short_name)
+ len += 4;
+
+ 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);
+ }
+
+ return max_length;
+}
+
static void
print_entry (GOptionGroup *group,
gint max_length,
static void
print_help (GOptionContext *context,
gboolean main_help,
- GOptionGroup *group)
+ GOptionGroup *group)
{
GList *list;
gint max_length, len;
gint i;
+ GOptionEntry *entry;
GHashTable *shadow_map;
gboolean seen[256];
{
for (i = 0; i < context->main_group->n_entries; i++)
{
+ entry = &context->main_group->entries[i];
g_hash_table_insert (shadow_map,
- (gpointer)context->main_group->entries[i].long_name,
- context->main_group->entries + i);
+ (gpointer)entry->long_name,
+ entry);
- if (seen[(guchar)context->main_group->entries[i].short_name])
- context->main_group->entries[i].short_name = 0;
+ if (seen[(guchar)entry->short_name])
+ entry->short_name = 0;
else
- seen[(guchar)context->main_group->entries[i].short_name] = TRUE;
+ seen[(guchar)entry->short_name] = TRUE;
}
}
GOptionGroup *group = list->data;
for (i = 0; i < group->n_entries; i++)
{
- if (g_hash_table_lookup (shadow_map, group->entries[i].long_name))
- group->entries[i].long_name = g_strdup_printf ("%s-%s", group->name, group->entries[i].long_name);
+ entry = &group->entries[i];
+ if (g_hash_table_lookup (shadow_map, entry->long_name))
+ entry->long_name = g_strdup_printf ("%s-%s", group->name, entry->long_name);
else
- g_hash_table_insert (shadow_map, (gpointer)group->entries[i].long_name, group->entries + i);
+ g_hash_table_insert (shadow_map, (gpointer)entry->long_name, entry);
- if (seen[(guchar)group->entries[i].short_name])
- group->entries[i].short_name = 0;
+ if (seen[(guchar)entry->short_name])
+ entry->short_name = 0;
else
- seen[(guchar)group->entries[i].short_name] = TRUE;
+ seen[(guchar)entry->short_name] = TRUE;
}
list = list->next;
}
list = context->groups;
- max_length = g_utf8_strlen ("--help, -?", -1);
+ max_length = g_utf8_strlen ("-?, --help", -1);
if (list)
{
max_length = MAX (max_length, len);
}
+ if (context->main_group)
+ {
+ len = calculate_max_length (context->main_group);
+ max_length = MAX (max_length, len);
+ }
+
while (list != NULL)
{
GOptionGroup *group = list->data;
max_length = MAX (max_length, len);
/* Then we go through the entries */
- for (i = 0; i < group->n_entries; i++)
- {
- if (group->entries[i].flags & G_OPTION_FLAG_HIDDEN)
- continue;
-
- len = g_utf8_strlen (group->entries[i].long_name, -1);
-
- if (group->entries[i].short_name)
- len += 4;
-
- if (group->entries[i].arg != G_OPTION_ARG_NONE &&
- group->entries[i].arg_description)
- len += 1 + g_utf8_strlen (TRANSLATE (group, group->entries[i].arg_description), -1);
-
- max_length = MAX (max_length, len);
- }
+ len = calculate_max_length (group);
+ max_length = MAX (max_length, len);
list = list->next;
}
{
list = context->groups;
- g_print ("%s\n --%-*s %s\n",
- _("Help Options:"), max_length, "help", _("Show help options"));
+ g_print ("%s\n -%c, --%-*s %s\n",
+ _("Help Options:"), '?', max_length - 4, "help",
+ _("Show help options"));
/* We only want --help-all when there are groups */
if (list)
- g_print (" --%-*s %s\n", max_length, "help-all", _("Show all help options"));
-
+ g_print (" --%-*s %s\n", max_length, "help-all",
+ _("Show all help options"));
+
while (list)
{
GOptionGroup *group = list->data;
- g_print (" --help-%-*s %s\n", max_length - 5, group->name, TRANSLATE (group, group->help_description));
+ g_print (" --help-%-*s %s\n", max_length - 5, group->name,
+ TRANSLATE (group, group->help_description));
list = list->next;
}
if (context->main_group)
for (i = 0; i < context->main_group->n_entries; i++)
- print_entry (context->main_group, max_length, &context->main_group->entries[i]);
+ print_entry (context->main_group, max_length,
+ &context->main_group->entries[i]);
while (list != NULL)
{
for (j = 0; j < strlen (arg); j++)
{
+ if (context->help_enabled && arg[j] == '?')
+ print_help (context, TRUE, NULL);
+
parsed = FALSE;
if (context->main_group &&