cleanup
[platform/upstream/glib.git] / gio / glib-compile-schemas.c
index 39938bf..e42949b 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Ryan Lortie <desrt@desrt.ca>
  */
 #include <stdio.h>
 #include <locale.h>
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 #include "gvdb/gvdb-builder.h"
 #include "strinfo.c"
 
+#ifdef G_OS_WIN32
+#include "glib/glib-private.h"
+#endif
+
+static void
+strip_string (GString *string)
+{
+  gint i;
+
+  for (i = 0; g_ascii_isspace (string->str[i]); i++);
+  g_string_erase (string, 0, i);
+
+  if (string->len > 0)
+    {
+      /* len > 0, so there must be at least one non-whitespace character */
+      for (i = string->len - 1; g_ascii_isspace (string->str[i]); i--);
+      g_string_truncate (string, i + 1);
+    }
+}
+
 /* Handling of <enum> {{{1 */
 typedef struct
 {
@@ -629,6 +643,23 @@ key_state_serialise (KeyState *state)
           /* translation */
           if (state->l10n)
             {
+              /* We are going to store the untranslated default for
+               * runtime translation according to the current locale.
+               * We need to strip leading and trailing whitespace from
+               * the string so that it's exactly the same as the one
+               * that ended up in the .po file for translation.
+               *
+               * We want to do this so that
+               *
+               *   <default l10n='messages'>
+               *     ['a', 'b', 'c']
+               *   </default>
+               *
+               * ends up in the .po file like "['a', 'b', 'c']",
+               * omitting the extra whitespace at the start and end.
+               */
+              strip_string (state->unparsed_default_value);
+
               if (state->l10n_context)
                 {
                   gint len;
@@ -761,7 +792,7 @@ is_valid_keyname (const gchar  *key,
         {
           g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        _("invalid name '%s': invalid character '%c'; "
-                         "only lowercase letters, numbers and dash ('-') "
+                         "only lowercase letters, numbers and hyphen ('-') "
                          "are permitted."), key, key[i]);
           return FALSE;
         }
@@ -769,7 +800,7 @@ is_valid_keyname (const gchar  *key,
       if (key[i] == '-' && key[i + 1] == '-')
         {
           g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                       _("invalid name '%s': two successive dashes ('--') "
+                       _("invalid name '%s': two successive hyphens ('--') "
                          "are not permitted."), key);
           return FALSE;
         }
@@ -779,7 +810,7 @@ is_valid_keyname (const gchar  *key,
     {
       g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                    _("invalid name '%s': the last character may not be a "
-                     "dash ('-')."), key);
+                     "hyphen ('-')."), key);
       return FALSE;
     }
 
@@ -1089,8 +1120,8 @@ parse_state_start_schema (ParseState  *state,
         {
           g_set_error (error, G_MARKUP_ERROR,
                        G_MARKUP_ERROR_INVALID_CONTENT,
-                       _("<schema id='%s'> extends not yet "
-                         "existing schema '%s'"), id, extends_name);
+                       _("<schema id='%s'> extends not yet existing "
+                         "schema '%s'"), id, extends_name);
           return;
         }
     }
@@ -1105,8 +1136,8 @@ parse_state_start_schema (ParseState  *state,
         {
           g_set_error (error, G_MARKUP_ERROR,
                        G_MARKUP_ERROR_INVALID_CONTENT,
-                       _("<schema id='%s'> is list of not yet "
-                         "existing schema '%s'"), id, list_of);
+                       _("<schema id='%s'> is list of not yet existing "
+                         "schema '%s'"), id, list_of);
           return;
         }
 
@@ -1171,6 +1202,12 @@ parse_state_start_schema (ParseState  *state,
       return;
     }
 
+  if (path && (g_str_has_prefix (path, "/apps/") ||
+               g_str_has_prefix (path, "/desktop/") ||
+               g_str_has_prefix (path, "/system/")))
+    g_printerr ("warning: Schema '%s' has path '%s'.  Paths starting with "
+                "'/apps/', '/desktop/' or '/system/' are deprecated.\n", id, path);
+
   state->schema_state = schema_state_new (path, gettext_domain,
                                           extends, extends_name, list_of);
 
@@ -1417,7 +1454,7 @@ start_element (GMarkupParseContext  *context,
                  element_name, container);
   else
     g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
-                 _("Element <%s> not allowed at toplevel"), element_name);
+                 _("Element <%s> not allowed at the top level"), element_name);
 }
 /* 2}}} */
 /* End element {{{2 */
@@ -1498,21 +1535,38 @@ text (GMarkupParseContext  *context,
       GError              **error)
 {
   ParseState *state = user_data;
-  gsize i;
-
-  for (i = 0; i < text_len; i++)
-    if (!g_ascii_isspace (text[i]))
-      {
-        if (state->string)
-          g_string_append_len (state->string, text, text_len);
 
-        else
-          g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                       _("text may not appear inside <%s>"),
-                       g_markup_parse_context_get_element (context));
+  if (state->string)
+    {
+      /* we are expecting a string, so store the text data.
+       *
+       * we store the data verbatim here and deal with whitespace
+       * later on.  there are two reasons for that:
+       *
+       *  1) whitespace is handled differently depending on the tag
+       *     type.
+       *
+       *  2) we could do leading whitespace removal by refusing to
+       *     insert it into state->string if it's at the start, but for
+       *     trailing whitespace, we have no idea if there is another
+       *     text() call coming or not.
+       */
+      g_string_append_len (state->string, text, text_len);
+    }
+  else
+    {
+      /* string is not expected: accept (and ignore) pure whitespace */
+      gsize i;
 
-        break;
-      }
+      for (i = 0; i < text_len; i++)
+        if (!g_ascii_isspace (text[i]))
+          {
+            g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+                         _("text may not appear inside <%s>"),
+                         g_markup_parse_context_get_element (context));
+            break;
+          }
+    }
 }
 
 /* Write to GVDB {{{1 */
@@ -1604,7 +1658,7 @@ output_schema (gpointer key,
 
   if (state->list_of)
     gvdb_hash_table_insert_string (data.pair.table, ".list-of",
-                                   state->extends_name);
+                                   state->list_of);
 
   if (data.l10n)
     gvdb_hash_table_insert_string (data.pair.table,
@@ -1667,7 +1721,9 @@ parse_gschema_files (gchar    **files,
         }
 
       context = g_markup_parse_context_new (&parser,
-                                            G_MARKUP_PREFIX_ERROR_POSITION,
+                                            G_MARKUP_TREAT_CDATA_AS_TEXT |
+                                            G_MARKUP_PREFIX_ERROR_POSITION |
+                                            G_MARKUP_IGNORE_QUALIFIED,
                                             &state, NULL);
 
 
@@ -1800,8 +1856,8 @@ set_overrides (GHashTable  *schema_table,
 
               if (state == NULL)
                 {
-                  fprintf (stderr, _("No such key `%s' in schema `%s' as "
-                                     "specified in override file `%s'"),
+                  fprintf (stderr, _("No such key '%s' in schema '%s' as "
+                                     "specified in override file '%s'"),
                            key, group, filename);
 
                   if (!strict)
@@ -1826,9 +1882,9 @@ set_overrides (GHashTable  *schema_table,
 
               if (value == NULL)
                 {
-                  fprintf (stderr, _("error parsing key `%s' in schema `%s' "
-                                     "as specified in override file `%s': "
-                                     "%s.  "),
+                  fprintf (stderr, _("error parsing key '%s' in schema '%s' "
+                                     "as specified in override file '%s': "
+                                     "%s."),
                            key, group, filename, error->message);
 
                   g_clear_error (&error);
@@ -1854,8 +1910,8 @@ set_overrides (GHashTable  *schema_table,
                       g_variant_compare (value, state->maximum) > 0)
                     {
                       fprintf (stderr,
-                               _("override for key `%s' in schema `%s' in "
-                                 "override file `%s' is out of the range "
+                               _("override for key '%s' in schema '%s' in "
+                                 "override file '%s' is outside the range "
                                  "given in the schema"),
                                key, group, filename);
 
@@ -1882,8 +1938,8 @@ set_overrides (GHashTable  *schema_table,
                   if (!is_valid_choices (value, state->strinfo))
                     {
                       fprintf (stderr,
-                               _("override for key `%s' in schema `%s' in "
-                                 "override file `%s' is not in the list "
+                               _("override for key '%s' in schema '%s' in "
+                                 "override file '%s' is not in the list "
                                  "of valid choices"),
                                key, group, filename);
 
@@ -1946,7 +2002,6 @@ main (int argc, char **argv)
   };
 
 #ifdef G_OS_WIN32
-  extern gchar *_glib_get_locale_dir (void);
   gchar *tmp;
 #endif