1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003 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 XEmacs UTF-2000.
10 ;; XEmacs UTF-2000 is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; XEmacs UTF-2000 is distributed in the hope that it will be useful,
16 ;; but 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 UTF-2000; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
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 (decode-char 'ucs (+ #x2EFF i)))
72 (defvar char-db-ignored-attributes nil)
75 (defun char-ref= (cr1 cr2)
76 (cond ((char-ref-p cr1)
78 (char-spec= (plist-get cr1 :char)
79 (plist-get cr2 :char))
80 (char-spec= (plist-get cr1 :char) cr2)))
88 (defun char-spec= (cs1 cs2)
92 (eq cs1 (find-char cs2)))
94 (eq (find-char cs1) cs2)
95 (eq (find-char cs1) (find-char cs2)))))
97 (defun char-attribute-name< (ka kb)
103 ((= (charset-dimension ka)
104 (charset-dimension kb))
105 (cond ((= (charset-chars ka)(charset-chars kb))
106 (if (charset-iso-final-char ka)
108 ((>= (charset-iso-final-char ka) ?@)
109 (if (and (charset-iso-final-char kb)
110 (>= (charset-iso-final-char kb) ?@))
111 (< (charset-iso-final-char ka)
112 (charset-iso-final-char kb))
115 (if (charset-iso-final-char kb)
116 (if (>= (charset-iso-final-char kb) ?@)
118 (< (charset-iso-final-char ka)
119 (charset-iso-final-char kb)))
121 (if (charset-iso-final-char kb)
123 (< (charset-id ka)(charset-id kb)))))
124 ((<= (charset-chars ka)(charset-chars kb)))))
126 (< (charset-dimension ka)
127 (charset-dimension kb))
137 (string< (symbol-name ka)
143 (defvar char-db-coded-charset-priority-list
144 (let ((rest default-coded-charset-priority-list)
147 (when (symbolp (car rest))
148 (cond ((memq (car rest)
157 ((string-match "^mojikyo-" (symbol-name (car rest))))
158 ((string-match "^ideograph-cbeta" (symbol-name (car rest))))
159 ((string-match "^china3-jef" (symbol-name (car rest))))
160 ((string-match "^chinese-big5" (symbol-name (car rest))))
161 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
162 (unless (memq 'ideograph-gt dest)
163 (setq dest (cons 'ideograph-gt dest))))
165 (setq dest (cons (car rest) dest)))))
166 (setq rest (cdr rest)))
167 (append (sort dest #'char-attribute-name<)
168 '(chinese-big5-cdp ideograph-cbeta china3-jef
169 chinese-big5-eten chinese-big5))))
171 (defun char-db-make-char-spec (char)
173 (cond ((characterp char)
174 (cond ((and (setq ret (get-char-attribute char 'ucs))
175 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
176 (setq char-spec (list (cons 'ucs ret)))
177 (cond ((setq ret (get-char-attribute char 'name))
178 (setq char-spec (cons (cons 'name ret) char-spec))
180 ((setq ret (get-char-attribute char 'name*))
181 (setq char-spec (cons (cons 'name* ret) char-spec))
186 (let ((rest char-db-coded-charset-priority-list))
189 (get-char-attribute char (car rest)))
190 (throw 'tag (cons (car rest) ret)))
191 (setq rest (cdr rest))))))
192 (setq char-spec (list ret))
193 (dolist (ccs (delq (car ret) (charset-list)))
194 (if (or (and (charset-iso-final-char ccs)
195 (setq ret (get-char-attribute char ccs)))
196 (eq ccs 'ideograph-daikanwa))
197 (setq char-spec (cons (cons ccs ret) char-spec))))
199 (setq char-spec (split-char char)))
200 (cond ((setq ret (get-char-attribute char 'name))
201 (setq char-spec (cons (cons 'name ret) char-spec))
203 ((setq ret (get-char-attribute char 'name*))
204 (setq char-spec (cons (cons 'name* ret) char-spec))
211 (defun char-db-insert-char-spec (char &optional readable column)
213 (setq column (current-column)))
214 (let (char-spec ret al cal key temp-char)
215 (setq char-spec (char-db-make-char-spec char))
216 (unless (or (characterp char) ; char
218 (setq char (find-char char-spec))
220 ;; define temporary character
221 ;; Current implementation is dirty.
222 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
224 (remove-char-attribute temp-char 'ideograph-daikanwa)
225 (setq char temp-char))
229 (setq key (car (car char-spec)))
230 (unless (memq key char-db-ignored-attributes)
231 (if (find-charset key)
232 (if (get-char-attribute char key)
233 (setq cal (cons key cal)))
234 (setq al (cons key al))))
235 (setq char-spec (cdr char-spec)))
237 (setq char-spec (char-db-make-char-spec char))
239 (setq key (car (car char-spec)))
240 (unless (memq key char-db-ignored-attributes)
241 (if (find-charset key)
242 (setq cal (cons key cal))
243 (setq al (cons key al))))
244 (setq char-spec (cdr char-spec)))
247 (memq 'ideographic-structure al))
248 (push 'ideographic-structure al))
249 (insert-char-attributes char
253 ;; undefine temporary character
254 ;; Current implementation is dirty.
255 (setq char-spec (char-attribute-alist temp-char))
257 (remove-char-attribute temp-char (car (car char-spec)))
258 (setq char-spec (cdr char-spec))))))
260 (defun char-db-insert-alist (alist &optional readable column)
262 (setq column (current-column)))
264 (concat "\n" (make-string (1+ column) ?\ )))
267 lbs cell rest separator)
270 (setq name (car (car alist))
271 value (cdr (car alist)))
272 (cond ((eq name 'char)
274 (if (setq ret (condition-case nil
281 (setq key (car (car value)))
282 (if (find-charset key)
283 (setq cal (cons key cal))
284 (setq al (cons key al)))
285 (setq value (cdr value)))
286 (insert-char-attributes ret
289 (insert (prin1-to-string value)))
291 (insert line-breaking))
293 (insert (format "(%-18s " name))
294 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
296 (setq cell (car value))
297 (if (and (consp cell)
299 (setq ret (condition-case nil
308 (setq key (car (car rest)))
309 (if (find-charset key)
310 (setq cal (cons key cal))
311 (setq al (cons key al)))
312 (setq rest (cdr rest)))
315 (insert-char-attributes ret
318 (setq separator lbs))
321 (insert (prin1-to-string cell))
322 (setq separator " "))
323 (setq value (cdr value)))
325 (insert line-breaking))
327 (insert (format "(%-18s . %S)%s"
330 (setq alist (cdr alist))))
333 (defun char-db-insert-char-reference (plist &optional readable column)
335 (setq column (current-column)))
337 (concat "\n" (make-string (1+ column) ?\ )))
342 (setq name (pop plist))
343 (setq value (pop plist))
344 (cond ((eq name :char)
347 (cond ((numberp value)
348 (setq value (decode-char 'ucs value)))
350 ;; (setq value (or (find-char value)
353 (char-db-insert-char-spec value readable)
354 (insert line-breaking)
357 (insert (format "%s%s\t%d ; %c%s"
360 (aref ideographic-radicals value)
364 (insert (format "%s%s\t%S" separator name value))
365 (setq separator line-breaking)))
369 (defun char-db-decode-isolated-char (ccs code-point)
372 (cond ((eq ccs 'arabic-iso8859-6)
373 (decode-char ccs code-point))
374 ((and (memq ccs '(ideograph-gt-pj-1
385 (setq ret (decode-char ccs code-point))
386 (setq ret (get-char-attribute ret 'ideograph-gt)))
387 (decode-builtin-char 'ideograph-gt ret))
389 (decode-builtin-char ccs code-point))))
390 (cond ((and (<= 0 (char-int ret))
391 (<= (char-int ret) #x1F))
392 (decode-char 'ucs (+ #x2400 (char-int ret))))
393 ((= (char-int ret) #x7F)
397 (defvar char-db-convert-obsolete-format t)
399 (defun insert-char-attributes (char &optional readable
400 attributes ccs-attributes
405 (if (consp attributes)
407 (dolist (name attributes)
408 (unless (memq name char-db-ignored-attributes)
411 (dolist (name (char-attribute-list))
412 (unless (memq name char-db-ignored-attributes)
413 (if (find-charset name)
417 #'char-attribute-name<))
419 (sort (if ccs-attributes
422 (dolist (name ccs-attributes)
423 (unless (memq name char-db-ignored-attributes)
428 (dolist (name (charset-list))
429 (unless (memq name char-db-ignored-attributes)
432 #'char-attribute-name<)))
434 (setq column (current-column)))
435 (let (name value has-long-ccs-name rest
438 (concat "\n" (make-string (1+ column) ?\ )))
439 lbs cell separator ret
442 (when (and (memq 'name attributes)
443 (setq value (get-char-attribute char 'name)))
445 (if (> (+ (current-column) (length value)) 48)
448 value line-breaking))
449 (setq attributes (delq 'name attributes))
451 (when (and (memq 'name* attributes)
452 (setq value (get-char-attribute char 'name*)))
454 (if (> (+ (current-column) (length value)) 48)
457 value line-breaking))
458 (setq attributes (delq 'name* attributes))
460 (when (and (memq 'script attributes)
461 (setq value (get-char-attribute char 'script)))
462 (insert (format "(script\t\t%s)%s"
463 (mapconcat (function prin1-to-string)
466 (setq attributes (delq 'script attributes))
468 (when (and (memq '=>ucs attributes)
469 (setq value (get-char-attribute char '=>ucs)))
470 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
471 value (decode-char 'ucs value)
473 (setq attributes (delq '=>ucs attributes))
475 (when (and (memq '=>ucs* attributes)
476 (setq value (get-char-attribute char '=>ucs*)))
477 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
478 value (decode-char 'ucs value)
480 (setq attributes (delq '=>ucs* attributes))
482 (when (and (memq '=>ucs-gb attributes)
483 (setq value (get-char-attribute char '=>ucs-gb)))
484 (insert (format "(=>ucs-gb\t\t. #x%04X)\t; %c%s"
485 value (decode-char 'ucs value)
487 (setq attributes (delq '=>ucs-gb attributes))
489 (when (and (memq '=>ucs-cns attributes)
490 (setq value (get-char-attribute char '=>ucs-cns)))
491 (insert (format "(=>ucs-cns\t\t. #x%04X)\t; %c%s"
492 value (decode-char 'ucs-cns value)
494 (setq attributes (delq '=>ucs-cns attributes))
496 (when (and (memq '=>ucs-jis attributes)
497 (setq value (get-char-attribute char '=>ucs-jis)))
498 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
499 value (decode-char 'ucs-jis value)
501 (setq attributes (delq '=>ucs-jis attributes))
503 (when (and (memq '=>ucs-ks attributes)
504 (setq value (get-char-attribute char '=>ucs-ks)))
505 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
506 value (decode-char 'ucs-ks value)
508 (setq attributes (delq '=>ucs-ks attributes))
510 (when (and (memq '->ucs attributes)
511 (setq value (get-char-attribute char '->ucs)))
512 (insert (format (if char-db-convert-obsolete-format
513 "(=>ucs\t\t. #x%04X)\t; %c%s"
514 "(->ucs\t\t. #x%04X)\t; %c%s")
515 value (decode-char 'ucs value)
517 (setq attributes (delq '->ucs attributes))
519 (when (and (memq 'general-category attributes)
520 (setq value (get-char-attribute char 'general-category)))
522 "(general-category\t%s) ; %s%s"
523 (mapconcat (lambda (cell)
526 (cond ((rassoc value unidata-normative-category-alist)
527 "Normative Category")
528 ((rassoc value unidata-informative-category-alist)
529 "Informative Category")
533 (setq attributes (delq 'general-category attributes))
535 (when (and (memq 'bidi-category attributes)
536 (setq value (get-char-attribute char 'bidi-category)))
537 (insert (format "(bidi-category\t. %S)%s"
540 (setq attributes (delq 'bidi-category attributes))
542 (unless (or (not (memq 'mirrored attributes))
543 (eq (setq value (get-char-attribute char 'mirrored 'empty))
545 (insert (format "(mirrored\t\t. %S)%s"
548 (setq attributes (delq 'mirrored attributes))
551 ((and (memq 'decimal-digit-value attributes)
552 (setq value (get-char-attribute char 'decimal-digit-value)))
553 (insert (format "(decimal-digit-value . %S)%s"
556 (setq attributes (delq 'decimal-digit-value attributes))
557 (when (and (memq 'digit-value attributes)
558 (setq value (get-char-attribute char 'digit-value)))
559 (insert (format "(digit-value\t . %S)%s"
562 (setq attributes (delq 'digit-value attributes))
564 (when (and (memq 'numeric-value attributes)
565 (setq value (get-char-attribute char 'numeric-value)))
566 (insert (format "(numeric-value\t . %S)%s"
569 (setq attributes (delq 'numeric-value attributes))
573 (when (and (memq 'digit-value attributes)
574 (setq value (get-char-attribute char 'digit-value)))
575 (insert (format "(digit-value\t. %S)%s"
578 (setq attributes (delq 'digit-value attributes))
580 (when (and (memq 'numeric-value attributes)
581 (setq value (get-char-attribute char 'numeric-value)))
582 (insert (format "(numeric-value\t. %S)%s"
585 (setq attributes (delq 'numeric-value attributes))
587 (when (and (memq 'iso-10646-comment attributes)
588 (setq value (get-char-attribute char 'iso-10646-comment)))
589 (insert (format "(iso-10646-comment\t. %S)%s"
592 (setq attributes (delq 'iso-10646-comment attributes))
594 (when (and (memq 'morohashi-daikanwa attributes)
595 (setq value (get-char-attribute char 'morohashi-daikanwa)))
596 (insert (format "(morohashi-daikanwa\t%s)%s"
597 (mapconcat (function prin1-to-string) value " ")
599 (setq attributes (delq 'morohashi-daikanwa attributes))
603 (when (and (memq 'ideographic-radical attributes)
604 (setq value (get-char-attribute char 'ideographic-radical)))
606 (insert (format "(ideographic-radical . %S)\t; %c%s"
608 (aref ideographic-radicals radical)
610 (setq attributes (delq 'ideographic-radical attributes))
612 (when (and (memq 'ideographic-strokes attributes)
613 (setq value (get-char-attribute char 'ideographic-strokes)))
615 (insert (format "(ideographic-strokes . %S)%s"
618 (setq attributes (delq 'ideographic-strokes attributes))
620 (when (and (memq 'kangxi-radical attributes)
621 (setq value (get-char-attribute char 'kangxi-radical)))
622 (unless (eq value radical)
623 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
625 (aref ideographic-radicals value)
628 (setq radical value)))
629 (setq attributes (delq 'kangxi-radical attributes))
631 (when (and (memq 'kangxi-strokes attributes)
632 (setq value (get-char-attribute char 'kangxi-strokes)))
633 (unless (eq value strokes)
634 (insert (format "(kangxi-strokes\t . %S)%s"
638 (setq strokes value)))
639 (setq attributes (delq 'kangxi-strokes attributes))
641 (when (and (memq 'japanese-radical attributes)
642 (setq value (get-char-attribute char 'japanese-radical)))
643 (unless (eq value radical)
644 (insert (format "(japanese-radical\t . %S)\t; %c%s"
646 (aref ideographic-radicals value)
649 (setq radical value)))
650 (setq attributes (delq 'japanese-radical attributes))
652 (when (and (memq 'japanese-strokes attributes)
653 (setq value (get-char-attribute char 'japanese-strokes)))
654 (unless (eq value strokes)
655 (insert (format "(japanese-strokes\t . %S)%s"
659 (setq strokes value)))
660 (setq attributes (delq 'japanese-strokes attributes))
662 (when (and (memq 'cns-radical attributes)
663 (setq value (get-char-attribute char 'cns-radical)))
664 (insert (format "(cns-radical\t . %S)\t; %c%s"
666 (aref ideographic-radicals value)
668 (setq attributes (delq 'cns-radical attributes))
670 (when (and (memq 'cns-strokes attributes)
671 (setq value (get-char-attribute char 'cns-strokes)))
672 (unless (eq value strokes)
673 (insert (format "(cns-strokes\t . %S)%s"
677 (setq strokes value)))
678 (setq attributes (delq 'cns-strokes attributes))
680 (when (and (memq 'shinjigen-1-radical attributes)
681 (setq value (get-char-attribute char 'shinjigen-1-radical)))
682 (unless (eq value radical)
683 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
685 (aref ideographic-radicals value)
688 (setq radical value)))
689 (setq attributes (delq 'shinjigen-1-radical attributes))
691 (when (and (memq 'ideographic- attributes)
692 (setq value (get-char-attribute char 'ideographic-)))
693 (insert "(ideographic- ")
694 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
697 (setq cell (car value))
699 (setq cell (decode-char 'ucs cell)))
700 (cond ((characterp cell)
704 (insert (format "%S" cell))
705 (char-db-insert-char-spec cell readable))
706 (setq separator lbs))
710 (if (consp (car cell))
711 (char-db-insert-char-spec cell readable)
712 (char-db-insert-char-reference cell readable))
713 (setq separator lbs))
717 (insert (prin1-to-string cell))
718 (setq separator " ")))
719 (setq value (cdr value)))
721 (insert line-breaking)
722 (setq attributes (delq 'ideographic- attributes)))
723 (when (and (memq 'total-strokes attributes)
724 (setq value (get-char-attribute char 'total-strokes)))
725 (insert (format "(total-strokes . %S)%s"
728 (setq attributes (delq 'total-strokes attributes))
730 (when (and (memq '->ideograph attributes)
731 (setq value (get-char-attribute char '->ideograph)))
732 (insert (format "(->ideograph\t%s)%s"
733 (mapconcat (lambda (code)
734 (cond ((symbolp code)
737 (format "#x%04X" code))
740 line-breaking code))))
743 (setq attributes (delq '->ideograph attributes))
745 (when (and (memq '->decomposition attributes)
746 (setq value (get-char-attribute char '->decomposition)))
747 (insert (format "(->decomposition\t%s)%s"
748 (mapconcat (lambda (code)
749 (cond ((symbolp code)
758 (format "#x%04X" code))
760 (format "%s%S" line-breaking code))))
763 (setq attributes (delq '->decomposition attributes))
765 (if (equal (get-char-attribute char '->titlecase)
766 (get-char-attribute char '->uppercase))
767 (setq attributes (delq '->titlecase attributes)))
768 (when (and (memq '->mojikyo attributes)
769 (setq value (get-char-attribute char '->mojikyo)))
770 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
771 value (decode-char 'mojikyo value)
773 (setq attributes (delq '->mojikyo attributes))
775 (when (and (memq 'hanyu-dazidian-vol attributes)
776 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
777 (insert (format "(hanyu-dazidian-vol . %d)%s"
778 value line-breaking))
779 (setq attributes (delq 'hanyu-dazidian-vol attributes))
781 (when (and (memq 'hanyu-dazidian-page attributes)
782 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
783 (insert (format "(hanyu-dazidian-page . %d)%s"
784 value line-breaking))
785 (setq attributes (delq 'hanyu-dazidian-page attributes))
787 (when (and (memq 'hanyu-dazidian-char attributes)
788 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
789 (insert (format "(hanyu-dazidian-char . %d)%s"
790 value line-breaking))
791 (setq attributes (delq 'hanyu-dazidian-char attributes))
793 (setq rest ccs-attributes)
796 (setq value (get-char-attribute char (car rest)))
798 (if (>= (length (symbol-name (car rest))) 19)
800 (setq has-long-ccs-name t)
804 (setq rest (cdr rest)))
806 (setq name (car attributes))
807 (if (setq value (get-char-attribute char name))
808 (cond ((eq name 'jisx0208-1978/4X)
809 (insert (format "(%-18s . #x%04X)%s"
812 ((or (eq name 'ideographic-structure)
813 (eq name 'ideographic-)
814 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
815 (insert (format "(%-18s%s " name line-breaking))
816 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
819 (setq cell (car value))
821 (setq cell (decode-char 'ucs cell)))
822 (cond ((characterp cell)
826 (insert (format "%S" cell))
827 (char-db-insert-char-spec cell readable))
828 (setq separator lbs))
832 (if (consp (car cell))
833 (char-db-insert-char-spec cell readable)
834 (char-db-insert-char-reference cell readable))
835 (setq separator lbs))
839 (insert (prin1-to-string cell))
840 (setq separator " ")))
841 (setq value (cdr value)))
843 (insert line-breaking))
844 ((memq name '(ideograph=
845 original-ideograph-of
849 simplified-ideograph-of
851 ideographic-different-form-of))
852 (insert (format "(%-18s%s " name line-breaking))
853 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
856 (setq cell (car value))
857 (if (and (consp cell)
862 (char-db-insert-alist cell readable)
863 (setq separator lbs))
866 (insert (prin1-to-string cell))
867 (setq separator " "))
868 (setq value (cdr value)))
870 (insert line-breaking))
871 ;; ((string-match "^->" (symbol-name name))
873 ;; (format "(%-18s %s)%s"
875 ;; (mapconcat (lambda (code)
876 ;; (cond ((symbolp code)
877 ;; (symbol-name code))
879 ;; (format "#x%04X" code))
882 ;; line-breaking code))))
886 (insert (format "(%-18s " name))
887 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
890 (setq cell (car value))
891 (if (and (consp cell)
893 (setq ret (condition-case nil
901 (setq key (car (car rest)))
902 (if (find-charset key)
903 (setq cal (cons key cal))
904 (setq al (cons key al)))
905 (setq rest (cdr rest)))
908 (insert-char-attributes ret
911 (setq separator lbs))
914 (insert (prin1-to-string cell))
915 (setq separator " "))
916 (setq value (cdr value)))
918 (insert line-breaking))
920 (insert (format "(%-18s . %S)%s"
924 (setq attributes (cdr attributes)))
925 (while ccs-attributes
926 (setq name (car ccs-attributes))
927 (if (and (eq name (charset-name name))
928 (setq value (get-char-attribute char name)))
931 (cond ((memq name '(ideograph-daikanwa-2
936 (if has-long-ccs-name
937 "(%-26s . %05d)\t; %c%s"
938 "(%-18s . %05d)\t; %c%s"))
940 (if has-long-ccs-name
941 "(%-26s . %06d)\t; %c%s"
942 "(%-18s . %06d)\t; %c%s"))
943 ((>= (charset-dimension name) 2)
944 (if has-long-ccs-name
945 "(%-26s . #x%04X)\t; %c%s"
946 "(%-18s . #x%04X)\t; %c%s"))
948 (if has-long-ccs-name
949 "(%-26s . #x%02X)\t; %c%s"
950 "(%-18s . #x%02X)\t; %c%s")))
952 (if (= (charset-iso-graphic-plane name) 1)
954 (cond ((= (charset-dimension name) 1)
956 ((= (charset-dimension name) 2)
958 ((= (charset-dimension name) 3)
962 (char-db-decode-isolated-char name value)
964 (setq ccs-attributes (cdr ccs-attributes)))
967 (defun insert-char-data (char &optional readable
968 attributes ccs-attributes)
970 (narrow-to-region (point)(point))
971 (insert "(define-char
973 (insert-char-attributes char readable
974 attributes ccs-attributes)
976 (goto-char (point-min))
977 (while (re-search-forward "[ \t]+$" nil t)
979 (goto-char (point-max))
980 (tabify (point-min)(point-max))
983 (defun insert-char-data-with-variant (char &optional printable
985 script excluded-script)
986 (insert-char-data char printable)
987 (let ((variants (or (char-variants char)
988 (let ((ucs (get-char-attribute char '->ucs)))
990 (delete char (char-variants (int-char ucs)))))))
992 (setq variants (sort variants #'<))
994 (setq variant (car variants))
995 (if (and (or (null script)
996 (null (setq vs (get-char-attribute variant 'script)))
998 (or (null excluded-script)
999 (null (setq vs (get-char-attribute variant 'script)))
1000 (not (memq excluded-script vs))))
1001 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
1002 (insert-char-data variant printable)))
1003 (setq variants (cdr variants))
1006 (defun insert-char-range-data (min max &optional script excluded-script)
1009 (while (<= code max)
1010 (setq char (decode-char 'ucs code))
1011 (if (get-char-attribute char 'ucs)
1012 (insert-char-data-with-variant char nil 'no-ucs-variant
1013 script excluded-script))
1014 (setq code (1+ code))
1017 (defun write-char-range-data-to-file (min max file
1018 &optional script excluded-script)
1019 (let ((coding-system-for-write 'utf-8))
1021 (insert-char-range-data min max script excluded-script)
1022 (write-region (point-min)(point-max) file))))
1024 (defvar what-character-original-window-configuration)
1027 (defun what-char-definition (char)
1028 (interactive (list (char-after)))
1029 (let ((buf (get-buffer-create "*Character Description*"))
1030 (the-buf (current-buffer))
1031 (win-conf (current-window-configuration)))
1033 (make-local-variable 'what-character-original-window-configuration)
1034 (setq what-character-original-window-configuration win-conf)
1035 (setq buffer-read-only nil)
1039 (insert-char-data-with-variant char 'printable)
1040 (unless (char-attribute-alist char)
1041 (insert (format ";; = %c\n"
1042 (let* ((rest (split-char char))
1046 (setq code (logior (lsh code 8)
1048 (decode-char ccs code)))))
1049 ;; (char-db-update-comment)
1050 (set-buffer-modified-p nil)
1051 (view-mode the-buf (lambda (buf)
1052 (set-window-configuration
1053 what-character-original-window-configuration)
1055 (goto-char (point-min)))
1057 (set-window-configuration
1058 what-character-original-window-configuration)
1059 (signal (car err) (cdr err)))))))
1061 (provide 'char-db-util)
1063 ;;; char-db-util.el ends here