Rename `idc' to `ids'.
[chise/ids.git] / ids-util.el
1 ;;; ids-util.el --- Utilities about ideographic-structure property
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 'ucs #x5922)
74          (decode-char 'ideograph-daikanwa 05802))
75    (cons (decode-char 'ucs #x656C)
76          (decode-char 'ideograph-daikanwa 13303))
77    (cons (decode-char 'ucs #x8449)
78          (decode-char 'ideograph-daikanwa 31387))
79    (cons (decode-char 'ucs #x2EA4)
80          (decode-char 'ucs #x722B))
81    (cons (decode-char 'ucs #x5151)
82          (decode-char 'ideograph-daikanwa 01356))
83    (cons (decode-char 'ucs #x544A)
84          (decode-char 'ideograph-daikanwa 03381))
85    (cons (decode-char 'ucs #x5F66)
86          (decode-char 'ideograph-daikanwa 09980))
87    (cons (decode-char 'ucs #x8005)
88          (decode-char 'ideograph-daikanwa 28853))
89    (cons (decode-char 'ucs #x82E5)
90          (decode-char 'ideograph-daikanwa 30796))
91    (cons (decode-char 'ucs #x82F1)
92          (decode-char 'ideograph-daikanwa 30808))
93    (cons (decode-char 'ucs #x9063)
94          (decode-char 'ideograph-daikanwa 39052))
95    (cons (decode-char 'ucs #x4EA0)
96          (decode-char 'chinese-big5-cdp #x8B42))
97    (cons (decode-char 'ucs #x5154)
98          (decode-char 'ideograph-daikanwa 01368))
99    (cons (decode-char 'ucs #x53CA)
100          (decode-char 'ideograph-daikanwa 03118))
101    (cons (decode-char 'ucs #x5468)
102          (decode-char 'ideograph-daikanwa 03441))
103    (cons (decode-char 'ucs #x5C1A)
104          (decode-char 'ucs #x5C19))
105    (cons (decode-char 'ucs #x5D29)
106          (decode-char 'ideograph-daikanwa 08212))
107    (cons (decode-char 'ucs #x670B)
108          (decode-char 'ideograph-daikanwa 14340))
109    (cons (decode-char 'ucs #x7FBD)
110          (decode-char 'ideograph-daikanwa 28614))
111    (cons (decode-char 'ucs #x8096)
112          (decode-char 'ideograph-daikanwa 29263))
113    (cons (decode-char 'ucs #x8981)
114          (decode-char 'ideograph-daikanwa 34768))
115    (cons (decode-char 'ucs #x8AF8)
116          (decode-char 'ideograph-daikanwa 35743))
117    (cons (decode-char 'ucs #x9023)
118          (decode-char 'ideograph-daikanwa 38902))
119    (cons (decode-char 'ucs #x9752)
120          (decode-char 'ucs #x9751))
121    ))
122
123 ;;;###autoload
124 (defun ideographic-structure-convert-to-daikanwa (structure)
125   (let (dest cell morohashi ret)
126     (while structure
127       (setq cell (car structure))
128       (setq dest
129             (cons
130              (cond ((characterp cell)
131                     (cond ((setq ret
132                                  (assq cell morohashi-char-replace-alist))
133                            (cdr ret))
134                           ((get-char-attribute cell 'ideograph-daikanwa)
135                            cell)
136                           ((setq morohashi
137                                  (get-char-attribute
138                                   cell 'morohashi-daikanwa))
139                            (cond ((null (cdr (cdr morohashi)))
140                                   cell)
141                                  ((= (nth 1 morohashi) 0)
142                                   (decode-char 'ideograph-daikanwa
143                                                (car morohashi)))
144                                  (t
145                                   (setq morohashi (list (car morohashi)
146                                                         (nth 1 morohashi)))
147                                   (or (map-char-attribute
148                                        (lambda (char val)
149                                          (if (equal morohashi val)
150                                              char))
151                                        'morohashi-daikanwa)
152                                       cell))))
153                           (t
154                            cell)))
155                    ((and (consp cell)
156                          (symbolp (car cell)))
157                     cell)
158                    ((setq ret (find-char cell))
159                     (if (or (get-char-attribute ret 'ideograph-daikanwa)
160                             (null
161                              (setq morohashi
162                                    (get-char-attribute
163                                     ret 'morohashi-daikanwa)))
164                             (null (cdr (cdr morohashi))))
165                         cell
166                       (if (= (nth 1 morohashi) 0)
167                           (decode-char 'ideograph-daikanwa (car morohashi))
168                         cell)))
169                    ((setq ret (assq 'ideographic-structure cell))
170                     (put-alist 'ideographic-structure
171                                (ideographic-structure-convert-to-daikanwa
172                                 (cdr ret))
173                                (copy-alist cell)))
174                    (t cell))
175              dest))
176       (setq structure (cdr structure)))
177     (nreverse dest)))
178
179
180 ;;; @ End.
181 ;;;
182
183 (provide 'ids-util)
184
185 ;;; ids-util.el ends here