summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-08-31 17:11:40 +0800
committerPeng Wu <alexepico@gmail.com>2011-08-31 17:11:40 +0800
commit27f3ec826fbd49c1ebca756405dec6974d5f1c5c (patch)
treeaef58201bc845eb6fdedfb02b861360052a67902 /utils
parentd6288dc6efd141b0307a56f0660771e11a1cc690 (diff)
downloadlibpinyin-27f3ec826fbd49c1ebca756405dec6974d5f1c5c.tar.gz
libpinyin-27f3ec826fbd49c1ebca756405dec6974d5f1c5c.tar.xz
libpinyin-27f3ec826fbd49c1ebca756405dec6974d5f1c5c.zip
add gen zhuyin map
Diffstat (limited to 'utils')
-rw-r--r--utils/storage/Makefile.am10
-rw-r--r--utils/storage/gen_zhuyin_map.cpp116
2 files changed, 125 insertions, 1 deletions
diff --git a/utils/storage/Makefile.am b/utils/storage/Makefile.am
index 36452a4..db31fe6 100644
--- a/utils/storage/Makefile.am
+++ b/utils/storage/Makefile.am
@@ -21,7 +21,15 @@ INCLUDES = -I$(top_srcdir)/src \
-I$(top_srcdir)/src/lookup \
@GLIB2_CPPFLAGS@
-noinst_PROGRAMS = gen_pinyin_table gen_binary_files export_interpolation import_interpolation
+noinst_PROGRAMS = gen_zhuyin_map \
+ gen_pinyin_table \
+ gen_binary_files \
+ export_interpolation \
+ import_interpolation
+
+gen_zhuyin_map_SOURCES = gen_zhuyin_map.cpp
+
+gen_zhuyin_map_LDADD = ../../src/libpinyin_internal.la @GLIB2_LDFLAGS@
gen_pinyin_table_SOURCES = gen_pinyin_table.cpp
diff --git a/utils/storage/gen_zhuyin_map.cpp b/utils/storage/gen_zhuyin_map.cpp
new file mode 100644
index 0000000..68efbcc
--- /dev/null
+++ b/utils/storage/gen_zhuyin_map.cpp
@@ -0,0 +1,116 @@
+/*
+ * libpinyin
+ * Library to deal with pinyin.
+ *
+ * Copyright (C) 2006 James Su <suzhe@tsinghua.org.cn>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "pinyin_internal.h"
+#include <stdio.h>
+#include <string.h>
+
+
+static const char *map_names [] = {
+ "__zhuyin_standard_map",
+ "__zhuyin_hsu_map",
+ "__zhuyin_ibm_map",
+ "__zhuyin_gin_yieh_map",
+ "__zhuyin_et_map",
+ "__zhuyin_et26_map",
+ 0
+};
+
+static const char *input_keys [] = {
+ "1qaz2wsxedcrfv5tgbyhnujm8ik,9ol.0p;/-7634", /* standard kb */
+ "bpmfdtnlgkhjvcjvcrzasexuyhgeiawomnkllsdfj", /* hsu */
+ "1234567890-qwertyuiopasdfghjkl;zxcvbn/m,.", /* IBM */
+ "2wsx3edcrfvtgb6yhnujm8ik,9ol.0p;/-['=1qaz", /* Gin-yieh */
+ "bpmfdtnlvkhg7c,./j;'sexuaorwiqzy890-=1234", /* ET */
+ "bpmfdtnlvkhgvcgycjqwsexuaorwiqzpmntlhdfjk", /* ET26 */
+ 0
+};
+
+static PinyinKey pinyin_keys [] =
+{
+ PinyinKey (PINYIN_Bo), PinyinKey (PINYIN_Po), PinyinKey (PINYIN_Mo), PinyinKey (PINYIN_Fo),
+ PinyinKey (PINYIN_De), PinyinKey (PINYIN_Te), PinyinKey (PINYIN_Ne), PinyinKey (PINYIN_Le),
+ PinyinKey (PINYIN_Ge), PinyinKey (PINYIN_Ke), PinyinKey (PINYIN_He), PinyinKey (PINYIN_Ji),
+ PinyinKey (PINYIN_Qi), PinyinKey (PINYIN_Xi), PinyinKey (PINYIN_Zhi), PinyinKey (PINYIN_Chi),
+ PinyinKey (PINYIN_Shi), PinyinKey (PINYIN_Ri), PinyinKey (PINYIN_Zi), PinyinKey (PINYIN_Ci),
+ PinyinKey (PINYIN_Si), PinyinKey (PINYIN_ZeroInitial,PINYIN_I), PinyinKey (PINYIN_ZeroInitial,PINYIN_U), PinyinKey (PINYIN_ZeroInitial,PINYIN_V),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_A), PinyinKey (PINYIN_ZeroInitial,PINYIN_O), PinyinKey (PINYIN_ZeroInitial,PINYIN_E), PinyinKey (PINYIN_ZeroInitial,PINYIN_Ea),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_Ai), PinyinKey (PINYIN_ZeroInitial,PINYIN_Ei), PinyinKey (PINYIN_ZeroInitial,PINYIN_Ao), PinyinKey (PINYIN_ZeroInitial,PINYIN_Ou),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_An), PinyinKey (PINYIN_ZeroInitial,PINYIN_En), PinyinKey (PINYIN_ZeroInitial,PINYIN_Ang),PinyinKey (PINYIN_ZeroInitial,PINYIN_Eng),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_Er),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_ZeroFinal,PINYIN_Fifth),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_ZeroFinal,PINYIN_Second),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_ZeroFinal,PINYIN_Third),
+ PinyinKey (PINYIN_ZeroInitial,PINYIN_ZeroFinal,PINYIN_Fourth)
+};
+
+void print_map (int num)
+{
+ PinyinKey map[93][3];
+
+ map[0][0].set_tone (PINYIN_First);
+
+ const char *p = input_keys [num];
+
+ for (size_t i=0; *p; ++i, ++p) {
+ size_t idx = *p - 0x20;
+ size_t n;
+ for (n=0; n<3; ++n)
+ if (map[idx][n].is_empty ()) break;
+
+ map[idx][n] = pinyin_keys [i];
+ }
+
+ printf("static const PinyinKey %s [][3] = \n{\n", map_names[num]);
+
+ char buf11[40];
+ char buf12[40];
+ char buf13[40];
+
+ char buf21[40];
+ char buf22[40];
+ char buf23[40];
+
+ for (size_t i=0; i<93; ++i) {
+ snprintf (buf11, 40, "PinyinKey(%d)", map[i][0].get_value ());
+ snprintf (buf12, 40, "PinyinKey(%d)", map[i][1].get_value ());
+ snprintf (buf13, 40, "PinyinKey(%d)", map[i][2].get_value ());
+
+ snprintf (buf21, 40, "/* %s */", map[i][0].get_key_string ());
+ snprintf (buf22, 40, "/* %s */", map[i][1].get_key_string ());
+ snprintf (buf23, 40, "/* %s */", map[i][2].get_key_string ());
+
+ printf ("/* %c */{%-15s%9s, %-15s%9s, %-15s%9s},\n", i+0x20, buf11, buf21, buf12, buf22, buf13, buf23);
+ }
+
+ printf("};\n\n");
+}
+
+int main ()
+{
+ for (int i=0; input_keys[i]; ++i)
+ print_map (i);
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab
+*/