1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
Copyright (C) 1995-2008 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/
#include "gcin.h"
#include "pho.h"
int pho_lookup(char *s, char *num, char *typ)
{
int i;
char tt[CH_SZ+1], *pp;
int len = utf8_sz(s);
if (utf8_eq(s, "1")) {
*num = 0;
*typ = 3;
return TRUE;
}
if (!(*s&0x80))
return *s-'0';
bchcpy(tt, s);
tt[len]=0;
for(i=0;i<4;i++) {
if ((pp=strstr(pho_chars[i], tt)))
break;
}
if (!pp)
return FALSE;
*typ=i;
*num=(pp - pho_chars[i])/3;
return TRUE;
}
void swap_char(char *a, char *b)
{
char t;
t = *a;
*a = *b;
*b = t;
}
int main(int argc, char **argv)
{
FILE *fp;
char s[128];
int i,len;
PHOKBM phkb;
char num, typ, chk;
char fnamesrc[40];
char fnameout[40];
if (!getenv("NO_GTK_INIT"))
gtk_init(&argc, &argv);
if (argc < 2) {
puts("file name expected");
exit(1);
}
bzero(&phkb,sizeof(phkb));
strcpy(fnameout,argv[1]);
char *p;
if ((p=strchr(fnameout, '.')))
*p = 0;
strcpy(fnamesrc,fnameout);
strcat(fnamesrc,".kbmsrc");
strcat(fnameout,".kbm");
if ((fp=fopen(fnamesrc,"r"))==NULL) {
printf("Cannot open %s\n", fnamesrc);
exit(1);
}
// fgets(s,sizeof(s),fp);
// len=strlen(s);
// s[len-1]=0;
// strcpy(phkb.selkey, s);
// phkb.selkeyN = strlen(s);
while (!feof(fp)) {
s[0]=0;
fgets(s,sizeof(s),fp);
len=strlen(s);
if (!len)
break;
if (s[len-1]=='\n')
s[--len]=0;
if (!len)
break;
if (!pho_lookup(s, &num, &typ))
p_err("err found %s", s);
int utf8sz = utf8_sz(s);
chk=s[utf8sz + 1];
#if 0
if (chk>='A' && chk<='Z')
chk+=32;
#endif
for(i=0;i<3;i++) {
if (!phkb.phokbm[(int)chk][i].num) {
phkb.phokbm[(int)chk][i].num=num;
phkb.phokbm[(int)chk][i].typ=typ;
// printf("%c %d %d i:%d\n", chk, num, typ, i);
break;
}
}
}
fclose(fp);
if (strstr(fnamesrc, "pinyin"))
phkb.phokbm[' '][0].num=0;
phkb.phokbm[' '][0].typ=3;
if ((fp=fopen(fnameout,"w"))==NULL) {
printf("Cannot create %s\n", fnameout);
exit(1);
}
fwrite(&phkb,sizeof(phkb),1,fp);
fclose(fp);
exit(0);
}
|