34
34
#include "fcitx/ime.h"
35
35
#include "fcitx/keys.h"
36
36
#include "fcitx/ui.h"
37
#include "fcitx/frontend.h"
38
#include "fcitx/module.h"
39
#include "fcitx/context.h"
40
#include "fcitx/profile.h"
41
#include "fcitx/configfile.h"
42
#include "fcitx-config/xdg.h"
43
#include "fcitx-utils/utf8.h"
44
#include "fcitx-utils/log.h"
39
47
#include "pyParser.h"
41
#include "fcitx-utils/utf8.h"
42
#include "fcitx/profile.h"
43
#include "fcitx/configfile.h"
44
#include "fcitx-utils/log.h"
45
#include "fcitx-config/xdg.h"
46
49
#include "pyconfig.h"
47
#include "fcitx/instance.h"
48
#include "fcitx/frontend.h"
49
#include "fcitx/module.h"
50
#include "fcitx/candidate.h"
51
#include "fcitx/context.h"
52
50
#include "spdata.h"
51
#include "module/quickphrase/fcitx-quickphrase.h"
54
53
#define PY_INDEX_MAGIC_NUMBER 0xf7462e34
55
54
#define PINYIN_TEMP_FILE "pinyin_XXXXXX"
64
int ABI_VERSION = FCITX_ABI_VERSION;
66
const UT_icd pycand_icd = {sizeof(PYCandWord*) , NULL, NULL, NULL };
68
typedef struct _PYCandWordSortContext {
69
57
PY_CAND_WORD_TYPE type;
71
59
FcitxPinyinState* pystate;
72
60
} PYCandWordSortContext;
74
static void LoadPYPhraseDict(FcitxPinyinState* pystate, FILE* fp, boolean isSystem, boolean stripDup);
75
static void * LoadPYBaseDictWrapper(void* arg, FcitxModuleFunctionArg args);
76
static void * PYGetPYByHZWrapper(void* arg, FcitxModuleFunctionArg args);
77
static void * DoPYInputWrapper(void* arg, FcitxModuleFunctionArg args);
78
static void * PYGetCandWordsWrapper(void* arg, FcitxModuleFunctionArg args);
79
static void * PYGetFindStringWrapper(void* arg, FcitxModuleFunctionArg args);
80
static void * PYResetWrapper(void* arg, FcitxModuleFunctionArg args);
62
static void LoadPYPhraseDict(FcitxPinyinState* pystate, FILE* fp,
63
boolean isSystem, boolean stripDup);
81
64
static void ReloadConfigPY(void* arg);
82
65
static void PinyinMigration();
83
66
static int PYCandWordCmp(const void* b, const void* a, void* arg);
84
static void* PYSP2QP(void* arg, FcitxModuleFunctionArg args);
85
static boolean PYGetPYMapByHZ(FcitxPinyinState*pystate, char *strHZ, char* mapHint, char *strMap);
86
static void PYAddUserPhraseFromCString(void* arg, FcitxModuleFunctionArg args);
67
static boolean PYGetPYMapByHZ(FcitxPinyinState*pystate, char *strHZ,
68
char* mapHint, char *strMap);
70
FCITX_DEFINE_PLUGIN(fcitx_pinyin, ime2, FcitxIMClass2) = {
81
DECLARE_ADDFUNCTIONS(Pinyin)
88
83
void *PYCreate(FcitxInstance* instance)
90
FcitxPinyinState *pystate = fcitx_utils_malloc0(sizeof(FcitxPinyinState));
91
FcitxAddon* pyaddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_PINYIN_NAME);
85
FcitxPinyinState *pystate = fcitx_utils_new(FcitxPinyinState);
92
86
InitMHPY(&pystate->pyconfig.MHPY_C, MHPY_C_TEMPLATE);
93
87
InitMHPY(&pystate->pyconfig.MHPY_S, MHPY_S_TEMPLATE);
94
88
InitPYTable(&pystate->pyconfig);
106
101
pystate->pool = fcitx_memory_pool_create();
108
103
FcitxInstanceRegisterIM(instance,
124
118
FcitxInstanceRegisterIM(instance,
140
133
pystate->owner = instance;
142
/* ensure the order! */
143
AddFunction(pyaddon, LoadPYBaseDictWrapper); // 0
144
AddFunction(pyaddon, PYGetPYByHZWrapper); // 1
145
AddFunction(pyaddon, DoPYInputWrapper); // 2
146
AddFunction(pyaddon, PYGetCandWordsWrapper); // 3
147
AddFunction(pyaddon, PYGetFindStringWrapper); // 4
148
AddFunction(pyaddon, PYResetWrapper); // 5
149
AddFunction(pyaddon, PYSP2QP); // 6
150
AddFunction(pyaddon, PYAddUserPhraseFromCString); // 6
135
FcitxPinyinAddFunctions(instance);
139
void PYDestroy(void* arg)
141
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
142
free(pystate->pyconfig.MHPY_C);
143
free(pystate->pyconfig.MHPY_S);
144
free(pystate->pyconfig.PYTable);
145
FreePYSplitData(&pystate->pyconfig);
146
FcitxConfigFree(&pystate->pyconfig.gconfig);
147
fcitx_memory_pool_destroy(pystate->pool);
150
PYFA *PYFAList = pystate->PYFAList;
151
for (i = 0; i < pystate->iPYFACount; i++) {
152
for (j = 0; j < PYFAList[i].iBase; j++) {
153
PyPhrase* phrase = USER_PHRASE_NEXT(PYFAList[i].pyBase[j].userPhrase);
154
for (k = 0; k < PYFAList[i].pyBase[j].iUserPhrase; k++) {
155
PyPhrase* cur = phrase;
156
fcitx_utils_free(cur->strPhrase);
157
fcitx_utils_free(cur->strMap);
158
phrase = USER_PHRASE_NEXT(phrase);
162
free(PYFAList[i].pyBase[j].userPhrase);
163
fcitx_utils_free(PYFAList[i].pyBase[j].phrase);
165
free(PYFAList[i].pyBase);
169
while(pystate->pyFreq) {
170
PyFreq* pCurFreq = pystate->pyFreq;
171
pystate->pyFreq = pCurFreq->next;
172
while (pCurFreq->HZList) {
173
HZ* pHZ = pCurFreq->HZList;
174
pCurFreq->HZList = pHZ->next;
154
183
boolean PYInit(void *arg)
156
185
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
180
209
boolean LoadPYBaseDict(FcitxPinyinState *pystate)
185
215
fp = FcitxXDGGetFileWithPrefix("pinyin", PY_BASE_FILE, "r", NULL);
189
fread(&pystate->iPYFACount, sizeof(int), 1, fp);
190
pystate->PYFAList = (PYFA *) fcitx_utils_malloc0(sizeof(PYFA) * pystate->iPYFACount);
191
PYFA* PYFAList = pystate->PYFAList;
219
fcitx_utils_read_int32(fp, &pystate->iPYFACount);
220
pystate->PYFAList = (PYFA*)fcitx_utils_malloc0(sizeof(PYFA) * pystate->iPYFACount);
221
PYFA *PYFAList = pystate->PYFAList;
192
222
for (i = 0; i < pystate->iPYFACount; i++) {
193
223
fread(PYFAList[i].strMap, sizeof(char) * 2, 1, fp);
194
224
PYFAList[i].strMap[2] = '\0';
196
fread(&(PYFAList[i].iBase), sizeof(int), 1, fp);
197
PYFAList[i].pyBase = (PyBase *) fcitx_utils_malloc0(sizeof(PyBase) * PYFAList[i].iBase);
226
fcitx_utils_read_int32(fp, &PYFAList[i].iBase);
227
PYFAList[i].pyBase = (PyBase*)fcitx_utils_malloc0(sizeof(PyBase) * PYFAList[i].iBase);
198
228
for (j = 0; j < PYFAList[i].iBase; j++) {
200
230
fread(&len, sizeof(char), 1, fp);
201
231
fread(PYFAList[i].pyBase[j].strHZ, sizeof(char) * len, 1, fp);
202
232
PYFAList[i].pyBase[j].strHZ[len] = '\0';
203
fread(&iLen, sizeof(int), 1, fp);
233
fcitx_utils_read_int32(fp, &iLen);
204
234
PYFAList[i].pyBase[j].iIndex = iLen;
205
235
PYFAList[i].pyBase[j].iHit = 0;
206
236
if (iLen > pystate->iCounter)
207
237
pystate->iCounter = iLen;
208
238
PYFAList[i].pyBase[j].iPhrase = 0;
209
239
PYFAList[i].pyBase[j].iUserPhrase = 0;
210
PYFAList[i].pyBase[j].userPhrase = (PyUsrPhrase *) fcitx_utils_malloc0(sizeof(PyUsrPhrase));
240
PYFAList[i].pyBase[j].userPhrase = fcitx_utils_new(PyUsrPhrase);
211
241
PYFAList[i].pyBase[j].userPhrase->next = PYFAList[i].pyBase[j].userPhrase;
218
248
pystate->iOrigCounter = pystate->iCounter;
220
pystate->pyFreq = (PyFreq *) fcitx_utils_malloc0(sizeof(PyFreq));
221
pystate->pyFreq->next = NULL;
250
pystate->pyFreq = fcitx_utils_new(PyFreq);
251
// pystate->pyFreq->next = NULL;
226
256
void LoadPYPhraseDict(FcitxPinyinState* pystate, FILE *fp, boolean isSystem, boolean stripDup)
228
int i, j , k, count, iLen;
259
int32_t i, count, iLen;
229
260
char strBase[UTF8_MAX_LENGTH + 1];
230
261
PyPhrase *phrase = NULL, *temp;
231
262
PYFA* PYFAList = pystate->PYFAList;
232
263
while (!feof(fp)) {
234
if (!fread(&i, sizeof(int), 1, fp))
265
if (!fcitx_utils_read_int32(fp, &i))
236
267
if (!fread(&clen, sizeof(int8_t), 1, fp))
258
289
for (k = 0; k < count; k++) {
260
phrase = (PyPhrase *) fcitx_utils_malloc0(sizeof(PyUsrPhrase));
262
fread(&iLen, sizeof(int), 1, fp);
265
phrase->strMap = (char* ) fcitx_memory_pool_alloc(pystate->pool, sizeof(char) * (iLen + 1));
267
phrase->strMap = (char *) fcitx_utils_malloc0(sizeof(char) * (iLen + 1));
291
phrase = (PyPhrase*)fcitx_utils_malloc0(sizeof(PyUsrPhrase));
293
fcitx_utils_read_int32(fp, &iLen);
296
phrase->strMap = (char*)fcitx_memory_pool_alloc(pystate->pool, sizeof(char) * (iLen + 1));
298
phrase->strMap = (char*)fcitx_utils_malloc0(sizeof(char) * (iLen + 1));
268
300
fread(phrase->strMap, sizeof(char) * iLen, 1, fp);
269
301
phrase->strMap[iLen] = '\0';
271
fread(&iLen, sizeof(int), 1, fp);
303
fcitx_utils_read_int32(fp, &iLen);
274
phrase->strPhrase = (char* ) fcitx_memory_pool_alloc(pystate->pool, sizeof(char) * (iLen + 1));
276
phrase->strPhrase = (char *) fcitx_utils_malloc0(sizeof(char) * (iLen + 1));
306
phrase->strPhrase = (char*)fcitx_memory_pool_alloc(pystate->pool, sizeof(char) * (iLen + 1));
308
phrase->strPhrase = (char*)fcitx_utils_malloc0(sizeof(char) * (iLen + 1));
277
310
fread(phrase->strPhrase, sizeof(char) * iLen, 1, fp);
278
311
phrase->strPhrase[iLen] = '\0';
280
fread(&iLen, sizeof(unsigned int), 1, fp);
313
fcitx_utils_read_int32(fp, &iLen);
281
314
phrase->iIndex = iLen;
282
315
if (iLen > pystate->iCounter)
283
316
pystate->iCounter = iLen;
396
429
fp = FcitxXDGGetFileUserWithPrefix("pinyin", PY_INDEX_FILE, "r", NULL);
398
431
uint32_t magic = 0;
399
fread(&magic, sizeof(uint32_t), 1, fp);
432
fcitx_utils_read_uint32(fp, &magic);
400
433
if (magic == PY_INDEX_MAGIC_NUMBER) {
401
fread(&iLen, sizeof(uint), 1, fp);
434
fcitx_utils_read_int32(fp, &iLen);
402
435
if (iLen > pystate->iCounter)
403
436
pystate->iCounter = iLen;
404
437
while (!feof(fp)) {
405
fread(&i, sizeof(int), 1, fp);
406
fread(&j, sizeof(int), 1, fp);
407
fread(&k, sizeof(int), 1, fp);
408
fread(&iIndex, sizeof(uint), 1, fp);
409
fread(&iLen, sizeof(uint), 1, fp);
438
fcitx_utils_read_int32(fp, &i);
439
fcitx_utils_read_int32(fp, &j);
440
fcitx_utils_read_int32(fp, &k);
441
fcitx_utils_read_uint32(fp, &iIndex);
442
fcitx_utils_read_int32(fp, &iLen);
411
444
if (i < pystate->iPYFACount) {
412
445
if (j < PYFAList[i].iBase) {
434
467
pPyFreq = pystate->pyFreq;
436
fread(&pystate->iPYFreqCount, sizeof(uint), 1, fp);
469
fcitx_utils_read_uint32(fp, &pystate->iPYFreqCount);
438
471
for (i = 0; i < pystate->iPYFreqCount; i++) {
439
pyFreqTemp = (PyFreq *) fcitx_utils_malloc0(sizeof(PyFreq));
440
pyFreqTemp->next = NULL;
441
pyFreqTemp->bIsSym = false;
472
pyFreqTemp = fcitx_utils_new(PyFreq);
473
// pyFreqTemp->next = NULL;
443
475
fread(pyFreqTemp->strPY, sizeof(char) * 11, 1, fp);
444
fread(&j, sizeof(int), 1, fp);
445
pyFreqTemp->iCount = j;
476
fcitx_utils_read_uint32(fp, &pyFreqTemp->iCount);
447
pyFreqTemp->HZList = (HZ *) fcitx_utils_malloc0(sizeof(HZ));
448
pyFreqTemp->HZList->next = NULL;
478
pyFreqTemp->HZList = fcitx_utils_new(HZ);
479
// pyFreqTemp->HZList->next = NULL;
449
480
pHZ = pyFreqTemp->HZList;
451
482
for (k = 0; k < pyFreqTemp->iCount; k++) {
453
HZTemp = (HZ *) fcitx_utils_malloc0(sizeof(HZ));
484
HZTemp = fcitx_utils_new(HZ);
454
485
fread(&slen, sizeof(int8_t), 1, fp);
455
486
fread(HZTemp->strHZ, sizeof(char) * slen, 1, fp);
456
487
HZTemp->strHZ[slen] = '\0';
457
fread(&j, sizeof(int), 1, fp);
459
fread(&j, sizeof(int), 1, fp);
461
fread(&j, sizeof(int), 1, fp);
488
fcitx_utils_read_int32(fp, &HZTemp->iPYFA);
489
fcitx_utils_read_uint32(fp, &HZTemp->iHit);
490
fcitx_utils_read_uint32(fp, &HZTemp->iIndex);
463
491
pHZ->next = HZTemp;
474
fp = FcitxXDGGetFileWithPrefix("pinyin", PY_SYMBOL_FILE, "r", NULL);
476
char* buf = NULL, *buf1 = NULL;
479
while (getline(&buf, &len, fp) != -1) {
482
buf1 = fcitx_utils_trim(buf);
485
while (*p && !isspace(*p))
487
if (*p == '\0' || *p == '#')
490
while (isspace(*p)) {
495
if (strlen(buf1) >= MAX_PY_PHRASE_LENGTH * MAX_PY_LENGTH)
498
if (strlen(p) >= MAX_PY_PHRASE_LENGTH * UTF8_MAX_LENGTH)
502
pyFreqTemp = pystate->pyFreq->next;
503
pPyFreq = pystate->pyFreq;
505
if (!strcmp(pyFreqTemp->strPY, buf1))
507
pPyFreq = pPyFreq->next;
508
pyFreqTemp = pyFreqTemp->next;
512
pyFreqTemp = (PyFreq *) fcitx_utils_malloc0(sizeof(PyFreq));
513
strcpy(pyFreqTemp->strPY, buf1);
514
pyFreqTemp->next = NULL;
515
pyFreqTemp->iCount = 0;
516
pyFreqTemp->bIsSym = true;
517
pyFreqTemp->HZList = (HZ *) fcitx_utils_malloc0(sizeof(HZ));
518
pyFreqTemp->HZList->next = NULL;
519
pPyFreq->next = pyFreqTemp;
520
pystate->iPYFreqCount++;
522
if (!pyFreqTemp->bIsSym) //不能与常用字的编码相同
526
HZTemp = (HZ *) fcitx_utils_malloc0(sizeof(HZ));
527
strcpy(HZTemp->strHZ, p);
529
pyFreqTemp->iCount++;
531
pHZ = pyFreqTemp->HZList;
597
551
/* is not in py special state */
598
552
if (!pystate->bIsPYAddFreq && !pystate->bIsPYDelFreq && !pystate->bIsPYDelUserPhr) {
599
553
if ((FcitxHotkeyIsHotKeyLAZ(sym, state)
600
|| FcitxHotkeyIsHotKey(sym, state, FCITX_SEPARATOR)
601
|| (pystate->bSP && FcitxInputStateGetRawInputBufferSize(input) > 0 && pystate->bSP_UseSemicolon && FcitxHotkeyIsHotKey(sym, state, FCITX_SEMICOLON)))) {
554
|| FcitxHotkeyIsHotKey(sym, state, FCITX_SEPARATOR)
555
|| (pystate->bSP && FcitxInputStateGetRawInputBufferSize(input) > 0 && pystate->bSP_UseSemicolon && FcitxHotkeyIsHotKey(sym, state, FCITX_SEMICOLON)))) {
602
556
FcitxInputStateSetIsInRemind(input, false);
603
557
FcitxInputStateSetShowCursor(input, true);
646
611
retVal = IRV_DISPLAY_CANDWORDS;
647
612
} else if (pystate->iPYInsertPoint) {
613
char *move_src = (pystate->strFindString
614
+ pystate->iPYInsertPoint);
648
615
/* we cannot delete it if cursor is at the first */
649
616
val = ((pystate->iPYInsertPoint > 1)
650
&& (pystate->strFindString[pystate->iPYInsertPoint - 2] == PY_SEPARATOR)) ? 2 : 1;
651
int len = strlen(pystate->strFindString + pystate->iPYInsertPoint), i = 0;
652
/* 这里使用<=而不是<是因为还有'\0'需要拷贝 */
653
for (i = 0; i <= len; i++)
654
pystate->strFindString[i + pystate->iPYInsertPoint - val] = pystate->strFindString[i + pystate->iPYInsertPoint];
655
ParsePY(&pystate->pyconfig, pystate->strFindString, &pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
617
&& (move_src[-2] == PY_SEPARATOR)) ? 2 : 1;
618
memmove(move_src - val, move_src, strlen(move_src) + 1);
619
ParsePY(&pystate->pyconfig, pystate->strFindString,
620
&pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
656
621
pystate->iPYInsertPoint -= val;
658
if (!strlen(pystate->strFindString)) {
659
if (!pystate->iPYSelected)
662
val = strlen(pystate->strFindString);
663
strcpy(strTemp, pystate->pySelected[pystate->iPYSelected - 1].strPY);
664
strcat(strTemp, pystate->strFindString);
665
strcpy(pystate->strFindString, strTemp);
666
pystate->iPYInsertPoint = strlen(pystate->strFindString) - val;
667
pystate->iPYSelected--;
668
ParsePY(&pystate->pyconfig, pystate->strFindString, &pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
623
if (!strlen(pystate->strFindString))
671
625
retVal = IRV_DISPLAY_CANDWORDS;
673
if (strlen(pystate->strFindString) == 0)
627
if (!strlen(pystate->strFindString))
674
628
return IRV_TO_PROCESS;
676
630
return IRV_DO_NOTHING;
679
633
if (FcitxInputStateGetRawInputBufferSize(input)) {
680
634
if (pystate->iPYInsertPoint == strlen(pystate->strFindString))
681
635
return IRV_DO_NOTHING;
682
val = (pystate->strFindString[pystate->iPYInsertPoint + 1] == PY_SEPARATOR) ? 2 : 1;
683
int len = strlen(pystate->strFindString + pystate->iPYInsertPoint + val), i = 0;
684
/* 这里使用<=而不是<是因为还有'\0'需要拷贝 */
685
for (i = 0; i <= len; i++)
686
pystate->strFindString[i + pystate->iPYInsertPoint] = pystate->strFindString[i + pystate->iPYInsertPoint + val];
636
char *move_dst = (pystate->strFindString
637
+ pystate->iPYInsertPoint);
638
val = (move_dst[1] == PY_SEPARATOR) ? 2 : 1;
639
memmove(move_dst, move_dst + val, strlen(move_dst + val) + 1);
688
ParsePY(&pystate->pyconfig, pystate->strFindString, &pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
641
ParsePY(&pystate->pyconfig, pystate->strFindString,
642
&pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
689
643
if (!strlen(pystate->strFindString))
690
644
return IRV_CLEAN;
691
645
retVal = IRV_DISPLAY_CANDWORDS;
730
684
retVal = IRV_DISPLAY_CANDWORDS;
732
686
} else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
733
if (pystate->findMap.iMode == PARSE_ERROR)
734
return IRV_DO_NOTHING;
736
if (FcitxCandidateWordPageCount(FcitxInputStateGetCandidateList(input)) == 0) {
687
FcitxCandidateWordList *candList;
688
candList = FcitxInputStateGetCandidateList(input);
689
if (FcitxCandidateWordPageCount(candList) == 0) {
737
690
if (FcitxInputStateGetRawInputBufferSize(input) == 0)
738
691
return IRV_TO_PROCESS;
740
693
return IRV_DO_NOTHING;
743
retVal = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
696
retVal = FcitxCandidateWordChooseByIndex(candList, 0);
744
697
} else if (FcitxHotkeyIsHotKey(sym, state, pystate->pyconfig.hkPYDelUserPhr)) {
745
698
if (!pystate->bIsPYDelUserPhr) {
700
FcitxCandidateWordList *candList;
746
701
FcitxCandidateWord* candWord = NULL;
747
for (candWord = FcitxCandidateWordGetCurrentWindow(FcitxInputStateGetCandidateList(input));
749
candWord = FcitxCandidateWordGetCurrentWindowNext(FcitxInputStateGetCandidateList(input), candWord)) {
702
candList = FcitxInputStateGetCandidateList(input);
704
(candWord = FcitxCandidateWordGetByIndex(candList, i));
750
706
if (candWord->owner == pystate) {
751
707
PYCandWord* pycandWord = candWord->priv;
752
708
if (pycandWord->iWhich == PY_CAND_USERPHRASE)
761
717
FcitxInputStateSetIsDoInputOnly(input, true);
763
719
FcitxInstanceCleanInputWindowUp(pystate->owner);
764
FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_TIPS, _("Press index to delete user phrase (ESC for cancel)"));
720
FcitxMessagesAddMessageStringsAtLast(
721
FcitxInputStateGetAuxUp(input), MSG_TIPS,
722
_("Press index to delete user phrase (ESC for cancel)"));
765
723
FcitxInputStateSetShowCursor(input, false);
767
725
return IRV_DISPLAY_MESSAGE;
772
730
FcitxInputStateSetIsDoInputOnly(input, true);
774
732
FcitxInstanceCleanInputWindowUp(pystate->owner);
775
FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_TIPS, _("Press number to make word in frequent list"), pystate->strFindString);
733
FcitxMessagesAddMessageStringsAtLast(
734
FcitxInputStateGetAuxUp(input), MSG_TIPS,
735
_("Press number to make word in frequent list"));
776
736
FcitxInputStateSetShowCursor(input, false);
778
738
return IRV_DISPLAY_MESSAGE;
780
740
} else if (FcitxHotkeyIsHotKey(sym, state, pystate->pyconfig.hkPYDelFreq)) {
781
741
if (!pystate->bIsPYDelFreq) {
784
744
FcitxCandidateWord* candWord = NULL;
785
for (candWord = FcitxCandidateWordGetCurrentWindow(FcitxInputStateGetCandidateList(input));
787
candWord = FcitxCandidateWordGetCurrentWindowNext(FcitxInputStateGetCandidateList(input), candWord)) {
745
FcitxCandidateWordList *candList;
746
candList = FcitxInputStateGetCandidateList(input);
748
(candWord = FcitxCandidateWordGetByIndex(candList, i));
789
750
if (candWord->owner == pystate) {
790
751
PYCandWord* pycandWord = candWord->priv;
791
752
if (pycandWord->iWhich == PY_CAND_FREQ) {
816
778
if (retVal == IRV_TO_PROCESS) {
817
if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
818
int iKey = sym - FcitxKey_0;
822
FcitxCandidateWord* candWord = FcitxCandidateWordGetByIndex(FcitxInputStateGetCandidateList(input), iKey - 1);
779
FcitxCandidateWordList *candList;
781
candList = FcitxInputStateGetCandidateList(input);
782
iKey = FcitxCandidateWordCheckChooseKey(candList, sym, state);
784
FcitxCandidateWord *candWord;
785
candWord = FcitxCandidateWordGetByIndex(candList, iKey);
823
786
if (!FcitxInputStateGetIsInRemind(input)) {
824
787
if (!FcitxInputStateGetRawInputBufferSize(input))
825
788
return IRV_TO_PROCESS;
851
814
ParsePY(&pystate->pyconfig, pystate->strFindString, &pystate->findMap, PY_PARSE_INPUT_USER, pystate->bSP);
852
815
pystate->iPYInsertPoint = 0;
853
816
retVal = IRV_DISPLAY_CANDWORDS;
854
} else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE))
817
} else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
855
818
return IRV_TO_PROCESS;
857
if (pystate->bIsPYAddFreq || pystate->bIsPYDelFreq || pystate->bIsPYDelUserPhr)
858
return IRV_DO_NOTHING;
861
if (FcitxCandidateWordPageCount(FcitxInputStateGetCandidateList(input)) != 0) {
862
if (state == FcitxKeyState_None && (sym == pystate->pyconfig.cPYYCDZ[0] || sym == pystate->pyconfig.cPYYCDZ[1])) {
863
FcitxCandidateWord* candWord = FcitxCandidateWordGetByIndex(FcitxInputStateGetCandidateList(input), pystate->iYCDZ);
864
if (candWord->owner == pystate) {
865
PYCandWord* pycandWord = candWord->priv;
866
if (pycandWord->iWhich == PY_CAND_USERPHRASE || pycandWord->iWhich == PY_CAND_SYSPHRASE) {
867
char *pBase, *pPhrase;
869
pBase = pystate->PYFAList[pycandWord->cand.phrase.iPYFA].pyBase[pycandWord->cand.phrase.iBase].strHZ;
870
pPhrase = pycandWord->cand.phrase.phrase->strPhrase;
872
if (sym == pystate->pyconfig.cPYYCDZ[0])
873
strcpy(FcitxInputStateGetOutputString(input), pBase);
876
clen = fcitx_utf8_char_len(pPhrase);
877
strncpy(FcitxInputStateGetOutputString(input), pPhrase, clen);
878
FcitxInputStateGetOutputString(input)[clen] = '\0';
880
FcitxMessagesSetMessageCount(FcitxInputStateGetAuxDown(input), 0);
881
return IRV_COMMIT_STRING;
884
} else if (!FcitxInputStateGetIsInRemind(input)) {
887
case FcitxKey_parenright:
889
case FcitxKey_parenleft:
891
case FcitxKey_asterisk:
893
case FcitxKey_ampersand:
895
case FcitxKey_asciicircum:
897
case FcitxKey_percent:
899
case FcitxKey_dollar:
901
case FcitxKey_numbersign:
905
case FcitxKey_exclam:
911
if (val != -1 && FcitxCandidateWordGetByIndex(FcitxInputStateGetCandidateList(input), val)) {
912
pystate->iYCDZ = val;
913
return IRV_DISPLAY_CANDWORDS;
819
} else if (pystate->bIsPYAddFreq || pystate->bIsPYDelFreq ||
820
pystate->bIsPYDelUserPhr) {
821
return IRV_DO_NOTHING;
1002
907
FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(pystate->owner);
1003
908
FcitxMessages* msgPreedit = FcitxInputStateGetPreedit(input);
1004
909
FcitxMessages* msgClientPreedit = FcitxInputStateGetClientPreedit(input);
1005
struct _FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
910
FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
912
FcitxCandidateWordSetPageSize(candList, config->iMaxCandWord);
913
FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE);
1007
915
/* update preedit string */
1009
917
FcitxMessagesSetMessageCount(msgPreedit, 0);
1010
918
FcitxMessagesSetMessageCount(msgClientPreedit, 0);
1011
919
if (pystate->iPYSelected) {
1012
FcitxMessagesAddMessageAtLast(msgPreedit, MSG_OTHER, "");
1013
FcitxMessagesAddMessageAtLast(msgClientPreedit, MSG_OTHER, "");
920
FcitxMessagesAddMessageStringsAtLast(msgPreedit, MSG_OTHER, "");
921
FcitxMessagesAddMessageStringsAtLast(msgClientPreedit, MSG_OTHER, "");
1014
922
for (i = 0; i < pystate->iPYSelected; i++) {
1015
923
FcitxMessagesMessageConcat(msgPreedit, FcitxMessagesGetMessageCount(msgPreedit) - 1, pystate->pySelected[i].strHZ);
1016
924
FcitxMessagesMessageConcat(msgClientPreedit, FcitxMessagesGetMessageCount(msgClientPreedit) - 1, pystate->pySelected[i].strHZ);
1020
928
for (i = 0; i < pystate->findMap.iHZCount; i++) {
1021
FcitxMessagesAddMessageAtLast(msgPreedit, MSG_CODE, "%s", pystate->findMap.strPYParsed[i]);
929
FcitxMessagesAddMessageStringsAtLast(msgPreedit, MSG_CODE,
930
pystate->findMap.strPYParsed[i]);
1022
931
if (i < pystate->findMap.iHZCount - 1)
1023
932
FcitxMessagesMessageConcat(msgPreedit, FcitxMessagesGetMessageCount(msgPreedit) - 1, " ");
1026
935
if (pystate->findMap.iMode == PARSE_ERROR) {
1027
936
for (i = 0; i < pystate->findMap.iHZCount; i++) {
1028
FcitxMessagesAddMessageAtLast(msgClientPreedit, MSG_CODE, "%s", pystate->findMap.strPYParsed[i]);
1029
if (i < pystate->findMap.iHZCount - 1)
1030
FcitxMessagesMessageConcat(msgClientPreedit, FcitxMessagesGetMessageCount(msgClientPreedit) - 1, " ");
937
FcitxMessagesAddMessageStringsAtLast(
938
msgClientPreedit, MSG_CODE, pystate->findMap.strPYParsed[i]);
940
char* errorAuto = FcitxUIMessagesToCString(msgClientPreedit);
1032
941
FcitxInstanceCleanInputWindowDown(pystate->owner);
1033
return IRV_DISPLAY_MESSAGE;
943
FcitxCandidateWord candWord;
944
candWord.owner = pystate;
945
candWord.callback = PYGetCandWord;
946
candWord.priv = NULL;
947
candWord.strWord = strdup(errorAuto);
948
candWord.strExtra = NULL;
949
candWord.wordType = MSG_OTHER;
950
FcitxCandidateWordAppend(candList, &candWord);
951
return IRV_DISPLAY_CANDWORDS;
1036
954
if (FcitxInputStateGetIsInRemind(input))
1037
955
return PYGetRemindCandWords(pystate);
1039
FcitxCandidateWordSetPageSize(candList, config->iMaxCandWord);
1040
FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE);
1044
957
//判断是不是要输入常用字或符号
1045
958
PyFreq* pCurFreq = pystate->pyFreq->next;
1046
959
for (iVal = 0; iVal < pystate->iPYFreqCount; iVal++) {
1049
962
pCurFreq = pCurFreq->next;
1052
/* if it is symbol mode, all word will be take care */
1053
if (!(pCurFreq && pCurFreq->bIsSym)) {
1055
if (pystate->pyconfig.bPYCreateAuto)
1056
PYCreateAuto(pystate);
1058
if (pystate->strPYAuto[0]) {
1059
FcitxCandidateWord candWord;
1060
PYCandWord* pycandword = fcitx_utils_malloc0(sizeof(PYCandWord));
1061
pycandword->iWhich = PY_CAND_AUTO;
1062
candWord.owner = pystate;
1063
candWord.callback = PYGetCandWord;
1064
candWord.priv = pycandword;
1065
candWord.strWord = strdup(pystate->strPYAuto);
1066
candWord.strExtra = NULL;
1067
candWord.wordType = MSG_OTHER;
1068
FcitxCandidateWordAppend(candList, &candWord);
1071
PYGetPhraseCandWords(pystate);
1073
PYGetFreqCandWords(pystate, pCurFreq);
1074
PYGetBaseCandWords(pystate, pCurFreq);
1076
PYGetSymCandWords(pystate, pCurFreq);
965
if (pystate->pyconfig.bPYCreateAuto)
966
PYCreateAuto(pystate);
968
if (pystate->strPYAuto[0]) {
969
FcitxCandidateWord candWord;
970
PYCandWord* pycandword = fcitx_utils_new(PYCandWord);
971
pycandword->iWhich = PY_CAND_AUTO;
972
candWord.owner = pystate;
973
candWord.callback = PYGetCandWord;
974
candWord.priv = pycandword;
975
candWord.strWord = strdup(pystate->strPYAuto);
976
candWord.strExtra = NULL;
977
candWord.wordType = MSG_OTHER;
978
FcitxCandidateWordAppend(candList, &candWord);
981
PYGetPhraseCandWords(pystate);
983
PYGetFreqCandWords(pystate, pCurFreq);
984
PYGetBaseCandWords(pystate, pCurFreq);
1079
986
if (FcitxCandidateWordPageCount(candList) != 0) {
1080
FcitxCandidateWord* candWord = FcitxCandidateWordGetCurrentWindow(candList);
1081
FcitxMessagesAddMessageAtLast(msgClientPreedit, MSG_INPUT, "%s", candWord->strWord);
987
FcitxCandidateWord *candWord = FcitxCandidateWordGetCurrentWindow(candList);
988
FcitxMessagesAddMessageStringsAtLast(msgClientPreedit, MSG_INPUT,
1084
992
return IRV_DISPLAY_CANDWORDS;
1247
1155
INPUT_RETURN_VALUE PYGetCandWord(void* arg, FcitxCandidateWord* candWord)
1249
1157
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
1158
FcitxInputState* input = FcitxInstanceGetInputState(pystate->owner);
1160
if (candWord->priv == NULL) {
1161
strcpy(FcitxInputStateGetOutputString(input), candWord->strWord);
1162
return IRV_COMMIT_STRING;
1250
1165
char *pBase = NULL, *pPhrase = NULL;
1251
1166
char *pBaseMap = NULL, *pPhraseMap = NULL;
1252
1167
uint *pIndex = NULL;
1401
1312
candPos.iPhrase < PYFAList[candPos.iPYFA].pyBase[candPos.iBase].iUserPhrase; candPos.iPhrase++) {
1402
1313
val = CmpMap(pyconfig, phrase->strMap, strMap, &iMatchedLength, pystate->bSP);
1403
1314
if (!val || (val && (strlen(phrase->strMap) == iMatchedLength))) {
1404
PYCandWord* pycandWord = fcitx_utils_malloc0(sizeof(PYCandWord));
1315
PYCandWord *pycandWord = fcitx_utils_new(PYCandWord);
1405
1316
PYAddPhraseCandWord(pystate, candPos, phrase, false, pycandWord);
1406
1317
utarray_push_back(&candtemp, &pycandWord);
1456
1367
candWord.wordType = MSG_OTHER;
1457
1368
const char* pBase = PYFAList[(*pcand)->cand.phrase.iPYFA].pyBase[(*pcand)->cand.phrase.iBase].strHZ;
1458
1369
const char* pPhrase = (*pcand)->cand.phrase.phrase->strPhrase;
1459
asprintf(&candWord.strWord, "%s%s", pBase, pPhrase);
1460
FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
1370
fcitx_utils_alloc_cat_str(candWord.strWord, pBase, pPhrase);
1371
FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input),
1463
1375
utarray_done(&candtemp);
1490
//********************************************
1491
void PYGetSymCandWords(FcitxPinyinState* pystate, PyFreq* pCurFreq)
1495
FcitxInputState* input = FcitxInstanceGetInputState(pystate->owner);
1497
if (pCurFreq && pCurFreq->bIsSym) {
1498
hz = pCurFreq->HZList->next;
1499
for (i = 0; i < pCurFreq->iCount; i++) {
1500
PYCandWord* pycandWord = fcitx_utils_malloc0(sizeof(PYCandWord));
1501
PYAddSymCandWord(hz, pycandWord);
1502
FcitxCandidateWord candWord;
1503
candWord.callback = PYGetCandWord;
1504
candWord.owner = pystate;
1505
candWord.priv = pycandWord;
1506
candWord.strExtra = NULL;
1507
candWord.strWord = strdup(hz->strHZ);
1508
candWord.wordType = MSG_OTHER;
1509
FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
1516
* 将一个符号加入到候选列表的合适位置中
1519
void PYAddSymCandWord(HZ * hz, PYCandWord* pycandWord)
1521
pycandWord->iWhich = PY_CAND_SYMBOL;
1522
pycandWord->cand.sym.hz = hz;
1525
1402
//*****************************************************
1527
1404
void PYGetBaseCandWords(FcitxPinyinState* pystate, PyFreq* pCurFreq)
1543
1420
if (!Cmp2Map(pyconfig, PYFAList[candPos.iPYFA].strMap, str, pystate->bSP)) {
1544
1421
for (candPos.iBase = 0; candPos.iBase < PYFAList[candPos.iPYFA].iBase; candPos.iBase++) {
1545
1422
if (!PYIsInFreq(pCurFreq, PYFAList[candPos.iPYFA].pyBase[candPos.iBase].strHZ)) {
1546
PYCandWord* pycandWord = fcitx_utils_malloc0(sizeof(PYCandWord));
1423
PYCandWord *pycandWord = fcitx_utils_new(PYCandWord);
1547
1424
PYAddBaseCandWord(candPos, pycandWord);
1548
1425
utarray_push_back(&candtemp, &pycandWord);
1593
1470
UT_array candtemp;
1594
1471
FcitxInputState* input = FcitxInstanceGetInputState(pystate->owner);
1595
utarray_init(&candtemp, &pycand_icd);
1472
utarray_init(&candtemp, fcitx_ptr_icd);
1597
if (pCurFreq && !pCurFreq->bIsSym) {
1598
1475
hz = pCurFreq->HZList->next;
1599
1476
for (i = 0; i < pCurFreq->iCount; i++) {
1600
PYCandWord* pycandWord = fcitx_utils_malloc0(sizeof(PYCandWord));
1477
PYCandWord *pycandWord = fcitx_utils_new(PYCandWord);
1601
1478
PYAddFreqCandWord(pCurFreq, hz, pCurFreq->strPY, pycandWord);
1602
1479
utarray_push_back(&candtemp, &pycandWord);
1694
newPhrase = (PyUsrPhrase *) fcitx_utils_malloc0(sizeof(PyUsrPhrase));
1695
newPhrase->phrase.strMap = (char *) fcitx_utils_malloc0(sizeof(char) * strlen(map + 2) + 1);
1696
newPhrase->phrase.strPhrase = (char *) fcitx_utils_malloc0(sizeof(char) * strlen(phrase + clen) + 1);
1571
newPhrase = fcitx_utils_new(PyUsrPhrase);
1572
newPhrase->phrase.strMap = (char*)fcitx_utils_malloc0(sizeof(char) * strlen(map + 2) + 1);
1573
newPhrase->phrase.strPhrase = (char*)fcitx_utils_malloc0(sizeof(char) * strlen(phrase + clen) + 1);
1697
1574
strcpy(newPhrase->phrase.strMap, map + 2);
1698
1575
strcpy(newPhrase->phrase.strPhrase, phrase + clen);
1699
1576
newPhrase->phrase.iIndex = ++pystate->iCounter;
1786
1663
iTemp = PYFAList[i].pyBase[j].iUserPhrase;
1789
fwrite(&i, sizeof(int), 1, fp);
1666
fcitx_utils_write_int32(fp, i);
1790
1667
clen = strlen(PYFAList[i].pyBase[j].strHZ);
1791
1668
fwrite(&clen, sizeof(char), 1, fp);
1792
1669
fwrite(PYFAList[i].pyBase[j].strHZ, sizeof(char) * clen, 1, fp);
1793
fwrite(&iTemp, sizeof(int), 1, fp);
1670
fcitx_utils_write_int32(fp, iTemp);
1794
1671
phrase = USER_PHRASE_NEXT(PYFAList[i].pyBase[j].userPhrase);
1795
1672
for (k = 0; k < PYFAList[i].pyBase[j].iUserPhrase; k++) {
1796
1673
iTemp = strlen(phrase->strMap);
1797
fwrite(&iTemp, sizeof(int), 1, fp);
1674
fcitx_utils_write_int32(fp, iTemp);
1798
1675
fwrite(phrase->strMap, sizeof(char) * iTemp, 1, fp);
1800
1677
iTemp = strlen(phrase->strPhrase);
1801
fwrite(&iTemp, sizeof(int), 1, fp);
1678
fcitx_utils_write_int32(fp, iTemp);
1802
1679
fwrite(phrase->strPhrase, sizeof(char) * iTemp, 1, fp);
1804
iTemp = phrase->iIndex;
1805
fwrite(&iTemp, sizeof(int), 1, fp);
1806
iTemp = phrase->iHit;
1807
fwrite(&iTemp, sizeof(int), 1, fp);
1681
fcitx_utils_write_uint32(fp, phrase->iIndex);
1682
fcitx_utils_write_uint32(fp, phrase->iHit);
1808
1683
phrase = USER_PHRASE_NEXT(phrase);
1849
1725
pPyFreq = pystate->pyFreq->next;
1850
1726
while (pPyFreq) {
1851
if (!pPyFreq->bIsSym)
1853
1728
pPyFreq = pPyFreq->next;
1855
fwrite(&i, sizeof(uint), 1, fp);
1730
fcitx_utils_write_int32(fp, i);
1856
1731
pPyFreq = pystate->pyFreq->next;
1857
1732
while (pPyFreq) {
1858
if (!pPyFreq->bIsSym) {
1859
fwrite(pPyFreq->strPY, sizeof(char) * 11, 1, fp);
1860
j = pPyFreq->iCount;
1861
fwrite(&j, sizeof(int), 1, fp);
1862
hz = pPyFreq->HZList->next;
1863
for (k = 0; k < pPyFreq->iCount; k++) {
1865
char slen = strlen(hz->strHZ);
1866
fwrite(&slen, sizeof(char), 1, fp);
1867
fwrite(hz->strHZ, sizeof(char) * slen, 1, fp);
1870
fwrite(&j, sizeof(int), 1, fp);
1873
fwrite(&j, sizeof(int), 1, fp);
1876
fwrite(&j, sizeof(int), 1, fp);
1733
fwrite(pPyFreq->strPY, sizeof(char) * 11, 1, fp);
1734
fcitx_utils_write_int32(fp, pPyFreq->iCount);
1735
hz = pPyFreq->HZList->next;
1736
for (k = 0; k < pPyFreq->iCount; k++) {
1737
char slen = strlen(hz->strHZ);
1738
fwrite(&slen, sizeof(char), 1, fp);
1739
fwrite(hz->strHZ, sizeof(char) * slen, 1, fp);
1740
fcitx_utils_write_int32(fp, hz->iPYFA);
1741
fcitx_utils_write_uint32(fp, hz->iHit);
1742
fcitx_utils_write_int32(fp, hz->iIndex);
1881
1746
pPyFreq = pPyFreq->next;
1921
uint32_t magic = PY_INDEX_MAGIC_NUMBER;
1922
fwrite(&magic, sizeof(uint32_t), 1, fp);
1786
fcitx_utils_write_uint32(fp, PY_INDEX_MAGIC_NUMBER);
1925
fwrite(&pystate->iCounter, sizeof(uint), 1, fp);
1789
fcitx_utils_write_uint32(fp, pystate->iCounter);
1928
1792
for (i = 0; i < pystate->iPYFACount; i++) {
1929
1793
for (j = 0; j < PYFAList[i].iBase; j++) {
1930
1794
if (PYFAList[i].pyBase[j].iIndex > pystate->iOrigCounter) {
1931
fwrite(&i, sizeof(int), 1, fp);
1932
fwrite(&j, sizeof(int), 1, fp);
1933
fwrite(&k, sizeof(int), 1, fp);
1934
l = PYFAList[i].pyBase[j].iIndex;
1935
fwrite(&l, sizeof(uint), 1, fp);
1936
l = PYFAList[i].pyBase[j].iHit;
1937
fwrite(&l, sizeof(uint), 1, fp);
1795
fcitx_utils_write_int32(fp, i);
1796
fcitx_utils_write_int32(fp, j);
1797
fcitx_utils_write_int32(fp, k);
1798
fcitx_utils_write_uint32(fp, PYFAList[i].pyBase[j].iIndex);
1799
fcitx_utils_write_uint32(fp, PYFAList[i].pyBase[j].iHit);
1943
1805
for (i = 0; i < pystate->iPYFACount; i++) {
1944
1806
for (j = 0; j < PYFAList[i].iBase; j++) {
1945
1807
for (k = 0; k < PYFAList[i].pyBase[j].iPhrase; k++) {
1946
if (PYFAList[i].pyBase[j].phrase[k].iIndex > pystate->iOrigCounter) {
1947
fwrite(&i, sizeof(int), 1, fp);
1948
fwrite(&j, sizeof(int), 1, fp);
1949
fwrite(&k, sizeof(int), 1, fp);
1950
l = PYFAList[i].pyBase[j].phrase[k].iIndex;
1951
fwrite(&l, sizeof(uint), 1, fp);
1952
l = PYFAList[i].pyBase[j].phrase[k].iHit;
1953
fwrite(&l, sizeof(uint), 1, fp);
1808
if (PYFAList[i].pyBase[j].phrase[k].iIndex
1809
> pystate->iOrigCounter) {
1810
fcitx_utils_write_int32(fp, i);
1811
fcitx_utils_write_int32(fp, j);
1812
fcitx_utils_write_int32(fp, k);
1813
fcitx_utils_write_uint32(
1814
fp, PYFAList[i].pyBase[j].phrase[k].iIndex);
1815
fcitx_utils_write_uint32(
1816
fp, PYFAList[i].pyBase[j].phrase[k].iHit);
2170
2032
phrase = USER_PHRASE_NEXT(phrase);
2173
FcitxMessagesSetMessageCount(FcitxInputStateGetAuxUp(input), 0);
2174
FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_TIPS, _("Remind: "));
2175
FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_INPUT, "%s", pystate->strPYRemindSource);
2035
FcitxMessages *msg_up = FcitxInputStateGetAuxUp(input);
2036
FcitxMessagesSetMessageCount(msg_up, 0);
2037
FcitxMessagesAddMessageStringsAtLast(msg_up, MSG_TIPS, _("Remind: "));
2038
FcitxMessagesAddMessageStringsAtLast(msg_up, MSG_INPUT,
2039
pystate->strPYRemindSource);
2177
2041
PYCandWord** pcand = NULL;
2178
2042
for (pcand = (PYCandWord**) utarray_front(&candtemp);
2235
2099
SavePYFreq(pystate);
2238
void* LoadPYBaseDictWrapper(void * arg, FcitxModuleFunctionArg args)
2240
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2241
if (!pystate->bPYBaseDictLoaded)
2242
LoadPYBaseDict(pystate);
2246
void* PYGetPYByHZWrapper(void * arg, FcitxModuleFunctionArg args)
2248
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2249
char *a = args.args[0];
2250
char *b = args.args[1];
2251
PYGetPYByHZ(pystate, a, b);
2255
void* DoPYInputWrapper(void * arg, FcitxModuleFunctionArg args)
2257
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2258
FcitxKeySym *a = args.args[0];
2259
unsigned int *b = args.args[1];
2260
DoPYInput(pystate, *a, *b);
2264
void* PYGetCandWordsWrapper(void * arg, FcitxModuleFunctionArg args)
2266
PYGetCandWords(arg);
2270
void* PYGetFindStringWrapper(void * arg, FcitxModuleFunctionArg args)
2272
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2273
return pystate->strFindString;
2276
void* PYResetWrapper(void * arg, FcitxModuleFunctionArg args)
2278
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2280
pystate->bSP = false;
2281
pystate->strPYAuto[0] = '\0';
2282
ResetPYStatus(pystate);
2287
2102
void ReloadConfigPY(void* arg)
2289
2104
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2412
void* PYSP2QP(void* arg, FcitxModuleFunctionArg args)
2227
PYSP2QP(FcitxPinyinState *pystate, const char* strSP)
2414
FcitxPinyinState *pystate = (FcitxPinyinState*)arg;
2415
char* strSP = args.args[0];
2416
char strQP[MAX_PY_LENGTH + 1];
2229
char strQP[MAX_PY_LENGTH + 1] = "";
2419
2230
SP2QP(&pystate->pyconfig, strSP, strQP);
2421
2231
return strdup(strQP);
2424
boolean PYGetPYMapByHZ(FcitxPinyinState* pystate, char* strHZ, char* mapHint, char* strMap)
2235
PYGetPYMapByHZ(FcitxPinyinState* pystate, char* strHZ,
2236
char* mapHint, char* strMap)
2427
2239
PYFA* PYFAList = pystate->PYFAList;
2454
2267
size_t hzCountLocal = 0;
2456
2269
if (pystate->iPYSelected) {
2458
for (i = 0 ; i < pystate->iPYSelected; i ++)
2271
for (i = 0 ; i < pystate->iPYSelected; i ++) {
2459
2272
hzCountLocal += strlen(pystate->pySelected[i].strMap) / 2;
2461
2275
hzCountLocal += pystate->findMap.iHZCount;
2463
2277
/* in order not to get a wrong one, use strict check */
2464
2278
if (hzCountLocal != hzCount || hzCount > MAX_PY_PHRASE_LENGTH)
2466
char* totalMap = fcitx_utils_malloc0(sizeof(char) * (1 + 2 * hzCount));
2280
char *totalMap = fcitx_utils_malloc0(1 + 2 * hzCount);
2468
2282
if (pystate->iPYSelected) {
2470
2284
for (i = 0 ; i < pystate->iPYSelected; i ++)
2471
2285
strcat(totalMap, pystate->pySelected[i].strMap);
2472
2286
strHZ = fcitx_utf8_get_nth_char(strHZ, strlen(totalMap) / 2);
2476
2290
while (*strHZ) {
2479
2293
sp = fcitx_utf8_get_char(strHZ, &chr);
2480
2294
size_t len = sp - strHZ;
2481
2295
strncpy(singleHZ, strHZ, len);
2482
2296
singleHZ[len] = '\0';
2484
if (!PYGetPYMapByHZ(pystate, singleHZ, pystate->findMap.strMap[i], strMap)) {
2298
if (!PYGetPYMapByHZ(pystate, singleHZ, pystate->findMap.strMap[i],
2485
2300
free(totalMap);
2489
2304
strncat(totalMap, strMap, 2);
2495
2309
PYAddUserPhrase(pystate, pivot, totalMap, true);
2496
2310
free(totalMap);
2501
// kate: indent-mode cstyle; space-indent on; indent-width 0;
2313
#include "fcitx-pinyin-addfunctions.h"