patches/GConf-01-g11n-locale-alias.diff
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 15120 e161b1a5d413
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15120
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     1
diff -ur GConf-2.6.1/gconf/gconf-locale.c GConf-2.6.1.hacked/gconf/gconf-locale.c
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     2
--- GConf-2.6.1/gconf/gconf-locale.c.orig	2004-08-02 13:19:41.166861000 -0700
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     3
+++ GConf-2.6.1/gconf/gconf-locale.c	2004-08-02 13:20:49.947469000 -0700
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     4
@@ -22,6 +22,7 @@
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     5
 #include <sys/time.h>
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     6
 #include <time.h>
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     7
 #include <string.h>
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     8
+#include <stdio.h>
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
     9
 
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    10
 static void
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    11
 gconf_locale_cache_add (GConfLocaleCache* cache,
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    12
@@ -189,7 +190,66 @@
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    13
  * Big mess o' cut-and-pasted code
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    14
  */
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    15
 
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    16
-/* --------------------------------------------------------------- */
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    17
+static GHashTable *alias_table = NULL;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    18
+
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    19
+/*read an alias file for the locales*/
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    20
+static void
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    21
+read_aliases (char *file)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    22
+{
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    23
+  FILE *fp;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    24
+  char buf[256];
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    25
+  if (!alias_table)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    26
+    alias_table = g_hash_table_new (g_str_hash, g_str_equal);
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    27
+  fp = fopen (file,"r");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    28
+  if (!fp)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    29
+    return;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    30
+  while (fgets (buf,256,fp))
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    31
+    {
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    32
+      char *p;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    33
+      g_strstrip(buf);
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    34
+      if (buf[0]=='#' || buf[0]=='\0')
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    35
+        continue;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    36
+      p = strtok (buf,"\t ");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    37
+      if (!p)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    38
+	continue;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    39
+      p = strtok (NULL,"\t ");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    40
+      if(!p)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    41
+	continue;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    42
+      if (!g_hash_table_lookup (alias_table, buf))
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    43
+	g_hash_table_insert (alias_table, g_strdup(buf), g_strdup(p));
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    44
+    }
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    45
+  fclose (fp);
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    46
+}
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    47
+
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    48
+/*return the un-aliased language as a newly allocated string*/
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    49
+static char *
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    50
+unalias_lang (char *lang)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    51
+{
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    52
+  char *p;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    53
+  int i;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    54
+  if (!alias_table)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    55
+    {
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    56
+      read_aliases ("/usr/share/locale/locale.alias");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    57
+      read_aliases ("/usr/local/share/locale/locale.alias");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    58
+      read_aliases ("/usr/lib/X11/locale/locale.alias");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    59
+      read_aliases ("/usr/openwin/lib/locale/locale.alias");
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    60
+    }
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    61
+  i = 0;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    62
+  while ((p=g_hash_table_lookup(alias_table,lang)) && strcmp(p, lang))
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    63
+    {
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    64
+      lang = p;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    65
+      if (i++ == 30)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    66
+        {
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    67
+          static gboolean said_before = FALSE;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    68
+	  if (!said_before)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    69
+            g_warning (_("Too many alias levels for a locale, "
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    70
+			 "may indicate a loop"));
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    71
+	  said_before = TRUE;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    72
+	  return lang;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    73
+	}
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    74
+    }
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    75
+  return lang;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    76
+}
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    77
 
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    78
 /* Mask for components of locale spec. The ordering here is from
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    79
  * least significant to most significant
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    80
@@ -360,6 +420,8 @@
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    81
           category_memory[0]= '\0'; 
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    82
           category_memory++;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    83
           
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    84
+	  cp = unalias_lang (cp); /* add locale alias support */
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    85
+
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    86
           if (strcmp (cp, "C") == 0)
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    87
             c_locale_defined= TRUE;
e161b1a5d413 2009-02-17 Stephen Browne <[email protected]>
stephen
parents:
diff changeset
    88