Locale Patch

Peter Naulls peter at chocky.org
Mon Jun 10 10:54:43 PDT 2002


The following adds the LC_MESSAGES define with suitable code, and fixes
some warnings in the locale code:

Index: clib/locale.h
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/clib/locale.h,v
retrieving revision 1.2
diff -u -r1.2 locale.h
--- clib/locale.h	29 Jan 2001 15:10:19 -0000	1.2
+++ clib/locale.h	10 Jun 2002 17:49:42 -0000
@@ -25,14 +25,16 @@
 /* Classification and conversion of characters, multibyte and
    wide characters.  */
 #define LC_CTYPE 1
+/* Localisable natural-language messages.  */
+#define LC_MESSAGES 2
 /* Formatting of monetary values.  */
-#define LC_MONETARY 2
+#define LC_MONETARY 3
 /* Formatting of numeric values that are not monetary. */
-#define LC_NUMERIC 3
+#define LC_NUMERIC 4
 /* Formatting of data and time values.  */
-#define LC_TIME 4
+#define LC_TIME 5
 /* Entire locale.  */
-#define LC_ALL 5
+#define LC_ALL 6
 
 /* Sets the current locale for category 'category' to 'locale'.
Index: locale/localeconv.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/locale/localeconv.c,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 localeconv.c
--- locale/localeconv.c	4 Sep 2001 16:32:04 -0000	1.2.2.2
+++ locale/localeconv.c	10 Jun 2002 17:49:52 -0000
@@ -121,13 +121,13 @@
      meanings of the following numbers.  */
   if (numeric == -1)
     {
-      /* We using the 'C' locale.  */
-      lc.decimal_point = ".";
-      lc.thousands_sep = "";
-      if (lc.grouping == NULL)
-	lc.grouping = malloc (1);
-      if (lc.grouping != NULL)
-	lc.grouping[0] = '\0';
+      /* We're using the 'C' locale.  */
+      free(lc.decimal_point);
+      lc.decimal_point = strdup(".");
+      free(lc.thousands_sep);
+      lc.thousands_sep = strdup("");
+      free(lc.grouping);
+      lc.grouping = strdup("");
     }
   else
     {
@@ -139,22 +139,26 @@
     {
       /* We using the 'C' locale.  Empty strings and CHAR_MAX means
 	 that these fields are unspecified.  */
-      lc.mon_decimal_point = "";
-      lc.mon_thousands_sep = "";
-      if (lc.mon_grouping == NULL)
-	lc.mon_grouping = malloc (1);
-      if (lc.mon_grouping != NULL)
-	lc.mon_grouping[0] = '\0';
+      free(lc.mon_decimal_point);
+      lc.mon_decimal_point = strdup("");
+      free(lc.mon_thousands_sep);
+      lc.mon_thousands_sep = strdup("");
+      free(lc.mon_grouping);
+      lc.mon_grouping = strdup("");
       lc.int_frac_digits = CHAR_MAX;
       lc.frac_digits = CHAR_MAX;
-      lc.currency_symbol = "";
-      lc.int_curr_symbol = "";
+      free(lc.currency_symbol);
+      lc.currency_symbol = strdup("");
+      free(lc.int_curr_symbol);
+      lc.int_curr_symbol = strdup("");
       lc.p_cs_precedes = CHAR_MAX;
       lc.n_cs_precedes = CHAR_MAX;
       lc.p_sep_by_space = CHAR_MAX;
       lc.n_sep_by_space = CHAR_MAX;
-      lc.positive_sign = "";
-      lc.negative_sign = "";
+      free(lc.positive_sign);
+      lc.positive_sign = strdup("");
+      free(lc.negative_sign);
+      lc.negative_sign = strdup("");
       lc.p_sign_posn = CHAR_MAX;
       lc.n_sign_posn = CHAR_MAX;
     }
Index: locale/setlocale.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/locale/setlocale.c,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 setlocale.c
--- locale/setlocale.c	4 Sep 2001 16:32:04 -0000	1.2.2.2
+++ locale/setlocale.c	10 Jun 2002 17:49:53 -0000
@@ -24,8 +24,9 @@
 
 /* Locale information types. These should correspond to the #defines
    in <locale.h>.  */
-static char *locale_names[] = { "LC_COLLATE", "LC_CTYPE", "LC_MONETARY",
-				"LC_NUMERIC", "LC_TIME", "LC_ALL" };
+static const char *locale_names[] = { "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES",
+                                      "LC_MONETARY", "LC_NUMERIC", "LC_TIME",
+                                      "LC_ALL" };
 
 /* Convert a territory number into a name.  */
 static void territory_name (int territory, char *buffer, int size)




-- 
------------------------------------------------------------------------
 Peter Naulls - peter at chocky.org
 Homepage                     -  http://www.chocky.org/
 RISC OS Projects Initiative  -  http://initiative.chocky.org/
 RISC OS C Programming        -  http://www.riscos.info/
------------------------------------------------------------------------



More information about the gcc mailing list