~ubuntu-branches/ubuntu/precise/hime/precise

« back to all changes in this revision

Viewing changes to data/t2s-file.c

  • Committer: Package Import Robot
  • Author(s): Yao Wei (魏銘廷)
  • Date: 2012-01-14 00:24:08 UTC
  • Revision ID: package-import@ubuntu.com-20120114002408-e79gagbeg1rt8npv
Tags: upstream-0.9.9
Import upstream version 0.9.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2010 Edward Der-Hua Liu, Hsin-Chu, Taiwan
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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
 
16
 */
 
17
 
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
#include <string.h>
 
21
#include <sys/types.h>
 
22
#include "t2s-file.h"
 
23
#include "util.h"
 
24
 
 
25
T2S t2s[3000],s2t[3000];
 
26
int t2sn;
 
27
 
 
28
int qcmp(const void *aa0, const void *bb0)
 
29
{
 
30
  T2S *aa = (T2S *)aa0;
 
31
  T2S *bb = (T2S *)bb0;
 
32
#if 0
 
33
  int64_t a = aa->a;
 
34
  int64_t b = bb->a;
 
35
#else
 
36
  u_int a = aa->a;
 
37
  u_int b = bb->a;
 
38
#endif
 
39
 
 
40
  if (a > b)
 
41
    return 1;
 
42
  if (a < b)
 
43
    return -1;
 
44
  return 0;
 
45
}
 
46
 
 
47
void gen(T2S *t, char *name)
 
48
{
 
49
  qsort(t, t2sn, sizeof(T2S), qcmp);
 
50
  FILE *fw;
 
51
 
 
52
  if ((fw=fopen(name,"w"))==NULL)
 
53
    p_err("cannot write %s", name);
 
54
  fwrite(t, sizeof(T2S), t2sn, fw);
 
55
  fclose(fw);
 
56
}
 
57
 
 
58
int main()
 
59
{
 
60
  /* This data file is maintained by caleb-, ONLY for conversion
 
61
   * from Traditional Chinese to Simplified Chinese.
 
62
   * (Single Chinese glyph, one to one conversion.)
 
63
   *
 
64
   * However, "hime-sim2trad" also use this file to do "S to T"
 
65
   * conversion, so the conversion result is not very ideal.
 
66
   */
 
67
  char *fname="t2s-file.table";
 
68
  FILE *fp=fopen(fname, "r");
 
69
 
 
70
  if (!fp)
 
71
    dbg("cannot open %s", fname);
 
72
 
 
73
  while (!feof(fp)) {
 
74
    char tt[128];
 
75
    tt[0]=0;
 
76
    fgets(tt, sizeof(tt), fp);
 
77
    if (!tt[0])
 
78
      break;
 
79
    char a[9],b[9];
 
80
 
 
81
    bzero(a, sizeof(a));
 
82
    bzero(b, sizeof(b));
 
83
    sscanf(tt,"%s %s",a,b);
 
84
    memcpy(&t2s[t2sn].a, a, sizeof(t2s[0].a));
 
85
    memcpy(&t2s[t2sn].b, b, sizeof(t2s[0].b));
 
86
    memcpy(&s2t[t2sn].b, a, sizeof(s2t[0].a));
 
87
    memcpy(&s2t[t2sn].a, b, sizeof(s2t[0].b));
 
88
    t2sn++;
 
89
//    dbg("%s %s\n", a,b);
 
90
  }
 
91
 
 
92
  gen(t2s, "t2s.dat");
 
93
  gen(s2t, "s2t.dat");
 
94
 
 
95
  return 0;
 
96
}