(mapping-table-ccs-setting-alist): Add setting for CNS 11643-5.
[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 (defvar mapping-table-ccs-setting-alist
28   '((=jis-x0208@1990
29      "^J90-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
30      =ucs@jis
31      "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
32     (=jis-x0212
33      "^JSP-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
34      =ucs@jis/1990
35      "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
36     (=jis-x0213-1-2000
37      "^JX1-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
38      =ucs@jis/2000
39      "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
40     (=jis-x0213-2-2000
41      "^JX2-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
42      =ucs@jis/2000
43      "\tJU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
44     (=gb2312
45      "^G0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
46      =ucs@gb
47      "\tGU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
48     (=cns11643-1
49      "^C1-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
50      =ucs@cns
51      "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
52     (=cns11643-2     
53      "^C2-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
54      =ucs@cns
55      "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
56     (=cns11643-3
57      "^C3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
58      =ucs@cns
59      "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
60     (=cns11643-4
61      "^C4-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
62      =ucs@cns
63      "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
64     (=cns11643-5
65      "^C5-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
66      =ucs@cns
67      "\tCU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
68     (=big5     
69      "^B-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
70      =ucs@big5
71      "\tBU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
72     (=jef-china3     
73      "^JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
74      nil
75      nil)
76     )
77   "*List of information about mapping table formats.
78 Elements are of the form
79 \(CCS CODE-REGEXP PAREN-EXP BASE UCS-CCS UCS-REGEXP).
80
81 CCS     is a symbol, which is a name of a target coded-charset.
82
83 CODE-REGEXP is a regular expression to match against
84         the representation of the target coded-charset.
85
86 PAREN-EXP is a number specifies which parenthesized expression
87         in the CODE-REGEXP.
88
89 BASE    base of code in the string specified by CODE-REGEXP and
90         PAREN-EXP.
91
92 UCS-CCS is a symbol, which is a name of a UCS-CCS.
93
94 UCS-REGEXP is a regular expression to match against
95         the representation of the UCS-CCS.")
96
97 ;;;###autoload
98 (defun mapping-table-read-file (filename)
99   "Read mapping table." 
100   (interactive "fMapping table : ")
101   (with-temp-buffer
102     (buffer-disable-undo)
103     (insert-file-contents filename)
104     (goto-char (point-min))
105     (let (rest setting ccs code ucs ucs-pat ucs-ccs ucs-code chr)
106       (while (not (eobp))
107         (setq rest mapping-table-ccs-setting-alist)
108         (catch 'matched
109           (while rest
110             (setq setting (car rest)
111                   ccs (pop setting))
112             (when (looking-at (pop setting))
113               (setq code (string-to-int (match-string (pop setting))
114                                         (pop setting))
115                     ucs-ccs (pop setting)
116                     ucs-pat (car setting))
117               (goto-char (match-end 0))
118               (throw 'matched t))
119             (setq rest (cdr rest)))
120           (setq ccs nil
121                 code nil
122                 ucs-pat nil
123                 ucs-ccs nil))
124         (setq ucs-code
125               (if (and ucs-pat
126                        (looking-at ucs-pat))
127                   (prog1
128                       (string-to-int (match-string 1) 16)
129                     (goto-char (match-end 0)))))
130         (setq ucs
131               (if (looking-at
132                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
133                   (string-to-int (match-string 1) 16)))
134         (if (and ucs-ccs ucs (not ucs-code))
135             (setq ucs-code ucs
136                   ucs nil))
137         (when (setq chr (decode-char ccs code))
138           (unless (eq (encode-char chr ccs 'defined-only)
139                       code)
140             (put-char-attribute chr ccs code))
141           (when (and ucs-code
142                      (not
143                       (eq (or
144                            (encode-char chr ucs-ccs 'defined-only)
145                            (cond
146                             ((memq ucs-ccs '(=ucs@jis
147                                              =ucs@jis/1990
148                                              =ucs@jis/2000))
149                              (encode-char chr '=ucs@jis/fw 'defined-only))
150                             ((eq ucs-ccs '=ucs@gb)
151                              (encode-char chr '=ucs@gb/fw 'defined-only))
152                             (t
153                              (char-feature chr '=>ucs))))
154                           ucs-code)))
155             (put-char-attribute chr ucs-ccs ucs-code))
156           (when (and ucs
157                      (not (eq (or (encode-char chr '=ucs 'defined-only)
158                                   (and (not (memq ucs-ccs '(=ucs@jis
159                                                             =ucs@jis/1990
160                                                             =ucs@jis/2000
161                                                             =ucs@gb
162                                                             =ucs@big5
163                                                             )))
164                                        (char-feature chr '=>ucs)))
165                               ucs)))
166             (if (or ucs-code (null ucs-ccs))
167                 (unless (eq (char-feature chr '=>ucs) ucs)
168                   (put-char-attribute chr '=>ucs ucs))
169               (unless (eq (encode-char chr ucs-ccs 'defined-only)
170                           ucs)
171                 (put-char-attribute chr ucs-ccs ucs)))))
172         (forward-line)))))
173
174 (defun jp-jouyou-read-file (filename)
175   (interactive "fjp-jouyou file : ")
176   (with-temp-buffer
177     (buffer-disable-undo)
178     (insert-file-contents filename)
179     (goto-char (point-min))
180     (let (char tchars)
181       (while (re-search-forward "^[^\t\n ]+\t\\(.\\)\t*" nil t)
182         (setq char (aref (match-string 1) 0)
183               tchars (buffer-substring (match-end 0)
184                                        (point-at-eol)))
185         (when (> (length tchars) 0)
186           (setq tchars
187                 (mapcar (lambda (c)
188                           (aref c 0))
189                         (split-string tchars " ")))
190           (unless (or (equal (char-feature char '<-simplified@JP/Jouyou)
191                              tchars)
192                       (and (equal (char-feature char '<-simplified)
193                                   tchars)
194                            (memq 'JP/Jouyou
195                                  (char-feature char '<-simplified*sources))))
196             (put-char-attribute char
197                                 '<-simplified@JP/Jouyou
198                                 tchars)))
199         ;; (put-char-attribute
200         ;;  char 'script (adjoin
201         ;;                'JP
202         ;;                (adjoin
203         ;;                 'Jouyou
204         ;;                 (adjoin
205         ;;                  'Ideograph
206         ;;                  (get-char-attribute char 'script)))))
207         ))))
208
209 (provide 'read-maps)
210
211 ;;; read-maps.el ends here