t2s-file.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2020 The HIME team, Taiwan
  3. * Copyright (C) 2010 Edward Der-Hua Liu, Hsin-Chu, Taiwan
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation version 2.1
  8. * of the License.
  9. *
  10. * This library 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 GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "t2s-file.h"
  23. #include "util.h"
  24. #define SIZE 3000
  25. static T2S t2s[SIZE], s2t[SIZE];
  26. static int t2sn;
  27. static int qcmp (const void *aa0, const void *bb0) {
  28. const T2S *aa = (const T2S *) aa0;
  29. const T2S *bb = (const T2S *) bb0;
  30. if (aa->a > bb->a)
  31. return 1;
  32. if (aa->a < bb->a)
  33. return -1;
  34. return 0;
  35. }
  36. static void gen (T2S *t, const char *name) {
  37. qsort (t, t2sn, sizeof (T2S), qcmp);
  38. FILE *fw = fopen (name, "w");
  39. if (!fw)
  40. p_err ("cannot write %s", name);
  41. fwrite (t, sizeof (T2S), t2sn, fw);
  42. fclose (fw);
  43. }
  44. int main (void) {
  45. /*
  46. * This data file is maintained by caleb-, ONLY for conversion
  47. * from Traditional Chinese to Simplified Chinese.
  48. * (Single Chinese glyph, one to one conversion.)
  49. *
  50. * However, "hime-sim2trad" also use this file to do "S to T"
  51. * conversion, so the conversion result is not very ideal.
  52. */
  53. t2sn = 0;
  54. const char *fname = "t2s-file.table";
  55. FILE *fp = fopen (fname, "r");
  56. if (!fp)
  57. dbg ("cannot open %s", fname);
  58. while (!feof (fp) && t2sn < SIZE) {
  59. char tt[128];
  60. tt[0] = '\0';
  61. fgets (tt, sizeof (tt), fp);
  62. if (!tt[0])
  63. break;
  64. char a[9], b[9];
  65. memset (a, 0, sizeof (a));
  66. memset (b, 0, sizeof (b));
  67. sscanf (tt, "%s %s", a, b);
  68. memcpy (&t2s[t2sn].a, a, sizeof (t2s[0].a));
  69. memcpy (&t2s[t2sn].b, b, sizeof (t2s[0].b));
  70. memcpy (&s2t[t2sn].b, a, sizeof (s2t[0].a));
  71. memcpy (&s2t[t2sn].a, b, sizeof (s2t[0].b));
  72. t2sn++;
  73. }
  74. gen (t2s, "t2s.dat");
  75. gen (s2t, "s2t.dat");
  76. return 0;
  77. }