Back to index

im-sdk  12.3.91
XimpConv.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1985, 1986, 1987, 1991, 1998  The Open Group
00003 
00004 Portions Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the
00008 "Software"), to deal in the Software without restriction, including
00009 without limitation the rights to use, copy, modify, merge, publish,
00010 distribute, sublicense, and/or sell copies of the Software, and to
00011 permit persons to whom the Software is furnished to do so, subject to
00012 the following conditions: The above copyright notice and this
00013 permission notice shall be included in all copies or substantial
00014 portions of the Software.
00015 
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00020 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00021 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00022 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00023 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00024 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00025 
00026 
00027 Except as contained in this notice, the names of The Open Group and/or
00028 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00029 promote the sale, use or other dealings in this Software without prior
00030 written authorization from The Open Group and/or Sun Microsystems,
00031 Inc., as applicable.
00032 
00033 
00034 X Window System is a trademark of The Open Group
00035 
00036 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00037 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00038 Group. All other trademarks and registered trademarks mentioned herein
00039 are the property of their respective owners. No right, title or
00040 interest in or to any trademark, service mark, logo or trade name of
00041 Sun Microsystems, Inc. or its licensors is granted.
00042 
00043 */
00044 /******************************************************************
00045 
00046               Copyright 1991, 1992 by Fuji Xerox Co.,Ltd.
00047 
00048 Permission to use, copy, modify, distribute, and sell this software
00049 and its documentation for any purpose is hereby granted without fee,
00050 provided that the above copyright notice appear in all copies and
00051 that both that copyright notice and this permission notice appear
00052 in supporting documentation, and that the name of Fuji Xerox Co.,Ltd.
00053 not be used in advertising or publicity pertaining to distribution
00054 of the software without specific, written prior permission.
00055 Fuji Xerox Co.,Ltd. makes no representations about the suitability of
00056 this software for any purpose.
00057 It is provided "as is" without express or implied warranty.
00058 
00059 FUJI XEROX CO.,LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00060 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
00061 IN NO EVENT SHALL FUJI XEROX CO.,LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT
00062 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00063 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00064 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
00065 THE USE OR PERFORMANCE OF THIS SOFTWARE.
00066 
00067   Auther: Kazunori Nishihara,  Fuji Xerox Co.,Ltd.
00068                                kaz@ssdev.ksp.fujixerox.co.jp
00069 
00070 ******************************************************************/
00071 /*
00072 
00073 Copyright (c) 1994  FUJITSU LIMITED
00074 
00075 Permission is hereby granted, free of charge, to any person obtaining
00076 a copy of this software and associated documentation files (the
00077 "Software"), to deal in the Software without restriction, including
00078 without limitation the rights to use, copy, modify, merge, publish,
00079 distribute, sublicense, and/or sell copies of the Software, and to
00080 permit persons to whom the Software is furnished to do so, subject to
00081 the following conditions:
00082 
00083 The above copyright notice and this permission notice shall be included
00084 in all copies or substantial portions of the Software.
00085 
00086 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00087 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00088 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00089 IN NO EVENT SHALL THE FUJITSU LIMITED BE LIABLE FOR ANY CLAIM, DAMAGES
00090 OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00091 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00092 OTHER DEALINGS IN THE SOFTWARE.
00093 
00094 Except as contained in this notice, the name of the FUJITSU LIMITED shall
00095 not be used in advertising or otherwise to promote the sale, use or
00096 other dealings in this Software without prior written authorization
00097 from the FUJITSU LIMITED.
00098 
00099   Auther  : Takashi Fujiwara   FUJITSU LIMITED 
00100 
00101 */
00102 
00103 #ifdef HAVE_CONFIG_H
00104 #include <config.h>
00105 #endif
00106 
00107 #define NEED_EVENTS
00108 #include <X11/Xlibint.h>
00109 #include <X11/Xutil.h>
00110 #include "Xlcint.h"
00111 
00112 #include "XimpIm.h"
00113 
00114 /* 
00115  * lookup_string() is stolen from libX11: xc/lib/X11/imconv.c
00116  *
00117  * Rather than just call _XLookupString (i.e. the pre-XKB XLookupString) 
00118  * do this because with XKB the event may have some funky modifiers that 
00119  * _XLookupString doesn't grok.
00120  */
00121 #include <X11/XKBlib.h>
00122 
00123 static int lookup_string(
00124     XKeyEvent*              event,
00125     char*            buffer,
00126     int                     nbytes,
00127     KeySym*          keysym,
00128     XComposeStatus*  status)
00129 {
00130   int ret;
00131 
00132   unsigned ctrls = XkbGetXlibControls (event->display);
00133   XkbSetXlibControls (event->display, 
00134                     XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
00135   ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
00136   XkbSetXlibControls (event->display,
00137                     XkbLC_ForceLatin1Lookup, ctrls);
00138 
00139   return ret;
00140 }
00141 
00142 /* maps Cyrillic keysyms to 8859-5 */
00143 static unsigned char cyrillic[128] = {
00144     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - */
00145     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00146     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - */
00147     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00148     0x00, 0xf2, 0xf3, 0xf1, 0xf4, 0xf5, 0xf6, 0xf7, /* 0xa0 - */
00149     0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0xfe, 0xff,
00150     0xf0, 0xa2, 0xa3, 0xa1, 0xa4, 0xa5, 0xa6, 0xa7, /* 0xb0 - */
00151     0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf,
00152     0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, /* 0xc0 - */
00153     0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
00154     0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, /* 0xd0 - */
00155     0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
00156     0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, /* 0xe0 - */
00157     0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
00158     0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, /* 0xf0 - */
00159     0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
00160 };
00161 
00162 /* maps Greek keysyms to 8859-7 */
00163 static unsigned char greek[128] = {
00164     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - */
00165     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00166     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - */
00167     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00168     0x00, 0xb6, 0xb8, 0xb9, 0xba, 0xda, 0x00, 0xbc, /* 0xa0 - */
00169     0xbe, 0xdb, 0x00, 0xbf, 0x00, 0x00, 0xb5, 0xaf,
00170     0x00, 0xdc, 0xdd, 0xde, 0xdf, 0xfa, 0xc0, 0xfc, /* 0xb0 - */
00171     0xfd, 0xfb, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00,
00172     0x00, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 0xc0 - */
00173     0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
00174     0xd0, 0xd1, 0xd3, 0x00, 0xd4, 0xd5, 0xd6, 0xd7, /* 0xd0 - */
00175     0xd8, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00176     0x00, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 0xe0 - */
00177     0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
00178     0xf0, 0xf1, 0xf3, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7, /* 0xf0 - */
00179     0xf8, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
00180 };
00181 
00182 static unsigned char get_code(), get_greek(), get_cyril();
00183 
00184 struct CodesetRec {
00185     unsigned long kset;
00186     char *designator;
00187     unsigned char (*char_code)();
00188 };
00189 
00190 static struct CodesetRec codeset[] = {
00191     {0x00l, "\033-A", get_code},  /* ISO 8859-1 (Latin 1) */
00192     {0x01l, "\033-B", get_code},  /* ISO 8859-2 (Latin 2) */
00193     {0x02l, "\033-C", get_code},  /* ISO 8859-3 (Latin 3) */
00194     {0x03l, "\033-D", get_code},  /* ISO 8859-4 (Latin 4) */
00195     {0x04l, "\033)I", get_code},  /* JIS x0201 (Katakana) */
00196     {0x05l, "\033-G", get_code},  /* ISO 8859-6 (Arabic) */
00197     {0x06l, "\033-L", get_cyril}, /* ISO 8859-5 (Cyrillic) */
00198     {0x07l, "\033-F", get_greek}, /* ISO 8859-7 (Greek) */
00199     {0x0cl, "\033-H", get_code},  /* ISO 8859-8 (Hebrew) */
00200 };
00201 
00202 static int codeset_size = sizeof(codeset) / sizeof(codeset[0]);
00203 
00204 static int _XimConvertCharCode(
00205                             char *, int, KeySym, XlcConv
00206 );
00207 
00208 static unsigned char
00209 get_code(keysym)
00210 KeySym keysym;
00211 {
00212     return((unsigned char)(keysym & 0xff));
00213 }
00214 
00215 static unsigned char
00216 get_cyril(keysym)
00217 KeySym keysym;
00218 {
00219     return(cyrillic[keysym & 0x7f]);
00220 }
00221 
00222 static unsigned char
00223 get_greek(keysym)
00224 KeySym keysym;
00225 {
00226     return(greek[keysym & 0x7f]);
00227 }
00228 
00229 #define BUF_SIZE (20)
00230 static char local_buf[BUF_SIZE] = {0};    /* Clean up bss */
00231 static unsigned char look[BUF_SIZE] = {0};       /* Clean up bss */
00232 
00233 #ifndef MAXINT
00234 #define MAXINT          (~((unsigned int)1 << (8 * sizeof(int)) - 1))
00235 #endif /* !MAXINT */
00236 
00237 Public int
00238 _Ximp_ctstombs(xim, from, from_len, to, to_len, state)
00239     XIM              xim;
00240     char      *from;
00241     int               from_len;
00242     char      *to;
00243     int               to_len;
00244     Status    *state;
00245 {
00246     Ximp_XIM   im = (Ximp_XIM)xim;
00247     XlcConv    conv = im->ximp_impart->ctom_conv;
00248     int               from_left;
00249     int               to_left;
00250     int               from_savelen;
00251     int               to_savelen;
00252     int               from_cnvlen;
00253     int               to_cnvlen;
00254     char      *from_buf;
00255     char      *to_buf, *tmp_buf;
00256     Status     tmp_state;
00257   
00258     if (!state)
00259        state = &tmp_state;
00260 
00261     if (!conv || !from || !from_len) {
00262        *state = XLookupNone;
00263        return 0;
00264     }
00265 
00266     if (to && to_len) {
00267        from_left = from_len;
00268 #ifdef sun
00269        to_left = to_len;
00270 #else
00271        to_left = to_len - 1;
00272 #endif
00273        from_cnvlen = 0;
00274        to_cnvlen = 0;
00275        for (;;) {
00276            from_savelen = from_left;
00277            to_savelen = to_left;
00278            from_buf = &from[from_cnvlen];
00279            to_buf = &to[to_cnvlen];
00280            if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00281                              (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
00282               *state = XLookupNone;
00283               return 0;
00284            }
00285            from_cnvlen += (from_savelen - from_left);
00286            to_cnvlen += (to_savelen - to_left);
00287            if (from_left == 0) {
00288               if (to_cnvlen > 0) {
00289 #ifndef sun
00290                   to[to_cnvlen] = '\0';
00291 #endif
00292                   *state = XLookupChars;
00293               } else {
00294                   *state = XLookupNone;
00295               }
00296               return to_cnvlen;
00297            }
00298            if (to_left == 0)
00299               break;
00300            /* Overflow : the to_left length is so small that it cannot 
00301               accomodate the first mb character in the next conversion block */
00302            if (to_left < MB_CUR_MAX)
00303               break;
00304        }
00305     }
00306 
00307     from_left = from_len;
00308     from_cnvlen = 0;
00309     to_cnvlen = 0;
00310     /* BugId : 4253988. In case the from_buf is bigger than the to_buffer,
00311        we need to return the required buffer size and status as XBufferOverflow.       We create a tmp buffer equals 8 times the from_len and do conversion.
00312     */ 
00313     to_left = (8 * from_len) ;
00314     tmp_buf = (char *)malloc(to_left);
00315     for (;;) {
00316        from_savelen = from_left;
00317        from_buf = &from[from_cnvlen];
00318        to_savelen = to_left;
00319        to_buf = &tmp_buf[to_cnvlen];
00320        if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00321                              (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
00322            *state = XLookupNone;
00323            return 0;
00324        }
00325        from_cnvlen += (from_savelen - from_left);
00326        to_cnvlen += (to_savelen - to_left);
00327        if (from_left == 0) {
00328            if (to_cnvlen > 0)
00329               *state = XBufferOverflow;
00330            else
00331               *state = XLookupNone;
00332            break;
00333        }
00334     }
00335     free(tmp_buf);
00336     return to_cnvlen;
00337 }
00338 
00339 Public int
00340 _Ximp_ctstowcs(xim, from, from_len, to, to_len, state)
00341     XIM              xim;
00342     char      *from;
00343     int               from_len;
00344     wchar_t   *to;
00345     int               to_len;
00346     Status    *state;
00347 {
00348     Ximp_XIM   im = (Ximp_XIM)xim;
00349     XlcConv    conv = im->ximp_impart->ctow_conv;
00350     int               from_left;
00351     int               to_left;
00352     int               from_savelen;
00353     int               to_savelen;
00354     int               from_cnvlen;
00355     int               to_cnvlen;
00356     char      *from_buf;
00357     wchar_t   *to_buf, *tmp_buf;
00358     Status     tmp_state;
00359 
00360     if (!state)
00361        state = &tmp_state;
00362 
00363     if (!conv || !from || !from_len) {
00364        *state = XLookupNone;
00365        return 0;
00366     }
00367 
00368     if (to && to_len) {
00369        from_left = from_len;
00370 #ifdef sun
00371        to_left = to_len;
00372 #else
00373        to_left = to_len - 1;
00374 #endif
00375        from_cnvlen = 0;
00376        to_cnvlen = 0;
00377        for (;;) {
00378            from_savelen = from_left;
00379            to_savelen = to_left;
00380            from_buf = &from[from_cnvlen];
00381            to_buf = &to[to_cnvlen];
00382            if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00383                              (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
00384               *state = XLookupNone;
00385               return 0;
00386            }
00387            from_cnvlen += (from_savelen - from_left);
00388            to_cnvlen += (to_savelen - to_left);
00389            if (from_left == 0) {
00390               if (to_cnvlen > 0) {
00391 #ifndef sun
00392                   to[to_cnvlen] = (wchar_t)'\0';
00393 #endif
00394                   *state = XLookupChars;
00395               } else {
00396                   *state = XLookupNone;
00397               }
00398               return to_cnvlen;
00399            }
00400            if (to_left == 0)
00401               break;
00402            /* Overflow : the to_left length is so small that it cannot 
00403               accomodate the first mb character in the next conversion block */
00404            if (to_left < sizeof(wchar_t)) {
00405               break;
00406            }
00407        }
00408     }
00409               
00410     from_left = from_len;
00411     from_cnvlen = 0;
00412     to_cnvlen = 0;
00413     /* BugId : 4253988. In case the from_buf is bigger than the to_buffer,
00414        we need to return the required buffer size and status as XBufferOverflow.       We create a tmp buffer equals 8 times the from_len and do conversion.
00415     */ 
00416     to_left = (8 * from_len) ;
00417     tmp_buf = (wchar_t *)malloc(to_left * sizeof(wchar_t));
00418     for (;;) {
00419        from_savelen = from_left;
00420        from_buf = &from[from_cnvlen];
00421        to_savelen = to_left;
00422        to_buf = &tmp_buf[to_cnvlen];
00423        if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00424                              (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
00425            *state = XLookupNone;
00426            return 0;
00427        }
00428        from_cnvlen += (from_savelen - from_left);
00429        to_cnvlen += (MAXINT - to_left);
00430        if (from_left == 0) {
00431            if (to_cnvlen > 0)
00432               *state = XBufferOverflow;
00433            else
00434               *state = XLookupNone;
00435            break;
00436        }
00437     }
00438     free(tmp_buf);
00439     return to_cnvlen;
00440 }
00441 
00442 Public int
00443 _Ximp_mbs_charlen(im, mbstr, mbstr_len)
00444     Ximp_XIM   im;
00445     char      *mbstr;
00446     int               mbstr_len;
00447 {
00448     return mbstowcs(NULL, mbstr, mbstr_len); /* maybe evil */
00449 }
00450 
00451 Public int
00452 _Ximp_LookupMBText(ic, event, buffer, nbytes, keysym, status)
00453     Ximp_XIC ic;
00454     XKeyEvent *event;
00455     unsigned char *buffer;
00456     int nbytes;
00457     KeySym *keysym;
00458     XComposeStatus *status;
00459 {
00460     Ximp_XIM im = (Ximp_XIM)ic->core.im;
00461     int count;
00462     KeySym symbol;
00463 
00464     count = lookup_string(event, (char *)buffer,
00465                        nbytes, &symbol, status);
00466     if (keysym) *keysym = symbol;
00467     if ((nbytes == 0) || (symbol == NoSymbol)) {
00468        return(count);
00469     }
00470     if (count == 0) {
00471        count = _XimConvertCharCode((char *)buffer, nbytes, symbol,
00472                                           im->ximp_impart->ctom_conv);
00473     } else if ((count != 1) || (buffer[0] >= 0xa0)) { /* not ASCII Encoding */
00474        bcopy(buffer, look, count);
00475        if ((count = im->methods->ctstombs((XIM)im,
00476                                       (char *)look, count,
00477                                       (char *)buffer, nbytes,
00478                                       NULL)) < 0) {
00479            count = 0;
00480        }
00481     }
00482     return(count);
00483 }
00484 
00485 Private int
00486 _XimctsConv(conv, from, from_len, to, to_len)
00487     XlcConv    conv;
00488     char      *from;
00489     int               from_len;
00490     char      *to;
00491     int               to_len;
00492 {
00493     int               from_left;
00494     int               to_left;
00495     int               from_savelen;
00496     int               to_savelen;
00497     int               from_cnvlen;
00498     int               to_cnvlen;
00499     char      *from_buf;
00500     char      *to_buf;
00501 
00502     if (!conv || !from || !from_len) {
00503        return 0;
00504     }
00505 
00506     if (to && to_len) {
00507        from_left = from_len;
00508        to_left = to_len - 1;
00509        from_cnvlen = 0;
00510        to_cnvlen = 0;
00511        for (;;) {
00512            from_savelen = from_left;
00513            to_savelen = to_left;
00514            from_buf = &from[from_cnvlen];
00515            to_buf = &to[to_cnvlen];
00516            if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00517                              (XPointer *)&to_buf, &to_left, NULL, 0) != 0) {
00518               return 0;
00519            }
00520            from_cnvlen += (from_savelen - from_left);
00521            to_cnvlen += (to_savelen - to_left);
00522            if (from_left == 0) {
00523               if (to_cnvlen > 0) {
00524                   to[to_cnvlen] = '\0';
00525               }
00526               return to_cnvlen;
00527            }
00528            if (to_left == 0)
00529               break;
00530        }
00531     }
00532 
00533     from_left = from_len;
00534     from_cnvlen = 0;
00535     to_cnvlen = 0;
00536     to_buf = NULL;
00537     for (;;) {
00538        from_savelen = from_left;
00539        to_left = MAXINT;
00540        from_buf = &from[from_cnvlen];
00541        if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
00542                              (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
00543            return 0;
00544        }
00545        from_cnvlen += (from_savelen - from_left);
00546        to_cnvlen += (MAXINT - to_left);
00547        if (from_left == 0) {
00548            break;
00549        }
00550     }
00551     return to_cnvlen;
00552 }
00553 
00554 Private int
00555 _XimConvertCharCode(buffer, nbytes, symbol, conv)
00556     char *buffer;
00557     int nbytes;
00558     KeySym symbol;
00559     XlcConv conv;
00560 {
00561     unsigned long kset;
00562     int count, local_count;
00563     struct CodesetRec *cset = (struct CodesetRec *)NULL;
00564     register int i;
00565     unsigned char c;
00566 
00567     count = 0;
00568     kset = (symbol >> 8) & 0xffffff;
00569     for (i = 0; i < codeset_size; i++) {
00570        if (kset == codeset[i].kset) {
00571            cset = &codeset[i];
00572            break;
00573        }
00574     }
00575     if ((cset) && (cset->char_code) && (c = (*cset->char_code)(symbol))) {
00576        strcpy(local_buf, cset->designator);
00577        local_count = strlen(cset->designator);
00578        local_buf[local_count] = c;
00579        local_count++;
00580        local_buf[local_count] = '\0';
00581        if ((count = _XimctsConv(conv,
00582               local_buf, local_count, (char *)buffer, nbytes)) < 0) {
00583            count = 0;
00584        }
00585        if (count == 0) {
00586            buffer[0] = c; buffer[1] = 0;
00587            count = 1;
00588        }
00589     }
00590     return count;
00591 }
00592 
00593 Public int
00594 _Ximp_LookupWCText(ic, event, buffer, nbytes, keysym, status)
00595     Ximp_XIC ic;
00596     XKeyEvent *event;
00597     wchar_t *buffer;
00598     int nbytes;
00599     KeySym *keysym;
00600     XComposeStatus *status;
00601 {
00602     Ximp_XIM im = (Ximp_XIM)ic->core.im;
00603     int count;
00604     KeySym symbol;
00605 
00606     count = lookup_string(event, (char *)buffer, nbytes,
00607                        &symbol, status);
00608     if (keysym) *keysym = symbol;
00609     if ((nbytes == 0) || (symbol == NoSymbol)) {
00610        return(count);
00611     }
00612     if (count == 0) { /* Not ISO 8859-1 Encoding */
00613        count = _XimConvertCharCode((char *)buffer, nbytes, symbol,
00614                                           im->ximp_impart->ctow_conv);
00615     } else if ((count != 1) || (*(unsigned char *)buffer >= 0xa0)) { /* not ASCII Encoding */
00616        bcopy(buffer, look, count);
00617        if ((count = im->methods->ctstowcs((XIM)im,
00618                                       (char *)look, count,
00619                                       buffer, nbytes,
00620                                       NULL)) < 0) {
00621            count = 0;
00622        }
00623     }
00624     else { /* ASCII Encoding */
00625        buffer[0] = *(char *)buffer;
00626     }
00627     return(count);
00628 }