Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
qjbj_punct.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "config.h"
#include "encode.h"
#include "kolelog.h"

Go to the source code of this file.

Classes

struct  _FullWideChar_Struct
struct  _PunctChar_Struct

Defines

#define QJBJ_FILE_NAME   "QjBj.txt"
#define PUNCT_FILE_NAME   "Punct.txt"
#define MAX_LINE_LEN   256
#define FULLWIDE_CHAR_NUM   94
#define PUNCT_CHAR_NUM   18

Typedefs

typedef struct _FullWideChar_Struct FullWideChar_Struct
typedef struct _PunctChar_Struct PunctChar_Struct

Functions

void qjbjpunct_init ()
void qjbjpunct_done ()
void getline (FILE *fd, char *line)
int read_qjbj_config_file (int lang_id)
int read_punct_config_file (int lang_id)
char * get_qj_str (int lang_id, char ch)
char * get_punct_str (int lang_id, char ch)

Variables

char * FullWideCharListByLang_CN [FULLWIDE_CHAR_NUM]
char * FullWideCharListByLang_TW [FULLWIDE_CHAR_NUM]
char PunctChars [PUNCT_CHAR_NUM]
char * PunctCharListByLang_CN [PUNCT_CHAR_NUM]
char * PunctCharListByLang_TW [PUNCT_CHAR_NUM]
FullWideChar_Struct FullWideCharListByLang [LANGS_NUM]
PunctChar_Struct PunctCharListByLang [LANGS_NUM]

Class Documentation

struct _FullWideChar_Struct

Definition at line 21 of file qjbj_punct.c.

Class Members
char bInit
char * QjStr
struct _PunctChar_Struct

Definition at line 26 of file qjbj_punct.c.

Class Members
char bInit
char * PunctStr

Define Documentation

#define FULLWIDE_CHAR_NUM   94

Definition at line 18 of file qjbj_punct.c.

#define MAX_LINE_LEN   256

Definition at line 17 of file qjbj_punct.c.

#define PUNCT_CHAR_NUM   18

Definition at line 19 of file qjbj_punct.c.

#define PUNCT_FILE_NAME   "Punct.txt"

Definition at line 15 of file qjbj_punct.c.

#define QJBJ_FILE_NAME   "QjBj.txt"

Definition at line 14 of file qjbj_punct.c.


Typedef Documentation


Function Documentation

char* get_punct_str ( int  lang_id,
char  ch 
)

Definition at line 491 of file qjbj_punct.c.

{
       int i, ch_pos;
       char *str;

       if (lang_id < 0 || lang_id > LANGS_NUM) 
              return(NULL);

       if (PunctCharListByLang[lang_id].bInit == 0)
              read_punct_config_file(lang_id);


       ch_pos = -1;
       for (i=0; i<PUNCT_CHAR_NUM; i++) {
              if (ch == PunctChars[i]) {
                     ch_pos = i;
                     break;
              }
       }
       if (ch_pos == -1)
              return(NULL);

       str = PunctCharListByLang[lang_id].PunctStr[ch_pos];

       if (str != NULL) return(str);

       if (lang_id == LANG_ZH_CN) 
              return(PunctCharListByLang_CN[ch_pos]);
       else if (lang_id == LANG_ZH_TW || lang_id == LANG_ZH_HK)
              return(PunctCharListByLang_TW[ch_pos]);
       else 
              return(NULL);
}

Here is the call graph for this function:

char* get_qj_str ( int  lang_id,
char  ch 
)

Definition at line 463 of file qjbj_punct.c.

{
       int ch_pos;
       char *str;

       if (lang_id < 0 || lang_id > LANGS_NUM) 
              return(NULL);

       if (FullWideCharListByLang[lang_id].bInit == 0)
              read_qjbj_config_file(lang_id);

       ch_pos = ch - 0x21;

       if (ch_pos < 0 || ch_pos >= FULLWIDE_CHAR_NUM)
              return(NULL);

       str = FullWideCharListByLang[lang_id].QjStr[ch_pos];

       if (str != NULL) return(str);

       if (lang_id == LANG_ZH_CN) 
              return(FullWideCharListByLang_CN[ch_pos]);
       else if (lang_id == LANG_ZH_TW || lang_id == LANG_ZH_HK)
              return(FullWideCharListByLang_TW[ch_pos]);
       else 
              return(NULL);
}

Here is the call graph for this function:

void getline ( FILE *  fd,
char *  line 
)

Definition at line 314 of file qjbj_punct.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++;

              while (isspace(line[line_ptr-1])) line_ptr--;
              line[line_ptr] = '\0';

              break;
       }
}

Here is the caller graph for this function:

void qjbjpunct_done ( )

Definition at line 294 of file qjbj_punct.c.

{
       int lang_id, char_id;
       char *str;

       for (lang_id=0; lang_id<LANGS_NUM; lang_id++) {
              FullWideCharListByLang[lang_id].bInit = 0;
              for (char_id=0; char_id<FULLWIDE_CHAR_NUM; char_id++) {
                     str = (char *)FullWideCharListByLang[lang_id].QjStr[char_id];
                     if (str != NULL) free(str);
              }

              PunctCharListByLang[lang_id].bInit = 0;
              for (char_id=0; char_id<PUNCT_CHAR_NUM; char_id++) {
                     str = (char *)PunctCharListByLang[lang_id].PunctStr[char_id];
                     if (str != NULL) free(str);
              }
       }
}
void qjbjpunct_init ( )

Definition at line 277 of file qjbj_punct.c.

{
       int lang_id, char_id;

       for (lang_id=0; lang_id<LANGS_NUM; lang_id++) {
              FullWideCharListByLang[lang_id].bInit = 0;
              for (char_id=0; char_id<FULLWIDE_CHAR_NUM; char_id++) {
                     FullWideCharListByLang[lang_id].QjStr[char_id] = NULL;
              }

              PunctCharListByLang[lang_id].bInit = 0;
              for (char_id=0; char_id<PUNCT_CHAR_NUM; char_id++) {
                     PunctCharListByLang[lang_id].PunctStr[char_id] = NULL;
              }
       }
}
int read_punct_config_file ( int  lang_id)

Definition at line 401 of file qjbj_punct.c.

{
       char   file_name[256], line[MAX_LINE_LEN];
       char   ch, *kptr, *ptr, *lang_name;
       int    i, ch_pos, len;
       FILE   *fd;

       PunctCharListByLang[lang_id].bInit = 1;

       lang_name = (char *)get_langname_from_langid(lang_id);
       sprintf(file_name, "%s/%s", LE_IME_MODULES_DIR, PUNCT_FILE_NAME);
       KOLE_LOG (LOGDEST_STDOUT, "file_name:%s\n", file_name);

       fd = fopen(file_name, "r");
       if (!fd) {
              KOLE_LOG (LOGDEST_STDOUT, "Can not open the file:%s\n", file_name);
              return(-1);
       }

       do {
              getline(fd, line);

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

              kptr = ptr = line;
              while(*ptr && !isspace(*ptr))  ptr++;
              if (!(*ptr)) continue;

              *ptr++ = '\0';

              len = strlen(kptr);
              if (len > 2) continue;

              if (len == 2) {
                     if (*kptr == '\\')
                            ch = *(kptr + 1);
                     else
                            continue;
              } else if (len == 1) {
                     ch = *kptr;
              }

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

              ch_pos = -1;
              for (i=0; i<PUNCT_CHAR_NUM; i++) {
                     if (ch == PunctChars[i]) {
                            ch_pos = i;
                            break;
                     }
              }
              if (ch_pos == -1) continue;
              PunctCharListByLang[lang_id].PunctStr[ch_pos] = (char *)strdup(ptr);
       } while (1);

       fclose(fd);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int read_qjbj_config_file ( int  lang_id)

Definition at line 343 of file qjbj_punct.c.

{
       char   file_name[256], line[MAX_LINE_LEN];
       char   ch, *kptr, *ptr, *lang_name;
       int    ch_pos, len;
       FILE   *fd;

       FullWideCharListByLang[lang_id].bInit = 1;

       lang_name = (char *)get_langname_from_langid(lang_id);
       KOLE_LOG (LOGDEST_STDOUT, "lang_name:%s\n", lang_name);
       sprintf(file_name, "%s/%s", LE_IME_MODULES_DIR, QJBJ_FILE_NAME);
       KOLE_LOG (LOGDEST_STDOUT, "file_name:%s\n", file_name);

       fd = fopen(file_name, "r");
       if (!fd) {
              KOLE_LOG (LOGDEST_STDOUT, "Can not open the file:%s\n", file_name);
              return(-1);
       }

       do {
              getline(fd, line);

              if (line[0] == '\0') break;
              if (line[0] == '#') continue;
              KOLE_LOG (LOGDEST_STDOUT, "line:%s#\n", line);

              kptr = ptr = line;
              while(*ptr && !isspace(*ptr))  ptr++;
              if (!(*ptr)) continue;

              *ptr++ = '\0';

              len = strlen(kptr);
              if (len > 2) continue;

              if (len == 2) {
                     if (*kptr == '\\')
                            ch = *(kptr + 1);
                     else
                            continue;
              } else if (len == 1) {
                     ch = *kptr;
              }

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

              ch_pos = ch - 0x21;
              FullWideCharListByLang[lang_id].QjStr[ch_pos] = (char *)strdup(ptr);

       } while (1);

       fclose(fd);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 274 of file qjbj_punct.c.

Definition at line 31 of file qjbj_punct.c.

Definition at line 128 of file qjbj_punct.c.

Definition at line 275 of file qjbj_punct.c.

Initial value:
 {
       "!",
       "“",
       "¥",
       "─",
       "‘",
       "(",
       ")",
       ",",
       "。",
       ":",
       ";",
       "》",
       "《",
       "?",
       "@",
       "、",
       "…",
       "__",
}

Definition at line 232 of file qjbj_punct.c.

Initial value:
 {
       "!",
       "“",
       "NT$",
       "─",
       "‘",
       "(",
       ")",
       ",",
       "。",
       ":",
       ";",
       "《",
       "》",
       "?",
       "@",
       "\",
       "…",
       "__",
}

Definition at line 253 of file qjbj_punct.c.

Initial value:
 {
       '!',     '"',     '$',     '&',     '\'',
       '(',     ')',     ',',     '.',
       ':',     ';',     '<',     '>',     '?',
       '@',     '\\',    '^',     '_'   
}

Definition at line 225 of file qjbj_punct.c.