diff options
| -rw-r--r-- | lisp/international/titdic-cnv.el | 110 |
1 files changed, 69 insertions, 41 deletions
diff --git a/lisp/international/titdic-cnv.el b/lisp/international/titdic-cnv.el index 6c0edaab239..6c60d2cbdca 100644 --- a/lisp/international/titdic-cnv.el +++ b/lisp/international/titdic-cnv.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; titdic-cnv.el --- convert TIT dictionary to Quail package | 1 | ;;; titdic-cnv.el --- convert cxterm dictionary (TIT format) to Quail package |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | 3 | ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. |
| 4 | ;; Licensed to the Free Software Foundation. | 4 | ;; Licensed to the Free Software Foundation. |
| @@ -24,12 +24,12 @@ | |||
| 24 | 24 | ||
| 25 | ;;; Comments: | 25 | ;;; Comments: |
| 26 | 26 | ||
| 27 | ;; Convert TIT format dictionary (of cxterm) to quail-package. | 27 | ;; Convert cxterm dictionary (of TIT format) to quail-package. |
| 28 | ;; | 28 | ;; |
| 29 | ;; Usage (within Emacs): | 29 | ;; Usage (within Emacs): |
| 30 | ;; M-x titdic-convert<CR>TIT-FILE-NAME<CR> | 30 | ;; M-x titdic-convert<CR>CXTERM-DICTIONARY-NAME<CR> |
| 31 | ;; Usage (from shell): | 31 | ;; Usage (from shell): |
| 32 | ;; % emacs -batch -l titdic-convert -f batch-titdic-convert\ | 32 | ;; % emacs -batch -l titdic-cnv -f batch-titdic-convert\ |
| 33 | ;; [-dir DIR] [DIR | FILE] ... | 33 | ;; [-dir DIR] [DIR | FILE] ... |
| 34 | ;; | 34 | ;; |
| 35 | ;; When you run titdic-convert within Emacs, you have a chance to | 35 | ;; When you run titdic-convert within Emacs, you have a chance to |
| @@ -37,7 +37,7 @@ | |||
| 37 | ;; converted file. For instance, you are likely to modify TITLE, | 37 | ;; converted file. For instance, you are likely to modify TITLE, |
| 38 | ;; DOCSTRING, and KEY-BINDINGS. | 38 | ;; DOCSTRING, and KEY-BINDINGS. |
| 39 | 39 | ||
| 40 | ;; TIT dictionary file (*.tit) is a line-oriented text (English, | 40 | ;; Cxterm dictionary file (*.tit) is a line-oriented text (English, |
| 41 | ;; Chinese, Japanese, and Korean) file. The whole file contains of | 41 | ;; Chinese, Japanese, and Korean) file. The whole file contains of |
| 42 | ;; two parts, the definition part (`header' here after) followed by | 42 | ;; two parts, the definition part (`header' here after) followed by |
| 43 | ;; the dictionary part (`body' here after). All lines begin with | 43 | ;; the dictionary part (`body' here after). All lines begin with |
| @@ -56,13 +56,33 @@ | |||
| 56 | 56 | ||
| 57 | (require 'quail) | 57 | (require 'quail) |
| 58 | 58 | ||
| 59 | ;; List of values of key "ENCODE:" and the corresponding Emacs' | 59 | ;; List of values of key "ENCODE:" and the corresponding Emacs |
| 60 | ;; coding-system and language environment name. | 60 | ;; coding-system and language environment name. |
| 61 | (defvar tit-encode-list | 61 | (defvar tit-encode-list |
| 62 | '(("GB" euc-china "Chinese-GB") | 62 | '(("GB" euc-china "Chinese-GB") |
| 63 | ("BIG5" cn-big5 "Chinese-BIG5") | 63 | ("BIG5" cn-big5 "Chinese-BIG5") |
| 64 | ("JIS" euc-japan "Japanese") | 64 | ("JIS" euc-japan "Japanese") |
| 65 | ("KS" euc-kk "Korean"))) | 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"))) | ||
| 66 | 86 | ||
| 67 | ;; Return a value of the key in the current line. | 87 | ;; Return a value of the key in the current line. |
| 68 | (defsubst tit-read-key-value () | 88 | (defsubst tit-read-key-value () |
| @@ -70,10 +90,10 @@ | |||
| 70 | (car (read-from-string (concat "\"" (match-string 0) "\""))))) | 90 | (car (read-from-string (concat "\"" (match-string 0) "\""))))) |
| 71 | 91 | ||
| 72 | ;; Return an appropriate quail-package filename from FILENAME (TIT | 92 | ;; Return an appropriate quail-package filename from FILENAME (TIT |
| 73 | ;; dictionary filename). For instance, ".../ZOZY.tit" -> "zozy.el". | 93 | ;; dictionary filename). For instance, ".../ZOZY.tit" -> "ZOZY.el". |
| 74 | (defun tit-make-quail-package-name (filename &optional dirname) | 94 | (defun tit-make-quail-package-file-name (filename &optional dirname) |
| 75 | (expand-file-name | 95 | (expand-file-name |
| 76 | (concat (downcase (file-name-nondirectory (substring filename 0 -4))) ".el") | 96 | (concat (file-name-nondirectory (substring filename 0 -4)) ".el") |
| 77 | dirname)) | 97 | dirname)) |
| 78 | 98 | ||
| 79 | ;; This value is t if we are processing phrase dictionary. | 99 | ;; This value is t if we are processing phrase dictionary. |
| @@ -163,35 +183,42 @@ | |||
| 163 | 183 | ||
| 164 | ;; Then, generate header part of the Quail package. | 184 | ;; Then, generate header part of the Quail package. |
| 165 | (goto-char (point-min)) | 185 | (goto-char (point-min)) |
| 166 | (insert ";; Quail package `" | 186 | (let ((package |
| 167 | (substring (file-name-nondirectory buffer-file-name) 0 -3) | 187 | (concat |
| 168 | "' generated by the command `titdic-convert'\n" | 188 | "chinese-" |
| 169 | ";;\tDate: " (current-time-string) "\n" | 189 | (substring (downcase (file-name-nondirectory buffer-file-name)) |
| 170 | ";;\tOriginal TIT dictionary file: " | 190 | 0 -3)))) |
| 171 | (file-name-nondirectory filename) | 191 | (insert ";; Quail package `" |
| 172 | "\n\n" | 192 | package |
| 173 | ";;; Comment:\n\n" | 193 | "' generated by the command `titdic-convert'\n" |
| 174 | ";; Do byte-compile this file again after any modification.\n\n" | 194 | ";;\tDate: " (current-time-string) "\n" |
| 175 | ";;; Start of the header of original TIT dictionary.\n\n") | 195 | ";;\tOriginal TIT dictionary file: " |
| 176 | 196 | (file-name-nondirectory filename) | |
| 177 | (goto-char (point-max)) | 197 | "\n\n" |
| 178 | (insert "\n" | 198 | ";;; Comment:\n\n" |
| 179 | ";;; End of the header of original TIT dictionary.\n\n" | 199 | ";; Do byte-compile this file again after any modification.\n\n" |
| 180 | ";;; Code:\n\n" | 200 | ";;; Start of the header of original TIT dictionary.\n\n") |
| 181 | "(require 'quail)\n\n") | 201 | |
| 182 | 202 | (goto-char (point-max)) | |
| 183 | (insert "(quail-define-package ") | 203 | (insert "\n" |
| 184 | ;; Args NAME, LANGUAGE, TITLE | 204 | ";;; End of the header of original TIT dictionary.\n\n" |
| 185 | (insert | 205 | ";;; Code:\n\n" |
| 186 | "\"" | 206 | "(require 'quail)\n\n") |
| 187 | (concat "quail-" | 207 | |
| 188 | (substring (file-name-nondirectory buffer-file-name) 0 -3)) | 208 | (insert "(quail-define-package ") |
| 189 | "\" \"" (nth 2 (assoc tit-encode tit-encode-list)) | 209 | ;; Args NAME, LANGUAGE, TITLE |
| 190 | "\" \"" | 210 | (let ((title (cdr (assoc package quail-cxterm-package-title-alist)))) |
| 191 | (if (string-match "[:$A!K$(0!(!J(B]+\\([^:$A!K$(0!(!K(B]+\\)" tit-prompt) | 211 | (insert |
| 192 | (substring tit-prompt (match-beginning 1) (match-end 1)) | 212 | "\"" |
| 193 | tit-prompt) | 213 | package |
| 194 | "\"\n") | 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 | ) | ||
| 195 | 222 | ||
| 196 | ;; Arg GUIDANCE | 223 | ;; Arg GUIDANCE |
| 197 | (if tit-keyprompt | 224 | (if tit-keyprompt |
| @@ -309,7 +336,8 @@ the generated Quail package is saved." | |||
| 309 | (erase-buffer) | 336 | (erase-buffer) |
| 310 | (let ((coding-system-for-read 'no-conversion)) | 337 | (let ((coding-system-for-read 'no-conversion)) |
| 311 | (insert-file-contents (expand-file-name filename))) | 338 | (insert-file-contents (expand-file-name filename))) |
| 312 | (set-visited-file-name (tit-make-quail-package-name filename dirname) t) | 339 | (set-visited-file-name |
| 340 | (tit-make-quail-package-file-name filename dirname) t) | ||
| 313 | (set-buffer-file-coding-system 'iso-2022-7bit) | 341 | (set-buffer-file-coding-system 'iso-2022-7bit) |
| 314 | 342 | ||
| 315 | ;; Decode the buffer contents from the encoding specified by a | 343 | ;; Decode the buffer contents from the encoding specified by a |
| @@ -391,7 +419,7 @@ To get complete usage, invoke \"emacs -batch -f batch-titdic-convert -h\"." | |||
| 391 | (while files | 419 | (while files |
| 392 | (setq file (expand-file-name (car files))) | 420 | (setq file (expand-file-name (car files))) |
| 393 | (if (file-newer-than-file-p | 421 | (if (file-newer-than-file-p |
| 394 | file (tit-make-quail-package-name file targetdir)) | 422 | file (tit-make-quail-package-file-name file targetdir)) |
| 395 | (progn | 423 | (progn |
| 396 | (message "Converting %s to quail-package..." file) | 424 | (message "Converting %s to quail-package..." file) |
| 397 | (titdic-convert file targetdir))) | 425 | (titdic-convert file targetdir))) |