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