qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs tty.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs tty.c
Date: Fri, 14 Aug 2015 15:56:29 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        15/08/14 15:56:29

Modified files:
        .              : tty.c 

Log message:
        tty: fixed non ASCII input from utf8 terminals

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.65&r2=1.66

Patches:
Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- tty.c       13 Aug 2015 23:14:11 -0000      1.65
+++ tty.c       14 Aug 2015 15:56:28 -0000      1.66
@@ -95,9 +95,8 @@
     /* input handling */
     enum InputState input_state;
     int input_param, input_param2;
-    int utf8_state;
     int utf8_index;
-    unsigned char buf[10];
+    unsigned char buf[8];
     char *term_name;
     enum TermCode term_code;
     int term_flags;
@@ -399,34 +398,42 @@
     QEditScreen *s = opaque;
     QEmacsState *qs = &qe_state;
     TTYState *ts = s->priv_data;
-    int ch;
     QEEvent ev1, *ev = &ev1;
+    u8 buf[1];
+    int ch, len;
 
-    if (read(fileno(s->STDIN), ts->buf + ts->utf8_index, 1) != 1)
+    if (read(fileno(s->STDIN), buf, 1) != 1)
         return;
 
     if (qs->trace_buffer &&
         qs->active_window &&
         qs->active_window->b != qs->trace_buffer) {
-        eb_trace_bytes(ts->buf + ts->utf8_index, 1, EB_TRACE_TTY);
+        eb_trace_bytes(buf, 1, EB_TRACE_TTY);
     }
 
+    ch = buf[0];
+
+    switch (ts->input_state) {
+    case IS_NORM:
     /* charset handling */
     if (s->charset == &charset_utf8) {
-        if (ts->utf8_state == 0) {
-            const char *p = cs8(ts->buf);
-            ch = utf8_decode(&p);
-        } else {
-            ts->utf8_state = utf8_length[ts->buf[0]] - 1;
+            if (ts->utf8_index && !(ch > 0x80 && ch < 0xc0)) {
+                /* not a valid continuation byte */
+                /* flush stored prefix, restart from current byte */
+                /* XXX: maybe should consume prefix byte as binary */
             ts->utf8_index = 0;
+            }
+            ts->buf[ts->utf8_index] = ch;
+            len = utf8_length[ts->buf[0]];
+            if (len > 1) {
+                const char *p = cs8(ts->buf);
+                if (++ts->utf8_index < len) {
+                    /* valid utf8 sequence underway, wait for next */
             return;
         }
-    } else {
-        ch = ts->buf[0];
+                ch = utf8_decode(&p);
+            }
     }
-
-    switch (ts->input_state) {
-    case IS_NORM:
         if (ch == '\033') {
             if (!tty_term_is_user_input_pending(s)) {
                 /* Trick to distinguish the ESC key from function and meta
@@ -465,7 +472,7 @@
         }
         break;
     case IS_CSI:
-        if (qe_isdigit(ch)) {
+        if (ch >= '0' && ch <= '9') {
             ts->input_param = ts->input_param * 10 + ch - '0';
             break;
         }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]