From: John Darrington Date: Sun, 2 May 2010 13:20:38 +0000 (+0200) Subject: Convert syntax files to UTF-8 before loading them. X-Git-Tag: v0.7.5~43 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=0f8c9c6c05632de5cadc70ca5381c1d9cb46960e Convert syntax files to UTF-8 before loading them. Convert the contents of a syntax file to UTF-8 before loading it into the syntax window. Fixes bug #29733 This change assumes that the files to be loaded are in the encoding of the current locale. If this assumption is not true, then an error will be displayed and the file not loaded. --- diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 48e1ea44..f9fe53cc 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -545,12 +545,26 @@ gboolean syntax_load (PsppireWindow *window, const gchar *filename) { GError *err = NULL; - gchar *text; + gchar *text_locale = NULL; + gchar *text_utf8 = NULL; + gsize len_locale = -1; + gsize len_utf8 = -1; GtkTextIter iter; PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window); /* FIXME: What if it's a very big file ? */ - if ( ! g_file_get_contents (filename, &text, NULL, &err) ) + if ( ! g_file_get_contents (filename, &text_locale, &len_locale, &err) ) + { + error_dialog (GTK_WINDOW (window), filename, err); + g_clear_error (&err); + return FALSE; + } + + text_utf8 = g_locale_to_utf8 (text_locale, len_locale, NULL, &len_utf8, &err); + + free (text_locale); + + if ( text_utf8 == NULL ) { error_dialog (GTK_WINDOW (window), filename, err); g_clear_error (&err); @@ -559,10 +573,12 @@ syntax_load (PsppireWindow *window, const gchar *filename) gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0); - gtk_text_buffer_insert (sw->buffer, &iter, text, -1); + gtk_text_buffer_insert (sw->buffer, &iter, text_utf8, len_utf8); gtk_text_buffer_set_modified (sw->buffer, FALSE); + free (text_utf8); + return TRUE; }