diff --git a/glib/goption.c b/glib/goption.c
index 167a7df46..bf1283a53 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -10,7 +10,7 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
@@ -18,29 +18,31 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
/**
* SECTION:option
* @Short_description: parses commandline options
* @Title: Commandline option parser
- *
- * The GOption commandline parser is intended to be a simpler replacement for the
- * popt library. It supports short and long commandline options, as shown in the
- * following example:
- *
+ *
+ * The GOption commandline parser is intended to be a simpler replacement
+ * for the popt library. It supports short and long commandline options,
+ * as shown in the following example:
+ *
* testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2
*
- * The example demonstrates a number of features of the GOption commandline parser
+ * The example demonstrates a number of features of the GOption
+ * commandline parser
*
* Options can be single letters, prefixed by a single dash. Multiple
* short options can be grouped behind a single dash.
*
* Long options are prefixed by two consecutive dashes.
*
- * Options can have an extra argument, which can be a number, a string or a
- * filename. For long options, the extra argument can be appended with an
- * equals sign after the option name, which is useful if the extra argument
- * starts with a dash, which would otherwise cause it to be interpreted
- * as another option.
+ * Options can have an extra argument, which can be a number, a string or
+ * a filename. For long options, the extra argument can be appended with
+ * an equals sign after the option name, which is useful if the extra
+ * argument starts with a dash, which would otherwise cause it to be
+ * interpreted as another option.
*
* Non-option arguments are returned to the application as rest arguments.
*
@@ -49,32 +51,34 @@
* to the application as rest arguments.
*
*
- * Another important feature of GOption is that it can automatically generate
- * nicely formatted help output. Unless it is explicitly turned off with
- * g_option_context_set_help_enabled(), GOption will recognize the
- * , ,
- * and groupname options
- * (where groupname is the name of a #GOptionGroup)
- * and write a text similar to the one shown in the following example to stdout.
+ * Another important feature of GOption is that it can automatically
+ * generate nicely formatted help output. Unless it is explicitly turned
+ * off with g_option_context_set_help_enabled(), GOption will recognize
+ * the , ,
+ * and
+ * groupname options
+ * (where groupname is the name of a
+ * #GOptionGroup) and write a text similar to the one shown in the
+ * following example to stdout.
*
*
* Usage:
* testtreemodel [OPTION...] - test tree model performance
- *
+ *
* Help Options:
* -h, --help Show help options
* --help-all Show all help options
* --help-gtk Show GTK+ Options
- *
+ *
* Application Options:
* -r, --repeats=N Average over N repetitions
* -m, --max-size=M Test up to 2^M items
* --display=DISPLAY X display to use
* -v, --verbose Be verbose
- * -b, --beep Beep when done
+ * -b, --beep Beep when done
* --rand Randomize the data
*
- *
+ *
* GOption groups options in #GOptionGroups, which makes it easy to
* incorporate options from multiple sources. The intended use for this is
* to let applications collect option groups from the libraries it uses,
@@ -82,21 +86,22 @@
* to g_option_context_parse(). See gtk_get_option_group() for an example.
*
* If an option is declared to be of type string or filename, GOption takes
- * care of converting it to the right encoding; strings are returned in UTF-8,
- * filenames are returned in the GLib filename encoding. Note that this only
- * works if setlocale() has been called before g_option_context_parse().
- *
+ * care of converting it to the right encoding; strings are returned in
+ * UTF-8, filenames are returned in the GLib filename encoding. Note that
+ * this only works if setlocale() has been called before
+ * g_option_context_parse().
+ *
* Here is a complete example of setting up GOption to parse the example
* commandline above and produce the example help output.
- *
+ *
*
* static gint repeats = 2;
* static gint max_size = 8;
* static gboolean verbose = FALSE;
* static gboolean beep = FALSE;
* static gboolean rand = FALSE;
- *
- * static GOptionEntry entries[] =
+ *
+ * static GOptionEntry entries[] =
* {
* { "repeats", 'r', 0, G_OPTION_ARG_INT, &repeats, "Average over N repetitions", "N" },
* { "max-size", 'm', 0, G_OPTION_ARG_INT, &max_size, "Test up to 2^M items", "M" },
@@ -105,13 +110,13 @@
* { "rand", 0, 0, G_OPTION_ARG_NONE, &rand, "Randomize the data", NULL },
* { NULL }
* };
- *
- * int
+ *
+ * int
* main (int argc, char *argv[])
* {
* GError *error = NULL;
* GOptionContext *context;
- *
+ *
* context = g_option_context_new ("- test tree model performance");
* g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
* g_option_context_add_group (context, gtk_get_option_group (TRUE));
@@ -120,26 +125,25 @@
* g_print ("option parsing failed: %s\n", error->message);
* exit (1);
* }
- *
- * // ...
- *
+ *
+ * /* ... */
+ *
* }
*
*/
#include "config.h"
-#include "goption.h"
-#include "glib.h"
-#include "glibintl.h"
-#include "gprintf.h"
-
-
#include
#include
#include
#include
+#include "goption.h"
+
+#include "gprintf.h"
+#include "glibintl.h"
+
#define TRANSLATE(group, str) (((group)->translate_func ? (* (group)->translate_func) ((str), (group)->translate_data) : (str)))
#define NO_ARG(entry) ((entry)->arg == G_OPTION_ARG_NONE || \
@@ -149,11 +153,11 @@
#define OPTIONAL_ARG(entry) ((entry)->arg == G_OPTION_ARG_CALLBACK && \
(entry)->flags & G_OPTION_FLAG_OPTIONAL_ARG)
-typedef struct
+typedef struct
{
GOptionArg arg_type;
- gpointer arg_data;
- union
+ gpointer arg_data;
+ union
{
gboolean bool;
gint integer;
@@ -162,10 +166,10 @@ typedef struct
gdouble dbl;
gint64 int64;
} prev;
- union
+ union
{
gchar *str;
- struct
+ struct
{
gint len;
gchar **data;
@@ -189,17 +193,17 @@ struct _GOptionContext
GTranslateFunc translate_func;
GDestroyNotify translate_notify;
- gpointer translate_data;
+ gpointer translate_data;
guint help_enabled : 1;
guint ignore_unknown : 1;
-
+
GOptionGroup *main_group;
/* We keep a list of change so we can revert them */
GList *changes;
-
- /* We also keep track of all argv elements
+
+ /* We also keep track of all argv elements
* that should be NULLed or modified.
*/
GList *pending_nulls;
@@ -216,7 +220,7 @@ struct _GOptionGroup
GTranslateFunc translate_func;
GDestroyNotify translate_notify;
- gpointer translate_data;
+ gpointer translate_data;
GOptionEntry *entries;
gint n_entries;
@@ -227,9 +231,9 @@ struct _GOptionGroup
};
static void free_changes_list (GOptionContext *context,
- gboolean revert);
+ gboolean revert);
static void free_pending_nulls (GOptionContext *context,
- gboolean perform_nulls);
+ gboolean perform_nulls);
static int
@@ -268,14 +272,14 @@ _g_utf8_strwidth (const gchar *p,
return 0;
/* this case may not be quite correct */
-
+
len += _g_unichar_get_width (g_utf8_get_char (p));
- p = g_utf8_next_char (p);
+ p = g_utf8_next_char (p);
while (p - start < max && *p)
{
len += _g_unichar_get_width (g_utf8_get_char (p));
- p = g_utf8_next_char (p);
+ p = g_utf8_next_char (p);
}
}
@@ -293,10 +297,10 @@ g_option_error_quark (void)
* g_option_context_new:
* @parameter_string: a string which is displayed in
* the first line of output, after the
- * usage summary
+ * usage summary
* programname [OPTION...]
*
- * Creates a new option context.
+ * Creates a new option context.
*
* The @parameter_string can serve multiple purposes. It can be used
* to add descriptions for "rest" arguments, which are not parsed by
@@ -338,9 +342,9 @@ g_option_context_new (const gchar *parameter_string)
/**
* g_option_context_free:
- * @context: a #GOptionContext
+ * @context: a #GOptionContext
*
- * Frees context and all the groups which have been
+ * Frees context and all the groups which have been
* added to it.
*
* Please note that parsed arguments need to be freed separately (see
@@ -348,23 +352,23 @@ g_option_context_new (const gchar *parameter_string)
*
* Since: 2.6
*/
-void g_option_context_free (GOptionContext *context)
+void g_option_context_free (GOptionContext *context)
{
g_return_if_fail (context != NULL);
g_list_foreach (context->groups, (GFunc)g_option_group_free, NULL);
g_list_free (context->groups);
- if (context->main_group)
+ if (context->main_group)
g_option_group_free (context->main_group);
free_changes_list (context, FALSE);
free_pending_nulls (context, FALSE);
-
+
g_free (context->parameter_string);
g_free (context->summary);
g_free (context->description);
-
+
if (context->translate_notify)
(* context->translate_notify) (context->translate_data);
@@ -377,12 +381,12 @@ void g_option_context_free (GOptionContext *context)
* @context: a #GOptionContext
* @help_enabled: %TRUE to enable , %FALSE to disable it
*
- * Enables or disables automatic generation of
+ * Enables or disables automatic generation of
* output. By default, g_option_context_parse() recognizes
* , ,
* ,
* and groupname and creates
- * suitable output to stdout.
+ * suitable output to stdout.
*
* Since: 2.6
*/
@@ -398,19 +402,19 @@ void g_option_context_set_help_enabled (GOptionContext *context,
/**
* g_option_context_get_help_enabled:
* @context: a #GOptionContext
- *
+ *
* Returns whether automatic generation
* is turned on for @context. See g_option_context_set_help_enabled().
- *
+ *
* Returns: %TRUE if automatic help generation is turned on.
*
* Since: 2.6
*/
-gboolean
-g_option_context_get_help_enabled (GOptionContext *context)
+gboolean
+g_option_context_get_help_enabled (GOptionContext *context)
{
g_return_val_if_fail (context != NULL, FALSE);
-
+
return context->help_enabled;
}
@@ -419,12 +423,12 @@ g_option_context_get_help_enabled (GOptionContext *context)
* @context: a #GOptionContext
* @ignore_unknown: %TRUE to ignore unknown options, %FALSE to produce
* an error when unknown options are met
- *
- * Sets whether to ignore unknown options or not. If an argument is
- * ignored, it is left in the @argv array after parsing. By default,
+ *
+ * Sets whether to ignore unknown options or not. If an argument is
+ * ignored, it is left in the @argv array after parsing. By default,
* g_option_context_parse() treats unknown options as error.
- *
- * This setting does not affect non-option arguments (i.e. arguments
+ *
+ * This setting does not affect non-option arguments (i.e. arguments
* which don't start with a dash). But note that GOption cannot reliably
* determine whether a non-option belongs to a preceding unknown option.
*
@@ -432,7 +436,7 @@ g_option_context_get_help_enabled (GOptionContext *context)
**/
void
g_option_context_set_ignore_unknown_options (GOptionContext *context,
- gboolean ignore_unknown)
+ gboolean ignore_unknown)
{
g_return_if_fail (context != NULL);
@@ -442,12 +446,12 @@ g_option_context_set_ignore_unknown_options (GOptionContext *context,
/**
* g_option_context_get_ignore_unknown_options:
* @context: a #GOptionContext
- *
+ *
* Returns whether unknown options are ignored or not. See
* g_option_context_set_ignore_unknown_options().
- *
+ *
* Returns: %TRUE if unknown options are ignored.
- *
+ *
* Since: 2.6
**/
gboolean
@@ -462,7 +466,7 @@ g_option_context_get_ignore_unknown_options (GOptionContext *context)
* g_option_context_add_group:
* @context: a #GOptionContext
* @group: the group to add
- *
+ *
* Adds a #GOptionGroup to the @context, so that parsing with @context
* will recognize the options in the group. Note that the group will
* be freed together with the context when g_option_context_free() is
@@ -473,7 +477,7 @@ g_option_context_get_ignore_unknown_options (GOptionContext *context)
**/
void
g_option_context_add_group (GOptionContext *context,
- GOptionGroup *group)
+ GOptionGroup *group)
{
GList *list;
@@ -488,9 +492,9 @@ g_option_context_add_group (GOptionContext *context,
GOptionGroup *g = (GOptionGroup *)list->data;
if ((group->name == NULL && g->name == NULL) ||
- (group->name && g->name && strcmp (group->name, g->name) == 0))
- g_warning ("A group named \"%s\" is already part of this GOptionContext",
- group->name);
+ (group->name && g->name && strcmp (group->name, g->name) == 0))
+ g_warning ("A group named \"%s\" is already part of this GOptionContext",
+ group->name);
}
context->groups = g_list_append (context->groups, group);
@@ -500,17 +504,17 @@ g_option_context_add_group (GOptionContext *context,
* g_option_context_set_main_group:
* @context: a #GOptionContext
* @group: the group to set as main group
- *
- * Sets a #GOptionGroup as main group of the @context.
- * This has the same effect as calling g_option_context_add_group(),
- * the only difference is that the options in the main group are
+ *
+ * Sets a #GOptionGroup as main group of the @context.
+ * This has the same effect as calling g_option_context_add_group(),
+ * the only difference is that the options in the main group are
* treated differently when generating output.
*
* Since: 2.6
**/
void
g_option_context_set_main_group (GOptionContext *context,
- GOptionGroup *group)
+ GOptionGroup *group)
{
g_return_if_fail (context != NULL);
g_return_if_fail (group != NULL);
@@ -521,16 +525,16 @@ g_option_context_set_main_group (GOptionContext *context,
return;
}
-
+
context->main_group = group;
}
/**
* g_option_context_get_main_group:
* @context: a #GOptionContext
- *
+ *
* Returns a pointer to the main group of @context.
- *
+ *
* Return value: the main group of @context, or %NULL if @context doesn't
* have a main group. Note that group belongs to @context and should
* not be modified or freed.
@@ -552,22 +556,22 @@ g_option_context_get_main_group (GOptionContext *context)
* @translation_domain: a translation domain to use for translating
* the output for the options in @entries
* with gettext(), or %NULL
- *
- * A convenience function which creates a main group if it doesn't
+ *
+ * A convenience function which creates a main group if it doesn't
* exist, adds the @entries to it and sets the translation domain.
- *
+ *
* Since: 2.6
**/
void
g_option_context_add_main_entries (GOptionContext *context,
- const GOptionEntry *entries,
- const gchar *translation_domain)
+ const GOptionEntry *entries,
+ const gchar *translation_domain)
{
g_return_if_fail (entries != NULL);
if (!context->main_group)
context->main_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
-
+
g_option_group_add_entries (context->main_group, entries);
g_option_group_set_translation_domain (context->main_group, translation_domain);
}
@@ -585,16 +589,16 @@ calculate_max_length (GOptionGroup *group)
entry = &group->entries[i];
if (entry->flags & G_OPTION_FLAG_HIDDEN)
- continue;
+ continue;
len = _g_utf8_strwidth (entry->long_name, -1);
-
+
if (entry->short_name)
- len += 4;
-
+ len += 4;
+
if (!NO_ARG (entry) && entry->arg_description)
- len += 1 + _g_utf8_strwidth (TRANSLATE (group, entry->arg_description), -1);
-
+ len += 1 + _g_utf8_strwidth (TRANSLATE (group, entry->arg_description), -1);
+
max_length = MAX (max_length, len);
}
@@ -603,12 +607,12 @@ calculate_max_length (GOptionGroup *group)
static void
print_entry (GOptionGroup *group,
- gint max_length,
- const GOptionEntry *entry,
+ gint max_length,
+ const GOptionEntry *entry,
GString *string)
{
GString *str;
-
+
if (entry->flags & G_OPTION_FLAG_HIDDEN)
return;
@@ -616,19 +620,19 @@ print_entry (GOptionGroup *group,
return;
str = g_string_new (NULL);
-
+
if (entry->short_name)
g_string_append_printf (str, " -%c, --%s", entry->short_name, entry->long_name);
else
g_string_append_printf (str, " --%s", entry->long_name);
-
+
if (entry->arg_description)
g_string_append_printf (str, "=%s", TRANSLATE (group, entry->arg_description));
-
+
g_string_append_printf (string, "%s%*s %s\n", str->str,
- (int) (max_length + 4 - _g_utf8_strwidth (str->str, -1)), "",
- entry->description ? TRANSLATE (group, entry->description) : "");
- g_string_free (str, TRUE);
+ (int) (max_length + 4 - _g_utf8_strwidth (str->str, -1)), "",
+ entry->description ? TRANSLATE (group, entry->description) : "");
+ g_string_free (str, TRUE);
}
static gboolean
@@ -703,9 +707,9 @@ context_has_h_entry (GOptionContext *context)
}
/**
- * g_option_context_get_help:
+ * g_option_context_get_help:
* @context: a #GOptionContext
- * @main_help: if %TRUE, only include the main group
+ * @main_help: if %TRUE, only include the main group
* @group: the #GOptionGroup to create help for, or %NULL
*
* Returns a formatted, translated help text for the given context.
@@ -722,8 +726,8 @@ context_has_h_entry (GOptionContext *context)
*/
gchar *
g_option_context_get_help (GOptionContext *context,
- gboolean main_help,
- GOptionGroup *group)
+ gboolean main_help,
+ GOptionGroup *group)
{
GList *list;
gint max_length, len;
@@ -742,18 +746,18 @@ g_option_context_get_help (GOptionContext *context,
{
for (i = 0; i < context->main_group->n_entries; i++)
- {
- entry = &context->main_group->entries[i];
- if (entry->long_name[0] == 0)
- {
- rest_description = TRANSLATE (context->main_group, entry->arg_description);
- break;
- }
- }
+ {
+ entry = &context->main_group->entries[i];
+ if (entry->long_name[0] == 0)
+ {
+ rest_description = TRANSLATE (context->main_group, entry->arg_description);
+ break;
+ }
+ }
}
- g_string_append_printf (string, "%s\n %s %s",
- _("Usage:"), g_get_prgname(), _("[OPTION...]"));
+ g_string_append_printf (string, "%s\n %s %s",
+ _("Usage:"), g_get_prgname(), _("[OPTION...]"));
if (rest_description)
{
@@ -781,17 +785,17 @@ g_option_context_get_help (GOptionContext *context,
if (context->main_group)
{
for (i = 0; i < context->main_group->n_entries; i++)
- {
- entry = &context->main_group->entries[i];
- g_hash_table_insert (shadow_map,
- (gpointer)entry->long_name,
- entry);
-
- if (seen[(guchar)entry->short_name])
- entry->short_name = 0;
- else
- seen[(guchar)entry->short_name] = TRUE;
- }
+ {
+ entry = &context->main_group->entries[i];
+ g_hash_table_insert (shadow_map,
+ (gpointer)entry->long_name,
+ entry);
+
+ if (seen[(guchar)entry->short_name])
+ entry->short_name = 0;
+ else
+ seen[(guchar)entry->short_name] = TRUE;
+ }
}
list = context->groups;
@@ -799,20 +803,20 @@ g_option_context_get_help (GOptionContext *context,
{
GOptionGroup *g = list->data;
for (i = 0; i < g->n_entries; i++)
- {
- entry = &g->entries[i];
- if (g_hash_table_lookup (shadow_map, entry->long_name) &&
- !(entry->flags & G_OPTION_FLAG_NOALIAS))
- entry->long_name = g_strdup_printf ("%s-%s", g->name, entry->long_name);
- else
- g_hash_table_insert (shadow_map, (gpointer)entry->long_name, entry);
+ {
+ entry = &g->entries[i];
+ if (g_hash_table_lookup (shadow_map, entry->long_name) &&
+ !(entry->flags & G_OPTION_FLAG_NOALIAS))
+ entry->long_name = g_strdup_printf ("%s-%s", g->name, entry->long_name);
+ else
+ g_hash_table_insert (shadow_map, (gpointer)entry->long_name, entry);
- if (seen[(guchar)entry->short_name] &&
- !(entry->flags & G_OPTION_FLAG_NOALIAS))
- entry->short_name = 0;
- else
- seen[(guchar)entry->short_name] = TRUE;
- }
+ if (seen[(guchar)entry->short_name] &&
+ !(entry->flags & G_OPTION_FLAG_NOALIAS))
+ entry->short_name = 0;
+ else
+ seen[(guchar)entry->short_name] = TRUE;
+ }
list = list->next;
}
@@ -837,7 +841,7 @@ g_option_context_get_help (GOptionContext *context,
while (list != NULL)
{
GOptionGroup *g = list->data;
-
+
/* First, we check the --help- options */
len = _g_utf8_strwidth ("--help-", -1) + _g_utf8_strwidth (g->name, -1);
max_length = MAX (max_length, len);
@@ -845,7 +849,7 @@ g_option_context_get_help (GOptionContext *context,
/* Then we go through the entries */
len = calculate_max_length (g);
max_length = MAX (max_length, len);
-
+
list = list->next;
}
@@ -858,27 +862,27 @@ g_option_context_get_help (GOptionContext *context,
token = context_has_h_entry (context) ? '?' : 'h';
- g_string_append_printf (string, "%s\n -%c, --%-*s %s\n",
- _("Help Options:"), token, max_length - 4, "help",
- _("Show help options"));
-
+ g_string_append_printf (string, "%s\n -%c, --%-*s %s\n",
+ _("Help Options:"), token, max_length - 4, "help",
+ _("Show help options"));
+
/* We only want --help-all when there are groups */
if (list)
- g_string_append_printf (string, " --%-*s %s\n",
- max_length, "help-all",
+ g_string_append_printf (string, " --%-*s %s\n",
+ max_length, "help-all",
_("Show all help options"));
-
- while (list)
- {
- GOptionGroup *g = list->data;
- if (group_has_visible_entries (context, g, FALSE))
- g_string_append_printf (string, " --help-%-*s %s\n",
- max_length - 5, g->name,
- TRANSLATE (g, g->help_description));
-
- list = list->next;
- }
+ while (list)
+ {
+ GOptionGroup *g = list->data;
+
+ if (group_has_visible_entries (context, g, FALSE))
+ g_string_append_printf (string, " --help-%-*s %s\n",
+ max_length - 5, g->name,
+ TRANSLATE (g, g->help_description));
+
+ list = list->next;
+ }
g_string_append (string, "\n");
}
@@ -903,24 +907,24 @@ g_option_context_get_help (GOptionContext *context,
list = context->groups;
while (list)
- {
- GOptionGroup *g = list->data;
+ {
+ GOptionGroup *g = list->data;
- if (group_has_visible_entries (context, g, FALSE))
- {
- g_string_append (string, g->description);
- g_string_append (string, "\n");
- for (i = 0; i < g->n_entries; i++)
- if (!(g->entries[i].flags & G_OPTION_FLAG_IN_MAIN))
- print_entry (g, max_length, &g->entries[i], string);
-
- g_string_append (string, "\n");
- }
+ if (group_has_visible_entries (context, g, FALSE))
+ {
+ g_string_append (string, g->description);
+ g_string_append (string, "\n");
+ for (i = 0; i < g->n_entries; i++)
+ if (!(g->entries[i].flags & G_OPTION_FLAG_IN_MAIN))
+ print_entry (g, max_length, &g->entries[i], string);
- list = list->next;
- }
+ g_string_append (string, "\n");
+ }
+
+ list = list->next;
+ }
}
-
+
/* Print application options if --help or --help-all has been specified */
if ((main_help || !group) &&
(group_has_visible_entries (context, context->main_group, TRUE) ||
@@ -931,25 +935,25 @@ g_option_context_get_help (GOptionContext *context,
g_string_append (string, _("Application Options:"));
g_string_append (string, "\n");
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], string);
+ for (i = 0; i < context->main_group->n_entries; i++)
+ print_entry (context->main_group, max_length,
+ &context->main_group->entries[i], string);
while (list != NULL)
- {
- GOptionGroup *g = list->data;
+ {
+ GOptionGroup *g = list->data;
- /* Print main entries from other groups */
- for (i = 0; i < g->n_entries; i++)
- if (g->entries[i].flags & G_OPTION_FLAG_IN_MAIN)
- print_entry (g, max_length, &g->entries[i], string);
-
- list = list->next;
- }
+ /* Print main entries from other groups */
+ for (i = 0; i < g->n_entries; i++)
+ if (g->entries[i].flags & G_OPTION_FLAG_IN_MAIN)
+ print_entry (g, max_length, &g->entries[i], string);
+
+ list = list->next;
+ }
g_string_append (string, "\n");
}
-
+
if (context->description)
{
g_string_append (string, TRANSLATE (context, context->description));
@@ -962,8 +966,8 @@ g_option_context_get_help (GOptionContext *context,
G_GNUC_NORETURN
static void
print_help (GOptionContext *context,
- gboolean main_help,
- GOptionGroup *group)
+ gboolean main_help,
+ GOptionGroup *group)
{
gchar *help;
@@ -971,27 +975,27 @@ print_help (GOptionContext *context,
g_print ("%s", help);
g_free (help);
- exit (0);
+ exit (0);
}
static gboolean
parse_int (const gchar *arg_name,
- const gchar *arg,
- gint *result,
- GError **error)
+ const gchar *arg,
+ gint *result,
+ GError **error)
{
gchar *end;
glong tmp;
errno = 0;
tmp = strtol (arg, &end, 0);
-
+
if (*arg == '\0' || *end != '\0')
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Cannot parse integer value '%s' for %s"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Cannot parse integer value '%s' for %s"),
+ arg, arg_name);
return FALSE;
}
@@ -999,9 +1003,9 @@ parse_int (const gchar *arg_name,
if (*result != tmp || errno == ERANGE)
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Integer value '%s' for %s out of range"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Integer value '%s' for %s out of range"),
+ arg, arg_name);
return FALSE;
}
@@ -1011,44 +1015,44 @@ parse_int (const gchar *arg_name,
static gboolean
parse_double (const gchar *arg_name,
- const gchar *arg,
- gdouble *result,
- GError **error)
+ const gchar *arg,
+ gdouble *result,
+ GError **error)
{
gchar *end;
gdouble tmp;
errno = 0;
tmp = g_strtod (arg, &end);
-
+
if (*arg == '\0' || *end != '\0')
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Cannot parse double value '%s' for %s"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Cannot parse double value '%s' for %s"),
+ arg, arg_name);
return FALSE;
}
if (errno == ERANGE)
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Double value '%s' for %s out of range"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Double value '%s' for %s out of range"),
+ arg, arg_name);
return FALSE;
}
*result = tmp;
-
+
return TRUE;
}
static gboolean
parse_int64 (const gchar *arg_name,
- const gchar *arg,
- gint64 *result,
- GError **error)
+ const gchar *arg,
+ gint64 *result,
+ GError **error)
{
gchar *end;
gint64 tmp;
@@ -1059,48 +1063,48 @@ parse_int64 (const gchar *arg_name,
if (*arg == '\0' || *end != '\0')
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Cannot parse integer value '%s' for %s"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Cannot parse integer value '%s' for %s"),
+ arg, arg_name);
return FALSE;
}
if (errno == ERANGE)
{
g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Integer value '%s' for %s out of range"),
- arg, arg_name);
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Integer value '%s' for %s out of range"),
+ arg, arg_name);
return FALSE;
}
*result = tmp;
-
+
return TRUE;
}
static Change *
get_change (GOptionContext *context,
- GOptionArg arg_type,
- gpointer arg_data)
+ GOptionArg arg_type,
+ gpointer arg_data)
{
GList *list;
Change *change = NULL;
-
+
for (list = context->changes; list != NULL; list = list->next)
{
change = list->data;
if (change->arg_data == arg_data)
- goto found;
+ goto found;
}
change = g_new0 (Change, 1);
change->arg_type = arg_type;
change->arg_data = arg_data;
-
+
context->changes = g_list_prepend (context->changes, change);
-
+
found:
return change;
@@ -1108,8 +1112,8 @@ get_change (GOptionContext *context,
static void
add_pending_null (GOptionContext *context,
- gchar **ptr,
- gchar *value)
+ gchar **ptr,
+ gchar *value)
{
PendingNull *n;
@@ -1119,15 +1123,15 @@ add_pending_null (GOptionContext *context,
context->pending_nulls = g_list_prepend (context->pending_nulls, n);
}
-
+
static gboolean
parse_arg (GOptionContext *context,
- GOptionGroup *group,
- GOptionEntry *entry,
- const gchar *value,
- const gchar *option_name,
- GError **error)
-
+ GOptionGroup *group,
+ GOptionEntry *entry,
+ const gchar *value,
+ const gchar *option_name,
+ GError **error)
+
{
Change *change;
@@ -1137,206 +1141,206 @@ parse_arg (GOptionContext *context,
{
case G_OPTION_ARG_NONE:
{
- change = get_change (context, G_OPTION_ARG_NONE,
- entry->arg_data);
+ change = get_change (context, G_OPTION_ARG_NONE,
+ entry->arg_data);
- *(gboolean *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE);
- break;
- }
+ *(gboolean *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE);
+ break;
+ }
case G_OPTION_ARG_STRING:
{
- gchar *data;
-
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ gchar *data;
- if (!data)
- return FALSE;
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- change = get_change (context, G_OPTION_ARG_STRING,
- entry->arg_data);
- g_free (change->allocated.str);
-
- change->prev.str = *(gchar **)entry->arg_data;
- change->allocated.str = data;
-
- *(gchar **)entry->arg_data = data;
- break;
+ if (!data)
+ return FALSE;
+
+ change = get_change (context, G_OPTION_ARG_STRING,
+ entry->arg_data);
+ g_free (change->allocated.str);
+
+ change->prev.str = *(gchar **)entry->arg_data;
+ change->allocated.str = data;
+
+ *(gchar **)entry->arg_data = data;
+ break;
}
case G_OPTION_ARG_STRING_ARRAY:
{
- gchar *data;
+ gchar *data;
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- if (!data)
- return FALSE;
+ if (!data)
+ return FALSE;
- change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
- entry->arg_data);
+ change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
+ entry->arg_data);
- if (change->allocated.array.len == 0)
- {
- change->prev.array = *(gchar ***)entry->arg_data;
- change->allocated.array.data = g_new (gchar *, 2);
- }
- else
- change->allocated.array.data =
- g_renew (gchar *, change->allocated.array.data,
- change->allocated.array.len + 2);
+ if (change->allocated.array.len == 0)
+ {
+ change->prev.array = *(gchar ***)entry->arg_data;
+ change->allocated.array.data = g_new (gchar *, 2);
+ }
+ else
+ change->allocated.array.data =
+ g_renew (gchar *, change->allocated.array.data,
+ change->allocated.array.len + 2);
- change->allocated.array.data[change->allocated.array.len] = data;
- change->allocated.array.data[change->allocated.array.len + 1] = NULL;
+ change->allocated.array.data[change->allocated.array.len] = data;
+ change->allocated.array.data[change->allocated.array.len + 1] = NULL;
- change->allocated.array.len ++;
+ change->allocated.array.len ++;
- *(gchar ***)entry->arg_data = change->allocated.array.data;
+ *(gchar ***)entry->arg_data = change->allocated.array.data;
- break;
+ break;
}
-
+
case G_OPTION_ARG_FILENAME:
{
- gchar *data;
+ gchar *data;
#ifdef G_OS_WIN32
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
-
- if (!data)
- return FALSE;
-#else
- data = g_strdup (value);
-#endif
- change = get_change (context, G_OPTION_ARG_FILENAME,
- entry->arg_data);
- g_free (change->allocated.str);
-
- change->prev.str = *(gchar **)entry->arg_data;
- change->allocated.str = data;
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- *(gchar **)entry->arg_data = data;
- break;
+ if (!data)
+ return FALSE;
+#else
+ data = g_strdup (value);
+#endif
+ change = get_change (context, G_OPTION_ARG_FILENAME,
+ entry->arg_data);
+ g_free (change->allocated.str);
+
+ change->prev.str = *(gchar **)entry->arg_data;
+ change->allocated.str = data;
+
+ *(gchar **)entry->arg_data = data;
+ break;
}
case G_OPTION_ARG_FILENAME_ARRAY:
{
- gchar *data;
-
+ gchar *data;
+
#ifdef G_OS_WIN32
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
-
- if (!data)
- return FALSE;
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+
+ if (!data)
+ return FALSE;
#else
- data = g_strdup (value);
+ data = g_strdup (value);
#endif
- change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
- entry->arg_data);
+ change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
+ entry->arg_data);
- if (change->allocated.array.len == 0)
- {
- change->prev.array = *(gchar ***)entry->arg_data;
- change->allocated.array.data = g_new (gchar *, 2);
- }
- else
- change->allocated.array.data =
- g_renew (gchar *, change->allocated.array.data,
- change->allocated.array.len + 2);
+ if (change->allocated.array.len == 0)
+ {
+ change->prev.array = *(gchar ***)entry->arg_data;
+ change->allocated.array.data = g_new (gchar *, 2);
+ }
+ else
+ change->allocated.array.data =
+ g_renew (gchar *, change->allocated.array.data,
+ change->allocated.array.len + 2);
- change->allocated.array.data[change->allocated.array.len] = data;
- change->allocated.array.data[change->allocated.array.len + 1] = NULL;
+ change->allocated.array.data[change->allocated.array.len] = data;
+ change->allocated.array.data[change->allocated.array.len + 1] = NULL;
- change->allocated.array.len ++;
+ change->allocated.array.len ++;
- *(gchar ***)entry->arg_data = change->allocated.array.data;
+ *(gchar ***)entry->arg_data = change->allocated.array.data;
- break;
+ break;
}
-
+
case G_OPTION_ARG_INT:
{
- gint data;
+ gint data;
- if (!parse_int (option_name, value,
- &data,
- error))
- return FALSE;
+ if (!parse_int (option_name, value,
+ &data,
+ error))
+ return FALSE;
- change = get_change (context, G_OPTION_ARG_INT,
- entry->arg_data);
- change->prev.integer = *(gint *)entry->arg_data;
- *(gint *)entry->arg_data = data;
- break;
+ change = get_change (context, G_OPTION_ARG_INT,
+ entry->arg_data);
+ change->prev.integer = *(gint *)entry->arg_data;
+ *(gint *)entry->arg_data = data;
+ break;
}
case G_OPTION_ARG_CALLBACK:
{
- gchar *data;
- gboolean retval;
+ gchar *data;
+ gboolean retval;
- if (!value && entry->flags & G_OPTION_FLAG_OPTIONAL_ARG)
- data = NULL;
- else if (entry->flags & G_OPTION_FLAG_NO_ARG)
- data = NULL;
- else if (entry->flags & G_OPTION_FLAG_FILENAME)
- {
+ if (!value && entry->flags & G_OPTION_FLAG_OPTIONAL_ARG)
+ data = NULL;
+ else if (entry->flags & G_OPTION_FLAG_NO_ARG)
+ data = NULL;
+ else if (entry->flags & G_OPTION_FLAG_FILENAME)
+ {
#ifdef G_OS_WIN32
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
#else
- data = g_strdup (value);
+ data = g_strdup (value);
#endif
- }
- else
- data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ }
+ else
+ data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- if (!(entry->flags & (G_OPTION_FLAG_NO_ARG|G_OPTION_FLAG_OPTIONAL_ARG)) &&
- !data)
- return FALSE;
+ if (!(entry->flags & (G_OPTION_FLAG_NO_ARG|G_OPTION_FLAG_OPTIONAL_ARG)) &&
+ !data)
+ return FALSE;
- retval = (* (GOptionArgFunc) entry->arg_data) (option_name, data, group->user_data, error);
-
- if (!retval && error != NULL && *error == NULL)
- g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- _("Error parsing option %s"), option_name);
+ retval = (* (GOptionArgFunc) entry->arg_data) (option_name, data, group->user_data, error);
- g_free (data);
-
- return retval;
-
- break;
+ if (!retval && error != NULL && *error == NULL)
+ g_set_error (error,
+ G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ _("Error parsing option %s"), option_name);
+
+ g_free (data);
+
+ return retval;
+
+ break;
}
case G_OPTION_ARG_DOUBLE:
{
- gdouble data;
+ gdouble data;
- if (!parse_double (option_name, value,
- &data,
- error))
- {
- return FALSE;
- }
+ if (!parse_double (option_name, value,
+ &data,
+ error))
+ {
+ return FALSE;
+ }
- change = get_change (context, G_OPTION_ARG_DOUBLE,
- entry->arg_data);
- change->prev.dbl = *(gdouble *)entry->arg_data;
- *(gdouble *)entry->arg_data = data;
- break;
+ change = get_change (context, G_OPTION_ARG_DOUBLE,
+ entry->arg_data);
+ change->prev.dbl = *(gdouble *)entry->arg_data;
+ *(gdouble *)entry->arg_data = data;
+ break;
}
case G_OPTION_ARG_INT64:
{
gint64 data;
- if (!parse_int64 (option_name, value,
- &data,
- error))
- {
- return FALSE;
- }
+ if (!parse_int64 (option_name, value,
+ &data,
+ error))
+ {
+ return FALSE;
+ }
- change = get_change (context, G_OPTION_ARG_INT64,
- entry->arg_data);
- change->prev.int64 = *(gint64 *)entry->arg_data;
- *(gint64 *)entry->arg_data = data;
- break;
+ change = get_change (context, G_OPTION_ARG_INT64,
+ entry->arg_data);
+ change->prev.int64 = *(gint64 *)entry->arg_data;
+ *(gint64 *)entry->arg_data = data;
+ break;
}
default:
g_assert_not_reached ();
@@ -1347,81 +1351,81 @@ parse_arg (GOptionContext *context,
static gboolean
parse_short_option (GOptionContext *context,
- GOptionGroup *group,
- gint idx,
- gint *new_idx,
- gchar arg,
- gint *argc,
- gchar ***argv,
- GError **error,
- gboolean *parsed)
+ GOptionGroup *group,
+ gint idx,
+ gint *new_idx,
+ gchar arg,
+ gint *argc,
+ gchar ***argv,
+ GError **error,
+ gboolean *parsed)
{
gint j;
-
+
for (j = 0; j < group->n_entries; j++)
{
if (arg == group->entries[j].short_name)
- {
- gchar *option_name;
- gchar *value = NULL;
-
- option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
+ {
+ gchar *option_name;
+ gchar *value = NULL;
- if (NO_ARG (&group->entries[j]))
- value = NULL;
- else
- {
- if (*new_idx > idx)
- {
- g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- _("Error parsing option %s"), option_name);
- g_free (option_name);
- return FALSE;
- }
+ option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
- if (idx < *argc - 1)
- {
- if (!OPTIONAL_ARG (&group->entries[j]))
- {
- value = (*argv)[idx + 1];
- add_pending_null (context, &((*argv)[idx + 1]), NULL);
- *new_idx = idx + 1;
- }
- else
- {
- if ((*argv)[idx + 1][0] == '-')
- value = NULL;
- else
- {
- value = (*argv)[idx + 1];
- add_pending_null (context, &((*argv)[idx + 1]), NULL);
- *new_idx = idx + 1;
- }
- }
- }
- else if (idx >= *argc - 1 && OPTIONAL_ARG (&group->entries[j]))
- value = NULL;
- else
- {
- g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Missing argument for %s"), option_name);
- g_free (option_name);
- return FALSE;
- }
- }
+ if (NO_ARG (&group->entries[j]))
+ value = NULL;
+ else
+ {
+ if (*new_idx > idx)
+ {
+ g_set_error (error,
+ G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ _("Error parsing option %s"), option_name);
+ g_free (option_name);
+ return FALSE;
+ }
- if (!parse_arg (context, group, &group->entries[j],
- value, option_name, error))
- {
- g_free (option_name);
- return FALSE;
- }
-
- g_free (option_name);
- *parsed = TRUE;
- }
+ if (idx < *argc - 1)
+ {
+ if (!OPTIONAL_ARG (&group->entries[j]))
+ {
+ value = (*argv)[idx + 1];
+ add_pending_null (context, &((*argv)[idx + 1]), NULL);
+ *new_idx = idx + 1;
+ }
+ else
+ {
+ if ((*argv)[idx + 1][0] == '-')
+ value = NULL;
+ else
+ {
+ value = (*argv)[idx + 1];
+ add_pending_null (context, &((*argv)[idx + 1]), NULL);
+ *new_idx = idx + 1;
+ }
+ }
+ }
+ else if (idx >= *argc - 1 && OPTIONAL_ARG (&group->entries[j]))
+ value = NULL;
+ else
+ {
+ g_set_error (error,
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Missing argument for %s"), option_name);
+ g_free (option_name);
+ return FALSE;
+ }
+ }
+
+ if (!parse_arg (context, group, &group->entries[j],
+ value, option_name, error))
+ {
+ g_free (option_name);
+ return FALSE;
+ }
+
+ g_free (option_name);
+ *parsed = TRUE;
+ }
}
return TRUE;
@@ -1429,146 +1433,146 @@ parse_short_option (GOptionContext *context,
static gboolean
parse_long_option (GOptionContext *context,
- GOptionGroup *group,
- gint *idx,
- gchar *arg,
- gboolean aliased,
- gint *argc,
- gchar ***argv,
- GError **error,
- gboolean *parsed)
+ GOptionGroup *group,
+ gint *idx,
+ gchar *arg,
+ gboolean aliased,
+ gint *argc,
+ gchar ***argv,
+ GError **error,
+ gboolean *parsed)
{
gint j;
for (j = 0; j < group->n_entries; j++)
{
if (*idx >= *argc)
- return TRUE;
+ return TRUE;
if (aliased && (group->entries[j].flags & G_OPTION_FLAG_NOALIAS))
- continue;
+ continue;
if (NO_ARG (&group->entries[j]) &&
- strcmp (arg, group->entries[j].long_name) == 0)
- {
- gchar *option_name;
- gboolean retval;
+ strcmp (arg, group->entries[j].long_name) == 0)
+ {
+ gchar *option_name;
+ gboolean retval;
- option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
- retval = parse_arg (context, group, &group->entries[j],
- NULL, option_name, error);
- g_free(option_name);
-
- add_pending_null (context, &((*argv)[*idx]), NULL);
- *parsed = TRUE;
+ option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
+ retval = parse_arg (context, group, &group->entries[j],
+ NULL, option_name, error);
+ g_free (option_name);
- return retval;
- }
+ add_pending_null (context, &((*argv)[*idx]), NULL);
+ *parsed = TRUE;
+
+ return retval;
+ }
else
- {
- gint len = strlen (group->entries[j].long_name);
-
- if (strncmp (arg, group->entries[j].long_name, len) == 0 &&
- (arg[len] == '=' || arg[len] == 0))
- {
- gchar *value = NULL;
- gchar *option_name;
+ {
+ gint len = strlen (group->entries[j].long_name);
- add_pending_null (context, &((*argv)[*idx]), NULL);
- option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
+ if (strncmp (arg, group->entries[j].long_name, len) == 0 &&
+ (arg[len] == '=' || arg[len] == 0))
+ {
+ gchar *value = NULL;
+ gchar *option_name;
- if (arg[len] == '=')
- value = arg + len + 1;
- else if (*idx < *argc - 1)
- {
- if (!(group->entries[j].flags & G_OPTION_FLAG_OPTIONAL_ARG))
- {
- value = (*argv)[*idx + 1];
- add_pending_null (context, &((*argv)[*idx + 1]), NULL);
- (*idx)++;
- }
- else
- {
- if ((*argv)[*idx + 1][0] == '-')
- {
- gboolean retval;
- retval = parse_arg (context, group, &group->entries[j],
- NULL, option_name, error);
- *parsed = TRUE;
- g_free (option_name);
- return retval;
- }
- else
- {
- value = (*argv)[*idx + 1];
- add_pending_null (context, &((*argv)[*idx + 1]), NULL);
- (*idx)++;
- }
- }
- }
- else if (*idx >= *argc - 1 &&
- group->entries[j].flags & G_OPTION_FLAG_OPTIONAL_ARG)
- {
- gboolean retval;
- retval = parse_arg (context, group, &group->entries[j],
- NULL, option_name, error);
- *parsed = TRUE;
- g_free (option_name);
- return retval;
- }
- else
- {
- g_set_error (error,
- G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
- _("Missing argument for %s"), option_name);
- g_free (option_name);
- return FALSE;
- }
+ add_pending_null (context, &((*argv)[*idx]), NULL);
+ option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
- if (!parse_arg (context, group, &group->entries[j],
- value, option_name, error))
- {
- g_free (option_name);
- return FALSE;
- }
+ if (arg[len] == '=')
+ value = arg + len + 1;
+ else if (*idx < *argc - 1)
+ {
+ if (!(group->entries[j].flags & G_OPTION_FLAG_OPTIONAL_ARG))
+ {
+ value = (*argv)[*idx + 1];
+ add_pending_null (context, &((*argv)[*idx + 1]), NULL);
+ (*idx)++;
+ }
+ else
+ {
+ if ((*argv)[*idx + 1][0] == '-')
+ {
+ gboolean retval;
+ retval = parse_arg (context, group, &group->entries[j],
+ NULL, option_name, error);
+ *parsed = TRUE;
+ g_free (option_name);
+ return retval;
+ }
+ else
+ {
+ value = (*argv)[*idx + 1];
+ add_pending_null (context, &((*argv)[*idx + 1]), NULL);
+ (*idx)++;
+ }
+ }
+ }
+ else if (*idx >= *argc - 1 &&
+ group->entries[j].flags & G_OPTION_FLAG_OPTIONAL_ARG)
+ {
+ gboolean retval;
+ retval = parse_arg (context, group, &group->entries[j],
+ NULL, option_name, error);
+ *parsed = TRUE;
+ g_free (option_name);
+ return retval;
+ }
+ else
+ {
+ g_set_error (error,
+ G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+ _("Missing argument for %s"), option_name);
+ g_free (option_name);
+ return FALSE;
+ }
- g_free (option_name);
- *parsed = TRUE;
- }
- }
+ if (!parse_arg (context, group, &group->entries[j],
+ value, option_name, error))
+ {
+ g_free (option_name);
+ return FALSE;
+ }
+
+ g_free (option_name);
+ *parsed = TRUE;
+ }
+ }
}
-
+
return TRUE;
}
static gboolean
parse_remaining_arg (GOptionContext *context,
- GOptionGroup *group,
- gint *idx,
- gint *argc,
- gchar ***argv,
- GError **error,
- gboolean *parsed)
+ GOptionGroup *group,
+ gint *idx,
+ gint *argc,
+ gchar ***argv,
+ GError **error,
+ gboolean *parsed)
{
gint j;
for (j = 0; j < group->n_entries; j++)
{
if (*idx >= *argc)
- return TRUE;
+ return TRUE;
if (group->entries[j].long_name[0])
- continue;
+ continue;
g_return_val_if_fail (group->entries[j].arg == G_OPTION_ARG_CALLBACK ||
group->entries[j].arg == G_OPTION_ARG_STRING_ARRAY ||
- group->entries[j].arg == G_OPTION_ARG_FILENAME_ARRAY, FALSE);
-
+ group->entries[j].arg == G_OPTION_ARG_FILENAME_ARRAY, FALSE);
+
add_pending_null (context, &((*argv)[*idx]), NULL);
-
+
if (!parse_arg (context, group, &group->entries[j], (*argv)[*idx], "", error))
- return FALSE;
-
+ return FALSE;
+
*parsed = TRUE;
return TRUE;
}
@@ -1578,7 +1582,7 @@ parse_remaining_arg (GOptionContext *context,
static void
free_changes_list (GOptionContext *context,
- gboolean revert)
+ gboolean revert)
{
GList *list;
@@ -1587,36 +1591,36 @@ free_changes_list (GOptionContext *context,
Change *change = list->data;
if (revert)
- {
- switch (change->arg_type)
- {
- case G_OPTION_ARG_NONE:
- *(gboolean *)change->arg_data = change->prev.bool;
- break;
- case G_OPTION_ARG_INT:
- *(gint *)change->arg_data = change->prev.integer;
- break;
- case G_OPTION_ARG_STRING:
- case G_OPTION_ARG_FILENAME:
+ {
+ switch (change->arg_type)
+ {
+ case G_OPTION_ARG_NONE:
+ *(gboolean *)change->arg_data = change->prev.bool;
+ break;
+ case G_OPTION_ARG_INT:
+ *(gint *)change->arg_data = change->prev.integer;
+ break;
+ case G_OPTION_ARG_STRING:
+ case G_OPTION_ARG_FILENAME:
g_free (change->allocated.str);
- *(gchar **)change->arg_data = change->prev.str;
- break;
- case G_OPTION_ARG_STRING_ARRAY:
- case G_OPTION_ARG_FILENAME_ARRAY:
- g_strfreev (change->allocated.array.data);
- *(gchar ***)change->arg_data = change->prev.array;
- break;
- case G_OPTION_ARG_DOUBLE:
- *(gdouble *)change->arg_data = change->prev.dbl;
- break;
- case G_OPTION_ARG_INT64:
- *(gint64 *)change->arg_data = change->prev.int64;
- break;
- default:
- g_assert_not_reached ();
- }
- }
-
+ *(gchar **)change->arg_data = change->prev.str;
+ break;
+ case G_OPTION_ARG_STRING_ARRAY:
+ case G_OPTION_ARG_FILENAME_ARRAY:
+ g_strfreev (change->allocated.array.data);
+ *(gchar ***)change->arg_data = change->prev.array;
+ break;
+ case G_OPTION_ARG_DOUBLE:
+ *(gdouble *)change->arg_data = change->prev.dbl;
+ break;
+ case G_OPTION_ARG_INT64:
+ *(gint64 *)change->arg_data = change->prev.int64;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ }
+
g_free (change);
}
@@ -1626,7 +1630,7 @@ free_changes_list (GOptionContext *context,
static void
free_pending_nulls (GOptionContext *context,
- gboolean perform_nulls)
+ gboolean perform_nulls)
{
GList *list;
@@ -1635,17 +1639,17 @@ free_pending_nulls (GOptionContext *context,
PendingNull *n = list->data;
if (perform_nulls)
- {
- if (n->value)
- {
- /* Copy back the short options */
- *(n->ptr)[0] = '-';
- strcpy (*n->ptr + 1, n->value);
- }
- else
- *n->ptr = NULL;
- }
-
+ {
+ if (n->value)
+ {
+ /* Copy back the short options */
+ *(n->ptr)[0] = '-';
+ strcpy (*n->ptr + 1, n->value);
+ }
+ else
+ *n->ptr = NULL;
+ }
+
g_free (n->value);
g_free (n);
}
@@ -1659,41 +1663,41 @@ free_pending_nulls (GOptionContext *context,
* @context: a #GOptionContext
* @argc: a pointer to the number of command line arguments
* @argv: a pointer to the array of command line arguments
- * @error: a return location for errors
- *
+ * @error: a return location for errors
+ *
* Parses the command line arguments, recognizing options
- * which have been added to @context. A side-effect of
+ * which have been added to @context. A side-effect of
* calling this function is that g_set_prgname() will be
* called.
*
* If the parsing is successful, any parsed arguments are
- * removed from the array and @argc and @argv are updated
+ * removed from the array and @argc and @argv are updated
* accordingly. A '--' option is stripped from @argv
- * unless there are unparsed options before and after it,
- * or some of the options after it start with '-'. In case
- * of an error, @argc and @argv are left unmodified.
+ * unless there are unparsed options before and after it,
+ * or some of the options after it start with '-'. In case
+ * of an error, @argc and @argv are left unmodified.
*
* If automatic support is enabled
- * (see g_option_context_set_help_enabled()), and the
+ * (see g_option_context_set_help_enabled()), and the
* @argv array contains one of the recognized help options,
* this function will produce help output to stdout and
* call exit (0).
*
- * Note that function depends on the
- * current locale for
+ * Note that function depends on the
+ * current locale for
* automatic character set conversion of string and filename
* arguments.
- *
- * Return value: %TRUE if the parsing was successful,
+ *
+ * Return value: %TRUE if the parsing was successful,
* %FALSE if an error occurred
*
* Since: 2.6
**/
gboolean
g_option_context_parse (GOptionContext *context,
- gint *argc,
- gchar ***argv,
- GError **error)
+ gint *argc,
+ gchar ***argv,
+ GError **error)
{
gint i, j, k;
GList *list;
@@ -1702,15 +1706,15 @@ g_option_context_parse (GOptionContext *context,
if (!g_get_prgname())
{
if (argc && argv && *argc)
- {
- gchar *prgname;
-
- prgname = g_path_get_basename ((*argv)[0]);
- g_set_prgname (prgname);
- g_free (prgname);
- }
+ {
+ gchar *prgname;
+
+ prgname = g_path_get_basename ((*argv)[0]);
+ g_set_prgname (prgname);
+ g_free (prgname);
+ }
else
- g_set_prgname ("");
+ g_set_prgname ("");
}
/* Call pre-parse hooks */
@@ -1718,22 +1722,22 @@ g_option_context_parse (GOptionContext *context,
while (list)
{
GOptionGroup *group = list->data;
-
+
if (group->pre_parse_func)
- {
- if (!(* group->pre_parse_func) (context, group,
- group->user_data, error))
- goto fail;
- }
-
+ {
+ if (!(* group->pre_parse_func) (context, group,
+ group->user_data, error))
+ goto fail;
+ }
+
list = list->next;
}
if (context->main_group && context->main_group->pre_parse_func)
{
if (!(* context->main_group->pre_parse_func) (context, context->main_group,
- context->main_group->user_data, error))
- goto fail;
+ context->main_group->user_data, error))
+ goto fail;
}
if (argc && argv)
@@ -1743,198 +1747,198 @@ g_option_context_parse (GOptionContext *context,
gint separator_pos = 0;
for (i = 1; i < *argc; i++)
- {
- gchar *arg, *dash;
- gboolean parsed = FALSE;
+ {
+ gchar *arg, *dash;
+ gboolean parsed = FALSE;
- if ((*argv)[i][0] == '-' && (*argv)[i][1] != '\0' && !stop_parsing)
- {
- if ((*argv)[i][1] == '-')
- {
- /* -- option */
+ if ((*argv)[i][0] == '-' && (*argv)[i][1] != '\0' && !stop_parsing)
+ {
+ if ((*argv)[i][1] == '-')
+ {
+ /* -- option */
- arg = (*argv)[i] + 2;
+ arg = (*argv)[i] + 2;
- /* '--' terminates list of arguments */
- if (*arg == 0)
- {
- separator_pos = i;
- stop_parsing = TRUE;
- continue;
- }
+ /* '--' terminates list of arguments */
+ if (*arg == 0)
+ {
+ separator_pos = i;
+ stop_parsing = TRUE;
+ continue;
+ }
- /* Handle help options */
- if (context->help_enabled)
- {
- if (strcmp (arg, "help") == 0)
- print_help (context, TRUE, NULL);
- else if (strcmp (arg, "help-all") == 0)
- print_help (context, FALSE, NULL);
- else if (strncmp (arg, "help-", 5) == 0)
- {
- list = context->groups;
-
- while (list)
- {
- GOptionGroup *group = list->data;
-
- if (strcmp (arg + 5, group->name) == 0)
- print_help (context, FALSE, group);
-
- list = list->next;
- }
- }
- }
+ /* Handle help options */
+ if (context->help_enabled)
+ {
+ if (strcmp (arg, "help") == 0)
+ print_help (context, TRUE, NULL);
+ else if (strcmp (arg, "help-all") == 0)
+ print_help (context, FALSE, NULL);
+ else if (strncmp (arg, "help-", 5) == 0)
+ {
+ list = context->groups;
- if (context->main_group &&
- !parse_long_option (context, context->main_group, &i, arg,
- FALSE, argc, argv, error, &parsed))
- goto fail;
+ while (list)
+ {
+ GOptionGroup *group = list->data;
- if (parsed)
- continue;
-
- /* Try the groups */
- list = context->groups;
- while (list)
- {
- GOptionGroup *group = list->data;
-
- if (!parse_long_option (context, group, &i, arg,
- FALSE, argc, argv, error, &parsed))
- goto fail;
-
- if (parsed)
- break;
-
- list = list->next;
- }
-
- if (parsed)
- continue;
+ if (strcmp (arg + 5, group->name) == 0)
+ print_help (context, FALSE, group);
- /* Now look for ---