1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,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
29 (defconst unidata-normative-category-alist
30 '(("Lu" letter uppercase)
31 ("Ll" letter lowercase)
32 ("Lt" letter titlecase)
33 ("Mn" mark non-spacing)
34 ("Mc" mark spacing-combining)
36 ("Nd" number decimal-digit)
39 ("Zs" separator space)
41 ("Zp" separator paragraph)
44 ("Cs" other surrogate)
45 ("Co" other private-use)
46 ("Cn" other not-assigned)))
48 (defconst unidata-informative-category-alist
49 '(("Lm" letter modifier)
51 ("Pc" punctuation connector)
52 ("Pd" punctuation dash)
53 ("Ps" punctuation open)
54 ("Pe" punctuation close)
55 ("Pi" punctuation initial-quote)
56 ("Pf" punctuation final-quote)
57 ("Po" punctuation other)
59 ("Sc" symbol currency)
60 ("Sk" symbol modifier)
64 (defconst ideographic-radicals
65 (let ((v (make-vector 215 nil))
68 (aset v i (int-char (+ #x2EFF i)))
70 (if (< (charset-iso-final-char (car (split-char (aref v 34)))) ?0)
71 (aset v 34 (make-char 'chinese-gb2312 #x62 #x3A)))
74 (defun char-attribute-name< (ka kb)
80 ((= (charset-dimension ka)
81 (charset-dimension kb))
82 (cond ((= (charset-chars ka)(charset-chars kb))
84 ((>= (charset-iso-final-char ka) ?@)
85 (if (>= (charset-iso-final-char kb) ?@)
86 (< (charset-iso-final-char ka)
87 (charset-iso-final-char kb))
89 ((>= (charset-iso-final-char ka) ?0)
91 ((>= (charset-iso-final-char kb) ?@)
93 ((>= (charset-iso-final-char kb) ?0)
94 (< (charset-iso-final-char ka)
95 (charset-iso-final-char kb)))
97 ((<= (charset-chars ka)(charset-chars kb)))))
99 (< (charset-dimension ka)
100 (charset-dimension kb))
110 (string< (symbol-name ka)
116 (defun insert-char-data (char &optional readable
117 attributes ccs-attributes)
119 (setq attributes (sort (char-attribute-list) #'char-attribute-name<)))
121 (setq ccs-attributes (sort (charset-list) #'char-attribute-name<)))
122 (let (name value has-long-ccs-name rest
125 (narrow-to-region (point)(point))
126 (insert "(define-char
128 (when (setq value (get-char-attribute char 'name))
130 (if (> (length value) 47)
136 (setq attributes (delq 'name attributes))
138 (when (setq value (get-char-attribute char 'script))
139 (insert (format "(script\t\t%s)
141 (mapconcat (function prin1-to-string)
143 (setq attributes (delq 'script attributes))
145 (when (setq value (get-char-attribute char '->ucs))
146 (insert (format "(->ucs\t\t. #x%04X)\t; %c
148 value (decode-char 'ucs value)))
149 (setq attributes (delq '->ucs attributes))
151 (when (setq value (get-char-attribute char 'general-category))
153 "(general-category\t%s) ; %s
155 (mapconcat (lambda (cell)
158 (cond ((rassoc value unidata-normative-category-alist)
159 "Normative Category")
160 ((rassoc value unidata-informative-category-alist)
161 "Informative Category")
163 "Unknown Category"))))
164 (setq attributes (delq 'general-category attributes))
166 (when (setq value (get-char-attribute char 'bidi-category))
167 (insert (format "(bidi-category\t. %S)
170 (setq attributes (delq 'bidi-category attributes))
172 (when (setq value (get-char-attribute char 'mirrored))
173 (insert (format "(mirrored\t\t. %S)
176 (setq attributes (delq 'mirrored attributes))
179 ((setq value (get-char-attribute char 'decimal-digit-value))
180 (insert (format "(decimal-digit-value . %S)
183 (setq attributes (delq 'decimal-digit-value attributes))
184 (when (setq value (get-char-attribute char 'digit-value))
185 (insert (format "(digit-value\t . %S)
188 (setq attributes (delq 'digit-value attributes))
190 (when (setq value (get-char-attribute char 'numeric-value))
191 (insert (format "(numeric-value\t . %S)
194 (setq attributes (delq 'numeric-value attributes))
198 (when (setq value (get-char-attribute char 'digit-value))
199 (insert (format "(digit-value\t. %S)
202 (setq attributes (delq 'digit-value attributes))
204 (when (setq value (get-char-attribute char 'numeric-value))
205 (insert (format "(numeric-value\t. %S)
208 (setq attributes (delq 'numeric-value attributes))
210 (when (setq value (get-char-attribute char 'iso-10646-comment))
211 (insert (format "(iso-10646-comment\t. %S)
214 (setq attributes (delq 'iso-10646-comment attributes))
216 (when (setq value (get-char-attribute char 'morohashi-daikanwa))
217 (insert (format "(morohashi-daikanwa\t%s)
219 (mapconcat (function prin1-to-string) value " ")))
220 (setq attributes (delq 'morohashi-daikanwa attributes))
224 (when (setq value (get-char-attribute char 'ideographic-radical))
226 (insert (format "(ideographic-radical . %S)\t; %c
229 (aref ideographic-radicals radical)))
230 (setq attributes (delq 'ideographic-radical attributes))
232 (when (setq value (get-char-attribute char 'ideographic-strokes))
234 (insert (format "(ideographic-strokes . %S)
237 (setq attributes (delq 'ideographic-strokes attributes))
239 (when (setq value (get-char-attribute char 'kangxi-radical))
240 (unless (eq value radical)
241 (insert (format "(kangxi-radical\t . %S)\t; %c
244 (aref ideographic-radicals value)))
246 (setq radical value)))
247 (setq attributes (delq 'kangxi-radical attributes))
249 (when (setq value (get-char-attribute char 'kangxi-strokes))
250 (unless (eq value strokes)
251 (insert (format "(kangxi-strokes\t . %S)
255 (setq strokes value)))
256 (setq attributes (delq 'kangxi-strokes attributes))
258 (when (setq value (get-char-attribute char 'japanese-radical))
259 (unless (eq value radical)
260 (insert (format "(japanese-radical\t . %S)\t; %c
263 (aref ideographic-radicals value)))
265 (setq radical value)))
266 (setq attributes (delq 'japanese-radical attributes))
268 (when (setq value (get-char-attribute char 'japanese-strokes))
269 (unless (eq value strokes)
270 (insert (format "(japanese-strokes\t . %S)
274 (setq strokes value)))
275 (setq attributes (delq 'japanese-strokes attributes))
277 (when (setq value (get-char-attribute char 'cns-radical))
278 (insert (format "(cns-radical\t . %S)\t; %c
281 (aref ideographic-radicals value)))
282 (setq attributes (delq 'cns-radical attributes))
284 (when (setq value (get-char-attribute char 'cns-strokes))
285 (unless (eq value strokes)
286 (insert (format "(cns-strokes\t . %S)
290 (setq strokes value)))
291 (setq attributes (delq 'cns-strokes attributes))
293 (when (setq value (get-char-attribute char 'total-strokes))
294 (insert (format "(total-strokes\t . %S)
297 (setq attributes (delq 'total-strokes attributes))
299 (when (setq value (get-char-attribute char '->ideograph))
300 (insert (format "(->ideograph\t%s)
302 (mapconcat (lambda (code)
303 (cond ((symbolp code)
306 (format "#x%04X" code))
308 (format "\n %S" code))))
310 (setq attributes (delq '->ideograph attributes))
312 (when (setq value (get-char-attribute char '->decomposition))
313 (insert (format "(->decomposition\t%s)
315 (mapconcat (lambda (code)
316 (cond ((symbolp code)
325 (format "#x%04X" code))
327 (format "\n %S" code))))
329 (setq attributes (delq '->decomposition attributes))
331 (when (setq value (get-char-attribute char '->uppercase))
332 (insert (format "(->uppercase\t%s)
334 (mapconcat (lambda (code)
335 (cond ((symbolp code)
338 (format "#x%04X" code))
340 (format "\n %S" code))))
342 (setq attributes (delq '->uppercase attributes))
344 (when (setq value (get-char-attribute char '->lowercase))
345 (insert (format "(->lowercase\t%s)
347 (mapconcat (lambda (code)
348 (cond ((symbolp code)
351 (format "#x%04X" code))
353 (format "\n %S" code))))
355 (setq attributes (delq '->lowercase attributes))
357 (when (setq value (get-char-attribute char '->titlecase))
358 (insert (format "(->titlecase\t%s)
360 (mapconcat (lambda (code)
361 (cond ((symbolp code)
364 (format "#x%04X" code))
366 (format "\n %S" code))))
368 (setq attributes (delq '->titlecase attributes))
370 (setq rest ccs-attributes)
373 (setq value (get-char-attribute char (car rest)))
375 (if (>= (length (symbol-name (car rest))) 19)
377 (setq has-long-ccs-name t)
381 (setq rest (cdr rest)))
383 (setq name (car attributes))
384 (if (setq value (get-char-attribute char name))
385 (cond ((string-match "^->" (symbol-name name))
390 (mapconcat (lambda (code)
391 (cond ((symbolp code)
394 (format "#x%04X" code))
396 (format "\n %S" code))))
399 (insert (format "(%-18s %s)
402 (mapconcat (function prin1-to-string)
404 ((eq name 'jisx0208-1978/4X)
405 (insert (format "(%-18s . #x%04X)
409 (insert (format "(%-18s . %S)
413 (setq attributes (cdr attributes)))
414 (while ccs-attributes
415 (setq name (car ccs-attributes))
416 (if (setq value (get-char-attribute char name))
419 (if has-long-ccs-name
420 (if (memq name '(ideograph-daikanwa mojikyo))
421 "(%-26s . %05d)\t; %c
423 "(%-26s . #x%X)\t; %c
426 (if (memq name '(ideograph-daikanwa mojikyo))
427 "(%-18s . %05d)\t; %c
429 "(%-18s . #x%X)\t; %c
433 (if (= (charset-iso-graphic-plane name) 1)
435 (cond ((= (charset-dimension name) 1)
437 ((= (charset-dimension name) 2)
439 ((= (charset-dimension name) 3)
443 (decode-builtin-char name value))))
444 (setq ccs-attributes (cdr ccs-attributes)))
446 (goto-char (point-min))
447 (while (re-search-forward "[ \t]+$" nil t)
449 (goto-char (point-max))
450 (tabify (point-min)(point-max))
454 (defun char-db-update-comment ()
457 (goto-char (point-min))
458 (let (cdef table char)
459 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
460 (goto-char (match-beginning 1))
461 (setq cdef (read (current-buffer)))
462 (when (find-charset (car cdef))
463 (goto-char (match-end 0))
466 (not (eq (car cdef) 'ideograph-daikanwa))
467 (or (memq (car cdef) '(ascii latin-viscii-upper
471 japanese-jisx0213-2))
472 (= (char-int (charset-iso-final-char (car cdef)))
474 (apply (function make-char) cdef)
475 (if (setq table (charset-mapping-table (car cdef)))
476 (set-charset-mapping-table (car cdef) nil))
478 (apply (function make-char) cdef)
480 (set-charset-mapping-table (car cdef) table)))))
481 (when (not (or (< (char-int char) 32)
482 (and (<= 128 (char-int char))
483 (< (char-int char) 160))))
484 (delete-region (point) (point-at-eol))
485 (insert (format "\t; %c" char)))
488 (defun insert-char-data-with-variant (char &optional script printable)
489 (insert-char-data char printable)
490 (let ((variants (or (char-variants char)
491 (let ((ucs (get-char-attribute char '->ucs)))
493 (delete char (char-variants (int-char ucs)))))))
496 (setq variant (car variants))
497 (if (or (null script)
498 (null (setq vs (get-char-attribute variant 'script)))
500 (insert-char-data variant printable))
501 (setq variants (cdr variants))
504 (defun insert-char-range-data (min max &optional script)
508 (setq char (int-char code))
509 (insert-char-data-with-variant char script)
510 (setq code (1+ code))
513 (defun write-char-range-data-to-file (min max file &optional script)
514 (let ((coding-system-for-write 'utf-8))
516 (insert-char-range-data min max script)
517 (write-region (point-min)(point-max) file))))
519 (defvar what-character-original-window-configuration)
522 (defun what-char-definition (char)
523 (interactive (list (char-after)))
524 (let ((buf (get-buffer-create "*Character Description*"))
525 (the-buf (current-buffer))
526 (win-conf (current-window-configuration)))
528 (make-local-variable 'what-character-original-window-configuration)
529 (setq what-character-original-window-configuration win-conf)
530 (setq buffer-read-only nil)
534 (insert-char-data-with-variant char nil 'printable)
535 ;; (char-db-update-comment)
536 (set-buffer-modified-p nil)
537 (view-mode the-buf (lambda (buf)
538 (set-window-configuration
539 what-character-original-window-configuration)
541 (goto-char (point-min)))
543 (set-window-configuration
544 what-character-original-window-configuration)
545 (signal (car err) (cdr err)))))))
547 (provide 'char-db-util)
549 ;;; char-db-util.el ends here