Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r89f5338 r428834d  
    4848#include <termios.h>
    4949#include <sys/stat.h>
     50#include <locale.h>
    5051#include "owl.h"
    5152
     
    6970  owl_editwin *tw;
    7071  owl_popwin *pw;
    71   int j, ret, initialsubs, debug, argcsave, followlast;
     72  int ret, initialsubs, debug, argcsave, followlast;
     73  owl_input j;
    7274  int newmsgs, nexttimediff;
    7375  struct sigaction sigact;
     
    8486  int newstderr;
    8587#endif
     88 
     89  if (!GLIB_CHECK_VERSION (2, 12, 0))
     90    g_error ("GLib version 2.12.0 or above is needed.");
    8691
    8792  argcsave=argc;
     
    9297  debug=0;
    9398  initialsubs=1;
     99
     100  setlocale(LC_ALL, "");
     101 
    94102  if (argc>0) {
    95103    argv++;
     
    538546     * little bit, but otherwise do not.  This lets input be grabbed
    539547     * as quickly as possbile */
    540     j=wgetch(typwin);
    541     if (j==ERR) {
     548    j.ch = wgetch(typwin);
     549    if (j.ch == ERR) {
    542550      usleep(10000);
    543551    } else {
     552      j.uch = '\0';
     553      if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
     554        /* This is a curses control character. */
     555      }
     556      else if (j.ch > 0x7f && j.ch < 0xfe) {
     557        /* Pull in a full utf-8 character. */
     558        int bytes, i;
     559        char *utf8buf[7];
     560        memset(utf8buf, '\0', 7);
     561
     562        utf8buf[0] = j.ch;
     563
     564        if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
     565        else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
     566        else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
     567        else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
     568        else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
     569        else bytes = 1;
     570       
     571        for (i = 1; i < bytes; i++) {
     572          utf8buf[i] = wgetch(typwin);
     573        }
     574        if (g_utf8_validate(utf8buf, -1, NULL)) {
     575          j.uch = g_utf8_get_char(utf8buf);
     576        }
     577        else {
     578          j.ch = ERR;
     579        }
     580      }
     581      else if (j.ch <= 0x7f) {
     582        j.uch = j.ch;
     583      }
     584     
    544585      owl_global_update_lastinputtime(&g);
    545586      /* find and activate the current keymap.
Note: See TracChangeset for help on using the changeset viewer.