Lookup.c

Go to the documentation of this file.
00001 /* $Xorg: Lookup.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1988, 1989, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/Lookup.c,v 3.7 2001/01/17 19:42:56 dawes Exp $ */
00029 
00030 #include <X11/Xmu/Lookup.h>
00031 
00032 #define XK_LATIN1
00033 #define XK_PUBLISHING
00034 #include <X11/keysymdef.h>
00035 
00036 /* bit (1<<i) means character is in codeset i */
00037 static unsigned short _Xconst latin1[128] =
00038   {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00039    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00040    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00041    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00042    0x10ee, 0x0000, 0x1000, 0x1084, 0x102e, 0x1000, 0x1080, 0x108e, /* 10 */
00043    0x108e, 0x1080, 0x0000, 0x1080, 0x1080, 0x10ee, 0x1000, 0x1008,
00044    0x108e, 0x1080, 0x1084, 0x1084, 0x108e, 0x1004, 0x1000, 0x1084, /* 11 */
00045    0x100e, 0x1000, 0x0000, 0x1080, 0x1000, 0x1084, 0x1000, 0x0000,
00046    0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 12 */
00047    0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
00048    0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 13 */
00049    0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x000e,
00050    0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 14 */
00051    0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
00052    0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 15 */
00053    0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x0000};
00054 
00055 /* bit (1<<i) means character is in codeset i */
00056 static unsigned short _Xconst latin2[128] =
00057   {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00058    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00059    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00060    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00061    0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 10 */
00062    0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
00063    0x0000, 0x0008, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, /* 11 */
00064    0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
00065    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
00066    0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00067    0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 13 */
00068    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00069    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 14 */
00070    0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
00071    0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 15 */
00072    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000c};
00073 
00074 /* maps Cyrillic keysyms to 8859-5 */
00075 static unsigned char _Xconst cyrillic[128] =
00076    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00077     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00078     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00079     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00080     0x00, 0xf2, 0xf3, 0xf1, 0xf4, 0xf5, 0xf6, 0xf7, /* 10 */
00081     0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0xfe, 0xff,
00082     0xf0, 0xa2, 0xa3, 0xa1, 0xa4, 0xa5, 0xa6, 0xa7, /* 11 */
00083     0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf,
00084     0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, /* 12 */
00085     0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
00086     0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, /* 13 */
00087     0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
00088     0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, /* 14 */
00089     0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
00090     0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, /* 15 */
00091     0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca};
00092 
00093 /* maps Greek keysyms to 8859-7 */
00094 static unsigned char _Xconst greek[128] =
00095    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00096     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00097     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00098     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00099     0x00, 0xb6, 0xb8, 0xb9, 0xba, 0xda, 0x00, 0xbc, /* 10 */
00100     0xbe, 0xdb, 0x00, 0xbf, 0x00, 0x00, 0xb5, 0xaf,
00101     0x00, 0xdc, 0xdd, 0xde, 0xdf, 0xfa, 0xc0, 0xfc, /* 11 */
00102     0xfd, 0xfb, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00,
00103     0x00, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 12 */
00104     0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
00105     0xd0, 0xd1, 0xd3, 0x00, 0xd4, 0xd5, 0xd6, 0xd7, /* 13 */
00106     0xd8, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00107     0x00, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 14 */
00108     0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
00109     0xf0, 0xf1, 0xf3, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7, /* 15 */
00110     0xf8, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
00111 
00112 #define sLatin1         (unsigned long)0
00113 #define sLatin2         (unsigned long)1
00114 #define sLatin3         (unsigned long)2
00115 #define sLatin4         (unsigned long)3
00116 #define sKana           (unsigned long)4
00117 #define sX0201          (unsigned long)0x01000004
00118 #define sArabic         (unsigned long)5
00119 #define sCyrillic       (unsigned long)6
00120 #define sGreek          (unsigned long)7
00121 #define sAPL            (unsigned long)11
00122 #define sHebrew         (unsigned long)12
00123 
00124 int
00125 XmuLookupString(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00126                 KeySym *keysym, XComposeStatus *status,
00127                 unsigned long keysymSet)
00128 {
00129     int count;
00130     KeySym symbol;
00131     unsigned long kset;
00132 
00133     kset = keysymSet & 0xffffff;
00134     count = XLookupString(event, (char *)buffer, nbytes, &symbol, status);
00135     if (keysym) *keysym = symbol;
00136     if ((nbytes == 0) || (symbol == NoSymbol)) {
00137         /* nothing */
00138     } else if ((count == 0) && ((symbol >> 8) == kset)) {
00139         count = 1;
00140         switch (keysymSet) {
00141         case sKana:
00142             buffer[0] = (symbol & 0xff);
00143             if (buffer[0] == 0x7e)
00144                 count = 0;
00145             break;
00146         case sCyrillic:
00147             buffer[0] = cyrillic[symbol & 0x7f];
00148             break;
00149         case sGreek:
00150             buffer[0] = greek[symbol & 0x7f];
00151             if (!buffer[0])
00152                 count = 0;
00153             break;
00154         default:
00155             buffer[0] = (symbol & 0xff);
00156             break;
00157         }
00158     } else if ((keysymSet != 0) && (count == 1) &&
00159                (((unsigned char *)buffer)[0] == symbol) &&
00160                (symbol & 0x80) &&
00161                !(latin1[symbol & 0x7f] & (1 << kset))) {
00162         if ((keysymSet == sHebrew) && (symbol == XK_multiply))
00163             buffer[0] = 0xaa;
00164         else if ((keysymSet == sHebrew) && (symbol == XK_division))
00165             buffer[0] = 0xba;
00166         else if ((keysymSet == sCyrillic) && (symbol == XK_section))
00167             buffer[0] = 0xfd;
00168         else if ((keysymSet == sX0201) && (symbol == XK_yen))
00169             buffer[0] = 0x5c;
00170         else
00171             count = 0;
00172     } else if (count != 0) {
00173         if ((keysymSet == sX0201) &&
00174             ((symbol == XK_backslash) || (symbol == XK_asciitilde)))
00175             count = 0;
00176     } else if (((symbol >> 8) == sLatin2) &&
00177                (symbol & 0x80) && (latin2[symbol & 0x7f] & (1 << kset))) {
00178         buffer[0] = (symbol & 0xff);
00179         count = 1;
00180     } else if ((keysymSet == sGreek) &&
00181                ((symbol == XK_leftsinglequotemark) ||
00182                 (symbol == XK_rightsinglequotemark))) {
00183         buffer[0] = symbol - (XK_leftsinglequotemark - 0xa1);
00184         count = 1;
00185     }
00186     return count;
00187 }
00188 
00189 /* produces ISO 8859-1 encoding plus ASCII control */
00190 int
00191 XmuLookupLatin1(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00192                 KeySym *keysym, XComposeStatus *status)
00193 {
00194     return XLookupString(event, (char *)buffer, nbytes, keysym, status);
00195 }
00196 
00197 /* produces ISO 8859-2 encoding plus ASCII control */
00198 int
00199 XmuLookupLatin2(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00200                 KeySym *keysym, XComposeStatus *status)
00201 {
00202     return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin2);
00203 }
00204 
00205 /* produces ISO 8859-3 encoding plus ASCII control */
00206 int
00207 XmuLookupLatin3(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00208                 KeySym *keysym, XComposeStatus *status)
00209 {
00210     return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin3);
00211 }
00212 
00213 /* produces ISO 8859-4 encoding plus ASCII control */
00214 int
00215 XmuLookupLatin4(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00216                 KeySym *keysym, XComposeStatus *status)
00217 {
00218     return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin4);
00219 }
00220 
00221 /* produces ISO 8859-1 GL plus Katakana plus ASCII control */
00222 int
00223 XmuLookupKana(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00224               KeySym *keysym, XComposeStatus *status)
00225 {
00226     return XmuLookupString(event, buffer, nbytes, keysym, status, sKana);
00227 }
00228 
00229 /* produces JIS X0201-1976 (8-bit) */
00230 int
00231 XmuLookupJISX0201(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00232                   KeySym *keysym, XComposeStatus *status)
00233 {
00234     return XmuLookupString(event, buffer, nbytes, keysym, status, sX0201);
00235 }
00236 
00237 /* produces ISO 8859-6 encoding plus ASCII control */
00238 int
00239 XmuLookupArabic(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00240                 KeySym *keysym, XComposeStatus *status)
00241 {
00242     return XmuLookupString(event, buffer, nbytes, keysym, status, sArabic);
00243 }
00244 
00245 /* produces ISO/IEC 8859-5 encoding plus ASCII control */
00246 int
00247 XmuLookupCyrillic(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00248                   KeySym *keysym, XComposeStatus *status)
00249 {
00250     return XmuLookupString(event, buffer, nbytes, keysym, status, sCyrillic);
00251 }
00252 
00253 /* produces ISO 8859-7 encoding plus ASCII control */
00254 int
00255 XmuLookupGreek(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00256                KeySym *keysym, XComposeStatus *status)
00257 {
00258     return XmuLookupString(event, buffer, nbytes, keysym, status, sGreek);
00259 }
00260 
00261 /* XXX this character set needs work */
00262 
00263 int
00264 XmuLookupAPL(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00265              KeySym *keysym, XComposeStatus *status)
00266 {
00267     return XmuLookupString(event, buffer, nbytes, keysym, status, sAPL);
00268 }
00269 
00270 /* produces ISO 8859-8 encoding plus ASCII control */
00271 int
00272 XmuLookupHebrew(register XKeyEvent *event, unsigned char *buffer, int nbytes,
00273                 KeySym *keysym, XComposeStatus *status)
00274 {
00275     return XmuLookupString(event, buffer, nbytes, keysym, status, sHebrew);
00276 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1