]> granicus.if.org Git - mutt/commitdiff
Entering multibyte characters. From Edmund Grimley Evans.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 9 Apr 2001 14:37:26 +0000 (14:37 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 9 Apr 2001 14:37:26 +0000 (14:37 +0000)
enter.c
keymap.c

diff --git a/enter.c b/enter.c
index 6a0a54d4bd513958b92f8ae357bc1c604f371d83..bf3c725f8dc926a74064c18f7a1eeefa83e22c61 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -198,8 +198,11 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
   wchar_t *tempbuf = 0;
   size_t templen = 0;
   history_class_t hclass;
+  wchar_t wc;
+  mbstate_t mbstate;
 
   int rv = 0;
+  memset (&mbstate, 0, sizeof (mbstate));
   
   if (state->wbuf)
   {
@@ -611,14 +614,34 @@ self_insert:
       /* use the raw keypress */
       ch = LastKey;
 
+      /* this probably shouldn't happen */
+      if (ch & ~0xff)
+       continue;
+
+      /* gather the octets into a wide character */
+      {
+       char c;
+       size_t k;
+
+       c = ch;
+       k = mbrtowc (&wc, &c, 1, &mbstate);
+       if (k == (size_t)(-2))
+         continue;
+       else if (k && k != 1)
+       {
+         memset (&mbstate, 0, sizeof (mbstate));
+         continue;
+       }
+      }
+
       if (first && (flags & M_CLEAR))
       {
        first = 0;
-       if (IsWPrint (ch)) /* why? */
+       if (IsWPrint (wc)) /* why? */
          state->curpos = state->lastchar = 0;
       }
 
-      if (CI_is_return (ch))
+      if (wc == '\r' || wc == '\n')
       {
        /* Convert from wide characters */
        my_wcstombs (buf, buflen, state->wbuf, state->lastchar);
@@ -637,7 +660,7 @@ self_insert:
        rv = 0; 
        goto bye;
       }
-      else if (ch && (ch < ' ' || IsWPrint (ch))) /* why? */
+      else if (wc && (wc < ' ' || IsWPrint (wc))) /* why? */
       {
        if (state->lastchar >= state->wbuflen)
        {
@@ -645,7 +668,7 @@ self_insert:
          safe_realloc ((void **) &state->wbuf, state->wbuflen * sizeof (wchar_t));
        }
        memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t));
-       state->wbuf[state->curpos++] = ch;
+       state->wbuf[state->curpos++] = wc;
        state->lastchar++;
       }
       else
index 0b97906d1947251ca53d7bfce9a2bac656aeeee3..eb41056da213fcede29c5fcfe281770b4ad14cdb 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -146,7 +146,7 @@ static int parsekeys (char *str, keycode_t *d, int max)
 
     if(!*d)
     {
-      *d = *s;
+      *d = (unsigned char)*s;
       s++;
     }
     d++;