Back to index

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

Go to the source code of this file.

Functions

int ThaiKeymapList_Init (TThaiKeymapList *pThaiKeymapList)
int ThaiKeymapList_Free (TThaiKeymapList *pThaiKeymapList)
int ThaiKeymapList_Alloc (TThaiKeymapList *pThaiKeymapList, int nNum_Alloced)
int ThaiKeymapList_ReAlloc (TThaiKeymapList *pThaiKeymapList, int nNum_ReAlloced)
int ThaiKeymapList_Print (TThaiKeymapList *pThaiKeymapList)
int ThaiKeymapList_Item_Prepare (TThaiKeymapList *pThaiKeymapList, int nKeymap_ID)
int ThaiKeymapList_Item_Set_Name (TThaiKeymapList *pThaiKeymapList, int nKeymap_ID, unsigned char *pName)
int ThaiKeymapList_Item_Set_KeymapValue (TThaiKeymapList *pThaiKeymapList, int nKeymap_ID, unsigned char key, unsigned char key_value)
int ThaiKeymapList_Item_Add_Keymap (TThaiKeymapList *pThaiKeymapList, unsigned char *pName, unsigned char *pKeymap)
int ThaiKeymapList_Item_Get_Symbol (TThaiKeymapList *pThaiKeymapList, int nKeymap_ID, int key)

Function Documentation

int ThaiKeymapList_Alloc ( TThaiKeymapList pThaiKeymapList,
int  nNum_Alloced 
)

Definition at line 45 of file thai_keymap.c.

{
       int i;

       pThaiKeymapList->nNum_Keymaps_Alloced = 0;
       pThaiKeymapList->pKeymaps = (PThaiKeymap*)malloc(nNum_Alloced*sizeof(PThaiKeymap));
       if (pThaiKeymapList->pKeymaps == NULL) {
              return(THAI_KEYMAP_ERROR);
       }

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

       pThaiKeymapList->nNum_Keymaps_Alloced = nNum_Alloced;

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_Free ( TThaiKeymapList pThaiKeymapList)

Definition at line 13 of file thai_keymap.c.

{
       int i;

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

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

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

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

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

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

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

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_Init ( TThaiKeymapList pThaiKeymapList)

Definition at line 4 of file thai_keymap.c.

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

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_Item_Add_Keymap ( TThaiKeymapList pThaiKeymapList,
unsigned char *  pName,
unsigned char *  pKeymap 
)

Definition at line 211 of file thai_keymap.c.

{
       int idx, ret;
       int nKeymap_ID;

       if (!pName || !*pName) 
              return(THAI_KEYMAP_ERROR);

       if (!pKeymap) 
              return(THAI_KEYMAP_ERROR);

       nKeymap_ID = pThaiKeymapList->nNum_Keymaps;
       ret = ThaiKeymapList_Item_Prepare(pThaiKeymapList, nKeymap_ID);
       if (ret == THAI_KEYMAP_ERROR)
              return(THAI_KEYMAP_ERROR);

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

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

       if (pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL) {
              pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap = (unsigned char *)calloc(THAI_KEYMAP_LEN + 1, sizeof(char));
              if (pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL)
                     return(THAI_KEYMAP_ERROR);
              for (idx = 0; idx < THAI_KEYMAP_LEN; idx ++) {
                     pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx] = idx+0x20;
              }
       }
              
       for (idx = 1; idx <= THAI_KEYMAP_LEN; idx++) {
              pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx] = pKeymap[idx];
       }

       pThaiKeymapList->nNum_Keymaps ++;

       return(THAI_KEYMAP_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ThaiKeymapList_Item_Get_Symbol ( TThaiKeymapList pThaiKeymapList,
int  nKeymap_ID,
int  key 
)

Definition at line 253 of file thai_keymap.c.

{
       if (nKeymap_ID < 0 || nKeymap_ID >= pThaiKeymapList->nNum_Keymaps)
              return(key);

       if (key <= 0x20 || key >= 0x80) 
              return(key);

       if (pThaiKeymapList->pKeymaps == NULL ||
           pThaiKeymapList->pKeymaps[nKeymap_ID] == NULL ||
           pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL)
              return(key);

       return(pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[key - 0x20]);
}

Here is the caller graph for this function:

int ThaiKeymapList_Item_Prepare ( TThaiKeymapList pThaiKeymapList,
int  nKeymap_ID 
)

Definition at line 115 of file thai_keymap.c.

{
       int ret;

       if (nKeymap_ID < 0 || nKeymap_ID >= pThaiKeymapList->nNum_Keymaps_Alloced + NUM_KEYMAPS_ALLOC)
              return(THAI_KEYMAP_ERROR);

       if (pThaiKeymapList->nNum_Keymaps_Alloced == 0) {
              ret = ThaiKeymapList_Alloc(pThaiKeymapList, NUM_KEYMAPS_ALLOC);
              if (ret == THAI_KEYMAP_ERROR)
                     return(THAI_KEYMAP_ERROR);
       }

       if (nKeymap_ID >= pThaiKeymapList->nNum_Keymaps_Alloced) {
              int nNum_Alloc = pThaiKeymapList->nNum_Keymaps_Alloced + NUM_KEYMAPS_ALLOC;
              ret = ThaiKeymapList_ReAlloc(pThaiKeymapList, nNum_Alloc);
              if (ret == THAI_KEYMAP_ERROR)
                     return(THAI_KEYMAP_ERROR);
       }

       if (pThaiKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              pThaiKeymapList->pKeymaps[nKeymap_ID] = (TThaiKeymap *)calloc(1, sizeof(TThaiKeymap));
              if (pThaiKeymapList->pKeymaps[nKeymap_ID] == NULL)
                     return(THAI_KEYMAP_ERROR);
       }

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

int ThaiKeymapList_Item_Set_KeymapValue ( TThaiKeymapList pThaiKeymapList,
int  nKeymap_ID,
unsigned char  key,
unsigned char  key_value 
)

Definition at line 177 of file thai_keymap.c.

{
       int idx;

       if (!key_value)
              return(THAI_KEYMAP_ERROR);

       if (key < 0x20 || key >= 0x80) 
              return(THAI_KEYMAP_ERROR);

       if (nKeymap_ID < 0 || nKeymap_ID >= pThaiKeymapList->nNum_Keymaps_Alloced)
              return(THAI_KEYMAP_ERROR);

       if (pThaiKeymapList->pKeymaps == NULL) {
              return(THAI_KEYMAP_ERROR);
       }

       if (pThaiKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              return(THAI_KEYMAP_ERROR);
       }

       if (pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL) {
              pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap = (unsigned char *)calloc(THAI_KEYMAP_LEN + 1, sizeof(char));
              if (pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap == NULL)
                     return(THAI_KEYMAP_ERROR);
              for (idx = 0; idx < THAI_KEYMAP_LEN; idx ++) {
                     pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx] = idx+0x20;
              }
       }
              
       pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[key - 0x20] = key_value;
       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_Item_Set_Name ( TThaiKeymapList pThaiKeymapList,
int  nKeymap_ID,
unsigned char *  pName 
)

Definition at line 154 of file thai_keymap.c.

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

       if (nKeymap_ID < 0 || nKeymap_ID >= pThaiKeymapList->nNum_Keymaps_Alloced)
              return(THAI_KEYMAP_ERROR);

       if (pThaiKeymapList->pKeymaps[nKeymap_ID] == NULL) {
              return(THAI_KEYMAP_ERROR);
       }

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

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

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_Print ( TThaiKeymapList pThaiKeymapList)

Definition at line 83 of file thai_keymap.c.

{
       int nKeymap_ID, idx, key;

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

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

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

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

              printf("Keymap: \n");
              for (idx = 1; idx <= THAI_KEYMAP_LEN; idx++) {
                     key = pThaiKeymapList->pKeymaps[nKeymap_ID]->pKeymap[idx];
                     if (key != 0) {
                            printf("%c:  %c  0x%x\n", idx + 0x20, key, key);
                     }
              }
       }

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function:

int ThaiKeymapList_ReAlloc ( TThaiKeymapList pThaiKeymapList,
int  nNum_ReAlloced 
)

Definition at line 63 of file thai_keymap.c.

{
       int i;

       pThaiKeymapList->pKeymaps = (PThaiKeymap*)realloc(pThaiKeymapList->pKeymaps,
                                   nNum_ReAlloced * sizeof(PThaiKeymap));
       if (pThaiKeymapList->pKeymaps == NULL) {
              pThaiKeymapList->nNum_Keymaps = 0;
              pThaiKeymapList->nNum_Keymaps_Alloced = 0;
              return(THAI_KEYMAP_ERROR);
       }

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

       pThaiKeymapList->nNum_Keymaps_Alloced = nNum_ReAlloced;

       return(THAI_KEYMAP_OK);
}

Here is the caller graph for this function: