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