1
/* Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either
6
* version 2.1 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library; if not, write to the Free Software
15
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "pho-status.h"
24
extern void key_typ_pho(phokey_t phokey, u_char rtyp_pho[]);
26
gboolean pin2juyin(gboolean full_match)
31
bzero(poo.typ_pho, sizeof(poo.typ_pho));
32
if (poo.inph[0]=='`') {
33
poo.typ_pho[0]=BACK_QUOTE_NO;
34
poo.typ_pho[1]=poo.inph[1];
38
int inphN = strlen(poo.inph);
39
for(i=0; i < pin_juyinN; i++) {
40
bzero(pin, sizeof(pin));
41
memcpy(pin, pin_juyin[i].pinyin, sizeof(pin_juyin[0].pinyin));
43
int pinN = strlen(pin);
47
if (full_match && pinN != inphN)
50
if (!memcmp(pin, poo.inph, inphN)) {
51
// dbg("pin %s %s\n", pin, poo.inph);
52
// prph(pin_juyin[i].key);
58
dbg("pin2juyin not found ..\n");
62
bzero(poo.typ_pho, sizeof(poo.typ_pho));
63
// prph(pin_juyin[i].key); dbg(" %x ph\n", pin_juyin[i].key);
64
key_typ_pho(pin_juyin[i].key, (u_char *)poo.typ_pho);
66
// dbg("pin2juyin found %d\n", poo.typ_pho[0]);
72
gboolean inph_typ_pho_pinyin(int newkey)
76
// dbg("inph_typ_pho_pinyin '%c'\n", newkey);
79
char num = phkbm.phokbm[newkey][0].num;
80
int typ = phkbm.phokbm[newkey][0].typ;
82
// dbg("cccc num %d typ:%d\n", num, typ);
86
poo.typ_pho[typ] = num;
87
// tss.chpho[tss.c_idx].flag |=FLAG_CHPHO_PINYIN_TONE;
88
// dbg("set %d\n",tss.c_idx);
90
// poo.typ_pho[typ]= PHO_PINYIN_TONE1;
91
return PHO_STATUS_OK_NEW | PHO_STATUS_TONE;
94
// dbg("'%c' %d\n", newkey, typ);
101
poo.inph[i] = newkey;
104
if (pin2juyin(newkey==' ')) {
107
return PHO_STATUS_OK_NEW;
108
if (poo.typ_pho[0]==BACK_QUOTE_NO && poo.typ_pho[1])
109
return PHO_STATUS_OK_NEW | PHO_STATUS_TONE;
110
// dbg("ok %d\n", poo.typ_pho[0]);
111
return PHO_STATUS_OK;
114
// dbg("yyy %d\n", i);
118
return PHO_STATUS_REJECT;
120
// v is not used as the first key
122
for(j=0; j < pin_juyinN; j++)
123
if (pin_juyin[j].pinyin[0]==newkey)
128
return PHO_STATUS_REJECT;
130
bzero(poo.inph, sizeof(poo.inph));
132
return PHO_STATUS_OK_NEW|PHO_STATUS_PINYIN_LEFT;
135
extern int text_pho_N;
137
void load_pin_juyin()
142
get_sys_table_file_name("pin-juyin.xlt", pinfname);
143
// dbg("pinyin kbm %s\n", pinfname);
146
if ((fr=fopen(pinfname,"rb"))==NULL)
147
p_err("Cannot open %s", pinfname);
149
fread(&pin_juyinN, sizeof(short), 1, fr);
150
pin_juyin = tmalloc(PIN_JUYIN, pin_juyinN);
151
fread(pin_juyin, sizeof(PIN_JUYIN), pin_juyinN, fr);