File glib-2.30.0-Add-g_option_context_parse_utf8.patch of Package mingw64-glib2

diff -Naur glib-2.30.0/docs/reference/glib/glib-sections.txt glib-2.30.0.new/docs/reference/glib/glib-sections.txt
--- glib-2.30.0/docs/reference/glib/glib-sections.txt	2011-09-26 22:54:50.000000000 +0200
+++ glib-2.30.0.new/docs/reference/glib/glib-sections.txt	2011-10-04 12:03:58.012842730 +0200
@@ -1129,6 +1129,7 @@
 g_option_context_set_translation_domain
 g_option_context_free
 g_option_context_parse
+g_option_context_parse_utf8
 g_option_context_set_help_enabled
 g_option_context_get_help_enabled
 g_option_context_set_ignore_unknown_options
diff -Naur glib-2.30.0/glib/glib.symbols glib-2.30.0.new/glib/glib.symbols
--- glib-2.30.0/glib/glib.symbols	2011-09-26 22:54:50.000000000 +0200
+++ glib-2.30.0.new/glib/glib.symbols	2011-10-04 12:03:58.012842730 +0200
@@ -750,6 +750,7 @@
 g_option_context_get_summary
 g_option_context_new
 g_option_context_parse
+g_option_context_parse_utf8
 g_option_context_set_description
 g_option_context_set_help_enabled
 g_option_context_set_ignore_unknown_options
diff -Naur glib-2.30.0/glib/goption.c glib-2.30.0.new/glib/goption.c
--- glib-2.30.0/glib/goption.c	2011-09-09 21:58:10.000000000 +0200
+++ glib-2.30.0.new/glib/goption.c	2011-10-04 12:18:27.633154942 +0200
@@ -1124,14 +1124,38 @@
   context->pending_nulls = g_list_prepend (context->pending_nulls, n);
 }
 
+static gchar *
+get_string_arg (const gchar *value,
+                gboolean     utf8_flag,
+                GError     **error)
+{
+  if (utf8_flag)
+    return g_strdup (value);
+
+  return g_locale_to_utf8 (value, -1, NULL, NULL, error);
+}
+
+static gchar *
+get_filename_arg (const gchar *value,
+                  gboolean     utf8_flag,
+                  GError     **error)
+{
+#ifdef G_OS_WIN32
+  if (!utf8_flag)
+    return g_locale_to_utf8 (value, -1, NULL, NULL, error);
+#endif
+
+  return g_strdup (value);
+}
+
 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,
+	   gboolean        utf8_flag,
+	   GError        **error)
 {
   Change *change;
 
@@ -1151,7 +1175,7 @@
       {
         gchar *data;
 
-        data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+        data = get_string_arg (value, utf8_flag, error);
 
         if (!data)
           return FALSE;
@@ -1170,7 +1194,7 @@
       {
         gchar *data;
 
-        data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+        data = get_string_arg (value, utf8_flag, error);
 
         if (!data)
           return FALSE;
@@ -1202,14 +1226,11 @@
       {
         gchar *data;
 
-#ifdef G_OS_WIN32
-        data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+        data = get_filename_arg (value, utf8_flag, 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);
@@ -1225,14 +1246,11 @@
       {
         gchar *data;
 
-#ifdef G_OS_WIN32
-        data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+        data = get_filename_arg (value, utf8_flag, error);
 
         if (!data)
           return FALSE;
-#else
-        data = g_strdup (value);
-#endif
+
         change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
                              entry->arg_data);
 
@@ -1281,15 +1299,9 @@
         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);
-#else
-            data = g_strdup (value);
-#endif
-          }
+          data = get_string_arg (value, utf8_flag, error);
         else
-          data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+          data = get_string_arg (value, utf8_flag, error);
 
         if (!(entry->flags & (G_OPTION_FLAG_NO_ARG|G_OPTION_FLAG_OPTIONAL_ARG)) &&
             !data)
@@ -1355,6 +1367,7 @@
                     gint            idx,
                     gint           *new_idx,
                     gchar           arg,
+                    gboolean        utf8_flag,
                     gint           *argc,
                     gchar        ***argv,
                     GError        **error,
@@ -1417,7 +1430,7 @@
             }
 
           if (!parse_arg (context, group, &group->entries[j],
-                          value, option_name, error))
+                          value, option_name, utf8_flag, error))
             {
               g_free (option_name);
               return FALSE;
@@ -1437,6 +1450,7 @@
                    gint           *idx,
                    gchar          *arg,
                    gboolean        aliased,
+                   gboolean        utf8_flag,
                    gint           *argc,
                    gchar        ***argv,
                    GError        **error,
@@ -1460,7 +1474,7 @@
 
           option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
           retval = parse_arg (context, group, &group->entries[j],
-                              NULL, option_name, error);
+                              NULL, option_name, utf8_flag, error);
           g_free (option_name);
 
           add_pending_null (context, &((*argv)[*idx]), NULL);
@@ -1497,7 +1511,7 @@
                         {
                           gboolean retval;
                           retval = parse_arg (context, group, &group->entries[j],
-                                              NULL, option_name, error);
+                                              NULL, option_name, utf8_flag, error);
                           *parsed = TRUE;
                           g_free (option_name);
                           return retval;
@@ -1514,7 +1528,7 @@
                 {
                     gboolean retval;
                     retval = parse_arg (context, group, &group->entries[j],
-                                        NULL, option_name, error);
+                                        NULL, option_name, utf8_flag, error);
                     *parsed = TRUE;
                     g_free (option_name);
                     return retval;
@@ -1529,7 +1543,7 @@
                 }
 
               if (!parse_arg (context, group, &group->entries[j],
-                              value, option_name, error))
+                              value, option_name, utf8_flag, error))
                 {
                   g_free (option_name);
                   return FALSE;
@@ -1547,6 +1561,7 @@
 static gboolean
 parse_remaining_arg (GOptionContext *context,
                      GOptionGroup   *group,
+                     gboolean        utf8_flag,
                      gint           *idx,
                      gint           *argc,
                      gchar        ***argv,
@@ -1569,7 +1584,7 @@
 
       add_pending_null (context, &((*argv)[*idx]), NULL);
 
-      if (!parse_arg (context, group, &group->entries[j], (*argv)[*idx], "", error))
+      if (!parse_arg (context, group, &group->entries[j], (*argv)[*idx], "", utf8_flag, error))
         return FALSE;
 
       *parsed = TRUE;
@@ -1690,46 +1705,12 @@
   return NULL;
 }
 
-/**
- * g_option_context_parse:
- * @context: a #GOptionContext
- * @argc: (inout) (allow-none): a pointer to the number of command line arguments
- * @argv: (inout) (array length=argc) (allow-none): a pointer to the array of command line arguments
- * @error: a return location for errors
- *
- * Parses the command line arguments, recognizing options
- * 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
- * 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.
- *
- * If automatic <option>--help</option> support is enabled
- * (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 <literal>exit (0)</literal>.
- *
- * Note that function depends on the
- * <link linkend="setlocale">current locale</link> for
- * automatic character set conversion of string and filename
- * arguments.
- *
- * 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)
+static gboolean
+option_context_parse_internal (GOptionContext   *context,
+                               gboolean          utf8_flag,
+                               gint             *argc,
+                               gchar          ***argv,
+                               GError          **error)
 {
   gint i, j, k;
   GList *list;
@@ -1827,7 +1808,7 @@
 
                   if (context->main_group &&
                       !parse_long_option (context, context->main_group, &i, arg,
-                                          FALSE, argc, argv, error, &parsed))
+                                          FALSE, utf8_flag, argc, argv, error, &parsed))
                     goto fail;
 
                   if (parsed)
@@ -1840,7 +1821,7 @@
                       GOptionGroup *group = list->data;
 
                       if (!parse_long_option (context, group, &i, arg,
-                                              FALSE, argc, argv, error, &parsed))
+                                              FALSE, utf8_flag, argc, argv, error, &parsed))
                         goto fail;
 
                       if (parsed)
@@ -1865,7 +1846,7 @@
                           if (strncmp (group->name, arg, dash - arg) == 0)
                             {
                               if (!parse_long_option (context, group, &i, dash + 1,
-                                                      TRUE, argc, argv, error, &parsed))
+                                                      TRUE, utf8_flag, argc, argv, error, &parsed))
                                 goto fail;
 
                               if (parsed)
@@ -1896,7 +1877,7 @@
                       parsed = FALSE;
                       if (context->main_group &&
                           !parse_short_option (context, context->main_group,
-                                               i, &new_i, arg[j],
+                                               i, &new_i, arg[j], utf8_flag,
                                                argc, argv, error, &parsed))
                         goto fail;
                       if (!parsed)
@@ -1907,7 +1888,7 @@
                             {
                               GOptionGroup *group = list->data;
                               if (!parse_short_option (context, group, i, &new_i, arg[j],
-                                                       argc, argv, error, &parsed))
+                                                       utf8_flag, argc, argv, error, &parsed))
                                 goto fail;
                               if (parsed)
                                 break;
@@ -1962,7 +1943,7 @@
             {
               /* Collect remaining args */
               if (context->main_group &&
-                  !parse_remaining_arg (context, context->main_group, &i,
+                  !parse_remaining_arg (context, context->main_group, utf8_flag, &i,
                                         argc, argv, error, &parsed))
                 goto fail;
 
@@ -2050,6 +2031,95 @@
 }
 
 /**
+ * g_option_context_parse:
+ * @context: a #GOptionContext
+ * @argc: (inout): a pointer to the number of command line arguments
+ * @argv: (inout) (array lenth=argc) (element-type filename): a pointer to an array of command line arguments
+ * @error: (allow-none): a location to store a #GError, or %NULL
+ *
+ * Parses the command line arguments, recognizing options
+ * 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
+ * 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.
+ *
+ * If automatic <option>--help</option> support is enabled
+ * (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 <literal>exit (0)</literal>.
+ *
+ * Note that function depends on the
+ * <link linkend="setlocale">current locale</link> for
+ * automatic character set conversion of string and filename
+ * arguments.
+ *
+ * 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)
+{
+  return option_context_parse_internal (context, FALSE, argc, argv, error);
+}
+
+/**
+ * g_option_context_parse_utf8:
+ * @context: a #GOptionContext
+ * @argc: (inout): a pointer to the number of strings in @argv
+ * @argv: (inout) (array length=argc) (element-type utf-8): a pointer to an array of UTF-8 strings
+ * @error: (allow-none): a location to store a #GError, or %NULL
+ *
+ * A variant of g_option_context_parse() that treats @argv as an
+ * array of UTF-8 strings.
+ *
+ * This function is suitable for use with the wide arguments array
+ * returned from g_win32_get_wargv().
+ *
+ * Note that arguments for %G_OPTION_ARG_FILENAME and
+ * %G_OPTION_ARG_FILENAME_ARRAY options, and %G_OPTION_ARG_CALLBACK
+ * options with %G_OPTION_FLAG_FILENAME will be passed the unchanged
+ * UTF-8 strings, and not strings converted to filename encoding
+ * (see g_filename_from_utf8()).
+ *
+ * Return value: %TRUE if the parsing was successful,
+ *               %FALSE if an error occurred
+ *
+ * Since: 2.26
+ **/
+gboolean
+g_option_context_parse_utf8 (GOptionContext   *context,
+                             gint             *argc,
+                             gchar          ***argv,
+                             GError          **error)
+{
+  gint i;
+
+  for (i = 0; i < *argc; ++i)
+    {
+      if (!g_utf8_validate ((*argv)[i], -1, NULL))
+        {
+          g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+                       "Argument is not UTF-8");
+          return FALSE;
+        }
+    }
+
+  return option_context_parse_internal (context, TRUE, argc, argv, error);
+}
+
+/**
  * g_option_group_new:
  * @name: the name for the option group, this is used to provide
  *   help for the options in this group with <option>--help-</option>@name
diff -Naur glib-2.30.0/glib/goption.h glib-2.30.0.new/glib/goption.h
--- glib-2.30.0/glib/goption.h	2011-09-09 21:58:10.000000000 +0200
+++ glib-2.30.0.new/glib/goption.h	2011-10-04 12:03:58.016842743 +0200
@@ -329,6 +329,11 @@
 						   gint                *argc,
 						   gchar             ***argv,
 						   GError             **error);
+gboolean	g_option_context_parse_utf8       (GOptionContext      *context,
+						   gint                *argc,
+						   gchar             ***argv,
+						   GError             **error);
+
 void            g_option_context_set_translate_func (GOptionContext     *context,
 						     GTranslateFunc      func,
 						     gpointer            data,
openSUSE Build Service is sponsored by