annotate lisp/international/titdic-cnv.el @ 20112:6e6838a12511

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