1 ;;; ideograph-util.el --- Ideographic Character Database utility
3 ;; Copyright (C) 1999 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
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 (int-char i))
81 (when (setq radical (char-ideograph-radical char))
82 (or (get-char-attribute char 'ucs)
83 (put-char-attribute char 'ucs i))
86 (aref ideograph-radical-chars-vector radical))))
87 (aset ideograph-radical-chars-vector radical
91 (while (<= i #x10FFFF)
92 (setq char (int-char i))
93 (when (setq radical (char-ideograph-radical char))
96 (aref ideograph-radical-chars-vector radical))))
97 (aset ideograph-radical-chars-vector radical
104 (setq char (make-char 'ideograph-daikanwa i j))
105 (if (and (setq radical (char-ideograph-radical char))
109 (aref ideograph-radical-chars-vector radical)))))
110 (aset ideograph-radical-chars-vector radical
119 (setq char (make-char (car charsets) i j))
120 (if (and (setq radical (char-ideograph-radical char))
123 (aref ideograph-radical-chars-vector
125 (aset ideograph-radical-chars-vector radical
129 (setq charsets (cdr charsets)))
132 (defun ideograph-char< (a b)
135 ((setq ra (or (get-char-attribute a 'morohashi-daikanwa)
136 (get-char-attribute a 'non-morohashi)))
138 ((setq rb (or (get-char-attribute b 'morohashi-daikanwa)
139 (get-char-attribute b 'non-morohashi)))
141 ((= (car ra)(car rb))
142 (cond ((eq (car (cdr ra))(car (cdr rb)))
143 (cond ((< (length ra)(length rb)))
144 ((= (length ra)(length rb))
145 (cond ((integerp (nth 2 ra))
146 (cond ((integerp (nth 2 rb))
147 (< (nth 2 ra)(nth 2 rb)))
150 (cond ((setq ra (get-char-attribute a 'ucs))
152 ((setq rb (get-char-attribute b 'ucs))
156 ((null (car (cdr ra))))
157 ((null (car (cdr rb)))
159 (t (< (car (cdr ra))(car (cdr rb))))))
160 (t (< (car ra)(car rb)))))
161 ((setq ra (get-char-attribute a 'ucs))
163 ((setq rb (get-char-attribute b 'ucs))
167 ((setq ra (char-ideograph-strokes a))
168 (cond ((setq rb (char-ideograph-strokes b))
170 (not (char-ideograph-strokes b)))
174 (defun insert-ideograph-radical-char-data (radical)
176 (sort (copy-list (aref ideograph-radical-chars-vector radical))
177 (function ideograph-char<))))
179 (insert-char-data (car chars))
180 (setq chars (cdr chars)))))
182 (defun write-ideograph-radical-char-data (radical file)
183 (if (file-directory-p file)
184 (let ((name (get-char-attribute (int-char (+ #x2EFF radical)) 'name)))
185 (if (string-match "KANGXI RADICAL " name)
186 (setq name (capitalize (substring name (match-end 0)))))
187 (setq name (mapconcat (lambda (char)
190 (char-to-string char))) name ""))
193 (format "Ideograph-R%03d-%s.el" radical name)
196 (insert-ideograph-radical-char-data radical)
197 (char-db-update-comment)
198 (let ((coding-system-for-write 'utf-8))
199 (write-region (point-min)(point-max) file)
202 (provide 'ideograph-util)
204 ;;; ideograph-util.el ends here