- g_return_if_fail(str != NULL);
- g_return_if_fail(str->file_mode != filemode_Read);
-
- /* Convert ch to a null-terminated string, call glk_put_string_stream() */
- gchar *s = g_strndup((gchar *)&ch, 1);
- glk_put_string_stream(str, s);
- g_free(s);
-}
-
-/* Internal function: change illegal (control) characters in a string to a
-placeholder character. Must free returned string afterwards. */
-static gchar *
-remove_latin1_control_characters(gchar *s)
-{
- gchar *retval = g_strdup(s);
- unsigned char *ptr;
- for(ptr = (unsigned char *)retval; *ptr != '\0'; ptr++)
- if( (*ptr < 32 && *ptr != 10) || (*ptr >= 127 && *ptr <= 159) )
- *ptr = '?';
- /* Our placeholder character is '?'; other options are possible,
- like printing "0x7F" or something */
- return retval;
-}
-
-/* Internal function: convert a Latin-1 string to a UTF-8 string, replacing
-Latin-1 control characters by a placeholder first. The UTF-8 string must be
-freed afterwards. Returns NULL on error. */
-static gchar *
-convert_latin1_to_utf8(gchar *s)
-{
- GError *error = NULL;
- gchar *utf8;
- gchar *canonical = remove_latin1_control_characters(s);
- utf8 = g_convert(canonical, -1, "UTF-8", "ISO-8859-1", NULL, NULL, &error);
- g_free(canonical);
-
- if(utf8 == NULL)
- {
- error_dialog(NULL, error, "Error during latin1->utf8 conversion: ");
- return NULL;
- }
-
- return utf8;
-}
-
-/* Internal function: write a UTF-8 string to a window's text buffer. */
-static void
-write_utf8_to_window(winid_t win, gchar *s)
-{
- GtkTextBuffer *buffer =
- gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
-
- GtkTextIter iter;
- gtk_text_buffer_get_end_iter(buffer, &iter);
- gtk_text_buffer_insert(buffer, &iter, s, -1);