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