annotate lisp/international/titdic-cnv.el @ 26804:ce54b1d60246

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 10 Dec 1999 21:52:33 +0000
parents d08387c742bb
children 3ab020a4847b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1 ;;; titdic-cnv.el --- convert cxterm dictionary (TIT format) to Quail package
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18202
diff changeset
4 ;; Licensed to the Free Software Foundation.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: Quail, TIT, cxterm
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
23 ;; Boston, MA 02111-1307, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;;; Comments:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
27 ;; Convert cxterm dictionary (of TIT format) to quail-package.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 ;; Usage (within Emacs):
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
30 ;; M-x titdic-convert<CR>CXTERM-DICTIONARY-NAME<CR>
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; Usage (from shell):
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
32 ;; % emacs -batch -l titdic-cnv -f batch-titdic-convert\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;; [-dir DIR] [DIR | FILE] ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; When you run titdic-convert within Emacs, you have a chance to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; modify arguments of `quail-define-package' before saving the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;; converted file. For instance, you are likely to modify TITLE,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; DOCSTRING, and KEY-BINDINGS.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
40 ;; Cxterm dictionary file (*.tit) is a line-oriented text (English,
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;; Chinese, Japanese, and Korean) file. The whole file contains of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;; two parts, the definition part (`header' here after) followed by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 ;; the dictionary part (`body' here after). All lines begin with
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; leading '#' are ignored.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; Each line in the header part has two fields, KEY and VALUE. These
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 ;; fields are separated by one or more white characters.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;; Each line in the body part has two fields, KEYSEQ and TRANSLATIONS.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 ;; These fields are separated by one or more white characters.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;; See the manual page of `tit2cit' of cxterm distribution for more
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 ;; detail.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 (require 'quail)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
59 ;; List of values of key "ENCODE:" and the corresponding Emacs
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 ;; coding-system and language environment name.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 (defvar tit-encode-list
17098
8917133b7e82 Remove prefix "coding-system-" from coding system symbol names.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
62 '(("GB" euc-china "Chinese-GB")
8917133b7e82 Remove prefix "coding-system-" from coding system symbol names.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
63 ("BIG5" cn-big5 "Chinese-BIG5")
8917133b7e82 Remove prefix "coding-system-" from coding system symbol names.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
64 ("JIS" euc-japan "Japanese")
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
65 ("KS" euc-kr "Korean")))
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
66
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
67 ;; List of package names and the corresponding titles.
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
68 (defvar quail-cxterm-package-title-alist
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
69 '(("chinese-4corner" . "$(0(?-F(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
70 ("chinese-array30" . "$(0#R#O(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
71 ("chinese-ccdospy" . "$AKuF4(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
72 ("chinese-ctlau" . "$AAuTA(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
73 ("chinese-ctlaub" . "$(0N,Gn(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
74 ("chinese-ecdict" . "$(05CKH(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
75 ("chinese-etzy" . "$(06/0D(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
76 ("chinese-punct-b5" . "$(0O:(BB")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
77 ("chinese-punct" . "$A1j(BG")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
78 ("chinese-py-b5" . "$(03<(BB")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
79 ("chinese-py" . "$AF4(BG")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
80 ("chinese-qj-b5" . "$(0)A(BB")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
81 ("chinese-qj" . "$AH+(BG")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
82 ("chinese-sw" . "$AJWN2(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
83 ("chinese-tonepy" . "$A5wF4(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
84 ("chinese-ziranma" . "$AK+F4(B")
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
85 ("chinese-zozy" . "$(0I\0D(B")))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 ;; Return a value of the key in the current line.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 (defsubst tit-read-key-value ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 (if (looking-at "[^ \t\n]+")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (car (read-from-string (concat "\"" (match-string 0) "\"")))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 ;; Return an appropriate quail-package filename from FILENAME (TIT
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
93 ;; dictionary filename). For instance, ".../ZOZY.tit" -> "ZOZY.el".
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
94 (defun tit-make-quail-package-file-name (filename &optional dirname)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 (expand-file-name
18555
39589a3b1b20 Add license note.
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
96 (concat (file-name-nondirectory (substring filename 0 -4)) ".el")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 dirname))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
99 ;; This value is nil if we are processing phrase dictionary.
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
100 (defconst tit-dictionary t)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (defvar tit-encode nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 (defvar tit-default-encode "GB")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 ;; Generate elements of KEY-BINDINGS arg for `quail-define-package' so
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 ;; that each characters in KEYS invokes FUNCTION-SYMBOL.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 (defun tit-generate-key-bindings (keys function-symbol)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (let ((len (length keys))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 (i 0)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
109 (first t)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 (while (< i len)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
112 (or first (princ "\n "))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (setq key (aref keys i))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
114 (if (if (< key ?\ )
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
115 (eq (lookup-key quail-translation-keymap
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
116 (char-to-string key))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 'quail-execute-non-quail-command)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
118 (<= key 127))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
119 (progn
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
120 (princ (cons (cond ((< key ?\ ) (format "\"\\C-%c\"" (+ key ?@)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
121 ((< key 127) (format "\"%c\"" key))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
122 (t "\"\\C-?\""))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
123 function-symbol))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
124 (setq first nil)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 (setq i (1+ i)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 ;; Analyze header part of TIT dictionary and generate an appropriate
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 ;; `quail-define-package' function call.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 (defun tit-process-header (filename)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (message "Processing header part...")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
133 ;; At first, generate header part of the Quail package while
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
134 ;; collecting information from the original header.
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
135 (let ((package (concat
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
136 "chinese-"
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
137 (substring (downcase (file-name-nondirectory filename))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
138 0 -4)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
139 ;; TIT keywords and the corresponding default values.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 (tit-multichoice t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 (tit-prompt "")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 (tit-comments nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 (tit-backspace "\010\177")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (tit-deleteall "\015\025")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (tit-moveright ".>")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (tit-moveleft ",<")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 (tit-keyprompt nil))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
148
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
149 (princ ";; Quail package `")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
150 (princ package)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
151 (princ "' generated by the command `titdic-convert'\n;;\tDate: ")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
152 (princ (current-time-string))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
153 (princ "\n;;\tOriginal TIT dictionary file: ")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
154 (princ (file-name-nondirectory filename))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
155 (princ "\n\n;;; Comment:\n\n")
21503
d08387c742bb (titdic-convert): Message improved.
Kenichi Handa <handa@m17n.org>
parents: 21081
diff changeset
156 (princ ";; Byte-compile this file again after any modification.\n\n")
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
157 (princ ";;; Start of the header of original TIT dictionary.\n\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
158
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (while (not (eobp))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
160 (let ((ch (following-char))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
161 (pos (point)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (cond ((= ch ?C) ; COMMENT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (cond ((looking-at "COMMENT")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (let ((pos (match-end 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (end-of-line)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (setq tit-comments (cons (buffer-substring pos (point))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 tit-comments))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 ((= ch ?M) ; MULTICHOICE, MOVERIGHT, MOVELEFT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (cond ((looking-at "MULTICHOICE:[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (goto-char (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (setq tit-multichoice (looking-at "YES")))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 ((looking-at "MOVERIGHT:[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (goto-char (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (setq tit-moveright (tit-read-key-value)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 ((looking-at "MOVELEFT:[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (goto-char (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 (setq tit-moveleft (tit-read-key-value)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 ((= ch ?P) ; PROMPT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 (cond ((looking-at "PROMPT:[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (goto-char (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 (setq tit-prompt (tit-read-key-value)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 ((= ch ?B) ; BACKSPACE, BEGINDICTIONARY,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 ; BEGINPHRASE
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 (cond ((looking-at "BACKSPACE:[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 (goto-char (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 (setq tit-backspace (tit-read-key-value)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 ((looking-at "BEGINDICTIONARY")
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
188 (setq tit-dictionary t))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 ((looking-at "BEGINPHRASE")
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
190 (setq tit-dictionary nil))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 ((= ch ?K) ; KEYPROMPT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (cond ((looking-at "KEYPROMPT(\\(.*\\)):[ \t]*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (let ((key-char (match-string 1)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (goto-char (match-end 0))
19943
23ada3fdbc8b (tit-process-header): Convert argument of KEYPROMPT if it contains an escape.
Richard M. Stallman <rms@gnu.org>
parents: 19431
diff changeset
195 (if (string-match "\\\\[0-9]+" key-char)
23ada3fdbc8b (tit-process-header): Convert argument of KEYPROMPT if it contains an escape.
Richard M. Stallman <rms@gnu.org>
parents: 19431
diff changeset
196 (setq key-char
23ada3fdbc8b (tit-process-header): Convert argument of KEYPROMPT if it contains an escape.
Richard M. Stallman <rms@gnu.org>
parents: 19431
diff changeset
197 (car (read-from-string (format "\"%s\""
23ada3fdbc8b (tit-process-header): Convert argument of KEYPROMPT if it contains an escape.
Richard M. Stallman <rms@gnu.org>
parents: 19431
diff changeset
198 key-char)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 (setq tit-keyprompt
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (cons (cons key-char (tit-read-key-value))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
201 tit-keyprompt)))))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
202 (end-of-line)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
203 (princ ";; ")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
204 (princ (buffer-substring pos (point)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
205 (princ "\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
206 (forward-line 1)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
208 (princ "\n;;; End of the header of original TIT dictionary.\n\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
209 (princ ";;; Code:\n\n(require 'quail)\n\n")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
211 (princ "(quail-define-package ")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
212 ;; Args NAME, LANGUAGE, TITLE
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
213 (let ((title (cdr (assoc package quail-cxterm-package-title-alist))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
214 (princ "\"")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
215 (princ package)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
216 (princ "\" \"")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
217 (princ (nth 2 (assoc tit-encode tit-encode-list)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
218 (princ "\" \"")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
219 (princ (or title
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
220 (if (string-match "[:$A!K$(0!(!J(B]+\\([^:$A!K$(0!(!K(B]+\\)" tit-prompt)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
221 (substring tit-prompt (match-beginning 1) (match-end 1))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
222 tit-prompt)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
223 (princ "\"\n"))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 ;; Arg GUIDANCE
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226 (if tit-keyprompt
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 (progn
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
228 (princ " '(")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 (while tit-keyprompt
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
230 (princ " ")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
231 (princ (format "(%d . \"%s\")\n"
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
232 (string-to-char (car (car tit-keyprompt)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
233 (cdr (car tit-keyprompt))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 (setq tit-keyprompt (cdr tit-keyprompt)))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
235 (princ ")"))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
236 (princ " t\n"))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 ;; Arg DOCSTRING
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
239 (prin1
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
240 (mapconcat 'identity (cons tit-prompt (nreverse tit-comments)) "\n"))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
241 (terpri)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 ;; Arg KEY-BINDINGS
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
244 (princ " '(")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 (tit-generate-key-bindings tit-backspace 'quail-delete-last-char)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
246 (princ "\n ")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 (tit-generate-key-bindings tit-deleteall 'quail-abort-translation)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
248 (princ "\n ")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 (tit-generate-key-bindings tit-moveright 'quail-next-translation)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
250 (princ "\n ")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 (tit-generate-key-bindings tit-moveleft 'quail-prev-translation)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
252 (princ ")\n")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 ;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 ;; The remaining args are all nil.
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
256 (princ " nil")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
257 (princ (if tit-multichoice " nil" " t"))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
258 (princ (if tit-keyprompt " t t)\n\n" " nil nil)\n\n"))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
260 (defsubst tit-flush-translations (key translations)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
261 (if (string-match "\\\\[0-9][0-9][0-9]" key)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
262 (let ((newkey (concat (substring key 0 (match-beginning 0))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
263 (car (read-from-string
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
264 (concat "\"" (match-string 0 key) "\"")))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
265 (idx (match-end 0)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
266 (while (string-match "\\\\[0-9][0-9][0-9]" key idx)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
267 (setq newkey (concat
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
268 newkey
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
269 (substring key idx (match-beginning 0))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
270 (car (read-from-string
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
271 (concat "\"" (match-string 0 key) "\"")))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
272 (setq idx (match-end 0)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
273 (setq key (concat newkey (substring key idx)))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
274 (prin1 (list key (if tit-dictionary translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
275 (vconcat (nreverse translations)))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
276 (princ "\n"))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
278 ;; Convert body part of TIT dictionary into `quail-define-rules'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 ;; function call.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 (defun tit-process-body ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281 (message "Formatting translation rules...")
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
282 (let* ((template (list nil nil))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
283 (second (cdr template))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
284 (prev-key "")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
285 ch key translations pos)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
286 (princ "(quail-define-rules\n")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 (while (null (eobp))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
288 (setq ch (following-char))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
289 (if (or (= ch ?#) (= ch ?\n))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
290 (forward-line 1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 (setq pos (point))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
292 (skip-chars-forward "^ \t\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
293 (setq key (buffer-substring pos (point)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
294 (skip-chars-forward " \t")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
295 (setq ch (following-char))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
296 (if (or (= ch ?#) (= ch ?\n))
18796
ab40b57484c1 (tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents: 18555
diff changeset
297 ;; This entry contains no translations. Let's ignore it.
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
298 (forward-line 1)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
299 (or (string= key prev-key)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
300 (progn
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
301 (if translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
302 (tit-flush-translations prev-key translations))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
303 (setq translations nil
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
304 prev-key key)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
305 (if tit-dictionary
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
306 (progn
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
307 (setq pos (point))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
308 (skip-chars-forward "^ \t#\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
309 (setq translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
310 (if translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
311 (concat translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
312 (buffer-substring pos (point)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
313 (buffer-substring pos (point)))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
314 (while (not (eolp))
18796
ab40b57484c1 (tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents: 18555
diff changeset
315 (setq pos (point))
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
316 (skip-chars-forward "^ \t\n")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
317 (setq translations (cons (buffer-substring pos (point))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
318 translations))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
319 (skip-chars-forward " \t")
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
320 (setq ch (following-char))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
321 (if (= ch ?#) (end-of-line))))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
322 (forward-line 1))))
18796
ab40b57484c1 (tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents: 18555
diff changeset
323
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
324 (if translations
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
325 (tit-flush-translations prev-key translations))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
326 (princ ")\n")))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 (defun titdic-convert (filename &optional dirname)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330 "Convert a TIT dictionary of FILENAME into a Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331 Optional argument DIRNAME if specified is the directory name under which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 the generated Quail package is saved."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 (interactive "FTIT dictionary file: ")
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
334 (with-temp-file (tit-make-quail-package-file-name filename dirname)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
335 (set-buffer-file-coding-system 'iso-2022-7bit)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
336 (let ((standard-output (current-buffer)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
337 (with-temp-buffer
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
338 (let ((coding-system-for-read 'no-conversion))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
339 (insert-file-contents (expand-file-name filename)))
21081
f7d33c30712e (titdic-convert): Use set-buffer-multibyte.
Richard M. Stallman <rms@gnu.org>
parents: 20840
diff changeset
340 (set-buffer-multibyte t)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
341
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
342 ;; Decode the buffer contents from the encoding specified by a
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
343 ;; value of the key "ENCODE:".
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
344 (if (not (search-forward "\nBEGIN" nil t))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
345 (error "TIT dictionary doesn't have body part"))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
346 (let ((limit (point))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
347 coding-system slot)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
348 (goto-char (point-min))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
349 (if (re-search-forward "^ENCODE:[ \t]*" limit t)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
350 (progn
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
351 (goto-char (match-end 0))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
352 (setq tit-encode (tit-read-key-value)))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
353 (setq tit-encode tit-default-encode))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
354 (setq slot (assoc tit-encode tit-encode-list))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
355 (if (not slot)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
356 (error "Invalid ENCODE: value in TIT dictionary"))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
357 (setq coding-system (nth 1 slot))
21503
d08387c742bb (titdic-convert): Message improved.
Kenichi Handa <handa@m17n.org>
parents: 21081
diff changeset
358 (message "Decoding with coding system %s..." coding-system)
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
359 (goto-char (point-min))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
360 (decode-coding-region (point-min) (point-max) coding-system))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
362 ;; Set point the starting position of the body part.
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
363 (goto-char (point-min))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
364 (if (not (search-forward "\nBEGIN" nil t))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
365 (error "TIT dictionary can't be decoded correctly"))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
367 ;; Process the header part.
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
368 (forward-line 1)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
369 (narrow-to-region (point-min) (point))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
370 (tit-process-header filename)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
371 (widen)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372
20840
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
373 ;; Process the body part. For speed, we turn off multibyte facility.
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
374 (with-current-buffer standard-output
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
375 (set-buffer-multibyte nil))
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
376 (set-buffer-multibyte nil)
1842af0263da Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents: 20795
diff changeset
377 (tit-process-body)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 ;;;###autoload
18831
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
380 (defun batch-titdic-convert (&optional force)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 "Run `titdic-convert' on the files remaining on the command line.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 Use this from the command line, with `-batch';
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 it won't work in an interactive Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 For example, invoke \"emacs -batch -f batch-titdic-convert XXX.tit\" to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 generate Quail package file \"xxx.el\" from TIT dictionary file \"XXX.tit\".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 (defvar command-line-args-left) ; Avoid compiler warning.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 (if (not noninteractive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 (error "`batch-titdic-convert' should be used only with -batch"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 (if (string= (car command-line-args-left) "-h")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 (message "To convert XXX.tit and YYY.tit into xxx.el and yyy.el:")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert XXX.tit YYY.tit")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 (message "To convert XXX.tit into DIR/xxx.el:")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert -dir DIR XXX.tit"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 (let (targetdir filename files file)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397 (if (string= (car command-line-args-left) "-dir")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 (setq command-line-args-left (cdr command-line-args-left))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 (setq targetdir (car command-line-args-left))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 (setq command-line-args-left (cdr command-line-args-left))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 (while command-line-args-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 (setq filename (expand-file-name (car command-line-args-left)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404 (if (file-directory-p filename)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 (message "Converting all tit files in the directory %s" filename)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 (setq files (directory-files filename t "\\.tit$")))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 (setq files (list filename)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409 (while files
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 (setq file (expand-file-name (car files)))
18831
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
411 (when (or force
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
412 (file-newer-than-file-p
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
413 file (tit-make-quail-package-file-name file targetdir)))
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
414 (message "Converting %s to quail-package..." file)
e6f6c2712a5f (batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents: 18796
diff changeset
415 (titdic-convert file targetdir))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 (setq files (cdr files)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 (setq command-line-args-left (cdr command-line-args-left)))
21503
d08387c742bb (titdic-convert): Message improved.
Kenichi Handa <handa@m17n.org>
parents: 21081
diff changeset
418 (message "Byte-compile the created files by:")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419 (message " %% emacs -batch -f batch-byte-compile XXX.el")))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 (kill-emacs 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 ;;; titdic-cnv.el ends here