New file.
[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 (with-temp-buffer
28   (buffer-disable-undo)
29   (dolist (file '("J90-to-UCS.txt" "JSP-to-UCS.txt"
30                   "JX1-to-UCS.txt" "JX2-to-UCS.txt"
31                   ;; "C3-to-UCS.txt" ; "C4-to-UCS.txt"
32                   "B-to-UCS.txt"))
33     (insert-file-contents (expand-file-name file "../etc/char-data/"))
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)
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 'japanese-jisx0213-1
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)
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 'japanese-jisx0213-2
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               (t
87                (setq ccs nil
88                      code nil
89                      ucs-pat nil
90                      ucs-ccs nil)
91                ))
92         (setq ucs-code
93               (if (looking-at ucs-pat)
94                   (prog1
95                       (string-to-int (match-string 1) 16)
96                     (goto-char (match-end 0)))))
97         (setq ucs
98               (if (looking-at
99                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
100                   (string-to-int (match-string 1) 16)))
101         (when (setq chr (decode-char ccs code))
102           (unless (eq (get-char-attribute chr ccs) code)
103             (put-char-attribute chr ccs code))
104           (when (and ucs-code
105                      (not (eq (or (get-char-attribute chr ucs-ccs)
106                                   (get-char-attribute chr 'ucs)
107                                   (get-char-attribute chr '=>ucs)
108                                   (get-char-attribute chr '->ucs))
109                               ucs-code)))
110             (put-char-attribute chr ucs-ccs ucs-code))
111           (when (and ucs
112                      (not (eq (or (get-char-attribute chr 'ucs)
113                                   (get-char-attribute chr '=>ucs)
114                                   (get-char-attribute chr '->ucs))
115                               ucs)))
116             (put-char-attribute chr (if ucs-code
117                                         '=>ucs
118                                       ucs-ccs) ucs)))
119         (forward-line)))
120     (erase-buffer)))
121
122 ;;; read-maps.el ends here