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-ideograph-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 (defun char-ideograph-strokes (char)
44 (or (get-char-attribute char 'ideographic-strokes)
46 (or (get-char-attribute char 'daikanwa-strokes)
47 (get-char-attribute char 'kangxi-strokes)
48 (get-char-attribute char 'japanese-strokes)
49 (get-char-attribute char 'korean-strokes))))
51 (put-char-attribute char 'ideographic-strokes strokes)
55 (defun update-ideograph-radical-table ()
60 (charsets '(japanese-jisx0208-1978
62 japanese-jisx0208-1990
80 (setq char (decode-char 'ucs i))
81 (when (and (or (null (setq script (get-char-attribute char 'script)))
82 (memq 'Ideograph script))
83 (setq radical (char-ideograph-radical char)))
84 (or (get-char-attribute char 'ucs)
85 (put-char-attribute char 'ucs i))
88 (aref ideograph-radical-chars-vector radical))))
89 (aset ideograph-radical-chars-vector radical
93 (while (<= i #x10FFFF)
94 (setq char (decode-char 'ucs i))
95 (when (and (or (null (setq script (get-char-attribute char 'script)))
96 (memq 'Ideograph script))
97 (setq radical (char-ideograph-radical char)))
100 (aref ideograph-radical-chars-vector radical))))
101 (aset ideograph-radical-chars-vector radical
108 (setq char (make-char 'ideograph-daikanwa i j))
109 (if (and (setq radical (char-ideograph-radical char))
113 (aref ideograph-radical-chars-vector radical)))))
114 (aset ideograph-radical-chars-vector radical
123 (setq char (make-char (car charsets) i j))
124 (if (and (or (null (setq script (get-char-attribute char 'script)))
125 (memq 'Ideograph script))
126 (setq radical (char-ideograph-radical char))
129 (aref ideograph-radical-chars-vector
131 (aset ideograph-radical-chars-vector radical
135 (setq charsets (cdr charsets)))
138 (defun ideograph-char< (a b)
141 ((setq ra (or (get-char-attribute a 'non-morohashi)
142 (get-char-attribute a 'morohashi-daikanwa)))
144 ((setq rb (or (get-char-attribute b 'non-morohashi)
145 (get-char-attribute b 'morohashi-daikanwa)))
147 ((= (car ra)(car rb))
148 (cond ((eq (car (cdr ra))(car (cdr rb)))
149 (cond ((< (length ra)(length rb)))
150 ((= (length ra)(length rb))
151 (cond ((integerp (nth 2 ra))
152 (cond ((integerp (nth 2 rb))
153 (< (nth 2 ra)(nth 2 rb)))
156 (cond ((setq ra (get-char-attribute a 'ucs))
158 ((setq rb (get-char-attribute b 'ucs))
162 ((null (car (cdr ra))))
163 ((null (car (cdr rb)))
165 (t (< (car (cdr ra))(car (cdr rb))))))
166 (t (< (car ra)(car rb)))))
168 ((or (get-char-attribute b 'non-morohashi)
169 (get-char-attribute b 'morohashi-daikanwa))
171 ((setq ra (get-char-attribute a 'ucs))
173 ((setq rb (get-char-attribute b 'ucs))
177 ((setq ra (char-ideograph-strokes a))
178 (cond ((setq rb (char-ideograph-strokes b))
180 (not (char-ideograph-strokes b)))
184 (defun insert-ideograph-radical-char-data (radical)
186 (sort (copy-list (aref ideograph-radical-chars-vector radical))
187 (function ideograph-char<))))
189 (insert-char-data (car chars))
190 (setq chars (cdr chars)))))
192 (defun write-ideograph-radical-char-data (radical file)
193 (if (file-directory-p file)
194 (let ((name (get-char-attribute (int-char (+ #x2EFF radical)) 'name)))
195 (if (string-match "KANGXI RADICAL " name)
196 (setq name (capitalize (substring name (match-end 0)))))
197 (setq name (mapconcat (lambda (char)
200 (char-to-string char))) name ""))
203 (format "Ideograph-R%03d-%s.el" radical name)
206 (insert-ideograph-radical-char-data radical)
207 (char-db-update-comment)
208 (let ((coding-system-for-write 'utf-8))
209 (write-region (point-min)(point-max) file)
212 (provide 'ideograph-util)
214 ;;; ideograph-util.el ends here