Back to index

im-sdk  12.3.91
Functions
codepoint_filter.c File Reference
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <wchar.h>
#include "SunIM.h"
#include "codepoint_im.h"
#include "unit_input.h"
#include "codepoint_filter.h"
#include "logf.h"

Go to the source code of this file.

Functions

int Check_Input_Type (TableStruct *unit_table)
int Is_UsedCodes_Key (TableStruct *unit_table, int key)
int Is_Commit_Key (TableStruct *unit_table, int key)
int Is_BackSpace_Key (TableStruct *unit_table, int key)
int Is_ClearAll_Key (TableStruct *unit_table, int key)
int commit_candidate (IMEBufferRec *ime_buffer, TableStruct *unit_table)
void warning_bell ()
int codepoint_filter (TableStruct *unit_table, IMEKey key_event, IMEBufferRec *ime_buffer)
int map_keyevent_to_imekey (TableStruct *unit_table, IMEKey key_event)
int convert_UCS4_to_UTF8 (unsigned int *from_buf, unsigned char *to_buf)

Function Documentation

int Check_Input_Type ( TableStruct unit_table)

Definition at line 61 of file codepoint_filter.c.

{
  if (!strcmp((char *)unit_table->InputType, (char *)"HEX"))
    return(0); 
  return(1); 
}

Here is the caller graph for this function:

int codepoint_filter ( TableStruct unit_table,
IMEKey  key_event,
IMEBufferRec ime_buffer 
)

Definition at line 151 of file codepoint_filter.c.

{
  int     key, default_input_len;
 
  ime_buffer->encode = unit_table->Encode;
  default_input_len = unit_table->Default_Input;

  IME_Status = 0;

  key = map_keyevent_to_imekey(unit_table, key_event);
  log_f("codepoint_filter: map_keyevent_to_imekey: return key:0x%x\n", key);
 
  if (key == IME_NOT_USED_KEY){
    log_f("IME_NOT_USED_KEY \n");
    return(IME_NOT_USED_KEY);
  }

  if (esc_key_flag)
    default_input_len = unit_table->Max_Input; 

  if (Is_UsedCodes_Key(unit_table, key)){
    /* if not key by key, and is selectkey, and Lookup Mode */
    /* directly select */
  
    Input_Buf[Input_Len] = key;
    Input_Len ++;
    Input_Buf[Input_Len] = 0;
  
    log_f("Input_Len:%d\n",Input_Len);

    if (Input_Len == default_input_len){
      Preedit_Buf[Preedit_Len] = key;
      Preedit_Len += 1;
      Preedit_Buf[Preedit_Len] = '\0';
      if (commit_candidate(ime_buffer, unit_table) == RETURN_KEY) {
        Preedit_Len = 0;
        Preedit_CaretPos = 0;
        Input_Len = 0;
        Input_Buf[Input_Len]='\0';
        IME_Status |= IME_PREEDIT_AREA; 
        return RETURN_KEY;
      }
      Preedit_Len = 0;
      Preedit_CaretPos = 0;
      Input_Len = 0;
      Input_Buf[Input_Len]='\0';
      IME_Status |= IME_PREEDIT_AREA; 
      return(IME_USED_KEY);
    }

    Preedit_Buf[Preedit_Len] = key;
    Preedit_Len += 1;
    Preedit_Buf[Preedit_Len] = '\0';
    Preedit_CaretPos = Preedit_Len;
    IME_Status = IME_PREEDIT_AREA;
    return(IME_USED_KEY);
  }

  if (Is_ClearAll_Key(unit_table, key)) { 
    /* Esc , clear preedit and so on */
    log_f("ESC_KEY\n");
    if (!esc_key_flag)
      esc_key_flag = 1;
    else
      esc_key_flag = 0;

    return(IME_NOT_USED_KEY);
  }

  if (Is_BackSpace_Key(unit_table, key)) { /* Back Space & Delete */
    log_f("BACKSPACE_KEY, Input_Len:%d, Preedit_Len:%d\n", Input_Len, Preedit_Len);
    /*  if no inputted key, directly return this key */
    if (Input_Len==0) {
      return(IME_NOT_USED_KEY);
    }

    Input_Len --;
    Input_Buf[Input_Len] = '\0';
    Preedit_Len -= 1;
    Preedit_Buf[Preedit_Len] = '\0';
    Preedit_CaretPos = Preedit_Len;
    IME_Status = IME_PREEDIT_AREA;

    return(IME_USED_KEY);
  }

  if (Is_Commit_Key(unit_table, key)) { /* space or return key */
    log_f("SPACE/RETURN KEY\n");
    if (Input_Len==0){
      return(IME_NOT_USED_KEY);
    }

    /* if any keys and key is Space key and mode is not keybykey */
    /* then search and display the candidates */

    if (Preedit_Len > 0){
      log_f("RETURN/SPACE key: Input_Buf:%s\n",Input_Buf);
      log_f("RETURN/SPACE key: Preedit_Buf:%s\n",Preedit_Buf);
      commit_candidate(ime_buffer, unit_table);
    }
    /* clear Preedit_Buf and Input_Buf */ 
    Preedit_Len = 0;
    Preedit_CaretPos = 0;
    Input_Len = 0;
    Input_Buf[Input_Len]='\0';
    IME_Status |= IME_PREEDIT_AREA; 
    return(IME_USED_KEY);
  }

  /* for unnormal keys 
     if (Input_Len==0) return(IME_NOT_USED_KEY);
     else return(IME_USED_KEY);
  */
  return(IME_USED_KEY);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int commit_candidate ( IMEBufferRec ime_buffer,
TableStruct unit_table 
)

Definition at line 109 of file codepoint_filter.c.

{
  char *ret;
  char tmpstr[80];
  unsigned int *from_buf;
  unsigned char *to_buf;

  esc_key_flag = 0;
  from_buf = (unsigned int *)calloc(10, sizeof(unsigned int));
  to_buf = (unsigned char *)calloc(256, sizeof(unsigned char));

  (void)memset((char *)tmpstr,'\0',sizeof(tmpstr));
  if (!Check_Input_Type(unit_table)){
    sprintf(tmpstr,"0X%s",Preedit_Buf);
  }else{
    sprintf(tmpstr,"0%s",Preedit_Buf);
  }
  from_buf[0] = (wchar_t)strtol(tmpstr,&ret, 0);
  if (from_buf[0] == IM_VK_ENTER) {
    return RETURN_KEY;
  }
  from_buf[1] = L'\0'; 
  convert_UCS4_to_UTF8(from_buf, to_buf);
  (void)strcpy((char *)Commit_Buf, (char *)to_buf);
  Commit_Len = strlen((char *)Commit_Buf);
  log_f("Inside commit_candidate, Commit_Buf <%s>\n",Commit_Buf);
  IME_Status = IME_COMMIT;
  free(from_buf);
  free(to_buf);
  return(0);
}

Here is the call graph for this function:

int convert_UCS4_to_UTF8 ( unsigned int *  from_buf,
unsigned char *  to_buf 
)

Definition at line 335 of file codepoint_filter.c.

                                                                         {
  int to_len = 0;
  unsigned char *ptr = to_buf;
                                                                                              
  if ( *from_buf <= 0x7F) {
    *ptr++ = (unsigned char) *from_buf;
    to_len++;
    from_buf++;
  } else if ( *from_buf <= 0x07FF ) {
    *ptr++= (unsigned char) ((*from_buf >> 6) | 0xC0 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F) | 0x80 );
    to_len+=2;
    from_buf++;
  } else if ( *from_buf <= 0xFFFF ) {
    *ptr++= (unsigned char) ((*from_buf >> 12) | 0xE0 );
    *ptr++= (unsigned char) ((*from_buf >> 6 & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F) | 0x80 );
    to_len+=3;
    from_buf++;
  } else if ( *from_buf <= 0x1FFFFF ) {
    *ptr++= (unsigned char) ((*from_buf >> 18) | 0xF0 );
    *ptr++= (unsigned char) (((*from_buf >> 12) & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf >> 6 & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F)| 0x80 );
    to_len+=4;
    from_buf++;
  }
  log_f("to_len [%d]\n",to_len);
  return (to_len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Is_BackSpace_Key ( TableStruct unit_table,
int  key 
)

Definition at line 89 of file codepoint_filter.c.

{
  if (key == BACKSPACE_KEY || key == DELETE_KEY)
    return(1);
  else
    return(0);
}
int Is_ClearAll_Key ( TableStruct unit_table,
int  key 
)

Definition at line 99 of file codepoint_filter.c.

{
  if (key == ESC_KEY)
    return(1);
  else
    return(0);
}
int Is_Commit_Key ( TableStruct unit_table,
int  key 
)

Definition at line 79 of file codepoint_filter.c.

{
  if (key == RETURN_KEY || key == SPACE_KEY)
    return(1);
  else
    return(0);
}
int Is_UsedCodes_Key ( TableStruct unit_table,
int  key 
)

Definition at line 69 of file codepoint_filter.c.

{
  if ( index(unit_table->UsedCodes, key) )
    return(1);
  else
    return(0);
}
int map_keyevent_to_imekey ( TableStruct unit_table,
IMEKey  key_event 
)

Definition at line 273 of file codepoint_filter.c.

{
  int keycode, keystatus, keychar;

  keycode = key_event->keyCode;
  keychar = key_event->keyChar;
  keystatus = key_event->modifier;

  log_f("codepoint_filter: keycode: 0x%x, keychar:0x%x, keystatus: 0x%x\n", keycode, keychar, keystatus);
  /* normal status */
  if (keystatus  == 0) {
    /* Function Keys */
    if (keychar == 0) {
      log_f(" Function Key :%d\n", keycode);
      switch (keycode) {
      case IM_VK_ESCAPE:
       return(ESC_KEY);

      case IM_VK_BACK_SPACE:
       return(BACKSPACE_KEY);

      case IM_VK_ENTER:
       return(RETURN_KEY);

      case IM_VK_INSERT:
       return(INSERT_KEY);

      case IM_VK_DELETE:
       return(DELETE_KEY);

      case IM_VK_HOME:
       return(HOME_KEY);

      case IM_VK_END:
       return(END_KEY);

      case IM_VK_PAGE_UP:
       return(PAGEUP_KEY);

      case IM_VK_PAGE_DOWN:
       return(PAGEDOWN_KEY);

      }
      return(IME_NOT_USED_KEY);
    } else {
      /*  normal key  */
      log_f("codepoint_filter:  Normal Key :0x%x, %c\n", keychar, keychar);
      return(keychar);
    }
  }

  /*  Shift status */
  if (keystatus == IM_SHIFT_MASK) {
    if (keychar != 0) {
      /*  normal key  */
      log_f("codepoint_filter:  Ascii Key :0x%x, %c\n", keychar, keychar);
      return(keychar);
    }
  }
  return (IME_NOT_USED_KEY);
}

Here is the caller graph for this function:

void warning_bell ( )

Definition at line 143 of file codepoint_filter.c.

{
}