diff options
Diffstat (limited to 'src/xkb/XKBCvt.c')
-rw-r--r-- | src/xkb/XKBCvt.c | 327 |
1 files changed, 29 insertions, 298 deletions
diff --git a/src/xkb/XKBCvt.c b/src/xkb/XKBCvt.c index bd965d2..c1a64dc 100644 --- a/src/xkb/XKBCvt.c +++ b/src/xkb/XKBCvt.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/X11/XKBCvt.c,v 3.34 2002/10/08 23:31:35 dawes Exp $ */ #include <stdio.h> #include <sys/types.h> @@ -37,6 +38,7 @@ from The Open Group. #include "Xlibint.h" #include "Xlcint.h" #include "XlcPubI.h" +#include "Ximint.h" #include <X11/Xutil.h> #include <X11/Xmd.h> #define XK_LATIN1 @@ -52,67 +54,6 @@ from The Open Group. #define XKB_EXTEND_LOOKUP_STRING #endif -#ifdef X_NOT_STDC_ENV -extern char *getenv(); -#endif - -#ifdef __STDC__ -#define Const const -#else -#define Const /**/ -#endif -#if defined(__STDC__) && !defined(NORCONST) -#define RConst const -#else -#define RConst /**/ -#endif - -/* bit (1<<i) means character is in codeset i at the same codepoint */ -extern unsigned int _Xlatin1[]; - -/* bit (1<<i) means character is in codeset i at the same codepoint */ -extern unsigned int _Xlatin2[]; - -/* maps Cyrillic keysyms to KOI8-R */ -extern unsigned char _Xkoi8[]; - -extern unsigned short _Xkoi8_size; - -#define sLatin1 0 -#define sLatin2 1 -#define sLatin3 2 -#define sLatin4 3 -#define sKana 4 -#define sX0201 0x01000004 -#define sArabic 5 -#define sCyrillic 6 -#define sGreek 7 -#define sAPL 11 -#define sHebrew 12 -#define sThai 13 -#define sKorean 14 -#define sLatin5 15 -#define sLatin6 16 -#define sLatin7 17 -#define sLatin8 18 -#define sLatin9 19 -#define sCurrency 32 - - -static unsigned long WantLatin1 = sLatin1; -static unsigned long WantLatin2 = sLatin2; -static unsigned long WantLatin3 = sLatin3; -static unsigned long WantLatin4 = sLatin4; -static unsigned long WantLatin5 = sLatin5; -static unsigned long WantLatin6 = sLatin6; -static unsigned long WantKana = sKana; -static unsigned long WantX0201 = sX0201; -static unsigned long WantArabic = sArabic; -static unsigned long WantCyrillic = sCyrillic; -static unsigned long WantGreek = sGreek; -static unsigned long WantAPL = sAPL; -static unsigned long WantHebrew = sHebrew; - static int #if NeedFunctionPrototypes _XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn) @@ -149,15 +90,8 @@ _XkbHandleSpecialSym(keysym, buffer, nbytes, extra_rtrn) return 1; } -extern int -_XGetCharCode ( -#if NeedFunctionPrototypes - unsigned long, KeySym, char*, int -#endif -); - /*ARGSUSED*/ -int +static int #if NeedFunctionPrototypes _XkbKSToKnownSet ( XPointer priv, KeySym keysym, @@ -173,16 +107,11 @@ _XkbKSToKnownSet (priv, keysym, buffer, nbytes, extra_rtrn) int *extra_rtrn; #endif { - unsigned long kset,keysymSet; - int count,isLatin1; char tbuf[8],*buf; if (extra_rtrn) *extra_rtrn= 0; - keysymSet = *((unsigned long *)priv); - kset = keysymSet&0xffffff; - /* convert "dead" diacriticals for dumb applications */ if ( (keysym&0xffffff00)== 0xfe00 ) { switch ( keysym ) { @@ -207,16 +136,13 @@ _XkbKSToKnownSet (priv, keysym, buffer, nbytes, extra_rtrn) } } - isLatin1 = ((keysym&0xffffff00)==0); - count = 0; - if (nbytes<1) buf= tbuf; else buf= buffer; if ((keysym&0xffffff00)==0xff00) { return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn); } - return _XGetCharCode (keysymSet, keysym, buf, nbytes); + return _XimGetCharCode (priv, keysym, (unsigned char *)buf, nbytes); } typedef struct _XkbToKS { @@ -251,62 +177,6 @@ _XkbKnownSetToKS(priv,buffer,nbytes,status) return NoSymbol; } -/*ARGSUSED*/ -int -#if NeedFunctionPrototypes -_XkbKSToThai ( XPointer priv, - KeySym keysym, - char * buffer, - int nbytes, - int * extra_rtrn) -#else -_XkbKSToThai (priv, keysym, buffer, nbytes, extra_rtrn) - XPointer priv; - KeySym keysym; - char *buffer; - int nbytes; - int *extra_rtrn; -#endif -{ - - if ((keysym&0xffffff00)==0xff00) { - return _XkbHandleSpecialSym(keysym, buffer, nbytes, extra_rtrn); - } - else if (((keysym&0xffffff80)==0xd80)||((keysym&0xffffff80)==0)) { - if (nbytes>0) { - buffer[0]= (char)(keysym&0xff); - if (nbytes>1) - buffer[1]= '\0'; - return 1; - } - if (extra_rtrn) - *extra_rtrn= 1; - } - return 0; -} - -/*ARGSUSED*/ -static KeySym -#if NeedFunctionPrototypes -_XkbThaiToKS(XPointer priv,char *buffer,int nbytes,Status *status) -#else -_XkbThaiToKS(priv,buffer,nbytes,status) - XPointer priv; - char *buffer; - int nbytes; - Status *status; -#endif -{ - if (nbytes!=1) - return NoSymbol; - if (((buffer[0]&0x80)==0)&&(buffer[0]>=32)) - return buffer[0]; - else if ((buffer[0]&0x7f)>=32) { - return 0xd00|buffer[0]; - } - return NoSymbol; -} - static KeySym #if NeedFunctionPrototypes __XkbDefaultToUpper(KeySym sym) @@ -321,117 +191,7 @@ __XkbDefaultToUpper(sym) return upper; } -int _XkbKSToKoi8 (priv, keysym, buffer, nbytes, status) - XPointer priv; - KeySym keysym; - char *buffer; - int nbytes; - Status *status; -{ - if ((keysym&0xffffff00)==0xff00) { - return _XkbHandleSpecialSym(keysym, buffer, nbytes, status); - } - else if (((keysym&0xffffff80)==0x680)||((keysym&0xffffff80)==0)) { - if (nbytes>0) { - if ( (keysym&0x80)==0 ) - buffer[0] = keysym&0x7f; - else buffer[0] = _Xkoi8[keysym & 0x7f]; - if (nbytes>1) - buffer[1]= '\0'; - return 1; - } - } - return 0; -} - -static KeySym -_XkbKoi8ToKS(priv,buffer,nbytes,status) - XPointer priv; - char *buffer; - int nbytes; - Status *status; -{ - if (nbytes!=1) - return NoSymbol; - if (((buffer[0]&0x80)==0)&&(buffer[0]>=32)) - return buffer[0]; - else if ((buffer[0]&0x7f)>=32) { - register int i; - for (i=0;i<_Xkoi8_size;i++) { - if (_Xkoi8[i]==buffer[0]) - return 0x680|i; - } - } - return NoSymbol; -} - -/***====================================================================***/ - - -static XkbConverters RConst cvt_ascii = { - _XkbKSToKnownSet,(XPointer)&WantLatin1,_XkbKnownSetToKS,NULL,__XkbDefaultToUpper -}; - -static XkbConverters RConst cvt_latin1 = { - _XkbKSToKnownSet,(XPointer)&WantLatin1,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_latin2 = { - _XkbKSToKnownSet,(XPointer)&WantLatin2,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_latin3 = { - _XkbKSToKnownSet,(XPointer)&WantLatin3,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_latin4 = { - _XkbKSToKnownSet,(XPointer)&WantLatin4,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_latin5 = { - _XkbKSToKnownSet,(XPointer)&WantLatin5,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_latin6 = { - _XkbKSToKnownSet,(XPointer)&WantLatin6,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_kana = { - _XkbKSToKnownSet,(XPointer)&WantKana,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_X0201 = { - _XkbKSToKnownSet,(XPointer)&WantX0201,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_Arabic = { - _XkbKSToKnownSet,(XPointer)&WantArabic,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_Cyrillic = { - _XkbKSToKnownSet,(XPointer)&WantCyrillic,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_Greek = { - _XkbKSToKnownSet,(XPointer)&WantGreek,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_APL = { - _XkbKSToKnownSet,(XPointer)&WantAPL,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters RConst cvt_Hebrew = { - _XkbKSToKnownSet,(XPointer)&WantHebrew,_XkbKnownSetToKS,NULL,NULL -}; - -static XkbConverters cvt_Thai = { - _XkbKSToThai, NULL, _XkbThaiToKS, NULL, NULL -}; - -static XkbConverters cvt_Koi8 = { - _XkbKSToKoi8, NULL, _XkbKoi8ToKS, NULL, NULL -}; - +#ifdef XKB_EXTEND_LOOKUP_STRING static int #if NeedFunctionPrototypes Strcmp(char *str1, char *str2) @@ -443,7 +203,11 @@ Strcmp(str1, str2) char str[256]; char c, *s; - if (strlen (str1) >= sizeof str) /* almost certain it's a mismatch */ + /* + * unchecked strings from the environment can end up here, so check + * the length before copying. + */ + if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */ return 1; for (s = str; (c = *str1++); ) { @@ -454,6 +218,7 @@ Strcmp(str1, str2) *s = '\0'; return (strcmp(str, str2)); } +#endif int #if NeedFunctionPrototypes @@ -464,55 +229,13 @@ _XkbGetConverters(encoding_name, cvt_rtrn) XkbConverters *cvt_rtrn; #endif { - if ( cvt_rtrn ) { - if ( (encoding_name==NULL) || - (Strcmp(encoding_name,"ascii")==0) || - (Strcmp(encoding_name,"string")==0) ) - *cvt_rtrn = cvt_ascii; - else if (Strcmp(encoding_name,"iso8859-1")==0) - *cvt_rtrn = cvt_latin1; - else if (Strcmp(encoding_name, "iso8859-2")==0) - *cvt_rtrn = cvt_latin2; - else if (Strcmp(encoding_name, "iso8859-3")==0) - *cvt_rtrn = cvt_latin3; - else if (Strcmp(encoding_name, "iso8859-4")==0) - *cvt_rtrn = cvt_latin4; - else if (Strcmp(encoding_name, "iso8859-5")==0) - *cvt_rtrn = cvt_Cyrillic; - else if (Strcmp(encoding_name, "iso8859-6")==0) - *cvt_rtrn = cvt_Arabic; - else if (Strcmp(encoding_name, "iso8859-7")==0) - *cvt_rtrn = cvt_Greek; - else if (Strcmp(encoding_name, "iso8859-8")==0) - *cvt_rtrn = cvt_Hebrew; - else if (Strcmp(encoding_name, "iso8859-9")==0) - *cvt_rtrn = cvt_latin5; - else if (Strcmp(encoding_name, "iso8859-10")==0) - *cvt_rtrn = cvt_latin6; - else if (Strcmp(encoding_name, "apl")==0) - *cvt_rtrn = cvt_APL; -#if 0 - else if (Strcmp(encoding_name, "ja.euc")==0) - *cvt_rtrn = ???; - else if (Strcmp(encoding_name, "ja.jis")==0) - *cvt_rtrn = ???; - else if (Strcmp(encoding_name, "ja.sjis")==0) - *cvt_rtrn = ???; -#endif - else if (Strcmp(encoding_name, "jisx0201")==0) /* ??? */ - *cvt_rtrn = cvt_X0201; - else if (Strcmp(encoding_name, "kana")==0) /* ??? */ - *cvt_rtrn = cvt_kana; - else if ((Strcmp(encoding_name, "tactis")==0) || - (Strcmp(encoding_name, "tis620.2533-1")==0)) - *cvt_rtrn = cvt_Thai; - else if (Strcmp(encoding_name, "koi8-r")==0) - *cvt_rtrn = cvt_Koi8; - /* other codesets go here */ - else *cvt_rtrn = cvt_latin1; - return 1; - } - *cvt_rtrn= cvt_latin1; + if ( !cvt_rtrn ) return 0; + + cvt_rtrn->KSToMB = _XkbKSToKnownSet; + cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name); + cvt_rtrn->MBToKS = _XkbKnownSetToKS; + cvt_rtrn->MBToKSPriv = NULL; + cvt_rtrn->KSToUpper = __XkbDefaultToUpper; return 1; } @@ -532,7 +255,7 @@ _XkbGetConverters(encoding_name, cvt_rtrn) */ #define CHARSET_FILE "/usr/lib/X11/input/charsets" -static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fi,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:bg,ru=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:th,th_TH,th_TH.TACTIS=tactis"; +static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251"; char * _XkbGetCharset() @@ -555,6 +278,9 @@ _XkbGetCharset() if ( locale == NULL ) return NULL; + if (strlen(locale) >= sizeof(lang)) + return NULL; + for (tmp = lang; *tmp = *locale++; tmp++) { if (isupper(*tmp)) *tmp = tolower(*tmp); @@ -581,8 +307,13 @@ _XkbGetCharset() } else { struct stat sbuf; FILE *file; - if ( (stat(CHARSET_FILE,&sbuf)==0) && (sbuf.st_mode&S_IFREG) && - (file = fopen(CHARSET_FILE,"r")) ) { +#ifndef __UNIXOS2__ + char *cf = CHARSET_FILE; +#else + char *cf = __XOS2RedirRoot(CHARSET_FILE); +#endif + if ( (stat(cf,&sbuf)==0) && (sbuf.st_mode&S_IFREG) && + (file = fopen(cf,"r")) ) { tmp = _XkbAlloc(sbuf.st_size+1); if (tmp!=NULL) { sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file); |