1 ;;; ideograph-util.el --- Ideographic Character Database utility
3 ;; Copyright (C) 1999,2000 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: UTF-2000, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of UTF-2000.
10 ;; UTF-2000 is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; UTF-2000 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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 (require 'char-db-util)
29 (defvar ideograph-radical-chars-vector
30 (make-vector 215 nil))
32 (defun char-ideographic-radical (char)
33 (or (get-char-attribute char 'ideographic-radical)
35 (or (get-char-attribute char 'daikanwa-radical)
36 (get-char-attribute char 'kangxi-radical)
37 (get-char-attribute char 'japanese-radical)
38 (get-char-attribute char 'korean-radical))))
40 (put-char-attribute char 'ideographic-radical radical)
43 (defvar ideograph-radical-strokes-vector
45 [nil 1 1 1 1 1 1 2 2 2
64 9 9 9 9 9 9 9 10 10 10
65 10 10 10 10 10 11 11 11 11 11
67 11 12 12 12 12 13 13 13 13 14
70 (defun char-ideographic-strokes (char)
71 (or (get-char-attribute char 'ideographic-strokes)
73 (or (get-char-attribute char 'daikanwa-strokes)
74 (get-char-attribute char 'kangxi-strokes)
75 (get-char-attribute char 'japanese-strokes)
76 (get-char-attribute char 'korean-strokes)
77 (let ((r (char-ideographic-radical char))
78 (ts (get-char-attribute char 'total-strokes)))
80 (- ts (aref ideograph-radical-strokes-vector r))))
83 (put-char-attribute char 'ideographic-strokes strokes)
87 (defun update-ideograph-radical-table ()
92 (charsets '(japanese-jisx0208-1978
94 japanese-jisx0208-1990
112 (setq char (decode-char 'ucs i))
113 (when (and (or (null (setq script (get-char-attribute char 'script)))
114 (memq 'Ideograph script))
115 (setq radical (char-ideographic-radical char)))
116 (or (get-char-attribute char 'ucs)
117 (put-char-attribute char 'ucs i))
118 (char-ideographic-strokes char)
121 (aref ideograph-radical-chars-vector radical))))
122 (aset ideograph-radical-chars-vector radical
126 (while (<= i #x10FFFF)
127 (setq char (decode-char 'ucs i))
128 (when (and (or (null (setq script (get-char-attribute char 'script)))
129 (memq 'Ideograph script))
130 (setq radical (char-ideographic-radical char)))
133 (aref ideograph-radical-chars-vector radical))))
134 (aset ideograph-radical-chars-vector radical
139 (setq char (decode-char 'ideograph-daikanwa i))
140 (if (and (setq radical (char-ideographic-radical char))
144 (aref ideograph-radical-chars-vector radical)))))
145 (aset ideograph-radical-chars-vector radical
153 (setq char (make-char (car charsets) i j))
154 (if (and (or (null (setq script (get-char-attribute char 'script)))
155 (memq 'Ideograph script))
156 (setq radical (char-ideographic-radical char))
159 (aref ideograph-radical-chars-vector
161 (aset ideograph-radical-chars-vector radical
165 (setq charsets (cdr charsets)))
168 (defun int-list< (a b)
169 (if (numberp (car a))
170 (if (numberp (car b))
171 (if (= (car a) (car b))
172 (int-list< (cdr a)(cdr b))
177 (defun ideograph-char< (a b)
178 (let ((a-m-m (get-char-attribute a 'ideograph-daikanwa))
179 (b-m-m (get-char-attribute b 'ideograph-daikanwa))
184 (setq a-s (char-ideographic-strokes a))
185 (setq a-m-r (get-char-attribute a 'morohashi-daikanwa))
188 (setq a-m-m (car a-m-r)
190 (if (= (car a-m-r) 0)
191 (setq a-s (char-ideographic-strokes
192 (decode-char 'ideograph-daikanwa a-m-m)))
193 (if (setq m (get-char-attribute a '->mojikyo))
194 (setq a-s (char-ideographic-strokes
195 (decode-char 'mojikyo m)))
196 (setq a-s (char-ideographic-strokes a)))))
197 (setq a-s (char-ideographic-strokes a))))
199 (setq b-s (char-ideographic-strokes b))
200 (setq b-m-r (get-char-attribute b 'morohashi-daikanwa))
203 (setq b-m-m (car b-m-r)
205 (if (= (car b-m-r) 0)
206 (setq b-s (char-ideographic-strokes
207 (decode-char 'ideograph-daikanwa b-m-m)))
208 (if (setq m (get-char-attribute b '->mojikyo))
209 (setq b-s (char-ideographic-strokes
210 (decode-char 'mojikyo m)))
211 (setq b-s (char-ideographic-strokes b)))))
212 (setq b-s (char-ideographic-strokes b))))
218 (int-list< (cons a-m-m a-m-r)
223 (setq a-u (get-char-attribute a 'ucs)
224 b-u (get-char-attribute b 'ucs))
228 (setq b-u (get-char-attribute b '->ucs))
232 (setq a-u (get-char-attribute a '->ucs))
236 (setq b-u (get-char-attribute b '->ucs))
240 (if (or b-u (get-char-attribute b '->ucs))
242 (< (char-int a)(char-int b)))))))
246 ;; (defun ideograph-char< (a b)
247 ;; (let (ra rb mma mmb msa msb)
250 ;; (if (setq ra (or (get-char-attribute a 'non-morohashi)
251 ;; (get-char-attribute a 'morohashi-daikanwa)))
252 ;; (setq msa (cdr ra)
254 ;; (setq mma (get-char-attribute a 'ideograph-daikanwa))))
257 ;; (if (setq rb (or (get-char-attribute b 'non-morohashi)
258 ;; (get-char-attribute b 'morohashi-daikanwa)))
259 ;; (setq msb (cdr rb)
261 ;; (setq mmb (get-char-attribute b 'ideograph-daikanwa))))
264 ;; (cond ((eq (car msa)(car msb))
265 ;; (cond ((< (length msa)(length msb)))
266 ;; ((= (length msa)(length msb))
267 ;; (cond ((integerp (nth 1 msa))
268 ;; (cond ((integerp (nth 1 msb))
269 ;; (< (nth 1 msa)(nth 1 msb)))
272 ;; (cond ((setq ra (get-char-attribute a 'ucs))
274 ;; ((setq rb (get-char-attribute b 'ucs))
278 ;; ((null (car msa)))
281 ;; (t (< (car msa)(car msb)))))
284 ;; ((or (get-char-attribute b 'non-morohashi)
285 ;; (get-char-attribute b 'morohashi-daikanwa)
286 ;; (get-char-attribute b 'ideograph-daikanwa))
288 ;; ((setq ra (get-char-attribute a 'ucs))
290 ;; ((setq rb (get-char-attribute b 'ucs))
294 ;; ((setq ra (char-ideographic-strokes a))
295 ;; (cond ((setq rb (char-ideographic-strokes b))
297 ;; (not (char-ideographic-strokes b)))
301 (defun insert-ideograph-radical-char-data (radical)
303 (sort (copy-list (aref ideograph-radical-chars-vector radical))
304 (function ideograph-char<)))
305 (attributes (sort (char-attribute-list) #'char-attribute-name<))
306 (ccs (sort (charset-list) #'char-attribute-name<)))
307 (aset ideograph-radical-chars-vector radical chars)
309 (insert-char-data (car chars) nil attributes ccs)
310 (setq chars (cdr chars)))))
312 (defun write-ideograph-radical-char-data (radical file)
313 (if (file-directory-p file)
314 (let ((name (get-char-attribute (int-char (+ #x2EFF radical)) 'name)))
315 (if (string-match "KANGXI RADICAL " name)
316 (setq name (capitalize (substring name (match-end 0)))))
317 (setq name (mapconcat (lambda (char)
320 (char-to-string char))) name ""))
323 (format "Ideograph-R%03d-%s.el" radical name)
326 (insert-ideograph-radical-char-data radical)
327 (char-db-update-comment)
328 (let ((coding-system-for-write 'utf-8))
329 (write-region (point-min)(point-max) file)
332 (provide 'ideograph-util)
334 ;;; ideograph-util.el ends here