From 7b70e24179dd4fe77a43550dcd16367a963d5b96 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 13 Jul 2005 13:31:30 +0000 Subject: [PATCH] Warn if a short name is not acceptable. 2005-07-13 Matthias Clasen * glib/goption.c (g_option_group_add_entries): Warn if a short name is not acceptable. --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-12 | 5 +++++ ChangeLog.pre-2-8 | 5 +++++ docs/reference/ChangeLog | 5 +++++ docs/reference/glib/tmpl/option.sgml | 4 +++- glib/goption.c | 18 ++++++++++++++++-- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59b77ae..ab584bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-07-13 Matthias Clasen + + * glib/goption.c (g_option_group_add_entries): Warn if a + short name is not acceptable. + 2005-07-12 Matthias Clasen * glib/goption.h (G_OPTION_FLAG_NOALIAS): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 59b77ae..ab584bd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2005-07-13 Matthias Clasen + + * glib/goption.c (g_option_group_add_entries): Warn if a + short name is not acceptable. + 2005-07-12 Matthias Clasen * glib/goption.h (G_OPTION_FLAG_NOALIAS): diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 59b77ae..ab584bd 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2005-07-13 Matthias Clasen + + * glib/goption.c (g_option_group_add_entries): Warn if a + short name is not acceptable. + 2005-07-12 Matthias Clasen * glib/goption.h (G_OPTION_FLAG_NOALIAS): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 59b77ae..ab584bd 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +2005-07-13 Matthias Clasen + + * glib/goption.c (g_option_group_add_entries): Warn if a + short name is not acceptable. + 2005-07-12 Matthias Clasen * glib/goption.h (G_OPTION_FLAG_NOALIAS): diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f89f4dc..283591a 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2005-07-13 Matthias Clasen + + * glib/tmpl/option.sgml: Document that short names must + be printable ASCII characters != '-'. + 2005-07-08 Matthias Clasen * === Released 2.7.2 === diff --git a/docs/reference/glib/tmpl/option.sgml b/docs/reference/glib/tmpl/option.sgml index 3014b3a..b48dc58 100644 --- a/docs/reference/glib/tmpl/option.sgml +++ b/docs/reference/glib/tmpl/option.sgml @@ -316,7 +316,9 @@ g_option_context_add_main_entries() or g_option_group_add_entries(). specify the option as --groupname-long_name. @short_name: If an option has a short name, it can be specified - -short_name in a commandline. + -short_name in a commandline. @short_name must be + a printable ASCII character different from '-', or zero if the option has no + short name. @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 diff --git a/glib/goption.c b/glib/goption.c index b0536e2..378e7a1 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -1649,16 +1649,30 @@ void g_option_group_add_entries (GOptionGroup *group, const GOptionEntry *entries) { - gint n_entries; + gint i, n_entries; g_return_if_fail (entries != NULL); - for (n_entries = 0; entries[n_entries].long_name != NULL; n_entries++); + for (n_entries = 0; entries[n_entries].long_name != NULL; n_entries++) ; group->entries = g_renew (GOptionEntry, group->entries, group->n_entries + n_entries); memcpy (group->entries + group->n_entries, entries, sizeof (GOptionEntry) * n_entries); + for (i = group->n_entries; i < group->n_entries + n_entries; i++) + { + gchar c = group->entries[i].short_name; + + if (c) + { + if (c == '-' || !g_ascii_isprint (c)) + { + g_warning (G_STRLOC": ignoring invalid short option '%c' (%d)", c, c); + group->entries[i].short_name = 0; + } + } + } + group->n_entries += n_entries; } -- 2.7.4