From: pcg Date: Thu, 18 Dec 2003 07:31:18 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=3348fe1f44a24fcf59c584715354bfc4cf779b98;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/src/command.C b/src/command.C index ee60cd7a..4d85d705 100644 --- a/src/command.C +++ b/src/command.C @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.19 2003-12-18 05:45:11 pcg Exp $ + * $Id: command.C,v 1.20 2003-12-18 07:31:18 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -50,6 +50,8 @@ #include "version.h" #include "command.h" +#include + /*----------------------------------------------------------------------*/ /*{{{ Convert the keypress event into a string */ @@ -90,24 +92,36 @@ rxvt_lookup_key(pR_ XKeyEvent *ev) Status status_return; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, - KBUFSZ, &keysym, &status_return); -#else - wchar_t wkbuf[KBUFSZ + 1]; - - // assume wchar_t == unicode or better - len = XwcLookupString (R->Input_Context, ev, wkbuf, - KBUFSZ, &keysym, &status_return); - - if (status_return == XLookupChars - || status_return == XLookupBoth) - { - wkbuf[len] = 0; - len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); - } + if (R->enc_utf8) + len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, + KBUFSZ, &keysym, &status_return); else - len = 0; #endif + { + wchar_t wkbuf[KBUFSZ + 1]; + + // the XOpenIM manpage lies about hardcoding the locale + // at the point of XOpenIM, so temporarily switch locales + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->rs[Rs_imLocale]); + // assume wchar_t == unicode or better + len = XwcLookupString (R->Input_Context, ev, wkbuf, + KBUFSZ, &keysym, &status_return); + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->locale); + + if (status_return == XLookupChars + || status_return == XLookupBoth) + { + wkbuf[len] = 0; + len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (len < 0) + len = 0; + } + else + len = 0; + } + valid_keysym = status_return == XLookupKeySym || status_return == XLookupBoth; } @@ -905,51 +919,23 @@ rxvt_term::pty_cb (io_watcher &w, short revents) uint32_t rxvt_term::next_char () { - struct mbstate &s = mbstate; - while (cmdbuf_ptr < cmdbuf_endp) { - uint8_t ch = *cmdbuf_ptr; + if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh + return *cmdbuf_ptr++; - if (s.cnt) - { - if ((ch & 0xc0) == 0x80) - { - cmdbuf_ptr++; + wchar_t wc; + int len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, &mbstate.mbs); - /* continuation */ - s.reg = (s.reg << 6) | (ch & 0x7f); + if (len == (size_t)-2) + return NOCHAR; - if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */ - return s.reg; + if (len == (size_t)-1) + return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through - continue; - } - else - { - s.cnt = 0; - return s.orig; /* the _occasional_ non-utf-8 character may slip through... */ - } - } - - if ((ch & 0xc0) == 0xc0) - { - cmdbuf_ptr++; - - /* first byte */ - s.orig = ch; /* for broken encodings */ - s.reg = ch; - if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; } - if ((ch & 0xf0) == 0xe0) { s.reg &= 0x0f; s.cnt = 2; } - if ((ch & 0xf8) == 0xf0) { s.reg &= 0x07; s.cnt = 3; } - if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; } - if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; } - } - else - { - cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ - return ch; - } + // assume wchar == unicode + cmdbuf_ptr += len; + return wc; } return NOCHAR; diff --git a/src/init.C b/src/init.C index 95927439..a10b3348 100644 --- a/src/init.C +++ b/src/init.C @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: init.c *----------------------------------------------------------------------* - * $Id: init.C,v 1.14 2003-12-18 05:45:11 pcg Exp $ + * $Id: init.C,v 1.15 2003-12-18 07:31:19 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -796,6 +796,23 @@ rxvt_term::init_env () * This is more or less stolen straight from XFree86 xterm. * This should support all European type languages. */ +void +rxvt_term::set_locale (const char *locale) +{ +#if HAVE_XSETLOCALE || HAVE_SETLOCALE + free (this->locale); + this->locale = strdup (setlocale (LC_CTYPE, "")); +#endif +#if HAVE_NL_LANGINFO + free (codeset); + codeset = strdup (nl_langinfo (CODESET)); + enc_utf8 = !STRCASECMP (codeset, "UTF-8") + || !STRCASECMP (codeset, "UTF8"); +#else + enc_utf8 = 1; +#endif +} + void rxvt_term::init_xlocale () { @@ -817,8 +834,6 @@ rxvt_term::init_xlocale () return; } - rxvt_setTermFontSet (this, 0); - /* see if we can connect yet */ rxvt_IMInstantiateCallback (Xdisplay, NULL, NULL); @@ -1124,7 +1139,6 @@ rxvt_Create_Windows(pR_ int argc, const char *const *argv) long vt_emask; #ifdef PREFER_24BIT - XSetWindowAttributes attributes; XWindowAttributes gattr; diff --git a/src/main.C b/src/main.C index 7eac3e40..e7442599 100644 --- a/src/main.C +++ b/src/main.C @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: main.c *----------------------------------------------------------------------* - * $Id: main.C,v 1.15 2003-12-18 05:45:11 pcg Exp $ + * $Id: main.C,v 1.16 2003-12-18 07:31:19 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -51,9 +51,9 @@ static char curlocale[128]; void rxvt_set_locale (const char *locale) { - if (locale && strncmp (locale, curlocale, 128)) + if (locale && STRNCMP (locale, curlocale, 128)) { - strncpy (curlocale, locale, 128); + STRNCPY (curlocale, locale, 128); setlocale (LC_CTYPE, curlocale); } } @@ -204,17 +204,12 @@ rxvt_term::init (int argc, const char *const *argv) rxvt_privileges (this, SAVE); rxvt_privileges (this, IGNORE); -#if HAVE_XSETLOCALE || HAVE_SETLOCALE - locale = strdup (setlocale (LC_CTYPE, "")); -#endif -#if HAVE_NL_LANGINFO - codeset = strdup (nl_langinfo (CODESET)); -#endif - init_secondary (); const char **cmd_argv = init_resources (argc, argv); + set_locale (""); + #if (MENUBAR_MAX) rxvt_menubar_read (this, rs[Rs_menu]); #endif @@ -1075,18 +1070,6 @@ rxvt_IMSendSpot(pR) XFree(preedit_attr); } -/* EXTPROTO */ -void -rxvt_setTermFontSet(pR_ int idx) -{ - char *string; - long length; - int success = 0; - - if (idx < 0 || idx >= MAX_NFONTS) - return; -} - /* INTPROTO */ void rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, @@ -1130,87 +1113,12 @@ rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data rxvt_IMInstantiateCallback, NULL); } -/* - * X manual pages and include files don't match on some systems: - * some think this is an XIDProc and others an XIMProc so we can't - * use the first argument - need to update this to be nice for - * both types via some sort of configure detection - */ -/* ARGSUSED */ -/* EXTPROTO */ -void -rxvt_IMInstantiateCallback(Display * unused - __attribute__ ((unused)), XPointer client_data - __attribute__ ((unused)), XPointer call_data - __attribute__ ((unused))) -{ - dR; - int i, found, had_im; - const char *p; - char **s; - char buf[IMBUFSIZ]; - - D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); - if (R->Input_Context) - return; - -#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (R->rs[Rs_imLocale]) - setlocale (LC_CTYPE, R->rs[Rs_imLocale]); -#endif - - p = R->rs[Rs_inputMethod]; - if (p && *p) - { - bool found = false; - - s = rxvt_splitcommastring (p); - for (i = 0; s[i]; i++) - { - if (*s[i]) - { - STRCPY (buf, "@im="); - STRNCAT (buf, s[i], IMBUFSIZ - 5); - if ((p = XSetLocaleModifiers (buf)) && *p - && rxvt_IM_get_IC (aR)) - { - found = true; - break; - } - } - } - for (i = 0; s[i]; i++) - free(s[i]); - free(s); - - if (found) - goto done; - } - -/* try with XMODIFIERS env. var. */ - if ((p = XSetLocaleModifiers ("")) && *p - && rxvt_IM_get_IC (aR)) - goto done; - -/* try with no modifiers base IF the user didn't specify an IM */ - if ((p = XSetLocaleModifiers ("@im=none")) && *p - && rxvt_IM_get_IC (aR) == True) - goto done; - -done: -#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (R->rs[Rs_imLocale]) - setlocale (LC_CTYPE, R->locale); -#endif -} - /* * Try to open a XIM with the current modifiers, then see if we can * open a suitable preedit type */ -/* INTPROTO */ -Bool -rxvt_IM_get_IC(pR) +static Bool +rxvt_IM_get_IC (pR) { int i, j, found; XIM xim; @@ -1224,12 +1132,12 @@ rxvt_IM_get_IC(pR) XIMCallback ximcallback; D_MAIN((stderr, "rxvt_IM_get_IC()")); - xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); + xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL); if (xim == NULL) return False; xim_styles = NULL; - if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) + if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles || !xim_styles->count_styles) { XCloseIM(xim); return False; @@ -1264,7 +1172,7 @@ rxvt_IM_get_IC(pR) ximcallback.callback = rxvt_IMDestroyCallback; -/* XXX: not sure why we need this (as well as IC one below) */ + /* XXX: not sure why we need this (as well as IC one below) */ XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); preedit_attr = status_attr = NULL; @@ -1322,6 +1230,80 @@ rxvt_IM_get_IC(pR) return True; } +/* + * X manual pages and include files don't match on some systems: + * some think this is an XIDProc and others an XIMProc so we can't + * use the first argument - need to update this to be nice for + * both types via some sort of configure detection + */ +/* ARGSUSED */ +/* EXTPROTO */ +void +rxvt_IMInstantiateCallback(Display * unused + __attribute__ ((unused)), XPointer client_data + __attribute__ ((unused)), XPointer call_data + __attribute__ ((unused))) +{ + dR; + int i, found, had_im; + const char *p; + char **s; + char buf[IMBUFSIZ]; + + D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); + if (R->Input_Context) + return; + +#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) + if (R->rs[Rs_imLocale]) + setlocale (LC_CTYPE, R->rs[Rs_imLocale]); +#endif + + p = R->rs[Rs_inputMethod]; + if (p && *p) + { + bool found = false; + + s = rxvt_splitcommastring (p); + for (i = 0; s[i]; i++) + { + if (*s[i]) + { + STRCPY (buf, "@im="); + STRNCAT (buf, s[i], IMBUFSIZ - 5); + if ((p = XSetLocaleModifiers (buf)) && *p + && rxvt_IM_get_IC (aR)) + { + found = true; + break; + } + } + } + for (i = 0; s[i]; i++) + free(s[i]); + free(s); + + if (found) + goto done; + } + +/* try with XMODIFIERS env. var. */ + if ((p = XSetLocaleModifiers ("")) && *p + && rxvt_IM_get_IC (aR)) + goto done; + +/* try with no modifiers base IF the user didn't specify an IM */ + if ((p = XSetLocaleModifiers ("@im=none")) && *p + && rxvt_IM_get_IC (aR) == True) + goto done; + +done: +#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) + if (R->rs[Rs_imLocale]) + setlocale (LC_CTYPE, R->locale); +#endif +} + /* EXTPROTO */ void rxvt_IMSetStatusPosition(pR) diff --git a/src/rxvt.h b/src/rxvt.h index 1c3d4f76..69a8b23b 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -1,5 +1,5 @@ /* - * $Id: rxvt.h,v 1.16 2003-12-18 05:45:11 pcg Exp $ + * $Id: rxvt.h,v 1.17 2003-12-18 07:31:19 pcg Exp $ */ #ifndef _RXVT_H_ /* include once only */ @@ -19,6 +19,8 @@ #include "iom.h" #include "salloc.h" +#include + /* ***************************************************************************** * SYSTEM HACKS @@ -833,13 +835,11 @@ enum { #define BLINK_INTERVAL 0.5 struct mbstate { - unsigned char orig; - uint32_t reg; - int cnt; + mbstate_t mbs; mbstate () { - cnt = 0; + MEMSET (&mbs, 0, sizeof (mbs)); } }; @@ -865,7 +865,8 @@ struct rxvt_term : rxvt_vars { hidden_pointer:1, #endif parsed_geometry:1, - seen_input:1; /* wether any input has been seen so far */ + seen_input:1, /* wether any input has been seen so far */ + enc_utf8:1; /* wether terminal reads/writes utf-8 */ unsigned char refresh_type, #ifdef UTMP_SUPPORT @@ -886,15 +887,15 @@ struct rxvt_term : rxvt_vars { #endif short rvideo; int16_t num_scr; /* screen: number lines scrolled */ - uint16_t prev_ncol, /* screen: previous number of columns */ + uint16_t prev_ncol, /* screen: previous number of columns */ prev_nrow; /* screen: previous number of rows */ #ifdef RXVT_GRAPHICS - uint16_t gr_prev_start; + uint16_t gr_prev_start; #endif /* ---------- */ rend_t rstyle; /* ---------- */ - uint32_t pixcolor_set[NPIXCLR_SETS]; + uint32_t pixcolor_set[NPIXCLR_SETS]; /* ---------- */ #ifdef SELECTION_SCROLLING int scroll_selection_delay, @@ -1130,6 +1131,7 @@ struct rxvt_term : rxvt_vars { void init_secondary (); const char **init_resources (int argc, const char *const *argv); void init_env (); + void set_locale (const char *locale); void init_xlocale (); void init_command (const char *const *argv); int run_command (const char *const *argv);