Back to index

im-sdk  12.3.91
Defines | Functions | Variables
ctim.c File Reference
#include <stdio.h>
#include "unit_input.h"
#include "codetable.h"
#include "logf.h"
#include "ctim.h"

Go to the source code of this file.

Defines

#define SUFFIX_DICT_FILE   ".data"

Functions

int codetable_filter (CodeTableStruct *hztbl, IMEKey key_event, IMEBufferRec *ime_buffer)
int ctim_SetOptions (IMECore, char *)
int ctim_SetValues (IMECore, IMEArgList, int)
int ctim_Init (IMECore)
int ctim_Open (IMECore, IMEBuffer, void *handler)
int ctim_Filter (IMECore, IMEKey, IMEArgList, IMEBuffer)
void ctim_Close (IMECore)

Variables

IMEMethodsRec ime_methods

Define Documentation

#define SUFFIX_DICT_FILE   ".data"

Definition at line 87 of file ctim.c.


Function Documentation

int codetable_filter ( CodeTableStruct hztbl,
IMEKey  key_event,
IMEBufferRec ime_buffer 
)

Definition at line 244 of file ctfilter.c.

{
  int     hznum;
  char    ch;
  int     key, pos;
  int nLookup_Pos_Save = 0;
  int  bNeedCheckMore = 0;
 
  int  Max_Lookup_Num = LOOKUP_CHOICE_NUM;
  int  nKeyByKeyMode = hztbl->nKeyByKeyMode;
  int  nHelpInfoMode = hztbl->nHelpInfoMode;
  int  nAutoSelectMode = hztbl->nAutoSelectMode;
  int  nKeyPromptMode = hztbl->nKeyPromptMode;
  int prev_Input_Len;
  static int static_prev_Input_Buf[MAX_INPUT_KEY_NUM];
  int *prev_Input_Buf = static_prev_Input_Buf;
 
  ime_buffer->encode = hztbl->Encode;

  IME_Status = 0;

  key = map_keyevent_to_imekey(hztbl, key_event);
  log_f("ctfilter: map_keyevent_to_imekey: return key:0x%x\n", key);
 
  if (key == IME_NOT_USED_KEY)
    return(IME_NOT_USED_KEY);
 
  switch(hztbl->nSelectKeyMode) {
  case NUMBER_MODE:
    ime_buffer->lookup_label_type = NUMERIC_LABEL;
    break;
  case LOWER_MODE:
    ime_buffer->lookup_label_type = LOWER_LABEL;
    break;
  case UPPER_MODE:
    ime_buffer->lookup_label_type = UPPER_LABEL;
    break;
  default:
    ime_buffer->lookup_label_type = NUMERIC_LABEL;
  }

  if((Is_UsedCodes_Key(hztbl, key)) || (Is_Wildchar_Key(hztbl, key))) { 
    prev_Input_Buf = Input_Buf;
    prev_Input_Len = Input_Len;

    /* if inputted keys length has over the limit */
          
    if (Input_Len >= hztbl->MaxCodes) {
      warning_bell();
      return (IME_USED_KEY);
    }

    /* if not key by key, and is selectkey, and Lookup Mode */
    /* directly select */

    if(!nKeyByKeyMode && (Is_Select_Key(hztbl, key)) && (Lookup_Num>0)) { 

      /* select from candidata */
      /* here should see whether there is enough candidates */

      int select_num;
      select_num = get_select_num(hztbl, key);
      if ((select_num >= 0) && (select_num < Lookup_Num)) {
        commit_candidate(ime_buffer, select_num);
      }else warning_bell();

      return(IME_USED_KEY);
    }

    Input_Buf[Input_Len] = key;
    Input_Len ++;
    Input_Buf[Input_Len] = '\0';

    Lookup_Num = 0;
    bNeedCheckMore = 0;
    /* if need display key by key */
    if (nKeyByKeyMode) {
      nLookup_Pos_Save = Lookup_Pos;
      Lookup_Pos = 0;
      Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
      if (Lookup_Num == 1 && nAutoSelectMode) {
        commit_candidate(ime_buffer, 0);
        return(IME_USED_KEY);
      }

      if (Lookup_Num == 0) {
        log_f("Lookup_Num is zero \n"); 
        /* if key is also a seleck key */
        if (Is_Select_Key(hztbl, key))
          bNeedCheckMore = 1;
        else {
          Input_Buf = prev_Input_Buf;
          Input_Len = prev_Input_Len;
          if (Input_Len == 0) {
            Commit_Len = 0;
            Commit_Buf[Commit_Len] = key;
            Commit_Len++;
            Commit_Buf[Commit_Len] = '\0';
            Commit_Len = strlen((char *)Commit_Buf);
            log_f("codetable_filter: commit_candidate, Commit_Buf <%s>\n",Commit_Buf);
            IME_Status = IME_COMMIT;
            Input_Len = 0;
            Input_Buf[Input_Len] = 0;
            Preedit_Len = 0;
            Preedit_Buf[Preedit_Len] = '\0';
            IME_Status |= IME_PREEDIT_AREA | IME_LOOKUP_AREA;
            return(IME_NOT_USED_KEY);
          }
          nLookup_Pos_Save = Lookup_Pos;
          Lookup_Pos = 0;
          Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
          commit_candidate(ime_buffer, 0);
          Input_Buf[Input_Len] = key;
          Input_Len ++;
          Input_Buf[Input_Len] = '\0';
          Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num);
          if (bNeedCheckMore == 0) {
            Preedit_Buf[Preedit_Len] = key;
            Preedit_Len += 1;
            Preedit_Buf[Preedit_Len] = '\0';
            Preedit_CaretPos = Preedit_Len;
            return(IME_USED_KEY);
          }
        }
      }
      log_f("prev_Input_Len [%d], Input_Len [%d]\n",prev_Input_Len, Input_Len);
      if (prev_Input_Len != Input_Len) {
       Preedit_Buf[Preedit_Len] = key;
       Preedit_Len += 1;
       Preedit_Buf[Preedit_Len] = '\0';
      }
    }else{
      Preedit_Buf[Preedit_Len] = key;
      Preedit_Len += 1;
      Preedit_Buf[Preedit_Len] = '\0';
    }
    Preedit_CaretPos = Preedit_Len;
    IME_Status = IME_PREEDIT_AREA;

    if (bNeedCheckMore == 0) {
      IME_Status |= IME_LOOKUP_AREA;
      return(IME_USED_KEY);
    }
  }
  
  if (bNeedCheckMore == 1) {
    /* restore the original status that before into this function */
    IME_Status = 0;
    Input_Len --;
    Input_Buf[Input_Len] = '\0';
    Lookup_Pos = nLookup_Pos_Save;
    Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
  }

  if (Is_Select_Key(hztbl, key)) { /* select from candidata */
    /* here should see whether there is enough candidates */
    int select_num;

    /*  if no inputted key, directly return this key */
    if (Input_Len==0) return(IME_NOT_USED_KEY);
    log_f("Select Key, key:%c, Lookup_Num:%d\n", key, Lookup_Num);
    select_num = get_select_num(hztbl, key);
    if (Lookup_Num>0 && (select_num >= 0) && (select_num < Lookup_Num)) {
      commit_candidate(ime_buffer, select_num);
    } else warning_bell();

    return(IME_USED_KEY);
  }

  if (Is_ClearAll_Key(hztbl, key)) { 
    /* Esc , clear preedit, lookup choice pointer, and so on */
    log_f("ESC_KEY\n");
    /*  if no inputted key, directly return this key */
    if (Input_Len==0) return(IME_NOT_USED_KEY);
  
    Input_Len = 0;
    Preedit_Len = 0;
    Lookup_Num = 0;
    Preedit_CaretPos = 0;
    IME_Status = IME_PREEDIT_AREA | IME_LOOKUP_AREA;
    return (IME_USED_KEY);
  }

  if (Is_BackSpace_Key(hztbl, key)) { /* Back Space & Delete */
    log_f("BACKSPACE_KEY\n");
    /*  if no inputted key, directly return this key */
    if (Input_Len==0) return(IME_NOT_USED_KEY);
  
    /* Delete characters in pre-edit region */
    Input_Len --;
    if (nKeyPromptMode) {
      ch = Input_Buf[Input_Len];
      log_f("ch:%c, keyprompt:%s\n", ch, hztbl->keyprompt[atoi(&ch)].prompt);
      Preedit_Len -= strlen(hztbl->keyprompt[atoi(&ch)].prompt);
      Preedit_Buf[Preedit_Len] = '\0';
    }else{
      Preedit_Len -= 1;
      Preedit_Buf[Preedit_Len] = '\0';
    }

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

    Lookup_Num = 0;
  
    /* if still left some keys, and need display key by key, then search. */
    /* else undisplay the candidate window */
    if ((Input_Len > 0) && nKeyByKeyMode) {
      Lookup_Pos = 0;
      Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
    }

    IME_Status |= IME_LOOKUP_AREA;
    return(IME_USED_KEY);

  }

  if (Is_NextPage_Key(hztbl, key)) { /* select from candidata */
    /*  if no inputted key, directly return this key */
    if (Input_Len==0) return(IME_NOT_USED_KEY);

    /* if any preedit key and not in Lookup status */
    log_f("NextPage:  Lookup_Num:%d\n", Lookup_Num);
    if (Lookup_Num==0) return(IME_USED_KEY);

    pos = Lookup_Pos + Max_Lookup_Num;
    log_f("NextPage: pos:%d\n", pos);
    hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookup_Num); 
    if (hznum > 0) {
      Lookup_Num = hznum;
      Lookup_Pos = pos;
      IME_Status = IME_LOOKUP_AREA;
    }else warning_bell();
    
    return(IME_USED_KEY);

  }

  if (Is_PrevPage_Key(hztbl, key)) { /* select from candidata */

    /*  if no inputted key, directly return this key */
    if (Input_Len==0) return(IME_NOT_USED_KEY);
    log_f("PrevPage:  Lookup_Num:%d\n", Lookup_Num);
    /* if any preedit key and not in Lookup status */
    if (Lookup_Num==0) return(IME_USED_KEY);
  
    /* if in beginning pos */
    if (Lookup_Pos<=0) {
      warning_bell();
      return(IME_USED_KEY);
    }

    pos = Lookup_Pos - Max_Lookup_Num;
    hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookup_Num); 
    log_f("hznum :%d\n", hznum);
    if (hznum > 0) {
      Lookup_Num = hznum;
      Lookup_Pos = pos;
      IME_Status = IME_LOOKUP_AREA;
    }else warning_bell();

    return(IME_USED_KEY);
  }

  if (Is_Commit_Key(hztbl, key)) { /* space or return key */
    log_f("Space or Return key, Commit Key ===\n");
    /* if no input keys and no candidates */
    if (Input_Len==0 && Lookup_Num==0) 
      return(IME_NOT_USED_KEY);

    /* if any candidates, then commit the first candidate */
    if (Lookup_Num > 0) {
      log_f("Commit Key , Commit the first candidate===\n");
      commit_candidate(ime_buffer, 0);
      return(IME_USED_KEY);
    }

    /* if any keys and key is Space key and mode is not keybykey */
    /* then search and display the candidates */
    if (key == SPACE_KEY && !nKeyByKeyMode) {
      Lookup_Pos = 0;
      Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
      log_f("Lookup_Num:%d\n", Lookup_Num);
      if (Lookup_Num == 1 && nAutoSelectMode) {
        commit_candidate(ime_buffer, 0);
        return(IME_USED_KEY);
      }

      if (Lookup_Num == 0)
        warning_bell();

      IME_Status = IME_LOOKUP_AREA;
      return(IME_USED_KEY);
    }

    return(IME_USED_KEY);
  }

  /* for unnormal keys */
  log_f(" unnormal key:%d\n", key);
  if (Input_Len==0) return(IME_NOT_USED_KEY);
  else return(IME_USED_KEY);
}
void ctim_Close ( IMECore  core)

Definition at line 245 of file ctim.c.

{
  CodeTableStruct *ctHeader;
  int         i;

  log_f("ctim_Close ==== \n");

  ctHeader = (CodeTableStruct *)(core->envinfo.data_ptr);
  UnloadCodeTable(ctHeader);
  free((char *)ctHeader);
  if (core->baseinfo.lname)
    free((char *)core->baseinfo.lname);
  if (core->baseinfo.cname)
    free((char *)core->baseinfo.cname);

  if (core->envinfo.data_path)
    free((char *)core->envinfo.data_path);

  if (core->keymapinfo.bSet == 1) {
    for (i=0; i<MAX_KEYMAP_KEY_NUM; i++) {
      if (core->keymapinfo.keymap[i])
       free((char *)core->keymapinfo.keymap[i]);
    }
  }
}

Here is the call graph for this function:

int ctim_Filter ( IMECore  core,
IMEKey  key_event,
IMEArgList  ime_args,
IMEBuffer  ime_buffer 
)

Definition at line 274 of file ctim.c.

{
  int         ret;
  CodeTableStruct *ctHeader;

  log_f("ctim_Filter ==== \n");

  if (core->baseinfo.status != ENGINE_INITIATED)
    return(IME_NOT_USED_KEY);
              
  /* set ctHeader's argument setting */
       
  /* ctHeader's argument setting are always coveried by user defined data */
  ctHeader = (CodeTableStruct *)(core->envinfo.data_ptr);
  ctHeader->Output_Encode = core->envinfo.output_encode_id;

  /* if no user defined arguments, set with system arguments */
  ctHeader->nKeyByKeyMode = core->argsinfo.args[KEYBYKEY_MODE_ID].value;
  ctHeader->nHelpInfoMode = core->argsinfo.args[HELPINFO_MODE_ID].value;
  ctHeader->nAutoSelectMode = core->argsinfo.args[AUTOSELECT_MODE_ID].value;
  ctHeader->nKeyPromptMode = core->argsinfo.args[KEYPROMPT_MODE_ID].value;

  if (ime_args != NULL && ime_args->args_num > 0) {
    /* if has user defined arguments, set with user defined arguments */
    ctHeader->nKeyByKeyMode = ime_args->args[KEYBYKEY_MODE_ID].value;
    ctHeader->nHelpInfoMode = ime_args->args[HELPINFO_MODE_ID].value;
    ctHeader->nAutoSelectMode = ime_args->args[AUTOSELECT_MODE_ID].value;
    ctHeader->nKeyPromptMode = ime_args->args[KEYPROMPT_MODE_ID].value;
  }
              
  ret = codetable_filter(ctHeader, key_event, ime_buffer);
  log_f("codetable_filter : return: %d\n", ret);
  return(ret);
}

Here is the call graph for this function:

int ctim_Init ( IMECore  core)

Definition at line 141 of file ctim.c.

{
  int                i, ret;
  char        *file_name;
  CodeTableStruct ctHeader;

  log_f("ctim_Init ====\n");

  /* read table from file to memory buffer  */
  file_name = core->envinfo.data_path;
  log_f("file name :%s\n",file_name);

  ret = LoadCodeTableHeader(file_name, &ctHeader); 
  if (ret == -1) 
    return (-1);

  /* Return Information that needed by Input Method Manager */
  /* Such as Encode, Cname, Status */
  core->baseinfo.status = ENGINE_NOT_INITIATED;
  core->baseinfo.lname = (char *)strdup(ctHeader.Lname);
  core->baseinfo.cname = (char *)strdup(ctHeader.Cname);
  core->baseinfo.encode_id = ctHeader.Encode;
       
  core->argsinfo.args_num = CTIM_ARGS_NUM;
  i = KEYBYKEY_MODE_ID;
  core->argsinfo.args[i].name = NULL;
  core->argsinfo.args[i].value = ctHeader.nKeyByKeyMode;
  i = HELPINFO_MODE_ID;
  core->argsinfo.args[i].name = NULL;
  core->argsinfo.args[i].value = ctHeader.nHelpInfoMode;
  i = AUTOSELECT_MODE_ID;
  core->argsinfo.args[i].name = NULL;
  core->argsinfo.args[i].value = ctHeader.nAutoSelectMode;
  i = KEYPROMPT_MODE_ID;
  core->argsinfo.args[i].name = NULL;
  core->argsinfo.args[i].value = ctHeader.nKeyPromptMode;

  return(0);
}

Here is the call graph for this function:

int ctim_Open ( IMECore  core,
IMEBuffer  ime_buffer,
void *  handler 
)

Definition at line 183 of file ctim.c.

{
  char        *file_name;
  int         i, ret;

  CodeTableStruct *ctHeader;

  log_f("ctim_Open ==== \n");

  ime_buffer->encode = 0;
  ime_buffer->return_status = 0;
  ime_buffer->preedit_len = 0;
  ime_buffer->commit_len  = 0;
  ime_buffer->lookup_num  = 0;
  ime_buffer->inputkey_len  = 0;
  ime_buffer->cur_lookup_pos = 0;

  if (core->baseinfo.status == ENGINE_NOT_INSTALLED)
    return(-1);

  if (core->baseinfo.status == ENGINE_INITIATED)
    return 0;

  /* if IME engine is not initiated, would malloc dictionary buffer */

  core->baseinfo.status = ENGINE_NOT_INSTALLED;

  /* read table from file to memory buffer  */
  file_name = core->envinfo.data_path;
  log_f("file name :%s\n",file_name);

  ctHeader = (CodeTableStruct *)calloc(1, sizeof(CodeTableStruct));
  if (ctHeader == NULL) {
    fprintf(stderr, "no memory for CodeTable Input method: %s\n",core->baseinfo.ename);
    return(-1);
  }

  ret = LoadCodeTable(file_name, ctHeader); 
  if (ret == -1) {
    UnloadCodeTable(ctHeader);
    free((char *)ctHeader);
    return(-1);
  }

  core->baseinfo.status = ENGINE_INITIATED;
  core->envinfo.data_ptr = (char *)ctHeader;

  /* if exist keymap setting */
  if (GETBIT(ctHeader->bSectionsFlag, KEYPROMPT_SECTION)) {
    core->keymapinfo.bSet = 1;
    for (i=0; i<MAX_KEYMAP_KEY_NUM; i++) {
      core->keymapinfo.keymap[i] = (char *) strdup(ctHeader->keyprompt[i+0x20].prompt);
      /*
       log_f("keymap: %d\t%s\n", i, core->keymapinfo.keymap[i]);
      */
    }
  }

  return(0);
}

Here is the call graph for this function:

int ctim_SetOptions ( IMECore  core,
char *  options 
)

Definition at line 90 of file ctim.c.

{
  char        data_path[256];

  sprintf(data_path, "%s/%s/%s/%s/%s%s", DEFAULT_ENGINE_PATH, core->envinfo.lang_name, options, DEFAULT_DICT_PATH, core->baseinfo.ename, SUFFIX_DICT_FILE);
  core->envinfo.data_path = (char *)strdup(data_path);

  log_f("data_path :%s\n", core->envinfo.data_path);
  return (0);
}

Here is the call graph for this function:

int ctim_SetValues ( IMECore  core,
IMEArgList  arglist,
int  option_value 
)

Definition at line 101 of file ctim.c.

{
  int i;

  log_f("ctim_SetValues === \n");

  if (arglist == NULL) return(-1);

  arglist->args_num = 0;

  if (option_value == -1) {
    int              ret;
    char             *file_name;
    CodeTableStruct ctHeader;

    /* read table from file to memory buffer  */
    file_name = core->envinfo.data_path;
    log_f("LoadCodeTableHeader: file_name:%s\n", file_name);
    ret = LoadCodeTableHeader(file_name, &ctHeader); 
    if (ret != -1) {
      i = KEYBYKEY_MODE_ID;
      arglist->args[i].value = ctHeader.nKeyByKeyMode;
      i = HELPINFO_MODE_ID;
      arglist->args[i].value = ctHeader.nHelpInfoMode;
      i = AUTOSELECT_MODE_ID;
      arglist->args[i].value = ctHeader.nAutoSelectMode;
      i = KEYPROMPT_MODE_ID;
      arglist->args[i].value = ctHeader.nKeyPromptMode;
    }

  } else {
    for (i = 0; i < CTIM_ARGS_NUM; i++) {
      arglist->args[i].value = (option_value >> i) & 1; 
    }
  }

  return(0);
}

Here is the call graph for this function:


Variable Documentation

Initial value:

Definition at line 78 of file ctim.c.