1
/***************************************************************************
2
* Copyright (C) 2002~2005 by Yuking *
3
* yuking_net@sohu.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
26
#include "fcitx-utils/utils.h"
29
void LoadPYMB(FILE *fi, struct _PYMB **pPYMB, int isUser)
35
/* Is there a way to avoid reading the whole file twice? */
37
/* First Pass: Determine the size of the PYMB array to be created */
43
r = fcitx_utils_read_int32(fi, &t);
50
fread(&clen, sizeof(int8_t), 1, fi);
52
fseek(fi, sizeof(char) * clen, SEEK_CUR);
54
fcitx_utils_read_int32(fi, &t);
56
for (i = 0; i < t; ++i) {
58
fcitx_utils_read_int32(fi, &iLen);
59
fseek(fi , sizeof(char) * iLen, SEEK_CUR);
60
fcitx_utils_read_int32(fi, &iLen);
61
fseek(fi , sizeof(char) * iLen, SEEK_CUR);
62
fcitx_utils_read_int32(fi, &iLen);
65
fcitx_utils_read_int32(fi, &iLen);
69
/* Second Pass: Actually read the data */
71
fseek(fi, 0, SEEK_SET);
73
*pPYMB = PYMB = malloc(sizeof(*PYMB) * (n + 1));
75
for (i = 0; i < n; ++i) {
76
r = fcitx_utils_read_int32(fi, &(PYMB[i].PYFAIndex));
79
fread(&clen, sizeof(int8_t), 1, fi);
80
fread(PYMB[i].HZ, sizeof(char) * clen, 1, fi);
81
PYMB[i].HZ[clen] = '\0';
83
fcitx_utils_read_int32(fi, &(PYMB[i].UserPhraseCount));
84
PYMB[i].UserPhrase = malloc(sizeof(*(PYMB[i].UserPhrase)) * PYMB[i].UserPhraseCount);
86
#define PU(i,j) (PYMB[(i)].UserPhrase[(j)])
88
for (j = 0; j < PYMB[i].UserPhraseCount; ++j) {
89
fcitx_utils_read_int32(fi, &(PU(i, j).Length));
91
PU(i, j).Map = malloc(sizeof(char) * PU(i, j).Length + 1);
92
fread(PU(i, j).Map, sizeof(char) * PU(i, j).Length, 1, fi);
93
PU(i, j).Map[PU(i, j).Length] = '\0';
96
fcitx_utils_read_int32(fi, &iLen);
97
PU(i, j).Phrase = malloc(sizeof(char) * iLen + 1);
98
fread(PU(i, j).Phrase, sizeof(char) * iLen, 1, fi);
99
PU(i, j).Phrase[iLen] = '\0';
101
fcitx_utils_read_int32(fi, &(PU(i, j).Index));
104
fcitx_utils_read_int32(fi, &(PU(i, j).Hit));
112
PYMB[n].HZ[0] = '\0';
117
int LoadPYBase(FILE *fi, struct _HZMap **pHZMap)
119
int32_t i, j, r, PYFACount;
121
struct _HZMap *HZMap;
123
r = fcitx_utils_read_int32(fi, &PYFACount);
128
*pHZMap = HZMap = malloc(sizeof(*HZMap) * (PYFACount + 1));
130
for (i = 0; i < PYFACount; ++i) {
131
fread(HZMap[i].Map, sizeof(char) * 2, 1, fi);
132
HZMap[i].Map[2] = '\0';
134
fcitx_utils_read_int32(fi, &(HZMap[i].BaseCount));
135
HZMap[i].HZ = malloc(sizeof(char *) * HZMap[i].BaseCount);
136
HZMap[i].Index = malloc(sizeof(int) * HZMap[i].BaseCount);
138
for (j = 0; j < HZMap[i].BaseCount; ++j) {
140
fread(&clen, sizeof(int8_t), 1, fi);
141
HZMap[i].HZ[j] = malloc(sizeof(char) * (clen + 1));
142
fread(HZMap[i].HZ[j], sizeof(char) * clen, 1, fi);
143
HZMap[i].HZ[j][clen] = '\0';
144
fcitx_utils_read_int32(fi, &HZMap[i].Index[j]);
148
HZMap[i].Map[0] = '\0';
153
// kate: indent-mode cstyle; space-indent on; indent-width 4;