1 ;;; titdic-cnv.el --- convert cxterm dictionary (TIT format) to Quail package -*- coding: utf-8-emacs; lexical-binding:t -*-
3 ;; Copyright (C) 1997-1998, 2000-2019 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
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
12 ;; Keywords: Quail, TIT, cxterm
14 ;; This file is part of GNU Emacs.
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.
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.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
31 ;; Convert cxterm dictionary (of TIT format) to quail-package.
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] ...
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.
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.
50 ;; Each line in the header part has two fields, KEY and VALUE. These
51 ;; fields are separated by one or more white characters.
53 ;; Each line in the body part has two fields, KEYSEQ and TRANSLATIONS.
54 ;; These fields are separated by one or more white characters.
56 ;; See the manual page of `tit2cit' of cxterm distribution for more
59 ;; Near the end of this file, we also have a few other tools to convert
60 ;; miscellaneous dictionaries.
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")))
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
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.
85 (defvar quail-cxterm-package-ext-info
86 '(("chinese-4corner" "四角")
87 ("chinese-array30" "30")
88 ("chinese-ccdospy" "缩拼"
89 "Pinyin base input method for Chinese charset GB2312 (`chinese-gb2312').
91 Pinyin is the standard Roman transliteration method for Chinese.
92 For the detail of Pinyin system, see the documentation of the input
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(ü)
98 keyseq: a f g h i j k l s u y v
100 Chinese: 啊 果 中 文 光 玉 全
101 Pinyin: a guo zhong wen guang yu quan
102 Keyseq: a1 guo4 as1 wf4 guh1 yu..6 qvj6
104 \\<quail-translation-docstring>
106 For double-width GB2312 characters corresponding to ASCII, use the
107 input method `chinese-qj'.")
109 ("chinese-ecdict" "英漢"
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\", \"電腦\" is input.
114 \\<quail-translation-docstring>")
117 "Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
120 Zhuyin is a kind of phonetic symbol. One to three Zhuyin symbols
121 compose one Chinese character.
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:陰平, 1:輕聲, 2:陽平, 3: 上聲,
128 \\<quail-translation-docstring>")
130 ("chinese-punct-b5" "標B"
131 "Input method for Chinese punctuation and symbols of Big5
132 \(`chinese-big5-1' and `chinese-big5-2').")
134 ("chinese-punct" "标G"
135 "Input method for Chinese punctuation and symbols of GB2312
136 \(`chinese-gb2312').")
138 ("chinese-py-b5" "拼B"
139 "Pinyin base input method for Chinese Big5 characters
140 \(`chinese-big5-1', `chinese-big5-2').
142 This input method works almost the same way as `chinese-py' (which
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.
150 For double-width Big5 characters corresponding to ASCII, use the input
151 method `chinese-qj-b5'.
153 The input method `chinese-py' and `chinese-tonepy' are also Pinyin
154 based, but for the character set GB2312 (`chinese-gb2312').")
156 ("chinese-qj-b5" "全B")
161 "Radical base input method for Chinese charset GB2312 (`chinese-gb2312').
163 In this input method, you enter a Chinese character by typing two
164 keys. The first key corresponds to the first (首) radical, the second
165 key corresponds to the last (尾) radical. The correspondence of keys
166 and radicals is as below:
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 心 冖 尸 丶 火 口 扌 氵 讠 艹 亻 木 礻 饣 月 纟 石 王 八 丿 日 辶 犭 竹 一 人
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 又 山 土 刀 阝 口 衣 疋 大 丁 厶 灬 十 歹 冂 门 今 丨 女 乙 囗 小 厂 虫 弋 卜
175 \\<quail-translation-docstring>")
177 ("chinese-tonepy" "调拼"
178 "Pinyin base input method for Chinese charset GB2312 (`chinese-gb2312').
180 Pinyin is the standard roman transliteration method for Chinese.
181 For the details of Pinyin system, see the documentation of the input
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:阴平, 2:阳平, 3:上声, 4下声, 5:轻声).
188 \\<quail-translation-docstring>
190 For instance, to input 你, 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.
194 For double-width GB2312 characters corresponding to ASCII, use the
195 input method `chinese-qj'.")
198 "Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
201 Zhuyin is a kind of a phonetic symbol. One to three Zhuyin symbols
202 compose a Chinese character.
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:陰平, 6:陽平, 3:上聲, 4:去聲,
209 \\<quail-translation-docstring>")))
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) "\"")))))
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
)
220 (concat (file-name-nondirectory (substring filename
0 -
4)) ".el")
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")
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
))
236 (or first
(princ "\n "))
237 (setq key
(aref keys i
))
239 (eq (lookup-key quail-translation-keymap
240 (char-to-string key
))
241 'quail-execute-non-quail-command
)
244 (princ (cons (cond ((< key ?\
) (format "\"\\C-%c\"" (+ key ?
@)))
245 ((< key
127) (format "\"%c\"" key
))
251 ;; Analyze header part of TIT dictionary and generate an appropriate
252 ;; `quail-define-package' function call.
253 (defun tit-process-header (filename)
254 (goto-char (point-min))
256 ;; At first, generate header part of the Quail package while
257 ;; collecting information from the original header.
258 (let ((package (concat
260 (substring (downcase (file-name-nondirectory filename
))
262 ;; TIT keywords and the corresponding default values.
266 (tit-backspace "\010\177")
267 (tit-deleteall "\015\025")
272 (princ ";; Quail package `")
275 (princ (substitute-command-keys
276 ";; Generated by the command `titdic-convert'\n"))
277 (princ ";;\tOriginal TIT dictionary file: ")
278 (princ (file-name-nondirectory filename
))
282 (let ((ch (following-char))
284 (cond ((= ch ?C
) ; COMMENT
285 (cond ((looking-at "COMMENT")
286 (let ((pos (match-end 0)))
289 (cons (buffer-substring-no-properties pos
(point))
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)))))
302 (cond ((looking-at "PROMPT:[ \t]*")
303 (goto-char (match-end 0))
304 (setq tit-prompt
(tit-read-key-value))
305 ;; Some TIT dictionaries 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,
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
)
327 (car (read-from-string (format "\"%s\""
330 (cons (cons key-char
(tit-read-key-value))
334 (princ (buffer-substring-no-properties pos
(point)))
338 (princ "\n;;; End of the header of original TIT dictionary.\n\n")
339 (princ ";;; Code:\n\n(require 'quail)\n\n")
341 (princ "(quail-define-package ")
342 ;; Args NAME, LANGUAGE, TITLE
343 (let ((title (nth 1 (assoc package quail-cxterm-package-ext-info
))))
347 (princ (nth 2 (assoc tit-encode tit-encode-list
)))
350 (if (string-match "[:∷:【]+\\([^:∷:】]+\\)" tit-prompt
)
351 (substring tit-prompt
(match-beginning 1) (match-end 1))
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
)))
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
))))
374 (setq doc
(concat doc
"\n" comments
"\n")))
376 (setq doc
(concat doc
"\n" doc-ext
"\n")))
382 (tit-generate-key-bindings tit-backspace
'quail-delete-last-char
)
384 (tit-generate-key-bindings tit-deleteall
'quail-abort-translation
)
386 (tit-generate-key-bindings tit-moveright
'quail-next-translation
)
388 (tit-generate-key-bindings tit-moveleft
'quail-prev-translation
)
391 ;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT.
392 ;; The remaining args are all nil.
394 (princ (if tit-multichoice
" nil" " t"))
395 (princ (if tit-keyprompt
" t t)\n\n" " nil nil)\n\n"))))
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
) "\"")))))
403 (while (string-match "\\\\[0-9][0-9][0-9]" key idx
)
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
)))))
415 ;; Convert body part of TIT dictionary into `quail-define-rules'
417 (defun tit-process-body ()
419 ch key translations pos
)
420 (princ "(quail-define-rules\n")
422 (setq ch
(following-char))
423 (if (or (= ch ?
#) (= ch ?
\n))
426 (skip-chars-forward "^ \t\n")
427 (setq key
(buffer-substring-no-properties pos
(point)))
428 (skip-chars-forward " \t")
429 (setq ch
(following-char))
430 (if (or (= ch ?
#) (= ch ?
\n))
431 ;; This entry contains no translations. Let's ignore it.
433 (or (string= key prev-key
)
436 (tit-flush-translations prev-key translations
))
437 (setq translations nil
442 (skip-chars-forward "^ \t#\n")
446 (buffer-substring-no-properties pos
(point)))
447 (buffer-substring-no-properties pos
(point)))))
450 (skip-chars-forward "^ \t\n")
451 (setq translations
(cons (buffer-substring-no-properties
454 (skip-chars-forward " \t")
455 (setq ch
(following-char))
456 (if (= ch ?
#) (end-of-line))))
460 (tit-flush-translations prev-key translations
))
464 (defun titdic-convert (filename &optional dirname
)
465 "Convert a TIT dictionary of FILENAME into a Quail package.
466 Optional argument DIRNAME if specified is the directory name under which
467 the generated Quail package is saved."
468 (interactive "FTIT dictionary file: ")
469 (let ((coding-system-for-write nil
))
470 (with-temp-file (tit-make-quail-package-file-name filename dirname
)
471 (let ((standard-output (current-buffer)))
473 (set-buffer-multibyte nil
)
474 ;; Here we must use `raw-text' instead of `no-conversion' to
475 ;; enable auto-decoding of eol format (CRLF->LF).
476 (let ((coding-system-for-read 'raw-text
))
477 (insert-file-contents (expand-file-name filename
)))
479 ;; Decode the buffer contents from the encoding specified by a
480 ;; value of the key "ENCODE:".
481 (if (not (search-forward "\nBEGIN" nil t
))
482 (error "TIT dictionary doesn't have body part"))
483 (let ((limit (point))
485 (goto-char (point-min))
486 (if (re-search-forward "^ENCODE:[ \t]*" limit t
)
488 (goto-char (match-end 0))
489 (setq tit-encode
(tit-read-key-value)))
490 (setq tit-encode tit-default-encode
))
491 (setq slot
(assoc tit-encode tit-encode-list
))
493 (error "Invalid ENCODE: value in TIT dictionary"))
494 (setq coding-system
(nth 1 slot
))
495 (goto-char (point-min))
496 (decode-coding-region (point-min) (point-max) coding-system
)
497 ;; Explicitly set eol format to `unix'.
498 (setq coding-system-for-write
'utf-8-unix
)
499 (remove-text-properties (point-min) (point-max) '(charset nil
)))
501 (set-buffer-multibyte t
)
502 ;; Set point the starting position of the body part.
503 (goto-char (point-min))
504 (if (not (search-forward "\nBEGIN" nil t
))
505 (error "TIT dictionary can't be decoded correctly"))
507 ;; Process the header part.
509 (narrow-to-region (point-min) (point))
510 (tit-process-header filename
)
513 ;; Process the body part
516 (princ ";; Local Variables:\n")
517 (princ ";; version-control: never\n")
518 (princ ";; no-update-autoloads: t\n")
519 (princ ";; End:\n"))))))
522 (defun batch-titdic-convert (&optional force
)
523 "Run `titdic-convert' on the files remaining on the command line.
524 Use this from the command line, with `-batch';
525 it won't work in an interactive Emacs.
526 For example, invoke \"emacs -batch -f batch-titdic-convert XXX.tit\" to
527 generate Quail package file \"xxx.el\" from TIT dictionary file \"XXX.tit\".
528 To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"."
529 (defvar command-line-args-left
) ; Avoid compiler warning.
530 (if (not noninteractive
)
531 (error "`batch-titdic-convert' should be used only with -batch"))
532 (if (string= (car command-line-args-left
) "-h")
534 (message "To convert XXX.tit and YYY.tit into xxx.el and yyy.el:")
535 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert XXX.tit YYY.tit")
536 (message "To convert XXX.tit into DIR/xxx.el:")
537 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert -dir DIR XXX.tit"))
538 (let (targetdir filename files file
)
539 (if (string= (car command-line-args-left
) "-dir")
541 (setq command-line-args-left
(cdr command-line-args-left
))
542 (setq targetdir
(car command-line-args-left
))
543 (setq command-line-args-left
(cdr command-line-args-left
))))
544 (while command-line-args-left
545 (setq filename
(expand-file-name (car command-line-args-left
)))
546 (if (file-directory-p filename
)
548 (message "Converting all tit files in the directory %s" filename
)
549 (setq files
(directory-files filename t
"\\.tit$")))
550 (setq files
(list filename
)))
552 (setq file
(expand-file-name (car files
)))
554 (file-newer-than-file-p
555 file
(tit-make-quail-package-file-name file targetdir
)))
556 (titdic-convert file targetdir
))
557 (setq files
(cdr files
)))
558 (setq command-line-args-left
(cdr command-line-args-left
)))))
562 ;;; Converter of miscellaneous dictionaries other than TIT format.
564 ;; Alist of input method names and the corresponding information.
565 ;; Each element has this form:
566 ;; (INPUT-METHOD-NAME ;; Name of the input method.
567 ;; INPUT-METHOD-TITLE ;; Title string of the input method
568 ;; DICFILE ;; Name of the source dictionary file.
569 ;; CODING ;; Coding system of the dictionary file.
570 ;; QUAILFILE ;; Name of the Quail package file.
571 ;; CONVERTER ;; Function to generate the Quail package.
572 ;; COPYRIGHT-NOTICE ;; Copyright notice of the source dictionary.
575 (defvar quail-misc-package-ext-info
576 '(("chinese-b5-tsangchi" "倉B"
577 "cangjie-table.b5" big5
"tsang-b5.el"
580 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
582 ;; # Permission to copy and distribute both modified and
583 ;; # unmodified versions is granted without royalty provided
584 ;; # this notice is preserved.")
586 ("chinese-b5-quick" "簡B"
587 "cangjie-table.b5" big5
"quick-b5.el"
590 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
592 ;; # Permission to copy and distribute both modified and
593 ;; # unmodified versions is granted without royalty provided
594 ;; # this notice is preserved.")
596 ("chinese-cns-tsangchi" "倉C"
597 "cangjie-table.cns" iso-2022-cn-ext
"tsang-cns.el"
600 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
602 ;; # Permission to copy and distribute both modified and
603 ;; # unmodified versions is granted without royalty provided
604 ;; # this notice is preserved.")
606 ("chinese-cns-quick" "簡C"
607 "cangjie-table.cns" iso-2022-cn-ext
"quick-cns.el"
610 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
612 ;; # Permission to copy and distribute both modified and
613 ;; # unmodified versions is granted without royalty provided
614 ;; # this notice is preserved.")
617 "pinyin.map" cn-gb-2312
"PY.el"
620 ;; \"pinyin.map\" is included in a free package called CCE. It is
622 ;; http://ftp.debian.org/debian/dists/potato/main
623 ;; /source/utils/cce_0.36.orig.tar.gz
624 ;; This package contains the following copyright notice.
627 ;; Copyright (C) 1999, Rui He, herui@cs.duke.edu
630 ;; CCE(Console Chinese Environment) 0.32
632 ;; CCE is free software; you can redistribute it and/or modify it under the
633 ;; terms of the GNU General Public License as published by the Free Software
634 ;; Foundation; either version 1, or (at your option) any later version.
636 ;; CCE is distributed in the hope that it will be useful, but WITHOUT ANY
637 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
638 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
641 ;; You should have received a copy of the GNU General Public License along with
642 ;; CCE. If not, see <https://www.gnu.org/licenses/>.")
644 ("chinese-ziranma" "自然"
645 "ziranma.cin" cn-gb-2312
"ZIRANMA.el"
648 ;; \"ziranma.cin\" is included in a free package called CCE. It is
650 ;; http://ftp.debian.org/debian/dists/potato/main
651 ;; /source/utils/cce_0.36.orig.tar.gz
652 ;; This package contains the following copyright notice.
655 ;; Copyright (C) 1999, Rui He, herui@cs.duke.edu
658 ;; CCE(Console Chinese Environment) 0.32
660 ;; CCE is free software; you can redistribute it and/or modify it under the
661 ;; terms of the GNU General Public License as published by the Free Software
662 ;; Foundation; either version 1, or (at your option) any later version.
664 ;; CCE is distributed in the hope that it will be useful, but WITHOUT ANY
665 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
666 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
669 ;; You should have received a copy of the GNU General Public License along with
670 ;; CCE. If not, see <https://www.gnu.org/licenses/>.")
672 ("chinese-ctlau" "刘粤"
673 "CTLau.html" cn-gb-2312
"CTLau.el"
676 ;; \"CTLau.html\" is available at:
678 ;; http://umunhum.stanford.edu/~lee/chicomp/CTLau.html
680 ;; It contains the following copyright notice:
682 ;; # Copyright (C) 1988-2001 Fung Fung Lee (lee@umunhum.stanford.edu)
684 ;; # This program is free software; you can redistribute it and/or
685 ;; # modify it under the terms of the GNU General Public License
686 ;; # as published by the Free Software Foundation; either version 2
687 ;; # of the License, or any later version.
689 ;; # This program is distributed in the hope that it will be useful,
690 ;; # but WITHOUT ANY WARRANTY; without even the implied warranty of
691 ;; # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
692 ;; # GNU General Public License for more details.
694 ;; # You should have received a copy of the GNU General Public License
695 ;; # along with this program. If not, see <https://www.gnu.org/licenses/>.")
697 ("chinese-ctlaub" "劉粵"
698 "CTLau-b5.html" big5
"CTLau-b5.el"
701 ;; \"CTLau-b5.html\" is available at:
703 ;; http://umunhum.stanford.edu/~lee/chicomp/CTLau-b5.html
705 ;; It contains the following copyright notice:
707 ;; # Copyright (C) 1988-2001 Fung Fung Lee (lee@umunhum.stanford.edu)
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.
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.
719 ;; # You should have received a copy of the GNU General Public License
720 ;; # along with this program. If not, see <https://www.gnu.org/licenses/>.")
723 ;; Generate a code of a Quail package in the current buffer from Tsang
724 ;; dictionary in the buffer DICBUF. The input method name of the
725 ;; Quail package is NAME, and the title string is TITLE.
727 ;; TSANG-P is non-nil, generate 倉頡 input method. Otherwise
728 ;; generate 簡易 (simple version of 倉頡). If BIG5-P is non-nil, the
729 ;; input method is for inputting Big5 characters. Otherwise the input
730 ;; method is for inputting CNS characters.
732 (defun tsang-quick-converter (dicbuf tsang-p big5-p
)
733 (let ((fulltitle (if tsang-p
(if big5-p
"倉頡" "倉頡")
734 (if big5-p
"簡易" "簡易")))
736 (goto-char (point-max))
738 (insert (format "\"中文輸入【%s】BIG5
742 [Q 手] [W 田] [E 水] [R 口] [T 廿] [Y 卜] [U 山] [I 戈] [O 人] [P 心]
744 [A 日] [S 尸] [D 木] [F 火] [G 土] [H 竹] [J 十] [L 中]
746 [Z ] [X 難] [C 金] [V 女] [B 月] [N 弓] [M 一]
748 \\\\<quail-translation-docstring>\"\n"
749 fulltitle fulltitle
))
750 (insert (format "\"中文輸入【%s】CNS
754 [Q 手] [W 田] [E 水] [R 口] [T 廿] [Y 卜] [U 山] [I 戈] [O 人] [P 心]
756 [A 日] [S 尸] [D 木] [F 火] [G 土] [H 竹] [J 十] [L 中]
758 [Z ] [X 難] [C 金] [V 女] [B 月] [N 弓] [M 一]
760 \\\\<quail-translation-docstring>\"\n"
761 fulltitle fulltitle
)))
762 (insert " '((\".\" . quail-next-translation-block)
763 (\",\" . quail-prev-translation-block))
765 (insert "(quail-define-rules\n")
766 (with-current-buffer dicbuf
767 ;; Handle double CR line ends, which result when checking out of
768 ;; CVS on MS-Windows.
769 (goto-char (point-min))
770 (search-forward "A440")
772 (let ((table (make-hash-table :test
'equal
))
776 (let ((trans (char-to-string (following-char)))
778 (re-search-forward "\\([A-Z]+\\)\r*$" nil t
)
781 (<= (- (match-end 1) (match-beginning 1)) 1))
783 (string (char-after (match-beginning 1))
784 (char-after (1- (match-end 1)))))))
785 (setq val
(gethash key table
))
786 (if val
(setq trans
(concat val trans
)))
787 (puthash key trans table
)
789 (maphash #'(lambda (key val
) (setq dic
(cons (cons key val
) dic
)))
791 (setq dic
(sort dic
(function (lambda (x y
) (string< (car x
) (car y
))))))
793 (insert (format "(%S\t%S)\n" (car elt
) (cdr elt
))))
794 (let ((punctuation '((";" ";﹔,、﹐﹑" ";﹔,、﹐﹑")
795 (":" ":︰﹕.。‧﹒·" ":︰﹕.。・﹒·")
797 ("\"" "”“〝〞〃" "”“〝〞〃")
802 ("<" "〈<﹤︿∠" "〈<﹤︿∠")
804 ("[" "〔【﹝︹︻「『﹁﹃" "〔【﹝︹︻「『﹁﹃")
805 ("]" "〕】﹞︺︼」』﹂﹄" "〕】﹞︺︼」』﹂﹄")
816 ("*" "*﹡※☆★" "*﹡※☆★")
819 ("-" "–—¯ ̄-﹣" "—–‾-﹣")
823 (dolist (elt punctuation
)
824 (insert (format "(%S %S)\n" (concat "z" (car elt
))
825 (if big5-p
(nth 1 elt
) (nth 2 elt
))))))
828 (defun tsang-b5-converter (dicbuf)
829 (tsang-quick-converter dicbuf t t
))
831 (defun quick-b5-converter (dicbuf)
832 (tsang-quick-converter dicbuf nil t
))
834 (defun tsang-cns-converter (dicbuf)
835 (tsang-quick-converter dicbuf t nil
))
837 (defun quick-cns-converter (dicbuf)
838 (tsang-quick-converter dicbuf nil nil
))
840 ;; Generate a code of a Quail package in the current buffer from
841 ;; Pinyin dictionary in the buffer DICBUF. The input method name of
842 ;; the Quail package is NAME, and the title string is TITLE.
844 (defun py-converter (dicbuf)
845 (goto-char (point-max))
846 (insert (format "%S\n" "汉字输入∷拼音∷
850 小写英文字母代表「拼音」符号, \"u(yu) 则用 u: 表示∶
852 Pinyin base input method for Chinese charset GB2312 (`chinese-gb2312').
854 Pinyin is the standard roman transliteration method for Chinese.
855 Pinyin uses a sequence of Latin alphabetic characters for each Chinese
856 character. The sequence is made by the combination of the initials
857 \(the beginning sounds) and finals (the ending sounds).
859 initials: b p m f d t n l z c s zh ch sh r j q x g k h
860 finals: a o e i er ai ei oa ou an en ang eng ong i ia iao ie iu ian in
861 iang ing iong u ua uo uai ui uan un uan ueng yu yue yuan yun
863 (Note: In the correct Pinyin writing, the sequence \"yu\" in the last
864 four finals should be written by the character u-umlaut `ü'.)
866 With this input method, you enter a Chinese character by first
867 entering its pinyin spelling.
869 \\<quail-translation-docstring>
871 For instance, to input 你, you type \"n i C-n 3\". The first \"n i\"
872 is a Pinyin, \"C-n\" selects the next group of candidates (each group
873 contains at most 10 characters), \"3\" select the third character in
876 This input method supports only Han characters. The related input
877 method `chinese-py-punct' is the combination of this method and
878 `chinese-punct'; it supports both Han characters and punctuation
881 For double-width GB2312 characters corresponding to ASCII, use the
882 input method `chinese-qj'.
884 The correct Pinyin system specifies tones by diacritical marks, but
885 this input method doesn't use them, which results in easy (you don't
886 have to know the exact tones), but verbose (many characters are assigned
887 to the same key sequence) input. You may also want to try the input
888 method `chinese-tonepy' with which you must specify tones by digits
890 (insert " '((\"\C-?\" . quail-delete-last-char)
891 (\".\" . quail-next-translation)
892 (\">\" . quail-next-translation)
893 (\",\" . quail-prev-translation)
894 (\"<\" . quail-prev-translation))
895 nil nil nil nil)\n\n")
896 (insert "(quail-define-rules\n")
898 (insert-buffer-substring-no-properties dicbuf
)
900 (re-search-forward "^[a-z]")
902 (delete-region pos
(point))
905 (skip-chars-forward "a-z")
909 (while (= (preceding-char) ?
\r)
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.
919 (defun ziranma-converter (dicbuf)
921 (with-current-buffer dicbuf
922 (goto-char (point-min))
923 (search-forward "\n%keyname end")
925 (let ((table (make-hash-table :test
'equal
))
929 (skip-chars-forward "^ \t")
930 (setq key
(buffer-substring-no-properties pos
(point)))
931 (skip-chars-forward " \t")
933 (skip-chars-forward "^\r\n")
934 (setq trans
(vector (buffer-substring-no-properties pos
(point))))
935 (setq val
(gethash key table
))
936 (if val
(setq trans
(vconcat val trans
)))
937 (puthash key trans table
)
939 (maphash #'(lambda (key trans
)
940 (let ((len (length trans
))
942 (if (and (= len
1) (= (length (aref trans
0)) 1))
943 (setq trans
(aref trans
0))
945 (while (and (< i len
)
946 (= (length (aref trans i
)) 1))
949 (setq trans
(mapconcat 'identity trans
"")))))
950 (setq dic
(cons (cons key trans
) dic
)))
952 (setq dic
(sort dic
(function (lambda (x y
) (string< (car x
) (car y
))))))
953 (goto-char (point-max))
954 (insert (format "%S\n" "汉字输入∷【自然】∷
957 ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
958 ┃Q ┃W ┃E ┃R ┃T ┃Y ┃Ush┃Ich┃O ┃P ┃
959 ┃ iu┃ ua┃ e┃ uan┃ ue┃ uai┃ u┃ i┃ o┃ un┃
960 ┃ ┃ ia┃ ┃ van┃ ve┃ ing┃ ┃ ┃ uo┃ vn┃
961 ┗┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┛
962 ┃A ┃S ┃D ┃F ┃G ┃H ┃J ┃K ┃L ┃
963 ┃ a┃iong┃uang┃ en┃ eng┃ ang┃ an┃ ao┃ ai┃
964 ┃ ┃ ong┃iang┃ ┃ ng┃ ┃ ┃ ┃ ┃
965 ┗┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━┻┳━━┓
966 ┃Z ┃X ┃C ┃Vzh┃B ┃N ┃M ┃, ┃. ┃ / ┃
967 ┃ ei┃ ie┃ iao┃ ui┃ ou┃ in┃ ian┃前页┃后页┃符号┃
968 ┃ ┃ ┃ ┃ v┃ ┃ ┃ ┃ ┃ ┃ ┃
969 ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛
972 Pinyin base input method for Chinese GB2312 characters (`chinese-gb2312').
974 Pinyin is the standard roman transliteration method for Chinese.
975 For the details of Pinyin system, see the documentation of the input
978 Unlike the standard spelling of Pinyin, in this input method all
979 initials and finals are assigned to single keys (see the above table).
980 For instance, the initial \"ch\" is assigned to the key `i', the final
981 \"iu\" is assigned to the key `q', and tones 1, 2, 3, 4, and 轻声 are
982 assigned to the keys `q', `w', `e', `r', `t' respectively.
984 \\<quail-translation-docstring>
986 To input one-letter words, you type 4 keys, the first two for the
987 Pinyin of the letter, next one for tone, and the last one is always a
988 quote ('). For instance, \"vsq'\" input 中. Exceptions are these
989 letters. You can input them just by typing a single key.
991 Character: 按 不 次 的 二 发 个 和 出 及 可 了 没
992 Key: a b c d e f g h i j k l m
993 Character: 你 欧 片 七 人 三 他 是 着 我 小 一 在
994 Key: n o p q r s t u v w x y z
996 To input two-letter words, you have two ways. One way is to type 4
997 keys, two for the first Pinyin, two for the second Pinyin. For
998 instance, \"vsgo\" inputs 中国. Another way is to type 3 keys: 2
999 initials of two letters, and quote ('). For instance, \"vg'\" also
1002 To input three-letter words, you type 4 keys: initials of three
1003 letters, and the last is quote ('). For instance, \"bjy'2\" inputs 北
1004 京鸭 (the last `2' is to select one of the candidates).
1006 To input words of more than three letters, you type 4 keys, initials
1007 of the first three letters and the last letter. For instance,
1008 \"bjdt\" inputs 北京电视台.
1010 To input symbols and punctuation, type `/' followed by one of `a' to
1011 `z', then select one of the candidates."))
1012 (insert " '((\"\C-?\" . quail-delete-last-char)
1013 (\".\" . quail-next-translation)
1014 (\"[\" . quail-next-translation)
1015 (\",\" . quail-prev-translation)
1016 (\"]\" . quail-prev-translation))
1017 nil nil nil nil)\n\n")
1018 (insert "(quail-define-rules\n")
1020 (insert (format "(%S %S)\n" (car elt
) (cdr elt
))))
1023 ;; Generate the code for a Quail package in the current buffer from a
1024 ;; CTLau or CTLau-b5 dictionary in the buffer DICBUF. The input
1025 ;; method name of the Quail package is NAME, and the title string is
1026 ;; TITLE. DESCRIPTION is the string shown by describe-input-method.
1028 (defun ctlau-converter (dicbuf description
)
1029 (goto-char (point-max))
1030 (insert (format "%S\n" description
))
1031 (insert " '((\"\C-?\" . quail-delete-last-char)
1032 (\".\" . quail-next-translation)
1033 (\">\" . quail-next-translation)
1034 (\",\" . quail-prev-translation)
1035 (\"<\" . quail-prev-translation))
1036 nil nil nil nil)\n\n")
1037 (insert "(quail-define-rules\n")
1038 (let (dicbuf-start dicbuf-end key-start
(pos (point)))
1039 ;; Find the dictionary, which starts below a horizontal rule and
1040 ;; ends at the second to last line in the HTML file.
1041 (with-current-buffer dicbuf
1042 (goto-char (point-min))
1043 (re-search-forward "^#<hr>")
1045 (setq dicbuf-start
(point))
1046 (goto-char (point-max))
1047 (re-search-backward "^<hr>")
1048 (setq dicbuf-end
(point)))
1049 (insert-buffer-substring-no-properties dicbuf dicbuf-start dicbuf-end
)
1050 ;; CTLau-b5.html contains characters (0xa1 0xbc) which show up as
1051 ;; hollow boxes when the original characters in CTLau.html from
1052 ;; which the file is converted have no Big5 equivalent. Go
1053 ;; through and delete them.
1055 (while (search-forward "□" nil t
)
1057 ;; Uppercase keys in dictionary need to be downcased. Backslashes
1058 ;; at the beginning of keys need to be turned into double
1063 (if (char-equal (following-char) ?
\\)
1065 (setq key-start
(point))
1066 (skip-chars-forward "\\\\A-Z")
1067 (downcase-region key-start
(point))
1071 (while (= (preceding-char) ?
\r)
1077 (defun ctlau-gb-converter (dicbuf)
1078 (ctlau-converter dicbuf
1082 Sidney Lau's Cantonese transcription scheme as described in his book
1083 \"Elementary Cantonese\", The Government Printer, Hong Kong, 1972.
1084 This file was prepared by Fung Fung Lee (李枫峰).
1085 Originally converted from CTCPS3.tit
1086 Last modified: June 2, 1993.
1088 Some infrequent GB characters are accessed by typing \\, followed by
1089 the Cantonese romanization of the respective radical (部首)."))
1091 (defun ctlau-b5-converter (dicbuf)
1092 (ctlau-converter dicbuf
1096 Sidney Lau's Cantonese transcription scheme as described in his book
1097 \"Elementary Cantonese\", The Government Printer, Hong Kong, 1972.
1098 This file was prepared by Fung Fung Lee (李楓峰).
1099 Originally converted from CTCPS3.tit
1100 Last modified: June 2, 1993.
1102 Some infrequent characters are accessed by typing \\, followed by
1103 the Cantonese romanization of the respective radical (部首)."))
1105 (declare-function dos-8
+3-filename
"dos-fns.el" (filename))
1107 (defun miscdic-convert (filename &optional dirname
)
1108 "Convert a dictionary file FILENAME into a Quail package.
1109 Optional argument DIRNAME if specified is the directory name under which
1110 the generated Quail package is saved."
1111 (interactive "FInput method dictionary file: ")
1112 (or (file-readable-p filename
)
1113 (error "%s does not exist" filename
))
1114 (let ((tail quail-misc-package-ext-info
)
1115 coding-system-for-write
1117 name title dicfile coding quailfile converter copyright
)
1119 (setq slot
(car tail
)
1120 dicfile
(nth 2 slot
)
1121 quailfile
(nth 4 slot
))
1122 (when (and (or (string-match dicfile filename
)
1123 ;; MS-DOS filesystem truncates file names to 8+3
1124 ;; limits, so "cangjie-table.cns" becomes
1125 ;; "cangjie-.cns", and the above string-match
1126 ;; fails. Give DOS users a chance...
1127 (and (fboundp 'msdos-long-file-names
)
1128 (not (msdos-long-file-names))
1129 (string-match (dos-8+3-filename dicfile
) filename
)))
1130 (if (file-newer-than-file-p
1131 filename
(expand-file-name quailfile dirname
))
1133 (message "%s is up to date" quailfile
)
1135 (setq name
(car slot
)
1138 converter
(nth 5 slot
)
1139 copyright
(nth 6 slot
))
1140 ;; Explicitly set eol format to `unix'.
1141 (setq coding-system-for-write
'utf-8-unix
)
1142 (with-temp-file (expand-file-name quailfile dirname
)
1143 (insert (format-message ";; Quail package `%s'\n" name
))
1144 (insert (format-message
1145 ";; Generated by the command `miscdic-convert'\n"))
1146 (insert ";; Source dictionary file: " dicfile
"\n")
1147 (insert ";; Copyright notice of the source file\n")
1148 (insert ";;------------------------------------------------------\n")
1149 (insert copyright
"\n")
1150 (insert ";;------------------------------------------------------\n")
1152 (insert ";;; Code:\n\n")
1153 (insert "(require 'quail)\n")
1154 (insert "(quail-define-package \"" name
"\" \""
1155 (if (eq coding
'big5
) "Chinese-BIG5"
1156 (if (eq coding
'iso-2022-cn-ext
) "Chinese-CNS"
1158 "\" \"" title
"\" t\n")
1159 (let ((coding-system-for-read
1160 (coding-system-change-eol-conversion coding
'unix
))
1161 (dstbuf (current-buffer)))
1163 (insert-file-contents filename
)
1164 (let ((dicbuf (current-buffer)))
1165 (with-current-buffer dstbuf
1166 (funcall converter dicbuf
)))))
1167 (insert ";; Local Variables:\n"
1168 ";; version-control: never\n"
1169 ";; no-update-autoloads: t\n"
1171 ";;; " quailfile
" ends here\n")))
1172 (setq tail
(cdr tail
)))))
1174 (defun batch-miscdic-convert ()
1175 "Run `miscdic-convert' on the files remaining on the command line.
1176 Use this from the command line, with `-batch';
1177 it won't work in an interactive Emacs.
1178 If there's an argument \"-dir\", the next argument specifies a directory
1179 to store generated Quail packages."
1180 (defvar command-line-args-left
) ; Avoid compiler warning.
1181 (if (not noninteractive
)
1182 (error "`batch-miscdic-convert' should be used only with -batch"))
1183 (let ((dir default-directory
)
1185 (while command-line-args-left
1186 (if (string= (car command-line-args-left
) "-dir")
1188 (setq command-line-args-left
(cdr command-line-args-left
))
1189 (setq dir
(car command-line-args-left
))
1190 (setq command-line-args-left
(cdr command-line-args-left
))))
1191 (setq filename
(car command-line-args-left
)
1192 command-line-args-left
(cdr command-line-args-left
))
1193 (if (file-directory-p filename
)
1194 (dolist (file (directory-files filename t nil t
))
1195 (or (file-directory-p file
)
1196 (miscdic-convert file dir
)))
1197 (miscdic-convert filename dir
))))
1200 (defun pinyin-convert ()
1201 "Convert text file pinyin.map into an elisp library.
1202 The library is named pinyin.el, and contains the constant
1203 `pinyin-character-map'."
1204 (let ((src-file (car command-line-args-left
))
1205 (dst-file (cadr command-line-args-left
))
1206 (coding-system-for-write 'utf-8-unix
))
1207 (with-temp-file dst-file
1208 (insert ";; This file is automatically generated from pinyin.map,\
1209 by the\n;; function pinyin-convert.\n\n")
1210 (insert "(defconst pinyin-character-map\n'(")
1211 (let ((pos (point)))
1212 (insert-file-contents src-file
)
1214 (re-search-forward "^[a-z]")
1216 (delete-region pos
(point))
1219 (skip-chars-forward "a-z")
1223 (while (= (preceding-char) ?
\r)
1227 (insert ")\n\"An alist holding correspondences between pinyin syllables\
1228 and\nChinese characters.\")\n\n")
1229 (insert "(provide 'pinyin)\n"))
1232 ;; Prevent "Local Variables" above confusing Emacs.
1235 ;;; titdic-cnv.el ends here