Mercurial > emacs
annotate lisp/international/titdic-cnv.el @ 29530:2485d23636b2
(executable-make-buffer-file-executable-if-script-p): Renamed and
simplified.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 09 Jun 2000 09:58:46 +0000 |
parents | d08387c742bb |
children | 3ab020a4847b |
rev | line source |
---|---|
18555 | 1 ;;; titdic-cnv.el --- convert cxterm dictionary (TIT format) to Quail package |
17052 | 2 |
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 | 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 | |
17071 | 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. | |
17052 | 24 |
25 ;;; Comments: | |
26 | |
18555 | 27 ;; Convert cxterm dictionary (of TIT format) to quail-package. |
17052 | 28 ;; |
29 ;; Usage (within Emacs): | |
18555 | 30 ;; M-x titdic-convert<CR>CXTERM-DICTIONARY-NAME<CR> |
17052 | 31 ;; Usage (from shell): |
18555 | 32 ;; % emacs -batch -l titdic-cnv -f batch-titdic-convert\ |
17052 | 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 | |
18555 | 40 ;; Cxterm dictionary file (*.tit) is a line-oriented text (English, |
17052 | 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. | |
54 | |
55 ;;; Code: | |
56 | |
57 (require 'quail) | |
58 | |
18555 | 59 ;; List of values of key "ENCODE:" and the corresponding Emacs |
17052 | 60 ;; coding-system and language environment name. |
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 | 65 ("KS" euc-kr "Korean"))) |
66 | |
67 ;; List of package names and the corresponding titles. | |
68 (defvar quail-cxterm-package-title-alist | |
69 '(("chinese-4corner" . "$(0(?-F(B") | |
70 ("chinese-array30" . "$(0#R#O(B") | |
71 ("chinese-ccdospy" . "$AKuF4(B") | |
72 ("chinese-ctlau" . "$AAuTA(B") | |
73 ("chinese-ctlaub" . "$(0N,Gn(B") | |
74 ("chinese-ecdict" . "$(05CKH(B") | |
75 ("chinese-etzy" . "$(06/0D(B") | |
76 ("chinese-punct-b5" . "$(0O:(BB") | |
77 ("chinese-punct" . "$A1j(BG") | |
78 ("chinese-py-b5" . "$(03<(BB") | |
79 ("chinese-py" . "$AF4(BG") | |
80 ("chinese-qj-b5" . "$(0)A(BB") | |
81 ("chinese-qj" . "$AH+(BG") | |
82 ("chinese-sw" . "$AJWN2(B") | |
83 ("chinese-tonepy" . "$A5wF4(B") | |
84 ("chinese-ziranma" . "$AK+F4(B") | |
85 ("chinese-zozy" . "$(0I\0D(B"))) | |
17052 | 86 |
87 ;; Return a value of the key in the current line. | |
88 (defsubst tit-read-key-value () | |
89 (if (looking-at "[^ \t\n]+") | |
90 (car (read-from-string (concat "\"" (match-string 0) "\""))))) | |
91 | |
92 ;; Return an appropriate quail-package filename from FILENAME (TIT | |
18555 | 93 ;; dictionary filename). For instance, ".../ZOZY.tit" -> "ZOZY.el". |
94 (defun tit-make-quail-package-file-name (filename &optional dirname) | |
17052 | 95 (expand-file-name |
18555 | 96 (concat (file-name-nondirectory (substring filename 0 -4)) ".el") |
17052 | 97 dirname)) |
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 | 101 (defvar tit-encode nil) |
102 (defvar tit-default-encode "GB") | |
103 | |
104 ;; Generate elements of KEY-BINDINGS arg for `quail-define-package' so | |
105 ;; that each characters in KEYS invokes FUNCTION-SYMBOL. | |
106 (defun tit-generate-key-bindings (keys function-symbol) | |
107 (let ((len (length keys)) | |
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 | 110 key) |
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 | 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 | 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 | 125 (setq i (1+ i))))) |
126 | |
127 ;; Analyze header part of TIT dictionary and generate an appropriate | |
128 ;; `quail-define-package' function call. | |
129 (defun tit-process-header (filename) | |
130 (message "Processing header part...") | |
131 (goto-char (point-min)) | |
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 | 140 (tit-multichoice t) |
141 (tit-prompt "") | |
142 (tit-comments nil) | |
143 (tit-backspace "\010\177") | |
144 (tit-deleteall "\015\025") | |
145 (tit-moveright ".>") | |
146 (tit-moveleft ",<") | |
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 | 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 | 162 (cond ((= ch ?C) ; COMMENT |
163 (cond ((looking-at "COMMENT") | |
164 (let ((pos (match-end 0))) | |
165 (end-of-line) | |
166 (setq tit-comments (cons (buffer-substring pos (point)) | |
167 tit-comments)))))) | |
168 ((= ch ?M) ; MULTICHOICE, MOVERIGHT, MOVELEFT | |
169 (cond ((looking-at "MULTICHOICE:[ \t]*") | |
170 (goto-char (match-end 0)) | |
171 (setq tit-multichoice (looking-at "YES"))) | |
172 ((looking-at "MOVERIGHT:[ \t]*") | |
173 (goto-char (match-end 0)) | |
174 (setq tit-moveright (tit-read-key-value))) | |
175 ((looking-at "MOVELEFT:[ \t]*") | |
176 (goto-char (match-end 0)) | |
177 (setq tit-moveleft (tit-read-key-value))))) | |
178 ((= ch ?P) ; PROMPT | |
179 (cond ((looking-at "PROMPT:[ \t]*") | |
180 (goto-char (match-end 0)) | |
181 (setq tit-prompt (tit-read-key-value))))) | |
182 ((= ch ?B) ; BACKSPACE, BEGINDICTIONARY, | |
183 ; BEGINPHRASE | |
184 (cond ((looking-at "BACKSPACE:[ \t]*") | |
185 (goto-char (match-end 0)) | |
186 (setq tit-backspace (tit-read-key-value))) | |
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 | 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 | 191 ((= ch ?K) ; KEYPROMPT |
192 (cond ((looking-at "KEYPROMPT(\\(.*\\)):[ \t]*") | |
193 (let ((key-char (match-string 1))) | |
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 | 199 (setq tit-keyprompt |
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 | 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 | 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 | 224 |
225 ;; Arg GUIDANCE | |
226 (if tit-keyprompt | |
227 (progn | |
20840
1842af0263da
Many codes re-written to adjust for
Kenichi Handa <handa@m17n.org>
parents:
20795
diff
changeset
|
228 (princ " '(") |
17052 | 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 | 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 | 237 |
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 | 242 |
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 | 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 | 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 | 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 | 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 | 253 |
254 ;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT. | |
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 | 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 | 277 |
278 ;; Convert body part of TIT dictionary into `quail-define-rules' | |
279 ;; function call. | |
280 (defun tit-process-body () | |
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 | 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 | 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 | 327 |
328 ;;;###autoload | |
329 (defun titdic-convert (filename &optional dirname) | |
330 "Convert a TIT dictionary of FILENAME into a Quail package. | |
331 Optional argument DIRNAME if specified is the directory name under which | |
332 the generated Quail package is saved." | |
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 | 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 | 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 | 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 | 378 |
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 | 381 "Run `titdic-convert' on the files remaining on the command line. |
382 Use this from the command line, with `-batch'; | |
383 it won't work in an interactive Emacs. | |
384 For example, invoke \"emacs -batch -f batch-titdic-convert XXX.tit\" to | |
385 generate Quail package file \"xxx.el\" from TIT dictionary file \"XXX.tit\". | |
386 To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"." | |
387 (defvar command-line-args-left) ; Avoid compiler warning. | |
388 (if (not noninteractive) | |
389 (error "`batch-titdic-convert' should be used only with -batch")) | |
390 (if (string= (car command-line-args-left) "-h") | |
391 (progn | |
392 (message "To convert XXX.tit and YYY.tit into xxx.el and yyy.el:") | |
393 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert XXX.tit YYY.tit") | |
394 (message "To convert XXX.tit into DIR/xxx.el:") | |
395 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert -dir DIR XXX.tit")) | |
396 (let (targetdir filename files file) | |
397 (if (string= (car command-line-args-left) "-dir") | |
398 (progn | |
399 (setq command-line-args-left (cdr command-line-args-left)) | |
400 (setq targetdir (car command-line-args-left)) | |
401 (setq command-line-args-left (cdr command-line-args-left)))) | |
402 (while command-line-args-left | |
403 (setq filename (expand-file-name (car command-line-args-left))) | |
404 (if (file-directory-p filename) | |
405 (progn | |
406 (message "Converting all tit files in the directory %s" filename) | |
407 (setq files (directory-files filename t "\\.tit$"))) | |
408 (setq files (list filename))) | |
409 (while files | |
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 | 416 (setq files (cdr files))) |
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 | 419 (message " %% emacs -batch -f batch-byte-compile XXX.el"))) |
420 (kill-emacs 0)) | |
421 | |
422 ;;; titdic-cnv.el ends here |