Blame src/Lookup.c

Packit Service 2b1f13
/*
Packit Service 2b1f13
Packit Service 2b1f13
Copyright 1988, 1989, 1998  The Open Group
Packit Service 2b1f13
Packit Service 2b1f13
Permission to use, copy, modify, distribute, and sell this software and its
Packit Service 2b1f13
documentation for any purpose is hereby granted without fee, provided that
Packit Service 2b1f13
the above copyright notice appear in all copies and that both that
Packit Service 2b1f13
copyright notice and this permission notice appear in supporting
Packit Service 2b1f13
documentation.
Packit Service 2b1f13
Packit Service 2b1f13
The above copyright notice and this permission notice shall be included in
Packit Service 2b1f13
all copies or substantial portions of the Software.
Packit Service 2b1f13
Packit Service 2b1f13
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 2b1f13
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 2b1f13
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service 2b1f13
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit Service 2b1f13
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 2b1f13
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit Service 2b1f13
Packit Service 2b1f13
Except as contained in this notice, the name of The Open Group shall not be
Packit Service 2b1f13
used in advertising or otherwise to promote the sale, use or other dealings
Packit Service 2b1f13
in this Software without prior written authorization from The Open Group.
Packit Service 2b1f13
Packit Service 2b1f13
*/
Packit Service 2b1f13
Packit Service 2b1f13
#ifdef HAVE_CONFIG_H
Packit Service 2b1f13
#include <config.h>
Packit Service 2b1f13
#endif
Packit Service 2b1f13
#include <X11/Xmu/Lookup.h>
Packit Service 2b1f13
Packit Service 2b1f13
#define XK_LATIN1
Packit Service 2b1f13
#define XK_PUBLISHING
Packit Service 2b1f13
#include <X11/keysymdef.h>
Packit Service 2b1f13
Packit Service 2b1f13
/* bit (1<
Packit Service 2b1f13
static unsigned short _Xconst latin1[128] =
Packit Service 2b1f13
  {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x10ee, 0x0000, 0x1000, 0x1084, 0x102e, 0x1000, 0x1080, 0x108e, /* 10 */
Packit Service 2b1f13
   0x108e, 0x1080, 0x0000, 0x1080, 0x1080, 0x10ee, 0x1000, 0x1008,
Packit Service 2b1f13
   0x108e, 0x1080, 0x1084, 0x1084, 0x108e, 0x1004, 0x1000, 0x1084, /* 11 */
Packit Service 2b1f13
   0x100e, 0x1000, 0x0000, 0x1080, 0x1000, 0x1084, 0x1000, 0x0000,
Packit Service 2b1f13
   0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 12 */
Packit Service 2b1f13
   0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
Packit Service 2b1f13
   0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 13 */
Packit Service 2b1f13
   0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x000e,
Packit Service 2b1f13
   0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 14 */
Packit Service 2b1f13
   0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
Packit Service 2b1f13
   0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 15 */
Packit Service 2b1f13
   0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x0000};
Packit Service 2b1f13
Packit Service 2b1f13
/* bit (1<
Packit Service 2b1f13
static unsigned short _Xconst latin2[128] =
Packit Service 2b1f13
  {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 10 */
Packit Service 2b1f13
   0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
Packit Service 2b1f13
   0x0000, 0x0008, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, /* 11 */
Packit Service 2b1f13
   0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
Packit Service 2b1f13
   0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 13 */
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 14 */
Packit Service 2b1f13
   0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Packit Service 2b1f13
   0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 15 */
Packit Service 2b1f13
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000c};
Packit Service 2b1f13
Packit Service 2b1f13
/* maps Cyrillic keysyms to 8859-5 */
Packit Service 2b1f13
static unsigned char _Xconst cyrillic[128] =
Packit Service 2b1f13
   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0xf2, 0xf3, 0xf1, 0xf4, 0xf5, 0xf6, 0xf7, /* 10 */
Packit Service 2b1f13
    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0xfe, 0xff,
Packit Service 2b1f13
    0xf0, 0xa2, 0xa3, 0xa1, 0xa4, 0xa5, 0xa6, 0xa7, /* 11 */
Packit Service 2b1f13
    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf,
Packit Service 2b1f13
    0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, /* 12 */
Packit Service 2b1f13
    0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
Packit Service 2b1f13
    0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, /* 13 */
Packit Service 2b1f13
    0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
Packit Service 2b1f13
    0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, /* 14 */
Packit Service 2b1f13
    0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
Packit Service 2b1f13
    0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, /* 15 */
Packit Service 2b1f13
    0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca};
Packit Service 2b1f13
Packit Service 2b1f13
/* maps Greek keysyms to 8859-7 */
Packit Service 2b1f13
static unsigned char _Xconst greek[128] =
Packit Service 2b1f13
   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0xb6, 0xb8, 0xb9, 0xba, 0xda, 0x00, 0xbc, /* 10 */
Packit Service 2b1f13
    0xbe, 0xdb, 0x00, 0xbf, 0x00, 0x00, 0xb5, 0xaf,
Packit Service 2b1f13
    0x00, 0xdc, 0xdd, 0xde, 0xdf, 0xfa, 0xc0, 0xfc, /* 11 */
Packit Service 2b1f13
    0xfd, 0xfb, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 12 */
Packit Service 2b1f13
    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
Packit Service 2b1f13
    0xd0, 0xd1, 0xd3, 0x00, 0xd4, 0xd5, 0xd6, 0xd7, /* 13 */
Packit Service 2b1f13
    0xd8, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit Service 2b1f13
    0x00, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 14 */
Packit Service 2b1f13
    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
Packit Service 2b1f13
    0xf0, 0xf1, 0xf3, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7, /* 15 */
Packit Service 2b1f13
    0xf8, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Packit Service 2b1f13
Packit Service 2b1f13
#define sLatin1		(unsigned long)0
Packit Service 2b1f13
#define sLatin2		(unsigned long)1
Packit Service 2b1f13
#define sLatin3		(unsigned long)2
Packit Service 2b1f13
#define sLatin4		(unsigned long)3
Packit Service 2b1f13
#define sKana		(unsigned long)4
Packit Service 2b1f13
#define sX0201		(unsigned long)0x01000004
Packit Service 2b1f13
#define sArabic		(unsigned long)5
Packit Service 2b1f13
#define sCyrillic	(unsigned long)6
Packit Service 2b1f13
#define sGreek		(unsigned long)7
Packit Service 2b1f13
#define sAPL		(unsigned long)11
Packit Service 2b1f13
#define sHebrew		(unsigned long)12
Packit Service 2b1f13
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupString(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status,
Packit Service 2b1f13
		unsigned long keysymSet)
Packit Service 2b1f13
{
Packit Service 2b1f13
    int count;
Packit Service 2b1f13
    KeySym symbol;
Packit Service 2b1f13
    unsigned long kset;
Packit Service 2b1f13
Packit Service 2b1f13
    kset = keysymSet & 0xffffff;
Packit Service 2b1f13
    count = XLookupString(event, (char *)buffer, nbytes, &symbol, status);
Packit Service 2b1f13
    if (keysym) *keysym = symbol;
Packit Service 2b1f13
    if ((nbytes == 0) || (symbol == NoSymbol)) {
Packit Service 2b1f13
	/* nothing */
Packit Service 2b1f13
    } else if ((count == 0) && ((symbol >> 8) == kset)) {
Packit Service 2b1f13
	count = 1;
Packit Service 2b1f13
	switch (keysymSet) {
Packit Service 2b1f13
	case sKana:
Packit Service 2b1f13
	    buffer[0] = (symbol & 0xff);
Packit Service 2b1f13
	    if (buffer[0] == 0x7e)
Packit Service 2b1f13
		count = 0;
Packit Service 2b1f13
	    break;
Packit Service 2b1f13
	case sCyrillic:
Packit Service 2b1f13
	    buffer[0] = cyrillic[symbol & 0x7f];
Packit Service 2b1f13
	    break;
Packit Service 2b1f13
	case sGreek:
Packit Service 2b1f13
	    buffer[0] = greek[symbol & 0x7f];
Packit Service 2b1f13
	    if (!buffer[0])
Packit Service 2b1f13
		count = 0;
Packit Service 2b1f13
	    break;
Packit Service 2b1f13
	default:
Packit Service 2b1f13
	    buffer[0] = (symbol & 0xff);
Packit Service 2b1f13
	    break;
Packit Service 2b1f13
	}
Packit Service 2b1f13
    } else if ((keysymSet != 0) && (count == 1) &&
Packit Service 2b1f13
	       (((unsigned char *)buffer)[0] == symbol) &&
Packit Service 2b1f13
	       (symbol & 0x80) &&
Packit Service 2b1f13
	       !(latin1[symbol & 0x7f] & (1 << kset))) {
Packit Service 2b1f13
	if ((keysymSet == sHebrew) && (symbol == XK_multiply))
Packit Service 2b1f13
	    buffer[0] = 0xaa;
Packit Service 2b1f13
	else if ((keysymSet == sHebrew) && (symbol == XK_division))
Packit Service 2b1f13
	    buffer[0] = 0xba;
Packit Service 2b1f13
	else if ((keysymSet == sCyrillic) && (symbol == XK_section))
Packit Service 2b1f13
	    buffer[0] = 0xfd;
Packit Service 2b1f13
	else if ((keysymSet == sX0201) && (symbol == XK_yen))
Packit Service 2b1f13
	    buffer[0] = 0x5c;
Packit Service 2b1f13
	else
Packit Service 2b1f13
	    count = 0;
Packit Service 2b1f13
    } else if (count != 0) {
Packit Service 2b1f13
	if ((keysymSet == sX0201) &&
Packit Service 2b1f13
	    ((symbol == XK_backslash) || (symbol == XK_asciitilde)))
Packit Service 2b1f13
	    count = 0;
Packit Service 2b1f13
    } else if (((symbol >> 8) == sLatin2) &&
Packit Service 2b1f13
	       (symbol & 0x80) && (latin2[symbol & 0x7f] & (1 << kset))) {
Packit Service 2b1f13
	buffer[0] = (symbol & 0xff);
Packit Service 2b1f13
	count = 1;
Packit Service 2b1f13
    } else if ((keysymSet == sGreek) &&
Packit Service 2b1f13
	       ((symbol == XK_leftsinglequotemark) ||
Packit Service 2b1f13
		(symbol == XK_rightsinglequotemark))) {
Packit Service 2b1f13
	buffer[0] = symbol - (XK_leftsinglequotemark - 0xa1);
Packit Service 2b1f13
	count = 1;
Packit Service 2b1f13
    }
Packit Service 2b1f13
    return count;
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-1 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupLatin1(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XLookupString(event, (char *)buffer, nbytes, keysym, status);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-2 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupLatin2(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin2);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-3 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupLatin3(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin3);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-4 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupLatin4(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin4);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-1 GL plus Katakana plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupKana(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
	      KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sKana);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces JIS X0201-1976 (8-bit) */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupJISX0201(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		  KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sX0201);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-6 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupArabic(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sArabic);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO/IEC 8859-5 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupCyrillic(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		  KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sCyrillic);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-7 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupGreek(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
	       KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sGreek);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* XXX this character set needs work */
Packit Service 2b1f13
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupAPL(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
	     KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sAPL);
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
/* produces ISO 8859-8 encoding plus ASCII control */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuLookupHebrew(register XKeyEvent *event, unsigned char *buffer, int nbytes,
Packit Service 2b1f13
		KeySym *keysym, XComposeStatus *status)
Packit Service 2b1f13
{
Packit Service 2b1f13
    return XmuLookupString(event, buffer, nbytes, keysym, status, sHebrew);
Packit Service 2b1f13
}