convert prtinf() strings to local charset when writing them to stdout or
authorTim Janik <timj@gtk.org>
Thu, 28 Mar 2002 20:12:32 +0000 (20:12 +0000)
committerTim Janik <timj@src.gnome.org>
Thu, 28 Mar 2002 20:12:32 +0000 (20:12 +0000)
Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>

        * glib/gmessages.c:
        (g_print):
        (g_printerr): convert prtinf() strings to local charset
        when writing them to stdout or stderr.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gmessages.c

index 34947a7..e98ae11 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 34947a7..e98ae11 100644 (file)
@@ -1,3 +1,10 @@
+Thu Mar 28 20:31:51 2002  Tim Janik  <timj@gtk.org>
+
+       * glib/gmessages.c:
+       (g_print): 
+       (g_printerr): convert prtinf() strings to local charset
+       when writing them to stdout or stderr.
+
 Wed Mar 27 18:42:22 2002  Tim Janik  <timj@gtk.org>
 
        * gmessages.[hc]:
index 40e6389..4a72be5 100644 (file)
@@ -527,6 +527,16 @@ g_log (const gchar   *log_domain,
   va_end (args);
 }
 
+static gchar*
+strdup_convert (const gchar *string,
+               const gchar *charset)
+{
+  if (!g_utf8_validate (string, -1, NULL))
+    return g_strconcat ("[Invalid UTF-8] ", string, NULL);
+  else
+    return g_convert_with_fallback (string, -1, charset, "UTF-8", "?", NULL, NULL, NULL);
+}
+
 /* For a radix of 8 we need at most 3 output bytes for 1 input
  * byte. Additionally we might need up to 2 output bytes for the
  * readix prefix and 1 byte for the trailing NULL.
@@ -760,18 +770,9 @@ g_log_default_handler (const gchar   *log_domain,
        g_string_append (gstring, message);     /* charset is UTF-8 already */
       else
        {
-         if (!g_utf8_validate (message, -1, NULL))
-           {
-             g_string_append (gstring, "[Invalid UTF-8] ");
-             g_string_append (gstring, message);
-           }
-         else
-           {
-             string = g_convert_with_fallback (message, -1, charset, "UTF-8",
-                                               ".", NULL, NULL, NULL);
-             g_string_append (gstring, string);
-             g_free (string);
-           }
+         string = strdup_convert (message, charset);
+         g_string_append (gstring, string);
+         g_free (string);
        }
     }
   if (is_fatal)
@@ -820,8 +821,18 @@ g_print (const gchar *format,
     local_glib_print_func (string);
   else
     {
+      const gchar *charset;
+
       ensure_stdout_valid ();
-      fputs (string, stdout);
+      if (g_get_charset (&charset))
+       fputs (string, stdout); /* charset is UTF-8 already */
+      else
+       {
+         gchar *lstring = strdup_convert (string, charset);
+
+         fputs (lstring, stdout);
+         g_free (lstring);
+       }
       fflush (stdout);
     }
   g_free (string);
@@ -862,7 +873,17 @@ g_printerr (const gchar *format,
     local_glib_printerr_func (string);
   else
     {
-      fputs (string, stderr);
+      const gchar *charset;
+
+      if (g_get_charset (&charset))
+       fputs (string, stderr); /* charset is UTF-8 already */
+      else
+       {
+         gchar *lstring = strdup_convert (string, charset);
+
+         fputs (lstring, stderr);
+         g_free (lstring);
+       }
       fflush (stderr);
     }
   g_free (string);