* egg/wnn.el (wnn-accept-charset-alist): XEmacs uses sisheng
[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-multibyte-character r4 r0)
61            (read r0)
62            (repeat))
63         ((if (r1 > ?\x80)
64              ((r0 &= ?\x7f)
65               (r0 <<= 7)
66               (r0 |= (r1 & ?\x7f))
67               (write-multibyte-character r2 r0)
68               (read r0)
69               (repeat))
70            ((r0 &= ?\x7f)
71             (r0 <<= 7)
72             (r0 |= r1)
73             (write-multibyte-character r3 r0)
74             (read r0)
75             (repeat)))))))))
76
77 (define-ccl-program ccl-encode-fixed-euc-jp
78   `(2
79     ((read r0)
80      (loop
81       (if (r0 == ,(charset-id 'latin-jisx0201))                   ; Unify
82           ((read r0)
83            (r0 &= ?\x7f)))
84       (if (r0 < ?\x80)                                            ;G0
85           ((write 0)
86            (write-read-repeat r0)))
87       (r6 = (r0 == ,(charset-id 'japanese-jisx0208)))
88       (r6 |= (r0 == ,(charset-id 'japanese-jisx0208-1978)))
89       (if r6                                                      ;G1
90           ((read r0)
91            (write r0)
92            (read r0)
93            (write-read-repeat r0)))
94       (if (r0 == ,(charset-id 'katakana-jisx0201))                ;G2
95           ((read r0)
96            (write 0)
97            (write-read-repeat r0)))
98       (if (r0 == ,(charset-id 'japanese-jisx0212))                ;G3
99           ((read r0)
100            (write r0)
101            (read r0)
102            (r0 &= ?\x7f)
103            (write-read-repeat r0)))
104       (read r0)
105       (repeat)))))
106 )
107
108 (if (featurep 'xemacs)
109     (make-coding-system 'fixed-euc-jp 'ccl "Coding System for fixed EUC Japanese"
110                         '(mnemonic "W"
111                           decode ccl-decode-fixed-euc-jp
112                           encode ccl-encode-fixed-euc-jp))
113   (make-coding-system 'fixed-euc-jp 4 ?W "Coding System for fixed EUC Japanese"
114                       (cons ccl-decode-fixed-euc-jp ccl-encode-fixed-euc-jp)))
115
116 ;; Korean
117
118 (eval-and-compile
119 (define-ccl-program ccl-decode-fixed-euc-kr
120   `(2
121     ((r2 = ,(charset-id 'korean-ksc5601))
122      (read r0)
123      (loop
124       (read r1)
125       (if (r0 < ?\x80)
126           ((r0 = r1 & ?\x7f)
127            (write-read-repeat r0))
128         ((r0 &= ?\x7f)
129          (r0 <<= 7)
130          (r0 |= (r1 & ?\x7f))
131          (write-multibyte-character r2 r0)
132          (read r0)
133          (repeat)))))))
134
135 (define-ccl-program ccl-encode-fixed-euc-kr
136   `(2
137     ((read r0)
138      (loop
139       (if (r0 < ?\x80)
140           ((write 0)
141            (write-read-repeat r0)))
142       (if (r0 == ,(charset-id 'korean-ksc5601))
143           ((read r0)
144            (write r0)
145            (read r0)
146            (write-read-repeat r0)))
147       (read r0)
148       (repeat)))))
149 )
150
151 (if (featurep 'xemacs)
152     (make-coding-system 'fixed-euc-kr 'ccl "Coding System for fixed EUC Korean"
153                         '(mnemonic "W" decode ccl-decode-fixed-euc-kr
154                                    encode ccl-encode-fixed-euc-kr))
155   (make-coding-system 'fixed-euc-kr 4 ?W "Coding System for fixed EUC Korean"
156                       (cons ccl-decode-fixed-euc-kr ccl-encode-fixed-euc-kr)))
157
158
159 ;; Chinese
160 (defconst egg-pinyin-shengmu
161   '((""  . 0)  ("B" . 1)  ("C"  . 2)  ("Ch" . 3)  ("D" . 4)
162     ("F" . 5)  ("G" . 6)  ("H"  . 7)  ("J"  . 8)  ("K" . 9)
163     ("L" . 10) ("M" . 11) ("N"  . 12) ("P"  . 13) ("Q" . 14)
164     ("R" . 15) ("S" . 16) ("Sh" . 17) ("T"  . 18) ("W" . 19)
165     ("X" . 20) ("Y" . 21) ("Z"  . 22) ("Zh" . 23)))
166
167 (defconst egg-pinyin-yunmu
168   '(("\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)
169     ("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)
170     ("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)
171     ("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)
172     ("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)
173     ("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)
174     ("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)
175     ("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)
176     ("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)
177     ("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)
178     ("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)
179     ("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)
180     ("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)
181     ("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)
182     ("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)
183     ("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)
184     ("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)
185     ("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)
186     ("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)
187     ("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)
188     ("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)
189     ("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)
190     ("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)
191     ("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)
192     ("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)
193     ("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)
194     ("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)
195     ("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)
196     ("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)
197     ("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)
198     ("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)
199     ("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)
200     ("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)
201     ("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)
202     ("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)
203     ("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)
204     ("\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)
205     ("\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)
206     ("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)))
207
208 (defconst egg-pinyin-table
209   [
210    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
211    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
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 0 0 1 0 0 1 1 1 0 0 1
213    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
214    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
215    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
216    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
217    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
218    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
219    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
220    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
221    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
222    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
223    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
224    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
225    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
226    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
227    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
228    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
229    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
230    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
231    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
232    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
233    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
234    ])
235
236 (defconst egg-zhuyin-shengmu
237   '((""  .  0) ("\e(0E\e(B" .  1) ("\e(0X\e(B" .  2) ("\e(0T\e(B" .  3) ("\e(0I\e(B" .  4)
238     ("\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)
239     ("\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)
240     ("\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)
241     ("\e(0R\e(B" . 20) ("\e(0g\e(B" . 21) ("\e(0W\e(B" . 22) ("\e(0S\e(B" . 23)))
242
243 (defconst egg-zhuyin-yunmu
244   '(("\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
245     ("\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
246     ("\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
247     ("\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
248     ("\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
249     ("\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
250     ("\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
251     ("\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
252     ("\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
253     ("\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
254     ("\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
255     ("\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
256     ("\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
257     ("\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
258     ("\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
259     ("\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
260     ("\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
261     ("\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
262     ("\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
263     ("\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
264     ("\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
265     ("\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
266     ("\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
267     ("@\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
268     ("\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
269     ("\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
270     ("\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
271     ("\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
272     ("\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
273     ("\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
274     ("\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
275     ("\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
276     ("\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
277     ("\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
278     ("\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
279     ("\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
280     ("\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
281     ("\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
282     ("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
283     ("\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
284     ("\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
285     ))
286
287 (defconst egg-zhuyin-table
288   [
289    ;; empty ShengMu
290    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
291    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x9586 ?\x0000 ?\x9592 ?\x9599
292    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x0000
293    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x959b ?\x95a0 ?\x0000 ?\x959e
294    ?\x95a2
295    ;; ShengMu B
296    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
297    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
298    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000
299    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
300    ?\x0000
301    ;; ShengMu C
302    ?\x828b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
303    ?\x0000 ?\x0280 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
304    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
305    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
306    ?\x0000
307    ;; ShengMu Ch
308    ?\x838b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
309    ?\x0000 ?\x0380 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
310    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
311    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
312    ?\x0000
313    ;; ShengMu D
314    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
315    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
316    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
317    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
318    ?\x0000
319    ;; ShengMu F
320    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
321    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
322    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
323    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
324    ?\x0000
325    ;; ShengMu G
326    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
327    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
328    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
329    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
330    ?\x0000
331    ;; ShengMu H
332    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
333    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
334    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
335    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
336    ?\x0000
337    ;; ShengMu J
338    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
339    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
340    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x08a4 ?\x0000 ?\x0000
341    ?\x08a7 ?\x0000 ?\x08a5 ?\x0000 ?\x08a8 ?\x0000 ?\x889b ?\x88a0 ?\x8000 ?\x889e
342    ?\x88a2
343    ;; ShengMu K
344    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
345    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
346    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
347    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
348    ?\x0000
349    ;; ShengMu L
350    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
351    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
352    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
353    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
354    ?\x0000
355    ;; ShengMu M
356    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
357    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
358    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
359    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
360    ?\x0000
361    ;; ShengMu N
362    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
363    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
364    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
365    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
366    ?\x0000
367    ;; ShengMu P
368    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
369    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
370    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
371    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
372    ?\x0000 
373    ;; ShengMu Q
374    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
375    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
376    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0ea4 ?\x0000 ?\x0000
377    ?\x0ea7 ?\x0000 ?\x0ea5 ?\x0000 ?\x0ea8 ?\x0000 ?\x8e9b ?\x8ea0 ?\x8000 ?\x8e9e
378    ?\x8ea2
379    ;; ShengMu R
380    ?\x8f8b ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
381    ?\x0000 ?\x0f80 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
382    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
383    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
384    ?\x0000
385    ;; ShengMu S
386    ?\x908b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
387    ?\x0000 ?\x1080 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
388    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
389    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
390    ?\x0000
391    ;; ShengMu Sh
392    ?\x918b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
393    ?\x0000 ?\x1180 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
394    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
395    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
396    ?\x0000
397    ;; ShengMu T
398    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
399    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
400    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
401    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
402    ?\x0000
403    ;; ShengMu W
404    ?\x939b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
405    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
406    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x1380 ?\x0000 ?\x0000
407    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
408    ?\x0000
409    ;; ShengMu X
410    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
411    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
412    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x14a4 ?\x0000 ?\x0000
413    ?\x14a7 ?\x0000 ?\x14a5 ?\x0000 ?\x14a8 ?\x0000 ?\x949b ?\x94a0 ?\x8000 ?\x949e
414    ?\x94a2
415    ;; ShengMu Y 
416    ?\x958b ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0090 ?\x0000 ?\x9591 ?\x9592
417    ?\x0000 ?\x1580 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x1588 ?\x1589 ?\x0000
418    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0093 ?\x8000 ?\x00a4 ?\x0000 ?\x0000
419    ?\x00a7 ?\x0000 ?\x00a5 ?\x0000 ?\x00a8 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
420    ?\x0000
421    ;; ShengMu Z
422    ?\x968b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
423    ?\x0000 ?\x1680 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
424    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
425    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
426    ?\x0000
427    ;; ShengMu Zh 
428    ?\x978b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
429    ?\x0000 ?\x1780 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
430    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
431    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
432    ?\x0000
433    ])
434
435 (defconst egg-chinese-syllable-max-len
436   (max (length "Zhu\e(0!\e(Bng\e(0@\e(B") (length "\e(0ShdA\e(B")))
437
438 (defun egg-chinese-syllable (str pos)
439   (setq str (substring str pos (min (length str)
440                                     (+ pos egg-chinese-syllable-max-len))))
441   (or (car (egg-pinyin-syllable str))
442       (car (egg-zhuyin-syllable str))))
443
444 (defsubst egg-make-fixed-euc-china-code (s y)
445   (cons
446    (+ (* 2 (nth 1 y)) (logand (nth 2 y) 1) 32)
447    (+ (* 4 (if (= s 0) 20 s)) (lsh (nth 2 y) -1) 156)))
448
449 (defun egg-pinyin-syllable (str)
450   (if (eq (string-match "^[A-Za-z\e(0!\e(B-\e(0?\e(B]+\e(0@\e(B" str) 0)
451       (let (s y end)
452         (setq end (match-end 0))
453         (cond
454          ((setq s (cdr (assoc (substring str 0 2) egg-pinyin-shengmu)))
455           (setq y (substring str 2 end)))
456          ((setq s (cdr (assoc (substring str 0 1) egg-pinyin-shengmu)))
457           (setq y (substring str 1 end)))
458          (t
459           (setq s 0 y (substring str 0 end))))
460         (if (and (setq y (assoc y egg-pinyin-yunmu))
461                  (= (aref egg-pinyin-table (+ (* 39 s) (nth 1 y))) 1))
462             (cons end (egg-make-fixed-euc-china-code s y))))))
463
464 (defun egg-zhuyin-syllable (str)
465   (if (eq (string-match "^[\e(0E\e(B-\e(0i\e(B@0-4]+[\e(0@ABCD\e(B]" str) 0)
466       (let (end s y c z (zhuyin-len (length "\e(0E\e(B")))
467         (setq end (match-end 0)
468               c (substring str 0 zhuyin-len)
469               s (cdr (assoc c egg-zhuyin-shengmu))
470               y (assoc (substring str zhuyin-len end) egg-zhuyin-yunmu))
471         (if (or (null (and s y))
472                 (and (or (eq s 11) (eq s 12)) (eq (nth 1 y) 0))) ; [\e(0GK\e(B][\e(0@ABCD\e(B]
473             (setq s 0
474                   y (assoc (substring str 0 end) egg-zhuyin-yunmu)))
475         (if (and y
476                  (setq z (aref egg-zhuyin-table (+ (* 41 s) (nth 1 y))))
477                  (/= (logand z ?\x8000) 0))
478             (if (/= (logand z ?\x80) 0)
479                 (cons end (egg-make-fixed-euc-china-code
480                            (logand (lsh z -8) ?\x7f)
481                            (list nil (logand z ?\x7f) (nth 2 y))))
482               (cons end (egg-make-fixed-euc-china-code s y)))))))
483
484 (defun encode-fixed-euc-china-region (beg end type)
485   "Encode the text in the region to EUC-CN/TW."
486   (let (s syl c cset)
487     (save-excursion
488       (save-restriction
489         (narrow-to-region beg end)
490         (goto-char (point-min))
491         (while (< (point) (point-max))
492           (setq s (buffer-substring
493                    (point)
494                    (min (point-max) (+ (point) egg-chinese-syllable-max-len))))
495           (cond
496            ((setq syl (egg-pinyin-syllable s))
497             (delete-region (point) (+ (point) (car syl)))
498             (insert (car (cdr syl)) (cdr (cdr syl))))
499            ((setq syl (egg-zhuyin-syllable s))
500             (delete-region (point) (+ (point) (car syl)))
501             (insert (car (cdr syl)) (cdr (cdr syl))))
502            (t
503             (setq c (split-char (following-char))
504                   cset (car c))
505             (cond
506              ((or (and (eq cset 'chinese-gb2312) (eq type 'cn))
507                   (and (eq cset 'chinese-cns11643-1) (eq type 'tw)))
508               (delete-char 1)
509               (insert (+ (nth 1 c) 128) (+ (nth 2 c) 128)))
510              ((and (eq cset 'chinese-cns11643-2) (eq type 'tw))
511               (delete-char 1)
512               (insert (+ (nth 1 c) 128) (nth 2 c)))
513              ((eq cset 'chinese-sisheng)
514               (delete-char 1)
515               (insert 0 (+ (nth 1 c) 128)))
516              ((eq cset 'sisheng)
517               (delete-char 1)
518               (insert 0 (+ (nth 1 c) 128)))
519              ((eq cset 'ascii)
520               (delete-char 1)
521               (insert 0 (nth 1 c)))
522              (t
523               (delete-char 1))))))
524         (- (point-max) (point-min))))))
525
526 (defun pre-write-encode-fixed-euc-china (from to type)
527   (let ((buf (current-buffer))
528         (work (get-buffer-create " *pre-write-encoding-work*")))
529     (set-buffer work)
530     (erase-buffer)
531     (if (null (stringp from))
532         (save-excursion
533           (set-buffer buf)
534           (setq from (buffer-substring from to))))
535     (insert (string-as-multibyte from))
536     (encode-fixed-euc-china-region 1 (point-max) type)
537     nil))
538
539 (defun pre-write-encode-euc-cn (from to)
540   (pre-write-encode-fixed-euc-china from to 'cn))
541
542 (defun pre-write-encode-euc-tw (from to)
543   (pre-write-encode-fixed-euc-china from to 'tw))
544
545 (defun decode-fixed-euc-china-region (beg end type zhuyin)
546   "Decode EUC-CN/TW encoded text in the region.
547 Return the length of resulting text."
548   (prog1
549       (let ((str (string-as-unibyte (buffer-substring beg end)))
550             (i 0)
551             l c0 c1 s y ss)
552         (delete-region beg end)
553         (setq l (1- (length str)))
554         (while (< i l)
555           (setq c0 (if (featurep 'xemacs)
556                        (char-to-int (aref str i))
557                      (aref str i))
558                 c1 (if (featurep 'xemacs)
559                        (char-to-int (aref str (1+ i)))
560                      (aref str (1+ i)))
561                 i  (+ i 2))
562           (cond
563            ((eq c0 0)
564             (if (> c1 ?\xa0)
565                 (insert (make-char (if (featurep 'xemacs)
566                                        'sisheng
567                                      'chinese-sisheng)
568                                    c1))
569               (insert c1)))
570            ((>= c0 ?\x80)
571             (cond
572              ((eq type 'cn)
573               (insert (make-char 'chinese-gb2312 c0 c1)))
574              ((>= c1 ?\x80)
575               (insert (make-char 'chinese-cns11643-1 c0 c1)))
576              (t
577               (insert (make-char 'chinese-cns11643-2 c0 c1)))))
578            (t
579             (setq c1 (logand c1 ?\x7f))
580             (setq s (- (lsh c1 -2) 7);;(+ (lsh (- c1 32) -2) 1)
581                   y (- (lsh c0 -1) 16);;(lsh (- c0 32) -1)
582                   ss (+ (logand c0 1) (logand c1 3)))
583             (if (and (eq s 20)
584                      (eq (aref egg-pinyin-table (+ (* 39 20) y)) 0))
585                 (setq s 0))
586             (if (null zhuyin)
587                 (setq s (car (nth s egg-pinyin-shengmu))
588                       y (car (nth (+ (* 5 y) ss) egg-pinyin-yunmu)))
589               (setq c0 (aref egg-zhuyin-table (+ (* 41 s) y)))
590               (if (eq (logand c0 ?\x8080) ?\x80)
591                   (setq s (lsh c0 -8)
592                         y (logand c0 ?\x7f)))
593               (setq s (car (nth s egg-zhuyin-shengmu))
594                     y (car (nth (+ (* 5 y) ss) egg-zhuyin-yunmu))))
595             (if enable-multibyte-characters
596                 (insert s y)
597               (insert (string-as-unibyte s) (string-as-unibyte y))))))
598         (- (point) beg))
599     (if (looking-at "\0\0") (forward-char 2))))
600
601 (defun post-read-decode-fixed-euc-china (len type zhuyin)
602   (let ((pos (point))
603         (buffer-modified-p (buffer-modified-p)))
604     (prog1
605         (decode-fixed-euc-china-region pos (+ pos len) type zhuyin)
606       (set-buffer-modified-p buffer-modified-p))))
607
608 (defun post-read-decode-euc-py-cn (len)
609   (post-read-decode-fixed-euc-china len 'cn nil))
610
611 (defun post-read-decode-euc-zy-cn (len)
612   (post-read-decode-fixed-euc-china len 'cn t))
613
614 (defun post-read-decode-euc-py-tw (len)
615   (post-read-decode-fixed-euc-china len 'tw nil))
616
617 (defun post-read-decode-euc-zy-tw (len)
618   (post-read-decode-fixed-euc-china len 'tw t))
619
620 ;; XEmacs incompatibility note.
621
622 ;; XEmacs uses pre-write-conversion and post-read-conversion when
623 ;; characters are read from or written to files.  post-read-conversion
624 ;; functions are called with arguments start and end.  It is not
625 ;; compatible with Emacs' counterpart which is called with length.
626 ;; This coding-system does not work on XEmacs because
627 ;; post-read-conversion is written in Emacs style.
628
629 ;; The actual usage of this coding-system is to convert string to the
630 ;; format cserver expects.  The problem is that post-read-conversion
631 ;; and pre-write-conversion is ignored when decode-coding-string and
632 ;; encode-coding-string are called, not post-read-conversion is
633 ;; incompatible.  So I decided to leave post-read-conversion as is and
634 ;; call it from comm-format-u16-string and comm-unpack-u16-string to
635 ;; work around the problem.
636 (if (featurep 'xemacs)
637     (make-coding-system 'fixed-euc-py-cn 'no-conversion
638                         "Coding System for fixed EUC Chinese-gb2312"
639                         '(mnemonic "W" pre-write-conversion pre-write-encode-euc-cn
640                                    post-read-conversion post-read-decode-euc-py-cn))
641   (make-coding-system 'fixed-euc-py-cn 0 ?W
642                       "Coding System for fixed EUC Chinese-gb2312")
643   (coding-system-put 'fixed-euc-py-cn
644                      'pre-write-conversion 'pre-write-encode-euc-cn)
645   (coding-system-put 'fixed-euc-py-cn
646                      'post-read-conversion 'post-read-decode-euc-py-cn))
647
648 (if (featurep 'xemacs)
649     (make-coding-system 'fixed-euc-zy-cn 'no-conversion
650                         "Coding System for fixed EUC Chinese-gb2312"
651                         '(mnemonic "W" pre-write-conversion pre-write-encode-euc-cn
652                                    post-read-conversion post-read-decode-euc-zy-cn))
653   (make-coding-system 'fixed-euc-zy-cn 0 ?W
654                       "Coding System for fixed EUC Chinese-gb2312")
655   (coding-system-put 'fixed-euc-zy-cn
656                      'pre-write-conversion 'pre-write-encode-euc-cn)
657   (coding-system-put 'fixed-euc-zy-cn
658                      'post-read-conversion 'post-read-decode-euc-zy-cn))
659
660 (if (featurep 'xemacs)
661     (make-coding-system 'fixed-euc-py-tw 'no-conversion
662                         "Coding System for fixed EUC Chinese-gb2312"
663                         '(mnemonic "W" pre-write-conversion pre-write-encode-euc-tw
664                                    post-read-conversion post-read-decode-euc-py-tw))
665   (make-coding-system 'fixed-euc-py-tw 0 ?W
666                       "Coding System for fixed EUC Chinese-cns11643")
667   (coding-system-put 'fixed-euc-py-tw
668                      'pre-write-conversion 'pre-write-encode-euc-tw)
669   (coding-system-put 'fixed-euc-py-tw
670                      'post-read-conversion 'post-read-decode-euc-py-tw))
671
672 (if (featurep 'xemacs)
673     (make-coding-system 'fixed-euc-zy-tw 'no-conversion
674                         "Coding System for fixed EUC Chinese-gb2312"
675                         '(mnemonic "W" pre-write-conversion pre-write-encode-euc-tw
676                                    post-read-conversion post-read-decode-euc-zy-tw))
677   (make-coding-system 'fixed-euc-zy-tw 0 ?W
678                       "Coding System for fixed EUC Chinese-cns11643")
679   (coding-system-put 'fixed-euc-zy-tw
680                      'pre-write-conversion 'pre-write-encode-euc-tw)
681   (coding-system-put 'fixed-euc-zy-tw
682                      'post-read-conversion 'post-read-decode-euc-zy-tw)
683   )
684 ;; Binary data
685
686 (eval-and-compile
687 (define-ccl-program ccl-decode-egg-binary
688   `(1
689     ((read r0)
690      (loop
691       (if (r0 == ?\xff)
692           (read r1))                    ; toss out
693       (write-read-repeat r0)))))
694
695 (define-ccl-program ccl-encode-egg-binary
696   `(2
697     ((read r0)
698      (loop
699       (if (r0 == ?\xff)
700           ((write r0)
701            (r0 = 0)))
702       (write-read-repeat r0))))))
703
704 (if (featurep 'xemacs)
705     (define-coding-system-alias 'egg-binary 'binary)
706   (make-coding-system 'egg-binary 4 ?W "Coding System for binary data"
707                       (cons ccl-decode-egg-binary ccl-encode-egg-binary)))
708
709 \f
710 (defun comm-format-u32c (uint32c)
711   (insert-char (logand (lsh (car uint32c) -8) 255) 1)
712   (insert-char (logand (car uint32c) 255) 1)
713   (insert-char (logand (lsh (nth 1 uint32c) -8) 255) 1)
714   (insert-char (logand (nth 1 uint32c) 255) 1))
715
716 (defun comm-format-u32 (uint32)
717   (insert-char (logand (lsh uint32 -24) 255) 1)
718   (insert-char (logand (lsh uint32 -16) 255) 1)
719   (insert-char (logand (lsh uint32 -8) 255) 1)
720   (insert-char (logand uint32 255) 1))
721
722 (defun comm-format-i32 (int32)
723   (insert-char (logand (ash int32 -24) 255) 1)
724   (insert-char (logand (ash int32 -16) 255) 1)
725   (insert-char (logand (ash int32 -8) 255) 1)
726   (insert-char (logand int32 255) 1))
727
728 (defun comm-format-u16 (uint16)
729   (insert-char (logand (lsh uint16 -8) 255) 1)
730   (insert-char (logand uint16 255) 1))
731
732 (defun comm-format-u8 (uint8)
733   (insert-char (logand uint8 255) 1))
734
735 (defun comm-format-truncate-after-null (s)
736   (if (string-match "\0" s)
737       (substring s 0 (match-beginning 0))
738     s))
739
740 (defun comm-format-u16-string (s)
741   (if (and (featurep 'xemacs)
742            (coding-system-get egg-fixed-euc 'pre-write-conversion))
743       (let ((fixed-euc egg-fixed-euc))
744         (insert (with-temp-buffer
745                   (insert (comm-format-truncate-after-null s))
746                   (goto-char (point-min))
747                   (funcall (coding-system-get fixed-euc 'pre-write-conversion)
748                            (point-min) (point-max))
749                   (buffer-string))))
750     (insert (encode-coding-string (comm-format-truncate-after-null s)
751                                   egg-fixed-euc)))
752   (insert-char 0 2))
753
754 (defun comm-format-mb-string (s)
755   (insert (encode-coding-string  (comm-format-truncate-after-null s)
756                                  egg-mb-euc))
757   (insert-char 0 1))
758
759 (defun comm-format-u8-string (s)
760   (insert (comm-format-truncate-after-null s))
761   (insert-char 0 1))
762
763 (defun comm-format-binary-data (s)
764   (insert (encode-coding-string s 'egg-binary))
765   (insert-char ?\377 2))
766
767 (defun comm-format-fixlen-string (s len)
768   (setq s (comm-format-truncate-after-null s))
769   (insert (if (< (length s) len) s (substring s 0 (1- len))))
770   (insert-char 0 (max (- len (length s)) 1)))
771
772 (defun comm-format-vector (s len)
773   (setq s (concat s))
774   (insert (if (<= (length s) len) s (substring s 0 len)))
775   (insert-char 0 (- len (length s))))
776
777 (defmacro comm-format (format &rest args)
778   "Format a string out of a control-list and arguments into the buffer.
779 The formated datas are network byte oder (i.e. big endian)..
780 U: 32-bit integer.  The argument is 2 element 16-bit unsigned integer list.
781 u: 32-bit integer.  The argument is treat as unsigned integer.
782    (Note:  Elisp's integer may be less than 32 bits)
783 i: 32-bit integer.
784    (Note:  Elisp's integer may be greater than 32 bits)
785 w: 16-bit integer.
786 b: 8-bit integer.
787 S: 16-bit wide-character EUC string (0x0000 terminated).
788 E: Multibyte EUC string (0x00 terminated).
789 s: 8-bit string (0x00 terminated).
790 B: Binary data (0xff terminated).
791 v: 8-bit vector (no terminator).  This takes 2 args (data length).
792 V: Fixed length string (0x00 terminated).  This takes 2 args (data length)."
793   (let ((p args)
794         (form format)
795         (result (list 'progn))
796         f arg)
797     (while (and form p)
798       (setq f (car form)
799             arg (car p))
800       (nconc result
801              (list
802               (cond ((eq f 'U) (list 'comm-format-u32c arg))
803                     ((eq f 'u) (list 'comm-format-u32 arg))
804                     ((eq f 'i) (list 'comm-format-i32 arg))
805                     ((eq f 'w) (list 'comm-format-u16 arg))
806                     ((eq f 'b) (list 'comm-format-u8 arg))
807                     ((eq f 'S) (list 'comm-format-u16-string arg))
808                     ((eq f 'E) (list 'comm-format-mb-string arg))
809                     ((eq f 's) (list 'comm-format-u8-string arg))
810                     ((eq f 'B) (list 'comm-format-binary-data arg))
811                     ((eq f 'V) (setq p (cdr p))
812                                (list 'comm-format-fixlen-string arg (car p)))
813                     ((eq f 'v) (setq p (cdr p))
814                                (list 'comm-format-vector arg (car p))))))
815       (setq form (cdr form)
816             p (cdr p)))
817     (if (or form p)
818         (error "comm-format %s: arguments mismatch" format))
819     result))
820 \f
821 (defvar comm-accept-timeout nil)
822
823 ;; Assume PROC is bound to the process of current buffer
824 ;; Do not move the point, leave it where it was.
825 (defmacro comm-accept-process-output ()
826   `(let ((p (point)))
827      (if (null (accept-process-output proc comm-accept-timeout))
828          (egg-error "backend timeout"))
829      (goto-char p)))
830
831 (defmacro comm-require-process-output (n)
832   `(if (< (point-max) (+ (point) ,n))
833        (comm-wait-for-space proc ,n)))
834
835 (defun comm-wait-for-space (proc n)
836   (let ((p (point))
837         (r (+ (point) n)))
838     (while (< (point-max) r)
839       (if (null (accept-process-output proc comm-accept-timeout))
840           (egg-error "backend timeout"))
841       (goto-char p))))
842
843 (defmacro comm-following+forward-char ()
844   `(prog1
845        (following-char)
846      (forward-char 1)))
847
848 (defun comm-unpack-u32c ()
849   (progn
850     (comm-require-process-output 4)
851     (list (+ (lsh (comm-following+forward-char) 8)
852              (comm-following+forward-char))
853           (+ (lsh (comm-following+forward-char) 8)
854              (comm-following+forward-char)))))
855
856 (defun comm-unpack-i32 ()
857   (progn
858     (comm-require-process-output 4)
859     (+ (lsh (- (logxor (comm-following+forward-char) 128) 128) 24)
860        (lsh (comm-following+forward-char) 16)
861        (lsh (comm-following+forward-char) 8)
862        (comm-following+forward-char))))
863
864 (defun comm-unpack-u32 ()
865   (progn
866     (comm-require-process-output 4)
867     (+ (lsh (comm-following+forward-char) 24)
868        (lsh (comm-following+forward-char) 16)
869        (lsh (comm-following+forward-char) 8)
870        (comm-following+forward-char))))
871
872 (defun comm-unpack-u16 ()
873   (progn
874     (comm-require-process-output 2)
875     (+ (lsh (comm-following+forward-char) 8)
876        (comm-following+forward-char))))
877
878 (defun comm-unpack-u8 ()
879   (progn
880     (comm-require-process-output 1)
881     (comm-following+forward-char)))
882
883 (defun comm-unpack-u16-string ()
884   (let ((start (point)))
885     (while (not (search-forward "\0\0" nil t))
886       (comm-accept-process-output))
887     (if (and (featurep 'xemacs)
888              (coding-system-get egg-fixed-euc 'post-read-conversion))
889         (let ((string (buffer-substring start (- (point) 2)))
890               (fixed-euc egg-fixed-euc))
891           (with-temp-buffer
892             (insert string)
893             (goto-char (point-min))
894             (funcall (coding-system-get fixed-euc 'post-read-conversion)
895                      (1- (point-max)))
896             (buffer-string)))
897       (decode-coding-string (buffer-substring start (- (point) 2))
898                             egg-fixed-euc))))
899
900 (defun comm-unpack-mb-string ()
901   (let ((start (point)))
902     (while (not (search-forward "\0" nil t))
903       (comm-accept-process-output))
904     (decode-coding-string (buffer-substring start (1- (point)))
905                           egg-mb-euc)))
906
907 (defun comm-unpack-u8-string ()
908   (let ((start (point)))
909     (while (not (search-forward "\0" nil 1))
910       (comm-accept-process-output))
911     (buffer-substring start (1- (point)))))
912
913 (defun comm-unpack-binary-data ()
914   (let ((start (point)))
915     (while (not (search-forward "\377\377" nil 1))
916       (comm-accept-process-output))
917     (string-as-unibyte
918      (decode-coding-string (buffer-substring start (- (point) 2))
919                            'egg-binary))))
920
921 (defun comm-unpack-fixlen-string (len)
922   (let (s)
923     (comm-require-process-output len)
924     (goto-char (+ (point) len))
925     (setq s (buffer-substring (- (point) len) (point)))
926     (if (string-match "\0" s)
927         (setq s (substring s 0 (match-beginning 0))))
928     s))
929
930 (defun comm-unpack-vector (len)
931   (progn
932     (comm-require-process-output len)
933     (goto-char (+ (point) len))
934     (buffer-substring (- (point) len) (point))))
935
936 (defmacro comm-unpack (format &rest args)
937   "Unpack a string out of a control-string and set arguments.
938 See `comm-format' for FORMAT."
939   (let ((p args)
940         (form format)
941         (result (list 'progn))
942         arg f)
943     (while (and form p)
944       (setq f (car form)
945             arg (car p))
946       (nconc result
947              (list
948               (cond ((eq f 'U) `(setq ,arg (comm-unpack-u32c)))
949                     ((eq f 'u) `(setq ,arg (comm-unpack-u32)))
950                     ((eq f 'i) `(setq ,arg (comm-unpack-i32)))
951                     ((eq f 'w) `(setq ,arg (comm-unpack-u16)))
952                     ((eq f 'b) `(setq ,arg (comm-unpack-u8)))
953                     ((eq f 'S) `(setq ,arg (comm-unpack-u16-string)))
954                     ((eq f 'E) `(setq ,arg (comm-unpack-mb-string)))
955                     ((eq f 's) `(setq ,arg (comm-unpack-u8-string)))
956                     ((eq f 'B) `(setq ,arg (comm-unpack-binary-data)))
957                     ((eq f 'V) (setq p (cdr p))
958                                `(setq ,arg (comm-unpack-fixlen-string ,(car p))))
959                     ((eq f 'v) (setq p (cdr p))
960                                `(setq ,arg (comm-unpack-vector ,(car p)))))))
961       (setq form (cdr form)
962             p (cdr p)))
963     (if (or form p)
964         (error "comm-unpack %s: arguments mismatch" format))
965     result))
966 \f
967 (defmacro comm-call-with-proc (proc vlist send-expr &rest receive-exprs)
968   (let ((euc-select
969          (and (eq (car-safe (car vlist)) 'zhuyin)
970               '((egg-fixed-euc (nth (if zhuyin 1 0) egg-fixed-euc))))))
971   `(let* ((proc ,proc)
972           (buffer (process-buffer proc))
973           ,@vlist)
974      (if (and (eq (process-status proc) 'open)
975               (buffer-live-p buffer))
976          (save-excursion
977            (set-buffer buffer)
978            (let ,euc-select
979              (erase-buffer)
980              ,send-expr
981              (goto-char (point-max))
982              (process-send-region proc (point-min) (point-max))
983              ,@receive-exprs))
984        (egg-error "process %s was killed" proc)))))
985
986 (defmacro comm-call-with-proc-1 (proc vlist send-expr &rest receive-exprs)
987   `(let ,vlist
988      (erase-buffer)
989      ,send-expr
990      (goto-char (point-max))
991      (process-send-region proc (point-min) (point-max))
992      ,@receive-exprs))
993
994 (provide 'egg-com)
995 ;;; egg-com.el ends here.