(jp-jouyou-read-file): New function.
[chise/xemacs-chise.git] / lisp / utf-2000 / read-maps.el
1 ;;; read-maps.el --- Read mapping-tables.
2
3 ;; Copyright (C) 2002,2003,2004 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: mapping table, character, CCS, multiscript, multilingual
7
8 ;; This file is part of XEmacs CHISE.
9
10 ;; XEmacs CHISE 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 CHISE 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 CHISE; 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-2000)
63                (goto-char (match-end 0))
64                )
65               ((looking-at "^C1-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
66                (setq ccs 'chinese-cns11643-1
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 "^C2-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
73                (setq ccs 'chinese-cns11643-2
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 "^C3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
80                (setq ccs 'chinese-cns11643-3
81                      code (string-to-int (match-string 1) 16)
82                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
83                      ucs-ccs 'ucs-cns)
84                (goto-char (match-end 0))
85                )
86               ((looking-at "^C4-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
87                (setq ccs 'chinese-cns11643-4
88                      code (string-to-int (match-string 1) 16)
89                      ucs-pat "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
90                      ucs-ccs 'ucs-cns)
91                (goto-char (match-end 0))
92                )
93               ((looking-at "^B-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
94                (setq ccs 'chinese-big5
95                      code (string-to-int (match-string 1) 16)
96                      ucs-pat "\tBU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)"
97                      ucs-ccs 'ucs-big5)
98                (goto-char (match-end 0))
99                )
100               ((looking-at "^JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)")
101                (setq ccs '=jef-china3
102                      code (string-to-int (match-string 1) 16)
103                      ucs-pat nil
104                      ucs-ccs nil)
105                (goto-char (match-end 0))
106                )
107               (t
108                (setq ccs nil
109                      code nil
110                      ucs-pat nil
111                      ucs-ccs nil)
112                ))
113         (setq ucs-code
114               (if (and ucs-pat
115                        (looking-at ucs-pat))
116                   (prog1
117                       (string-to-int (match-string 1) 16)
118                     (goto-char (match-end 0)))))
119         (setq ucs
120               (if (looking-at
121                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
122                   (string-to-int (match-string 1) 16)))
123         (when (setq chr (decode-char ccs code))
124           (unless (eq (encode-char chr ccs 'defined-only)
125                       code)
126             (put-char-attribute chr ccs code))
127           (when (and ucs-code
128                      (not (eq (or (encode-char chr ucs-ccs 'defined-only)
129                                   (get-char-attribute chr '=>ucs))
130                               ucs-code)))
131             (put-char-attribute chr ucs-ccs ucs-code))
132           (when (and ucs
133                      (not (eq (or (encode-char chr '=ucs 'defined-only)
134                                   (and (not (memq ucs-ccs '(ucs-jis
135                                                             =ucs-jis-1990
136                                                             =ucs-jis-2000
137                                                             ;; ucs-big5
138                                                             )))
139                                        (get-char-attribute chr '=>ucs)))
140                               ucs)))
141             (if (or ucs-code (null ucs-ccs))
142                 (put-char-attribute chr '=>ucs ucs)
143               (unless (eq (encode-char chr ucs-ccs 'defined-only)
144                           ucs)
145                 (put-char-attribute chr ucs-ccs ucs)))))
146         (forward-line)))))
147
148 (defun jp-jouyou-read-file (filename)
149   (interactive "fjp-jouyou file : ")
150   (with-temp-buffer
151     (buffer-disable-undo)
152     (insert-file-contents filename)
153     (goto-char (point-min))
154     (let (char tchars)
155       (while (re-search-forward "^[^\t\n ]+\t\\(.\\)\t*" nil t)
156         (setq char (aref (match-string 1) 0)
157               tchars (buffer-substring (match-end 0)
158                                        (point-at-eol)))
159         (when (> (length tchars) 0)
160           (setq tchars
161                 (mapcar (lambda (c)
162                           (aref c 0))
163                         (split-string tchars " ")))
164           (put-char-attribute char
165                               '<-simplified@JP/Jouyou
166                               tchars))
167         ;; (put-char-attribute
168         ;;  char 'script (adjoin
169         ;;                'JP
170         ;;                (adjoin
171         ;;                 'Jouyou
172         ;;                 (adjoin
173         ;;                  'Ideograph
174         ;;                  (get-char-attribute char 'script)))))
175         ))))
176
177 (provide 'read-maps)
178
179 ;;; read-maps.el ends here