Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Enumerations | Functions
codetable.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _tableNode
struct  _keyPrompt
struct  _functionKey
struct  CodeTableStruct

Defines

#define MAX_CHNAME_LEN   256
#define MAX_USEDCODES_NUM   126
#define MAX_WILDCHAR_NUM   4
#define MAX_KEYPROMPT_LEN   4
#define MAX_FUNCTIONKEY_LEN   6
#define CODETABLE_FLAG   "CODETABLE"
#define CODETABLE_VERSION   1
#define HZ_PHRASE_TAG   '\001'
#define BITMASK(i)   (1 << (i))
#define BITSET(a, i)   ((a) |= BITMASK(i))
#define BITCLEAR(a, i)   ((a) &= ~BITMASK(i))
#define GETBIT(a, i)   ((a) & BITMASK(i))

Typedefs

typedef struct _tableNode tableNode
typedef struct _keyPrompt keyPrompt
typedef struct _functionKey functionKey

Enumerations

enum  _Section_List {
  DEFAULT_SECTION = 0, DESCRIPTION_SECTION, COMMENT_SECTION, KEYPROMPT_SECTION,
  FUNCTIONKEY_SECTION, PHRASE_SECTION, SINGLE_SECTION, OPTIONS_SECTION,
  MAX_SECTION_NUM, DEFAULT_SECTION = 0, DESCRIPTION_SECTION, COMMENT_SECTION,
  KEYPROMPT_SECTION, FUNCTIONKEY_SECTION, PHRASE_SECTION, SINGLE_SECTION,
  OPTIONS_SECTION, MAX_SECTION_NUM, DEFAULT_SECTION = 0, DESCRIPTION_SECTION,
  MAX_SECTION_NUM, DEFAULT_SECTION = 0, DESCRIPTION_SECTION, COMMENT_SECTION,
  KEYPROMPT_SECTION, FUNCTIONKEY_SECTION, PHRASE_SECTION, SINGLE_SECTION,
  OPTIONS_SECTION, MAX_SECTION_NUM, DEFAULT_SECTION = 0, DESCRIPTION_SECTION,
  MAX_SECTION_NUM, DEFAULT_SECTION = 0, DESCRIPTION_SECTION, COMMENT_SECTION,
  KEYPROMPT_SECTION, FUNCTIONKEY_SECTION, PHRASE_SECTION, SINGLE_SECTION,
  OPTIONS_SECTION, MAX_SECTION_NUM
}
enum  _Function_Key_ID {
  PAGEUP_KEY_ID = 0, PAGEDOWN_KEY_ID, BACKSPACE_KEY_ID, CLEARALL_KEY_ID,
  MAX_FUNCTIONKEY_NUM, PAGEUP_KEY_ID = 0, PAGEDOWN_KEY_ID, BACKSPACE_KEY_ID,
  CLEARALL_KEY_ID, MAX_FUNCTIONKEY_NUM, PAGEUP_KEY_ID = 0, PAGEDOWN_KEY_ID,
  BACKSPACE_KEY_ID, CLEARALL_KEY_ID, MAX_FUNCTIONKEY_NUM, PAGEUP_KEY_ID = 0,
  PAGEDOWN_KEY_ID, BACKSPACE_KEY_ID, CLEARALL_KEY_ID, MAX_FUNCTIONKEY_NUM
}
enum  _Option_Mode {
  OFF_MODE = 0, ON_MODE, OFF_MODE = 0, ON_MODE,
  OFF_MODE = 0, ON_MODE, OFF_MODE = 0, ON_MODE
}
enum  _Select_Key_Mode {
  NUMBER0_MODE = 0, NUMBER_MODE, LOWER_MODE, UPPER_MODE,
  NUMBER0_MODE = 0, NUMBER_MODE, LOWER_MODE, UPPER_MODE,
  NUMBER_MODE = 0, LOWER_MODE, UPPER_MODE, NUMBER_MODE = 0,
  LOWER_MODE, UPPER_MODE
}

Functions

int LoadCodeTableHeader (char *file_name, CodeTableStruct *hztbl)
int LoadCodeTable (char *file_name, CodeTableStruct *hztbl)
void UnloadCodeTable (CodeTableStruct *hztbl)
int codetable_search (CodeTableStruct *hztbl, int *inbuf, int inlen, unsigned char **outbuf, unsigned char **attrbuf, int pos, int num)
int Is_Wildchar_Key (CodeTableStruct *hztbl, int key)

Class Documentation

struct _tableNode

Definition at line 73 of file codetable.h.

Class Members
unsigned char key
int keycode
int modifier
unsigned short num_HZchoice
unsigned char num_NextKeys
unsigned int pos_HZidx
unsigned int pos_NextKey
struct _keyPrompt

Definition at line 81 of file codetable.h.

Class Members
unsigned char prompt
struct _functionKey

Definition at line 85 of file codetable.h.

Class Members
unsigned char keylist
struct CodeTableStruct

Definition at line 90 of file codetable.h.

Collaboration diagram for CodeTableStruct:
Class Members
char Author
char bSectionsFlag
unsigned char Cname
char Copyright
char Encode
functionKey * functionkey
char Hinting
unsigned char * hzList
char IconPath
keyPrompt * keyprompt
unsigned char Lname
char MaxCodes
unsigned nAutoSelectMode:1
unsigned nDisplayOnSpotMode:1
unsigned nHelpInfoMode:1
unsigned nKeyByKeyMode:1
unsigned nKeyPromptMode:1
tableNode * nodeList
unsigned nReserved:1
unsigned nSelectKeyMode:2
char Output_Encode
unsigned int sizeHZList
unsigned int sizeNodeList
char UsedCodes
char UUID
char Version
unsigned char WildChar

Define Documentation

#define BITCLEAR (   a,
  i 
)    ((a) &= ~BITMASK(i))

Definition at line 103 of file codetable.h.

#define BITMASK (   i)    (1 << (i))

Definition at line 101 of file codetable.h.

#define BITSET (   a,
  i 
)    ((a) |= BITMASK(i))

Definition at line 102 of file codetable.h.

#define CODETABLE_FLAG   "CODETABLE"

Definition at line 57 of file codetable.h.

#define CODETABLE_VERSION   1

Definition at line 60 of file codetable.h.

#define GETBIT (   a,
  i 
)    ((a) & BITMASK(i))

Definition at line 104 of file codetable.h.

#define HZ_PHRASE_TAG   '\001'

Definition at line 98 of file codetable.h.

#define MAX_CHNAME_LEN   256

Definition at line 46 of file codetable.h.

#define MAX_FUNCTIONKEY_LEN   6

Definition at line 54 of file codetable.h.

#define MAX_KEYPROMPT_LEN   4

Definition at line 51 of file codetable.h.

#define MAX_USEDCODES_NUM   126

Definition at line 47 of file codetable.h.

#define MAX_WILDCHAR_NUM   4

Definition at line 48 of file codetable.h.


Typedef Documentation

typedef struct _functionKey functionKey
typedef struct _keyPrompt keyPrompt
typedef struct _tableNode tableNode

Enumeration Type Documentation

Enumerator:
PAGEUP_KEY_ID 
PAGEDOWN_KEY_ID 
BACKSPACE_KEY_ID 
CLEARALL_KEY_ID 
MAX_FUNCTIONKEY_NUM 
PAGEUP_KEY_ID 
PAGEDOWN_KEY_ID 
BACKSPACE_KEY_ID 
CLEARALL_KEY_ID 
MAX_FUNCTIONKEY_NUM 
PAGEUP_KEY_ID 
PAGEDOWN_KEY_ID 
BACKSPACE_KEY_ID 
CLEARALL_KEY_ID 
MAX_FUNCTIONKEY_NUM 
PAGEUP_KEY_ID 
PAGEDOWN_KEY_ID 
BACKSPACE_KEY_ID 
CLEARALL_KEY_ID 
MAX_FUNCTIONKEY_NUM 

Definition at line 76 of file codetable.h.

Enumerator:
OFF_MODE 
ON_MODE 
OFF_MODE 
ON_MODE 
OFF_MODE 
ON_MODE 
OFF_MODE 
ON_MODE 

Definition at line 85 of file codetable.h.

                  {
  OFF_MODE = 0,
  ON_MODE     ,
};
Enumerator:
DEFAULT_SECTION 
DESCRIPTION_SECTION 
COMMENT_SECTION 
KEYPROMPT_SECTION 
FUNCTIONKEY_SECTION 
PHRASE_SECTION 
SINGLE_SECTION 
OPTIONS_SECTION 
MAX_SECTION_NUM 
DEFAULT_SECTION 
DESCRIPTION_SECTION 
COMMENT_SECTION 
KEYPROMPT_SECTION 
FUNCTIONKEY_SECTION 
PHRASE_SECTION 
SINGLE_SECTION 
OPTIONS_SECTION 
MAX_SECTION_NUM 
DEFAULT_SECTION 
DESCRIPTION_SECTION 
MAX_SECTION_NUM 
DEFAULT_SECTION 
DESCRIPTION_SECTION 
COMMENT_SECTION 
KEYPROMPT_SECTION 
FUNCTIONKEY_SECTION 
PHRASE_SECTION 
SINGLE_SECTION 
OPTIONS_SECTION 
MAX_SECTION_NUM 
DEFAULT_SECTION 
DESCRIPTION_SECTION 
MAX_SECTION_NUM 
DEFAULT_SECTION 
DESCRIPTION_SECTION 
COMMENT_SECTION 
KEYPROMPT_SECTION 
FUNCTIONKEY_SECTION 
PHRASE_SECTION 
SINGLE_SECTION 
OPTIONS_SECTION 
MAX_SECTION_NUM 

Definition at line 63 of file codetable.h.

Enumerator:
NUMBER0_MODE 
NUMBER_MODE 
LOWER_MODE 
UPPER_MODE 
NUMBER0_MODE 
NUMBER_MODE 
LOWER_MODE 
UPPER_MODE 
NUMBER_MODE 
LOWER_MODE 
UPPER_MODE 
NUMBER_MODE 
LOWER_MODE 
UPPER_MODE 

Definition at line 91 of file codetable.h.


Function Documentation

int codetable_search ( CodeTableStruct hztbl,
int *  inbuf,
int  inlen,
unsigned char **  outbuf,
unsigned char **  attrbuf,
int  pos,
int  num 
)

Definition at line 597 of file codetable.c.

{
  HZSearchContext search_context, *pSC;

  int matched, i, j, k, len;
  tableNode *tnptr, *tCurTNptr;
  int search_num;
       
  /* search maxinum matched top node that not include wildchar */
  tCurTNptr = &(hztbl->nodeList[0]);
  i = 0;
  while (i < inlen)
    {
      if (    (Is_WildcharMatchSingle_Key(hztbl, inbuf[i])) || 
              (Is_WildcharMatchAny_Key(hztbl, inbuf[i])) )
       break;

      matched = 0;
      j = 0;
      tnptr = &(hztbl->nodeList[tCurTNptr->pos_NextKey]);
      while (j < tCurTNptr->num_NextKeys)
       {
         if (inbuf[i] == tnptr->key) {
           matched = 1;
           break;
         }
         tnptr ++;
         j ++;
       }
      if (matched == 0)
       return(0);

      tCurTNptr = tnptr;
      i++;
    }

  /* set search context */
  pSC = &search_context;
  pSC->depth = 0;
  pSC->tNnumSb[0] = 0;
  pSC->tNstack[0] = tCurTNptr;
  memset(pSC->repcode, 0, MAX_INPUT_KEY_NUM+1);
  memset(pSC->prefix, 0, MAX_INPUT_KEY_NUM+1);
  memset(pSC->wildpattern, 0, MAX_INPUT_KEY_NUM+1);

  if (i>0) {
    len = MAX_INPUT_KEY_NUM+1>i ? i : MAX_INPUT_KEY_NUM+1;  
    for(k=0;k<inlen;k++){
      pSC->prefix[k] = inbuf[k];
    }
    /*
      strncpy(pSC->prefix, inbuf, len);
    */
  }

  search_num = num > MAX_CANDIDATES_NUM ? MAX_CANDIDATES_NUM : num;
  if (i == inlen) {
    /* no wildchar,  begin normal mode search */
    num = normal_search(hztbl, pSC, outbuf, attrbuf, pos, search_num);
  } else {
    /* have any wildchar, begin wildchar mode search */
    for (k=0;k<inlen;k++){
      pSC->wildpattern[k] = inbuf[k+i];
    }
    num = wildchar_search(hztbl, pSC, outbuf, attrbuf, pos, search_num);
  }
  return(num);
}

Here is the call graph for this function:

int Is_Wildchar_Key ( CodeTableStruct hztbl,
int  key 
)

Definition at line 232 of file codetable.c.

{
       int ret;

       ret = ( Is_WildcharMatchSingle_Key(hztbl, key) || Is_WildcharMatchAny_Key(hztbl, key) );
       return(ret);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LoadCodeTable ( char *  file_name,
CodeTableStruct hztbl 
)

Definition at line 95 of file codetable.c.

{
       FILE *ifile;
       char ctFlag[256];
       int  ver, i;

       ifile = fopen (file_name, "r");
       if (! ifile) {
              printf("Unable to open the input table file \"%s\"\n",file_name);
              return(-1);
       }

       /* Read CodeTable File Flag */
       if (fread (ctFlag, strlen(CODETABLE_FLAG), 1, ifile) != 1) {
              fprintf (stderr, "Codetable File read Error:%s\n", file_name);
              fclose (ifile);
              return(-1);
       }

       if (strncmp (ctFlag, CODETABLE_FLAG, strlen(CODETABLE_FLAG)) != 0) {
              fprintf (stderr, "File is not in CodeTable format\n");
              fclose (ifile);
              return(-1);
       }

       /* Read CodeTable Version Flag */
       if (fread ((char *)(&ver), sizeof (int), 1, ifile) != 1)  {
              fprintf (stderr, "Codetable File read Error:%s\n", file_name);
              fclose (ifile);
              return(-1);
       }

       if (ver != CODETABLE_VERSION) {
              fprintf (stderr, "File is not in correct Version Number\n");
              fclose (ifile);
              return(-1);
       }

       if (fread((char *)hztbl, sizeof(CodeTableStruct), 1, ifile) == 0) {
              printf( "Error in loading input table for %s\n", file_name);
              fclose (ifile);
              return(-1);
       }

       /* malloc memory for codetable information */
       hztbl->nodeList = (tableNode *)calloc(hztbl->sizeNodeList,sizeof(tableNode));
       hztbl->hzList = (unsigned char *)calloc(hztbl->sizeHZList, sizeof(unsigned char));
       hztbl->keyprompt = (keyPrompt *)calloc(MAX_USEDCODES_NUM, sizeof(keyPrompt));
       hztbl->functionkey = (functionKey *)calloc(MAX_FUNCTIONKEY_NUM, sizeof(functionKey));
       if ((! hztbl->hzList) || (! hztbl->nodeList) ||
           (! hztbl->keyprompt) || (! hztbl->functionkey)) {
              printf( "No memory to load input table for %s\n", file_name);
              fclose (ifile);
              return(-1);
       }

       if ((fread ((char *)(hztbl->nodeList), sizeof(tableNode),
                (int)hztbl->sizeNodeList, ifile) != hztbl->sizeNodeList) ||
           (fread ((char *)hztbl->hzList, sizeof(unsigned char),
                (int)(hztbl->sizeHZList), ifile) != hztbl->sizeHZList))
       {
              printf( "Error in loading input table for %s\n", file_name);
              fclose (ifile);
              return(-1);
       }
       
       if (GETBIT(hztbl->bSectionsFlag, KEYPROMPT_SECTION)) {
              if (fread((char *)(&(hztbl->keyprompt[0])), MAX_USEDCODES_NUM, 
                     sizeof(keyPrompt), ifile) != sizeof(keyPrompt))
              {
                     printf( "Error in loading input table for %s\n", file_name);
                     fclose (ifile);
                     return(-1);
              }
       }

       if (GETBIT(hztbl->bSectionsFlag, FUNCTIONKEY_SECTION)) {
              if (fread((char *)(&(hztbl->functionkey[0])), MAX_FUNCTIONKEY_NUM, 
                     sizeof(functionKey), ifile) != sizeof(functionKey))
              {
                     printf( "Error in loading input table for %s\n", file_name);
                     fclose (ifile);
                     return(-1);
              }
       }

       for (i=0; i<MAX_USEDCODES_NUM; i++) {
              if (hztbl->keyprompt[i].prompt[0] == 0) {
                     hztbl->keyprompt[i].prompt[0] = i;
                     hztbl->keyprompt[i].prompt[1] = 0;
              }
       }

       fclose (ifile);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LoadCodeTableHeader ( char *  file_name,
CodeTableStruct hztbl 
)

Definition at line 39 of file codetable.c.

{
       FILE *ifile;
       char ctFlag[256];
       int  ver, i;

       DEBUG_printf("LoadCodeTableHeader ====\n");

       /* read table from file to memory buffer  */
       ifile = fopen (file_name, "r");
       if (! ifile) {
              fprintf(stderr, "Unable to open the input table file \"%s\"\n",file_name);
              return(-1);
       }

       /* Read CodeTable File Flag */
       if (fread (ctFlag, strlen(CODETABLE_FLAG), 1, ifile) != 1) {
              fprintf (stderr, "Codetable File read Error:%s\n", file_name);
              fclose(ifile);
              return(-1);
       }

       if (strncmp (ctFlag, CODETABLE_FLAG, strlen(CODETABLE_FLAG)) != 0) {
              fprintf (stderr, "File is not in CodeTable format\n");
              fclose(ifile);
              return(-1);
       }

       /* Read CodeTable Version Flag */
       if (fread ((char *)(&ver), sizeof (int), 1, ifile) != 1)  {
              fprintf (stderr, "Codetable File read Error:%s\n", file_name);
              fclose(ifile);
              return(-1);
       }

       if (ver != CODETABLE_VERSION) {
              fprintf (stderr, "File is not in correct Version Number\n");
              fclose(ifile);
              return(-1);
       }

       if (fread((char *)hztbl, sizeof(CodeTableStruct), 1, ifile) != 1) {
              fprintf(stderr, "Error in loading input table for %s\n", file_name);
              fclose(ifile);
              return(-1);
       }

       fclose (ifile);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void UnloadCodeTable ( CodeTableStruct hztbl)

Definition at line 197 of file codetable.c.

{
       if (! hztbl) return;

        if (hztbl->nodeList)  free ((char *)(hztbl->nodeList));
        if (hztbl->hzList)  free ((char *)(hztbl->hzList));
        if (hztbl->keyprompt)  free ((char *)(hztbl->keyprompt));
        if (hztbl->functionkey)  free ((char *)(hztbl->functionkey));
}

Here is the caller graph for this function: