gencin.c
来自「linux 下的 oxim 输入法,简单易用.」· C语言 代码 · 共 681 行 · 第 1/2 页
C
681 行
/* Copyright (C) 2006 by OXIM TEAM This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/ #ifdef HAVE_CONFIG_H# include "config.h"#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <locale.h>#include <unistd.h>#include "oximtool.h"#include "oxim-conv.h"static char validkey[128];static cintab_head_v1_t th;static cintab_locale_table *locale_table = NULL;static cintab_setting_table *setting_table = NULL;/* 所有詞的字元數目 */static char *word_table = NULL;static char *default_selection_keys = "1234567890";/*-------------------------------------------------------------------------- Normal cin2tab functions.--------------------------------------------------------------------------*/static void cin_keepcase(char *arg, cintab_t *cintab){ th.keep_key_case = True;}static voidcin_ename(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } strncpy(th.orig_name, arg, N_NAME_LENGTH); th.orig_name[N_NAME_LENGTH - 1] = '\0';}static voidcin_cname(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } if( (strlen(th.cname)+strlen(arg)) < N_NAME_LENGTH ) strcat(th.cname, arg);}static voidcin_cname_scim(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } if( (strlen(th.orig_name)+strlen(arg)) < N_NAME_LENGTH ) strcat(th.orig_name, arg);}static voidcin_name(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } th.n_locale ++; if (th.n_locale == 1) { locale_table = oxim_malloc(sizeof(cintab_locale_table), False); } else { locale_table = oxim_realloc(locale_table, th.n_locale * sizeof(cintab_locale_table)); } strcpy(locale_table[th.n_locale - 1].locale, "zh_TW"); strncpy(locale_table[th.n_locale - 1].name, arg, N_NAME_LENGTH); locale_table[th.n_locale - 1].name[N_NAME_LENGTH - 1] = '\0';}static voidcin_selkey(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } th.n_selection_key = strlen(arg); if (th.n_selection_key > N_KEYS) { oxim_perr(OXIMMSG_NORMAL, N_("%s(%d): too many selection keys defined.\n"), cintab->fname_cin, cintab->lineno); th.n_selection_key = 10; strcpy(th.selection_keys, "1234567890"); } else { strcpy(th.selection_keys, arg); } /* 設定合法字元表 */ char *s = th.selection_keys; for (; *s ; s++) { validkey[*s] = '\1'; }}static voidscim_selkey(char *arg, cintab_t *cintab){ unsigned int i; unsigned int len = strlen(arg); char selection_keys[256]; if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } bzero(selection_keys, 256); char *s = selection_keys; for (i=0 ; i < len; i++) { if (arg[i] != ',') { *s = arg[i]; s++; } } th.n_selection_key = strlen(selection_keys); if (th.n_selection_key > N_KEYS) { oxim_perr(OXIMMSG_NORMAL, N_("SCIM table \"%s\" line %d: too many selection keys defined. Use default selection keys \"%s\".\n"), cintab->fname_cin, cintab->lineno, default_selection_keys); th.n_selection_key = strlen(default_selection_keys); strcpy(th.selection_keys, default_selection_keys); } else { strcpy(th.selection_keys, selection_keys); } /* 設定合法字元表 */ s = th.selection_keys; for (; *s ; s++) { validkey[*s] = '\1'; }}static voidcin_endkey(char *arg, cintab_t *cintab){ if (!arg) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): arguement expected.\n"), cintab->fname_cin, cintab->lineno); return; } th.n_end_key = strlen(arg); if (th.n_end_key > N_KEYS) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): too many end keys defined.\n"), cintab->fname_cin, cintab->lineno); return; } strcpy(th.end_keys, arg); /* 設定合法字元表 */ char *s = th.end_keys; for (; *s ; s++) { validkey[*s] = '\1'; }}static voidcin_setting(char *arg, cintab_t *cintab){ char cmd1[N_SETTING_NAME_LENGTH], arg1[N_SETTING_VALUE_LENGTH]; int i, argc; while (argc = cmd_arg(True, cmd1, N_SETTING_NAME_LENGTH, arg1, N_SETTING_VALUE_LENGTH, NULL)) { if (strcasecmp("%setting", cmd1) == 0 && strcasecmp("end", arg1) == 0) { break; } if (argc != 2) { continue; } /* 檢查是否重複定義 */ int isduplicate = False; for (i = 0 ; i < th.n_setting ; i++) { if (strcasecmp(setting_table[i].key, cmd1) == 0) { isduplicate = True; break; } } if (isduplicate) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): setting->'%s %s' is already defined, overwrite it.\n"), cintab->fname_cin, cintab->lineno, cmd1, arg1); strcpy(setting_table[i].value, arg1); continue; } th.n_setting ++; if (th.n_setting == 1) { setting_table = oxim_malloc(sizeof(cintab_setting_table), False); } else { setting_table = oxim_realloc(setting_table, sizeof(cintab_setting_table) * th.n_setting); } strcpy(setting_table[th.n_setting-1].key, cmd1); strcpy(setting_table[th.n_setting-1].value, arg1); }}static voidcin_keyname(char *arg, cintab_t *cintab){ char cmd1[64], arg1[64]; int k, argc; while (argc = cmd_arg(True, cmd1, 64, arg1, 64, NULL)) { if ((strcasecmp("%keyname", cmd1) == 0 && strcasecmp("end", arg1) == 0) || strcasecmp("END_CHAR_PROMPTS_DEFINITION", cmd1) == 0) { break; } if (argc != 2 || strlen(cmd1) != 1) { continue; } k = cmd1[0]; if (k <= 0x20 || k > 0x7e) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): illegal key \"%c\" specified.\n"), cintab->fname_cin, cintab->lineno, k); continue; } if (!th.keep_key_case && k >= 'A' && k <= 'Z') { k = tolower(k); cmd1[0] = k; } if (th.keyname[k].uch) { oxim_perr(OXIMMSG_WARNING, N_("%s(%d): key \"%c\" is already in used, overwrite it.\n"), cintab->fname_cin, cintab->lineno, cmd1[0]); strncpy((char *)th.keyname[k].s, arg1, UCH_SIZE); continue; } strncpy((char *)th.keyname[k].s, arg1, UCH_SIZE); validkey[k] = '\1'; th.n_key_name++; }}/*------------------------------------------------------------------------*/typedef struct { unsigned char key_len; char *keystroke; unsigned int order; unsigned char word_len; unsigned int *word;} cin_char_t;static cin_char_t *cchar = NULL;static intchar_cmp(const void *a, const void *b){ cintab_char_index *aa=(cintab_char_index *)a; cintab_char_index *bb=(cintab_char_index *)b; if (aa->ucs4 == bb->ucs4) return 0; else if (aa->ucs4 > bb->ucs4) return 1; else return -1;}static inticode_cmp(const void *a, const void *b){ cin_char_t *aa=(cin_char_t *)a, *bb=(cin_char_t *)b; int cmp_val = strcmp(aa->keystroke, bb->keystroke);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?