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