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
21
// #include "gtab-phrase-db.h"
25
#define MAX_K (500000)
32
int qcmp_ch(const void *aa, const void *bb)
34
return memcmp(((ITEM *)aa)->ch, ((ITEM *)bb)->ch, CH_SZ);
37
int qcmp_ch64(const void *aa, const void *bb)
39
return memcmp(((ITEM64 *)aa)->ch, ((ITEM64 *)bb)->ch, CH_SZ);
42
ITEM *find_ch(char *s, int *N)
47
u8cpy((char *)t.ch, s);
49
ITEM *p = (ITEM *)bsearch(&t, it, itN, sizeof(ITEM), qcmp_ch);
55
while (p > it && !qcmp_ch(p-1, &t))
59
while (q < end && !qcmp_ch(q, &t))
69
ITEM64 *find_ch64(char *s, int *N)
74
u8cpy((char *)t.ch, s);
76
ITEM64 *p = (ITEM64 *)bsearch(&t, it64, itN, sizeof(ITEM64), qcmp_ch64);
82
while (p > it64 && !qcmp_ch64(p-1, &t))
85
ITEM64 *end = it64 + itN;
86
while (q < end && !qcmp_ch64(q, &t))
107
void get_keymap_str(u_int64_t k, char *keymap, int keybits, char tkey[]);
109
int main(int argc, char **argv)
111
gtk_init(&argc, &argv);
115
p_err("%s a_file.gtab outfile", argv[0]);
118
char *infile = argv[1];
119
char *outfile = argv[2];
121
char *infile = "data/ar30.gtab";
126
if ((fr=fopen(infile, "rb"))==NULL)
127
p_err("cannot err open %s", infile);
130
if ((fp_out=fopen(outfile,"w"))==NULL) {
131
printf("Cannot open %s", outfile);
136
fread(&th,1, sizeof(th), fr);
138
swap_byte_4(&th.version);
139
swap_byte_4(&th.flag);
140
swap_byte_4(&th.space_style);
141
swap_byte_4(&th.KeyS);
142
swap_byte_4(&th.MaxPress);
143
swap_byte_4(&th.M_DUP_SEL);
144
swap_byte_4(&th.DefC);
145
for(i=0; i <= KeyNum; i++)
146
swap_byte_4(&idx1[i]);
148
int KeyNum = th.KeyS;
149
dbg("keys %d\n",KeyNum);
153
dbg("keybits:%d maxPress:%d\n", th.keybits, th.MaxPress);
156
if (th.MaxPress*th.keybits > 32) {
157
// max_keyN = 64 / th.keybits;
159
dbg("it's a 64-bit .gtab\n");
161
// max_keyN = 32 / th.keybits;
165
dbg("key64:%d\n", key64);
167
char kname[128][CH_SZ];
169
gtab_idx1_t idx1[256];
170
// static char kno[128];
174
bzero(keymap, sizeof(keymap));
175
fread(keymap, 1, th.KeyS, fr);
176
fread(kname, CH_SZ, th.KeyS, fr);
177
fread(idx1, sizeof(gtab_idx1_t), KeyNum+1, fr);
181
for(i=0; i < th.KeyS; i++) {
186
fprintf(fp_out,TSIN_GTAB_KEY" %d %d %s\n", th.keybits, th.MaxPress, keymap+1);
189
fread(it64, sizeof(ITEM64), th.DefC, fr);
190
qsort(it64, th.DefC, sizeof(ITEM64), qcmp_ch64);
193
fread(it, sizeof(ITEM), th.DefC, fr);
194
qsort(it, th.DefC, sizeof(ITEM), qcmp_ch);
199
// dbg("itN:%d\n", itN);
201
for(i=0; i < itN; i++) {
203
utf8_putchar(it64[i].ch);
210
get_hime_user_fname(tsin32_f, fname);
213
if ((fp=fopen(fname,"rb"))==NULL) {
214
printf("Cannot open %s", fname);
221
phokey_t phbuf[MAX_PHRASE_LEN];
226
fread(&usecount, sizeof(usecount_t), 1,fp);
227
fread(phbuf,sizeof(phokey_t), clen, fp);
229
char str[MAX_PHRASE_LEN * CH_SZ + 1];
231
KKARR kk[MAX_PHRASE_LEN];
232
KKARR64 kk64[MAX_PHRASE_LEN];
233
gboolean has_err = FALSE;
236
bzero(kk64, sizeof(kk64));
238
bzero(kk, sizeof(kk));
240
// dbg("clen %d\n", clen);
241
for(i=0;i<clen;i++) {
244
int n = fread(ch, 1, 1, fp);
250
fread(&ch[1], 1, len-1, fp);
254
if (!(kk64[i].arr = find_ch64(ch, &kk64[i].N)))
257
if (!(kk[i].arr = find_ch(ch, &kk[i].N)))
261
memcpy(str+strN, ch, len);
266
// dbg("has_error\n");
270
for(i=0; i < clen; i++)
271
printf("%d ", kk64[i].N);
289
for(z=0; z < permN; z++) {
290
char vz[MAX_PHRASE_LEN];
295
for(i=0; i < clen; i++) {
296
vz[i] = tz % kk64[i].N;
300
for(i=0; i < clen; i++) {
301
vz[i] = tz % kk[i].N;
309
for(i=0;i<clen;i++) {
314
memcpy(&k, kk64[i].arr[vz[i]].key, 8);
317
memcpy(&t, kk[i].arr[vz[i]].key, 4);
321
get_keymap_str(k, keymap, th.keybits, tkey);
327
fprintf(fp_out,"%s %s%d\n", str, kstr, usecount);