Back to index

im-sdk  12.3.91
Classes | Defines | Functions | Variables
XimpConv.c File Reference
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xlcint.h"
#include "XimpIm.h"
#include <X11/XKBlib.h>

Go to the source code of this file.

Classes

struct  CodesetRec

Defines

#define NEED_EVENTS
#define BUF_SIZE   (20)
#define MAXINT   (~((unsigned int)1 << (8 * sizeof(int)) - 1))

Functions

static int lookup_string (XKeyEvent *event, char *buffer, int nbytes, KeySym *keysym, XComposeStatus *status)
static unsigned char get_code ()
static unsigned char get_greek ()
static unsigned char get_cyril ()
static int _XimConvertCharCode (char *, int, KeySym, XlcConv)
static unsigned char get_code (KeySym keysym)
static unsigned char get_cyril (KeySym keysym)
static unsigned char get_greek (KeySym keysym)
Public int _Ximp_ctstombs (XIM xim, char *from, int from_len, char *to, int to_len, Status *state)
Public int _Ximp_ctstowcs (XIM xim, char *from, int from_len, wchar_t *to, int to_len, Status *state)
Public int _Ximp_mbs_charlen (Ximp_XIM im, char *mbstr, int mbstr_len)
Public int _Ximp_LookupMBText (Ximp_XIC ic, XKeyEvent *event, unsigned char *buffer, int nbytes, KeySym *keysym, XComposeStatus *status)
Private int _XimctsConv (XlcConv conv, char *from, int from_len, char *to, int to_len)
Public int _Ximp_LookupWCText (Ximp_XIC ic, XKeyEvent *event, wchar_t *buffer, int nbytes, KeySym *keysym, XComposeStatus *status)

Variables

static unsigned char cyrillic [128]
static unsigned char greek [128]
static struct CodesetRec []
static int codeset_size = sizeof(codeset) / sizeof(codeset[0])
static char local_buf [BUF_SIZE] = {0}
static unsigned char look [BUF_SIZE] = {0}

Define Documentation

#define BUF_SIZE   (20)

Definition at line 229 of file XimpConv.c.

#define MAXINT   (~((unsigned int)1 << (8 * sizeof(int)) - 1))

Definition at line 234 of file XimpConv.c.

#define NEED_EVENTS

Definition at line 107 of file XimpConv.c.


Function Documentation

Private int _XimConvertCharCode ( char *  buffer,
int  nbytes,
KeySym  symbol,
XlcConv  conv 
) [static]

Definition at line 555 of file XimpConv.c.

{
    unsigned long kset;
    int count, local_count;
    struct CodesetRec *cset = (struct CodesetRec *)NULL;
    register int i;
    unsigned char c;

    count = 0;
    kset = (symbol >> 8) & 0xffffff;
    for (i = 0; i < codeset_size; i++) {
       if (kset == codeset[i].kset) {
           cset = &codeset[i];
           break;
       }
    }
    if ((cset) && (cset->char_code) && (c = (*cset->char_code)(symbol))) {
       strcpy(local_buf, cset->designator);
       local_count = strlen(cset->designator);
       local_buf[local_count] = c;
       local_count++;
       local_buf[local_count] = '\0';
       if ((count = _XimctsConv(conv,
              local_buf, local_count, (char *)buffer, nbytes)) < 0) {
           count = 0;
       }
       if (count == 0) {
           buffer[0] = c; buffer[1] = 0;
           count = 1;
       }
    }
    return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Private int _XimctsConv ( XlcConv  conv,
char *  from,
int  from_len,
char *  to,
int  to_len 
)

Definition at line 486 of file XimpConv.c.

{
    int               from_left;
    int               to_left;
    int               from_savelen;
    int               to_savelen;
    int               from_cnvlen;
    int               to_cnvlen;
    char      *from_buf;
    char      *to_buf;

    if (!conv || !from || !from_len) {
       return 0;
    }

    if (to && to_len) {
       from_left = from_len;
       to_left = to_len - 1;
       from_cnvlen = 0;
       to_cnvlen = 0;
       for (;;) {
           from_savelen = from_left;
           to_savelen = to_left;
           from_buf = &from[from_cnvlen];
           to_buf = &to[to_cnvlen];
           if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) != 0) {
              return 0;
           }
           from_cnvlen += (from_savelen - from_left);
           to_cnvlen += (to_savelen - to_left);
           if (from_left == 0) {
              if (to_cnvlen > 0) {
                  to[to_cnvlen] = '\0';
              }
              return to_cnvlen;
           }
           if (to_left == 0)
              break;
       }
    }

    from_left = from_len;
    from_cnvlen = 0;
    to_cnvlen = 0;
    to_buf = NULL;
    for (;;) {
       from_savelen = from_left;
       to_left = MAXINT;
       from_buf = &from[from_cnvlen];
       if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
           return 0;
       }
       from_cnvlen += (from_savelen - from_left);
       to_cnvlen += (MAXINT - to_left);
       if (from_left == 0) {
           break;
       }
    }
    return to_cnvlen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Public int _Ximp_ctstombs ( XIM  xim,
char *  from,
int  from_len,
char *  to,
int  to_len,
Status *  state 
)

Definition at line 238 of file XimpConv.c.

{
    Ximp_XIM   im = (Ximp_XIM)xim;
    XlcConv    conv = im->ximp_impart->ctom_conv;
    int               from_left;
    int               to_left;
    int               from_savelen;
    int               to_savelen;
    int               from_cnvlen;
    int               to_cnvlen;
    char      *from_buf;
    char      *to_buf, *tmp_buf;
    Status     tmp_state;
  
    if (!state)
       state = &tmp_state;

    if (!conv || !from || !from_len) {
       *state = XLookupNone;
       return 0;
    }

    if (to && to_len) {
       from_left = from_len;
#ifdef sun
       to_left = to_len;
#else
       to_left = to_len - 1;
#endif
       from_cnvlen = 0;
       to_cnvlen = 0;
       for (;;) {
           from_savelen = from_left;
           to_savelen = to_left;
           from_buf = &from[from_cnvlen];
           to_buf = &to[to_cnvlen];
           if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
              *state = XLookupNone;
              return 0;
           }
           from_cnvlen += (from_savelen - from_left);
           to_cnvlen += (to_savelen - to_left);
           if (from_left == 0) {
              if (to_cnvlen > 0) {
#ifndef sun
                  to[to_cnvlen] = '\0';
#endif
                  *state = XLookupChars;
              } else {
                  *state = XLookupNone;
              }
              return to_cnvlen;
           }
           if (to_left == 0)
              break;
           /* Overflow : the to_left length is so small that it cannot 
              accomodate the first mb character in the next conversion block */
           if (to_left < MB_CUR_MAX)
              break;
       }
    }

    from_left = from_len;
    from_cnvlen = 0;
    to_cnvlen = 0;
    /* BugId : 4253988. In case the from_buf is bigger than the to_buffer,
       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.
    */ 
    to_left = (8 * from_len) ;
    tmp_buf = (char *)malloc(to_left);
    for (;;) {
       from_savelen = from_left;
       from_buf = &from[from_cnvlen];
       to_savelen = to_left;
       to_buf = &tmp_buf[to_cnvlen];
       if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
           *state = XLookupNone;
           return 0;
       }
       from_cnvlen += (from_savelen - from_left);
       to_cnvlen += (to_savelen - to_left);
       if (from_left == 0) {
           if (to_cnvlen > 0)
              *state = XBufferOverflow;
           else
              *state = XLookupNone;
           break;
       }
    }
    free(tmp_buf);
    return to_cnvlen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Public int _Ximp_ctstowcs ( XIM  xim,
char *  from,
int  from_len,
wchar_t *  to,
int  to_len,
Status *  state 
)

Definition at line 340 of file XimpConv.c.

{
    Ximp_XIM   im = (Ximp_XIM)xim;
    XlcConv    conv = im->ximp_impart->ctow_conv;
    int               from_left;
    int               to_left;
    int               from_savelen;
    int               to_savelen;
    int               from_cnvlen;
    int               to_cnvlen;
    char      *from_buf;
    wchar_t   *to_buf, *tmp_buf;
    Status     tmp_state;

    if (!state)
       state = &tmp_state;

    if (!conv || !from || !from_len) {
       *state = XLookupNone;
       return 0;
    }

    if (to && to_len) {
       from_left = from_len;
#ifdef sun
       to_left = to_len;
#else
       to_left = to_len - 1;
#endif
       from_cnvlen = 0;
       to_cnvlen = 0;
       for (;;) {
           from_savelen = from_left;
           to_savelen = to_left;
           from_buf = &from[from_cnvlen];
           to_buf = &to[to_cnvlen];
           if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
              *state = XLookupNone;
              return 0;
           }
           from_cnvlen += (from_savelen - from_left);
           to_cnvlen += (to_savelen - to_left);
           if (from_left == 0) {
              if (to_cnvlen > 0) {
#ifndef sun
                  to[to_cnvlen] = (wchar_t)'\0';
#endif
                  *state = XLookupChars;
              } else {
                  *state = XLookupNone;
              }
              return to_cnvlen;
           }
           if (to_left == 0)
              break;
           /* Overflow : the to_left length is so small that it cannot 
              accomodate the first mb character in the next conversion block */
           if (to_left < sizeof(wchar_t)) {
              break;
           }
       }
    }
              
    from_left = from_len;
    from_cnvlen = 0;
    to_cnvlen = 0;
    /* BugId : 4253988. In case the from_buf is bigger than the to_buffer,
       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.
    */ 
    to_left = (8 * from_len) ;
    tmp_buf = (wchar_t *)malloc(to_left * sizeof(wchar_t));
    for (;;) {
       from_savelen = from_left;
       from_buf = &from[from_cnvlen];
       to_savelen = to_left;
       to_buf = &tmp_buf[to_cnvlen];
       if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
                             (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
           *state = XLookupNone;
           return 0;
       }
       from_cnvlen += (from_savelen - from_left);
       to_cnvlen += (MAXINT - to_left);
       if (from_left == 0) {
           if (to_cnvlen > 0)
              *state = XBufferOverflow;
           else
              *state = XLookupNone;
           break;
       }
    }
    free(tmp_buf);
    return to_cnvlen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Public int _Ximp_LookupMBText ( Ximp_XIC  ic,
XKeyEvent *  event,
unsigned char *  buffer,
int  nbytes,
KeySym keysym,
XComposeStatus *  status 
)

Definition at line 452 of file XimpConv.c.

{
    Ximp_XIM im = (Ximp_XIM)ic->core.im;
    int count;
    KeySym symbol;

    count = lookup_string(event, (char *)buffer,
                       nbytes, &symbol, status);
    if (keysym) *keysym = symbol;
    if ((nbytes == 0) || (symbol == NoSymbol)) {
       return(count);
    }
    if (count == 0) {
       count = _XimConvertCharCode((char *)buffer, nbytes, symbol,
                                          im->ximp_impart->ctom_conv);
    } else if ((count != 1) || (buffer[0] >= 0xa0)) { /* not ASCII Encoding */
       bcopy(buffer, look, count);
       if ((count = im->methods->ctstombs((XIM)im,
                                      (char *)look, count,
                                      (char *)buffer, nbytes,
                                      NULL)) < 0) {
           count = 0;
       }
    }
    return(count);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Public int _Ximp_LookupWCText ( Ximp_XIC  ic,
XKeyEvent *  event,
wchar_t *  buffer,
int  nbytes,
KeySym keysym,
XComposeStatus *  status 
)

Definition at line 594 of file XimpConv.c.

{
    Ximp_XIM im = (Ximp_XIM)ic->core.im;
    int count;
    KeySym symbol;

    count = lookup_string(event, (char *)buffer, nbytes,
                       &symbol, status);
    if (keysym) *keysym = symbol;
    if ((nbytes == 0) || (symbol == NoSymbol)) {
       return(count);
    }
    if (count == 0) { /* Not ISO 8859-1 Encoding */
       count = _XimConvertCharCode((char *)buffer, nbytes, symbol,
                                          im->ximp_impart->ctow_conv);
    } else if ((count != 1) || (*(unsigned char *)buffer >= 0xa0)) { /* not ASCII Encoding */
       bcopy(buffer, look, count);
       if ((count = im->methods->ctstowcs((XIM)im,
                                      (char *)look, count,
                                      buffer, nbytes,
                                      NULL)) < 0) {
           count = 0;
       }
    }
    else { /* ASCII Encoding */
       buffer[0] = *(char *)buffer;
    }
    return(count);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Public int _Ximp_mbs_charlen ( Ximp_XIM  im,
char *  mbstr,
int  mbstr_len 
)

Definition at line 443 of file XimpConv.c.

{
    return mbstowcs(NULL, mbstr, mbstr_len); /* maybe evil */
}
static unsigned char get_code ( ) [static]
static unsigned char get_code ( KeySym  keysym) [static]

Definition at line 209 of file XimpConv.c.

{
    return((unsigned char)(keysym & 0xff));
}
static unsigned char get_cyril ( )
static unsigned char get_cyril ( KeySym  keysym) [static]

Definition at line 216 of file XimpConv.c.

{
    return(cyrillic[keysym & 0x7f]);
}
static unsigned char get_greek ( )
static unsigned char get_greek ( KeySym  keysym) [static]

Definition at line 223 of file XimpConv.c.

{
    return(greek[keysym & 0x7f]);
}
static int lookup_string ( XKeyEvent *  event,
char *  buffer,
int  nbytes,
KeySym keysym,
XComposeStatus *  status 
) [static]

Definition at line 123 of file XimpConv.c.

{
  int ret;

  unsigned ctrls = XkbGetXlibControls (event->display);
  XkbSetXlibControls (event->display, 
                    XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
  ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
  XkbSetXlibControls (event->display,
                    XkbLC_ForceLatin1Lookup, ctrls);

  return ret;
}

Here is the caller graph for this function:


Variable Documentation

int codeset_size = sizeof(codeset) / sizeof(codeset[0]) [static]

Definition at line 202 of file XimpConv.c.

struct CodesetRec[] [static]
Initial value:
 {
    {0x00l, "\033-A", get_code},  
    {0x01l, "\033-B", get_code},  
    {0x02l, "\033-C", get_code},  
    {0x03l, "\033-D", get_code},  
    {0x04l, "\033)I", get_code},  
    {0x05l, "\033-G", get_code},  
    {0x06l, "\033-L", get_cyril}, 
    {0x07l, "\033-F", get_greek}, 
    {0x0cl, "\033-H", get_code},  
}

Definition at line 190 of file XimpConv.c.

unsigned char cyrillic[128] [static]
Initial value:
 {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0xf2, 0xf3, 0xf1, 0xf4, 0xf5, 0xf6, 0xf7, 
    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0xfe, 0xff,
    0xf0, 0xa2, 0xa3, 0xa1, 0xa4, 0xa5, 0xa6, 0xa7, 
    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf,
    0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, 
    0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
    0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, 
    0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
    0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, 
    0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
    0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, 
    0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
}

Definition at line 143 of file XimpConv.c.

unsigned char greek[128] [static]
Initial value:
 {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0xb6, 0xb8, 0xb9, 0xba, 0xda, 0x00, 0xbc, 
    0xbe, 0xdb, 0x00, 0xbf, 0x00, 0x00, 0xb5, 0xaf,
    0x00, 0xdc, 0xdd, 0xde, 0xdf, 0xfa, 0xc0, 0xfc, 
    0xfd, 0xfb, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00,
    0x00, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
    0xd0, 0xd1, 0xd3, 0x00, 0xd4, 0xd5, 0xd6, 0xd7, 
    0xd8, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
    0xf0, 0xf1, 0xf3, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7, 
    0xf8, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 163 of file XimpConv.c.

char local_buf[BUF_SIZE] = {0} [static]

Definition at line 230 of file XimpConv.c.

unsigned char look[BUF_SIZE] = {0} [static]

Definition at line 231 of file XimpConv.c.