Merge r21-4-7-utf-2000-5.
[chise/xemacs-chise.git] / lisp / utf-2000 / read-maps.el
1 ;;; read-maps.el --- Read mapping-tables.
2
3 ;; Copyright (C) 2002 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 (defun mapping-table-read-file (filename)
28   (interactive "fMapping table : ")
29   (with-temp-buffer
30     (buffer-disable-undo)
31     (insert-file-contents filename)
32     (goto-char (point-min))
33     (let (line ccs code ucs ucs-pat ucs-ccs ucs-code chr)
34       (while (not (eobp))
35         (cond ((looking-at "^J90-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
36                (setq ccs 'japanese-jisx0208-1990
37                      code (string-to-int (match-string 1) 16)
38                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
39                      ucs-ccs 'ucs-jis)
40                (goto-char (match-end 0))
41                )
42               ((looking-at "^JSP-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
43                (setq ccs 'japanese-jisx0212
44                      code (string-to-int (match-string 1) 16)
45                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
46                      ucs-ccs 'ucs-jis)
47                (goto-char (match-end 0))
48                )
49               ((looking-at "^JX1-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
50                (setq ccs 'japanese-jisx0213-1
51                      code (string-to-int (match-string 1) 16)
52                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
53                      ucs-ccs 'ucs-jis)
54                (goto-char (match-end 0))
55                )
56               ((looking-at "^JX2-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
57                (setq ccs 'japanese-jisx0213-2
58                      code (string-to-int (match-string 1) 16)
59                      ucs-pat "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
60                      ucs-ccs 'ucs-jis)
61                (goto-char (match-end 0))
62                )
63               ((looking-at "^C3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
64                (setq ccs 'chinese-cns11643-3
65                      code (string-to-int (match-string 1) 16)
66                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
67                      ucs-ccs 'ucs-cns)
68                (goto-char (match-end 0))
69                )
70               ((looking-at "^C4-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
71                (setq ccs 'chinese-cns11643-4
72                      code (string-to-int (match-string 1) 16)
73                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
74                      ucs-ccs 'ucs-cns)
75                (goto-char (match-end 0))
76                )
77               ((looking-at "^B-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
78                (setq ccs 'chinese-big5
79                      code (string-to-int (match-string 1) 16)
80                      ucs-pat "\tBU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
81                      ucs-ccs 'ucs-big5)
82                (goto-char (match-end 0))
83                )
84               ((looking-at "^JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
85                (setq ccs 'china3-jef
86                      code (string-to-int (match-string 1) 16)
87                      ucs-pat nil
88                      ucs-ccs nil)
89                (goto-char (match-end 0))
90                )
91               (t
92                (setq ccs nil
93                      code nil
94                      ucs-pat nil
95                      ucs-ccs nil)
96                ))
97         (setq ucs-code
98               (if (and ucs-pat
99                        (looking-at ucs-pat))
100                   (prog1
101                       (string-to-int (match-string 1) 16)
102                     (goto-char (match-end 0)))))
103         (setq ucs
104               (if (looking-at
105                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
106                   (string-to-int (match-string 1) 16)))
107         (when (setq chr (decode-char ccs code))
108           (unless (eq (get-char-attribute chr ccs) code)
109             (put-char-attribute chr ccs code))
110           (when (and ucs-code
111                      (not (eq (or (get-char-attribute chr ucs-ccs)
112                                   (get-char-attribute chr 'ucs)
113                                   (get-char-attribute chr '=>ucs))
114                               ucs-code)))
115             (put-char-attribute chr ucs-ccs ucs-code))
116           (when (and ucs
117                      (not (eq (or (get-char-attribute chr 'ucs)
118                                   (get-char-attribute chr '=>ucs))
119                               ucs)))
120             (put-char-attribute chr
121                                 (if ucs-code
122                                     '=>ucs
123                                   (or ucs-ccs
124                                       '=>ucs))
125                                 ucs)))
126         (forward-line)))))
127
128 (dolist (file '("J90-to-UCS.txt" "JSP-to-UCS.txt"
129                 "JX1-to-UCS.txt" "JX2-to-UCS.txt"
130                 ;; "C3-to-UCS.txt" ; "C4-to-UCS.txt"
131                 "B-to-UCS.txt" "JC3-to-UCS.txt"))
132   (mapping-table-read-file (expand-file-name file "../etc/char-data/")))
133
134 ;;; read-maps.el ends here