Back to index

im-sdk  12.3.91
Functions
zhuyin_keymap.c File Reference
#include <stdio.h>
#include "zhuyin_standard.h"
#include "zhuyin_keymap.h"

Go to the source code of this file.

Functions

int ZhuyinKeymapList_Init (TZhuyinKeymapList *pZhuyinKeymapList)
int ZhuyinKeymapList_Free (TZhuyinKeymapList *pZhuyinKeymapList)
int ZhuyinKeymapList_Alloc (TZhuyinKeymapList *pZhuyinKeymapList, int nNum_Alloced)
int ZhuyinKeymapList_ReAlloc (TZhuyinKeymapList *pZhuyinKeymapList, int nNum_ReAlloced)
int ZhuyinKeymapList_Print (TZhuyinKeymapList *pZhuyinKeymapList)
int ZhuyinKeymapList_Item_Prepare (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID)
int ZhuyinKeymapList_Item_Set_Name (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, unsigned char *pName)
int ZhuyinKeymapList_Item_Set_KeymapValue (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, unsigned char *pZhuyinSymbol, char key)
int ZhuyinKeymapList_Item_Add_StandardKeymap (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID)
int ZhuyinKeymapList_Item_KeyToIndex (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, int key)
unsigned char * ZhuyinKeymapList_Item_KeyToSymbol (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, int key)
int ZhuyinKeymapList_Item_KeyToType (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, int key)
int ZhuyinKeymapList_Item_KeyToStandardKey (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, int key)
int ZhuyinKeymapList_Item_CheckIfValidKey (TZhuyinKeymapList *pZhuyinKeymapList, int nKeymap_ID, int key)

Function Documentation

int ZhuyinKeymapList_Alloc ( TZhuyinKeymapList pZhuyinKeymapList,
int  nNum_Alloced 
)

Definition at line 88 of file zhuyin_keymap.c.

{
       int i;

       pZhuyinKeymapList->nNum_Keymaps_Alloced = 0;
       pZhuyinKeymapList->pKeymaps = (PZhuyinKeymap*)malloc(nNum_Alloced*sizeof(PZhuyinKeymap));
       if (pZhuyinKeymapList->pKeymaps == NULL) {
              return(ZHUYIN_KEYMAP_ERROR);
       }

       for (i=0; i<nNum_Alloced; i++)
              pZhuyinKeymapList->pKeymaps[i] = NULL;

       pZhuyinKeymapList->nNum_Keymaps_Alloced = nNum_Alloced;

       return(ZHUYIN_KEYMAP_OK);
}

Here is the caller graph for this function:

int ZhuyinKeymapList_Free ( TZhuyinKeymapList pZhuyinKeymapList)

Definition at line 56 of file zhuyin_keymap.c.

{
       int i;

       if (pZhuyinKeymapList->pKeymaps == NULL) {
              return(0);
       }

       for(i=0; i<pZhuyinKeymapList->nNum_Keymaps_Alloced; i++) {
              if (pZhuyinKeymapList->pKeymaps[i]== NULL)
                     continue;

              if (pZhuyinKeymapList->pKeymaps[i]->pName) {
                     free((char *)pZhuyinKeymapList->pKeymaps[i]->pName);
              }

              if (pZhuyinKeymapList->pKeymaps[i]->pKeymap) {
                     free((char *)pZhuyinKeymapList->pKeymaps[i]->pKeymap);
              }

              free((char *)pZhuyinKeymapList->pKeymaps[i]);
       }

       free((char *)pZhuyinKeymapList->pKeymaps);

       pZhuyinKeymapList->nNum_Keymaps = 0;
       pZhuyinKeymapList->nNum_Keymaps_Alloced = 0;
       pZhuyinKeymapList->pKeymaps = NULL;

       return(ZHUYIN_KEYMAP_OK);
}

Here is the caller graph for this function:

int ZhuyinKeymapList_Init ( TZhuyinKeymapList pZhuyinKeymapList)

Definition at line 47 of file zhuyin_keymap.c.

{
       pZhuyinKeymapList->nNum_Keymaps = 0;
       pZhuyinKeymapList->nNum_Keymaps_Alloced = 0;
       pZhuyinKeymapList->pKeymaps = NULL;

       return(ZHUYIN_KEYMAP_OK);
}

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_Add_StandardKeymap ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID 
)

Definition at line 247 of file zhuyin_keymap.c.

{
       int idx;
       char key;

       if (nKeymap_ID < 0 || nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps_Alloced)
              return(ZHUYIN_KEYMAP_ERROR);

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              return(ZHUYIN_KEYMAP_ERROR);
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName != NULL) {
              free((char *)pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName);
       }

       pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName = (unsigned char *)strdup(NAME_STANDARD_ZHUYIN_KEYMAP);
       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName == NULL)
              return(ZHUYIN_KEYMAP_ERROR);

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL) {
              pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap = (char *)calloc(NUM_OF_ZHUYIN_SYMBOL + 2, sizeof(char));
              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL)
                     return(ZHUYIN_KEYMAP_ERROR);
       }
              
       for (idx = 1; idx <= NUM_OF_ZHUYIN_SYMBOL; idx++) {
              pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx] = ZhuyinIndexToStandardKey(idx);
       }
       return(ZHUYIN_KEYMAP_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_CheckIfValidKey ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 318 of file zhuyin_keymap.c.

{
       int idx = ZhuyinKeymapList_Item_KeyToIndex(pZhuyinKeymapList, nKeymap_ID, key);
       return(idx ? 1 : 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_KeyToIndex ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 279 of file zhuyin_keymap.c.

{
       int idx;
       char *pKeymap;

       if (nKeymap_ID < 0 || nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps)
              return(0);

       pKeymap = pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap;
       if (pKeymap == NULL)
              return(0);

       key = tolower(key);
       for (idx = 1; idx <= NUM_OF_ZHUYIN_SYMBOL; idx++) {
              if (key == pKeymap[idx]) {
                     return(idx);
              }
       }
       return(0);
}

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_KeyToStandardKey ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 312 of file zhuyin_keymap.c.

{
       int idx = ZhuyinKeymapList_Item_KeyToIndex(pZhuyinKeymapList, nKeymap_ID, key);
       return(ZhuyinIndexToStandardKey(idx));
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned char* ZhuyinKeymapList_Item_KeyToSymbol ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 300 of file zhuyin_keymap.c.

{
       int idx = ZhuyinKeymapList_Item_KeyToIndex(pZhuyinKeymapList, nKeymap_ID, key);
       return((unsigned char *)ZhuyinIndexToZhuyinSymbol(idx));
}

Here is the call graph for this function:

int ZhuyinKeymapList_Item_KeyToType ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 306 of file zhuyin_keymap.c.

{
       int idx = ZhuyinKeymapList_Item_KeyToIndex(pZhuyinKeymapList, nKeymap_ID, key);
       return(ZhuyinIndexToZhuyinType(idx));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_Prepare ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID 
)

Definition at line 158 of file zhuyin_keymap.c.

{
       int ret;

       if (nKeymap_ID < 0 || nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps_Alloced + NUM_KEYMAPS_ALLOC)
              return(ZHUYIN_KEYMAP_ERROR);

       if (pZhuyinKeymapList->nNum_Keymaps_Alloced == 0) {
              ret = ZhuyinKeymapList_Alloc(pZhuyinKeymapList, NUM_KEYMAPS_ALLOC);
              if (ret == ZHUYIN_KEYMAP_ERROR)
                     return(ZHUYIN_KEYMAP_ERROR);
       }

       if (nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps_Alloced) {
              int nNum_Alloc = pZhuyinKeymapList->nNum_Keymaps_Alloced + NUM_KEYMAPS_ALLOC;
              ret = ZhuyinKeymapList_ReAlloc(pZhuyinKeymapList, nNum_Alloc);
              if (ret == ZHUYIN_KEYMAP_ERROR)
                     return(ZHUYIN_KEYMAP_ERROR);
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              pZhuyinKeymapList->pKeymaps[nKeymap_ID] = (TZhuyinKeymap *)calloc(1, sizeof(TZhuyinKeymap));
              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL)
                     return(ZHUYIN_KEYMAP_ERROR);
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName != NULL) {
              free((char *)pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName);
              pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName = NULL;
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap != NULL) {
              free((char *)pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap);
              pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap = NULL;
       }
              
       return(ZHUYIN_KEYMAP_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_Set_KeymapValue ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
unsigned char *  pZhuyinSymbol,
char  key 
)

Definition at line 220 of file zhuyin_keymap.c.

{
       int idx;

       if (!pZhuyinSymbol || !*pZhuyinSymbol)
              return(ZHUYIN_KEYMAP_ERROR);

       if (nKeymap_ID < 0 || nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps_Alloced)
              return(ZHUYIN_KEYMAP_ERROR);

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              return(ZHUYIN_KEYMAP_ERROR);
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL) {
              pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap = (char *)calloc(NUM_OF_ZHUYIN_SYMBOL + 2, sizeof(char));
              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL)
                     return(ZHUYIN_KEYMAP_ERROR);
       }
              
       idx = ZhuyinSymbolToZhuyinIndex(pZhuyinSymbol);
       if (idx == 0) return(ZHUYIN_KEYMAP_OK);

       pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx] = tolower(key);
       return(ZHUYIN_KEYMAP_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_Item_Set_Name ( TZhuyinKeymapList pZhuyinKeymapList,
int  nKeymap_ID,
unsigned char *  pName 
)

Definition at line 197 of file zhuyin_keymap.c.

{
       if (!pName || !*pName) 
              return(ZHUYIN_KEYMAP_ERROR);

       if (nKeymap_ID < 0 || nKeymap_ID >= pZhuyinKeymapList->nNum_Keymaps_Alloced)
              return(ZHUYIN_KEYMAP_ERROR);

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              return(ZHUYIN_KEYMAP_ERROR);
       }

       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName != NULL) {
              free((char *)pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName);
       }

       pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName = (unsigned char *)strdup(pName);
       if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName == NULL)
              return(ZHUYIN_KEYMAP_ERROR);

       return(ZHUYIN_KEYMAP_OK);
}

Here is the caller graph for this function:

int ZhuyinKeymapList_Print ( TZhuyinKeymapList pZhuyinKeymapList)

Definition at line 126 of file zhuyin_keymap.c.

{
       int nKeymap_ID, idx, key;

       printf("nNum_Keymaps: %d\n", pZhuyinKeymapList->nNum_Keymaps);
       for(nKeymap_ID = 0; nKeymap_ID < pZhuyinKeymapList->nNum_Keymaps; nKeymap_ID ++) {
              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID] == NULL) {
                     return(ZHUYIN_KEYMAP_ERROR);
              }

              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName == NULL) {
                     return(ZHUYIN_KEYMAP_ERROR);
              }

              if (pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL) {
                     return(ZHUYIN_KEYMAP_ERROR);
              }

              printf("Name: %s\n", pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName);

              printf("Keymap: \n");
              for (idx = 1; idx <= NUM_OF_ZHUYIN_SYMBOL; idx++) {
                     key = pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx];
                     if (key != 0) {
                            printf("%s:  %c  0x%x\n", (char *)ZhuyinIndexToZhuyinSymbol(idx), key, key);
                     }
              }
       }

       return(ZHUYIN_KEYMAP_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ZhuyinKeymapList_ReAlloc ( TZhuyinKeymapList pZhuyinKeymapList,
int  nNum_ReAlloced 
)

Definition at line 106 of file zhuyin_keymap.c.

{
       int i;

       pZhuyinKeymapList->pKeymaps = (PZhuyinKeymap*)realloc(pZhuyinKeymapList->pKeymaps,
                                   nNum_ReAlloced * sizeof(PZhuyinKeymap));
       if (pZhuyinKeymapList->pKeymaps == NULL) {
              pZhuyinKeymapList->nNum_Keymaps = 0;
              pZhuyinKeymapList->nNum_Keymaps_Alloced = 0;
              return(ZHUYIN_KEYMAP_ERROR);
       }

       for (i=pZhuyinKeymapList->nNum_Keymaps_Alloced; i<nNum_ReAlloced; i++)
              pZhuyinKeymapList->pKeymaps[i] = NULL;

       pZhuyinKeymapList->nNum_Keymaps_Alloced = nNum_ReAlloced;

       return(ZHUYIN_KEYMAP_OK);
}

Here is the caller graph for this function: