Only in eterm-0.9.6-utf8/debian: build
Only in eterm-0.9.6-utf8/debian: eterm
Only in eterm-0.9.6-utf8/debian: eterm.debhelper.log
Only in eterm-0.9.6-utf8/debian: eterm.postinst.debhelper
Only in eterm-0.9.6-utf8/debian: eterm.postrm.debhelper
Only in eterm-0.9.6-utf8/debian: eterm.substvars
Only in eterm-0.9.6-utf8/debian: files
Only in eterm-0.9.6-utf8/debian: stamp-build
Only in eterm-0.9.6-utf8/debian: stamp-install
Only in eterm-0.9.6-utf8/debian: stamp-tarcopy
diff -urp eterm-0.9.6/src/screen.c eterm-0.9.6-utf8/src/screen.c
--- eterm-0.9.6/src/screen.c	2011-03-16 06:16:59.000000000 +0100
+++ eterm-0.9.6-utf8/src/screen.c	2013-01-02 21:36:17.000000000 +0100
@@ -41,6 +41,7 @@ static const char cvs_ident[] = "$Id: sc
 #ifdef ESCREEN
 #  include "screamcfg.h"
 #endif
+#include <iconv.h>
 
 static int pb = 0;
 
@@ -109,9 +110,10 @@ blank_line(text_t *et, rend_t *er, int w
     register unsigned int i = width;
     rend_t *r = er, fs = efs;
 
-    MEMSET(et, ' ', i);
-    for (; i--;)
+    for (; i--;) {
+        *et++ = ' ';
         *r++ = fs;
+    }
 }
 
 /* Create a new row in the screen buffer and initialize it. */
@@ -121,15 +123,18 @@ blank_screen_mem(text_t **tp, rend_t **r
 {
     register unsigned int i = TERM_WINDOW_GET_REPORTED_COLS();
     rend_t *r, fs = efs;
+    text_t *et;
 
     if (!tp[row]) {
         tp[row] = MALLOC(sizeof(text_t) * (TERM_WINDOW_GET_REPORTED_COLS() + 1));
         rp[row] = MALLOC(sizeof(rend_t) * TERM_WINDOW_GET_REPORTED_COLS());
     }
-    MEMSET(tp[row], ' ', i);
     tp[row][i] = 0;
-    for (r = rp[row]; i--;)
+    et = tp[row];
+    for (r = rp[row]; i--;) {
+        *et++ = ' ';
         *r++ = fs;
+    }
 }
 
 void
@@ -687,19 +692,99 @@ scroll_text(int row1, int row2, int coun
     return count;
 }
 
+#undef FIXME_BLOCK
+#define FIXME_BLOCK 1
+
+#define UTF8_DEBUG 0
+
+static text_t *
+mb2text(const char *str, size_t *len)
+{
+    static iconv_t ih = (iconv_t)-1;
+    text_t *tstr;
+    char *pi, *po;
+    size_t olen, maxolen;
+
+    maxolen = *len * sizeof(text_t);
+    tstr = MALLOC(maxolen);
+    pi = (char*)str;
+    po = (char*)tstr;
+    if (ih == (iconv_t)-1)
+        ih = iconv_open("UCS-2", "UTF-8");
+    olen = maxolen;
+    while (*len > 0) {
+        size_t result = iconv(ih, &pi, len, &po, &olen);
+        if (*len > 0 && result == (size_t)-1) {
+            if (errno == EILSEQ) {
+                pi++;
+                (*len)--;
+                *po++ = '?';
+                *po++ = 0;
+                olen -= 2;
+            } else {
+                *len = 0;
+            }
+        }
+    }
+    olen = (maxolen - olen) / 2;
+#if UTF8_DEBUG
+    int i;
+    printf("TO UCS2:");
+    for (i = 0; i < olen; i++)
+       printf(" %04x", tstr[i]);
+    printf(" UCS2 len=%d\n", olen);
+#endif
+    *len = olen;
+    return tstr;
+}
+
+static text_t *
+ucs22utf8(const text_t *tstr, int *ilen)
+{
+    static iconv_t ih = (iconv_t)-1;
+    char *str;
+    char *pi, *po;
+    size_t len = *ilen * sizeof(text_t);
+    size_t olen, maxolen;
+
+    maxolen = 4 * *ilen;
+    str = MALLOC(maxolen);
+    pi = (char*)tstr;
+    po = (char*)str;
+    if (ih == (iconv_t)-1)
+        ih = iconv_open("UTF-8", "UCS-2");
+    olen = maxolen;
+#if UTF8_DEBUG
+    int i;
+    printf("FROM UCS2:");
+    printf(" \"%s\"", tstr);
+    printf(" UCS2 len=%d\n", len);
+#endif
+    iconv(ih, &pi, &len, &po, &olen);
+    olen = maxolen - olen;
+#if UTF8_DEBUG
+    printf("TO UTF8:");
+    printf(" \"%s\"", str);
+    printf(" UTF8 len=%d\n", olen);
+#endif
+    str[olen] = 0;
+    *ilen = olen;
+    return str;
+}
+
 /*
  * Add text given in <str> of length <len> to screen struct
  */
 void
-scr_add_lines(const unsigned char *str, int nlines, int len)
+scr_add_lines(const unsigned char *str, int nlines, size_t len)
 {
 /*    char            c; */
-    register char c;
+    register text_t c;
 
 /*    int             i, j, row, last_col; */
     int last_col;
     register int i, j, row;
-    text_t *stp;
+    text_t *stp, *tstr;
     rend_t *srp;
     row_col_t beg, end;
 
@@ -742,8 +827,11 @@ scr_add_lines(const unsigned char *str,
         chstat = WBYTE;
 #endif
 
+    /* Convert incoming (mb) string to UCS-2 */
+    tstr = mb2text(str, &len);
+
     for (i = 0; i < len;) {
-        c = str[i++];
+        c = tstr[i++];
 #ifdef MULTI_CHARSET
         if ((encoding_method != LATIN1) && (chstat == WBYTE)) {
             rstyle |= RS_multiMask;     /* multibyte 2nd byte */
@@ -826,6 +914,9 @@ scr_add_lines(const unsigned char *str,
                 screen.flags &= ~Screen_WrapNext;
         }
     }
+
+    FREE(tstr);
+
     LOWER_BOUND(stp[last_col], screen.col);
     if (screen.col == 0) {
         end.col = last_col - 1;
@@ -1488,7 +1579,7 @@ set_multichar_encoding(const char *str)
 void
 scr_expose(int x, int y, int width, int height)
 {
-    int i;
+    int i, j;
     register short nc, nr;
     row_col_t rect_beg, rect_end;
 
@@ -1510,7 +1601,9 @@ scr_expose(int x, int y, int width, int
               rect_end.col, rect_end.row));
 
     for (i = rect_beg.row; i <= rect_end.row; i++) {
-        MEMSET(&(drawn_text[i][rect_beg.col]), 0, rect_end.col - rect_beg.col + 1);
+        for (j = rect_beg.col; j <= rect_end.col; j++) {
+            drawn_text[i][j] = 0;
+        }
     }
 }
 
@@ -1626,6 +1719,50 @@ scr_multi2(void)
 }
 #endif /* MULTI_CHARSET */
 
+static int
+scr_draw_string(Display *dpy, Drawable draw, GC gc, int x, int y, text_t *str, int len)
+{
+    unsigned short buf[2048];
+    int i;
+
+    if (len > 2048)
+        len = 2048;
+#if UTF8_DEBUG
+    for (i = 0; i < len; i++)
+    {
+       buf[i] = (str[i] >> 8) | (str[i] << 8);
+       printf(" %04x", buf[i]);
+    }
+    printf("\n");
+#else
+    for (i = 0; i < len; i++)
+       buf[i] = (str[i] >> 8) | (str[i] << 8);
+#endif
+    XDrawString16(dpy, draw, gc, x, y, (XChar2b*)buf, len);
+}
+
+static int
+scr_draw_image_string(Display *dpy, Drawable draw, GC gc, int x, int y, text_t *str, int len)
+{
+    unsigned short buf[2048];
+    int i;
+
+    if (len > 2048)
+        len = 2048;
+#if UTF8_DEBUG
+    for (i = 0; i < len; i++)
+    {
+       buf[i] = (str[i] >> 8) | (str[i] << 8);
+       printf(" %04x", buf[i]);
+    }
+    printf("\n");
+#else
+    for (i = 0; i < len; i++)
+       buf[i] = (str[i] >> 8) | (str[i] << 8);
+#endif
+    XDrawImageString16(dpy, draw, gc, x, y, (XChar2b*)buf, len);
+}
+
 /*
  * Refresh the screen
  * drawn_text/drawn_rend contain the screen information before the update.
@@ -1658,8 +1795,8 @@ scr_refresh(int type)
     rend_t *drp, *srp;          /* drawn-rend-pointer, screen-rend-pointer   */
     text_t *dtp, *stp;          /* drawn-text-pointer, screen-text-pointer   */
     XGCValues gcvalue;          /* Graphics Context values                   */
-    char buf[MAX_COLS + 1];
-    register char *buffer = buf;
+    text_t buf[MAX_COLS + 1];
+    register text_t *buffer = buf;
     Pixmap pmap = images[image_bg].current->pmap->pixmap;
     int (*draw_string) (), (*draw_image_string) ();
     register int low_x = 99999, low_y = 99999, high_x = 0, high_y = 0;
@@ -1706,8 +1843,8 @@ scr_refresh(int type)
     XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid);
 
 #if FIXME_BLOCK
-    draw_string = XmbDrawString;
-    draw_image_string = XmbDrawImageString;
+    draw_string = scr_draw_string;
+    draw_image_string = scr_draw_image_string;
 #else
     draw_string = XDrawString;
     draw_image_string = XDrawImageString;
@@ -1797,8 +1934,8 @@ scr_refresh(int type)
                         wbyte = 1;
                         XSetFont(Xdisplay, TermWin.gc, TermWin.mfont->fid);
 # if FIXME_BLOCK
-                        draw_string = XmbDrawString;
-                        draw_image_string = XmbDrawImageString;
+                        draw_string = scr_draw_string;
+                        draw_image_string = scr_draw_image_string;
 # else
                         draw_string = XDrawString16;
                         draw_image_string = XDrawImageString16;
@@ -1840,8 +1977,8 @@ scr_refresh(int type)
                         wbyte = 0;
                         XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid);
 # if FIXME_BLOCK
-                        draw_string = XmbDrawString;
-                        draw_image_string = XmbDrawImageString;
+                        draw_string = scr_draw_string;
+                        draw_image_string = scr_draw_image_string;
 # else
                         draw_string = XDrawString;
                         draw_image_string = XDrawImageString;
@@ -2250,7 +2387,7 @@ scr_strmatch(unsigned long row, unsigned
 void
 scr_search_scrollback(char *str)
 {
-    unsigned char *c;
+    text_t *c;
     char *s;
     static char *last_str = NULL;
     unsigned int *i;
@@ -2738,8 +2875,7 @@ selection_make(Time tm)
 {
     int i, col, end_col, row, end_row;
     text_t *new_selection_text;
-    char *str;
-    text_t *t;
+    text_t *str, *t;
 
     D_SELECT(("selection.op=%d, selection.clicks=%d\n", selection.op, selection.clicks));
     switch (selection.op) {
@@ -2766,8 +2902,8 @@ selection_make(Time tm)
         return;
     }
     i = (selection.end.row - selection.beg.row + 1) * (TERM_WINDOW_GET_REPORTED_COLS() + 1) + 1;
-    str = MALLOC(i * sizeof(char));
-    new_selection_text = (unsigned char *) str;
+    str = MALLOC(i * sizeof(text_t));
+    new_selection_text = str;
 
     col = MAX(selection.beg.col, 0);
     row = selection.beg.row + TermWin.saveLines;
@@ -2810,14 +2946,16 @@ selection_make(Time tm)
     if (i)
         *str++ = '\n';
     *str = '\0';
-    if ((i = strlen((char *) new_selection_text)) == 0) {
+    ptrdiff_t j = str - new_selection_text;
+    if (j == 0) {
         FREE(new_selection_text);
         return;
     }
-    selection.len = i;
+    selection.len = j;
     if (selection.text)
         FREE(selection.text);
-    selection.text = new_selection_text;
+    selection.text = ucs22utf8(new_selection_text, &selection.len);
+    FREE(new_selection_text);
     selection.screen = current_screen;
 
     selection_copy(XA_PRIMARY);
diff -urp eterm-0.9.6/src/screen.h eterm-0.9.6-utf8/src/screen.h
--- eterm-0.9.6/src/screen.h	2011-03-16 06:16:59.000000000 +0100
+++ eterm-0.9.6-utf8/src/screen.h	2012-12-28 12:33:46.000000000 +0100
@@ -155,7 +155,7 @@ enum {
    many lines back into the scrollback buffer the currently-visible data
    is.  (0 means we're at the bottom and not in scrollback.)
 */
-typedef unsigned char text_t;
+typedef unsigned short text_t;
 typedef unsigned int rend_t;
 typedef enum {
     SELECTION_CLEAR = 0,
@@ -250,7 +250,7 @@ extern int scr_change_screen(int);
 extern void scr_color(unsigned int, unsigned int);
 extern void scr_rendition(int, int);
 extern int scroll_text(int, int, int, int);
-extern void scr_add_lines(const unsigned char *, int, int);
+extern void scr_add_lines(const unsigned char *, int, size_t);
 extern void scr_backspace(void);
 extern void scr_tab(int);
 extern void scr_gotorc(int, int, int);
