tamago-4.0.6
[elisp/tamago.git] / egg-com.el
1 ;;; egg-com.el --- Communication Routines in Egg Input Method Architecture
2
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc
4
5 ;; Author: Hisashi Miyashita <himi@bird.scphys.kyoto-u.ac.jp>
6 ;;         NIIBE Yutaka <gniibe@chroot.org>
7 ;;         KATAYAMA Yoshio <kate@pfu.co.jp>  ; Korean, Chinese support.
8
9 ;; Maintainer: TOMURA Satoru <tomura@etl.go.jp>
10
11 ;; Keywords: mule, multilingual, input method
12
13 ;; This file is part of EGG.
14
15 ;; EGG is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19
20 ;; EGG is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
29
30 ;;; Commentary:
31
32 ;;; Code:
33
34
35 (require 'egg-edep)
36
37 (defvar egg-fixed-euc '(fixed-euc-jp))
38 (make-variable-buffer-local 'egg-fixed-euc)
39 (put 'egg-fixed-euc 'permanent-local t)
40
41 (defvar egg-mb-euc 'euc-japan)
42 (make-variable-buffer-local 'egg-mb-euc)
43 (put 'egg-mb-euc 'permanent-local t)
44
45 ;; Japanese
46
47 (eval-and-compile
48 (define-ccl-program ccl-decode-fixed-euc-jp
49   `(2
50     ((r2 = ,(charset-id 'japanese-jisx0208))
51      (r3 = ,(charset-id 'japanese-jisx0212))
52      (r4 = ,(charset-id 'katakana-jisx0201))
53      (read r0)
54      (loop
55       (read r1)
56       (if (r0 < ?\x80)
57           ((r0 = r1)
58            (if (r1 < ?\x80)
59                (write-read-repeat r0))
60            (write r4)
61            (write-read-repeat r0))
62         ((if (r1 > ?\x80)
63              ((write r2 r0)
64               (r0 = r1)
65               (write-read-repeat r0))
66            ((write r3 r0)
67             (r0 = (r1 | ?\x80))
68             (write-read-repeat r0)))))))))
69
70 (define-ccl-program ccl-encode-fixed-euc-jp
71   `(2
72     ((read r0)
73      (loop
74       (if (r0 == ,(charset-id 'latin-jisx0201))                   ; Unify
75           ((read r0)
76            (r0 &= ?\x7f)))
77       (if (r0 < ?\x80)                                            ;G0
78           ((write 0)
79            (write-read-repeat r0)))
80       (r6 = (r0 == ,(charset-id 'japanese-jisx0208)))
81       (r6 |= (r0 == ,(charset-id 'japanese-jisx0208-1978)))
82       (if r6                                                      ;G1
83           ((read r0)
84            (write r0)
85            (read r0)
86            (write-read-repeat r0)))
87       (if (r0 == ,(charset-id 'katakana-jisx0201))                ;G2
88           ((read r0)
89            (write 0)
90            (write-read-repeat r0)))
91       (if (r0 == ,(charset-id 'japanese-jisx0212))                ;G3
92           ((read r0)
93            (write r0)
94            (read r0)
95            (r0 &= ?\x7f)
96            (write-read-repeat r0)))
97       (read r0)
98       (repeat)))))
99 )
100
101 (make-coding-system 'fixed-euc-jp 4 ?W "Coding System for fixed EUC Japanese"
102                     (cons ccl-decode-fixed-euc-jp ccl-encode-fixed-euc-jp))
103
104 ;; Korean
105
106 (eval-and-compile
107 (define-ccl-program ccl-decode-fixed-euc-kr
108   `(2
109     ((r2 = ,(charset-id 'korean-ksc5601))
110      (read r0)
111      (loop
112       (read r1)
113       (if (r0 < ?\x80)
114           (r0 = r1 & ?\x7f)
115         ((write r2 r0)
116          (r0 = r1 | ?\x80)))
117       (write-read-repeat r0)))))
118
119 (define-ccl-program ccl-encode-fixed-euc-kr
120   `(2
121     ((read r0)
122      (loop
123       (if (r0 < ?\x80)
124           ((write 0)
125            (write-read-repeat r0)))
126       (if (r0 == ,(charset-id 'korean-ksc5601))
127           ((read r0)
128            (write r0)
129            (read r0)
130            (write-read-repeat r0)))
131       (read r0)
132       (repeat)))))
133 )
134
135 (make-coding-system 'fixed-euc-kr 4 ?W "Coding System for fixed EUC Korean"
136                     (cons ccl-decode-fixed-euc-kr ccl-encode-fixed-euc-kr))
137
138 ;; Chinese
139 (defconst egg-pinyin-shengmu
140   '((""  . 0)  ("B" . 1)  ("C"  . 2)  ("Ch" . 3)  ("D" . 4)
141     ("F" . 5)  ("G" . 6)  ("H"  . 7)  ("J"  . 8)  ("K" . 9)
142     ("L" . 10) ("M" . 11) ("N"  . 12) ("P"  . 13) ("Q" . 14)
143     ("R" . 15) ("S" . 16) ("Sh" . 17) ("T"  . 18) ("W" . 19)
144     ("X" . 20) ("Y" . 21) ("Z"  . 22) ("Zh" . 23)))
145
146 (defconst egg-pinyin-yunmu
147   '(("\e(0@\e(B"      0 0) ("\e(0@\e(B"      0 1) ("\e(0@\e(B"      0 3) ("\e(0@\e(B"      0 5) ("\e(0@\e(B"      0 7)
148     ("a\e(0@\e(B"     1 0) ("\e(0!@\e(B"     1 1) ("\e(0"@\e(B"     1 3) ("\e(0#@\e(B"     1 5) ("\e(0$@\e(B"     1 7)
149     ("ai\e(0@\e(B"    2 0) ("\e(0!\e(Bi\e(0@\e(B"    2 1) ("\e(0"\e(Bi\e(0@\e(B"    2 3) ("\e(0#\e(Bi\e(0@\e(B"    2 5) ("\e(0$\e(Bi\e(0@\e(B"    2 7)
150     ("an\e(0@\e(B"    3 0) ("\e(0!\e(Bn\e(0@\e(B"    3 1) ("\e(0"\e(Bn\e(0@\e(B"    3 3) ("\e(0#\e(Bn\e(0@\e(B"    3 5) ("\e(0$\e(Bn\e(0@\e(B"    3 7)
151     ("ang\e(0@\e(B"   4 0) ("\e(0!\e(Bng\e(0@\e(B"   4 1) ("\e(0"\e(Bng\e(0@\e(B"   4 3) ("\e(0#\e(Bng\e(0@\e(B"   4 5) ("\e(0$\e(Bng\e(0@\e(B"   4 7)
152     ("ao\e(0@\e(B"    5 0) ("\e(0!\e(Bo\e(0@\e(B"    5 1) ("\e(0"\e(Bo\e(0@\e(B"    5 3) ("\e(0#\e(Bo\e(0@\e(B"    5 5) ("\e(0$\e(Bo\e(0@\e(B"    5 7)
153     ("e\e(0@\e(B"     6 0) ("\e(0%@\e(B"     6 1) ("\e(0&@\e(B"     6 3) ("\e(0'@\e(B"     6 5) ("\e(0(@\e(B"     6 7)
154     ("ei\e(0@\e(B"    7 0) ("\e(0%\e(Bi\e(0@\e(B"    7 1) ("\e(0&\e(Bi\e(0@\e(B"    7 3) ("\e(0'\e(Bi\e(0@\e(B"    7 5) ("\e(0(\e(Bi\e(0@\e(B"    7 7)
155     ("en\e(0@\e(B"    8 0) ("\e(0%\e(Bn\e(0@\e(B"    8 1) ("\e(0&\e(Bn\e(0@\e(B"    8 3) ("\e(0'\e(Bn\e(0@\e(B"    8 5) ("\e(0(\e(Bn\e(0@\e(B"    8 7)
156     ("eng\e(0@\e(B"   9 0) ("\e(0%\e(Bng\e(0@\e(B"   9 1) ("\e(0&\e(Bng\e(0@\e(B"   9 3) ("\e(0'\e(Bng\e(0@\e(B"   9 5) ("\e(0(\e(Bng\e(0@\e(B"   9 7)
157     ("er\e(0@\e(B"   10 0) ("\e(0%\e(Br\e(0@\e(B"   10 1) ("\e(0&\e(Br\e(0@\e(B"   10 3) ("\e(0'\e(Br\e(0@\e(B"   10 5) ("\e(0(\e(Br\e(0@\e(B"   10 7)
158     ("i\e(0@\e(B"    11 0) ("\e(0)@\e(B"    11 1) ("\e(0*@\e(B"    11 3) ("\e(0+@\e(B"    11 5) ("\e(0,@\e(B"    11 7)
159     ("ia\e(0@\e(B"   12 0) ("i\e(0!@\e(B"   12 1) ("i\e(0"@\e(B"   12 3) ("i\e(0#@\e(B"   12 5) ("i\e(0$@\e(B"   12 7)
160     ("ian\e(0@\e(B"  13 0) ("i\e(0!\e(Bn\e(0@\e(B"  13 1) ("i\e(0"\e(Bn\e(0@\e(B"  13 3) ("i\e(0#\e(Bn\e(0@\e(B"  13 5) ("i\e(0$\e(Bn\e(0@\e(B"  13 7)
161     ("iang\e(0@\e(B" 14 0) ("i\e(0!\e(Bng\e(0@\e(B" 14 1) ("i\e(0"\e(Bng\e(0@\e(B" 14 3) ("i\e(0#\e(Bng\e(0@\e(B" 14 5) ("i\e(0$\e(Bng\e(0@\e(B" 14 7)
162     ("iao\e(0@\e(B"  15 0) ("i\e(0!\e(Bo\e(0@\e(B"  15 1) ("i\e(0"\e(Bo\e(0@\e(B"  15 3) ("i\e(0#\e(Bo\e(0@\e(B"  15 5) ("i\e(0$\e(Bo\e(0@\e(B"  15 7)
163     ("ie\e(0@\e(B"   16 0) ("i\e(0%@\e(B"   16 1) ("i\e(0&@\e(B"   16 3) ("i\e(0'@\e(B"   16 5) ("i\e(0(@\e(B"   16 7)
164     ("in\e(0@\e(B"   17 0) ("\e(0)\e(Bn\e(0@\e(B"   17 1) ("\e(0*\e(Bn\e(0@\e(B"   17 3) ("\e(0+\e(Bn\e(0@\e(B"   17 5) ("\e(0,\e(Bn\e(0@\e(B"   17 7)
165     ("ing\e(0@\e(B"  18 0) ("\e(0)\e(Bng\e(0@\e(B"  18 1) ("\e(0*\e(Bng\e(0@\e(B"  18 3) ("\e(0+\e(Bng\e(0@\e(B"  18 5) ("\e(0,\e(Bng\e(0@\e(B"  18 7)
166     ("iong\e(0@\e(B" 19 0) ("i\e(0-\e(Bng\e(0@\e(B" 19 1) ("i\e(0.\e(Bng\e(0@\e(B" 19 3) ("i\e(0/\e(Bng\e(0@\e(B" 19 5) ("i\e(00\e(Bng\e(0@\e(B" 19 7)
167     ("iu\e(0@\e(B"   20 0) ("i\e(01@\e(B"   20 1) ("i\e(02@\e(B"   20 3) ("i\e(03@\e(B"   20 5) ("i\e(04@\e(B"   20 7)
168     ("m\e(0@\e(B"    21 0) ("m\e(0@\e(B"    21 1) ("m\e(0@\e(B"    21 3) ("m\e(0@\e(B"    21 5) ("m\e(0@\e(B"    21 7)
169     ("n\e(0@\e(B"    22 0) ("n\e(0@\e(B"    22 1) ("\e(0=@\e(B"    22 3) ("\e(0>@\e(B"    22 5) ("\e(0?@\e(B"    22 7)
170     ("ng\e(0@\e(B"   23 0) ("ng\e(0@\e(B"   23 1) ("ng\e(0@\e(B"   23 3) ("ng\e(0@\e(B"   23 5) ("ng\e(0@\e(B"   23 7)
171     ("o\e(0@\e(B"    24 0) ("\e(0-@\e(B"    24 1) ("\e(0.@\e(B"    24 3) ("\e(0/@\e(B"    24 5) ("\e(00@\e(B"    24 7)
172     ("ong\e(0@\e(B"  25 0) ("\e(0-\e(Bng\e(0@\e(B"  25 1) ("\e(0.\e(Bng\e(0@\e(B"  25 3) ("\e(0/\e(Bng\e(0@\e(B"  25 5) ("\e(00\e(Bng\e(0@\e(B"  25 7)
173     ("ou\e(0@\e(B"   26 0) ("\e(0-\e(Bu\e(0@\e(B"   26 1) ("\e(0.\e(Bu\e(0@\e(B"   26 3) ("\e(0/\e(Bu\e(0@\e(B"   26 5) ("\e(00\e(Bu\e(0@\e(B"   26 7)
174     ("u\e(0@\e(B"    27 0) ("\e(01@\e(B"    27 1) ("\e(02@\e(B"    27 3) ("\e(03@\e(B"    27 5) ("\e(04@\e(B"    27 7)
175     ("ua\e(0@\e(B"   28 0) ("u\e(0!@\e(B"   28 1) ("u\e(0"@\e(B"   28 3) ("u\e(0#@\e(B"   28 5) ("u\e(0$@\e(B"   28 7)
176     ("uai\e(0@\e(B"  29 0) ("u\e(0!\e(Bi\e(0@\e(B"  29 1) ("u\e(0"\e(Bi\e(0@\e(B"  29 3) ("u\e(0#\e(Bi\e(0@\e(B"  29 5) ("u\e(0$\e(Bi\e(0@\e(B"  29 7)
177     ("uan\e(0@\e(B"  30 0) ("u\e(0!\e(Bn\e(0@\e(B"  30 1) ("u\e(0"\e(Bn\e(0@\e(B"  30 3) ("u\e(0#\e(Bn\e(0@\e(B"  30 5) ("u\e(0$\e(Bn\e(0@\e(B"  30 7)
178     ("uang\e(0@\e(B" 31 0) ("u\e(0!\e(Bng\e(0@\e(B" 31 1) ("u\e(0"\e(Bng\e(0@\e(B" 31 3) ("u\e(0#\e(Bng\e(0@\e(B" 31 5) ("u\e(0$\e(Bng\e(0@\e(B" 31 7)
179     ("ue\e(0@\e(B"   32 0) ("u\e(0%@\e(B"   32 1) ("u\e(0&@\e(B"   32 3) ("u\e(0'@\e(B"   32 5) ("u\e(0(@\e(B"   32 7)
180     ("ui\e(0@\e(B"   33 0) ("u\e(0)@\e(B"   33 1) ("u\e(0*@\e(B"   33 3) ("u\e(0+@\e(B"   33 5) ("u\e(0,@\e(B"   33 7)
181     ("un\e(0@\e(B"   34 0) ("\e(01\e(Bn\e(0@\e(B"   34 1) ("\e(02\e(Bn\e(0@\e(B"   34 3) ("\e(03\e(Bn\e(0@\e(B"   34 5) ("\e(04\e(Bn\e(0@\e(B"   34 7)
182     ("uo\e(0@\e(B"   35 0) ("u\e(0-@\e(B"   35 1) ("u\e(0.@\e(B"   35 3) ("u\e(0/@\e(B"   35 5) ("u\e(00@\e(B"   35 7)
183     ("\e(09@\e(B"    36 0) ("\e(05@\e(B"    36 1) ("\e(06@\e(B"    36 3) ("\e(07@\e(B"    36 5) ("\e(08@\e(B"    36 7)
184     ("\e(09\e(Be\e(0@\e(B"   37 0) ("\e(09%@\e(B"   37 1) ("\e(09&@\e(B"   37 3) ("\e(09'@\e(B"   37 5) ("\e(09(@\e(B"   37 7)
185     ("0\e(0@\e(B"    38 0) ("1\e(0@\e(B"    38 1) ("2\e(0@\e(B"    38 3) ("3\e(0@\e(B"    38 5) ("4\e(0@\e(B"    38 7)))
186
187 (defconst egg-pinyin-table
188   [
189    0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
190    0 1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1
191    0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1
192    0 1 1 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1
193    0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1
194    0 1 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1
195    0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1
196    0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1
197    0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 1
198    0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1
199    0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1
200    0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1
201    0 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 1 1 1
202    0 1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1
203    0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 1
204    0 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 1 1 1 0 0 1
205    0 1 1 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1
206    0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 1
207    0 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1
208    0 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1
209    0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 1
210    0 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 1 0 0 0 1
211    0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1
212    0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1
213    ])
214
215 (defconst egg-zhuyin-shengmu
216   '((""  .  0) ("\e(0E\e(B" .  1) ("\e(0X\e(B" .  2) ("\e(0T\e(B" .  3) ("\e(0I\e(B" .  4)
217     ("\e(0H\e(B" .  5) ("\e(0M\e(B" .  6) ("\e(0O\e(B" .  7) ("\e(0P\e(B" .  8) ("\e(0N\e(B" .  9)
218     ("\e(0L\e(B" . 10) ("\e(0G\e(B" . 11) ("\e(0K\e(B" . 12) ("\e(0F\e(B" . 13) ("\e(0Q\e(B" . 14)
219     ("\e(0V\e(B" . 15) ("\e(0Y\e(B" . 16) ("\e(0U\e(B" . 17) ("\e(0J\e(B" . 18) ("\e(0h\e(B" . 19)
220     ("\e(0R\e(B" . 20) ("\e(0g\e(B" . 21) ("\e(0W\e(B" . 22) ("\e(0S\e(B" . 23)))
221
222 (defconst egg-zhuyin-yunmu
223   '(("\e(0@\e(B"    0 0) ("\e(0A\e(B"    0 1) ("\e(0B\e(B"    0 3) ("\e(0C\e(B"    0 5) ("\e(0D\e(B"    0 7) ; i
224     ("\e(0Z@\e(B"   1 0) ("\e(0ZA\e(B"   1 1) ("\e(0ZB\e(B"   1 3) ("\e(0ZC\e(B"   1 5) ("\e(0ZD\e(B"   1 7) ; a
225     ("\e(0^@\e(B"   2 0) ("\e(0^A\e(B"   2 1) ("\e(0^B\e(B"   2 3) ("\e(0^C\e(B"   2 5) ("\e(0^D\e(B"   2 7) ; ai
226     ("\e(0b@\e(B"   3 0) ("\e(0bA\e(B"   3 1) ("\e(0bB\e(B"   3 3) ("\e(0bC\e(B"   3 5) ("\e(0bD\e(B"   3 7) ; an
227     ("\e(0d@\e(B"   4 0) ("\e(0dA\e(B"   4 1) ("\e(0dB\e(B"   4 3) ("\e(0dC\e(B"   4 5) ("\e(0dD\e(B"   4 7) ; ang
228     ("\e(0`@\e(B"   5 0) ("\e(0`A\e(B"   5 1) ("\e(0`B\e(B"   5 3) ("\e(0`C\e(B"   5 5) ("\e(0`D\e(B"   5 7) ; ao
229     ("\e(0\@\e(B"   6 0) ("\e(0\A\e(B"   6 1) ("\e(0\B\e(B"   6 3) ("\e(0\C\e(B"   6 5) ("\e(0\D\e(B"   6 7) ; e
230     ("\e(0_@\e(B"   7 0) ("\e(0_A\e(B"   7 1) ("\e(0_B\e(B"   7 3) ("\e(0_C\e(B"   7 5) ("\e(0_D\e(B"   7 7) ; ei
231     ("\e(0c@\e(B"   8 0) ("\e(0cA\e(B"   8 1) ("\e(0cB\e(B"   8 3) ("\e(0cC\e(B"   8 5) ("\e(0cD\e(B"   8 7) ; en
232     ("\e(0e@\e(B"   9 0) ("\e(0eA\e(B"   9 1) ("\e(0eB\e(B"   9 3) ("\e(0eC\e(B"   9 5) ("\e(0eD\e(B"   9 7) ; eng
233     ("\e(0f@\e(B"  10 0) ("\e(0fA\e(B"  10 1) ("\e(0fB\e(B"  10 3) ("\e(0fC\e(B"  10 5) ("\e(0fD\e(B"  10 7) ; er
234     ("\e(0g@\e(B"  11 0) ("\e(0gA\e(B"  11 1) ("\e(0gB\e(B"  11 3) ("\e(0gC\e(B"  11 5) ("\e(0gD\e(B"  11 7) ; i
235     ("\e(0gZ@\e(B" 12 0) ("\e(0gZA\e(B" 12 1) ("\e(0gZB\e(B" 12 3) ("\e(0gZC\e(B" 12 5) ("\e(0gZD\e(B" 12 7) ; ia
236     ("\e(0gb@\e(B" 13 0) ("\e(0gbA\e(B" 13 1) ("\e(0gbB\e(B" 13 3) ("\e(0gbC\e(B" 13 5) ("\e(0gbD\e(B" 13 7) ; ian
237     ("\e(0gd@\e(B" 14 0) ("\e(0gdA\e(B" 14 1) ("\e(0gdB\e(B" 14 3) ("\e(0gdC\e(B" 14 5) ("\e(0gdD\e(B" 14 7) ; iang
238     ("\e(0g`@\e(B" 15 0) ("\e(0g`A\e(B" 15 1) ("\e(0g`B\e(B" 15 3) ("\e(0g`C\e(B" 15 5) ("\e(0g`D\e(B" 15 7) ; iao
239     ("\e(0g]@\e(B" 16 0) ("\e(0g]A\e(B" 16 1) ("\e(0g]B\e(B" 16 3) ("\e(0g]C\e(B" 16 5) ("\e(0g]D\e(B" 16 7) ; ie
240     ("\e(0gc@\e(B" 17 0) ("\e(0gcA\e(B" 17 1) ("\e(0gcB\e(B" 17 3) ("\e(0gcC\e(B" 17 5) ("\e(0gcD\e(B" 17 7) ; in
241     ("\e(0ge@\e(B" 18 0) ("\e(0geA\e(B" 18 1) ("\e(0geB\e(B" 18 3) ("\e(0geC\e(B" 18 5) ("\e(0geD\e(B" 18 7) ; ing
242     ("\e(0ie@\e(B" 19 0) ("\e(0ieA\e(B" 19 1) ("\e(0ieB\e(B" 19 3) ("\e(0ieC\e(B" 19 5) ("\e(0ieD\e(B" 19 7) ; iong
243     ("\e(0ga@\e(B" 20 0) ("\e(0gaA\e(B" 20 1) ("\e(0gaB\e(B" 20 3) ("\e(0gaC\e(B" 20 5) ("\e(0gaD\e(B" 20 7) ; iu
244     ("\e(0G@\e(B"  21 0) ("\e(0GA\e(B"  21 1) ("\e(0GB\e(B"  21 3) ("\e(0GC\e(B"  21 5) ("\e(0GD\e(B"  21 7) ; m
245     ("\e(0K@\e(B"  22 0) ("\e(0KA\e(B"  22 1) ("\e(0KB\e(B"  22 3) ("\e(0KC\e(B"  22 5) ("\e(0KD\e(B"  22 7) ; n
246     ("@\e(0@\e(B"  23 0) ("@\e(0A\e(B"  23 1) ("@\e(0B\e(B"  23 3) ("@\e(0C\e(B"  23 5) ("@\e(0D\e(B"  23 7) ; ng
247     ("\e(0[@\e(B"  24 0) ("\e(0[A\e(B"  24 1) ("\e(0[B\e(B"  24 3) ("\e(0[C\e(B"  24 5) ("\e(0[D\e(B"  24 7) ; o
248     ("\e(0he@\e(B" 25 0) ("\e(0heA\e(B" 25 1) ("\e(0heB\e(B" 25 3) ("\e(0heC\e(B" 25 5) ("\e(0heD\e(B" 25 7) ; ong
249     ("\e(0a@\e(B"  26 0) ("\e(0aA\e(B"  26 1) ("\e(0aB\e(B"  26 3) ("\e(0aC\e(B"  26 5) ("\e(0aD\e(B"  26 7) ; ou
250     ("\e(0h@\e(B"  27 0) ("\e(0hA\e(B"  27 1) ("\e(0hB\e(B"  27 3) ("\e(0hC\e(B"  27 5) ("\e(0hD\e(B"  27 7) ; u
251     ("\e(0hZ@\e(B" 28 0) ("\e(0hZA\e(B" 28 1) ("\e(0hZB\e(B" 28 3) ("\e(0hZC\e(B" 28 5) ("\e(0hZD\e(B" 28 7) ; ua
252     ("\e(0h^@\e(B" 29 0) ("\e(0h^A\e(B" 29 1) ("\e(0h^B\e(B" 29 3) ("\e(0h^C\e(B" 29 5) ("\e(0h^D\e(B" 29 7) ; uai
253     ("\e(0hb@\e(B" 30 0) ("\e(0hbA\e(B" 30 1) ("\e(0hbB\e(B" 30 3) ("\e(0hbC\e(B" 30 5) ("\e(0hbD\e(B" 30 7) ; uan
254     ("\e(0hd@\e(B" 31 0) ("\e(0hdA\e(B" 31 1) ("\e(0hdB\e(B" 31 3) ("\e(0hdC\e(B" 31 5) ("\e(0hdD\e(B" 31 7) ; uang
255     ("\e(0i]@\e(B" 37 0) ("\e(0i]A\e(B" 37 1) ("\e(0i]B\e(B" 37 3) ("\e(0i]C\e(B" 37 5) ("\e(0i]D\e(B" 37 7) ; ue
256     ("\e(0h_@\e(B" 33 0) ("\e(0h_A\e(B" 33 1) ("\e(0h_B\e(B" 33 3) ("\e(0h_C\e(B" 33 5) ("\e(0h_D\e(B" 33 7) ; ui
257     ("\e(0hc@\e(B" 34 0) ("\e(0hcA\e(B" 34 1) ("\e(0hcB\e(B" 34 3) ("\e(0hcC\e(B" 34 5) ("\e(0hcD\e(B" 34 7) ; un
258     ("\e(0h[@\e(B" 35 0) ("\e(0h[A\e(B" 35 1) ("\e(0h[B\e(B" 35 3) ("\e(0h[C\e(B" 35 5) ("\e(0h[D\e(B" 35 7) ; uo
259     ("\e(0i@\e(B"  36 0) ("\e(0iA\e(B"  36 1) ("\e(0iB\e(B"  36 3) ("\e(0iC\e(B"  36 5) ("\e(0iD\e(B"  36 7) ; \e(09\e(B
260     ("\e(0i]@\e(B" 37 0) ("\e(0i]A\e(B" 37 1) ("\e(0i]B\e(B" 37 3) ("\e(0i]C\e(B" 37 5) ("\e(0i]D\e(B" 37 7) ; \e(09\e(Be
261     ("0\e(0@\e(B"  38 0) ("1\e(0A\e(B"  38 1) ("2\e(0B\e(B"  38 3) ("3\e(0C\e(B"  38 5) ("4\e(0D\e(B"  38 7) ; undefined
262     ("\e(0ib@\e(B" 39 0) ("\e(0ibA\e(B" 39 1) ("\e(0ibB\e(B" 39 3) ("\e(0ibC\e(B" 39 5) ("\e(0ibD\e(B" 39 7) ; \e(09\e(Ban
263     ("\e(0ic@\e(B" 40 0) ("\e(0icA\e(B" 40 1) ("\e(0icB\e(B" 40 3) ("\e(0icC\e(B" 40 5) ("\e(0icD\e(B" 40 7) ; \e(09\e(Bn
264     ))
265
266 (defconst egg-zhuyin-table
267   [
268    ;; empty ShengMu
269    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
270    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x9586 ?\x0000 ?\x9592 ?\x9599
271    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x0000
272    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x959b ?\x95a0 ?\x0000 ?\x959e
273    ?\x95a2
274    ;; ShengMu B
275    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
276    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
277    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000
278    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
279    ?\x0000
280    ;; ShengMu C
281    ?\x828b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
282    ?\x0000 ?\x0280 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
283    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
284    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
285    ?\x0000
286    ;; ShengMu Ch
287    ?\x838b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
288    ?\x0000 ?\x0380 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
289    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
290    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
291    ?\x0000
292    ;; ShengMu D
293    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
294    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
295    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
296    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
297    ?\x0000
298    ;; ShengMu F
299    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
300    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
301    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
302    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
303    ?\x0000
304    ;; ShengMu G
305    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
306    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
307    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
308    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
309    ?\x0000
310    ;; ShengMu H
311    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
312    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
313    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
314    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
315    ?\x0000
316    ;; ShengMu J
317    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
318    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
319    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x08a4 ?\x0000 ?\x0000
320    ?\x08a7 ?\x0000 ?\x08a5 ?\x0000 ?\x08a8 ?\x0000 ?\x889b ?\x88a0 ?\x8000 ?\x889e
321    ?\x88a2
322    ;; ShengMu K
323    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
324    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
325    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
326    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
327    ?\x0000
328    ;; ShengMu L
329    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
330    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
331    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
332    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
333    ?\x0000
334    ;; ShengMu M
335    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
336    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
337    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
338    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
339    ?\x0000
340    ;; ShengMu N
341    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
342    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
343    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
344    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
345    ?\x0000
346    ;; ShengMu P
347    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
348    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
349    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
350    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
351    ?\x0000 
352    ;; ShengMu Q
353    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
354    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
355    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0ea4 ?\x0000 ?\x0000
356    ?\x0ea7 ?\x0000 ?\x0ea5 ?\x0000 ?\x0ea8 ?\x0000 ?\x8e9b ?\x8ea0 ?\x8000 ?\x8e9e
357    ?\x8ea2
358    ;; ShengMu R
359    ?\x8f8b ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
360    ?\x0000 ?\x0f80 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
361    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
362    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
363    ?\x0000
364    ;; ShengMu S
365    ?\x908b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
366    ?\x0000 ?\x1080 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
367    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
368    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
369    ?\x0000
370    ;; ShengMu Sh
371    ?\x918b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
372    ?\x0000 ?\x1180 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
373    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
374    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
375    ?\x0000
376    ;; ShengMu T
377    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
378    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
379    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
380    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
381    ?\x0000
382    ;; ShengMu W
383    ?\x939b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
384    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
385    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x1380 ?\x0000 ?\x0000
386    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
387    ?\x0000
388    ;; ShengMu X
389    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
390    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
391    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x14a4 ?\x0000 ?\x0000
392    ?\x14a7 ?\x0000 ?\x14a5 ?\x0000 ?\x14a8 ?\x0000 ?\x949b ?\x94a0 ?\x8000 ?\x949e
393    ?\x94a2
394    ;; ShengMu Y 
395    ?\x958b ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0090 ?\x0000 ?\x9591 ?\x9592
396    ?\x0000 ?\x1580 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x1588 ?\x1589 ?\x0000
397    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0093 ?\x8000 ?\x00a4 ?\x0000 ?\x0000
398    ?\x00a7 ?\x0000 ?\x00a5 ?\x0000 ?\x00a8 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
399    ?\x0000
400    ;; ShengMu Z
401    ?\x968b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
402    ?\x0000 ?\x1680 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
403    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
404    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
405    ?\x0000
406    ;; ShengMu Zh 
407    ?\x978b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
408    ?\x0000 ?\x1780 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
409    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
410    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
411    ?\x0000
412    ])
413
414 (defconst egg-chinese-syllable-max-len
415   (max (length "Zhu\e(0!\e(Bng\e(0@\e(B") (length "\e(0ShdA\e(B")))
416
417 (defun egg-chinese-syllable (str pos)
418   (setq str (substring str pos (min (length str)
419                                     (+ pos egg-chinese-syllable-max-len))))
420   (or (car (egg-pinyin-syllable str))
421       (car (egg-zhuyin-syllable str))))
422
423 (defsubst egg-make-fixed-euc-china-code (s y)
424   (cons
425    (+ (* 2 (nth 1 y)) (logand (nth 2 y) 1) 32)
426    (+ (* 4 (if (= s 0) 20 s)) (lsh (nth 2 y) -1) 156)))
427
428 (defun egg-pinyin-syllable (str)
429   (if (eq (string-match "^[A-Za-z\e(0!\e(B-\e(0?\e(B]+\e(0@\e(B" str) 0)
430       (let (s y end)
431         (setq end (match-end 0))
432         (cond
433          ((setq s (cdr (assoc (substring str 0 2) egg-pinyin-shengmu)))
434           (setq y (substring str 2 end)))
435          ((setq s (cdr (assoc (substring str 0 1) egg-pinyin-shengmu)))
436           (setq y (substring str 1 end)))
437          (t
438           (setq s 0 y (substring str 0 end))))
439         (if (and (setq y (assoc y egg-pinyin-yunmu))
440                  (= (aref egg-pinyin-table (+ (* 39 s) (nth 1 y))) 1))
441             (cons end (egg-make-fixed-euc-china-code s y))))))
442
443 (defun egg-zhuyin-syllable (str)
444   (if (eq (string-match "^[\e(0E\e(B-\e(0i\e(B@0-4]+[\e(0@ABCD\e(B]" str) 0)
445       (let (end s y c z (zhuyin-len (length "\e(0E\e(B")))
446         (setq end (match-end 0)
447               c (substring str 0 zhuyin-len)
448               s (cdr (assoc c egg-zhuyin-shengmu))
449               y (assoc (substring str zhuyin-len end) egg-zhuyin-yunmu))
450         (if (or (null (and s y))
451                 (and (or (eq s 11) (eq s 12)) (eq (nth 1 y) 0))) ; [\e(0GK\e(B][\e(0@ABCD\e(B]
452             (setq s 0
453                   y (assoc (substring str 0 end) egg-zhuyin-yunmu)))
454         (if (and y
455                  (setq z (aref egg-zhuyin-table (+ (* 41 s) (nth 1 y))))
456                  (/= (logand z ?\x8000) 0))
457             (if (/= (logand z ?\x80) 0)
458                 (cons end (egg-make-fixed-euc-china-code
459                            (logand (lsh z -8) ?\x7f)
460                            (list nil (logand z ?\x7f) (nth 2 y))))
461               (cons end (egg-make-fixed-euc-china-code s y)))))))
462
463 (defun encode-fixed-euc-china-region (beg end type)
464   "Encode the text in the region to EUC-CN/TW."
465   (let (s syl c cset)
466     (save-excursion
467       (save-restriction
468         (narrow-to-region beg end)
469         (goto-char (point-min))
470         (while (< (point) (point-max))
471           (setq s (buffer-substring
472                    (point)
473                    (min (point-max) (+ (point) egg-chinese-syllable-max-len))))
474           (cond
475            ((setq syl (egg-pinyin-syllable s))
476             (delete-region (point) (+ (point) (car syl)))
477             (insert (car (cdr syl)) (cdr (cdr syl))))
478            ((setq syl (egg-zhuyin-syllable s))
479             (delete-region (point) (+ (point) (car syl)))
480             (insert (car (cdr syl)) (cdr (cdr syl))))
481            (t
482             (setq c (split-char (following-char))
483                   cset (car c))
484             (cond
485              ((or (and (eq cset 'chinese-gb2312) (eq type 'cn))
486                   (and (eq cset 'chinese-cns11643-1) (eq type 'tw)))
487               (delete-char 1)
488               (insert (+ (nth 1 c) 128) (+ (nth 2 c) 128)))
489              ((and (eq cset 'chinese-cns11643-2) (eq type 'tw))
490               (delete-char 1)
491               (insert (+ (nth 1 c) 128) (nth 2 c)))
492              ((eq cset 'chinese-sisheng)
493               (delete-char 1)
494               (insert 0 (+ (nth 1 c) 128)))
495              ((eq cset 'ascii)
496               (delete-char 1)
497               (insert 0 (nth 1 c)))
498              (t
499               (delete-char 1))))))
500         (- (point-max) (point-min))))))
501
502 (defun pre-write-encode-fixed-euc-china (from to type)
503   (let ((buf (current-buffer))
504         (work (get-buffer-create " *pre-write-encoding-work*")))
505     (set-buffer work)
506     (erase-buffer)
507     (if (null (stringp from))
508         (save-excursion
509           (set-buffer buf)
510           (setq from (buffer-substring from to))))
511     (insert (string-as-multibyte from))
512     (encode-fixed-euc-china-region 1 (point-max) type)
513     nil))
514
515 (defun pre-write-encode-euc-cn (from to)
516   (pre-write-encode-fixed-euc-china from to 'cn))
517
518 (defun pre-write-encode-euc-tw (from to)
519   (pre-write-encode-fixed-euc-china from to 'tw))
520
521 (defun decode-fixed-euc-china-region (beg end type zhuyin)
522   "Decode EUC-CN/TW encoded text in the region.
523 Return the length of resulting text."
524   (prog1
525       (let ((str (string-as-unibyte (buffer-substring beg end)))
526             (i 0)
527             l c0 c1 s y ss)
528         (delete-region beg end)
529         (setq l (1- (length str)))
530         (while (< i l)
531           (setq c0 (aref str i)
532                 c1 (aref str (1+ i))
533                 i  (+ i 2))
534           (cond
535            ((eq c0 0)
536             (if (> c1 ?\xa0)
537                 (insert leading-code-private-11
538                         (charset-id 'chinese-sisheng)
539                         c1)
540               (insert c1)))
541            ((>= c0 ?\x80)
542             (cond
543              ((eq type 'cn)
544               (insert (charset-id 'chinese-gb2312) c0 (logior c1 ?\x80)))
545              ((>= c1 ?\x80)
546               (insert (charset-id 'chinese-cns11643-1) c0 c1))
547              (t
548               (insert (charset-id 'chinese-cns11643-2) c0 (+ c1 ?\x80)))))
549            (t
550             (setq c1 (logand c1 ?\x7f))
551             (setq s (- (lsh c1 -2) 7);;(+ (lsh (- c1 32) -2) 1)
552                   y (- (lsh c0 -1) 16);;(lsh (- c0 32) -1)
553                   ss (+ (logand c0 1) (logand c1 3)))
554             (if (and (eq s 20)
555                      (eq (aref egg-pinyin-table (+ (* 39 20) y)) 0))
556                 (setq s 0))
557             (if (null zhuyin)
558                 (setq s (car (nth s egg-pinyin-shengmu))
559                       y (car (nth (+ (* 5 y) ss) egg-pinyin-yunmu)))
560               (setq c0 (aref egg-zhuyin-table (+ (* 41 s) y)))
561               (if (eq (logand c0 ?\x8080) ?\x80)
562                   (setq s (lsh c0 -8)
563                         y (logand c0 ?\x7f)))
564               (setq s (car (nth s egg-zhuyin-shengmu))
565                     y (car (nth (+ (* 5 y) ss) egg-zhuyin-yunmu))))
566             (if enable-multibyte-characters
567                 (insert s y)
568               (insert (string-as-unibyte s) (string-as-unibyte y))))))
569         (- (point) beg))
570     (if (looking-at "\0\0") (forward-char 2))))
571
572 (defun post-read-decode-fixed-euc-china (len type zhuyin)
573   (let ((pos (point))
574         (buffer-modified-p (buffer-modified-p)))
575     (prog1
576         (decode-fixed-euc-china-region pos (+ pos len) type zhuyin)
577       (set-buffer-modified-p buffer-modified-p))))
578
579 (defun post-read-decode-euc-py-cn (len)
580   (post-read-decode-fixed-euc-china len 'cn nil))
581
582 (defun post-read-decode-euc-zy-cn (len)
583   (post-read-decode-fixed-euc-china len 'cn t))
584
585 (defun post-read-decode-euc-py-tw (len)
586   (post-read-decode-fixed-euc-china len 'tw nil))
587
588 (defun post-read-decode-euc-zy-tw (len)
589   (post-read-decode-fixed-euc-china len 'tw t))
590
591 (make-coding-system 'fixed-euc-py-cn 0 ?W
592                     "Coding System for fixed EUC Chinese-gb2312")
593 (coding-system-put 'fixed-euc-py-cn
594                    'pre-write-conversion 'pre-write-encode-euc-cn)
595 (coding-system-put 'fixed-euc-py-cn
596                    'post-read-conversion 'post-read-decode-euc-py-cn)
597
598 (make-coding-system 'fixed-euc-zy-cn 0 ?W
599                     "Coding System for fixed EUC Chinese-gb2312")
600 (coding-system-put 'fixed-euc-zy-cn
601                    'pre-write-conversion 'pre-write-encode-euc-cn)
602 (coding-system-put 'fixed-euc-zy-cn
603                    'post-read-conversion 'post-read-decode-euc-zy-cn)
604
605 (make-coding-system 'fixed-euc-py-tw 0 ?W
606                     "Coding System for fixed EUC Chinese-cns11643")
607 (coding-system-put 'fixed-euc-py-tw
608                    'pre-write-conversion 'pre-write-encode-euc-tw)
609 (coding-system-put 'fixed-euc-py-tw
610                    'post-read-conversion 'post-read-decode-euc-py-tw)
611
612 (make-coding-system 'fixed-euc-zy-tw 0 ?W
613                     "Coding System for fixed EUC Chinese-cns11643")
614 (coding-system-put 'fixed-euc-zy-tw
615                    'pre-write-conversion 'pre-write-encode-euc-tw)
616 (coding-system-put 'fixed-euc-zy-tw
617                    'post-read-conversion 'post-read-decode-euc-zy-tw)
618
619 ;; Binary data
620
621 (eval-and-compile
622 (define-ccl-program ccl-decode-egg-binary
623   `(2
624     ((read r0)
625      (loop
626       (if (r0 == ?\xff)
627           (read r1))                    ; toss out
628       (write-read-repeat r0)))))
629
630 (define-ccl-program ccl-encode-egg-binary
631   `(1
632     ((read r0)
633      (loop
634       (if (r0 == ?\xff)
635           ((write r0)
636            (r0 = 0)))
637       (write-read-repeat r0))))))
638
639 (make-coding-system 'egg-binary 4 ?W "Coding System for binary data"
640                     (cons ccl-decode-egg-binary ccl-encode-egg-binary))
641
642 \f
643 (defun comm-format-u32c (uint32c)
644   (insert-char (logand (lsh (car uint32c) -8) 255) 1)
645   (insert-char (logand (car uint32c) 255) 1)
646   (insert-char (logand (lsh (nth 1 uint32c) -8) 255) 1)
647   (insert-char (logand (nth 1 uint32c) 255) 1))
648
649 (defun comm-format-u32 (uint32)
650   (insert-char (logand (lsh uint32 -24) 255) 1)
651   (insert-char (logand (lsh uint32 -16) 255) 1)
652   (insert-char (logand (lsh uint32 -8) 255) 1)
653   (insert-char (logand uint32 255) 1))
654
655 (defun comm-format-i32 (int32)
656   (insert-char (logand (ash int32 -24) 255) 1)
657   (insert-char (logand (ash int32 -16) 255) 1)
658   (insert-char (logand (ash int32 -8) 255) 1)
659   (insert-char (logand int32 255) 1))
660
661 (defun comm-format-u16 (uint16)
662   (insert-char (logand (lsh uint16 -8) 255) 1)
663   (insert-char (logand uint16 255) 1))
664
665 (defun comm-format-u8 (uint8)
666   (insert-char (logand uint8 255) 1))
667
668 (defun comm-format-truncate-after-null (s)
669   (if (string-match "\0" s)
670       (substring s 0 (match-beginning 0))
671     s))
672
673 (defun comm-format-u16-string (s)
674   (insert (encode-coding-string (comm-format-truncate-after-null s)
675                                 egg-fixed-euc))
676   (insert-char 0 2))
677
678 (defun comm-format-mb-string (s)
679   (insert (encode-coding-string  (comm-format-truncate-after-null s)
680                                  egg-mb-euc))
681   (insert-char 0 1))
682
683 (defun comm-format-u8-string (s)
684   (insert (comm-format-truncate-after-null s))
685   (insert-char 0 1))
686
687 (defun comm-format-binary-data (s)
688   (insert (encode-coding-string s 'egg-binary))
689   (insert-char ?\377 2))
690
691 (defun comm-format-fixlen-string (s len)
692   (setq s (comm-format-truncate-after-null s))
693   (insert (if (< (length s) len) s (substring s 0 (1- len))))
694   (insert-char 0 (max (- len (length s)) 1)))
695
696 (defun comm-format-vector (s len)
697   (setq s (concat s))
698   (insert (if (<= (length s) len) s (substring s 0 len)))
699   (insert-char 0 (- len (length s))))
700
701 (defmacro comm-format (format &rest args)
702   "Format a string out of a control-list and arguments into the buffer.
703 The formated datas are network byte oder (i.e. big endian)..
704 U: 32-bit integer.  The argument is 2 element 16-bit unsigned integer list.
705 u: 32-bit integer.  The argument is treat as unsigned integer.
706    (Note:  Elisp's integer may be less than 32 bits)
707 i: 32-bit integer.
708 w: 16-bit integer.
709 b: 8-bit integer.
710 S: 16-bit wide-character EUC string (0x0000 terminated).
711 E: Multibyte EUC string (0x00 terminated).
712 s: 8-bit string (0x00 terminated).
713 B: Binary data (0xff terminated).
714 v: 8-bit vector (no terminator).  This takes 2 args (data length).
715 V: Fixed length string (0x00 terminated).  This takes 2 args (data length)."
716   (let ((p args)
717         (form format)
718         (result (list 'progn))
719         f arg)
720     (while (and form p)
721       (setq f (car form)
722             arg (car p))
723       (nconc result
724              (list
725               (cond ((eq f 'U) (list 'comm-format-u32c arg))
726                     ((eq f 'u) (list 'comm-format-u32 arg))
727                     ((eq f 'i) (list 'comm-format-i32 arg))
728                     ((eq f 'w) (list 'comm-format-u16 arg))
729                     ((eq f 'b) (list 'comm-format-u8 arg))
730                     ((eq f 'S) (list 'comm-format-u16-string arg))
731                     ((eq f 'E) (list 'comm-format-mb-string arg))
732                     ((eq f 's) (list 'comm-format-u8-string arg))
733                     ((eq f 'B) (list 'comm-format-binary-data arg))
734                     ((eq f 'V) (setq p (cdr p))
735                                (list 'comm-format-fixlen-string arg (car p)))
736                     ((eq f 'v) (setq p (cdr p))
737                                (list 'comm-format-vector arg (car p))))))
738       (setq form (cdr form)
739             p (cdr p)))
740     (if (or form p)
741         (error "comm-format %s: arguments mismatch" format))
742     result))
743 \f
744 (defvar comm-accept-timeout nil)
745
746 ;; Assume PROC is bound to the process of current buffer
747 ;; Do not move the point, leave it where it was.
748 (defmacro comm-accept-process-output ()
749   `(let ((p (point)))
750      (if (null (accept-process-output proc comm-accept-timeout))
751          (egg-error "backend timeout"))
752      (goto-char p)))
753
754 (defmacro comm-require-process-output (n)
755   `(if (< (point-max) (+ (point) ,n))
756        (comm-wait-for-space proc ,n)))
757
758 (defun comm-wait-for-space (proc n)
759   (let ((p (point))
760         (r (+ (point) n)))
761     (while (< (point-max) r)
762       (if (null (accept-process-output proc comm-accept-timeout))
763           (egg-error "backend timeout"))
764       (goto-char p))))
765
766 (defmacro comm-following+forward-char ()
767   `(prog1
768        (following-char)
769      (forward-char 1)))
770
771 (defun comm-unpack-u32c ()
772   (progn
773     (comm-require-process-output 4)
774     (list (+ (lsh (comm-following+forward-char) 8)
775              (comm-following+forward-char))
776           (+ (lsh (comm-following+forward-char) 8)
777              (comm-following+forward-char)))))
778
779 (defun comm-unpack-u32 ()
780   (progn
781     (comm-require-process-output 4)
782     (+ (lsh (comm-following+forward-char) 24)
783        (lsh (comm-following+forward-char) 16)
784        (lsh (comm-following+forward-char) 8)
785        (comm-following+forward-char))))
786
787 (defun comm-unpack-u16 ()
788   (progn
789     (comm-require-process-output 2)
790     (+ (lsh (comm-following+forward-char) 8)
791        (comm-following+forward-char))))
792
793 (defun comm-unpack-u8 ()
794   (progn
795     (comm-require-process-output 1)
796     (comm-following+forward-char)))
797
798 (defun comm-unpack-u16-string ()
799   (let ((start (point)))
800     (while (not (search-forward "\0\0" nil t))
801       (comm-accept-process-output))
802     (decode-coding-string (buffer-substring start (- (point) 2))
803                           egg-fixed-euc)))
804
805 (defun comm-unpack-mb-string ()
806   (let ((start (point)))
807     (while (not (search-forward "\0" nil t))
808       (comm-accept-process-output))
809     (decode-coding-string (buffer-substring start (1- (point)))
810                           egg-mb-euc)))
811
812 (defun comm-unpack-u8-string ()
813   (let ((start (point)))
814     (while (not (search-forward "\0" nil 1))
815       (comm-accept-process-output))
816     (buffer-substring start (1- (point)))))
817
818 (defun comm-unpack-binary-data ()
819   (let ((start (point)))
820     (while (not (search-forward "\377\377" nil 1))
821       (comm-accept-process-output))
822     (string-as-unibyte
823      (decode-coding-string (buffer-substring start (- (point) 2))
824                            'egg-binary))))
825
826 (defun comm-unpack-fixlen-string (len)
827   (let (s)
828     (comm-require-process-output len)
829     (goto-char (+ (point) len))
830     (setq s (buffer-substring (- (point) len) (point)))
831     (if (string-match "\0" s)
832         (setq s (substring s 0 (match-beginning 0))))
833     s))
834
835 (defun comm-unpack-vector (len)
836   (progn
837     (comm-require-process-output len)
838     (goto-char (+ (point) len))
839     (buffer-substring (- (point) len) (point))))
840
841 (defmacro comm-unpack (format &rest args)
842   "Unpack a string out of a control-string and set arguments.
843 See `comm-format' for FORMAT."
844   (let ((p args)
845         (form format)
846         (result (list 'progn))
847         arg f)
848     (while (and form p)
849       (setq f (car form)
850             arg (car p))
851       (nconc result
852              (list
853               (cond ((eq f 'U) `(setq ,arg (comm-unpack-u32c)))
854                     ((eq f 'u) `(setq ,arg (comm-unpack-u32)))
855                     ((eq f 'i) `(setq ,arg (comm-unpack-u32)))
856                     ((eq f 'w) `(setq ,arg (comm-unpack-u16)))
857                     ((eq f 'b) `(setq ,arg (comm-unpack-u8)))
858                     ((eq f 'S) `(setq ,arg (comm-unpack-u16-string)))
859                     ((eq f 'E) `(setq ,arg (comm-unpack-mb-string)))
860                     ((eq f 's) `(setq ,arg (comm-unpack-u8-string)))
861                     ((eq f 'B) `(setq ,arg (comm-unpack-binary-data)))
862                     ((eq f 'V) (setq p (cdr p))
863                                `(setq ,arg (comm-unpack-fixlen-string ,(car p))))
864                     ((eq f 'v) (setq p (cdr p))
865                                `(setq ,arg (comm-unpack-vector ,(car p)))))))
866       (setq form (cdr form)
867             p (cdr p)))
868     (if (or form p)
869         (error "comm-unpack %s: arguments mismatch" format))
870     result))
871 \f
872 (defmacro comm-call-with-proc (proc vlist send-expr &rest receive-exprs)
873   (let ((euc-select
874          (and (eq (car-safe (car vlist)) 'zhuyin)
875               '((egg-fixed-euc (nth (if zhuyin 1 0) egg-fixed-euc))))))
876   `(let* ((proc ,proc)
877           (buffer (process-buffer proc))
878           ,@vlist)
879      (if (and (eq (process-status proc) 'open)
880               (buffer-live-p buffer))
881          (save-excursion
882            (set-buffer buffer)
883            (let ,euc-select
884              (erase-buffer)
885              ,send-expr
886              (goto-char (point-max))
887              (process-send-region proc (point-min) (point-max))
888              ,@receive-exprs))
889        (egg-error "process %s was killed" proc)))))
890
891 (defmacro comm-call-with-proc-1 (proc vlist send-expr &rest receive-exprs)
892   `(let ,vlist
893      (erase-buffer)
894      ,send-expr
895      (goto-char (point-max))
896      (process-send-region proc (point-min) (point-max))
897      ,@receive-exprs))
898
899 (provide 'egg-com)
900 ;;; egg-com.el ends here.