*** empty log message ***
[bpt/emacs.git] / lisp / international / titdic-cnv.el
CommitLineData
c7211fed 1;;; titdic-cnv.el --- convert cxterm dictionary (TIT format) to Quail package -*- coding:iso-2022-7bit; -*-
4ed46869 2
4ed46869 3;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
fa526c4a 4;; Licensed to the Free Software Foundation.
4ed46869
KH
5
6;; Keywords: Quail, TIT, cxterm
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
369314dc
KH
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
4ed46869 24
60370d40 25;;; Commentary:
4ed46869 26
49ed466f 27;; Convert cxterm dictionary (of TIT format) to quail-package.
4ed46869
KH
28;;
29;; Usage (within Emacs):
49ed466f 30;; M-x titdic-convert<CR>CXTERM-DICTIONARY-NAME<CR>
4ed46869 31;; Usage (from shell):
49ed466f 32;; % emacs -batch -l titdic-cnv -f batch-titdic-convert\
4ed46869
KH
33;; [-dir DIR] [DIR | FILE] ...
34;;
35;; When you run titdic-convert within Emacs, you have a chance to
36;; modify arguments of `quail-define-package' before saving the
37;; converted file. For instance, you are likely to modify TITLE,
38;; DOCSTRING, and KEY-BINDINGS.
39
49ed466f 40;; Cxterm dictionary file (*.tit) is a line-oriented text (English,
4ed46869
KH
41;; Chinese, Japanese, and Korean) file. The whole file contains of
42;; two parts, the definition part (`header' here after) followed by
43;; the dictionary part (`body' here after). All lines begin with
44;; leading '#' are ignored.
45;;
46;; Each line in the header part has two fields, KEY and VALUE. These
47;; fields are separated by one or more white characters.
48;;
49;; Each line in the body part has two fields, KEYSEQ and TRANSLATIONS.
50;; These fields are separated by one or more white characters.
51;;
52;; See the manual page of `tit2cit' of cxterm distribution for more
53;; detail.
c063e381 54;;
b138056a 55;; Near the end of this file, we also have a few other tools to convert
c063e381 56;; miscellaneous dictionaries.
4ed46869
KH
57
58;;; Code:
59
60(require 'quail)
61
49ed466f 62;; List of values of key "ENCODE:" and the corresponding Emacs
4ed46869
KH
63;; coding-system and language environment name.
64(defvar tit-encode-list
a7f2c216
KH
65 '(("GB" euc-china "Chinese-GB")
66 ("BIG5" cn-big5 "Chinese-BIG5")
67 ("JIS" euc-japan "Japanese")
49ed466f
KH
68 ("KS" euc-kr "Korean")))
69
4558e816
KH
70;; Alist of input method names and the corresponding title and extra
71;; docstring. For each of input method generated from TIT dictionary,
72;; a docstring is automatically generated from the comments in the
73;; dictionary. The extra docstring in this alist is to add more
74;; information.
75;; The command describe-input-method shows the automatically generated
c7211fed 76;; docstring, then an extra docstring while replacing the form \<VAR>
4558e816
KH
77;; by the value of variable VAR. For instance, the form
78;; \<quail-translation-docstring> is replaced by a description about
79;; how to select a translation from a list of candidates.
80
6b1e079c
KH
81(defvar quail-cxterm-package-ext-info
82 '(("chinese-4corner" "\e$(0(?-F\e(B")
83 ("chinese-array30" "\e$(0#R#O\e(B")
4558e816
KH
84 ("chinese-ccdospy" "\e$AKuF4\e(B"
85 "Pinyin base input method for Chinese charset GB2312 \(`chinese-gb2312').
86
c7211fed 87Pinyin is the standard Roman transliteration method for Chinese.
4558e816
KH
88For the detail of Pinyin system, see the documentation of the input
89method `chinese-py'.
90
91This input method works almost the same way as `chinese-py'. The
92difference is that you type a single key for these Pinyin spelling.
93 Pinyin: zh en eng ang ch an ao ai ong sh ing yu(\e$A(9\e(B)
94 keyseq: a f g h i j k l s u y v
c7211fed 95For example:
4558e816
KH
96 Chinese: \e$A0!\e(B \e$A9{\e(B \e$AVP\e(B \e$AND\e(B \e$A9b\e(B \e$ASq\e(B \e$AH+\e(B
97 Pinyin: a guo zhong wen guang yu quan
98 Keyseq: a1 guo4 as1 wf4 guh1 yu..6 qvj6
99
100\\<quail-translation-docstring>
101
102For double-width GB2312 characters correponding to ASCII, use the
103input method `chinese-qj'.")
104
4558e816
KH
105 ("chinese-ecdict" "\e$(05CKH\e(B"
106"In this input method, you enter a Chinese (Big5) charactere or word
107by typing the corresponding English word. For example, if you type
108\"computer\", \"\e$(0IZH+\e(B\" is input.
109
110\\<quail-translation-docstring>")
111
112 ("chinese-etzy" "\e$(06/0D\e(B"
113"Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
114`chinese-big5-2').
115
116Zhuyin is a kind of phonetic symbol. One to three Zhuyin symbols
117compose one Chinese character.
118
119In this input method, you enter a Chinese character by first typing
120keys corresponding to Zhuyin symbols (see the above table) followed by
121SPC, 1, 2, 3, or 4 specifing a tone (SPC:\e$(0?v(N\e(B, 1:\e$(0M=Vy\e(B, 2:\e$(0Dm(N\e(B, 3: \e$(0&9Vy\e(B,
1224:\e$(0(+Vy\e(B).
123
124\\<quail-translation-docstring>")
6b1e079c
KH
125
126 ("chinese-punct-b5" "\e$(0O:\e(BB"
127 "Input method for Chinese punctuations and symbols of Big5
128\(`chinese-big5-1' and `chinese-big5-2').")
129
130 ("chinese-punct" "\e$A1j\e(BG"
131 "Input method for Chinese punctuations and symbols of GB2312
132\(`chinese-gb2312').")
133
134 ("chinese-py-b5" "\e$(03<\e(BB"
135 "Pinyin base input method for Chinese Big5 characters
136\(`chinese-big5-1', `chinese-big5-2').
137
138This input method works almost the same way as `chinese-py' (which
139see).
140
141This input method supports only Han characters. The more convenient
43b11fee
EZ
142method is `chinese-py-punct-b5', which is the combination of this
143method and `chinese-punct-b5' and which supports both Han characters
144and punctuation/symbols.
6b1e079c 145
43b11fee 146For double-width Big5 characters corresponding to ASCII, use the input
6b1e079c
KH
147method `chinese-qj-b5'.
148
149The input method `chinese-py' and `chinese-tonepy' are also Pinyin
43b11fee 150based, but for the character set GB2312 (`chinese-gb2312').")
6b1e079c 151
4558e816
KH
152 ("chinese-qj-b5" "\e$(0)A\e(BB")
153
154 ("chinese-qj" "\e$AH+\e(BG")
155
6b1e079c 156 ("chinese-sw" "\e$AJWN2\e(B"
4558e816
KH
157"Radical base input method for Chinese charset GB2312 (`chinese-gb2312').
158
d20faceb
EZ
159In this input method, you enter a Chinese character by typing two
160keys. The first key corresponds to the first (\e$AJW\e(B) radical, the second
161key corresponds to the last (\e$AN2\e(B) radical. The correspondence of keys
162and radicals is as below:
4558e816
KH
163
164 first radical:
165 a b c d e f g h i j k l m n o p q r s t u v w x y z
166 \e$APD\e(B \e$AZ"\e(B \e$AJ,\e(B \e$AX<\e(B \e$A;p\e(B \e$A?Z\e(B \e$A^P\e(B \e$Ac_\e(B \e$AZ%\e(B \e$A\3\e(B \e$AXi\e(B \e$AD>\e(B \e$Alj\e(B \e$Ab;\e(B \e$ATB\e(B \e$Afy\e(B \e$AJ/\e(B \e$AMu\e(B \e$A0K\e(B \e$AX/\e(B \e$AHU\e(B \e$AeA\e(B \e$Aak\e(B \e$AVq\e(B \e$AR;\e(B \e$AHK\e(B
167 last radical:
168 a b c d e f g h i j k l m n o p q r s t u v w x y z
169 \e$ASV\e(B \e$AI=\e(B \e$AMA\e(B \e$A56\e(B \e$AZb\e(B \e$A?Z\e(B \e$ARB\e(B \e$Aqb\e(B \e$A4s\e(B \e$A6!\e(B \e$A[L\e(B \e$Ala\e(B \e$AJ.\e(B \e$A4u\e(B \e$AXg\e(B \e$ACE\e(B \e$A=q\e(B \e$AX-\e(B \e$AE.\e(B \e$ARR\e(B \e$A`m\e(B \e$AP!\e(B \e$A3'\e(B \e$A3f\e(B \e$A_.\e(B \e$A27\e(B
170
43e5a7fe 171\\<quail-translation-docstring>")
4558e816 172
6b1e079c
KH
173 ("chinese-tonepy" "\e$A5wF4\e(B"
174 "Pinyin base input method for Chinese charset GB2312 (`chinese-gb2312').
175
176Pinyin is the standared roman transliteration method for Chinese.
d20faceb 177For the details of Pinyin system, see the documentation of the input
6b1e079c
KH
178method `chinese-py'.
179
180This input method works almost the same way as `chinese-py'. The
4558e816
KH
181difference is that you must type 1..5 after each Pinyin spelling to
182specify a tone (1:\e$ARuF=\e(B, 2:\e$AQtF=\e(B, 3:\e$AIOIy\e(B, 4\e$AOBIy\e(B, 5:\e$AGaIy\e(B).
183
43e5a7fe 184\\<quail-translation-docstring>
4558e816
KH
185
186For instance, to input \e$ADc\e(B, you type \"n i 3 3\", the first \"n i\" is
187a Pinyin, the next \"3\" specifies tone, and the last \"3\" selects
188the third character from the candidate list.
6b1e079c
KH
189
190For double-width GB2312 characters correponding to ASCII, use the
191input method `chinese-qj'.")
192
4558e816
KH
193 ("chinese-zozy" "\e$(0I\0D\e(B"
194"Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
195`chinese-big5-2').
196
d20faceb 197Zhuyin is a kind of a phonetic symbol. One to three Zhuyin symbols
4558e816
KH
198compose a Chinese character.
199
200In this input method, you enter a Chinese character by first typing
201keys corresponding to Zhuyin symbols (see the above table) followed by
202SPC, 6, 3, 4, or 7 specifing a tone (SPC:\e$(0?v(N\e(B, 6:\e$(0Dm(N\e(B, 3:\e$(0&9Vy\e(B, 4:\e$(0(+Vy\e(B,
2037:\e$(0M=Vy\e(B).
204
43e5a7fe 205\\<quail-translation-docstring>")))
4ed46869
KH
206
207;; Return a value of the key in the current line.
208(defsubst tit-read-key-value ()
209 (if (looking-at "[^ \t\n]+")
210 (car (read-from-string (concat "\"" (match-string 0) "\"")))))
211
212;; Return an appropriate quail-package filename from FILENAME (TIT
49ed466f
KH
213;; dictionary filename). For instance, ".../ZOZY.tit" -> "ZOZY.el".
214(defun tit-make-quail-package-file-name (filename &optional dirname)
4ed46869 215 (expand-file-name
49ed466f 216 (concat (file-name-nondirectory (substring filename 0 -4)) ".el")
4ed46869
KH
217 dirname))
218
1375754c 219;; This value is nil if we are processing phrase dictionary.
8c1ccc6c 220(defvar tit-dictionary t)
4ed46869
KH
221(defvar tit-encode nil)
222(defvar tit-default-encode "GB")
223
224;; Generate elements of KEY-BINDINGS arg for `quail-define-package' so
225;; that each characters in KEYS invokes FUNCTION-SYMBOL.
226(defun tit-generate-key-bindings (keys function-symbol)
227 (let ((len (length keys))
228 (i 0)
1375754c 229 (first t)
4ed46869
KH
230 key)
231 (while (< i len)
1375754c 232 (or first (princ "\n "))
4ed46869 233 (setq key (aref keys i))
1375754c
KH
234 (if (if (< key ?\ )
235 (eq (lookup-key quail-translation-keymap
236 (char-to-string key))
4ed46869 237 'quail-execute-non-quail-command)
1375754c
KH
238 (<= key 127))
239 (progn
240 (princ (cons (cond ((< key ?\ ) (format "\"\\C-%c\"" (+ key ?@)))
241 ((< key 127) (format "\"%c\"" key))
242 (t "\"\\C-?\""))
243 function-symbol))
244 (setq first nil)))
4ed46869
KH
245 (setq i (1+ i)))))
246
247;; Analyze header part of TIT dictionary and generate an appropriate
248;; `quail-define-package' function call.
249(defun tit-process-header (filename)
250 (message "Processing header part...")
251 (goto-char (point-min))
252
1375754c
KH
253 ;; At first, generate header part of the Quail package while
254 ;; collecting information from the original header.
255 (let ((package (concat
256 "chinese-"
257 (substring (downcase (file-name-nondirectory filename))
258 0 -4)))
259 ;; TIT keywords and the corresponding default values.
4ed46869
KH
260 (tit-multichoice t)
261 (tit-prompt "")
262 (tit-comments nil)
263 (tit-backspace "\010\177")
264 (tit-deleteall "\015\025")
265 (tit-moveright ".>")
266 (tit-moveleft ",<")
267 (tit-keyprompt nil))
1375754c
KH
268
269 (princ ";; Quail package `")
c7211fed
DL
270 (princ package) (princ "' -*- coding:iso-2022-7bit; -*-\n")
271 (princ ";; Generated by the command `titdic-convert'\n;;\tDate: ")
1375754c
KH
272 (princ (current-time-string))
273 (princ "\n;;\tOriginal TIT dictionary file: ")
274 (princ (file-name-nondirectory filename))
275 (princ "\n\n;;; Comment:\n\n")
86e4f7c0 276 (princ ";; Byte-compile this file again after any modification.\n\n")
1375754c
KH
277 (princ ";;; Start of the header of original TIT dictionary.\n\n")
278
4ed46869 279 (while (not (eobp))
1375754c
KH
280 (let ((ch (following-char))
281 (pos (point)))
4ed46869
KH
282 (cond ((= ch ?C) ; COMMENT
283 (cond ((looking-at "COMMENT")
284 (let ((pos (match-end 0)))
285 (end-of-line)
4ed46869
KH
286 (setq tit-comments (cons (buffer-substring pos (point))
287 tit-comments))))))
288 ((= ch ?M) ; MULTICHOICE, MOVERIGHT, MOVELEFT
289 (cond ((looking-at "MULTICHOICE:[ \t]*")
290 (goto-char (match-end 0))
291 (setq tit-multichoice (looking-at "YES")))
292 ((looking-at "MOVERIGHT:[ \t]*")
293 (goto-char (match-end 0))
294 (setq tit-moveright (tit-read-key-value)))
295 ((looking-at "MOVELEFT:[ \t]*")
296 (goto-char (match-end 0))
297 (setq tit-moveleft (tit-read-key-value)))))
298 ((= ch ?P) ; PROMPT
299 (cond ((looking-at "PROMPT:[ \t]*")
300 (goto-char (match-end 0))
6b1e079c
KH
301 (setq tit-prompt (tit-read-key-value))
302 ;; Some TIT dictionaies that are encoded by
303 ;; euc-china contains invalid character at the tail.
304 (let* ((last (aref tit-prompt (1- (length tit-prompt))))
305 (split (split-char last)))
306 (if (or (eq (nth 1 split) 32)
307 (eq (nth 2 split) 32))
308 (setq tit-prompt (substring tit-prompt 0 -1)))))))
4ed46869
KH
309 ((= ch ?B) ; BACKSPACE, BEGINDICTIONARY,
310 ; BEGINPHRASE
311 (cond ((looking-at "BACKSPACE:[ \t]*")
312 (goto-char (match-end 0))
313 (setq tit-backspace (tit-read-key-value)))
314 ((looking-at "BEGINDICTIONARY")
1375754c 315 (setq tit-dictionary t))
4ed46869 316 ((looking-at "BEGINPHRASE")
1375754c 317 (setq tit-dictionary nil))))
4ed46869
KH
318 ((= ch ?K) ; KEYPROMPT
319 (cond ((looking-at "KEYPROMPT(\\(.*\\)):[ \t]*")
320 (let ((key-char (match-string 1)))
321 (goto-char (match-end 0))
1fa1e1f5
RS
322 (if (string-match "\\\\[0-9]+" key-char)
323 (setq key-char
324 (car (read-from-string (format "\"%s\""
325 key-char)))))
4ed46869
KH
326 (setq tit-keyprompt
327 (cons (cons key-char (tit-read-key-value))
1375754c
KH
328 tit-keyprompt)))))))
329 (end-of-line)
330 (princ ";; ")
331 (princ (buffer-substring pos (point)))
332 (princ "\n")
333 (forward-line 1)))
4ed46869 334
1375754c
KH
335 (princ "\n;;; End of the header of original TIT dictionary.\n\n")
336 (princ ";;; Code:\n\n(require 'quail)\n\n")
337
338 (princ "(quail-define-package ")
339 ;; Args NAME, LANGUAGE, TITLE
6b1e079c 340 (let ((title (nth 1 (assoc package quail-cxterm-package-ext-info))))
1375754c
KH
341 (princ "\"")
342 (princ package)
343 (princ "\" \"")
344 (princ (nth 2 (assoc tit-encode tit-encode-list)))
345 (princ "\" \"")
346 (princ (or title
347 (if (string-match "[:\e$A!K\e$(0!(!J\e(B]+\\([^:\e$A!K\e$(0!(!K\e(B]+\\)" tit-prompt)
348 (substring tit-prompt (match-beginning 1) (match-end 1))
349 tit-prompt)))
350 (princ "\"\n"))
4ed46869
KH
351
352 ;; Arg GUIDANCE
353 (if tit-keyprompt
354 (progn
1375754c 355 (princ " '(")
4ed46869 356 (while tit-keyprompt
1375754c
KH
357 (princ " ")
358 (princ (format "(%d . \"%s\")\n"
359 (string-to-char (car (car tit-keyprompt)))
360 (cdr (car tit-keyprompt))))
4ed46869 361 (setq tit-keyprompt (cdr tit-keyprompt)))
1375754c
KH
362 (princ ")"))
363 (princ " t\n"))
4ed46869
KH
364
365 ;; Arg DOCSTRING
6b1e079c
KH
366 (let ((doc (concat tit-prompt "\n"))
367 (comments (if tit-comments
368 (mapconcat 'identity (nreverse tit-comments) "\n")))
369 (doc-ext (nth 2 (assoc package quail-cxterm-package-ext-info))))
370 (if comments
371 (setq doc (concat doc "\n" comments "\n")))
372 (if doc-ext
373 (setq doc (concat doc "\n" doc-ext "\n")))
374 (prin1 doc)
375 (terpri))
4ed46869
KH
376
377 ;; Arg KEY-BINDINGS
1375754c 378 (princ " '(")
4ed46869 379 (tit-generate-key-bindings tit-backspace 'quail-delete-last-char)
1375754c 380 (princ "\n ")
4ed46869 381 (tit-generate-key-bindings tit-deleteall 'quail-abort-translation)
1375754c 382 (princ "\n ")
4ed46869 383 (tit-generate-key-bindings tit-moveright 'quail-next-translation)
1375754c 384 (princ "\n ")
4ed46869 385 (tit-generate-key-bindings tit-moveleft 'quail-prev-translation)
1375754c 386 (princ ")\n")
4ed46869
KH
387
388 ;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT.
389 ;; The remaining args are all nil.
1375754c
KH
390 (princ " nil")
391 (princ (if tit-multichoice " nil" " t"))
392 (princ (if tit-keyprompt " t t)\n\n" " nil nil)\n\n"))))
393
394(defsubst tit-flush-translations (key translations)
395 (if (string-match "\\\\[0-9][0-9][0-9]" key)
396 (let ((newkey (concat (substring key 0 (match-beginning 0))
397 (car (read-from-string
398 (concat "\"" (match-string 0 key) "\"")))))
399 (idx (match-end 0)))
400 (while (string-match "\\\\[0-9][0-9][0-9]" key idx)
401 (setq newkey (concat
402 newkey
403 (substring key idx (match-beginning 0))
404 (car (read-from-string
405 (concat "\"" (match-string 0 key) "\"")))))
406 (setq idx (match-end 0)))
407 (setq key (concat newkey (substring key idx)))))
408 (prin1 (list key (if tit-dictionary translations
409 (vconcat (nreverse translations)))))
410 (princ "\n"))
4ed46869
KH
411
412;; Convert body part of TIT dictionary into `quail-define-rules'
413;; function call.
414(defun tit-process-body ()
415 (message "Formatting translation rules...")
1375754c
KH
416 (let* ((template (list nil nil))
417 (second (cdr template))
418 (prev-key "")
419 ch key translations pos)
420 (princ "(quail-define-rules\n")
4ed46869 421 (while (null (eobp))
1375754c
KH
422 (setq ch (following-char))
423 (if (or (= ch ?#) (= ch ?\n))
424 (forward-line 1)
4ed46869 425 (setq pos (point))
1375754c
KH
426 (skip-chars-forward "^ \t\n")
427 (setq key (buffer-substring pos (point)))
4ed46869 428 (skip-chars-forward " \t")
1375754c
KH
429 (setq ch (following-char))
430 (if (or (= ch ?#) (= ch ?\n))
08a1bf22 431 ;; This entry contains no translations. Let's ignore it.
1375754c
KH
432 (forward-line 1)
433 (or (string= key prev-key)
08a1bf22 434 (progn
1375754c
KH
435 (if translations
436 (tit-flush-translations prev-key translations))
437 (setq translations nil
438 prev-key key)))
439 (if tit-dictionary
440 (progn
441 (setq pos (point))
442 (skip-chars-forward "^ \t#\n")
443 (setq translations
444 (if translations
445 (concat translations
446 (buffer-substring pos (point)))
447 (buffer-substring pos (point)))))
448 (while (not (eolp))
449 (setq pos (point))
450 (skip-chars-forward "^ \t\n")
451 (setq translations (cons (buffer-substring pos (point))
452 translations))
453 (skip-chars-forward " \t")
454 (setq ch (following-char))
455 (if (= ch ?#) (end-of-line))))
08a1bf22 456 (forward-line 1))))
1375754c
KH
457
458 (if translations
459 (tit-flush-translations prev-key translations))
460 (princ ")\n")))
4ed46869
KH
461
462;;;###autoload
463(defun titdic-convert (filename &optional dirname)
464 "Convert a TIT dictionary of FILENAME into a Quail package.
465Optional argument DIRNAME if specified is the directory name under which
466the generated Quail package is saved."
467 (interactive "FTIT dictionary file: ")
c7211fed
DL
468 (let ((coding-system-for-write 'iso-2022-7bit))
469 (with-temp-file (tit-make-quail-package-file-name filename dirname)
470 (set-buffer-file-coding-system 'iso-2022-7bit)
471 (let ((standard-output (current-buffer)))
472 (with-temp-buffer
473 (set-buffer-multibyte nil)
474 (let ((coding-system-for-read 'no-conversion))
475 (insert-file-contents (expand-file-name filename)))
1375754c 476
c7211fed
DL
477 ;; Decode the buffer contents from the encoding specified by a
478 ;; value of the key "ENCODE:".
479 (if (not (search-forward "\nBEGIN" nil t))
480 (error "TIT dictionary doesn't have body part"))
481 (let ((limit (point))
482 coding-system slot)
483 (goto-char (point-min))
484 (if (re-search-forward "^ENCODE:[ \t]*" limit t)
485 (progn
486 (goto-char (match-end 0))
487 (setq tit-encode (tit-read-key-value)))
488 (setq tit-encode tit-default-encode))
489 (setq slot (assoc tit-encode tit-encode-list))
490 (if (not slot)
491 (error "Invalid ENCODE: value in TIT dictionary"))
492 (setq coding-system (nth 1 slot))
493 (message "Decoding with coding system %s..." coding-system)
494 (goto-char (point-min))
495 (decode-coding-region (point-min) (point-max) coding-system))
496
497 ;; Set point the starting position of the body part.
1375754c 498 (goto-char (point-min))
c7211fed
DL
499 (if (not (search-forward "\nBEGIN" nil t))
500 (error "TIT dictionary can't be decoded correctly"))
501
502 ;; Process the header part.
503 (forward-line 1)
504 (narrow-to-region (point-min) (point))
505 (tit-process-header filename)
506 (widen)
507
508 ;; Process the body part. For speed, we turn off multibyte facility.
509 (with-current-buffer standard-output
510 (set-buffer-multibyte nil))
511 (set-buffer-multibyte nil)
512 (tit-process-body))))))
4ed46869
KH
513
514;;;###autoload
44cbfae9 515(defun batch-titdic-convert (&optional force)
4ed46869
KH
516 "Run `titdic-convert' on the files remaining on the command line.
517Use this from the command line, with `-batch';
518it won't work in an interactive Emacs.
519For example, invoke \"emacs -batch -f batch-titdic-convert XXX.tit\" to
520 generate Quail package file \"xxx.el\" from TIT dictionary file \"XXX.tit\".
521To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"."
522 (defvar command-line-args-left) ; Avoid compiler warning.
523 (if (not noninteractive)
524 (error "`batch-titdic-convert' should be used only with -batch"))
525 (if (string= (car command-line-args-left) "-h")
526 (progn
527 (message "To convert XXX.tit and YYY.tit into xxx.el and yyy.el:")
528 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert XXX.tit YYY.tit")
529 (message "To convert XXX.tit into DIR/xxx.el:")
530 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert -dir DIR XXX.tit"))
531 (let (targetdir filename files file)
532 (if (string= (car command-line-args-left) "-dir")
533 (progn
534 (setq command-line-args-left (cdr command-line-args-left))
535 (setq targetdir (car command-line-args-left))
536 (setq command-line-args-left (cdr command-line-args-left))))
537 (while command-line-args-left
538 (setq filename (expand-file-name (car command-line-args-left)))
539 (if (file-directory-p filename)
540 (progn
541 (message "Converting all tit files in the directory %s" filename)
542 (setq files (directory-files filename t "\\.tit$")))
543 (setq files (list filename)))
544 (while files
545 (setq file (expand-file-name (car files)))
44cbfae9
KH
546 (when (or force
547 (file-newer-than-file-p
548 file (tit-make-quail-package-file-name file targetdir)))
549 (message "Converting %s to quail-package..." file)
550 (titdic-convert file targetdir))
4ed46869
KH
551 (setq files (cdr files)))
552 (setq command-line-args-left (cdr command-line-args-left)))
86e4f7c0 553 (message "Byte-compile the created files by:")
4ed46869
KH
554 (message " %% emacs -batch -f batch-byte-compile XXX.el")))
555 (kill-emacs 0))
556
c063e381
KH
557\f
558;;; Converter of miscellaneous dictionaries other than TIT format.
559
560;; Alist of input method names and the corresponding information.
561;; Each element has this form:
562;; (INPUT-METHOD-NAME ;; Name of the input method.
563;; INPUT-METHOD-TITLE ;; Title string of the input method
564;; DICFILE ;; Name of the source dictionary file.
565;; CODING ;; Coding system of the dictionary file.
566;; QUAILFILE ;; Name of the Quail package file.
567;; CONVERTER ;; Function to generate the Quail package.
568;; COPYRIGHT-NOTICE ;; Copyright notice of the source dictionary.
569;; )
570
571(defvar quail-misc-package-ext-info
572 '(("chinese-b5-tsangchi" "\e$(06A\e(BB"
573 "cangjie-table.b5" big5 "tsang-b5.el"
574 tsang-b5-converter
575 "\
576;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
577;; #
578;; # Permission to copy and distribute both modified and
579;; # unmodified versions is granted without royalty provided
580;; # this notice is preserved.")
581
582 ("chinese-b5-quick" "\e$(0X|\e(BB"
583 "cangjie-table.b5" big5 "quick-b5.el"
584 quick-b5-converter
585 "\
586;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
587;; #
588;; # Permission to copy and distribute both modified and
589;; # unmodified versions is granted without royalty provided
590;; # this notice is preserved.")
591
592 ("chinese-cns-tsangchi" "\e$(GT?\e(BC"
593 "cangjie-table.cns" iso-2022-cn-ext "tsang-cns.el"
594 tsang-cns-converter
595 "\
596;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
597;; #
598;; # Permission to copy and distribute both modified and
599;; # unmodified versions is granted without royalty provided
600;; # this notice is preserved.")
601
602 ("chinese-cns-quick" "\e$(Gv|\e(BC"
603 "cangjie-table.cns" iso-2022-cn-ext "quick-cns.el"
604 quick-cns-converter
605 "\
606;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
607;; #
608;; # Permission to copy and distribute both modified and
609;; # unmodified versions is granted without royalty provided
610;; # this notice is preserved.")
611
612 ("chinese-py" "\e$AF4\e(BG"
613 "pinyin.map" cn-gb-2312 "PY.el"
614 py-converter
615 "\
616;; \"pinyin.map\" is included in a free package called CCE. It is
617;; available at:
618;; http://ftp.debian.org/debian/dists/potato/main
619;; /source/utils/cce_0.36.orig.tar.gz
620;; This package contains the following copyright notice.
621;;
622;;
623;; Copyright (C) 1999, Rui He, herui@cs.duke.edu
624;;
625;;
626;; CCE(Console Chinese Environment) 0.32
627;;
628;; CCE is free software; you can redistribute it and/or modify it under the
629;; terms of the GNU General Public License as published by the Free Software
630;; Foundation; either version 1, or (at your option) any later version.
631;;
632;; CCE is distributed in the hope that it will be useful, but WITHOUT ANY
633;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
634;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
635;; details.
636;;
637;; You should have received a copy of the GNU General Public License along with
638;; CCE; see the file COPYING. If not, write to the Free Software Foundation,
639;; 675 Mass Ave, Cambridge, MA 02139, USA.")
640
641 ("chinese-ziranma" "\e$AWTH;\e(B"
642 "ziranma.cin" cn-gb-2312 "ZIRANMA.el"
643 ziranma-converter
644 "\
645;; \"ziranma.cin\" is included in a free package called CCE. It is
646;; available at:
647;; http://ftp.debian.org/debian/dists/potato/main
648;; /source/utils/cce_0.36.orig.tar.gz
649;; This package contains the following copyright notice.
650;;
651;;
652;; Copyright (C) 1999, Rui He, herui@cs.duke.edu
653;;
654;;
655;; CCE(Console Chinese Environment) 0.32
656;;
657;; CCE is free software; you can redistribute it and/or modify it under the
658;; terms of the GNU General Public License as published by the Free Software
659;; Foundation; either version 1, or (at your option) any later version.
660;;
661;; CCE is distributed in the hope that it will be useful, but WITHOUT ANY
662;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
663;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
664;; details.
665;;
666;; You should have received a copy of the GNU General Public License along with
667;; CCE; see the file COPYING. If not, write to the Free Software Foundation,
668;; 675 Mass Ave, Cambridge, MA 02139, USA.")
a4c4011b 669
a4c4011b
AC
670 ("chinese-ctlau" "\e$AAuTA\e(B"
671 "CTLau.html" cn-gb-2312 "CTLau.el"
672 ctlau-gb-converter
673 "\
674;; \"CTLau.html\" is available at:
675;;
676;; http://umunhum.stanford.edu/~lee/chicomp/CTLau.html
677;;
678;; It contains the following copyright notice:
679;;
680;; # Copyright (C) 1988-2001 Fung Fung Lee (lee@umunhum.stanford.edu)
681;; #
682;; # This program is free software; you can redistribute it and/or
683;; # modify it under the terms of the GNU General Public License
684;; # as published by the Free Software Foundation; either version 2
685;; # of the License, or any later version.
686;; #
687;; # This program is distributed in the hope that it will be useful,
688;; # but WITHOUT ANY WARRANTY; without even the implied warranty of
689;; # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
690;; # GNU General Public License for more details.
691;; #
692;; # You should have received a copy of the GNU General Public License
693;; # along with this program; if not, write to the Free Software Foundation,
694;; # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.")
695
e089be2d 696 ("chinese-ctlaub" "\e$(0N,Gn\e(B"
2bef0948 697 "CTLau-b5.html" big5 "CTLau-b5.el"
a4c4011b
AC
698 ctlau-b5-converter
699 "\
700;; \"CTLau-b5.html\" is available at:
701;;
702;; http://umunhum.stanford.edu/~lee/chicomp/CTLau-b5.html
703;;
704;; It contains the following copyright notice:
705;;
706;; # Copyright (C) 1988-2001 Fung Fung Lee (lee@umunhum.stanford.edu)
707;; #
708;; # This program is free software; you can redistribute it and/or
709;; # modify it under the terms of the GNU General Public License
710;; # as published by the Free Software Foundation; either version 2
711;; # of the License, or any later version.
712;; #
713;; # This program is distributed in the hope that it will be useful,
714;; # but WITHOUT ANY WARRANTY; without even the implied warranty of
715;; # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
716;; # GNU General Public License for more details.
717;; #
718;; # You should have received a copy of the GNU General Public License
719;; # along with this program; if not, write to the Free Software Foundation,
720;; # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.")
c063e381
KH
721 ))
722
723;; Generate a code of a Quail package in the current buffer from Tsang
724;; dictionary in the buffer DICBUF. The input method name of the
725;; Quail package is NAME, and the title string is TITLE.
726
727;; TSANG-P is non-nil, genereate \e$(06AQo\e(B input method. Otherwise
728;; generate \e$(0X|/y\e(B (simple version of \e$(06AQo\e(B). If BIG5-P is non-nil, the
729;; input method is for inputting Big5 characters. Otherwise the input
730;; method is for inputting CNS characters.
731
732(defun tsang-quick-converter (dicbuf name title tsang-p big5-p)
733 (let ((fulltitle (if tsang-p (if big5-p "\e$(06AQo\e(B" "\e$(GT?on\e(B")
734 (if big5-p "\e$(0X|/y\e(B" "\e$(Gv|Mx\e(B")))
735 dic)
736 (goto-char (point-max))
737 (if big5-p
738 (insert (format "\"\e$(0&d'GTT&,!J\e(B%s\e$(0!K\e(BBIG5
739
740 \e$(0KHM$\e(B%s\e$(0TT&,WoOu\e(B
741
742 [Q \e$(0'D\e(B] [W \e$(0(q\e(B] [E \e$(0'V\e(B] [R \e$(0&H\e(B] [T \e$(0'>\e(B] [Y \e$(0&4\e(B] [U \e$(0&U\e(B] [I \e$(0'B\e(B] [O \e$(0&*\e(B] [P \e$(0'A\e(B]
743
744 [A \e$(0'K\e(B] [S \e$(0&T\e(B] [D \e$(0'N\e(B] [F \e$(0'W\e(B] [G \e$(0&I\e(B] [H \e$(0*M\e(B] [J \e$(0&3\e(B] [L \e$(0&d\e(B]
745
746 [Z ] [X \e$(0[E\e(B] [C \e$(01[\e(B] [V \e$(0&M\e(B] [B \e$(0'M\e(B] [N \e$(0&_\e(B] [M \e$(0&"\e(B]
747
748\\\\<quail-translation-docstring>\"\n"
749 fulltitle fulltitle))
750 (insert (format "\"\e$(GDcEFrSD+!J\e(B%s\e$(G!K\e(BCNS
751
752 \e$(GiGk#\e(B%s\e$(GrSD+uomu\e(B
753
754 [Q \e$(GEC\e(B] [W \e$(GFp\e(B] [E \e$(GEU\e(B] [R \e$(GDG\e(B] [T \e$(GE=\e(B] [Y \e$(GD3\e(B] [U \e$(GDT\e(B] [I \e$(GEA\e(B] [O \e$(GD)\e(B] [P \e$(GE@\e(B]
755
756 [A \e$(GEJ\e(B] [S \e$(GDS\e(B] [D \e$(GEM\e(B] [F \e$(GEV\e(B] [G \e$(GDH\e(B] [H \e$(GHL\e(B] [J \e$(GD2\e(B] [L \e$(GDc\e(B]
757
758 [Z ] [X \e$(GyE\e(B] [C \e$(GOZ\e(B] [V \e$(GDL\e(B] [B \e$(GEL\e(B] [N \e$(GD^\e(B] [M \e$(GD!\e(B]
759
760\\\\<quail-translation-docstring>\"\n"
761 fulltitle fulltitle)))
762 (insert " '((\".\" . quail-next-translation-block)
763 (\",\" . quail-prev-translation-block))
764 nil nil)\n\n")
765 (insert "(quail-define-rules\n")
766 (save-excursion
767 (set-buffer dicbuf)
768 (goto-char (point-min))
769 (search-forward "A440")
770 (beginning-of-line)
771 (let ((table (make-hash-table :test 'equal))
772 val)
773 (while (not (eobp))
774 (forward-char 5)
775 (let ((trans (char-to-string (following-char)))
776 key slot)
777 (re-search-forward "[A-Z]+$" nil t)
778 (setq key (downcase
779 (if (or tsang-p
780 (<= (- (match-end 0) (match-beginning 0)) 1))
781 (match-string 0)
782 (string (char-after (match-beginning 0))
783 (char-after (1- (match-end 0)))))))
784 (setq val (gethash key table))
785 (if val (setq trans (concat val trans)))
786 (puthash key trans table)
787 (forward-line 1)))
788 (maphash #'(lambda (key val) (setq dic (cons (cons key val) dic)))
789 table)))
790 (setq dic (sort dic (function (lambda (x y) (string< (car x ) (car y))))))
791 (dolist (elt dic)
792 (insert (format "(%S\t%S)\n" (car elt) (cdr elt))))
793 (let ((punctuations '((";" "\e$(0!'!2!"!#!.!/\e(B" "\e$(G!'!2!"!#!.!/\e(B")
794 (":" "\e$(0!(!+!3!%!$!&!0!1\e(B" "\e$(G!(!+!3!%!$!&!0!1\e(B")
795 ("'" "\e$(0!e!d\e(B" "\e$(G!e!d\e(B")
796 ("\"" "\e$(0!g!f!h!i!q\e(B" "\e$(G!g!f!h!i!q\e(B")
797 ("\\" "\e$(0"`"b#M\e(B" "\e$(G"`"b#M\e(B")
798 ("|" "\e$(0!6!8!:"^\e(B" "\e$(G!6!8!:"^\e(B")
799 ("/" "\e$(0"_"a#L\e(B" "\e$(G"_"a#L\e(B")
800 ("?" "\e$(0!)!4\e(B" "\e$(G!)!4\e(B")
801 ("<" "\e$(0!R"6"A!T"H\e(B" "\e$(G!R"6"A!T"H\e(B")
802 (">" "\e$(0!S"7"B!U\e(B" "\e$(G!S"7"B!U\e(B")
803 ("[" "\e$(0!F!J!b!H!L!V!Z!X!\\e(B" "\e$(G!F!J!b!H!L!V!Z!X!\\e(B")
804 ("]" "\e$(0!G!K!c!I!M!W![!Y!]\e(B" "\e$(G!G!K!c!I!M!W![!Y!]\e(B")
805 ("{" "\e$(0!B!`!D\e(B " "\e$(G!B!`!D\e(B ")
806 ("}" "\e$(0!C!a!E\e(B" "\e$(G!C!a!E\e(B")
807 ("`" "\e$(0!j!k\e(B" "\e$(G!j!k\e(B")
808 ("~" "\e$(0"D"+",!<!=\e(B" "\e$(G"D"+",!<!=\e(B")
809 ("!" "\e$(0!*!5\e(B" "\e$(G!*!5\e(B")
810 ("@" "\e$(0"i"n\e(B" "\e$(G"i"n\e(B")
811 ("#" "\e$(0!l"-\e(B" "\e$(G!l"-\e(B")
812 ("$" "\e$(0"c"l\e(B" "\e$(G"c"l\e(B")
813 ("%" "\e$(0"h"m\e(B" "\e$(G"h"m\e(B")
814 ("&" "\e$(0!m".\e(B" "\e$(G!m".\e(B")
815 ("*" "\e$(0!n"/!o!w!x\e(B" "\e$(G!n"/!o!w!x\e(B")
816 ("(" "\e$(0!>!^!@\e(B" "\e$(G!>!^!@\e(B")
817 (")" "\e$(0!?!_!A\e(B" "\e$(G!?!_!A\e(B")
818 ("-" "\e$(0!7!9"#"$"1"@\e(B" "\e$(G!7!9"#"$"1"@\e(B")
819 ("_" "\e$(0"%"&\e(B" "\e$(G"%"&\e(B")
820 ("=" "\e$(0"8"C\e(B" "\e$(G"8"C\e(B")
821 ("+" "\e$(0"0"?\e(B" "\e$(G"0"?\e(B"))))
822 (dolist (elt punctuations)
823 (insert (format "(%S %S)\n" (concat "z" (car elt))
824 (if big5-p (nth 1 elt) (nth 2 elt))))))
825 (insert ")\n")))
826
827(defun tsang-b5-converter (dicbuf name title)
828 (tsang-quick-converter dicbuf name title t t))
829
830(defun quick-b5-converter (dicbuf name title)
831 (tsang-quick-converter dicbuf name title nil t))
832
833(defun tsang-cns-converter (dicbuf name title)
834 (tsang-quick-converter dicbuf name title t nil))
835
836(defun quick-cns-converter (dicbuf name title)
837 (tsang-quick-converter dicbuf name title nil nil))
838
839;; Generate a code of a Quail package in the current buffer from
840;; Pinyin dictionary in the buffer DICBUF. The input method name of
841;; the Quail package is NAME, and the title string is TITLE.
842
843(defun py-converter (dicbuf name title)
844 (goto-char (point-max))
845 (insert (format "%S\n" "\e$A::WVJdHk!KF4Rt!K\e(B
846
847 \e$AF4Rt7=08\e(B
848
849 \e$AP!P4S"NDWVD84z1m!8F4Rt!97{:E#,\e(B \"u(yu) \e$ATrSC\e(B u: \e$A1mJ>!C\e(B
850
851Pinyin base input method for Chinese charset GB2312 (`chinese-gb2312').
852
853Pinyin is the standared roman transliteration method for Chinese.
854Pinyin uses a sequence of Latin alphabetic characters for each Chinese
855character. The sequence is made by the combination of the initials
856\(the beginning sounds) and finals (the ending sounds).
857
858 initials: b p m f d t n l z c s zh ch sh r j q x g k h
859 finals: a o e i er ai ei oa ou an en ang eng ong i ia iao ie iu ian in
860 iang ing iong u ua uo uai ui uan un uan ueng yu yue yuan yun
861
862 (Note: In the correct Pinyin writing, the sequence \"yu\" in the last
863 four finals should be written by the character u-umlaut `\e$A(9\e(B'.)
864
865With this input method, you enter a Chinese character by first
866entering its pinyin spelling.
867
868\\<quail-translation-docstring>
869
870For instance, to input \e$ADc\e(B, you type \"n i C-n 3\". The first \"n i\"
871is a Pinyin, \"C-n\" selects the next group of candidates (each group
872contains at most 10 characters), \"3\" select the third character in
873that group.
874
875This input method supports only Han characters. The related input
876method `chinese-py-punct' is the combination of this method and
877`chinese-punct'; it supports both Han characters and punctuation
878characters.
879
880For double-width GB2312 characters corresponding to ASCII, use the
881input method `chinese-qj'.
882
883The correct Pinyin system specifies tones by diacritical marks, but
884this input method doesn't use them, which results in easy (you don't
885have to know the exact tones), but verbose (many characters are assigned
886to the same key sequence) input. You may also want to try the input
887method `chinese-tonepy' with which you must specify tones by digits
888\(1..5)."))
889 (insert " '((\"\C-?\" . quail-delete-last-char)
890 (\".\" . quail-next-translation)
891 (\">\" . quail-next-translation)
892 (\",\" . quail-prev-translation)
893 (\"<\" . quail-prev-translation))
894 nil nil nil nil)\n\n")
895 (insert "(quail-define-rules\n")
896 (let ((pos (point)))
897 (insert-buffer-substring dicbuf)
898 (goto-char pos)
899 (while (not (eobp))
900 (insert "(\"")
901 (skip-chars-forward "a-z")
902 (insert "\" \"")
903 (delete-char 1)
904 (end-of-line)
905 (insert "\")")
906 (forward-line 1)))
907 (insert ")\n"))
908
909;; Generate a code of a Quail package in the current buffer from
910;; Ziranma dictionary in the buffer DICBUF. The input method name of
911;; the Quail package is NAME, and the title string is TITLE.
912
913(defun ziranma-converter (dicbuf name title)
914 (let (dic)
915 (save-excursion
916 (set-buffer dicbuf)
917 (goto-char (point-min))
918 (search-forward "%keyname end\n")
919 (let ((table (make-hash-table :test 'equal))
920 elt pos key trans val)
921 (while (not (eobp))
922 (setq pos (point))
923 (skip-chars-forward "^ \t")
924 (setq key (buffer-substring pos (point)))
925 (skip-chars-forward " \t")
926 (setq trans (vector (buffer-substring (point) (line-end-position))))
927 (setq val (gethash key table))
928 (if val (setq trans (vconcat val trans)))
929 (puthash key trans table)
930 (forward-line 1))
931 (maphash #'(lambda (key trans)
932 (let ((len (length trans))
933 i)
934 (if (and (= len 1) (= (length (aref trans 0)) 1))
935 (setq trans (aref trans 0))
936 (setq i 0)
937 (while (and (< i len)
938 (= (length (aref trans i)) 1))
939 (setq i (1+ i)))
940 (if (= i len)
941 (setq trans (mapconcat 'identity trans "")))))
942 (setq dic (cons (cons key trans) dic)))
943 table)))
944 (setq dic (sort dic (function (lambda (x y) (string< (car x) (car y))))))
945 (goto-char (point-max))
946 (insert (format "%S\n" "\e$A::WVJdHk!K!>WTH;!?!K\e(B
947
948 \e$A<|EL6TUU1m\e(B:
949 \e$A)3)%)%)W)%)%)W)%)%)W)%)%)W)%)%)W)%)%)W)%)%)W)%)%)W)%)%)W)%)%)7\e(B
950 \e$A)'#Q\e(B \e$A)'#W\e(B \e$A)'#E\e(B \e$A)'#R\e(B \e$A)'#T\e(B \e$A)'#Y\e(B \e$A)'#U\e(Bsh\e$A)'#I\e(Bch\e$A)'#O\e(B \e$A)'#P\e(B \e$A)'\e(B
951 \e$A)'\e(B iu\e$A)'\e(B ua\e$A)'\e(B e\e$A)'\e(B uan\e$A)'\e(B ue\e$A)'\e(B uai\e$A)'\e(B u\e$A)'\e(B i\e$A)'\e(B o\e$A)'\e(B un\e$A)'\e(B
952 \e$A)'\e(B \e$A)'\e(B ia\e$A)'\e(B \e$A)'\e(B van\e$A)'\e(B ve\e$A)'\e(B ing\e$A)'\e(B \e$A)'\e(B \e$A)'\e(B uo\e$A)'\e(B vn\e$A)'\e(B
953 \e$A);)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)?\e(B
954 \e$A)'#A\e(B \e$A)'#S\e(B \e$A)'#D\e(B \e$A)'#F\e(B \e$A)'#G\e(B \e$A)'#H\e(B \e$A)'#J\e(B \e$A)'#K\e(B \e$A)'#L\e(B \e$A)'\e(B
955 \e$A)'\e(B a\e$A)'\e(Biong\e$A)'\e(Buang\e$A)'\e(B en\e$A)'\e(B eng\e$A)'\e(B ang\e$A)'\e(B an\e$A)'\e(B ao\e$A)'\e(B ai\e$A)'\e(B
956 \e$A)'\e(B \e$A)'\e(B ong\e$A)'\e(Biang\e$A)'\e(B \e$A)'\e(B ng\e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B
957 \e$A);)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)_)W)%)%)7\e(B
958 \e$A)'#Z\e(B \e$A)'#X\e(B \e$A)'#C\e(B \e$A)'#V\e(Bzh\e$A)'#B\e(B \e$A)'#N\e(B \e$A)'#M\e(B \e$A)'#,\e(B \e$A)'#.\e(B \e$A)'\e(B \e$A#/\e(B \e$A)'\e(B
959 \e$A)'\e(B ei\e$A)'\e(B ie\e$A)'\e(B iao\e$A)'\e(B ui\e$A)'\e(B ou\e$A)'\e(B in\e$A)'\e(B ian\e$A)'G0R3)':sR3)'7{:E)'\e(B
960 \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B v\e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B \e$A)'\e(B
961 \e$A);)%)%)_)%)%)_)%)%)_)%)%)_)%)%)_)%)%)_)%)%)_)%)%)_)%)%)_)%)%)?\e(B
962
963
964Pinyin base input method for Chinese GB2312 characters (`chinese-gb2312').
965
966Pinyin is the standard roman transliteration method for Chinese.
967For the details of Pinyin system, see the documentation of the input
968method `chinese-py'.
969
970Unlike the standard spelling of Pinyin, in this input method all
971initials and finals are assigned to single keys (see the above table).
972For instance, the initial \"ch\" is assigned to the key `i', the final
973\"iu\" is assigned to the key `q', and tones 1, 2, 3, 4, and \e$AGaIy\e(B are
974assigned to the keys `q', `w', `e', `r', `t' respectively.
975
976\\<quail-translation-docstring>
977
978To input one-letter words, you type 4 keys, the first two for the
979Pinyin of the letter, next one for tone, and the last one is always a
980quote ('). For instance, \"vsq'\" input \e$AVP\e(B. Exceptions are these
981letters. You can input them just by typing a single key.
982
983 Character: \e$A04\e(B \e$A2;\e(B \e$A4N\e(B \e$A5D\e(B \e$A6~\e(B \e$A7"\e(B \e$A8v\e(B \e$A:M\e(B \e$A3v\e(B \e$A<0\e(B \e$A?I\e(B \e$AAK\e(B \e$AC;\e(B
984 Key: a b c d e f g h i j k l m
985 Character: \e$ADc\e(B \e$AE7\e(B \e$AF,\e(B \e$AF_\e(B \e$AHK\e(B \e$AH}\e(B \e$AK{\e(B \e$AJG\e(B \e$AWE\e(B \e$ANR\e(B \e$AP!\e(B \e$AR;\e(B \e$ATZ\e(B
986 Key: n o p q r s t u v w x y z
987
988To input two-letter words, you have two ways. One way is to type 4
989keys, two for the first Pinyin, two for the second Pinyin. For
990instance, \"vsgo\" inputs \e$AVP9z\e(B. Another way is to type 3 keys: 2
991initials of two letters, and quote ('). For instance, \"vg'\" also
992inputs \e$AVP9z\e(B.
993
994To input three-letter words, you type 4 keys: initials of three
995letters, and the last is quote ('). For instance, \"bjy'2\" inputs \e$A11\e(B
996\e$A>)Q<\e(B (the last `2' is to select one of the candidates).
997
998To input words of more than three letters, you type 4 keys, initials
999of the first three letters and the last letter. For instance,
1000\"bjdt\" inputs \e$A11>)5gJSL(\e(B.
1001
1002To input symbols and punctuations, type `/' followed by one of `a' to
1003`z', then select one of the candidates."))
1004 (insert " '((\"\C-?\" . quail-delete-last-char)
1005 (\".\" . quail-next-translation)
1006 (\"[\" . quail-next-translation)
1007 (\",\" . quail-prev-translation)
1008 (\"]\" . quail-prev-translation))
1009 nil nil nil nil)\n\n")
1010 (insert "(quail-define-rules\n")
1011 (dolist (elt dic)
1012 (insert (format "(%S %S)\n" (car elt) (cdr elt))))
1013 (insert ")\n")))
1014
a4c4011b
AC
1015;; Generate the code for a Quail package in the current buffer from a
1016;; CTLau or CTLau-b5 dictionary in the buffer DICBUF. The input
1017;; method name of the Quail package is NAME, and the title string is
1018;; TITLE. DESCRIPTION is the string shown by describe-input-method.
1019
1020(defun ctlau-converter (dicbuf name title description)
1021 (goto-char (point-max))
1022 (insert (format "%S\n" description))
1023 (insert " '((\"\C-?\" . quail-delete-last-char)
1024 (\".\" . quail-next-translation)
1025 (\">\" . quail-next-translation)
1026 (\",\" . quail-prev-translation)
1027 (\"<\" . quail-prev-translation))
1028 nil nil nil nil)\n\n")
1029 (insert "(quail-define-rules\n")
1030 (let (dicbuf-start dicbuf-end key-start key (pos (point)))
1031 ;; Find the dictionary, which starts below a horizontal rule and
1032 ;; ends at the second to last line in the HTML file.
1033 (save-excursion
1034 (set-buffer dicbuf)
1035 (goto-char (point-min))
1036 (search-forward "#\n#<hr>\n")
1037 (setq dicbuf-start (point))
1038 (goto-char (point-max))
1039 (forward-line -1)
1040 (setq dicbuf-end (point)))
1041 (insert-buffer-substring dicbuf dicbuf-start dicbuf-end)
1042 ;; CTLau-b5.html contains characters (0xa1 0xbc) which show up as
1043 ;; hollow boxes when the original characters in CTLau.html from
1044 ;; which the file is converted have no Big5 equivalent. Go
1045 ;; through and delete them.
1046 (goto-char pos)
1047 (while (search-forward "\e$(0!{\e(B" nil t)
1048 (delete-char -1))
1049 ;; Uppercase keys in dictionary need to be downcased. Backslashes
1050 ;; at the beginning of keys need to be turned into double
1051 ;; backslashes.
1052 (goto-char pos)
1053 (while (not (eobp))
1054 (insert "(\"")
1055 (if (char-equal (following-char) ?\\)
1056 (insert "\\"))
1057 (setq key-start (point))
1058 (skip-chars-forward "\\\\A-Z")
1059 (downcase-region key-start (point))
1060 (insert "\" \"")
1061 (delete-char 1)
1062 (end-of-line)
1063 (insert "\")")
1064 (forward-line 1)))
1065 (insert ")\n"))
1066
1067(defun ctlau-gb-converter (dicbuf name title)
1068 (ctlau-converter dicbuf name title
1069"\e$A::WVJdHk!KAuN}OiJ=TARt!K\e(B
1070
1071 \e$AAuN}OiJ=TASoW"Rt7=08\e(B
1072 Sidney Lau's Cantonese transcription scheme as described in his book
1073 \"Elementary Cantonese\", The Government Printer, Hong Kong, 1972.
1074 This file was prepared by Fung Fung Lee (\e$A@n7c7e\e(B).
1075 Originally converted from CTCPS3.tit
1076 Last modified: June 2, 1993.
1077
4e7e1f03 1078 Some infrequent GB characters are accessed by typing \\, followed by
a4c4011b
AC
1079 the Cantonese romanization of the respective radical (\e$A2?JW\e(B)."))
1080
1081(defun ctlau-b5-converter (dicbuf name title)
1082 (ctlau-converter dicbuf name title
1083"\e$(0KH)tTT&,!(N,Tg>A*#Gn5x!(\e(B
1084
1085 \e$(0N,Tg>A*#GnM$0D5x'J7{\e(B
1086 Sidney Lau's Cantonese transcription scheme as described in his book
1087 \"Elementary Cantonese\", The Government Printer, Hong Kong, 1972.
1088 This file was prepared by Fung Fung Lee (\e$(0,XFS76\e(B).
1089 Originally converted from CTCPS3.tit
1090 Last modified: June 2, 1993.
1091
4e7e1f03 1092 Some infrequent characters are accessed by typing \\, followed by
a4c4011b
AC
1093 the Cantonese romanization of the respective radical (\e$(0?f5}\e(B)."))
1094
c063e381
KH
1095(defun miscdic-convert (filename &optional dirname)
1096 "Convert a dictionary file FILENAME into a Quail package.
1097Optional argument DIRNAME if specified is the directory name under which
1098the generated Quail package is saved."
1099 (interactive "FInput method dictionary file: ")
1100 (or (file-readable-p filename)
1101 (error "%s does not exist" filename))
1102 (let ((tail quail-misc-package-ext-info)
1103 (default-buffer-file-coding-system 'iso-2022-7bit)
1104 slot
1105 name title dicfile coding quailfile converter copyright
1106 dicbuf)
1107 (while tail
f3d78a1c
EZ
1108 (when (or (string-match (nth 2 (car tail)) filename)
1109 ;; MS-DOS filesystem truncates file names to 8+3
1110 ;; limits, so "cangjie-table.cns" becomes
1111 ;; "cangjie-.cns", and the above string-match fails.
1112 ;; Give DOS users a chance...
1113 (and (fboundp 'msdos-long-file-names)
1114 (not (msdos-long-file-names))
51f32106 1115 (string-match (dos-8+3-filename (nth 2 (car tail)))
f3d78a1c 1116 filename)))
c063e381
KH
1117 (setq slot (car tail)
1118 name (car slot)
1119 title (nth 1 slot)
1120 dicfile (nth 2 slot)
1121 coding (nth 3 slot)
1122 quailfile (nth 4 slot)
1123 converter (nth 5 slot)
1124 copyright (nth 6 slot))
1125 (message "Converting %s to %s..." dicfile quailfile)
1126 (with-temp-file (expand-file-name quailfile dirname)
1127 (set-buffer-file-coding-system 'iso-2022-7bit)
1128 (insert ";; Quail package `" name "' -*- coding:iso-2022-7bit; -*-\n")
1129 (insert ";; Generated by the command `miscdic-convert'\n")
1130 (insert ";; Date: " (current-time-string) "\n")
1131 (insert ";; Source dictionary file: " dicfile "\n")
1132 (insert ";; Copyright notice of the source file\n")
1133 (insert ";;------------------------------------------------------\n")
1134 (insert copyright "\n")
1135 (insert ";;------------------------------------------------------\n")
1136 (insert "\n")
1137 (insert ";;; Code:\n\n")
1138 (insert "(require 'quail)\n")
1139 (insert "(quail-define-package \"" name "\" \""
9d5db27a 1140 (if (eq coding 'big5) "Chinese-BIG5" "Chinese-CNS")
c063e381
KH
1141 "\" \"" title "\" t\n")
1142 (let* ((coding-system-for-read coding)
1143 (dicbuf (find-file-noselect filename)))
1144 (funcall converter dicbuf name title)
1145 (kill-buffer dicbuf)))
1146 (message "Converting %s to %s...done" dicfile quailfile))
1147 (setq tail (cdr tail)))))
1148
1149(defun batch-miscdic-convert ()
1150 "Run `miscdic-convert' on the files remaing on the command line.
1151Use this from the command line, with `-batch';
1152it won't work in an interactive Emacs.
1153If there's an argument \"-dir\", the next argument specifies a directory
1154to store generated Quail packages."
1155 (defvar command-line-args-left) ; Avoid compiler warning.
1156 (if (not noninteractive)
1157 (error "`batch-miscdic-convert' should be used only with -batch"))
1158 (let ((dir default-directory)
1159 filename)
1160 (while command-line-args-left
1161 (if (string= (car command-line-args-left) "-dir")
1162 (progn
1163 (setq command-line-args-left (cdr command-line-args-left))
0631f894
KH
1164 (setq dir (car command-line-args-left))
1165 (setq command-line-args-left (cdr command-line-args-left))))
c063e381
KH
1166 (setq filename (car command-line-args-left)
1167 command-line-args-left (cdr command-line-args-left))
1168 (if (file-directory-p filename)
1169 (dolist (file (directory-files filename t nil t))
1170 (miscdic-convert file dir))
1171 (miscdic-convert filename dir))))
1172 (kill-emacs 0))
1173
5cdaf2a5
KH
1174;; Local Variables:
1175;; coding: iso-2022-7bit
1176;; End:
60370d40
PJ
1177
1178;;; titdic-cnv.el ends here