An electric test is now passing
[emacs.git] / lisp / international / titdic-cnv.el
blob8615d9533192c025bf2b93a3fffb1ff486ce7dc2
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
8 ;; Copyright (C) 2003
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/>.
29 ;;; Commentary:
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
57 ;; detail.
59 ;; Near the end of this file, we also have a few other tools to convert
60 ;; miscellaneous dictionaries.
62 ;;; Code:
64 (require 'quail)
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
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.
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
93 method `chinese-py'.
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
99 For example:
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>")
116 ("chinese-etzy" "倚注"
117 "Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
118 `chinese-big5-2').
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: 上聲,
126 4:去聲).
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
143 see).
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")
158 ("chinese-qj" "全G")
160 ("chinese-sw" "首尾"
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:
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 心 冖 尸 丶 火 口 扌 氵 讠 艹 亻 木 礻 饣 月 纟 石 王 八 丿 日 辶 犭 竹 一 人
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 又 山 土 刀 阝 口 衣 疋 大 丁 厶 灬 十 歹 冂 门 今 丨 女 乙 囗 小 厂 虫 弋 卜
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
182 method `chinese-py'.
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'.")
197 ("chinese-zozy" "零注"
198 "Zhuyin base input method for Chinese Big5 characters (`chinese-big5-1',
199 `chinese-big5-2').
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:去聲,
207 7:輕聲).
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)
219 (expand-file-name
220 (concat (file-name-nondirectory (substring filename 0 -4)) ".el")
221 dirname))
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))
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)))))
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
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))
272 (princ ";; Quail package `")
273 (princ package)
274 (princ "\n")
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))
279 (princ "\n\n")
281 (while (not (eobp))
282 (let ((ch (following-char))
283 (pos (point)))
284 (cond ((= ch ?C) ; COMMENT
285 (cond ((looking-at "COMMENT")
286 (let ((pos (match-end 0)))
287 (end-of-line)
288 (setq tit-comments
289 (cons (buffer-substring-no-properties 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 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,
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-no-properties pos (point)))
335 (princ "\n")
336 (forward-line 1)))
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))))
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 "[:∷:【]+\\([^:∷:】]+\\)" tit-prompt)
351 (substring tit-prompt (match-beginning 1) (match-end 1))
352 tit-prompt)))
353 (princ "\"\n"))
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"))
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))
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")
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"))))
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"))
415 ;; Convert body part of TIT dictionary into `quail-define-rules'
416 ;; function call.
417 (defun tit-process-body ()
418 (let* ((prev-key "")
419 ch key translations pos)
420 (princ "(quail-define-rules\n")
421 (while (null (eobp))
422 (setq ch (following-char))
423 (if (or (= ch ?#) (= ch ?\n))
424 (forward-line 1)
425 (setq pos (point))
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.
432 (forward-line 1)
433 (or (string= key prev-key)
434 (progn
435 (if translations
436 (tit-flush-translations prev-key translations))
437 (setq translations nil
438 prev-key key)))
439 (if tit-dictionary
440 (progn
441 (setq pos (point))
442 (skip-chars-forward "^ \t#\n")
443 (setq translations
444 (if translations
445 (concat translations
446 (buffer-substring-no-properties pos (point)))
447 (buffer-substring-no-properties pos (point)))))
448 (while (not (eolp))
449 (setq pos (point))
450 (skip-chars-forward "^ \t\n")
451 (setq translations (cons (buffer-substring-no-properties
452 pos (point))
453 translations))
454 (skip-chars-forward " \t")
455 (setq ch (following-char))
456 (if (= ch ?#) (end-of-line))))
457 (forward-line 1))))
459 (if translations
460 (tit-flush-translations prev-key translations))
461 (princ ")\n")))
463 ;;;###autoload
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)))
472 (with-temp-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))
484 coding-system slot)
485 (goto-char (point-min))
486 (if (re-search-forward "^ENCODE:[ \t]*" limit t)
487 (progn
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))
492 (if (not slot)
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.
508 (forward-line 1)
509 (narrow-to-region (point-min) (point))
510 (tit-process-header filename)
511 (widen)
513 ;; Process the body part
514 (tit-process-body)
516 (princ ";; Local Variables:\n")
517 (princ ";; version-control: never\n")
518 (princ ";; no-update-autoloads: t\n")
519 (princ ";; End:\n"))))))
521 ;;;###autoload
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")
533 (progn
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")
540 (progn
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)
547 (progn
548 (message "Converting all tit files in the directory %s" filename)
549 (setq files (directory-files filename t "\\.tit$")))
550 (setq files (list filename)))
551 (while files
552 (setq file (expand-file-name (car files)))
553 (when (or force
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)))))
559 (kill-emacs 0))
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.
573 ;; )
575 (defvar quail-misc-package-ext-info
576 '(("chinese-b5-tsangchi" "倉B"
577 "cangjie-table.b5" big5 "tsang-b5.el"
578 tsang-b5-converter
580 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
581 ;; #
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"
588 quick-b5-converter
590 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
591 ;; #
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"
598 tsang-cns-converter
600 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
601 ;; #
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"
608 quick-cns-converter
610 ;; # Copyright 2001 Christian Wittern <wittern@iis.sinica.edu.tw>
611 ;; #
612 ;; # Permission to copy and distribute both modified and
613 ;; # unmodified versions is granted without royalty provided
614 ;; # this notice is preserved.")
616 ("chinese-py" "拼G"
617 "pinyin.map" cn-gb-2312 "PY.el"
618 py-converter
620 ;; \"pinyin.map\" is included in a free package called CCE. It is
621 ;; available at:
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
639 ;; details.
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"
646 ziranma-converter
648 ;; \"ziranma.cin\" is included in a free package called CCE. It is
649 ;; available at:
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
667 ;; details.
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"
674 ctlau-gb-converter
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)
683 ;; #
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.
688 ;; #
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.
693 ;; #
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"
699 ctlau-b5-converter
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)
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, 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 "簡易" "簡易")))
735 dic)
736 (goto-char (point-max))
737 (if big5-p
738 (insert (format "\"中文輸入【%s】BIG5
740 漢語%s輸入鍵盤
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
752 漢語%s輸入鍵盤
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))
764 nil nil)\n\n")
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")
771 (beginning-of-line)
772 (let ((table (make-hash-table :test 'equal))
773 val)
774 (while (not (eobp))
775 (forward-char 5)
776 (let ((trans (char-to-string (following-char)))
777 key)
778 (re-search-forward "\\([A-Z]+\\)\r*$" nil t)
779 (setq key (downcase
780 (if (or tsang-p
781 (<= (- (match-end 1) (match-beginning 1)) 1))
782 (match-string 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)
788 (forward-line 1)))
789 (maphash #'(lambda (key val) (setq dic (cons (cons key val) dic)))
790 table)))
791 (setq dic (sort dic (function (lambda (x y) (string< (car x ) (car y))))))
792 (dolist (elt dic)
793 (insert (format "(%S\t%S)\n" (car elt) (cdr elt))))
794 (let ((punctuation '((";" ";﹔,、﹐﹑" ";﹔,、﹐﹑")
795 (":" ":︰﹕.。‧﹒·" ":︰﹕.。・﹒·")
796 ("'" "’‘" "’‘")
797 ("\"" "”“〝〞〃" "”“〝〞〃")
798 ("\\" "\﹨╲" "\﹨╲")
799 ("|" "|︱︳∣" "︱︲|")
800 ("/" "/∕╱" "/∕╱")
801 ("?" "?﹖" "?﹖")
802 ("<" "〈<﹤︿∠" "〈<﹤︿∠")
803 (">" "〉>﹥﹀" "〉>﹦﹀")
804 ("[" "〔【﹝︹︻「『﹁﹃" "〔【﹝︹︻「『﹁﹃")
805 ("]" "〕】﹞︺︼」』﹂﹄" "〕】﹞︺︼」』﹂﹄")
806 ("{" "{﹛︷ " "{﹛︷ ")
807 ("}" "}﹜︸" "}﹜︸")
808 ("`" "‵′" "′‵")
809 ("~" "~﹋﹌︴﹏" "∼﹋﹌")
810 ("!" "!﹗" "!﹗")
811 ("@" "@﹫" "@﹫")
812 ("#" "#﹟" "#﹟")
813 ("$" "$﹩" "$﹩")
814 ("%" "%﹪" "%﹪")
815 ("&" "&﹠" "&﹠")
816 ("*" "*﹡※☆★" "*﹡※☆★")
817 ("(" "(﹙︵" "(﹙︵")
818 (")" ")﹚︶" ")﹚︶")
819 ("-" "–—¯ ̄-﹣" "—–‾-﹣")
820 ("_" "_ˍ" "_")
821 ("=" "=﹦" "=﹥")
822 ("+" "+﹢" "+﹢"))))
823 (dolist (elt punctuation)
824 (insert (format "(%S %S)\n" (concat "z" (car elt))
825 (if big5-p (nth 1 elt) (nth 2 elt))))))
826 (insert ")\n")))
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" "汉字输入∷拼音∷
848 拼音方案
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
874 that group.
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
879 characters.
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
889 \(1..5)."))
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")
897 (let ((pos (point)))
898 (insert-buffer-substring-no-properties dicbuf)
899 (goto-char pos)
900 (re-search-forward "^[a-z]")
901 (beginning-of-line)
902 (delete-region pos (point))
903 (while (not (eobp))
904 (insert "(\"")
905 (skip-chars-forward "a-z")
906 (insert "\" \"")
907 (delete-char 1)
908 (end-of-line)
909 (while (= (preceding-char) ?\r)
910 (delete-char -1))
911 (insert "\")")
912 (forward-line 1)))
913 (insert ")\n"))
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)
920 (let (dic)
921 (with-current-buffer dicbuf
922 (goto-char (point-min))
923 (search-forward "\n%keyname end")
924 (forward-line 1)
925 (let ((table (make-hash-table :test 'equal))
926 pos key trans val)
927 (while (not (eobp))
928 (setq pos (point))
929 (skip-chars-forward "^ \t")
930 (setq key (buffer-substring-no-properties pos (point)))
931 (skip-chars-forward " \t")
932 (setq pos (point))
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)
938 (forward-line 1))
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))
944 (setq i 0)
945 (while (and (< i len)
946 (= (length (aref trans i)) 1))
947 (setq i (1+ i)))
948 (if (= i len)
949 (setq trans (mapconcat 'identity trans "")))))
950 (setq dic (cons (cons key trans) dic)))
951 table)))
952 (setq dic (sort dic (function (lambda (x y) (string< (car x) (car y))))))
953 (goto-char (point-max))
954 (insert (format "%S\n" "汉字输入∷【自然】∷
956 键盘对照表:
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
976 method `chinese-py'.
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
1000 inputs 中国.
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")
1019 (dolist (elt dic)
1020 (insert (format "(%S %S)\n" (car elt) (cdr elt))))
1021 (insert ")\n")))
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>")
1044 (forward-line 1)
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.
1054 (goto-char pos)
1055 (while (search-forward "□" nil t)
1056 (delete-char -1))
1057 ;; Uppercase keys in dictionary need to be downcased. Backslashes
1058 ;; at the beginning of keys need to be turned into double
1059 ;; backslashes.
1060 (goto-char pos)
1061 (while (not (eobp))
1062 (insert "(\"")
1063 (if (char-equal (following-char) ?\\)
1064 (insert "\\"))
1065 (setq key-start (point))
1066 (skip-chars-forward "\\\\A-Z")
1067 (downcase-region key-start (point))
1068 (insert "\" \"")
1069 (delete-char 1)
1070 (end-of-line)
1071 (while (= (preceding-char) ?\r)
1072 (delete-char -1))
1073 (insert "\")")
1074 (forward-line 1)))
1075 (insert ")\n"))
1077 (defun ctlau-gb-converter (dicbuf)
1078 (ctlau-converter dicbuf
1079 "汉字输入∷刘锡祥式粤音∷
1081 刘锡祥式粤语注音方案
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
1093 "漢字輸入:劉錫祥式粵音:
1095 劉錫祥式粵語注音方案
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
1116 slot
1117 name title dicfile coding quailfile converter copyright)
1118 (while tail
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)
1134 nil))
1135 (setq name (car slot)
1136 title (nth 1 slot)
1137 coding (nth 3 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")
1151 (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"
1157 "Chinese-GB"))
1158 "\" \"" title "\" t\n")
1159 (let ((coding-system-for-read
1160 (coding-system-change-eol-conversion coding 'unix))
1161 (dstbuf (current-buffer)))
1162 (with-temp-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"
1170 ";; End:\n\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)
1184 filename)
1185 (while command-line-args-left
1186 (if (string= (car command-line-args-left) "-dir")
1187 (progn
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))))
1198 (kill-emacs 0))
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)
1213 (goto-char pos)
1214 (re-search-forward "^[a-z]")
1215 (beginning-of-line)
1216 (delete-region pos (point))
1217 (while (not (eobp))
1218 (insert "(\"")
1219 (skip-chars-forward "a-z")
1220 (insert "\" . \"")
1221 (delete-char 1)
1222 (end-of-line)
1223 (while (= (preceding-char) ?\r)
1224 (delete-char -1))
1225 (insert "\")")
1226 (forward-line 1)))
1227 (insert ")\n\"An alist holding correspondences between pinyin syllables\
1228 and\nChinese characters.\")\n\n")
1229 (insert "(provide 'pinyin)\n"))
1230 (kill-emacs 0)))
1232 ;; Prevent "Local Variables" above confusing Emacs.
1235 ;;; titdic-cnv.el ends here