Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Warn if a short name is not acceptable.
Browse files Browse the repository at this point in the history
2005-07-13  Matthias Clasen  <mclasen@redhat.com>

	* glib/goption.c (g_option_group_add_entries): Warn if a
	short name is not acceptable.
  • Loading branch information
Matthias Clasen authored and Matthias Clasen committed Jul 13, 2005
1 parent 138b6c9 commit 7b70e24
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2005-07-13 Matthias Clasen <mclasen@redhat.com>

* glib/goption.c (g_option_group_add_entries): Warn if a
short name is not acceptable.

2005-07-12 Matthias Clasen <mclasen@redhat.com>

* glib/goption.h (G_OPTION_FLAG_NOALIAS):
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.pre-2-10
@@ -1,3 +1,8 @@
2005-07-13 Matthias Clasen <mclasen@redhat.com>

* glib/goption.c (g_option_group_add_entries): Warn if a
short name is not acceptable.

2005-07-12 Matthias Clasen <mclasen@redhat.com>

* glib/goption.h (G_OPTION_FLAG_NOALIAS):
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.pre-2-12
@@ -1,3 +1,8 @@
2005-07-13 Matthias Clasen <mclasen@redhat.com>

* glib/goption.c (g_option_group_add_entries): Warn if a
short name is not acceptable.

2005-07-12 Matthias Clasen <mclasen@redhat.com>

* glib/goption.h (G_OPTION_FLAG_NOALIAS):
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.pre-2-8
@@ -1,3 +1,8 @@
2005-07-13 Matthias Clasen <mclasen@redhat.com>

* glib/goption.c (g_option_group_add_entries): Warn if a
short name is not acceptable.

2005-07-12 Matthias Clasen <mclasen@redhat.com>

* glib/goption.h (G_OPTION_FLAG_NOALIAS):
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/ChangeLog
@@ -1,3 +1,8 @@
2005-07-13 Matthias Clasen <mclasen@redhat.com>

* glib/tmpl/option.sgml: Document that short names must
be printable ASCII characters != '-'.

2005-07-08 Matthias Clasen <mclasen@redhat.com>

* === Released 2.7.2 ===
Expand Down
4 changes: 3 additions & 1 deletion docs/reference/glib/tmpl/option.sgml
Expand Up @@ -316,7 +316,9 @@ g_option_context_add_main_entries() or g_option_group_add_entries().
specify the option as
--<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.
-<replaceable>short_name</replaceable> 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
Expand Down
18 changes: 16 additions & 2 deletions glib/goption.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7b70e24

Please sign in to comment.