Merge r21-4-11-chise-0_20-=ucs.
[chise/xemacs-chise.git.1] / lisp / utf-2000 / read-maps.el
1 ;;; read-maps.el --- Read mapping-tables.
2
3 ;; Copyright (C) 2002,2003 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: UTF-2000, UCS-4, character, CCS, multiscript, multilingual
7
8 ;; This file is part of XEmacs UTF-2000.
9
10 ;; XEmacs UTF-2000 is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; XEmacs UTF-2000 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 GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs UTF-2000; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 ;;;###autoload
28 (defun mapping-table-read-file (filename)
29   "Read mapping table." 
30   (interactive "fMapping table : ")
31   (with-temp-buffer
32     (buffer-disable-undo)
33     (insert-file-contents filename)
34     (goto-char (point-min))
35     (let (line ccs code ucs ucs-pat ucs-ccs ucs-code chr)
36       (while (not (eobp))
37         (cond ((looking-at "^J90-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
38                (setq ccs 'japanese-jisx0208-1990
39                      code (string-to-int (match-string 1) 16)
40                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
41                      ucs-ccs 'ucs-jis)
42                (goto-char (match-end 0))
43                )
44               ((looking-at "^JSP-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
45                (setq ccs 'japanese-jisx0212
46                      code (string-to-int (match-string 1) 16)
47                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
48                      ucs-ccs '=ucs-jis-1990)
49                (goto-char (match-end 0))
50                )
51               ((looking-at "^JX1-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
52                (setq ccs '=jis-x0213-1-2000
53                      code (string-to-int (match-string 1) 16)
54                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
55                      ucs-ccs '=ucs-jis-2000)
56                (goto-char (match-end 0))
57                )
58               ((looking-at "^JX2-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
59                (setq ccs '=jis-x0213-2-2000
60                      code (string-to-int (match-string 1) 16)
61                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
62                      ucs-ccs 'ucs-jis)
63                (goto-char (match-end 0))
64                )
65               ((looking-at "^C3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
66                (setq ccs 'chinese-cns11643-3
67                      code (string-to-int (match-string 1) 16)
68                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
69                      ucs-ccs 'ucs-cns)
70                (goto-char (match-end 0))
71                )
72               ((looking-at "^C4-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
73                (setq ccs 'chinese-cns11643-4
74                      code (string-to-int (match-string 1) 16)
75                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
76                      ucs-ccs 'ucs-cns)
77                (goto-char (match-end 0))
78                )
79               ((looking-at "^B-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
80                (setq ccs 'chinese-big5
81                      code (string-to-int (match-string 1) 16)
82                      ucs-pat "\tBU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
83                      ucs-ccs 'ucs-big5)
84                (goto-char (match-end 0))
85                )
86               ((looking-at "^JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
87                (setq ccs '=jef-china3
88                      code (string-to-int (match-string 1) 16)
89                      ucs-pat nil
90                      ucs-ccs nil)
91                (goto-char (match-end 0))
92                )
93               (t
94                (setq ccs nil
95                      code nil
96                      ucs-pat nil
97                      ucs-ccs nil)
98                ))
99         (setq ucs-code
100               (if (and ucs-pat
101                        (looking-at ucs-pat))
102                   (prog1
103                       (string-to-int (match-string 1) 16)
104                     (goto-char (match-end 0)))))
105         (setq ucs
106               (if (looking-at
107                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
108                   (string-to-int (match-string 1) 16)))
109         (when (setq chr (decode-char ccs code))
110           (unless (eq (encode-char chr ccs 'defined-only)
111                       code)
112             (put-char-attribute chr ccs code))
113           (when (and ucs-code
114                      (not (eq (or (encode-char chr ucs-ccs 'defined-only)
115                                   (get-char-attribute chr '=>ucs))
116                               ucs-code)))
117             (put-char-attribute chr ucs-ccs ucs-code))
118           (when (and ucs
119                      (not (eq (or (encode-char chr '=ucs 'defined-only)
120                                   (and (not (eq ucs-ccs 'ucs-jis))
121                                        (get-char-attribute chr '=>ucs)))
122                               ucs)))
123             (if (or ucs-code (null ucs-ccs))
124                 (put-char-attribute chr '=>ucs ucs)
125               (unless (eq (encode-char chr ucs-ccs 'defined-only)
126                           ucs)
127                 (put-char-attribute chr ucs-ccs ucs)))))
128         (forward-line)))))
129
130
131 (provide 'read-maps)
132
133 ;;; read-maps.el ends here