(sj3): New group.
[elisp/egg.git] / euc-cn.el
1 ;;; euc-cn.el --- Fixed EUC-CN handling routines.
2
3 ;; Copyright (C) 1997 Mule Project,
4 ;; Powered by Electrotechnical Laboratory, JAPAN.
5 ;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
6
7 ;; Author: KATAYAMA Yoshio <kate@pfu.co.jp>
8 ;; Maintainer: KATAYAMA Yoshio <kate@pfu.co.jp>
9 ;; Keywords: mule, multilingual, input method, chinese
10
11 ;; This file will be part of GNU Emacs (in future).
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30
31 ;;; Code:
32
33 (defvar cwnn-zhuyin nil)
34
35 (defconst chinese-sisheng-leading-chars
36   (concat (char-to-string (aref (charset-info 'chinese-sisheng) 6))
37           (char-to-string (aref (charset-info 'chinese-sisheng) 7))))
38 (defconst yincoding-pinyin-shengmu
39   '((""  . 0)  ("B" . 1)  ("C"  . 2)  ("Ch" . 3)  ("D" . 4)
40     ("F" . 5)  ("G" . 6)  ("H"  . 7)  ("J"  . 8)  ("K" . 9)
41     ("L" . 10) ("M" . 11) ("N"  . 12) ("P"  . 13) ("Q" . 14)
42     ("R" . 15) ("S" . 16) ("Sh" . 17) ("T"  . 18) ("W" . 19)
43     ("X" . 20) ("Y" . 21) ("Z"  . 22) ("Zh" . 23)))
44
45 (defconst yincoding-pinyin-yunmu
46   '(("\e(0@\e(B"      0) ("\e(0@\e(B"      0 0) ("\e(0@\e(B"      0 1) ("\e(0@\e(B"      0 2) ("\e(0@\e(B"      0 3)
47     ("a\e(0@\e(B"     1) ("\e(0!@\e(B"     1 0) ("\e(0"@\e(B"     1 1) ("\e(0#@\e(B"     1 2) ("\e(0$@\e(B"     1 3)
48     ("ai\e(0@\e(B"    2) ("\e(0!\e(Bi\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 2) ("\e(0$\e(Bi\e(0@\e(B"    2 3)
49     ("an\e(0@\e(B"    3) ("\e(0!\e(Bn\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 2) ("\e(0$\e(Bn\e(0@\e(B"    3 3)
50     ("ang\e(0@\e(B"   4) ("\e(0!\e(Bng\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 2) ("\e(0$\e(Bng\e(0@\e(B"   4 3)
51     ("ao\e(0@\e(B"    5) ("\e(0!\e(Bo\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 2) ("\e(0$\e(Bo\e(0@\e(B"    5 3)
52     ("e\e(0@\e(B"     6) ("\e(0%@\e(B"     6 0) ("\e(0&@\e(B"     6 1) ("\e(0'@\e(B"     6 2) ("\e(0(@\e(B"     6 3)
53     ("ei\e(0@\e(B"    7) ("\e(0%\e(Bi\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 2) ("\e(0(\e(Bi\e(0@\e(B"    7 3)
54     ("en\e(0@\e(B"    8) ("\e(0%\e(Bn\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 2) ("\e(0(\e(Bn\e(0@\e(B"    8 3)
55     ("eng\e(0@\e(B"   9) ("\e(0%\e(Bng\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 2) ("\e(0(\e(Bng\e(0@\e(B"   9 3)
56     ("er\e(0@\e(B"   10) ("\e(0%\e(Br\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 2) ("\e(0(\e(Br\e(0@\e(B"   10 3)
57     ("i\e(0@\e(B"    11) ("\e(0)@\e(B"    11 0) ("\e(0*@\e(B"    11 1) ("\e(0+@\e(B"    11 2) ("\e(0,@\e(B"    11 3)
58     ("ia\e(0@\e(B"   12) ("i\e(0!@\e(B"   12 0) ("i\e(0"@\e(B"   12 1) ("i\e(0#@\e(B"   12 2) ("i\e(0$@\e(B"   12 3)
59     ("ian\e(0@\e(B"  13) ("i\e(0!\e(Bn\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 2) ("i\e(0$\e(Bn\e(0@\e(B"  13 3)
60     ("iang\e(0@\e(B" 14) ("i\e(0!\e(Bng\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 2) ("i\e(0$\e(Bng\e(0@\e(B" 14 3)
61     ("iao\e(0@\e(B"  15) ("i\e(0!\e(Bo\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 2) ("i\e(0$\e(Bo\e(0@\e(B"  15 3)
62     ("ie\e(0@\e(B"   16) ("i\e(0%@\e(B"   16 0) ("i\e(0&@\e(B"   16 1) ("i\e(0'@\e(B"   16 2) ("i\e(0(@\e(B"   16 3)
63     ("in\e(0@\e(B"   17) ("\e(0)\e(Bn\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 2) ("\e(0,\e(Bn\e(0@\e(B"   17 3)
64     ("ing\e(0@\e(B"  18) ("\e(0)\e(Bng\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 2) ("\e(0,\e(Bng\e(0@\e(B"  18 3)
65     ("iong\e(0@\e(B" 19) ("i\e(0-\e(Bng\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 2) ("i\e(00\e(Bng\e(0@\e(B" 19 3)
66     ("iu\e(0@\e(B"   20) ("i\e(01@\e(B"   20 0) ("i\e(02@\e(B"   20 1) ("i\e(03@\e(B"   20 2) ("i\e(04@\e(B"   20 3)
67     ("m\e(0@\e(B"    21) ("m\e(0@\e(B"    21 0) ("m\e(0@\e(B"    21 1) ("m\e(0@\e(B"    21 2) ("m\e(0@\e(B"    21 3)
68     ("n\e(0@\e(B"    22) ("n\e(0@\e(B"    22 0) ("\e(0=@\e(B"    22 1) ("\e(0>@\e(B"    22 2) ("\e(0?@\e(B"    22 3)
69     ("ng\e(0@\e(B"   23) ("ng\e(0@\e(B"   23 0) ("ng\e(0@\e(B"   23 1) ("ng\e(0@\e(B"   23 2) ("ng\e(0@\e(B"   23 3)
70     ("o\e(0@\e(B"    24) ("\e(0-@\e(B"    24 0) ("\e(0.@\e(B"    24 1) ("\e(0/@\e(B"    24 2) ("\e(00@\e(B"    24 3)
71     ("ong\e(0@\e(B"  25) ("\e(0-\e(Bng\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 2) ("\e(00\e(Bng\e(0@\e(B"  25 3)
72     ("ou\e(0@\e(B"   26) ("\e(0-\e(Bu\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 2) ("\e(00\e(Bu\e(0@\e(B"   26 3)
73     ("u\e(0@\e(B"    27) ("\e(01@\e(B"    27 0) ("\e(02@\e(B"    27 1) ("\e(03@\e(B"    27 2) ("\e(04@\e(B"    27 3)
74     ("ua\e(0@\e(B"   28) ("u\e(0!@\e(B"   28 0) ("u\e(0"@\e(B"   28 1) ("u\e(0#@\e(B"   28 2) ("u\e(0$@\e(B"   28 3)
75     ("uai\e(0@\e(B"  29) ("u\e(0!\e(Bi\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 2) ("u\e(0$\e(Bi\e(0@\e(B"  29 3)
76     ("uan\e(0@\e(B"  30) ("u\e(0!\e(Bn\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 2) ("u\e(0$\e(Bn\e(0@\e(B"  30 3)
77     ("uang\e(0@\e(B" 31) ("u\e(0!\e(Bng\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 2) ("u\e(0$\e(Bng\e(0@\e(B" 31 3)
78     ("ue\e(0@\e(B"   32) ("u\e(0%@\e(B"   32 0) ("u\e(0&@\e(B"   32 1) ("u\e(0'@\e(B"   32 2) ("u\e(0(@\e(B"   32 3)
79     ("ui\e(0@\e(B"   33) ("u\e(0)@\e(B"   33 0) ("u\e(0*@\e(B"   33 1) ("u\e(0+@\e(B"   33 2) ("u\e(0,@\e(B"   33 3)
80     ("un\e(0@\e(B"   34) ("\e(01\e(Bn\e(0@\e(B"   34 0) ("\e(02\e(Bn\e(0@\e(B"   34 1) ("\e(03\e(Bn\e(0@\e(B"   34 2) ("\e(04\e(Bn\e(0@\e(B"   34 3)
81     ("uo\e(0@\e(B"   35) ("u\e(0-@\e(B"   35 0) ("u\e(0.@\e(B"   35 1) ("u\e(0/@\e(B"   35 2) ("u\e(00@\e(B"   35 3)
82     ("\e(09@\e(B"    36) ("\e(05@\e(B"    36 0) ("\e(06@\e(B"    36 1) ("\e(07@\e(B"    36 2) ("\e(08@\e(B"    36 3)
83     ("\e(09\e(Be\e(0@\e(B"   37) ("\e(09%@\e(B"   37 0) ("\e(09&@\e(B"   37 1) ("\e(09'@\e(B"   37 2) ("\e(09(@\e(B"   37 3)
84     ("0\e(0@\e(B"    38) ("1\e(0@\e(B"    38 0) ("2\e(0@\e(B"    38 1) ("3\e(0@\e(B"    38 2) ("4\e(0@\e(B"    38 3)))
85
86 (defconst yincoding-pinyin-table
87   [
88    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
89    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
90    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
91    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
92    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
93    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
94    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
95    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
96    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
97    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
98    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
99    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
100    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
101    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
102    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
103    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
104    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
105    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
106    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
107    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
108    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
109    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
110    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
111    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
112    ])
113
114 (defconst yincoding-zhuyin-length (charset-bytes 'chinese-sisheng))
115
116 (defconst yincoding-zhuyin-shengmu
117   '((""  .  0) ("\e(0E\e(B" .  1) ("\e(0X\e(B" .  2) ("\e(0T\e(B" .  3) ("\e(0I\e(B" .  4)
118     ("\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)
119     ("\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)
120     ("\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)
121     ("\e(0R\e(B" . 20) ("\e(0g\e(B" . 21) ("\e(0W\e(B" . 22) ("\e(0S\e(B" . 23)))
122
123 (defconst yincoding-zhuyin-yunmu
124   '(("\e(0@\e(B"    0) ("\e(0A\e(B"    0 0) ("\e(0B\e(B"    0 1) ("\e(0C\e(B"    0 2) ("\e(0D\e(B"    0 3) ; i
125     ("\e(0Z@\e(B"   1) ("\e(0ZA\e(B"   1 0) ("\e(0ZB\e(B"   1 1) ("\e(0ZC\e(B"   1 2) ("\e(0ZD\e(B"   1 3) ; a
126     ("\e(0^@\e(B"   2) ("\e(0^A\e(B"   2 0) ("\e(0^B\e(B"   2 1) ("\e(0^C\e(B"   2 2) ("\e(0^D\e(B"   2 3) ; ai
127     ("\e(0b@\e(B"   3) ("\e(0bA\e(B"   3 0) ("\e(0bB\e(B"   3 1) ("\e(0bC\e(B"   3 2) ("\e(0bD\e(B"   3 3) ; an
128     ("\e(0d@\e(B"   4) ("\e(0dA\e(B"   4 0) ("\e(0dB\e(B"   4 1) ("\e(0dC\e(B"   4 2) ("\e(0dD\e(B"   4 3) ; ang
129     ("\e(0`@\e(B"   5) ("\e(0`A\e(B"   5 0) ("\e(0`B\e(B"   5 1) ("\e(0`C\e(B"   5 2) ("\e(0`D\e(B"   5 3) ; ao
130     ("\e(0\@\e(B"   6) ("\e(0\A\e(B"   6 0) ("\e(0\B\e(B"   6 1) ("\e(0\C\e(B"   6 2) ("\e(0\D\e(B"   6 3) ; e
131     ("\e(0_@\e(B"   7) ("\e(0_A\e(B"   7 0) ("\e(0_B\e(B"   7 1) ("\e(0_C\e(B"   7 2) ("\e(0_D\e(B"   7 3) ; ei
132     ("\e(0c@\e(B"   8) ("\e(0cA\e(B"   8 0) ("\e(0cB\e(B"   8 1) ("\e(0cC\e(B"   8 2) ("\e(0cD\e(B"   8 3) ; en
133     ("\e(0e@\e(B"   9) ("\e(0eA\e(B"   9 0) ("\e(0eB\e(B"   9 1) ("\e(0eC\e(B"   9 2) ("\e(0eD\e(B"   9 3) ; eng
134     ("\e(0f@\e(B"  10) ("\e(0fA\e(B"  10 0) ("\e(0fB\e(B"  10 1) ("\e(0fC\e(B"  10 2) ("\e(0fD\e(B"  10 3) ; er
135     ("\e(0g@\e(B"  11) ("\e(0gA\e(B"  11 0) ("\e(0gB\e(B"  11 1) ("\e(0gC\e(B"  11 2) ("\e(0gD\e(B"  11 3) ; i
136     ("\e(0gZ@\e(B" 12) ("\e(0gZA\e(B" 12 0) ("\e(0gZB\e(B" 12 1) ("\e(0gZC\e(B" 12 2) ("\e(0gZD\e(B" 12 3) ; ia
137     ("\e(0gb@\e(B" 13) ("\e(0gbA\e(B" 13 0) ("\e(0gbB\e(B" 13 1) ("\e(0gbC\e(B" 13 2) ("\e(0gbD\e(B" 13 3) ; ian
138     ("\e(0gd@\e(B" 14) ("\e(0gdA\e(B" 14 0) ("\e(0gdB\e(B" 14 1) ("\e(0gdC\e(B" 14 2) ("\e(0gdD\e(B" 14 3) ; iang
139     ("\e(0g`@\e(B" 15) ("\e(0g`A\e(B" 15 0) ("\e(0g`B\e(B" 15 1) ("\e(0g`C\e(B" 15 2) ("\e(0g`D\e(B" 15 3) ; iao
140     ("\e(0g]@\e(B" 16) ("\e(0g]A\e(B" 16 0) ("\e(0g]B\e(B" 16 1) ("\e(0g]C\e(B" 16 2) ("\e(0g]D\e(B" 16 3) ; ie
141     ("\e(0gc@\e(B" 17) ("\e(0gcA\e(B" 17 0) ("\e(0gcB\e(B" 17 1) ("\e(0gcC\e(B" 17 2) ("\e(0gcD\e(B" 17 3) ; in
142     ("\e(0ge@\e(B" 18) ("\e(0geA\e(B" 18 0) ("\e(0geB\e(B" 18 1) ("\e(0geC\e(B" 18 2) ("\e(0geD\e(B" 18 3) ; ing
143     ("\e(0ie@\e(B" 19) ("\e(0ieA\e(B" 19 0) ("\e(0ieB\e(B" 19 1) ("\e(0ieC\e(B" 19 2) ("\e(0ieD\e(B" 19 3) ; iong
144     ("\e(0ga@\e(B" 20) ("\e(0gaA\e(B" 20 0) ("\e(0gaB\e(B" 20 1) ("\e(0gaC\e(B" 20 2) ("\e(0gaD\e(B" 20 3) ; iu
145     ("\e(0G@\e(B"  21) ("\e(0GA\e(B"  21 0) ("\e(0GB\e(B"  21 1) ("\e(0GC\e(B"  21 2) ("\e(0GD\e(B"  21 3) ; m
146     ("\e(0K@\e(B"  22) ("\e(0KA\e(B"  22 0) ("\e(0KB\e(B"  22 1) ("\e(0KC\e(B"  22 2) ("\e(0KD\e(B"  22 3) ; n
147     ("@\e(0@\e(B"  23) ("@\e(0A\e(B"  23 0) ("@\e(0B\e(B"  23 1) ("@\e(0C\e(B"  23 2) ("@\e(0D\e(B"  23 3) ; ng
148     ("\e(0[@\e(B"  24) ("\e(0[A\e(B"  24 0) ("\e(0[B\e(B"  24 1) ("\e(0[C\e(B"  24 2) ("\e(0[D\e(B"  24 3) ; o
149     ("\e(0he@\e(B" 25) ("\e(0heA\e(B" 25 0) ("\e(0heB\e(B" 25 1) ("\e(0heC\e(B" 25 2) ("\e(0heD\e(B" 25 3) ; ong
150     ("\e(0a@\e(B"  26) ("\e(0aA\e(B"  26 0) ("\e(0aB\e(B"  26 1) ("\e(0aC\e(B"  26 2) ("\e(0aD\e(B"  26 3) ; ou
151     ("\e(0h@\e(B"  27) ("\e(0hA\e(B"  27 0) ("\e(0hB\e(B"  27 1) ("\e(0hC\e(B"  27 2) ("\e(0hD\e(B"  27 3) ; u
152     ("\e(0hZ@\e(B" 28) ("\e(0hZA\e(B" 28 0) ("\e(0hZB\e(B" 28 1) ("\e(0hZC\e(B" 28 2) ("\e(0hZD\e(B" 28 3) ; ua
153     ("\e(0h^@\e(B" 29) ("\e(0h^A\e(B" 29 0) ("\e(0h^B\e(B" 29 1) ("\e(0h^C\e(B" 29 2) ("\e(0h^D\e(B" 29 3) ; uai
154     ("\e(0hb@\e(B" 30) ("\e(0hbA\e(B" 30 0) ("\e(0hbB\e(B" 30 1) ("\e(0hbC\e(B" 30 2) ("\e(0hbD\e(B" 30 3) ; uan
155     ("\e(0hd@\e(B" 31) ("\e(0hdA\e(B" 31 0) ("\e(0hdB\e(B" 31 1) ("\e(0hdC\e(B" 31 2) ("\e(0hdD\e(B" 31 3) ; uang
156     ("\e(0i]@\e(B" 37) ("\e(0i]A\e(B" 37 0) ("\e(0i]B\e(B" 37 1) ("\e(0i]C\e(B" 37 2) ("\e(0i]D\e(B" 37 3) ; ue
157     ("\e(0h_@\e(B" 33) ("\e(0h_A\e(B" 33 0) ("\e(0h_B\e(B" 33 1) ("\e(0h_C\e(B" 33 2) ("\e(0h_D\e(B" 33 3) ; ui
158     ("\e(0hc@\e(B" 34) ("\e(0hcA\e(B" 34 0) ("\e(0hcB\e(B" 34 1) ("\e(0hcC\e(B" 34 2) ("\e(0hcD\e(B" 34 3) ; un
159     ("\e(0h[@\e(B" 35) ("\e(0h[A\e(B" 35 0) ("\e(0h[B\e(B" 35 1) ("\e(0h[C\e(B" 35 2) ("\e(0h[D\e(B" 35 3) ; uo
160     ("\e(0i@\e(B"  36) ("\e(0iA\e(B"  36 0) ("\e(0iB\e(B"  36 1) ("\e(0iC\e(B"  36 2) ("\e(0iD\e(B"  36 3) ; \e(09\e(B
161     ("\e(0i]@\e(B" 37) ("\e(0i]A\e(B" 37 0) ("\e(0i]B\e(B" 37 1) ("\e(0i]C\e(B" 37 2) ("\e(0i]D\e(B" 37 3) ; \e(09\e(Be
162     ("0\e(0@\e(B"  38) ("1\e(0A\e(B"  38 0) ("2\e(0B\e(B"  38 1) ("3\e(0C\e(B"  38 2) ("4\e(0D\e(B"  38 3) ; undefined YunMu
163     ("\e(0ib@\e(B" 39) ("\e(0ibA\e(B" 39 0) ("\e(0ibB\e(B" 39 1) ("\e(0ibC\e(B" 39 2) ("\e(0ibD\e(B" 39 3) ; \e(09\e(Ban
164     ("\e(0ic@\e(B" 40) ("\e(0icA\e(B" 40 0) ("\e(0icB\e(B" 40 1) ("\e(0icC\e(B" 40 2) ("\e(0icD\e(B" 40 3) ; \e(09\e(Bn
165     ))
166
167 (defconst yincoding-zhuyin-table
168   [
169    ;; empty ShengMu
170    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
171    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x9586 ?\x0000 ?\x9592 ?\x9599
172    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x0000
173    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x959b ?\x95a0 ?\x0000 ?\x959e
174    ?\x95a2
175    ;; ShengMu B
176    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
177    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
178    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000
179    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
180    ?\x0000
181    ;; ShengMu C
182    ?\x828b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
183    ?\x0000 ?\x0280 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
184    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
185    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
186    ?\x0000
187    ;; ShengMu Ch
188    ?\x838b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
189    ?\x0000 ?\x0380 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
190    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
191    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
192    ?\x0000
193    ;; ShengMu D
194    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
195    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
196    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
197    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
198    ?\x0000
199    ;; ShengMu F
200    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
201    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
202    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
203    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
204    ?\x0000
205    ;; ShengMu G
206    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
207    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
208    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
209    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
210    ?\x0000
211    ;; ShengMu H
212    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
213    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
214    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
215    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
216    ?\x0000
217    ;; ShengMu J
218    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
219    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
220    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x08a4 ?\x0000 ?\x0000
221    ?\x08a7 ?\x0000 ?\x08a5 ?\x0000 ?\x08a8 ?\x0000 ?\x889b ?\x88a0 ?\x8000 ?\x889e
222    ?\x88a2
223    ;; ShengMu K
224    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
225    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
226    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
227    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
228    ?\x0000
229    ;; ShengMu L
230    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
231    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
232    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
233    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
234    ?\x0000
235    ;; ShengMu M
236    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
237    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
238    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
239    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
240    ?\x0000
241    ;; ShengMu N
242    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
243    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
244    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
245    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
246    ?\x0000
247    ;; ShengMu P
248    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
249    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
250    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
251    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
252    ?\x0000 
253    ;; ShengMu Q
254    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
255    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
256    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0ea4 ?\x0000 ?\x0000
257    ?\x0ea7 ?\x0000 ?\x0ea5 ?\x0000 ?\x0ea8 ?\x0000 ?\x8e9b ?\x8ea0 ?\x8000 ?\x8e9e
258    ?\x8ea2
259    ;; ShengMu R
260    ?\x8f8b ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
261    ?\x0000 ?\x0f80 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
262    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000
263    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
264    ?\x0000
265    ;; ShengMu S
266    ?\x908b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000
267    ?\x0000 ?\x1080 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
268    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
269    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
270    ?\x0000
271    ;; ShengMu Sh
272    ?\x918b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
273    ?\x0000 ?\x1180 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
274    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
275    ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
276    ?\x0000
277    ;; ShengMu T
278    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x8000
279    ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x0000 ?\x8000 ?\x0000
280    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000
281    ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
282    ?\x0000
283    ;; ShengMu W
284    ?\x939b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x0000 ?\x0000 ?\x8000 ?\x8000 ?\x8000
285    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
286    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000 ?\x0000 ?\x1380 ?\x0000 ?\x0000
287    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
288    ?\x0000
289    ;; ShengMu X
290    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000
291    ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
292    ?\x8000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x14a4 ?\x0000 ?\x0000
293    ?\x14a7 ?\x0000 ?\x14a5 ?\x0000 ?\x14a8 ?\x0000 ?\x949b ?\x94a0 ?\x8000 ?\x949e
294    ?\x94a2
295    ;; ShengMu Y 
296    ?\x958b ?\x8000 ?\x0000 ?\x8000 ?\x8000 ?\x8000 ?\x0090 ?\x0000 ?\x9591 ?\x9592
297    ?\x0000 ?\x1580 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x1588 ?\x1589 ?\x0000
298    ?\x0000 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0093 ?\x8000 ?\x00a4 ?\x0000 ?\x0000
299    ?\x00a7 ?\x0000 ?\x00a5 ?\x0000 ?\x00a8 ?\x0000 ?\x0000 ?\x0000 ?\x8000 ?\x0000
300    ?\x0000
301    ;; ShengMu Z
302    ?\x968b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
303    ?\x0000 ?\x1680 ?\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 Zh 
308    ?\x978b ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000 ?\x8000
309    ?\x0000 ?\x1780 ?\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    ])
314
315 (defun encode-euc-cwnn-region (beg end)
316   "Encode the text in the current region to EUC-cWnn.
317 Return the length of resulting text."
318   (interactive "r")
319   (let (sylend s y z (enable-multibyte-characters t))
320     (save-excursion
321       (save-restriction
322         (narrow-to-region beg end)
323         (goto-char (point-min))
324         (while (< (point) (point-max))
325           (cond
326            ((looking-at "[A-Za-z\e(0!\e(B-\e(0?\e(B]+\e(0@\e(B")
327             ;; PinYin
328             (setq sylend (match-end 0))
329             (if (and (looking-at "[B-Z]h?")
330                      (setq s (assoc (buffer-substring (match-beginning 0) (match-end 0))
331                                     yincoding-pinyin-shengmu)))
332                 (setq s (cdr s) y (buffer-substring (match-end 0) sylend))
333               (setq s 0 y (buffer-substring (point) sylend)))
334             (if (and (setq y (assoc y yincoding-pinyin-yunmu))
335                      (= (aref yincoding-pinyin-table (+ (* 39 s) (nth 1 y))) 1))
336                 (progn
337                   (delete-region (point) sylend)
338                   (insert (char-to-string (+ (* 2 (nth 1 y)) 32 (if (nth 2 y) 1 0)))
339                           (char-to-string (+ (* 4 (if (= s 0) 20 s)) 156 (if (nth 2 y) (nth 2 y) 0)))))
340               (encode-euc-cwnn-1-char)))
341            ((looking-at "[\e(0E\e(B-\e(0i\e(B@0-4]+[\e(0@ABCD\e(B]")
342             ;; ZhuYin
343             (setq sylend (match-end 0))
344             (if (setq y (assoc (buffer-substring (point) sylend) yincoding-zhuyin-yunmu))
345                 (setq s 0)
346               (if (setq s (assoc (char-to-string (following-char)) yincoding-zhuyin-shengmu))
347                   (setq s (cdr s) y (buffer-substring (+ (point) yincoding-zhuyin-length) sylend))
348                 (setq s 0 y (buffer-substring (point) sylend)))
349               (setq y (assoc y yincoding-zhuyin-yunmu)))
350             (if (and y
351                      (/= (logand (setq z (aref yincoding-zhuyin-table (+ (* 41 s) (nth 1 y)))) ?\x8000) 0))
352                 (progn
353                   (delete-region (point) sylend)
354                   (if (/= (logand z ?\x80) 0)
355                       (setq s (logand (lsh z -8) 127) y (list nil (logand z 127) (nth 2 y))))
356                   (insert (+ (* 2 (nth 1 y)) 32 (if (nth 2 y) 1 0))
357                           (+ (* 4 (if (= s 0) 20 s)) 156 (if (nth 2 y) (nth 2 y) 0))))
358               (encode-euc-cwnn-1-char)))
359            (t (encode-euc-cwnn-1-char))))
360         (- (point-max) (point-min))))))
361
362 (defun encode-euc-cwnn-1-char ()
363   (let ((enable-multibyte-characters nil))
364     (cond
365      ((eq (following-char) (charset-id 'chinese-gb2312))
366       (delete-char 1)
367       (forward-char 2))
368      ((looking-at chinese-sisheng-leading-chars)
369       (delete-region (match-beginning 0) (match-end 0))
370       (insert 0)
371       (forward-char))
372      (t
373       (insert 0)
374       (forward-char)))))
375
376 (defun pre-write-encode-euc-cwnn (from to)
377   (let ((buf (current-buffer))
378         (work (get-buffer-create " *pre-write-encoding-work*")))
379     (set-buffer work)
380     (erase-buffer)
381     (if (stringp from)
382         (insert from)
383       (insert-buffer-substring buf from to))
384     (encode-euc-cwnn-region 1 (point-max))
385     nil))
386
387 (defun decode-euc-cwnn-region (beg end)
388   "Decode EUC-cWnn encoded text in the current region.
389 Return the length of resulting text."
390   (interactive "r")
391   (prog1
392       (let (c cc s y ss (enable-multibyte-characters nil))
393         (save-restriction
394           (narrow-to-region beg end)
395           (goto-char (point-min))
396           (while (< (point) (point-max))
397             (setq c (following-char))
398             (cond
399              ((eq c 0)
400               (delete-char 1)
401               (if (>= (following-char) 128)
402                   (insert chinese-sisheng-leading-chars))
403               (forward-char))
404              ((>= c 128)
405               (insert (charset-id 'chinese-gb2312))
406               (forward-char 2)
407               (if (< (setq c (preceding-char)) 128)
408                   (progn
409                     (delete-char -1)
410                     (insert (+ c 128))
411                     (forward-char))))
412              (t
413               (delete-char 1)
414               (setq cc (logand (following-char) 127))
415               (delete-char 1)
416               (setq s (+ (lsh (- cc 32) -2) 1)
417                     y (lsh (- c 32) -1)
418                     ss (+ (logand c 1) (logand cc 3)))
419               (if cwnn-zhuyin
420                   (progn
421                     (setq c (aref yincoding-zhuyin-table (+ (* 41 s) y)))
422                     (if (eq (logand c ?\x8080) ?\x80)
423                         (setq s (lsh c -8)
424                               y (logand c 127)))
425                     (if (and (eq s 20)
426                              (eq (aref yincoding-pinyin-table (+ (* 39 s) y)) 0))
427                         (setq s 0))
428                     (insert (car (nth s yincoding-zhuyin-shengmu))
429                             (car (nth (+ (* 5 y) ss) yincoding-zhuyin-yunmu))))
430                 (if (and (eq s 20)
431                          (eq (aref yincoding-pinyin-table (+ (* 39 s) y)) 0))
432                     (setq s 0))
433                 (insert (car (nth s yincoding-pinyin-shengmu))
434                         (car (nth (+ (* 5 y) ss) yincoding-pinyin-yunmu)))))))
435           (- (point-max) (point-min))))
436     (if (looking-at "\0\0") (forward-char 2))))
437
438 (defun post-read-decode-euc-cwnn (len)
439   (let ((pos (point))
440         (buffer-modified-p (buffer-modified-p)))
441     (prog1
442         (decode-euc-cwnn-region pos (+ pos len))
443       (set-buffer-modified-p buffer-modified-p))))
444
445 (make-coding-system 'fixed-euc-cn 5 ?W "Coding System for fixed EUC Japanese")
446 (put 'fixed-euc-cn 'post-read-conversion 'post-read-decode-euc-cwnn)
447 (put 'fixed-euc-cn 'pre-write-conversion 'pre-write-encode-euc-cwnn)
448
449 ;;; euc-cn.el ends here.