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 8 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 'daikanwa-strokes)
72 (get-char-attribute char 'ideographic-strokes)
74 (or (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
149 (while (< i (* 94 60 22))
150 (setq char (decode-char 'mojikyo i))
151 (if (and (setq radical (char-ideographic-radical char))
155 (aref ideograph-radical-chars-vector radical)))))
156 (aset ideograph-radical-chars-vector radical
164 (setq char (make-char (car charsets) i j))
165 (if (and (or (null (setq script (get-char-attribute char 'script)))
166 (memq 'Ideograph script))
167 (setq radical (char-ideographic-radical char))
170 (aref ideograph-radical-chars-vector
172 (aset ideograph-radical-chars-vector radical
176 (setq charsets (cdr charsets)))
179 (defun int-list< (a b)
180 (if (numberp (car a))
181 (if (numberp (car b))
182 (if (= (car a) (car b))
183 (int-list< (cdr a)(cdr b))
188 (defun ideograph-char< (a b)
189 (let ((a-m-m (get-char-attribute a 'ideograph-daikanwa))
190 (b-m-m (get-char-attribute b 'ideograph-daikanwa))
195 (setq a-s (char-ideographic-strokes a))
196 (setq a-m-r (get-char-attribute a 'morohashi-daikanwa))
199 (setq a-m-m (car a-m-r)
201 (if (= (car a-m-r) 0)
202 (setq a-s (char-ideographic-strokes
203 (decode-char 'ideograph-daikanwa a-m-m)))
204 (if (setq m (get-char-attribute a '->mojikyo))
205 (setq a-s (char-ideographic-strokes
206 (decode-char 'mojikyo m)))
207 (setq a-s (char-ideographic-strokes a)))))
208 (setq a-s (char-ideographic-strokes a))))
210 (setq b-s (char-ideographic-strokes b))
211 (setq b-m-r (get-char-attribute b 'morohashi-daikanwa))
214 (setq b-m-m (car b-m-r)
216 (if (= (car b-m-r) 0)
217 (setq b-s (char-ideographic-strokes
218 (decode-char 'ideograph-daikanwa b-m-m)))
219 (if (setq m (get-char-attribute b '->mojikyo))
220 (setq b-s (char-ideographic-strokes
221 (decode-char 'mojikyo m)))
222 (setq b-s (char-ideographic-strokes b)))))
223 (setq b-s (char-ideographic-strokes b))))
229 (int-list< (cons a-m-m a-m-r)
234 (setq a-u (get-char-attribute a 'ucs)
235 b-u (get-char-attribute b 'ucs))
239 (setq b-u (get-char-attribute b '->ucs))
243 (setq a-u (get-char-attribute a '->ucs))
247 (setq b-u (get-char-attribute b '->ucs))
251 (if (or b-u (get-char-attribute b '->ucs))
253 (< (char-int a)(char-int b)))))))
257 ;; (defun ideograph-char< (a b)
258 ;; (let (ra rb mma mmb msa msb)
261 ;; (if (setq ra (or (get-char-attribute a 'non-morohashi)
262 ;; (get-char-attribute a 'morohashi-daikanwa)))
263 ;; (setq msa (cdr ra)
265 ;; (setq mma (get-char-attribute a 'ideograph-daikanwa))))
268 ;; (if (setq rb (or (get-char-attribute b 'non-morohashi)
269 ;; (get-char-attribute b 'morohashi-daikanwa)))
270 ;; (setq msb (cdr rb)
272 ;; (setq mmb (get-char-attribute b 'ideograph-daikanwa))))
275 ;; (cond ((eq (car msa)(car msb))
276 ;; (cond ((< (length msa)(length msb)))
277 ;; ((= (length msa)(length msb))
278 ;; (cond ((integerp (nth 1 msa))
279 ;; (cond ((integerp (nth 1 msb))
280 ;; (< (nth 1 msa)(nth 1 msb)))
283 ;; (cond ((setq ra (get-char-attribute a 'ucs))
285 ;; ((setq rb (get-char-attribute b 'ucs))
289 ;; ((null (car msa)))
292 ;; (t (< (car msa)(car msb)))))
295 ;; ((or (get-char-attribute b 'non-morohashi)
296 ;; (get-char-attribute b 'morohashi-daikanwa)
297 ;; (get-char-attribute b 'ideograph-daikanwa))
299 ;; ((setq ra (get-char-attribute a 'ucs))
301 ;; ((setq rb (get-char-attribute b 'ucs))
305 ;; ((setq ra (char-ideographic-strokes a))
306 ;; (cond ((setq rb (char-ideographic-strokes b))
308 ;; (not (char-ideographic-strokes b)))
312 (defun insert-ideograph-radical-char-data (radical)
314 (sort (copy-list (aref ideograph-radical-chars-vector radical))
315 (function ideograph-char<)))
316 (attributes (sort (char-attribute-list) #'char-attribute-name<))
317 (ccs (sort (charset-list) #'char-attribute-name<)))
318 (aset ideograph-radical-chars-vector radical chars)
320 (insert-char-data (car chars) nil attributes ccs)
321 (setq chars (cdr chars)))))
323 (defun write-ideograph-radical-char-data (radical file)
324 (if (file-directory-p file)
325 (let ((name (get-char-attribute (int-char (+ #x2EFF radical)) 'name)))
326 (if (string-match "KANGXI RADICAL " name)
327 (setq name (capitalize (substring name (match-end 0)))))
328 (setq name (mapconcat (lambda (char)
331 (char-to-string char))) name ""))
334 (format "Ideograph-R%03d-%s.el" radical name)
337 (insert-ideograph-radical-char-data radical)
338 (char-db-update-comment)
339 (let ((coding-system-for-write 'utf-8))
340 (write-region (point-min)(point-max) file)
343 (provide 'ideograph-util)
345 ;;; ideograph-util.el ends here