Sync with r21-2-44-utf-2000-0_18m-uj90.
[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               (t
85                (setq ccs nil
86                      code nil
87                      ucs-pat nil
88                      ucs-ccs nil)
89                ))
90         (setq ucs-code
91               (if (looking-at ucs-pat)
92                   (prog1
93                       (string-to-int (match-string 1) 16)
94                     (goto-char (match-end 0)))))
95         (setq ucs
96               (if (looking-at
97                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
98                   (string-to-int (match-string 1) 16)))
99         (when (setq chr (decode-char ccs code))
100           (unless (eq (get-char-attribute chr ccs) code)
101             (put-char-attribute chr ccs code))
102           (when (and ucs-code
103                      (not (eq (or (get-char-attribute chr ucs-ccs)
104                                   (get-char-attribute chr 'ucs)
105                                   (get-char-attribute chr '=>ucs)
106                                   (get-char-attribute chr '->ucs))
107                               ucs-code)))
108             (put-char-attribute chr ucs-ccs ucs-code))
109           (when (and ucs
110                      (not (eq (or (get-char-attribute chr 'ucs)
111                                   (get-char-attribute chr '=>ucs)
112                                   (get-char-attribute chr '->ucs))
113                               ucs)))
114             (put-char-attribute chr (if ucs-code
115                                         '=>ucs
116                                       ucs-ccs) ucs)))
117         (forward-line)))))
118
119 (dolist (file '("J90-to-UCS.txt" "JSP-to-UCS.txt"
120                 "JX1-to-UCS.txt" "JX2-to-UCS.txt"
121                 ;; "C3-to-UCS.txt" ; "C4-to-UCS.txt"
122                 "B-to-UCS.txt"))
123   (mapping-table-read-file (expand-file-name file "../etc/char-data/")))
124
125 ;;; read-maps.el ends here