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