mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-12 10:45:13 +01:00
Take main group options into account when calculating column size.
2005-02-10 Matthias Clasen <mclasen@redhat.com> * glib/goption.c (print_help): Take main group options into account when calculating column size. (#166921) (g_option_context_parse): Accept -? as documented. (#166977)
This commit is contained in:
parent
de2763c99a
commit
1795e0aeb0
@ -1,5 +1,10 @@
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
2005-02-10 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/goption.c (print_help): Take main group options into
|
||||
account when calculating column size. (#166921)
|
||||
(g_option_context_parse): Accept -? as documented. (#166977)
|
||||
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
* glib/gkeyfile.c (find_file_in_data_dirs): Don't leak path
|
||||
here. (#166801, Kjartan Maraas)
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
2005-02-10 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/goption.c (print_help): Take main group options into
|
||||
account when calculating column size. (#166921)
|
||||
(g_option_context_parse): Accept -? as documented. (#166977)
|
||||
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
* glib/gkeyfile.c (find_file_in_data_dirs): Don't leak path
|
||||
here. (#166801, Kjartan Maraas)
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
2005-02-10 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/goption.c (print_help): Take main group options into
|
||||
account when calculating column size. (#166921)
|
||||
(g_option_context_parse): Accept -? as documented. (#166977)
|
||||
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
* glib/gkeyfile.c (find_file_in_data_dirs): Don't leak path
|
||||
here. (#166801, Kjartan Maraas)
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
2005-02-10 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/goption.c (print_help): Take main group options into
|
||||
account when calculating column size. (#166921)
|
||||
(g_option_context_parse): Accept -? as documented. (#166977)
|
||||
|
||||
2005-02-09 Matthias Clasen <mclasen@redhat.com>
|
||||
* glib/gkeyfile.c (find_file_in_data_dirs): Don't leak path
|
||||
here. (#166801, Kjartan Maraas)
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
2005-02-10 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/tmpl/option.sgml: Fix a typo. (#166985)
|
||||
|
||||
2005-02-07 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/glib-sections.txt: Add g_listenv.
|
||||
|
@ -56,7 +56,7 @@ Usage:
|
||||
testtreemodel [OPTION...] - test tree model performance
|
||||
|
||||
Help Options:
|
||||
--help Show help options
|
||||
-?, --help Show help options
|
||||
--help-all Show all help options
|
||||
--help-gtk Show GTK+ Options
|
||||
|
||||
@ -299,7 +299,7 @@ g_option_context_add_main_entries() or g_option_group_add_entries().
|
||||
--<replaceable>groupname</replaceable>-<replaceable>long_name</replaceable>.
|
||||
@short_name: If an option has a short name, it can be specified
|
||||
-<replaceable>short_name</replaceable> in a commandline.
|
||||
@flags: Flags from #GOptionEntryFlags.
|
||||
@flags: Flags from #GOptionFlags.
|
||||
@arg: The type of the option, as a #GOptionArg.
|
||||
@arg_data: If the @arg type is %G_OPTION_ARG_CALLBACK, then @arg_data must
|
||||
point to a #GOptionArgFunc callback function, which will be called to handle
|
||||
|
101
glib/goption.c
101
glib/goption.c
@ -362,6 +362,35 @@ g_option_context_add_main_entries (GOptionContext *context,
|
||||
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,
|
||||
@ -393,11 +422,12 @@ print_entry (GOptionGroup *group,
|
||||
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];
|
||||
|
||||
@ -412,14 +442,15 @@ print_help (GOptionContext *context,
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,15 +460,16 @@ print_help (GOptionContext *context,
|
||||
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;
|
||||
}
|
||||
@ -446,7 +478,7 @@ print_help (GOptionContext *context,
|
||||
|
||||
list = context->groups;
|
||||
|
||||
max_length = g_utf8_strlen ("--help, -?", -1);
|
||||
max_length = g_utf8_strlen ("-?, --help", -1);
|
||||
|
||||
if (list)
|
||||
{
|
||||
@ -454,6 +486,12 @@ print_help (GOptionContext *context,
|
||||
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;
|
||||
@ -463,22 +501,8 @@ print_help (GOptionContext *context,
|
||||
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;
|
||||
}
|
||||
@ -490,18 +514,21 @@ print_help (GOptionContext *context,
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -548,7 +575,8 @@ print_help (GOptionContext *context,
|
||||
|
||||
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)
|
||||
{
|
||||
@ -1244,6 +1272,9 @@ g_option_context_parse (GOptionContext *context,
|
||||
|
||||
for (j = 0; j < strlen (arg); j++)
|
||||
{
|
||||
if (context->help_enabled && arg[j] == '?')
|
||||
print_help (context, TRUE, NULL);
|
||||
|
||||
parsed = FALSE;
|
||||
|
||||
if (context->main_group &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user