Back to index

im-sdk  12.3.91
Defines | Enumerations | Functions
zhuyin_config.c File Reference
#include <stdio.h>
#include "zhuyin_data.h"

Go to the source code of this file.

Defines

#define MAX_LINE_LEN   256
#define BASE_DIR_STRING   "base_dir"
#define DATA_FILE_STRING   "data_file"
#define KEYMAP_STRING   "keymap"
#define BASE_DIR_NAME_STRING   "path"
#define DATA_FILE_NAME_STRING   "file"
#define KEYMAP_NAME_STRING   "name"

Enumerations

enum  { ZHUYIN_DEFAULT_SECTION = 0, ZHUYIN_BASE_DIR_SECTION, ZHUYIN_DATA_FILE_SECTION, ZHUYIN_KEYMAP_SECTION }

Functions

int parse_line_for_keymap_name (TZhuyinData *pZhuyinData, char *line_buf)
char * skip_space (char *s)
char * to_space (char *s)
char * trim_string (char *s)
int parse_line_for_pair (char *line_buf, char **key_ptr, char **value_ptr)
int parse_line_for_section_flag (TZhuyinData *pZhuyinData, char *line_buf)
int parse_line_for_basedir_section (TZhuyinData *pZhuyinData, char *line_buf, char **pBaseDir)
int parse_line_for_datafile_section (TZhuyinData *pZhuyinData, char *line_buf, char **pDataFile)
int parse_line_for_keymap_section (TZhuyinData *pZhuyinData, char *line_buf)
 ZhuyinData_Read_Config (char *file_name, TZhuyinData *pZhuyinData)

Define Documentation

#define BASE_DIR_NAME_STRING   "path"

Definition at line 56 of file zhuyin_config.c.

#define BASE_DIR_STRING   "base_dir"

Definition at line 52 of file zhuyin_config.c.

#define DATA_FILE_NAME_STRING   "file"

Definition at line 57 of file zhuyin_config.c.

#define DATA_FILE_STRING   "data_file"

Definition at line 53 of file zhuyin_config.c.

#define KEYMAP_NAME_STRING   "name"

Definition at line 58 of file zhuyin_config.c.

#define KEYMAP_STRING   "keymap"

Definition at line 54 of file zhuyin_config.c.

#define MAX_LINE_LEN   256

Definition at line 50 of file zhuyin_config.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
ZHUYIN_DEFAULT_SECTION 
ZHUYIN_BASE_DIR_SECTION 
ZHUYIN_DATA_FILE_SECTION 
ZHUYIN_KEYMAP_SECTION 

Definition at line 60 of file zhuyin_config.c.


Function Documentation

int parse_line_for_basedir_section ( TZhuyinData pZhuyinData,
char *  line_buf,
char **  pBaseDir 
)

Definition at line 177 of file zhuyin_config.c.

{
       char *key_ptr, *value_ptr;

       parse_line_for_pair(line_buf, &key_ptr, &value_ptr);

       if (!strcasecmp(key_ptr, BASE_DIR_NAME_STRING)) {
              if (*pBaseDir != NULL) free((char *)*pBaseDir);
              *pBaseDir = (char *)strdup(value_ptr);
       }
       return(ZHUYIN_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int parse_line_for_datafile_section ( TZhuyinData pZhuyinData,
char *  line_buf,
char **  pDataFile 
)

Definition at line 190 of file zhuyin_config.c.

{
       char *key_ptr, *value_ptr;

       parse_line_for_pair(line_buf, &key_ptr, &value_ptr);

       if (!strcasecmp(key_ptr, DATA_FILE_NAME_STRING)) {
              if (*pDataFile != NULL) free((char *)*pDataFile);
              *pDataFile = (char *)strdup(value_ptr);
       }
       return(ZHUYIN_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int parse_line_for_keymap_name ( TZhuyinData pZhuyinData,
char *  line_buf 
)

Definition at line 216 of file zhuyin_config.c.

{
       char *key_ptr, *value_ptr;
       int nKeymap_ID;

       if (pZhuyinData->pZhuyinKeymapList->nNum_Keymaps == 0) {
              pZhuyinData->pZhuyinKeymapList->nNum_Keymaps++;
              ZhuyinKeymapList_Item_Prepare(pZhuyinData->pZhuyinKeymapList, 0);
              ZhuyinKeymapList_Item_Add_StandardKeymap(pZhuyinData->pZhuyinKeymapList, 0);
       }

       nKeymap_ID = pZhuyinData->pZhuyinKeymapList->nNum_Keymaps - 1;
       if (pZhuyinData->pZhuyinKeymapList->pKeymaps[nKeymap_ID]->pName != NULL)
              pZhuyinData->pZhuyinKeymapList->nNum_Keymaps ++;

       nKeymap_ID = pZhuyinData->pZhuyinKeymapList->nNum_Keymaps - 1;
       ZhuyinKeymapList_Item_Prepare(pZhuyinData->pZhuyinKeymapList, nKeymap_ID);

       parse_line_for_pair(line_buf, &key_ptr, &value_ptr);
       if (!strcasecmp(key_ptr, KEYMAP_NAME_STRING)) {
              ZhuyinKeymapList_Item_Set_Name(pZhuyinData->pZhuyinKeymapList, nKeymap_ID, value_ptr);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int parse_line_for_keymap_section ( TZhuyinData pZhuyinData,
char *  line_buf 
)

Definition at line 203 of file zhuyin_config.c.

{
       char *key_ptr, *value_ptr;
       int nKeymap_ID;

       parse_line_for_pair(line_buf, &key_ptr, &value_ptr);

       nKeymap_ID = pZhuyinData->pZhuyinKeymapList->nNum_Keymaps - 1;
       ZhuyinKeymapList_Item_Set_KeymapValue(pZhuyinData->pZhuyinKeymapList, nKeymap_ID, key_ptr, *value_ptr);

       return(ZHUYIN_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int parse_line_for_pair ( char *  line_buf,
char **  key_ptr,
char **  value_ptr 
)

Definition at line 120 of file zhuyin_config.c.

{
       char *ptr, *kptr, *vptr;

       *key_ptr = ptr = skip_space(line_buf);

       while(*ptr && !(*ptr==' ' || *ptr=='\t' || *ptr=='\n' || *ptr=='=' || *ptr==':')) ptr++;

       if (*ptr=='=' || *ptr==':') {
              *ptr = '\0';
              ptr = skip_space(ptr+1);
       } else if (*ptr==' ' || *ptr=='\t') {
              *ptr = '\0';
              ptr = skip_space(ptr+1);
              if (*ptr=='=' || *ptr==':') {
                     ptr = skip_space(ptr+1);
              }
       } else if (*ptr=='\n') {
              *ptr = '\0';
       }

       /* skip " */
       if (*ptr == '\"') ptr++;
       *value_ptr = ptr;
       
       ptr = to_space(ptr);
       if (*(ptr-1) == '\"') ptr--;
       *ptr = '\0';

       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int parse_line_for_section_flag ( TZhuyinData pZhuyinData,
char *  line_buf 
)

Definition at line 152 of file zhuyin_config.c.

{
       char *flag_section_str;

       int flag_section = ZHUYIN_DEFAULT_SECTION;

       /* Extract the name of section */
       line_buf[strlen(line_buf) - 1] = '\0';
       flag_section_str = trim_string(line_buf+1);

       if (!*flag_section_str) return(ZHUYIN_DEFAULT_SECTION);

       /* get flag_section */
       if (!(strncasecmp(flag_section_str, BASE_DIR_STRING, strlen(BASE_DIR_STRING)))) {
              flag_section = ZHUYIN_BASE_DIR_SECTION;
       } else if (!(strncasecmp(flag_section_str, DATA_FILE_STRING, strlen(DATA_FILE_STRING)))) {
              flag_section = ZHUYIN_DATA_FILE_SECTION;
       } else if (!(strncasecmp(flag_section_str, KEYMAP_STRING, strlen(KEYMAP_STRING)))) {
              flag_section = ZHUYIN_KEYMAP_SECTION;
              parse_line_for_keymap_name(pZhuyinData, flag_section_str + strlen(KEYMAP_STRING));
       }

       return(flag_section);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* skip_space ( char *  s)

Definition at line 83 of file zhuyin_config.c.

{
        while (*s && (*s == ' ' || *s == '\t')) s++;
        return s;
}
char* to_space ( char *  s)

Definition at line 89 of file zhuyin_config.c.

{
       while (*s && !(*s == ' ' || *s == '\t')) s++;
        return s;
}
char* trim_string ( char *  s)

Definition at line 95 of file zhuyin_config.c.

{
       char *head_ptr, *tail_ptr;

       if (!s || !*s) return(s);

       head_ptr = s;

       /* trim left space */
       while(*head_ptr && (*head_ptr == ' ' || *head_ptr == '\t' || *head_ptr == '\n'))
              head_ptr ++;

       if (!*head_ptr) return(head_ptr);

       /* trim right space */
       tail_ptr = head_ptr + strlen(head_ptr) - 1;
       
       while(*tail_ptr && (*tail_ptr == ' ' || *tail_ptr == '\t' || *tail_ptr == '\n')) {
              *tail_ptr = '\0';
              tail_ptr --;
       }

       return(head_ptr);
}
ZhuyinData_Read_Config ( char *  file_name,
TZhuyinData pZhuyinData 
)

Definition at line 240 of file zhuyin_config.c.

{
       FILE *ifile;
       char line_buf[MAX_LINE_LEN], *line_ptr;
       int flag_section;
       char *pBaseDir = NULL;
       char *pDataFile = NULL;
       char *data_base_dir, *data_file_name;
       char data_file_path[MAX_LINE_LEN];

       ifile = fopen(file_name, "r");
       if (ifile == NULL) {
              fprintf(stderr, "Error: open file %s\n", file_name);
              return(ZHUYIN_ERROR);
       }

       while(fgets(line_buf, MAX_LINE_LEN, ifile) != NULL) {
              line_ptr = trim_string(line_buf);

              if (*line_ptr && line_ptr[0] == '[' && line_ptr[strlen(line_ptr)-1] == ']') {
                     flag_section = parse_line_for_section_flag(pZhuyinData, line_ptr);
                     continue;
              }

              /* If space line or comment line */
              if (*line_ptr == '\0' || *line_ptr == '#') continue;

              switch (flag_section) {
                     case ZHUYIN_DEFAULT_SECTION:
                            break;

                     case ZHUYIN_BASE_DIR_SECTION:
                            parse_line_for_basedir_section(pZhuyinData, line_ptr, &pBaseDir);
                            break;

                     case ZHUYIN_DATA_FILE_SECTION:
                            parse_line_for_datafile_section(pZhuyinData, line_ptr, &pDataFile);
                            break;

                     case ZHUYIN_KEYMAP_SECTION:
                            parse_line_for_keymap_section(pZhuyinData, line_ptr);
                            break;
              }
       }

       pZhuyinData->data_file = NULL;

       if (pBaseDir)
              data_base_dir = pBaseDir;
       else
              data_base_dir = LE_IME_MODULES_DIR;

       if (pDataFile)
              data_file_name = pDataFile;
       else
              data_file_name = "data/zhuyin.data";

       snprintf(data_file_path, MAX_LINE_LEN, "%s/%s", data_base_dir, data_file_name);
       pZhuyinData->data_file = (char *)strdup(data_file_path);

       if (pBaseDir) free((char *)pBaseDir);
       if (pDataFile) free((char *)pDataFile);

       fclose(ifile);

       return(ZHUYIN_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function: