Commit f4040896 authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

convert prtinf() strings to local charset when writing them to stdout or

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.
parent beeb35bc
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
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> Wed Mar 27 18:42:22 2002 Tim Janik <timj@gtk.org>
* gmessages.[hc]: * gmessages.[hc]:
......
...@@ -527,6 +527,16 @@ g_log (const gchar *log_domain, ...@@ -527,6 +527,16 @@ g_log (const gchar *log_domain,
va_end (args); 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 /* 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 * byte. Additionally we might need up to 2 output bytes for the
* readix prefix and 1 byte for the trailing NULL. * readix prefix and 1 byte for the trailing NULL.
...@@ -760,18 +770,9 @@ g_log_default_handler (const gchar *log_domain, ...@@ -760,18 +770,9 @@ g_log_default_handler (const gchar *log_domain,
g_string_append (gstring, message); /* charset is UTF-8 already */ g_string_append (gstring, message); /* charset is UTF-8 already */
else else
{ {
if (!g_utf8_validate (message, -1, NULL)) string = strdup_convert (message, charset);
{ g_string_append (gstring, string);
g_string_append (gstring, "[Invalid UTF-8] "); g_free (string);
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);
}
} }
} }
if (is_fatal) if (is_fatal)
...@@ -820,8 +821,18 @@ g_print (const gchar *format, ...@@ -820,8 +821,18 @@ g_print (const gchar *format,
local_glib_print_func (string); local_glib_print_func (string);
else else
{ {
const gchar *charset;
ensure_stdout_valid (); 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); fflush (stdout);
} }
g_free (string); g_free (string);
...@@ -862,7 +873,17 @@ g_printerr (const gchar *format, ...@@ -862,7 +873,17 @@ g_printerr (const gchar *format,
local_glib_printerr_func (string); local_glib_printerr_func (string);
else 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); fflush (stderr);
} }
g_free (string); g_free (string);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment