Mercurial > emacs
annotate lisp/international/titdic-cnv.el @ 19796:ea31f3e716e8
Continue previous change, add mipsel-*-openbsd*.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 07 Sep 1997 05:27:45 +0000 |
parents | 9c5fdc90d3c6 |
children | 23ada3fdbc8b |
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 | |
99 ;; This value is t if we are processing phrase dictionary. | |
100 (defvar tit-phrase nil) | |
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) | |
109 key) | |
110 (while (< i len) | |
111 (setq key (aref keys i)) | |
112 (indent-to 3) | |
113 (if (< key ?\ ) | |
114 (if (eq (lookup-key quail-translation-keymap (char-to-string key)) | |
115 'quail-execute-non-quail-command) | |
116 (insert (format "(\"\\C-%c\" . %s)\n" | |
117 (+ key ?@) function-symbol))) | |
118 (if (< key 127) | |
119 (insert (format "(\"%c\" . %s)\n" key function-symbol)) | |
120 (insert (format "(\"\\C-?\" . %s)\n" function-symbol)))) | |
121 (setq i (1+ i))))) | |
122 | |
123 ;; Analyze header part of TIT dictionary and generate an appropriate | |
124 ;; `quail-define-package' function call. | |
125 (defun tit-process-header (filename) | |
126 (message "Processing header part...") | |
127 (goto-char (point-min)) | |
128 | |
129 (let (;; TIT keywords and the corresponding default values. | |
130 (tit-multichoice t) | |
131 (tit-prompt "") | |
132 (tit-comments nil) | |
133 (tit-backspace "\010\177") | |
134 (tit-deleteall "\015\025") | |
135 (tit-moveright ".>") | |
136 (tit-moveleft ",<") | |
137 (tit-keyprompt nil)) | |
138 ;; At first, collect information from the header. | |
139 (while (not (eobp)) | |
140 (insert ";; ") | |
141 (let ((ch (following-char))) | |
142 (cond ((= ch ?C) ; COMMENT | |
143 (cond ((looking-at "COMMENT") | |
144 (let ((pos (match-end 0))) | |
145 (end-of-line) | |
146 (while (re-search-backward "[\"\\]" pos t) | |
147 (insert "\\") | |
148 (forward-char -1)) | |
149 (end-of-line) | |
150 (setq tit-comments (cons (buffer-substring pos (point)) | |
151 tit-comments)))))) | |
152 ((= ch ?M) ; MULTICHOICE, MOVERIGHT, MOVELEFT | |
153 (cond ((looking-at "MULTICHOICE:[ \t]*") | |
154 (goto-char (match-end 0)) | |
155 (setq tit-multichoice (looking-at "YES"))) | |
156 ((looking-at "MOVERIGHT:[ \t]*") | |
157 (goto-char (match-end 0)) | |
158 (setq tit-moveright (tit-read-key-value))) | |
159 ((looking-at "MOVELEFT:[ \t]*") | |
160 (goto-char (match-end 0)) | |
161 (setq tit-moveleft (tit-read-key-value))))) | |
162 ((= ch ?P) ; PROMPT | |
163 (cond ((looking-at "PROMPT:[ \t]*") | |
164 (goto-char (match-end 0)) | |
165 (setq tit-prompt (tit-read-key-value))))) | |
166 ((= ch ?B) ; BACKSPACE, BEGINDICTIONARY, | |
167 ; BEGINPHRASE | |
168 (cond ((looking-at "BACKSPACE:[ \t]*") | |
169 (goto-char (match-end 0)) | |
170 (setq tit-backspace (tit-read-key-value))) | |
171 ((looking-at "BEGINDICTIONARY") | |
172 (setq tit-phrase nil)) | |
173 ((looking-at "BEGINPHRASE") | |
174 (setq tit-phrase t)))) | |
175 ((= ch ?K) ; KEYPROMPT | |
176 (cond ((looking-at "KEYPROMPT(\\(.*\\)):[ \t]*") | |
177 (let ((key-char (match-string 1))) | |
178 (goto-char (match-end 0)) | |
179 (setq tit-keyprompt | |
180 (cons (cons key-char (tit-read-key-value)) | |
181 tit-keyprompt)))))))) | |
182 (forward-line 1)) | |
183 | |
184 ;; Then, generate header part of the Quail package. | |
185 (goto-char (point-min)) | |
18555 | 186 (let ((package |
187 (concat | |
188 "chinese-" | |
189 (substring (downcase (file-name-nondirectory buffer-file-name)) | |
190 0 -3)))) | |
191 (insert ";; Quail package `" | |
192 package | |
193 "' generated by the command `titdic-convert'\n" | |
194 ";;\tDate: " (current-time-string) "\n" | |
195 ";;\tOriginal TIT dictionary file: " | |
196 (file-name-nondirectory filename) | |
197 "\n\n" | |
198 ";;; Comment:\n\n" | |
199 ";; Do byte-compile this file again after any modification.\n\n" | |
200 ";;; Start of the header of original TIT dictionary.\n\n") | |
17052 | 201 |
18555 | 202 (goto-char (point-max)) |
203 (insert "\n" | |
204 ";;; End of the header of original TIT dictionary.\n\n" | |
205 ";;; Code:\n\n" | |
206 "(require 'quail)\n\n") | |
17052 | 207 |
18555 | 208 (insert "(quail-define-package ") |
209 ;; Args NAME, LANGUAGE, TITLE | |
210 (let ((title (cdr (assoc package quail-cxterm-package-title-alist)))) | |
211 (insert | |
212 "\"" | |
213 package | |
214 "\" \"" (nth 2 (assoc tit-encode tit-encode-list)) | |
215 "\" \"" | |
216 (or title | |
217 (if (string-match "[:$A!K$(0!(!J(B]+\\([^:$A!K$(0!(!K(B]+\\)" tit-prompt) | |
218 (substring tit-prompt (match-beginning 1) (match-end 1)) | |
219 tit-prompt)) | |
220 "\"\n")) | |
221 ) | |
17052 | 222 |
223 ;; Arg GUIDANCE | |
224 (if tit-keyprompt | |
225 (progn | |
226 (insert " '(") | |
227 (while tit-keyprompt | |
228 (indent-to 3) | |
229 (insert (format "(%d . \"%s\")\n" | |
230 (string-to-char (car (car tit-keyprompt))) | |
231 (cdr (car tit-keyprompt)))) | |
232 (setq tit-keyprompt (cdr tit-keyprompt))) | |
233 (forward-char -1) | |
234 (insert ")") | |
235 (forward-char 1)) | |
236 (insert " t\n")) | |
237 | |
238 ;; Arg DOCSTRING | |
239 (insert "\"" tit-prompt "\n") | |
240 (let ((l (nreverse tit-comments))) | |
241 (while l | |
242 (insert (format "%s\n" (car l))) | |
243 (setq l (cdr l)))) | |
244 (insert "\"\n") | |
245 | |
246 ;; Arg KEY-BINDINGS | |
247 (insert " '(") | |
248 (tit-generate-key-bindings tit-backspace 'quail-delete-last-char) | |
249 (tit-generate-key-bindings tit-deleteall 'quail-abort-translation) | |
250 (tit-generate-key-bindings tit-moveright 'quail-next-translation) | |
251 (tit-generate-key-bindings tit-moveleft 'quail-prev-translation) | |
252 (forward-char -1) | |
253 (insert ")") | |
254 (forward-char 1) | |
255 | |
256 ;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT. | |
257 ;; The remaining args are all nil. | |
258 (insert " nil" | |
259 (if tit-multichoice " nil" " t") | |
260 (if tit-keyprompt " t t)\n\n" " nil nil)\n\n"))) | |
261 | |
262 ;; Return the position of end of the header. | |
263 (point-max)) | |
264 | |
265 ;; Convert body part of TIT dictionary into `quail-define-rules' | |
266 ;; function call. | |
267 (defun tit-process-body () | |
268 (message "Formatting translation rules...") | |
269 (let ((enable-multibyte-characters nil) | |
270 (keyseq "\000") | |
271 pos) | |
272 (insert "(quail-define-rules\n") | |
273 (while (null (eobp)) | |
274 (if (or (= (following-char) ?#) (= (following-char) ?\n)) | |
18796
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
275 (progn |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
276 (insert ";; ") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
277 (forward-line 1)) |
17052 | 278 (insert "(\"") |
279 (setq pos (point)) | |
280 (skip-chars-forward "^ \t") | |
281 (setq keyseq | |
282 (concat (regexp-quote (buffer-substring pos (point))) "[ \t]+")) | |
283 (save-excursion | |
19431
9c5fdc90d3c6
(tit-process-body): Handle `\' used
Kenichi Handa <handa@m17n.org>
parents:
18831
diff
changeset
|
284 ;; Escape `"' and `\' which is not used for quoting the |
9c5fdc90d3c6
(tit-process-body): Handle `\' used
Kenichi Handa <handa@m17n.org>
parents:
18831
diff
changeset
|
285 ;; following octal digits. |
9c5fdc90d3c6
(tit-process-body): Handle `\' used
Kenichi Handa <handa@m17n.org>
parents:
18831
diff
changeset
|
286 (while (re-search-backward "\"\\|\\\\[^0-9]" pos t) |
17052 | 287 (insert "\\") |
288 (forward-char -1))) | |
289 (insert "\"") | |
290 (skip-chars-forward " \t") | |
291 | |
292 ;; Now point is at the start of translations. Remember it in | |
293 ;; POS and combine lines of the same key sequence while | |
294 ;; deleting trailing white spaces and comments (start with | |
295 ;; '#'). POS doesn't has to be a marker because we never | |
296 ;; modify region before POS. | |
297 (setq pos (point)) | |
298 (if (looking-at "[^ \t]*\\([ \t]*#.*\\)") | |
299 (delete-region (match-beginning 1) (match-end 1))) | |
300 (while (and (= (forward-line 1) 0) | |
301 (looking-at keyseq)) | |
302 (let ((p (match-end 0))) | |
303 (skip-chars-backward " \t\n") | |
304 (delete-region (point) p) | |
305 (if tit-phrase (insert " ")) | |
306 (if (looking-at "[^ \t]*\\([ \t]*#.*\\)") | |
307 (delete-region (match-beginning 1) (match-end 1))) | |
308 )) | |
309 | |
310 (goto-char pos) | |
18796
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
311 (if (eolp) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
312 ;; This entry contains no translations. Let's ignore it. |
17052 | 313 (progn |
18796
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
314 (beginning-of-line) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
315 (setq pos (point)) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
316 (forward-line 1) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
317 (delete-region pos (point))) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
318 |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
319 ;; Modify the current line to meet the syntax of Quail package. |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
320 (if tit-phrase |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
321 (progn |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
322 ;; PHRASE1 PHRASE2 ... => ["PHRASE1" "PHRASE2" ...] |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
323 (insert "[\"") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
324 (skip-chars-forward "^ \t\n") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
325 (while (not (eolp)) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
326 (insert "\"") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
327 (forward-char 1) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
328 (insert "\"") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
329 (skip-chars-forward "^ \t\n")) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
330 (insert "\"])")) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
331 ;; TRANSLATIONS => "TRANSLATIONS" |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
332 (insert "\"") |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
333 (end-of-line) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
334 (insert "\")")) |
ab40b57484c1
(tit-process-body): Ignore vacant entries.
Kenichi Handa <handa@m17n.org>
parents:
18555
diff
changeset
|
335 (forward-line 1)))) |
17052 | 336 (insert ")\n"))) |
337 | |
338 ;;;###autoload | |
339 (defun titdic-convert (filename &optional dirname) | |
340 "Convert a TIT dictionary of FILENAME into a Quail package. | |
341 Optional argument DIRNAME if specified is the directory name under which | |
342 the generated Quail package is saved." | |
343 (interactive "FTIT dictionary file: ") | |
344 (let ((buf (get-buffer-create "*tit-work*"))) | |
345 (save-excursion | |
346 ;; Setup the buffer. | |
347 (set-buffer buf) | |
348 (erase-buffer) | |
349 (let ((coding-system-for-read 'no-conversion)) | |
350 (insert-file-contents (expand-file-name filename))) | |
18555 | 351 (set-visited-file-name |
352 (tit-make-quail-package-file-name filename dirname) t) | |
18202
1fe28ee1b0cd
Coding system name changed from
Kenichi Handa <handa@m17n.org>
parents:
17098
diff
changeset
|
353 (set-buffer-file-coding-system 'iso-2022-7bit) |
17052 | 354 |
355 ;; Decode the buffer contents from the encoding specified by a | |
356 ;; value of the key "ENCODE:". | |
357 (let (coding-system) | |
358 (save-excursion | |
359 (if (search-forward "\nBEGIN" nil t) | |
360 (let ((limit (point)) | |
361 slot) | |
362 (goto-char 1) | |
363 (if (re-search-forward "^ENCODE:[ \t]*" limit t) | |
364 (progn | |
365 (goto-char (match-end 0)) | |
366 (setq tit-encode (tit-read-key-value))) | |
367 (setq tit-encode tit-default-encode)) | |
368 (setq slot (assoc tit-encode tit-encode-list)) | |
369 (if slot | |
370 (setq coding-system (nth 1 slot)) | |
371 (error "Invalid ENCODE: value in TIT dictionary"))) | |
372 (error "TIT dictionary doesn't have body part"))) | |
373 (message "Decoding %s..." coding-system) | |
374 (goto-char 1) | |
375 (decode-coding-region 1 (point-max) coding-system)) | |
376 | |
377 ;; Set point the starting position of the body part. | |
378 (goto-char 1) | |
379 (if (search-forward "\nBEGIN" nil t) | |
380 (forward-line 1) | |
381 (error "TIT dictionary can't be decoded correctly")) | |
382 | |
383 ;; Now process the header and body parts. | |
384 (goto-char | |
385 (save-excursion | |
386 (save-restriction | |
387 (narrow-to-region 1 (point)) | |
388 (tit-process-header filename)))) | |
389 (tit-process-body)) | |
390 | |
391 (if noninteractive | |
392 ;; Save the Quail package file. | |
393 (save-excursion | |
394 (set-buffer buf) | |
395 (save-buffer 0)) | |
396 ;; Show the Quail package just generated. | |
397 (switch-to-buffer buf) | |
398 (goto-char 1) | |
399 (message "Save this buffer after you make any modification")))) | |
400 | |
401 ;;;###autoload | |
18831
e6f6c2712a5f
(batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents:
18796
diff
changeset
|
402 (defun batch-titdic-convert (&optional force) |
17052 | 403 "Run `titdic-convert' on the files remaining on the command line. |
404 Use this from the command line, with `-batch'; | |
405 it won't work in an interactive Emacs. | |
406 For example, invoke \"emacs -batch -f batch-titdic-convert XXX.tit\" to | |
407 generate Quail package file \"xxx.el\" from TIT dictionary file \"XXX.tit\". | |
408 To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"." | |
409 (defvar command-line-args-left) ; Avoid compiler warning. | |
410 (if (not noninteractive) | |
411 (error "`batch-titdic-convert' should be used only with -batch")) | |
412 (if (string= (car command-line-args-left) "-h") | |
413 (progn | |
414 (message "To convert XXX.tit and YYY.tit into xxx.el and yyy.el:") | |
415 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert XXX.tit YYY.tit") | |
416 (message "To convert XXX.tit into DIR/xxx.el:") | |
417 (message " %% emacs -batch -l titdic-cnv -f batch-titdic-convert -dir DIR XXX.tit")) | |
418 (let (targetdir filename files file) | |
419 (if (string= (car command-line-args-left) "-dir") | |
420 (progn | |
421 (setq command-line-args-left (cdr command-line-args-left)) | |
422 (setq targetdir (car command-line-args-left)) | |
423 (setq command-line-args-left (cdr command-line-args-left)))) | |
424 (while command-line-args-left | |
425 (setq filename (expand-file-name (car command-line-args-left))) | |
426 (if (file-directory-p filename) | |
427 (progn | |
428 (message "Converting all tit files in the directory %s" filename) | |
429 (setq files (directory-files filename t "\\.tit$"))) | |
430 (setq files (list filename))) | |
431 (while files | |
432 (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
|
433 (when (or force |
e6f6c2712a5f
(batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents:
18796
diff
changeset
|
434 (file-newer-than-file-p |
e6f6c2712a5f
(batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents:
18796
diff
changeset
|
435 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
|
436 (message "Converting %s to quail-package..." file) |
e6f6c2712a5f
(batch-titdic-convert): Add optional arg FORCE.
Kenichi Handa <handa@m17n.org>
parents:
18796
diff
changeset
|
437 (titdic-convert file targetdir)) |
17052 | 438 (setq files (cdr files))) |
439 (setq command-line-args-left (cdr command-line-args-left))) | |
440 (message "Do byte-compile the created files by:") | |
441 (message " %% emacs -batch -f batch-byte-compile XXX.el"))) | |
442 (kill-emacs 0)) | |
443 | |
444 ;;; titdic-cnv.el ends here |