Add new character.
[chise/ids.git] / ids-util.el
1 ;;; ids-util.el --- Utilities about ideographic-structure -*- coding: utf-8 -*-
2
3 ;; Copyright (C) 2001 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: ideographic-structure, UTF-2000, database
7
8 ;; This file is a part of Tomoyo Utilities.
9
10 ;; This program 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 ;; This program is distributed in the hope that it will be useful, but
16 ;; 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 this program; 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 ;;; Commentary:
26
27 ;;; Code:
28
29 ;;;###autoload
30 (defun ideographic-structure-convert-to-ucs (structure)
31   (let (dest cell ucs ret)
32     (while structure
33       (setq cell (car structure))
34       (setq dest
35             (cons
36              (cond ((characterp cell)
37                     (if (or (get-char-attribute cell 'ucs)
38                             (null
39                              (setq ucs
40                                    (or (get-char-attribute cell '=>ucs)
41                                        (get-char-attribute cell '->ucs)))))
42                         cell
43                       (decode-char 'ucs ucs)))
44                    ((and (consp cell)
45                          (symbolp (car cell)))
46                     cell)
47                    ((setq ret (find-char cell))
48                     (if (or (get-char-attribute ret 'ucs)
49                             (null
50                              (setq ucs
51                                    (or (get-char-attribute ret '=>ucs)
52                                        (get-char-attribute ret '->ucs)))))
53                         cell
54                       (decode-char 'ucs ucs)))
55                    ((setq ret (assq 'ideographic-structure cell))
56                     (put-alist 'ideographic-structure
57                                (ideographic-structure-convert-to-ucs
58                                 (cdr ret))
59                                (copy-alist cell)))
60                    (t cell))
61              dest))
62       (setq structure (cdr structure)))
63     (nreverse dest)))
64
65 (defvar morohashi-char-replace-alist
66   (list
67    (cons (decode-char 'chinese-big5-cdp #x8B42)
68          (decode-char 'chinese-big5-cdp #x8B42))
69    (cons (decode-char 'chinese-big5-cdp #x8AFC)
70          (decode-char 'chinese-big5-cdp #x8AFC))
71    (cons (decode-char 'ucs #x2EBE)
72          (decode-char 'ucs #x2EBF))
73    (cons ?亽 (decode-char 'chinese-big5-cdp #x8AFC))
74    (cons ?亼 (decode-char 'chinese-big5-cdp #x8AFC))
75    (cons (decode-char 'chinese-big5-cdp #x8AFC)
76          (decode-char 'chinese-big5-cdp #x8AFC))
77    '(?夂 . ?夂)
78    (cons (decode-char 'ucs #x5922)
79          (decode-char 'ideograph-daikanwa 05802))
80    (cons (decode-char 'ucs #x656C)
81          (decode-char 'ideograph-daikanwa 13303))
82    (cons (decode-char 'ucs #x8449)
83          (decode-char 'ideograph-daikanwa 31387))
84    (cons (decode-char 'ucs #x2EA4)
85          (decode-char 'ucs #x722B))
86    (cons (decode-char 'ucs #x5151)
87          (decode-char 'ideograph-daikanwa 01356))
88    (cons (decode-char 'ucs #x544A)
89          (decode-char 'ideograph-daikanwa 03381))
90    (cons (decode-char 'ucs #x5F66)
91          (decode-char 'ideograph-daikanwa 09980))
92    (cons (decode-char 'ucs #x8005)
93          (decode-char 'ideograph-daikanwa 28853))
94    (cons (decode-char 'ucs #x82E5)
95          (decode-char 'ideograph-daikanwa 30796))
96    (cons (decode-char 'ucs #x82F1)
97          (decode-char 'ideograph-daikanwa 30808))
98    (cons (decode-char 'ucs #x9063)
99          (decode-char 'ideograph-daikanwa 39052))
100    (cons (decode-char 'ucs #x4EA0)
101          (decode-char 'chinese-big5-cdp #x8B42))
102    (cons (decode-char 'ucs #x5154)
103          (decode-char 'ideograph-daikanwa 01368))
104    (cons (decode-char 'ucs #x53CA)
105          (decode-char 'ideograph-daikanwa 03118))
106    (cons (decode-char 'ucs #x5468)
107          (decode-char 'ideograph-daikanwa 03441))
108    (cons (decode-char 'ucs #x5C1A)
109          (decode-char 'ucs #x5C19))
110    (cons (decode-char 'ucs #x5D29)
111          (decode-char 'ideograph-daikanwa 08212))
112    (cons (decode-char 'ucs #x670B)
113          (decode-char 'ideograph-daikanwa 14340))
114    (cons (decode-char 'ucs #x7FBD)
115          (decode-char 'ideograph-daikanwa 28614))
116    (cons (decode-char 'ucs #x8096)
117          (decode-char 'ideograph-daikanwa 29263))
118    (cons (decode-char 'ucs #x8981)
119          (decode-char 'ideograph-daikanwa 34768))
120    (cons (decode-char 'ucs #x8AF8)
121          (decode-char 'ideograph-daikanwa 35743))
122    (cons (decode-char 'ucs #x9023)
123          (decode-char 'ideograph-daikanwa 38902))
124    (cons (decode-char 'ucs #x9752)
125          (decode-char 'ucs #x9751))
126    (cons (decode-char 'japanese-jisx0213-2 #x2327)
127          (decode-char 'japanese-jisx0213-2 #x2327))
128    (cons (decode-char 'chinese-big5-cdp #x8BFA)
129          (decode-char 'japanese-jisx0213-2 #x2327))
130    ))
131
132 ;;;###autoload
133 (defun ideographic-structure-convert-to-daikanwa (structure)
134   (let (dest cell morohashi ret)
135     (while structure
136       (setq cell (car structure))
137       (setq dest
138             (cons
139              (cond ((characterp cell)
140                     (cond ((setq ret
141                                  (assq cell morohashi-char-replace-alist))
142                            (cdr ret))
143                           ((get-char-attribute cell 'ideograph-daikanwa)
144                            cell)
145                           ((setq morohashi
146                                  (get-char-attribute
147                                   cell 'morohashi-daikanwa))
148                            (cond ((null (cdr (cdr morohashi)))
149                                   cell)
150                                  ((= (nth 1 morohashi) 0)
151                                   (decode-char 'ideograph-daikanwa
152                                                (car morohashi)))
153                                  (t
154                                   (setq morohashi (list (car morohashi)
155                                                         (nth 1 morohashi)))
156                                   (or (map-char-attribute
157                                        (lambda (char val)
158                                          (if (equal morohashi val)
159                                              char))
160                                        'morohashi-daikanwa)
161                                       cell))))
162                           (t
163                            cell)))
164                    ((and (consp cell)
165                          (symbolp (car cell)))
166                     cell)
167                    ((setq ret (find-char cell))
168                     (if (or (get-char-attribute ret 'ideograph-daikanwa)
169                             (null
170                              (setq morohashi
171                                    (get-char-attribute
172                                     ret 'morohashi-daikanwa)))
173                             (null (cdr (cdr morohashi))))
174                         cell
175                       (if (= (nth 1 morohashi) 0)
176                           (decode-char 'ideograph-daikanwa (car morohashi))
177                         cell)))
178                    ((setq ret (assq 'ideographic-structure cell))
179                     (put-alist 'ideographic-structure
180                                (ideographic-structure-convert-to-daikanwa
181                                 (cdr ret))
182                                (copy-alist cell)))
183                    (t cell))
184              dest))
185       (setq structure (cdr structure)))
186     (nreverse dest)))
187
188
189 ;;; @ End.
190 ;;;
191
192 (provide 'ids-util)
193
194 ;;; ids-util.el ends here