(mapping-table-ccs-setting-alist): Add setting for `=ks-x1001'.
[chise/xemacs-chise.git] / lisp / utf-2000 / read-maps.el
1 ;;; read-maps.el --- Read mapping-tables.
2
3 ;; Copyright (C) 2002,2003,2004,2005 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     (=ks-x1001
73      "^K0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
74      =ucs@ks
75      "\tKU[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
76     (=jef-china3     
77      "^JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)" 1 16
78      nil
79      nil)
80     )
81   "*List of information about mapping table formats.
82 Elements are of the form
83 \(CCS CODE-REGEXP PAREN-EXP BASE UCS-CCS UCS-REGEXP).
84
85 CCS     is a symbol, which is a name of a target coded-charset.
86
87 CODE-REGEXP is a regular expression to match against
88         the representation of the target coded-charset.
89
90 PAREN-EXP is a number specifies which parenthesized expression
91         in the CODE-REGEXP.
92
93 BASE    base of code in the string specified by CODE-REGEXP and
94         PAREN-EXP.
95
96 UCS-CCS is a symbol, which is a name of a UCS-CCS.
97
98 UCS-REGEXP is a regular expression to match against
99         the representation of the UCS-CCS.")
100
101 ;;;###autoload
102 (defun mapping-table-read-file (filename)
103   "Read mapping table." 
104   (interactive "fMapping table : ")
105   (with-temp-buffer
106     (buffer-disable-undo)
107     (insert-file-contents filename)
108     (goto-char (point-min))
109     (let (rest setting ccs code ucs ucs-pat ucs-ccs ucs-code chr)
110       (while (not (eobp))
111         (setq rest mapping-table-ccs-setting-alist)
112         (catch 'matched
113           (while rest
114             (setq setting (car rest)
115                   ccs (pop setting))
116             (when (looking-at (pop setting))
117               (setq code (string-to-int (match-string (pop setting))
118                                         (pop setting))
119                     ucs-ccs (pop setting)
120                     ucs-pat (car setting))
121               (goto-char (match-end 0))
122               (throw 'matched t))
123             (setq rest (cdr rest)))
124           (setq ccs nil
125                 code nil
126                 ucs-pat nil
127                 ucs-ccs nil))
128         (setq ucs-code
129               (if (and ucs-pat
130                        (looking-at ucs-pat))
131                   (prog1
132                       (string-to-int (match-string 1) 16)
133                     (goto-char (match-end 0)))))
134         (setq ucs
135               (if (looking-at
136                    "[ \t]*U[+-]\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]+\\)")
137                   (string-to-int (match-string 1) 16)))
138         (if (and ucs-ccs ucs (not ucs-code))
139             (setq ucs-code ucs
140                   ucs nil))
141         (when (setq chr (decode-char ccs code))
142           (unless (eq (encode-char chr ccs 'defined-only)
143                       code)
144             (put-char-attribute chr ccs code))
145           (when (and ucs-code
146                      (not
147                       (eq (or
148                            (encode-char chr ucs-ccs 'defined-only)
149                            (cond
150                             ((memq ucs-ccs '(=ucs@jis
151                                              =ucs@jis/1990
152                                              =ucs@jis/2000))
153                              (encode-char chr '=ucs@jis/fw 'defined-only))
154                             ((eq ucs-ccs '=ucs@gb)
155                              (encode-char chr '=ucs@gb/fw 'defined-only))
156                             ;; ((eq ucs-ccs '=ucs@cns)
157                             ;;  (encode-char chr '=ucs@cns/fw 'defined-only))
158                             ;; ((eq ucs-ccs '=ucs@big5)
159                             ;;  nil)
160                             ;; ((eq ucs-ccs '=ucs@ks)
161                             ;;  (encode-char chr '=ucs@ks/fw 'defined-only))
162                             (t
163                              (char-feature chr '=>ucs))))
164                           ucs-code)))
165             (put-char-attribute chr ucs-ccs ucs-code))
166           (when (and ucs
167                      (not (eq (or (encode-char chr '=ucs 'defined-only)
168                                   (and (not (memq ucs-ccs '(=ucs@jis
169                                                             =ucs@jis/1990
170                                                             =ucs@jis/2000
171                                                             =ucs@gb
172                                                             =ucs@cns
173                                                             =ucs@big5
174                                                             =ucs@ks
175                                                             )))
176                                        (char-feature chr '=>ucs)))
177                               ucs)))
178             (if (or ucs-code (null ucs-ccs))
179                 (unless (eq (char-feature chr '=>ucs) ucs)
180                   (put-char-attribute chr '=>ucs ucs))
181               (unless (eq (encode-char chr ucs-ccs 'defined-only)
182                           ucs)
183                 (put-char-attribute chr ucs-ccs ucs)))))
184         (forward-line)))))
185
186 (defun jp-jouyou-read-file (filename)
187   (interactive "fjp-jouyou file : ")
188   (with-temp-buffer
189     (buffer-disable-undo)
190     (insert-file-contents filename)
191     (goto-char (point-min))
192     (let (char tchars)
193       (while (re-search-forward "^[^\t\n ]+\t\\(.\\)\t*" nil t)
194         (setq char (aref (match-string 1) 0)
195               tchars (buffer-substring (match-end 0)
196                                        (point-at-eol)))
197         (when (> (length tchars) 0)
198           (setq tchars
199                 (mapcar (lambda (c)
200                           (aref c 0))
201                         (split-string tchars " ")))
202           (unless (or (equal (char-feature char '<-simplified@JP/Jouyou)
203                              tchars)
204                       (and (equal (char-feature char '<-simplified)
205                                   tchars)
206                            (memq 'JP/Jouyou
207                                  (char-feature char '<-simplified*sources))))
208             (put-char-attribute char
209                                 '<-simplified@JP/Jouyou
210                                 tchars)))
211         ;; (put-char-attribute
212         ;;  char 'script (adjoin
213         ;;                'JP
214         ;;                (adjoin
215         ;;                 'Jouyou
216         ;;                 (adjoin
217         ;;                  'Ideograph
218         ;;                  (get-char-attribute char 'script)))))
219         ))))
220
221 (provide 'read-maps)
222
223 ;;; read-maps.el ends here