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