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
23
void prph2(FILE *fp, phokey_t kk);
25
void get_keymap_str(u_int64_t k, char *keymap, int keybits, char tkey[]);
26
char *phokey2pinyin(phokey_t k);
27
gboolean is_pinyin_kbm();
31
int main(int argc, char **argv)
37
gboolean pr_usecount = TRUE;
39
char *fname_out = NULL;
41
gtk_init(&argc, &argv);
44
printf("%s: file name expected\n", argv[0]);
50
gboolean b_pinyin = is_pinyin_kbm();
53
if (!strcmp(argv[i], "-nousecount")) {
58
if (!strcmp(argv[i], "-o")) {
60
p_err("-o need out file name");
61
fname_out = argv[i+1];
72
dbg("%s use %s\n", argv[0], fname_out);
73
fp_out = fopen(fname_out, "w");
75
p_err("cannot create %s\n", fname_out);
80
fprintf(fp_out, "!!pinyin\n");
82
if ((fp=fopen(fname,"rb"))==NULL)
83
p_err("Cannot open %s %s", fname, sys_err_strA());
89
fread(&head, sizeof(head), 1, fp);
90
if (!strcmp(head.signature, TSIN_GTAB_KEY)) {
91
if (head.maxkey * head.keybits > 32)
99
fprintf(stderr, "phsz %d keybits:%d\n", phsz, head.keybits);
100
fprintf(stderr, "keymap '%s'\n", head.keymap);
101
fprintf(fp_out,TSIN_GTAB_KEY" %d %d %s\n", head.keybits, head.maxkey, head.keymap+1);
105
phokey_t phbuf[MAX_PHRASE_LEN];
106
u_int phbuf32[MAX_PHRASE_LEN];
107
u_int64_t phbuf64[MAX_PHRASE_LEN];
108
gboolean is_deleted = FALSE;
116
fread(&usecount, sizeof(usecount_t), 1,fp);
121
fread(phbuf, sizeof(phokey_t), clen, fp);
124
fread(phbuf32, 4, clen, fp);
127
fread(phbuf64, 8, clen, fp);
133
for(i=0;i<clen;i++) {
136
int n = fread(ch, 1, 1, fp);
142
fread(&ch[1], 1, len-1, fp);
144
memcpy(tt+ttlen, ch, len);
155
fprintf(fp_out, "%s ", tt);
157
for(i=0;i<clen;i++) {
160
char *t = phokey2pinyin(phbuf[i]);
162
fprintf(fp_out, "%s", t);
164
prph2(fp_out, phbuf[i]);
173
get_keymap_str(k, head.keymap, head.keybits, tkey);
174
fprintf(fp_out, "%s", tkey);
178
fprintf(fp_out, " ");
181
fprintf(fp_out, " %d\n", usecount);