This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Patch: java.util.Currency implementation


Michael> Yes, can you please send it to me ?

I've CCd the list to put it on the record.
(It may already be in the classpath archives, I forget.)

I haven't tried it since around Jan 2002.  It probably won't apply
cleanly to the glibc tree :-(.

Any improvements here are definitely welcome.  For instance we could
generate collation tables for java.text (hard), generate properties
files instead of classes (easy), add other missing locale information
(unknown).

Also cool would be to either get something like this into glibc or to
write a new program that reads the glibc compiled format and writes
out our files -- anything to get this more robust than "patch in Tom's
home directory".

Tom


Index: Makefile
===================================================================
RCS file: /cvs/glibc/libc/locale/Makefile,v
retrieving revision 1.59
diff -u -r1.59 Makefile
--- Makefile 2001/08/14 22:37:31 1.59
+++ Makefile 2002/01/03 04:44:07
@@ -59,7 +59,7 @@
 vpath %.gperf programs
 
 localedef-modules	:= $(categories:%=ld-%) charmap linereader locfile \
-			   repertoire
+			   repertoire java-output
 locale-modules		:= locale-spec
 lib-modules		:= charmap-dir simple-hash xmalloc xstrdup
 
Index: programs/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* locfile.h (java_monetary_output): Declare.
	(java_numeric_output): Likewise.
	(java_time_output): Likewise.
	* localedef.h (java_style): Declare.
	(java_end_locale, java_start_locale, java_printf,
	java_print_string): Likewise.
	* locfile.c (java_write_funcs): New global.
	* java-output.c: New file.
	* ld-time.c (java_time_output): New function.
	(java_print_time_format): Likewise.
	(java_time_map): New global.
	(struct time_map): New struct.
	(java_print_array): New function.
	* ld-numeric.c (java_numeric_output): New function.
	(java_print_number_format): Likewise.
	* ld-monetary.c (java_monetary_output): New function.
	(java_print_monetary_format): Likewise.
	* localedef.c (java_style): New global.
	(OPT_JAVA): New define.
	(options): Added `java' entry.
	(parse_opt): Handle --java.

Index: programs/java-output.c
===================================================================
RCS file: java-output.c
diff -N java-output.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ programs/java-output.c Wed Jan 2 20:44:08 2002
@@ -0,0 +1,179 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Tom Tromey <tromey@gnu.org>, 2001
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <langinfo.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <assert.h>
+
+#include "linereader.h"
+#include "localedef.h"
+#include "localeinfo.h"
+#include "locfile.h"
+
+/* Current locale we're generating, or NULL if we haven't started one
+   yet.  */
+static struct localedef_t *current;
+
+/* File handle corresponding to current locale being generated.  */
+static FILE *current_file;
+
+static const char *fields[] =
+{
+  "weekdays",
+  "shortWeekdays",
+  "shortMonths",
+  "months",
+#if 0
+  "eras",
+#endif
+  "ampms",
+  "shortDateFormat",
+#if 0
+  "mediumTimeFormat",
+#endif
+  "defaultTimeFormat",
+  "currencySymbol",
+  "intlCurrencySymbol",
+  "currencyFormat",
+  "decimalSeparator",
+  "groupingSeparator",
+  "numberFormat",
+  "percentFormat",
+  NULL
+};
+
+void
+java_end_locale ()
+{
+  int i;
+
+  java_printf (current, "  private static final Object[][] contents =\n  {\n");
+  for (i = 0; fields[i]; ++i)
+    {
+      java_printf (current, "    { \"%s\", %s },\n",
+		   fields[i], fields[i]);
+    }
+  java_printf (current, "  };\n\n");
+  java_printf (current, "  public Object[][] getContents () { return contents; }\n}\n");
+
+  fclose (current_file);
+  current_file = NULL;
+  current = NULL;
+}
+
+void
+java_start_locale (const char *output_path, struct localedef_t *locale)
+{
+  char *fname;
+  const char *lname;
+
+  assert (! current && ! current_file);
+
+  lname = strrchr (locale->name, '/');
+  if (lname == NULL)
+    lname = locale->name;
+  else
+    ++lname;
+
+  fname = xmalloc (strlen (output_path) + strlen (lname) + 25);
+  sprintf (fname, "%s/LocaleInformation_%s.java", output_path, lname);
+
+  current = locale;
+  current_file = fopen (fname, "w");
+  if (current_file == NULL)
+    error (1, errno, _("cannot open output file `%s'"), fname);
+  free (fname);
+
+  fprintf (current_file, "// This file was automatically generated by localedef.\n\n");
+  fprintf (current_file, "package gnu.java.locale;\n\n");
+  fprintf (current_file, "import java.util.ListResourceBundle;\n\n");
+  fprintf (current_file, "public class LocaleInformation_%s extends ListResourceBundle\n{\n",
+	   lname);
+}
+
+/* Extract a character from a Java-style Utf8 string.
+ * PTR points to the current character.
+ * LIMIT points to the end of the Utf8 string.
+ * PTR is incremented to point after the character thta gets returns.
+ * On an error, -1 is returned. */
+#define UTF8_GET(PTR, LIMIT) \
+  ((PTR) >= (LIMIT) ? -1 \
+   : *(PTR) < 128 ? *(PTR)++ \
+   : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
+   ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
+   : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
+   && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
+   ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
+   : ((PTR)++, -1))
+
+void
+java_printf (struct localedef_t *locale,
+	     const char *format,
+	     ...)
+{
+  va_list ap;
+  unsigned char *out, *limit;
+
+  assert (locale == current);
+
+  /* Print to a temporary string, and then print in a Java-friendly
+     way.  This is ugly, and inefficient, but that doesn't really
+     matter to us.  */
+  va_start (ap, format);
+  vasprintf ((char **) &out, format, ap);
+  va_end (ap);
+
+  limit = out + strlen (out);
+  while (out < limit)
+    {
+      unsigned int c = UTF8_GET (out, limit);
+      if (c == -1)
+	break;
+      if ((c < 32 || c > 127)
+	  && c != '\t' && c != '\n')
+	fprintf (current_file, "\\u%04X", c);
+      else
+	fputc (c, current_file);
+    }
+
+  /*  free (out);*/
+}
+
+void
+java_print_string (struct localedef_t *locale,
+		   const char *copy_name,
+		   const char *field_name,
+		   const char *value)
+{
+  java_printf (locale, "  static final String %s = ", field_name);
+  if (copy_name)
+    java_printf (locale, "LocaleInformation_%s.%s;\n",
+		 copy_name, field_name);
+  else
+    java_printf (locale, "\"%s\";\n", value);
+}
Index: programs/ld-monetary.c
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/ld-monetary.c,v
retrieving revision 1.32
diff -u -r1.32 ld-monetary.c
--- programs/ld-monetary.c 2001/12/10 01:15:02 1.32
+++ programs/ld-monetary.c 2002/01/03 04:44:11
@@ -623,6 +623,152 @@
   return strcmp (s1, *s2);
 }
 
+/* Helper for java_monetary_output which knows how to print a single
+   number format.  */
+static void
+java_print_monetary_format (struct localedef_t *locale,
+			    int cs_precedes, int sep_by_space,
+			    const char *grouping,
+			    int frac_digits,
+			    const char *sign,
+			    int sign_posn)
+{
+  int len = strlen (grouping);
+  int i;
+
+  /* FIXME: we don't handle the difference between sep_by_space==1 and
+     sep_by_space==2.  */
+
+  if (sign_posn < 0 || sign_posn > 4)
+    sign_posn = 4;
+
+  /* Handle leading sign and monetary symbol, if required.  */
+  if (sign_posn == 0)
+    java_printf (locale, "(");
+  else if (sign_posn == 1)
+    java_printf (locale, "%s", sign);
+  if (cs_precedes)
+    {
+      if (sign_posn == 3)
+	java_printf (locale, "%s", sign);
+
+      /* Here the `$' is a NumberFormat pattern char.  It will be
+	 localized at runtime.  */
+      java_printf (locale, "$");
+      if (sep_by_space)
+	java_printf (locale, " ");
+
+      if (sign_posn == 4)
+	java_printf (locale, "%s", sign);
+    }
+
+  /* Handle grouping.  `,' here is a symbol for NumberFormat; it is
+     localized at runtime.  */
+  java_printf (locale, "#");
+  for (i = len - 1; i >= 0; --i)
+    {
+      int j;
+      /* Java can't handle this case.  */
+      if (grouping[i] == '\377')
+	continue;
+      java_printf (locale, ",");
+      for (j = grouping[i] - 1; j >= 0; --j)
+	{
+	  java_printf (locale, "%s", 
+		       (i == 0 && j == 0) ? "0" : "#");
+	}
+    }
+
+  /* Fractional digits.  */
+  java_printf (locale, ".");
+  for (i = 0; i < frac_digits; ++i)
+    java_printf (locale, "0");
+
+  /* Trailing sign and monetary symbol, if required.  */
+  if (! cs_precedes)
+    {
+      if (sign_posn == 3)
+	java_printf (locale, "%s", sign);
+      if (sep_by_space)
+	java_printf (locale, " ");
+      java_printf (locale, "$");
+      if (sign_posn == 4)
+	java_printf (locale, "%s", sign);
+    }
+  if (sign_posn == 2)
+    java_printf (locale, "%s", sign);
+  if (sign_posn == 0)
+    java_printf (locale, ")");
+}
+
+/* Generate output suitable for libgcj.  */
+void
+java_monetary_output (struct localedef_t *locale,
+		      const struct charmap_t *charmap,
+		      const char *output_path)
+{
+  struct locale_monetary_t *monetary
+    = locale->categories[LC_MONETARY].monetary;
+  const char *copy_name = NULL;
+  char sym[4];
+
+  if (locale->copy_name[LC_MONETARY] != NULL)
+    {
+      /* If we're copying some other locale, we might as well just
+	 refer directly to it.  */
+      struct localedef_t *from = locale;
+
+      do
+	from = find_locale (LC_MONETARY, from->copy_name[LC_MONETARY],
+			    from->repertoire_name, charmap);
+      while (from->copy_name[LC_MONETARY] != NULL);
+      copy_name = from->name;
+    }
+
+  java_print_string (locale, copy_name, "currencySymbol",
+		     monetary->currency_symbol);
+  /* Remove the trailing space from the international symbol.  */
+  assert (monetary->int_curr_symbol[3] == ' ');
+  strncpy (sym, monetary->int_curr_symbol, 3);
+  sym[3] = '\0';
+  java_print_string (locale, copy_name, "intlCurrencySymbol", sym);
+
+  java_printf (locale, "  static final String currencyFormat = ");
+  if (copy_name)
+    java_printf (locale, "LocaleInformation_%s.currencyFormat;\n",
+		 copy_name);
+  else
+    {
+      /* Generate something NumberFormat will recognize.  */
+      java_printf (locale, "\"");
+
+      java_print_monetary_format (locale, monetary->p_cs_precedes,
+				  monetary->p_sep_by_space,
+				  monetary->mon_grouping,
+				  /* Java doesn't have a notion of an
+				     international currency format.
+				     So we always use the local value
+				     here.  */
+				  monetary->int_frac_digits,
+				  monetary->positive_sign,
+				  monetary->p_sign_posn);
+      java_printf (locale, ";");
+      java_print_monetary_format (locale, monetary->n_cs_precedes,
+				  monetary->n_sep_by_space,
+				  monetary->mon_grouping,
+				  /* Java doesn't have a notion of an
+				     international currency format.
+				     So we always use the local value
+				     here.  */
+				  monetary->int_frac_digits,
+				  monetary->negative_sign,
+				  monetary->n_sign_posn);
+      java_printf (locale, "\";\n");
+    }
+
+  java_printf (locale, "\n");
+}
+
 
 /* The parser for the LC_MONETARY section of the locale definition.  */
 void
Index: programs/ld-numeric.c
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/ld-numeric.c,v
retrieving revision 1.25
diff -u -r1.25 ld-numeric.c
--- programs/ld-numeric.c 2001/12/10 01:15:02 1.25
+++ programs/ld-numeric.c 2002/01/03 04:44:13
@@ -191,6 +191,74 @@
 }
 
 
+/* Helper for java_numeric_output which generates a numeric format.  */
+static void
+java_print_number_format (struct localedef_t *locale,
+			  const char *copy_name,
+			  const char *grouping,
+			  int is_perc)
+{
+  const char *name = is_perc ? "percentFormat" : "numberFormat";
+
+  java_printf (locale, "  static final String %s = ", name);
+  if (copy_name)
+    java_printf (locale, "LocaleInformation_%s.%s;\n",
+		 copy_name, name);
+  else
+    {
+      int i;
+      java_printf (locale, "\"#");
+      for (i = strlen (grouping) - 1; i >= 0; --i)
+	{
+	  int j;
+	  /* Java can't handle this case.  */
+	  if (grouping[i] == '\377')
+	    continue;
+	  java_printf (locale, ",");
+	  for (j = grouping[i] - 1; j >= 0; --j)
+	    {
+	      java_printf (locale, "%s", 
+			   (i == 0 && j == 0) ? "0" : "#");
+	    }
+	}
+      java_printf (locale, "%s\";\n",
+		   is_perc ? "%" : ".###");
+    }
+}
+
+/* Generate output suitable for libgcj.  */
+void
+java_numeric_output (struct localedef_t *locale,
+		     const struct charmap_t *charmap,
+		     const char *output_path)
+{
+  struct locale_numeric_t *numeric
+    = locale->categories[LC_NUMERIC].numeric;
+  const char *copy_name = NULL;
+
+  if (locale->copy_name[LC_NUMERIC] != NULL)
+    {
+      /* If we're copying some other locale, we might as well just
+	 refer directly to it.  */
+      struct localedef_t *from = locale;
+
+      do
+	from = find_locale (LC_NUMERIC, from->copy_name[LC_NUMERIC],
+			    from->repertoire_name, charmap);
+      while (from->copy_name[LC_NUMERIC] != NULL);
+      copy_name = from->name;
+    }
+
+  java_print_string (locale, copy_name, "decimalSeparator",
+		     numeric->decimal_point);
+  java_print_string (locale, copy_name, "groupingSeparator",
+		     numeric->thousands_sep);
+
+  /* Handle numeric formats.  */
+  java_print_number_format (locale, copy_name, numeric->grouping, 0);
+  java_print_number_format (locale, copy_name, numeric->grouping, 1);
+}
+
 /* The parser for the LC_NUMERIC section of the locale definition.  */
 void
 numeric_read (struct linereader *ldfile, struct localedef_t *result,
Index: programs/ld-time.c
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/ld-time.c,v
retrieving revision 1.36
diff -u -r1.36 ld-time.c
--- programs/ld-time.c 2001/12/10 01:15:02 1.36
+++ programs/ld-time.c 2002/01/03 04:44:16
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995-1999, 2000, 2001 , 2002Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
 
@@ -906,6 +906,185 @@
   assert (last_idx  == _NL_ITEM_INDEX (_NL_NUM_LC_TIME));
 
   write_locale_data (output_path, "LC_TIME", 2 + cnt, iov);
+}
+
+
+/* Helper function for java_time_output which prints a string array.  */
+static void
+java_print_array (struct localedef_t *locale,
+		  const char *copy_name,
+		  const char *field_name,
+		  const char **text,
+		  int max,
+		  int null_position)
+{
+  assert (null_position == -1 || null_position == 0 || null_position == max);
+
+  java_printf (locale, "  static final String[] %s = ", field_name);
+  if (copy_name)
+    java_printf (locale, "LocaleInformation_%s.%s;\n", copy_name, field_name);
+  else
+    {
+      int count;
+      java_printf (locale, "{ ");
+      if (null_position == 0)
+	java_printf (locale, "null, ");
+      for (count = 0; count < max; ++count)
+	{
+	  java_printf (locale, "\"%s\"", text[count]);
+	  if (count + 1 < max || null_position == max)
+	    java_printf (locale, ", ");
+	}
+      if (null_position == max)
+	java_printf (locale, "null");
+      java_printf (locale, " };\n");
+    }
+  java_printf (locale, "\n");
+}
+
+struct time_map
+{
+  /* Format for strftime.  \0 here indicates end of table.  */
+  char ftime;
+  /* Format for SimpleDateFormat.  NULL here indicates entry we don't
+     handle.  */
+  const char *datef;
+};
+
+const static struct time_map java_time_map[] =
+{
+  { 'a', "E" },
+  { 'A', "EEEE" },
+  { 'b', "MMM" },
+  { 'B', "MMMM" },
+  { 'c', NULL },
+  { 'C', "yy" },
+  { 'd', "dd" },
+  { 'D', NULL },
+  { 'e', NULL },
+  { 'F', NULL },
+  { 'g', NULL },
+  { 'G', NULL },
+  { 'h', "MMM" },
+  { 'H', "H" },
+  { 'I', "hh" },
+  { 'j', "D" },
+  { 'k', "H" },
+  { 'l', "hh" },
+  { 'm', "MM" },
+  { 'M', "m" },
+  { 'n', "\n" },
+  { 'p', "a" },
+  { 'P', "a" },
+  { 'r', NULL },
+  { 'R', NULL },
+  { 's', NULL },
+  { 'S', "s" },
+  { 't', "\t" },
+  { 'T', NULL },
+  { 'u', NULL },
+  { 'U', "w" },
+  { 'U', "w" },
+  { 'V', "w" },
+  { 'w', NULL },
+  { 'W', "w" },
+  { 'x', NULL },
+  { 'X', NULL },
+  { 'y', "yy" },
+  { 'Y', "yyyy" },
+  { 'z', "z" },
+  { 'Z', "z" },
+  { '%', "%" },
+  { '\0', NULL }
+};
+
+/* Helper for java_time_output.  This transforms a strftime-style
+   format to a DateFormat-style format.  */
+static void
+java_print_time_format (struct localedef_t *locale,
+			const char *copy_name,
+			const char *field_name,
+			const char *in_fmt)
+{
+  int i;
+  int was_perc = 0;
+
+  java_printf (locale, "  static final String %s = ", field_name);
+  if (copy_name)
+    java_printf (locale, "LocaleInformation_%s.%s;\n",
+		 copy_name, field_name);
+  else
+    {
+      java_printf (locale, "\"");
+      for (i = 0; in_fmt[i] != '\0'; ++i)
+	{
+	  if (was_perc)
+	    {
+	      int j;
+	      for (j = 0; java_time_map[j].ftime != '\0'; ++j)
+		{
+		  if (java_time_map[j].ftime == in_fmt[i])
+		    {
+		      java_printf (locale, "%s", java_time_map[j].datef);
+		      break;
+		    }
+		}
+	      assert (java_time_map[j].datef);
+	      was_perc = 0;
+	    }
+	  else if (in_fmt[i] == '%')
+	    was_perc = 1;
+	  else
+	    {
+	      /* FIXME: handle quoting, utf-8 here.  */
+	      java_printf (locale, "%c", in_fmt[i]);
+	    }
+	}
+      java_printf (locale, "\";\n");
+    }
+}
+
+/* Generate output suitable for libgcj.  */
+void
+java_time_output (struct localedef_t *locale, const struct charmap_t *charmap,
+		  const char *output_path)
+{
+  struct locale_time_t *time = locale->categories[LC_TIME].time;
+  const char *copy_name = NULL;
+
+  if (locale->copy_name[LC_TIME] != NULL)
+    {
+      /* If we're copying some other locale, we might as well just
+	 refer directly to it.  */
+      struct localedef_t *from = locale;
+
+      do
+	from = find_locale (LC_TIME, from->copy_name[LC_TIME],
+			    from->repertoire_name, charmap);
+      while (from->copy_name[LC_TIME] != NULL);
+      copy_name = from->name;
+    }
+
+  /* FIXME: in general what should we do if something is missing??  */
+  java_print_array (locale, copy_name, "weekdays", time->day, 7, 0);
+  java_print_array (locale, copy_name, "shortWeekdays", time->abday, 7, 0);
+  java_print_array (locale, copy_name, "shortMonths", time->abmon, 12, 12);
+  java_print_array (locale, copy_name, "months", time->mon, 12, 12);
+#if 0
+  /* FIXME: this isn't exactly right.  libgcj assumes there are only
+     two eras.  */
+  java_print_array (locale, copy_name, "eras", time->era, time->num_era, -1);
+#endif
+  java_print_array (locale, copy_name, "ampms", time->am_pm, 2, -1);
+
+  /* These are approximations.  Java supports more canned time and
+     date formats than POSIX.  */
+  java_print_time_format (locale, copy_name, "shortDateFormat", time->d_fmt);
+#if 0
+  java_print_time_format (locale, copy_name, "mediumTimeFormat", time->t_fmt);
+#endif
+  java_print_time_format (locale, copy_name, "defaultTimeFormat",
+			  time->t_fmt_ampm);
 }
 
 
Index: programs/localedef.c
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/localedef.c,v
retrieving revision 1.53
diff -u -r1.53 localedef.c
--- programs/localedef.c 2001/12/10 01:21:50 1.53
+++ programs/localedef.c 2002/01/03 04:44:17
@@ -58,6 +58,9 @@
 /* If not zero, produce old-style hash table instead of 3-level access tables.  */
 int oldstyle_tables;
 
+/* If not zero, generate Java-style output.  */
+int java_style;
+
 /* If not zero force output even if warning were issued.  */
 static int force_output;
 
@@ -85,6 +88,7 @@
 #define OPT_QUIET 2
 #define OPT_OLDSTYLE 3
 #define OPT_PREFIX 4
+#define OPT_JAVA 5
 
 /* Definitions of arguments for argp functions.  */
 static const struct argp_option options[] =
@@ -99,6 +103,7 @@
   { NULL, 0, NULL, 0, N_("Output control:") },
   { "force", 'c', NULL, 0,
     N_("Create output even if warning messages were issued") },
+  { "java", OPT_JAVA, NULL, 0, N_("Create Java-style tables") },
   { "old-style", OPT_OLDSTYLE, NULL, 0, N_("Create old-style tables") },
   { "prefix", OPT_PREFIX, "PATH", 0, N_("Optional output file prefix") },
   { "posix", OPT_POSIX, NULL, 0, N_("Be strictly POSIX conform") },
@@ -260,6 +265,9 @@
     case OPT_PREFIX:
       output_prefix = arg;
       break;
+    case OPT_JAVA:
+      java_style = 1;
+      break;
     case 'c':
       force_output = 1;
       break;
@@ -337,7 +345,9 @@
   char *result;
   char *endp;
 
-  if (strchr (path, '/') == NULL)
+  if (java_style)
+    result = output_prefix;
+  else if (strchr (path, '/') == NULL)
     {
       /* This is a system path.  First examine whether the locale name
 	 contains a reference to the codeset.  This should be
Index: programs/localedef.h
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/localedef.h,v
retrieving revision 1.7
diff -u -r1.7 localedef.h
--- programs/localedef.h 2001/12/10 01:22:36 1.7
+++ programs/localedef.h 2002/01/03 04:44:18
@@ -112,6 +112,7 @@
 extern int verbose;
 extern int be_quiet;
 extern int oldstyle_tables;
+extern int java_style;
 extern const char *repertoire_global;
 
 
@@ -138,5 +139,16 @@
 					const char *repertoire_name,
 					const struct charmap_t *charmap,
 					struct localedef_t *copy_locale);
+
+/* Printing, java-style.  */
+extern void java_end_locale (void);
+extern void java_start_locale (const char *output_path,
+			       struct localedef_t *locale);
+extern void java_printf (struct localedef_t *locale, const char *format, ...)
+     __attribute__ ((format (printf, 2, 3)));
+extern void java_print_string (struct localedef_t *locale,
+			       const char *copy_name,
+			       const char *field_name,
+			       const char *value);
 
 #endif /* localedef.h */
Index: programs/locfile.c
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/locfile.c,v
retrieving revision 1.30
diff -u -r1.30 locfile.c
--- programs/locfile.c 2001/12/10 01:20:35 1.30
+++ programs/locfile.c 2002/01/03 04:44:19
@@ -312,6 +312,23 @@
   [LC_IDENTIFICATION] = identification_output
 };
 
+static void (*const java_write_funcs[]) (struct localedef_t *,
+				    const struct charmap_t *, const char *) =
+{
+  [LC_CTYPE] = NULL,
+  [LC_COLLATE] = NULL,
+  [LC_MESSAGES] = NULL,
+  [LC_MONETARY] = java_monetary_output,
+  [LC_NUMERIC] = java_numeric_output,
+  [LC_TIME] = java_time_output,
+  [LC_PAPER] = NULL,
+  [LC_NAME] = NULL,
+  [LC_ADDRESS] = NULL,
+  [LC_TELEPHONE] = NULL,
+  [LC_MEASUREMENT] = NULL,
+  [LC_IDENTIFICATION] = NULL
+};
+
 void
 write_all_categories (struct localedef_t *definitions,
 		      const struct charmap_t *charmap,
@@ -319,9 +336,19 @@
 {
   int cnt;
 
+  void (* const *funcs) (struct localedef_t *, const struct charmap_t *,
+		   const char *);
+  funcs = java_style ? java_write_funcs : write_funcs;
+
+  if (java_style)
+    java_start_locale (output_path, definitions);
+
   for (cnt = 0; cnt < sizeof (write_funcs) / sizeof (write_funcs[0]); ++cnt)
-    if (write_funcs[cnt] != NULL)
-      write_funcs[cnt] (definitions, charmap, output_path);
+    if (funcs[cnt] != NULL)
+      funcs[cnt] (definitions, charmap, output_path);
+
+  if (java_style)
+    java_end_locale ();
 }
 
 /* Return a NULL terminated list of the directories next to output_path
Index: programs/locfile.h
===================================================================
RCS file: /cvs/glibc/libc/locale/programs/locfile.h,v
retrieving revision 1.13
diff -u -r1.13 locfile.h
--- programs/locfile.h 2001/12/10 01:24:11 1.13
+++ programs/locfile.h 2002/01/03 04:44:20
@@ -161,6 +161,9 @@
 extern void monetary_output (struct localedef_t *locale,
 			     const struct charmap_t *charmap,
 			     const char *output_path);
+extern void java_monetary_output (struct localedef_t *locale,
+				  const struct charmap_t *charmap,
+				  const char *output_path);
 
 /* Handle LC_NUMERIC category.  */
 extern void numeric_read (struct linereader *ldfile,
@@ -173,6 +176,9 @@
 extern void numeric_output (struct localedef_t *locale,
 			    const struct charmap_t *charmap,
 			    const char *output_path);
+extern void java_numeric_output (struct localedef_t *locale,
+				 const struct charmap_t *charmap,
+				 const char *output_path);
 
 /* Handle LC_MESSAGES category.  */
 extern void messages_read (struct linereader *ldfile,
@@ -197,6 +203,9 @@
 extern void time_output (struct localedef_t *locale,
 			 const struct charmap_t *charmap,
 			 const char *output_path);
+extern void java_time_output (struct localedef_t *locale,
+			      const struct charmap_t *charmap,
+			      const char *output_path);
 
 /* Handle LC_PAPER category.  */
 extern void paper_read (struct linereader *ldfile,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]