Back to index

im-sdk  12.3.91
Defines | Functions
array_filter.c File Reference
#include <stdio.h>
#include "ctim.h"
#include "array_data.h"

Go to the source code of this file.

Defines

#define LOOKUP_CHOICE_NUM   6
#define IME_Status   ime_buffer->return_status
#define Input_Buf   ime_buffer->input_buf
#define Input_Len   ime_buffer->input_len
#define Preedit_Buf   ime_buffer->preedit_buf
#define Preedit_Len   ime_buffer->preedit_len
#define Preedit_CaretPos   ime_buffer->preedit_caretpos
#define Commit_Buf   ime_buffer->commit_buf
#define Commit_Len   ime_buffer->commit_len
#define Status_Buf   ime_buffer->status_buf
#define Status_Len   ime_buffer->status_len
#define Lookups_Num   ime_buffer->num_candidates
#define Lookup_Pos   ime_buffer->cur_lookup_pos
#define Candidates   ime_buffer->candidates
#define Comments   ime_buffer->comments
#define Lookups   ime_buffer->lookups
#define Page_State   ime_buffer->page_state

Functions

int Is_UsedCodes_Key (CodeTableStruct *hztbl, int key)
int get_select_num (CodeTableStruct *hztbl, int key)
int Is_Select_Key (CodeTableStruct *hztbl, int key)
int Is_Space_Key (CodeTableStruct *hztbl, int key)
int Is_Return_Key (CodeTableStruct *hztbl, int key)
int Is_BackSpace_Key (CodeTableStruct *hztbl, int key)
int Is_ClearAll_Key (CodeTableStruct *hztbl, int key)
int Is_NextPage_Key (CodeTableStruct *hztbl, int key)
int Is_PrevPage_Key (CodeTableStruct *hztbl, int key)
int get_lookup_result (CodeTableStruct *hztbl, ImeBufferRec *ime_buffer, int nHelpInfoMode, int pos, int max_lookup_num)
int Commit_And_Clean_All_Area (ImeBufferRec *ime_buffer)
int Clean_All_Area (ImeBufferRec *ime_buffer)
int commit_candidate (ImeBufferRec *ime_buffer, int id)
void warning_bell (ImeBufferRec *ime_buffer)
int If_Has_WildChar (char *input_str)
int get_high_frequence_characters (CodeTableStruct *hztbl, ImeBufferRec *ime_buffer)
int get_symbol_characters (CodeTableStruct *hztbl, ImeBufferRec *ime_buffer, int symbol_area_id, int pos, int max_lookup_num)
int ctim_filter (CodeTableStruct *hztbl, unsigned char key, ImeBufferRec *ime_buffer)

Define Documentation

#define Candidates   ime_buffer->candidates

Definition at line 19 of file array_filter.c.

#define Comments   ime_buffer->comments

Definition at line 20 of file array_filter.c.

#define Commit_Buf   ime_buffer->commit_buf

Definition at line 13 of file array_filter.c.

#define Commit_Len   ime_buffer->commit_len

Definition at line 14 of file array_filter.c.

#define IME_Status   ime_buffer->return_status

Definition at line 7 of file array_filter.c.

#define Input_Buf   ime_buffer->input_buf

Definition at line 8 of file array_filter.c.

#define Input_Len   ime_buffer->input_len

Definition at line 9 of file array_filter.c.

#define LOOKUP_CHOICE_NUM   6

Definition at line 5 of file array_filter.c.

#define Lookup_Pos   ime_buffer->cur_lookup_pos

Definition at line 18 of file array_filter.c.

#define Lookups   ime_buffer->lookups

Definition at line 21 of file array_filter.c.

#define Lookups_Num   ime_buffer->num_candidates

Definition at line 17 of file array_filter.c.

#define Page_State   ime_buffer->page_state

Definition at line 22 of file array_filter.c.

#define Preedit_Buf   ime_buffer->preedit_buf

Definition at line 10 of file array_filter.c.

#define Preedit_CaretPos   ime_buffer->preedit_caretpos

Definition at line 12 of file array_filter.c.

#define Preedit_Len   ime_buffer->preedit_len

Definition at line 11 of file array_filter.c.

#define Status_Buf   ime_buffer->status_buf

Definition at line 15 of file array_filter.c.

#define Status_Len   ime_buffer->status_len

Definition at line 16 of file array_filter.c.


Function Documentation

int Clean_All_Area ( ImeBufferRec ime_buffer)
int Commit_And_Clean_All_Area ( ImeBufferRec ime_buffer)
int commit_candidate ( ImeBufferRec ime_buffer,
int  id 
)

Definition at line 196 of file array_filter.c.

{
       if (id >= Lookups_Num)
              return(-1);

       strcpy((char *)Commit_Buf, (char *)Candidates[id]);
       Commit_Len = strlen((char *)Commit_Buf);
       Commit_And_Clean_All_Area(ime_buffer);

       return(0);
}

Here is the call graph for this function:

int ctim_filter ( CodeTableStruct hztbl,
unsigned char  key,
ImeBufferRec ime_buffer 
)

Definition at line 308 of file array_filter.c.

{
       char    ch;
       int     i, k, hznum;
       int     pos, select_num;
       int    bHasWildChar, symbol_area_id;

       int    Max_Lookups_Num = LOOKUP_CHOICE_NUM;
       int     Max_Symbols_Lookups_Num = 10;
       int    nHelpInfoMode = hztbl->nHelpInfoMode;
       int    nAutoSelectMode = hztbl->nAutoSelectMode;
       int    nKeyPromptMode = hztbl->nKeyPromptMode;

       ime_buffer->encoding = hztbl->Encode;

       IME_Status = 0;

/*
       ime_buffer->lookup_label_type = NUMERIC_LABEL;
*/
       bHasWildChar = If_Has_WildChar(Input_Buf);

       if ((key >= '0' && key <= '9') && (Input_Len == 1) && (toupper(Input_Buf[0]) == 'W')) {
              /* "W1": Process Symbol Input */
              symbol_area_id = key - '0';
              Lookups_Num = get_symbol_characters(hztbl, ime_buffer, symbol_area_id, 0, Max_Symbols_Lookups_Num); 

              Input_Buf[1] = key;
              Input_Len = 0;
              Preedit_Len = 0;
              Preedit_CaretPos = 0;
              IME_Status = IME_PREEDIT_AREA | IME_LOOKUP_AREA;

              return(IME_OK);
       }

       if(Is_Select_Key(hztbl, key)) {
              if (Lookups_Num > 0) {
                     select_num = get_select_num(hztbl, key);
                     if (select_num >= 0 && select_num < Lookups_Num) {
                            commit_candidate(ime_buffer, select_num);
                     } else {
                            warning_bell(ime_buffer);
                     }
                     return(IME_OK);
              }
       }

       if((Is_UsedCodes_Key(hztbl, key)) || (Is_Wildchar_Key(hztbl, key))) { 
              /* if inputted keys length has over the limit */
              if (Input_Len >= hztbl->MaxCodes) {
                     return(IME_OK);
              }

              if (Lookups_Num > 0 && Lookups_Num < 10 && Input_Len <= 2) {
                     strcpy((char *)Commit_Buf, (char *)Candidates[0]);
                        Commit_Len = strlen((char *)Commit_Buf);
                        Commit_And_Clean_All_Area(ime_buffer);
              }

              Input_Buf[Input_Len] = key;
              Input_Len ++;
              Input_Buf[Input_Len] = '\0';
              
              if (nKeyPromptMode) {
                     strcpy(Preedit_Buf+Preedit_Len, hztbl->keyprompt[key].prompt);
                     Preedit_Len += strlen(hztbl->keyprompt[key].prompt);
                     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;

              Lookups_Num = 0;
              if (!bHasWildChar && (Input_Len == 1 || Input_Len == 2)) {
                     Lookups_Num = get_high_frequence_characters(hztbl, ime_buffer);
              } else {
                     Lookup_Pos = 0;
                     Lookups_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookups_Num); 
              }
              IME_Status |= IME_LOOKUP_AREA;
              return(IME_OK);
       }

       if(Is_ClearAll_Key(hztbl, key)) { 
              /* Esc , clear preedit area, lookup choice area */

              /*  if no inputted key, directly return this key */
              if (Lookups_Num == 0 && Input_Len==0) return(IME_UNUSED_KEY);

              Clean_All_Area(ime_buffer);
              return (IME_OK);
       }

       if (Is_BackSpace_Key(hztbl, key)) { /* Back Space & Delete */
              /*  if no inputted key, directly return this key */
              if (Input_Len==0) return(IME_UNUSED_KEY);

              /* Delete characters in pre-edit region */
              Input_Len --;
              if (nKeyPromptMode) {
                     ch = Input_Buf[Input_Len];
                     Preedit_Len -= strlen(hztbl->keyprompt[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;

              Lookups_Num = 0;
              if (Input_Len > 0) {
                     if (!bHasWildChar && (Input_Len == 1 || Input_Len == 2)) {
                            Lookups_Num = get_high_frequence_characters(hztbl, ime_buffer);
                     } else {
                            Lookup_Pos = 0;
                            Lookups_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookups_Num); 
                     }
              }
              IME_Status |= IME_LOOKUP_AREA;
              return(IME_OK);

       }

       if(Is_NextPage_Key(hztbl, key)) {
              if ((toupper(Input_Buf[0]) == 'W') && (Input_Buf[1] >= '0' && Input_Buf[1] <= '9')) {
                     int symbol_area_id = Input_Buf[1] - '0';

                     pos = Lookup_Pos + Max_Symbols_Lookups_Num;
                     hznum = get_symbol_characters(hztbl, ime_buffer, symbol_area_id, pos, Max_Symbols_Lookups_Num); 
                     if (hznum > 0) {
                            Lookups_Num = hznum;
                            Lookup_Pos = pos;
                            IME_Status = IME_LOOKUP_AREA;
                     } else {
                                   warning_bell(ime_buffer);
                     }

                     return(IME_OK);
              }

              /*  if no inputted key, directly return this key */
              if (Input_Len==0) return(IME_UNUSED_KEY);

              /* if any preedit key and not in Lookup status */
              if (Lookups_Num==0) return(IME_OK);

              if (!bHasWildChar && (Input_Len == 1 || Input_Len == 2)) {
                     return(IME_OK);
              }

              pos = Lookup_Pos + Max_Lookups_Num;
              hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookups_Num); 
              if (hznum > 0) {
                     Lookups_Num = hznum;
                     Lookup_Pos = pos;
                     IME_Status = IME_LOOKUP_AREA;
              } else {
                            warning_bell(ime_buffer);
              }

              return(IME_OK);
       }

       if(Is_PrevPage_Key(hztbl, key)) {
              if ((toupper(Input_Buf[0]) == 'W') && (Input_Buf[1] >= '0' && Input_Buf[1] <= '9')) {
                     int symbol_area_id = Input_Buf[1] - '0';

                     /* if in beginning pos */
                     if (Lookup_Pos<=0) {
                                   warning_bell(ime_buffer);
                            return(IME_OK);
                     }

                     pos = Lookup_Pos - Max_Symbols_Lookups_Num;
                     hznum = get_symbol_characters(hztbl, ime_buffer, symbol_area_id, pos, Max_Symbols_Lookups_Num); 
                     if (hznum > 0) {
                            Lookups_Num = hznum;
                            Lookup_Pos = pos;
                            IME_Status = IME_LOOKUP_AREA;
                     } else {
                                   warning_bell(ime_buffer);
                     }
       
                     return(IME_OK);
              }

              /*  if no inputted key, directly return this key */
              if (Input_Len==0) return(IME_UNUSED_KEY);

              /* if any preedit key and not in Lookup status */
              if (Lookups_Num==0) return(IME_OK);

              if (!bHasWildChar && (Input_Len == 1 || Input_Len == 2)) {
                     return(IME_OK);
              }

              /* if in beginning pos */
              if (Lookup_Pos<=0) {
                            warning_bell(ime_buffer);
                     return(IME_OK);
              }

              pos = Lookup_Pos - Max_Lookups_Num;
              hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookups_Num); 
              if (hznum > 0) {
                     Lookups_Num = hznum;
                     Lookup_Pos = pos;
                     IME_Status = IME_LOOKUP_AREA;
              } else {
                            warning_bell(ime_buffer);
              }

              return(IME_OK);
       }

       if(Is_Return_Key(hztbl, key)) { 
              /* Esc , clear preedit area, lookup choice area */

              /*  if no inputted key, directly return this key */
              if (Lookups_Num == 0 && Input_Len==0) return(IME_UNUSED_KEY);

              if ((toupper(Input_Buf[0]) == 'W') && (Input_Buf[1] >= '0' && Input_Buf[1] <= '9')) {
                     return(IME_UNUSED_KEY);
              }

              Clean_All_Area(ime_buffer);
              return (IME_OK);
       }

       if(Is_Space_Key(hztbl, key)) {
              /* if no input keys and no candidates */
              if (Input_Len == 0 && Lookups_Num == 0) 
                     return(IME_UNUSED_KEY);

              if ((toupper(Input_Buf[0]) == 'W') && (Input_Buf[1] >= '0' && Input_Buf[1] <= '9')) {
                     int symbol_area_id = Input_Buf[1] - '0';

                     pos = Lookup_Pos + Max_Symbols_Lookups_Num;
                     hznum = get_symbol_characters(hztbl, ime_buffer, symbol_area_id, pos, Max_Symbols_Lookups_Num); 
                     if (hznum > 0) {
                            Lookups_Num = hznum;
                            Lookup_Pos = pos;
                     } else {
                            Lookups_Num = get_symbol_characters(hztbl, ime_buffer, symbol_area_id, 0, Max_Symbols_Lookups_Num); 
                            Lookup_Pos = 0;
                     }
                     IME_Status = IME_LOOKUP_AREA;

                     return(IME_OK);
              }

              /* if any candidates, then commit the first candidate */
              if (Lookups_Num > 0 && Lookups_Num < 10) {
                     commit_candidate(ime_buffer, 0);
                     return(IME_OK);
              }

              /* if any keys and key is Space key and mode is not keybykey */
              /* then search and display the candidates */
              Lookup_Pos = 0;
              Lookups_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookups_Num); 
              if (Lookups_Num == 1) {
                     commit_candidate(ime_buffer, 0);
                     return(IME_OK);
              } else if (Lookups_Num == 0) {
                     warning_bell(ime_buffer);
              }

              IME_Status = IME_LOOKUP_AREA;
              return(IME_OK);
       }

       /* for unnormal keys */
       if (Lookups_Num > 0) {
              /* need commit the first candidate */
              strcpy((char *)Commit_Buf, (char *)Candidates[0]);
              Commit_Len = strlen((char *)Commit_Buf);
              Commit_And_Clean_All_Area(ime_buffer);
       }

        return(IME_UNUSED_KEY);
}

Here is the call graph for this function:

int get_high_frequence_characters ( CodeTableStruct hztbl,
ImeBufferRec ime_buffer 
)

Definition at line 225 of file array_filter.c.

{
       int i;
       int high_char_pos = 0;
       int found = 0;

       Page_State = ImeCandidatesFirstPage | ImeCandidatesLastPage;

       while(high_char_pos <= 930) {
              if (!strcasecmp(highword[high_char_pos][0], Input_Buf))  {
                     found = 1;
                     break;
              }
              high_char_pos ++;
       }
       if (found) {
              for (i=0; i<10; i++) {
                     char *hw_str = highword[high_char_pos][i+1];
                     if (hztbl->Encode == ENCODE_UTF8) {
                            strcpy(Candidates[i], hw_str);
                            strcpy(Lookups[i], hw_str);
                     } else {
                            char *ip, *op, buffer[128];
                            int ileft, oleft;

                            ip = (char *)hw_str;
                            ileft = strlen(hw_str);
                            op = buffer;
                            oleft = 128;
                            memset(buffer, 0, 128);
                            Convert_UTF8_To_Native(hztbl->Encode, ip, ileft, &op, &oleft);
                            strcpy(Candidates[i], buffer);
                            strcpy(Lookups[i], buffer);
                     }
              }
              return(10);
       }

       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int get_lookup_result ( CodeTableStruct hztbl,
ImeBufferRec ime_buffer,
int  nHelpInfoMode,
int  pos,
int  max_lookup_num 
)

Definition at line 149 of file array_filter.c.

{
       int i, lookup_num;

       lookup_num = codetable_search(hztbl, Input_Buf, Candidates, Comments, pos, max_lookup_num + 1); 
       if (lookup_num > 0) {
              Page_State = 0;
              if (pos == 0)
                     Page_State |= ImeCandidatesFirstPage;
              if (lookup_num < max_lookup_num + 1)
                     Page_State |= ImeCandidatesLastPage;
              if (lookup_num == max_lookup_num + 1)
                     lookup_num = max_lookup_num;

              for (i=0; i<lookup_num; i++) {
                     DEBUG_printf("%d: %s %s\n", i, Candidates[i], Comments[i]);
                     if (nHelpInfoMode)
                            snprintf((char *)Lookups[i], MAX_CANDIDATE_CHAR_NUM, "%s %s",
                                    Candidates[i], Comments[i]);
                     else
                            strcpy(Lookups[i], Candidates[i]);
              }
       }

       return(lookup_num);

}

Here is the call graph for this function:

int get_select_num ( CodeTableStruct hztbl,
int  key 
)

Definition at line 32 of file array_filter.c.

{
       int ret = -1;
       switch(hztbl->nSelectKeyMode) {
              case NUMBER0_MODE:
                     if (key >= '0' && key <= '9')
                            ret = (key - '0') % 10;
                     break;

              case NUMBER_MODE:
                     if (key >= '0' && key <= '9')
                            ret = (key - '0' + 9) % 10;
                     break;

              case LOWER_MODE:
                     if (key >= 'a' && key <= 'a' + 10)
                            ret = key - 'a';
                     break;

              case UPPER_MODE:
                     if (key >= 'A' && key <= 'A' + 10)
                            ret = key - 'A';
                     break;
       }
       return(ret);
}
int get_symbol_characters ( CodeTableStruct hztbl,
ImeBufferRec ime_buffer,
int  symbol_area_id,
int  pos,
int  max_lookup_num 
)

Definition at line 266 of file array_filter.c.

{
       int k;
       int num_matched;
       char *symbol_str;

       num_matched = 0;
       for(k=0;k<no_arraytbl[symbol_area_id];k++) {
              if (k<pos) continue;

              symbol_str = (char *)arraytbl10[symbol_area_id][k];
              if (!is_valid_candidate(symbol_str, strlen(symbol_str), ENCODE_UTF8, hztbl->Output_Encode))
                     continue;

              if (hztbl->Encode == ENCODE_UTF8) {
                     strcpy(Candidates[num_matched], symbol_str);
                     strcpy(Lookups[num_matched], symbol_str);
              } else {
                     char *ip, *op, buffer[128];
                     int ileft, oleft;

                     ip = (char *)symbol_str;
                     ileft = strlen(symbol_str);
                     op = buffer;
                     oleft = 128;
                     memset(buffer, 0, 128);
                     Convert_UTF8_To_Native(hztbl->Encode, ip, ileft, &op, &oleft);
                     strcpy(Candidates[num_matched], buffer);
                     strcpy(Lookups[num_matched], buffer);
              }
              if (num_matched == max_lookup_num)
                     break;

              num_matched++;
       }

       Page_State = ImeCandidatesFirstPage | ImeCandidatesLastPage;
       return(num_matched);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int If_Has_WildChar ( char *  input_str)

Definition at line 213 of file array_filter.c.

{
       char *p = input_str;

       while(*p) {
              if (*p == '?' || *p == '*')
                     return(1);
              p++;
       }
       return(0);
}

Here is the caller graph for this function:

int Is_BackSpace_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 84 of file array_filter.c.

{
       int i;
       unsigned char *keylist = hztbl->functionkey[BACKSPACE_KEY_ID].keylist;

       if (key == IME_FILTERED_KEY_BACKSPACE || key == IME_FILTERED_KEY_DELETE)
              return(1);

       if (keylist[0]) {
              for (i=0; i<MAX_FUNCTIONKEY_LEN; i++)
                     if (keylist[i] == key)
                            return(1);
       }

       return(0);
}
int Is_ClearAll_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 101 of file array_filter.c.

{
       int i;
       unsigned char *keylist = hztbl->functionkey[CLEARALL_KEY_ID].keylist;

       if (key == IME_FILTERED_KEY_ESCAPE)
              return(1);

       if (keylist[0]) {
              for (i=0; i<MAX_FUNCTIONKEY_LEN; i++)
                     if (keylist[i] == key)
                            return(1);
       }
       return(0);
}
int Is_NextPage_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 117 of file array_filter.c.

{
       int i;
       unsigned char *keylist = hztbl->functionkey[PAGEDOWN_KEY_ID].keylist;

       if (key == IME_FILTERED_KEY_PAGEDOWN)
              return(1);

       if (keylist[0]) {
              for (i=0; i<MAX_FUNCTIONKEY_LEN; i++)
                     if (keylist[i] == key)
                            return(1);
       }
       return(0);
}
int Is_PrevPage_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 133 of file array_filter.c.

{
       int i;
       unsigned char *keylist = hztbl->functionkey[PAGEUP_KEY_ID].keylist;

       if (key == IME_FILTERED_KEY_PAGEUP)
              return(1);
       
       if (keylist[0]) {
              for (i=0; i<MAX_FUNCTIONKEY_LEN; i++)
                     if (keylist[i] == key)
                            return(1);
       }
       return(0);
}
int Is_Return_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 76 of file array_filter.c.

{
       if (key == IME_FILTERED_KEY_ENTER)
              return(1);
       else
              return(0);
}

Here is the caller graph for this function:

int Is_Select_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 59 of file array_filter.c.

{
       int ret = get_select_num(hztbl, key);
       if (ret == -1)
              return(0);
       else
              return(1);
}

Here is the call graph for this function:

int Is_Space_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 68 of file array_filter.c.

{
       if (key == IME_FILTERED_KEY_SPACEBAR)
              return(1);
       else
              return(0);
}

Here is the caller graph for this function:

int Is_UsedCodes_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 24 of file array_filter.c.

{
       if (index(hztbl->UsedCodes, key))
              return(1);
       else
              return(0);
}
void warning_bell ( ImeBufferRec ime_buffer)

Definition at line 208 of file array_filter.c.