/*--------------------------------*-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 <jdb@ukc.ac.uk>
#include "version.h"
#include "command.h"
+#include <wchar.h>
+
/*----------------------------------------------------------------------*/
/*{{{ Convert the keypress event into a string */
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;
}
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;
/*--------------------------------*-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 <jdb@ukc.ac.uk>
* 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 ()
{
#ifdef USE_XIM
return;
}
- rxvt_setTermFontSet (this, 0);
-
/* see if we can connect yet */
rxvt_IMInstantiateCallback (Xdisplay, NULL, NULL);
long vt_emask;
#ifdef PREFER_24BIT
-
XSetWindowAttributes attributes;
XWindowAttributes gattr;
/*--------------------------------*-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 <jdb@ukc.ac.uk>
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);
}
}
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
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,
}
/*
- * 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;
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;
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;
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)
/*
- * $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 */
#include "iom.h"
#include "salloc.h"
+#include <wchar.h>
+
/*
*****************************************************************************
* SYSTEM HACKS
#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));
}
};
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
#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,
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);