EasyPG 1.07 Released
[packages] / mule-packages / leim / quail / sisheng.el
1 ;;; sisheng.el --- sisheng input method for Chinese pinyin transliteration -*- coding: ctext -*- 
2
3 ;; Copyright (C) 2004, 2006  Free Software Foundation, Inc.
4
5 ;; Author: Werner LEMBERG <wl@gnu.org>
6
7 ;; Keywords: multilingual, input method, Chinese, pinyin, sisheng
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to
21 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Synched up with: FSF 22.0.50.6
25
26 ;;; Commentary:
27
28 ;;; XEmacs change: use ctext as coding system for compatibility with 21.4
29
30 ;;; Code:
31
32 (require 'quail)
33
34 (defconst sisheng-regexp
35   "[\e-Dàºïòþ\e$(A(5\e(B]\\|\e-Aü\e-Dº")\e-A
36
37 ;; First element is the key,
38 ;; second element is the vowel used for the input sequence,
39 ;; last four elements are the resulting tones.
40 ;;
41 (defconst sisheng-vowel-table
42   '(("\e-Dà" "a" "à" "\e-Aá" "\e$(A(#\e(B" "à")
43     ("\e-Dº" "e" "º" "\e-Aé" "\e-Bì" "\e-Aè")
44     ("\e-Dï" "i" "ï" "\e-Aí" "\e$(A(+\e(B" "ì")
45     ("\e-Dò" "o" "ò" "\e-Aó" "\e$(A(/\e(B" "ò")
46     ("\e-Dþ" "u" "þ" "\e-Aú" "\e$(A(3\e(B" "ù")
47     ("\e$(A(5\e(B" "v" "\e$(A(5\e(B" "\e$(A(6\e(B" "\e$(A(7\e(B" "\e$(A(8\e(B")
48     ("ü\e-Dº" "ve" "\e-Aü\e-Dº" "\e-Aüé" "ü\e-Bì" "\e-Aüè")))
49
50
51 ;; All possible syllables in Mandarin Chinese, presented in the first
52 ;; tone.  Note that make-sisheng-rules always constructs rules for all
53 ;; four tones even if some of those tones aren't used in Mandarin.
54 ;;
55 (defconst sisheng-syllable-table
56   '("\e-Dà" "ài" "àn" "àng" "ào"\e-A
57
58     "b\e-Dà" "bài" "bàn" "bàng" "bào"\e-A
59     "b\e-Dºi" "bºn" "bºng"\e-A
60     "b\e-Dï" "biàn" "biào" "biº" "bïn" "bïng"\e-A
61     "b\e-Dò"\e-A
62     "b\e-Dþ"\e-A
63
64     "c\e-Dà" "cài" "càn" "càng" "cào"\e-A
65     "c\e-Dº" "cºn" "cºng"\e-A
66     "c\e-Dï"\e-A
67     "c\e-Dòng" "còu"\e-A
68     "c\e-Dþ" "cuàn" "cuï" "cþn" "cuò"\e-A
69
70     "ch\e-Dà" "chài" "chàn" "chàng" "chào"\e-A
71     "ch\e-Dº" "chºn" "chºng"\e-A
72     "ch\e-Dï"\e-A
73     "ch\e-Dòng" "chòu"\e-A
74     "ch\e-Dþ" "chuà" "chuài" "chuàn" "chuàng" "chuï" "chþn" "chuò"\e-A
75
76     "d\e-Dà" "dài" "dàn" "dàng" "dào"\e-A
77     "d\e-Dº" "dºi" "dºn" "dºng"\e-A
78     "d\e-Dï" "diàn" "diào" "diº" "dïng" "diþ"\e-A
79     "d\e-Dòng" "dòu"\e-A
80     "d\e-Dþ" "duàn" "duï" "dþn" "duò"\e-A
81
82     "\e-Dº" "ºi" "ºn" "ºng" "ºr"\e-A
83
84     "f\e-Dà" "fàn" "fàng"\e-A
85     "f\e-Dºi" "fºn" "fºng"\e-A
86     "fi\e-Dào"\e-A
87     "f\e-Dò" "fòu"\e-A
88     "f\e-Dþ"\e-A
89
90     "g\e-Dà" "gài" "gàn" "gàng" "gào"\e-A
91     "g\e-Dº" "gºi" "gºn" "gºng"\e-A
92     "g\e-Dòng" "gòu"\e-A
93     "g\e-Dþ" "guà" "guài" "guàn" "guàng" "guï" "gþn" "guò"\e-A
94
95     "h\e-Dà" "hài" "hàn" "hàng" "hào"\e-A
96     "h\e-Dº" "hºi" "hºn" "hºng"\e-A
97     "h\e-Dòng" "hòu"\e-A
98     "h\e-Dþ" "huà" "huài" "huàn" "huàng" "huï" "hþn" "huò"\e-A
99
100     "j\e-Dï" "jià" "jiàn" "jiàng" "jiào" "jiº" "jïn" "jïng" "jiòng" "jiþ"\e-A
101     "j\e-Dþ" "juàn" "juº" "jþn"\e-A
102
103     "k\e-Dà" "kài" "kàn" "kàng" "kào"\e-A
104     "k\e-Dº" "kºi" "kºn" "kºng"\e-A
105     "k\e-Dòng" "kòu"\e-A
106     "k\e-Dþ" "kuà" "kuài" "kuàn" "kuàng" "kuï" "kþn" "kuò"\e-A
107
108     "l\e-Dà" "lài" "làn" "làng" "lào"\e-A
109     "l\e-Dº" "lºi" "lºng"\e-A
110     "l\e-Dï" "lià" "liàn" "liàng" "liào" "liº" "lïn" "lïng" "liþ"\e-A
111     "l\e-Dòng" "lòu"\e-A
112     "l\e-Dþ" "luàn" "lþn" "luò"\e-A
113     "l\e$(A(5\e(B" "lü\e-Dº"\e-A
114
115     "m\e-Dà" "mài" "màn" "màng" "mào"\e-A
116     "m\e-Dº" "mºi" "mºn" "mºng"\e-A
117     "m\e-Dï" "miàn" "miào" "miº" "mïn" "mïng" "miþ"\e-A
118     "m\e-Dò" "mòu"\e-A
119     "m\e-Dþ"\e-A
120
121     "n\e-Dà" "nài" "nàn" "nàng" "nào"\e-A
122     "n\e-Dº" "nºi" "nºn" "nºng"\e-A
123     "n\e-Dï" "niàn" "niàng" "niào" "niº" "nïn" "nïng" "niþ"\e-A
124     "n\e-Dòng" "nòu"\e-A
125     "n\e-Dþ" "nuàn" "nuò"\e-A
126     "n\e$(A(5\e(B" "nü\e-Dº"\e-A
127
128     "\e-Dò" "òu"\e-A
129
130     "p\e-Dà" "pài" "pàn" "pàng" "pào"\e-A
131     "p\e-Dºi" "pºn" "pºng"\e-A
132     "p\e-Dï" "piàn" "piào" "piº" "pïn" "pïng"\e-A
133     "p\e-Dò" "pòu"\e-A
134     "p\e-Dþ"\e-A
135
136     "q\e-Dï" "qià" "qiàn" "qiàng" "qiào" "qiº" "qïn" "qïng" "qiòng" "qiþ"\e-A
137     "q\e-Dþ" "quàn" "quº" "qþn"\e-A
138
139     "r\e-Dàn" "ràng" "rào"\e-A
140     "r\e-Dº" "rºn" "rºng"\e-A
141     "r\e-Dï"\e-A
142     "r\e-Dòng" "ròu"\e-A
143     "r\e-Dþ" "ruà" "ruàn" "ruï" "rþn" "ruò"\e-A
144
145     "s\e-Dà" "sài" "sàn" "sàng" "sào"\e-A
146     "s\e-Dº" "sºn" "sºng"\e-A
147     "s\e-Dï"\e-A
148     "s\e-Dòng" "sòu"\e-A
149     "s\e-Dþ" "suàn" "suï" "sþn" "suò"\e-A
150
151     "sh\e-Dà" "shài" "shàn" "shàng" "shào"\e-A
152     "sh\e-Dº" "shºi" "shºn" "shºng"\e-A
153     "sh\e-Dï"\e-A
154     "sh\e-Dòu"\e-A
155     "sh\e-Dþ" "shuà" "shuài" "shuàn" "shuàng" "shuï" "shþn" "shuò"\e-A
156
157     "t\e-Dà" "tài" "tàn" "tàng" "tào"\e-A
158     "t\e-Dº" "tºi" "tºng"\e-A
159     "t\e-Dï" "tiàn" "tiào" "tiº" "tïng"\e-A
160     "t\e-Dòng" "tòu"\e-A
161     "t\e-Dþ" "tuàn" "tuï" "tþn" "tuò"\e-A
162
163     "w\e-Dà" "wài" "wàn" "wàng"\e-A
164     "w\e-Dºi" "wºn" "wºng"\e-A
165     "w\e-Dò"\e-A
166     "w\e-Dþ"\e-A
167
168     "x\e-Dï" "xià" "xiàn" "xiàng" "xiào" "xiº" "xïn" "xïng" "xiòng" "xiþ"\e-A
169     "x\e-Dþ" "xuàn" "xuº" "xþn"\e-A
170
171     "y\e-Dà" "yàn" "yàng" "yào"\e-A
172     "y\e-Dº"\e-A
173     "y\e-Dï" "yïn" "yïng"\e-A
174     "y\e-Dò" "yòng" "yòu"\e-A
175     "y\e-Dþ" "yuàn" "yuº" "yþn"\e-A
176
177     "z\e-Dà" "zài" "zàn" "zàng" "zào"\e-A
178     "z\e-Dº" "zºi" "zºn" "zºng"\e-A
179     "z\e-Dï"\e-A
180     "z\e-Dòng" "zòu"\e-A
181     "z\e-Dþ" "zuàn" "zuï" "zþn" "zuò"\e-A
182
183     "zh\e-Dà" "zhài" "zhàn" "zhàng" "zhào"\e-A
184     "zh\e-Dº" "zhºi" "zhºn" "zhºng"\e-A
185     "zh\e-Dï"\e-A
186     "zh\e-Dòng" "zhòu"\e-A
187     "zh\e-Dþ" "zhuà" "zhuài" "zhuàn" "zhuàng" "zhuï" "zhþn" "zhuò"))\e-A
188
189 ;; This function converts e.g.
190 ;;
191 ;;   "zhu\e-Dò"\e-A
192 ;;
193 ;; into
194 ;;
195 ;;   (("zhuo4" ["zhuò"])
196 ;;    ("zhuo3" ["zhu\e$(A(/\e(B"])
197 ;;    ("zhuo2" ["zhuó"])
198 ;;    ("zhuo1" ["zhu\e-Dò"]))\e-A
199 ;;
200 (defun quail-make-sisheng-rules (syllable)
201   (let ((case-fold-search t)
202         vowel-match
203         vowel-list
204         input-vowel
205         base-key
206         key
207         value
208         key-value-list
209         (i 1))
210     (string-match sisheng-regexp syllable)
211     (setq vowel-match (downcase (match-string 0 syllable)))
212     (setq vowel-list
213           (cdr (assoc-string vowel-match sisheng-vowel-table)))
214     (setq input-vowel (car vowel-list))
215     (setq base-key (replace-match input-vowel nil nil syllable))
216     (while (<= i 4)
217       (setq key (concat base-key (number-to-string i)))
218       (setq value (vector (replace-match (nth i vowel-list) nil nil syllable)))
219       (push (list key value) key-value-list)
220       (setq i (1+ i)))
221     key-value-list))
222
223 ;; Set up sisheng input method.
224 ;;
225 (quail-define-package
226  "chinese-sisheng"                      ; name
227  "Chinese"                              ; language
228  "\e$(A(7\e(B"                                    ; title
229  t                                      ; guidance
230  "Sìsh\e-Dºng input method for pïnyïn transliteration of Chinese.\e-A
231
232 Examples: shuang1 -> shu\e-Dàng\e-A
233           Lv3     -> L\e$(A(7\e(B
234           AN4     -> ÀN
235
236 Use the fifth (unstressed) tone for syllables containing `ü'
237 without a tone mark.
238
239 Example:  nve5    -> nüe
240 "                                       ; docstring
241  nil                                    ; translation-keys
242  t                                      ; forget-last-selection
243  nil                                    ; deterministic
244  nil                                    ; kbd-translate
245  nil                                    ; show-layout
246  nil                                    ; create-decode-map
247  nil                                    ; maximum-shortest
248  nil                                    ; overlay-plist
249  nil                                    ; update-translation-function
250  nil                                    ; conversion-keys
251  t                                      ; simple
252  )
253
254 ;; Call quail-make-sisheng-rules for all syllables in sisheng-syllable-table.
255 ;;
256 (let ((case-table-save (current-case-table))
257       sisheng-list)
258   (set-case-table (standard-case-table))
259   (dolist (syllable sisheng-syllable-table)
260     (setq sisheng-list
261           (append (quail-make-sisheng-rules syllable)
262                   sisheng-list)))
263
264   (dolist (syllable sisheng-syllable-table)
265     (setq sisheng-list
266           (append (quail-make-sisheng-rules (upcase-initials syllable))
267                   sisheng-list)))
268
269   (dolist (syllable sisheng-syllable-table)
270     (setq sisheng-list
271           (append (quail-make-sisheng-rules (upcase syllable))
272                   sisheng-list)))
273
274   (eval `(quail-define-rules
275           ,@sisheng-list
276         
277           ("lv5" ["lü"])
278           ("lve5" ["lüe"])
279           ("nv5" ["nü"])
280           ("nve5" ["nüe"])
281
282           ("Lv5" ["Lü"])
283           ("Lve5" ["Lüe"])
284           ("Nv5" ["Nü"])
285           ("Nve5" ["Nüe"])
286
287           ("LV5" ["LÜ"])
288           ("LVE5" ["LÜE"])
289           ("NV5" ["NÜ"])
290           ("NVE5" ["NÜE"])))
291   (set-case-table case-table-save))
292
293 ;;; arch-tag: 1fa6ba5f-6747-44bc-bf12-30628ad3e8ad