Back to index

im-sdk  12.3.91
Defines | Functions | Variables
IMEConfig.c File Reference
#include <stdio.h>
#include <locale.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "hzinput.h"
#include "kolelog.h"
#include "encode.h"

Go to the source code of this file.

Defines

#define MAX_LINE_LEN   256

Functions

IMEBaseRecIMEItem_Malloc ()
void IMEItem_Free (IMEBaseRec *pIME_Base)
void IMEList_Init ()
void IMEList_Free ()
void Add_IME_To_AllList (IMEBaseRec *baseinfo)
void get_ime_line (FILE *fd, char *line)
void Select_IMEs_From_Profile ()
void Save_IMEList_To_Profile (IMEListRec *imelist)

Variables

IMEListRec AllIMEList
IMEListRec SelectedIMEList
char gLocaleID

Define Documentation

#define MAX_LINE_LEN   256

Definition at line 10 of file IMEConfig.c.


Function Documentation

void Add_IME_To_AllList ( IMEBaseRec baseinfo)

Definition at line 68 of file IMEConfig.c.

{
       int engine_num, engine_locale_id, system_locale_id, encode_id;
       int ilen, olen, ret, nIME_Num;
       char *engine_cname, *ime_cname, tmp_name[256];
       IMEBaseRec *pIME_Base;

       engine_locale_id = baseinfo->locale_id;
       system_locale_id = gLocaleID;

       KOLE_LOG (LOGDEST_STDOUT, "locale_id:%d, engine_id:%d, status:%d, ename:%s, cname:%s\n",
              baseinfo->locale_id,
              baseinfo->engine_id,
              baseinfo->status,
              baseinfo->ename,
              baseinfo->cname);
       
       /* if is ENCODES_NUM, means this engine is a common engine for this language. */
       if (engine_locale_id != system_locale_id && engine_locale_id != ENCODES_NUM)
              return;

       if (baseinfo->status == ENGINE_NOT_INSTALLED)
              return;

       nIME_Num = AllIMEList.nIME_Num;
       pIME_Base = AllIMEList.arrIME_Base[nIME_Num];
       if (pIME_Base != NULL) IMEItem_Free(pIME_Base);
       AllIMEList.arrIME_Base[nIME_Num] = NULL;

       pIME_Base = (IMEBaseRec *)IMEItem_Malloc();
       if (pIME_Base == NULL) return;

       pIME_Base->engine_id = baseinfo->engine_id;
       pIME_Base->locale_id = baseinfo->locale_id;
       pIME_Base->encode_id = baseinfo->encode_id;
       pIME_Base->status = baseinfo->status;
       pIME_Base->ename = (char *)strdup(baseinfo->ename);
       
       /* convert IME name to native encoding. */
       /* Usually: IME name is in UTF-8 or native encoding */
       encode_id = pIME_Base->encode_id;
       if (encode_id == ENCODE_UTF8) {
              engine_cname = (char *)baseinfo->cname;
              ilen = strlen((char *)engine_cname);
              ime_cname = tmp_name;
              olen = 256;
              memset(ime_cname, 0, olen);
              ret = Convert_UTF8_To_Native(system_locale_id, engine_cname, ilen, &ime_cname, &olen);
              KOLE_LOG (LOGDEST_STDOUT, "ret:%d, ime_cname:%s, olen:%d\n", ret, ime_cname, olen);
              if (ret == 0)
                     pIME_Base->cname = (char *)strdup(tmp_name);
              else
                     pIME_Base->cname = (char *)strdup(baseinfo->ename);
       } else {
              pIME_Base->cname = (char *)strdup(baseinfo->cname);
       }

       AllIMEList.arrIME_Base[nIME_Num] = pIME_Base;
       nIME_Num ++;
       AllIMEList.nIME_Num = nIME_Num;
}

Here is the call graph for this function:

static void get_ime_line ( FILE *  fd,
char *  line 
)

Definition at line 130 of file IMEConfig.c.

{
       int line_ptr;
       char line_buf[256], *ptr;

       line_ptr = 0;
       line[0] = '\0';

       /* get line with no space */
       while(fgets(line_buf, 255, fd) != NULL) {
              ptr = line_buf;

              /* skip space keys */
              while(*ptr && isspace(*ptr)) ptr++;

              /* if is space line, get new line */
              if (*ptr == '\n' || *ptr == '\0')
                     continue;

              while(*ptr != '\n' && *ptr != '\0' && line_ptr < MAX_LINE_LEN) 
                     line[line_ptr++] = *ptr++;

              /* trim right space */
              while (isspace(line[line_ptr-1])) line_ptr--;
              line[line_ptr] = '\0';

              /* if the line end with '\', then continue read the next line */
              if (line[line_ptr-1] == '\\') {
                     line_ptr--;
                     line[line_ptr] = '\0';
                     continue;
              }

              break;
       }
}

Here is the caller graph for this function:

void IMEItem_Free ( IMEBaseRec pIME_Base)

Definition at line 30 of file IMEConfig.c.

{
       if (pIME_Base == NULL) return;

       if (pIME_Base->ename) free((char *)pIME_Base->ename);
       if (pIME_Base->cname) free((char *)pIME_Base->cname);

       free((char *)pIME_Base);
}

Here is the caller graph for this function:

Definition at line 17 of file IMEConfig.c.

{
       IMEBaseRec *pIME_Base;

       pIME_Base = (IMEBaseRec *)calloc(1, sizeof(IMEBaseRec));
       if (pIME_Base == NULL) return(NULL);

       pIME_Base->ename = NULL;
       pIME_Base->cname = NULL;

       return(pIME_Base);
}

Here is the caller graph for this function:

void IMEList_Free ( )

Definition at line 53 of file IMEConfig.c.

Here is the call graph for this function:

void IMEList_Init ( )

Definition at line 40 of file IMEConfig.c.

void Save_IMEList_To_Profile ( IMEListRec imelist)

Definition at line 233 of file IMEConfig.c.

{
       FILE *fd;
       int ret, i;
       struct stat file_stat;
       char path_name[256], tmp_name[256];
       char *locale_name;

       /* Create Path $(HOME)/.Xlocale */
       sprintf(path_name, "%s/%s", (char *)getenv("HOME"), USER_PROFILE_PATH);
       KOLE_LOG (LOGDEST_STDOUT, "path_name: %s\n", path_name);

       ret = stat(path_name, &file_stat);
       if (ret == -1) {
              KOLE_LOG (LOGDEST_STDOUT, "%s not exist\n", path_name);
              ret = mkdir(path_name, 0777);
              if (ret == -1) {
                     KOLE_LOG (LOGDEST_STDOUT, "can not create path %s\n", path_name);
                     return;
              }
       }

       /* Create Path $(HOME)/.Xlocale/<locale> */
       locale_name = setlocale(LC_CTYPE, NULL);

       sprintf(tmp_name, "%s/%s", path_name, locale_name);
       strcpy(path_name, tmp_name);

       ret = stat(path_name, &file_stat);
       if (ret == -1) {
              KOLE_LOG (LOGDEST_STDOUT, "%s not exist\n", path_name);
              ret = mkdir(path_name, 0777);
              if (ret == -1) {
                     KOLE_LOG (LOGDEST_STDOUT, "can not create path %s\n", path_name);
                     return;
              }
       }

       /* Create File $(HOME)/.Xlocale/<locale>/ime.cfg */
       sprintf(tmp_name, "%s/%s", path_name, USER_PROFILE_NAME);
       strcpy(path_name, tmp_name);
       KOLE_LOG (LOGDEST_STDOUT, "path_name: %s\n", path_name);
       fd = fopen(path_name, "wb");
       if (! fd) {
              KOLE_LOG (LOGDEST_STDOUT, "unable open the file: %s\n", path_name);
              return;
       }

       for (i=0; i<imelist->nIME_Num; i++) {
              fprintf(fd, "%s\n", imelist->arrIME_Base[i]->ename);
       }

       fclose(fd);
}

Here is the call graph for this function:

Definition at line 167 of file IMEConfig.c.

{
       char            file_name[256], line[MAX_LINE_LEN]; 
       int           i, nInstalledIME;
    
       register char        *ptr, *ime_name;
       FILE          *fd;

       char          *locale_name;

       if (AllIMEList.nIME_Num == 0) return;

       locale_name = setlocale(LC_CTYPE, NULL);

       /* read profile from file to memory buffer  */ 
       sprintf(file_name, "%s/%s/%s/%s", getenv("HOME"), 
              USER_PROFILE_PATH, locale_name, USER_PROFILE_NAME);
       KOLE_LOG (LOGDEST_STDOUT, "file name :%s\n",file_name);

       fd = fopen(file_name, "r");
       if (! fd) {
              SelectedIMEList = AllIMEList;
              return;
       }

       nInstalledIME = 0;
       do {
              get_ime_line(fd, line);

              if (line[0] == '\0') break;
              if (line[0] == '#') continue;

              /* get IME language engine name */
              ime_name = line;

              KOLE_LOG (LOGDEST_STDOUT, "IME Name:%s\n", ime_name);
              for (i=0; i<AllIMEList.nIME_Num; i++) {
                     if (strcasecmp(ime_name, AllIMEList.arrIME_Base[i]->ename)) {
                            continue;
                     } else {
                            SelectedIMEList.arrIME_Base[nInstalledIME] = AllIMEList.arrIME_Base[i];
                            nInstalledIME ++;
                            break;
                     }
              }
       } while (1);

       fclose(fd);
       
       if (nInstalledIME == 0) 
              SelectedIMEList = AllIMEList;
       else
              SelectedIMEList.nIME_Num = nInstalledIME;

       for (i=0; i<SelectedIMEList.nIME_Num; i++) {
              KOLE_LOG (LOGDEST_STDOUT, "localeid:%d, ename:%s, cname:%s, imid:%d, status:%d\n", 
                     SelectedIMEList.arrIME_Base[i]->locale_id,
                     SelectedIMEList.arrIME_Base[i]->ename,
                     SelectedIMEList.arrIME_Base[i]->cname,
                     SelectedIMEList.arrIME_Base[i]->engine_id,
                     SelectedIMEList.arrIME_Base[i]->status);
       }

       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 13 of file IMEConfig.c.

char gLocaleID

Definition at line 31 of file common_aux_methods.c.

Definition at line 13 of file IMEConfig.c.