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
158 japanese-jisx0208-1978
200 (defun char-db-make-char-spec (char)
202 (cond ((characterp char)
203 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
204 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
205 (setq char-spec (list (cons '=ucs ret)))
206 (cond ((setq ret (get-char-attribute char 'name))
207 (setq char-spec (cons (cons 'name ret) char-spec))
209 ((setq ret (get-char-attribute char 'name*))
210 (setq char-spec (cons (cons 'name* ret) char-spec))
215 (let ((rest char-db-coded-charset-priority-list))
218 (get-char-attribute char (car rest)))
219 (throw 'tag (cons (car rest) ret)))
220 (setq rest (cdr rest))))))
221 (setq char-spec (list ret))
222 (dolist (ccs (delq (car ret) (charset-list)))
223 (if (and (or (charset-iso-final-char ccs)
229 (setq ret (get-char-attribute char ccs)))
230 (setq char-spec (cons (cons ccs ret) char-spec))))
232 (setq char-spec (split-char char)))
233 (cond ((setq ret (get-char-attribute char 'name))
234 (setq char-spec (cons (cons 'name ret) char-spec))
236 ((setq ret (get-char-attribute char 'name*))
237 (setq char-spec (cons (cons 'name* ret) char-spec))
244 (defun char-db-insert-char-spec (char &optional readable column)
246 (setq column (current-column)))
247 (let (char-spec ret al cal key temp-char)
248 (setq char-spec (char-db-make-char-spec char))
249 (unless (or (characterp char) ; char
251 (setq char (find-char char-spec))
253 ;; define temporary character
254 ;; Current implementation is dirty.
255 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
257 (remove-char-attribute temp-char 'ideograph-daikanwa)
258 (setq char temp-char))
262 (setq key (car (car char-spec)))
263 (unless (memq key char-db-ignored-attributes)
264 (if (find-charset key)
265 (if (get-char-attribute char key)
266 (setq cal (cons key cal)))
267 (setq al (cons key al))))
268 (setq char-spec (cdr char-spec)))
270 (setq char-spec (char-db-make-char-spec char))
272 (setq key (car (car char-spec)))
273 (unless (memq key char-db-ignored-attributes)
274 (if (find-charset key)
275 (setq cal (cons key cal))
276 (setq al (cons key al))))
277 (setq char-spec (cdr char-spec)))
280 (memq 'ideographic-structure al))
281 (push 'ideographic-structure al))
282 (insert-char-attributes char
286 ;; undefine temporary character
287 ;; Current implementation is dirty.
288 (setq char-spec (char-attribute-alist temp-char))
290 (remove-char-attribute temp-char (car (car char-spec)))
291 (setq char-spec (cdr char-spec))))))
293 (defun char-db-insert-alist (alist &optional readable column)
295 (setq column (current-column)))
297 (concat "\n" (make-string (1+ column) ?\ )))
300 lbs cell rest separator)
303 (setq name (car (car alist))
304 value (cdr (car alist)))
305 (cond ((eq name 'char)
307 (if (setq ret (condition-case nil
314 (setq key (car (car value)))
315 (if (find-charset key)
316 (setq cal (cons key cal))
317 (setq al (cons key al)))
318 (setq value (cdr value)))
319 (insert-char-attributes ret
322 (insert (prin1-to-string value)))
324 (insert line-breaking))
326 (insert (format "(%-18s " name))
327 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
329 (setq cell (car value))
330 (if (and (consp cell)
332 (setq ret (condition-case nil
341 (setq key (car (car rest)))
342 (if (find-charset key)
343 (setq cal (cons key cal))
344 (setq al (cons key al)))
345 (setq rest (cdr rest)))
348 (insert-char-attributes ret
351 (setq separator lbs))
354 (insert (prin1-to-string cell))
355 (setq separator " "))
356 (setq value (cdr value)))
358 (insert line-breaking))
360 (insert (format "(%-18s . %S)%s"
363 (setq alist (cdr alist))))
366 (defun char-db-insert-char-reference (plist &optional readable column)
368 (setq column (current-column)))
370 (concat "\n" (make-string (1+ column) ?\ )))
375 (setq name (pop plist))
376 (setq value (pop plist))
377 (cond ((eq name :char)
380 (cond ((numberp value)
381 (setq value (decode-char '=ucs value)))
383 ;; (setq value (or (find-char value)
386 (char-db-insert-char-spec value readable)
387 (insert line-breaking)
390 (insert (format "%s%s\t%d ; %c%s"
393 (aref ideographic-radicals value)
397 (insert (format "%s%s\t%S" separator name value))
398 (setq separator line-breaking)))
402 (defun char-db-decode-isolated-char (ccs code-point)
405 (cond ((eq ccs 'arabic-iso8859-6)
406 (decode-char ccs code-point))
407 ((and (memq ccs '(=gt-pj-1
418 (setq ret (decode-char ccs code-point))
419 (setq ret (get-char-attribute ret '=gt)))
420 (decode-builtin-char '=gt ret))
422 (decode-builtin-char ccs code-point))))
423 (cond ((and (<= 0 (char-int ret))
424 (<= (char-int ret) #x1F))
425 (decode-char '=ucs (+ #x2400 (char-int ret))))
426 ((= (char-int ret) #x7F)
430 (defvar char-db-convert-obsolete-format t)
432 (defun insert-char-attributes (char &optional readable
433 attributes ccs-attributes
438 (if (consp attributes)
440 (dolist (name attributes)
441 (unless (memq name char-db-ignored-attributes)
444 (dolist (name (char-attribute-list))
445 (unless (memq name char-db-ignored-attributes)
446 (if (find-charset name)
450 #'char-attribute-name<))
452 (sort (if ccs-attributes
455 (dolist (name ccs-attributes)
456 (unless (memq name char-db-ignored-attributes)
461 (dolist (name (charset-list))
462 (unless (memq name char-db-ignored-attributes)
465 #'char-attribute-name<)))
467 (setq column (current-column)))
468 (let (name value has-long-ccs-name rest
471 (concat "\n" (make-string (1+ column) ?\ )))
472 lbs cell separator ret
475 (when (and (memq 'name attributes)
476 (setq value (get-char-attribute char 'name)))
478 (if (> (+ (current-column) (length value)) 48)
481 value line-breaking))
482 (setq attributes (delq 'name attributes))
484 (when (and (memq 'name* attributes)
485 (setq value (get-char-attribute char 'name*)))
487 (if (> (+ (current-column) (length value)) 48)
490 value line-breaking))
491 (setq attributes (delq 'name* attributes))
493 (when (and (memq 'script attributes)
494 (setq value (get-char-attribute char 'script)))
495 (insert (format "(script\t\t%s)%s"
496 (mapconcat (function prin1-to-string)
499 (setq attributes (delq 'script attributes))
501 (dolist (name '(=>ucs =>ucs*))
502 (when (and (memq name attributes)
503 (setq value (get-char-attribute char name)))
504 (insert (format "(%-18s . #x%04X)\t; %c%s"
505 name value (decode-char '=ucs value)
507 (setq attributes (delq name attributes))))
508 ;; (when (and (memq '=>ucs* attributes)
509 ;; (setq value (get-char-attribute char '=>ucs*)))
510 ;; (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
511 ;; value (decode-char '=ucs value)
513 ;; (setq attributes (delq '=>ucs* attributes))
515 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
516 (when (and (memq name attributes)
517 (setq value (get-char-attribute char name)))
518 (insert (format "(%-18s . #x%04X)\t; %c%s"
523 (symbol-name name) 2)))
526 (setq attributes (delq name attributes))
528 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
529 (when (and (memq name attributes)
530 (setq value (get-char-attribute char name)))
531 (insert (format "(%-18s . #x%04X)\t; %c%s"
534 (substring (symbol-name name) 6)))
539 (symbol-name name) 6)))
542 (setq attributes (delq name attributes))))
543 ;; (when (and (memq '=>ucs-gb attributes)
544 ;; (setq value (get-char-attribute char '=>ucs-gb)))
545 ;; (insert (format "(=>ucs@gb\t\t. #x%04X)\t; %c%s"
546 ;; value (decode-char '=ucs@gb value)
548 ;; (setq attributes (delq '=>ucs-gb attributes))
550 ;; (when (and (memq '=>ucs-cns attributes)
551 ;; (setq value (get-char-attribute char '=>ucs-cns)))
552 ;; (insert (format "(=>ucs@cns\t\t. #x%04X)\t; %c%s"
553 ;; value (decode-char '=ucs@cns value)
555 ;; (setq attributes (delq '=>ucs-cns attributes))
557 ;; (when (and (memq '=>ucs-big5 attributes)
558 ;; (setq value (get-char-attribute char '=>ucs-big5)))
559 ;; (insert (format "(=>ucs-big5\t\t. #x%04X)\t; %c%s"
560 ;; value (decode-char 'ucs-big5 value)
562 ;; (setq attributes (delq '=>ucs-big5 attributes))
564 ;; (when (and (memq '=>ucs-jis attributes)
565 ;; (setq value (get-char-attribute char '=>ucs-jis)))
566 ;; (insert (format "(=>ucs@jis\t\t. #x%04X)\t; %c%s"
567 ;; value (decode-char '=ucs@jis value)
569 ;; (setq attributes (delq '=>ucs-jis attributes))
571 ;; (when (and (memq '=>ucs-ks attributes)
572 ;; (setq value (get-char-attribute char '=>ucs-ks)))
573 ;; (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
574 ;; value (decode-char 'ucs-ks value)
576 ;; (setq attributes (delq '=>ucs-ks attributes))
578 (when (and (memq '->ucs attributes)
579 (setq value (get-char-attribute char '->ucs)))
580 (insert (format (if char-db-convert-obsolete-format
581 "(=>ucs\t\t. #x%04X)\t; %c%s"
582 "(->ucs\t\t. #x%04X)\t; %c%s")
583 value (decode-char '=ucs value)
585 (setq attributes (delq '->ucs attributes))
587 (when (and (memq 'general-category attributes)
588 (setq value (get-char-attribute char 'general-category)))
590 "(general-category\t%s) ; %s%s"
591 (mapconcat (lambda (cell)
594 (cond ((rassoc value unidata-normative-category-alist)
595 "Normative Category")
596 ((rassoc value unidata-informative-category-alist)
597 "Informative Category")
601 (setq attributes (delq 'general-category attributes))
603 (when (and (memq 'bidi-category attributes)
604 (setq value (get-char-attribute char 'bidi-category)))
605 (insert (format "(bidi-category\t. %S)%s"
608 (setq attributes (delq 'bidi-category attributes))
610 (unless (or (not (memq 'mirrored attributes))
611 (eq (setq value (get-char-attribute char 'mirrored 'empty))
613 (insert (format "(mirrored\t\t. %S)%s"
616 (setq attributes (delq 'mirrored attributes))
619 ((and (memq 'decimal-digit-value attributes)
620 (setq value (get-char-attribute char 'decimal-digit-value)))
621 (insert (format "(decimal-digit-value . %S)%s"
624 (setq attributes (delq 'decimal-digit-value attributes))
625 (when (and (memq 'digit-value attributes)
626 (setq value (get-char-attribute char 'digit-value)))
627 (insert (format "(digit-value\t . %S)%s"
630 (setq attributes (delq 'digit-value attributes))
632 (when (and (memq 'numeric-value attributes)
633 (setq value (get-char-attribute char 'numeric-value)))
634 (insert (format "(numeric-value\t . %S)%s"
637 (setq attributes (delq 'numeric-value attributes))
641 (when (and (memq 'digit-value attributes)
642 (setq value (get-char-attribute char 'digit-value)))
643 (insert (format "(digit-value\t. %S)%s"
646 (setq attributes (delq 'digit-value attributes))
648 (when (and (memq 'numeric-value attributes)
649 (setq value (get-char-attribute char 'numeric-value)))
650 (insert (format "(numeric-value\t. %S)%s"
653 (setq attributes (delq 'numeric-value attributes))
655 (when (and (memq 'iso-10646-comment attributes)
656 (setq value (get-char-attribute char 'iso-10646-comment)))
657 (insert (format "(iso-10646-comment\t. %S)%s"
660 (setq attributes (delq 'iso-10646-comment attributes))
662 (when (and (memq 'morohashi-daikanwa attributes)
663 (setq value (get-char-attribute char 'morohashi-daikanwa)))
664 (insert (format "(morohashi-daikanwa\t%s)%s"
665 (mapconcat (function prin1-to-string) value " ")
667 (setq attributes (delq 'morohashi-daikanwa attributes))
671 (when (and (memq 'ideographic-radical attributes)
672 (setq value (get-char-attribute char 'ideographic-radical)))
674 (insert (format "(ideographic-radical . %S)\t; %c%s"
676 (aref ideographic-radicals radical)
678 (setq attributes (delq 'ideographic-radical attributes))
680 (when (and (memq 'ideographic-strokes attributes)
681 (setq value (get-char-attribute char 'ideographic-strokes)))
683 (insert (format "(ideographic-strokes . %S)%s"
686 (setq attributes (delq 'ideographic-strokes attributes))
688 (when (and (memq 'kangxi-radical attributes)
689 (setq value (get-char-attribute char 'kangxi-radical)))
690 (unless (eq value radical)
691 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
693 (aref ideographic-radicals value)
696 (setq radical value)))
697 (setq attributes (delq 'kangxi-radical attributes))
699 (when (and (memq 'kangxi-strokes attributes)
700 (setq value (get-char-attribute char 'kangxi-strokes)))
701 (unless (eq value strokes)
702 (insert (format "(kangxi-strokes\t . %S)%s"
706 (setq strokes value)))
707 (setq attributes (delq 'kangxi-strokes attributes))
709 (when (and (memq 'japanese-radical attributes)
710 (setq value (get-char-attribute char 'japanese-radical)))
711 (unless (eq value radical)
712 (insert (format "(japanese-radical\t . %S)\t; %c%s"
714 (aref ideographic-radicals value)
717 (setq radical value)))
718 (setq attributes (delq 'japanese-radical attributes))
720 (when (and (memq 'japanese-strokes attributes)
721 (setq value (get-char-attribute char 'japanese-strokes)))
722 (unless (eq value strokes)
723 (insert (format "(japanese-strokes\t . %S)%s"
727 (setq strokes value)))
728 (setq attributes (delq 'japanese-strokes attributes))
730 (when (and (memq 'cns-radical attributes)
731 (setq value (get-char-attribute char 'cns-radical)))
732 (insert (format "(cns-radical\t . %S)\t; %c%s"
734 (aref ideographic-radicals value)
736 (setq attributes (delq 'cns-radical attributes))
738 (when (and (memq 'cns-strokes attributes)
739 (setq value (get-char-attribute char 'cns-strokes)))
740 (unless (eq value strokes)
741 (insert (format "(cns-strokes\t . %S)%s"
745 (setq strokes value)))
746 (setq attributes (delq 'cns-strokes attributes))
748 (when (and (memq 'shinjigen-1-radical attributes)
749 (setq value (get-char-attribute char 'shinjigen-1-radical)))
750 (unless (eq value radical)
751 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
753 (aref ideographic-radicals value)
756 (setq radical value)))
757 (setq attributes (delq 'shinjigen-1-radical attributes))
759 (when (and (memq 'ideographic- attributes)
760 (setq value (get-char-attribute char 'ideographic-)))
761 (insert "(ideographic- ")
762 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
765 (setq cell (car value))
767 (setq cell (decode-char '=ucs cell)))
768 (cond ((characterp cell)
772 (insert (format "%S" cell))
773 (char-db-insert-char-spec cell readable))
774 (setq separator lbs))
778 (if (consp (car cell))
779 (char-db-insert-char-spec cell readable)
780 (char-db-insert-char-reference cell readable))
781 (setq separator lbs))
785 (insert (prin1-to-string cell))
786 (setq separator " ")))
787 (setq value (cdr value)))
789 (insert line-breaking)
790 (setq attributes (delq 'ideographic- attributes)))
791 (when (and (memq 'total-strokes attributes)
792 (setq value (get-char-attribute char 'total-strokes)))
793 (insert (format "(total-strokes . %S)%s"
796 (setq attributes (delq 'total-strokes attributes))
798 (when (and (memq '->ideograph attributes)
799 (setq value (get-char-attribute char '->ideograph)))
800 (insert (format "(->ideograph\t%s)%s"
801 (mapconcat (lambda (code)
802 (cond ((symbolp code)
805 (format "#x%04X" code))
808 line-breaking code))))
811 (setq attributes (delq '->ideograph attributes))
813 (when (and (memq '->decomposition attributes)
814 (setq value (get-char-attribute char '->decomposition)))
815 (insert (format "(->decomposition\t%s)%s"
816 (mapconcat (lambda (code)
817 (cond ((symbolp code)
826 (format "#x%04X" code))
828 (format "%s%S" line-breaking code))))
831 (setq attributes (delq '->decomposition attributes))
833 (if (equal (get-char-attribute char '->titlecase)
834 (get-char-attribute char '->uppercase))
835 (setq attributes (delq '->titlecase attributes)))
836 (when (and (memq '->mojikyo attributes)
837 (setq value (get-char-attribute char '->mojikyo)))
838 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
839 value (decode-char 'mojikyo value)
841 (setq attributes (delq '->mojikyo attributes))
843 (when (and (memq 'hanyu-dazidian-vol attributes)
844 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
845 (insert (format "(hanyu-dazidian-vol . %d)%s"
846 value line-breaking))
847 (setq attributes (delq 'hanyu-dazidian-vol attributes))
849 (when (and (memq 'hanyu-dazidian-page attributes)
850 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
851 (insert (format "(hanyu-dazidian-page . %d)%s"
852 value line-breaking))
853 (setq attributes (delq 'hanyu-dazidian-page attributes))
855 (when (and (memq 'hanyu-dazidian-char attributes)
856 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
857 (insert (format "(hanyu-dazidian-char . %d)%s"
858 value line-breaking))
859 (setq attributes (delq 'hanyu-dazidian-char attributes))
861 (setq rest ccs-attributes)
864 (setq value (get-char-attribute char (car rest)))
866 (if (>= (length (symbol-name (car rest))) 19)
868 (setq has-long-ccs-name t)
872 (setq rest (cdr rest)))
874 (setq name (car attributes))
875 (if (setq value (get-char-attribute char name))
876 (cond ((string-match "^=>ucs@" (symbol-name name))
877 (insert (format "(%-18s . #x%04X)\t; %c%s"
878 name value (decode-char '=ucs value)
881 ((eq name 'jisx0208-1978/4X)
882 (insert (format "(%-18s . #x%04X)%s"
885 ((or (eq name 'ideographic-structure)
886 (eq name 'ideographic-)
887 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
888 (insert (format "(%-18s%s " name line-breaking))
889 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
892 (setq cell (car value))
894 (setq cell (decode-char '=ucs cell)))
895 (cond ((characterp cell)
899 (insert (format "%S" cell))
900 (char-db-insert-char-spec cell readable))
901 (setq separator lbs))
905 (if (consp (car cell))
906 (char-db-insert-char-spec cell readable)
907 (char-db-insert-char-reference cell readable))
908 (setq separator lbs))
912 (insert (prin1-to-string cell))
913 (setq separator " ")))
914 (setq value (cdr value)))
916 (insert line-breaking))
917 ((memq name '(ideograph=
918 original-ideograph-of
922 simplified-ideograph-of
924 ideographic-different-form-of))
925 (insert (format "(%-18s%s " name line-breaking))
926 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
929 (setq cell (car value))
930 (if (and (consp cell)
935 (char-db-insert-alist cell readable)
936 (setq separator lbs))
939 (insert (prin1-to-string cell))
940 (setq separator " "))
941 (setq value (cdr value)))
943 (insert line-breaking))
944 ;; ((string-match "^->" (symbol-name name))
946 ;; (format "(%-18s %s)%s"
948 ;; (mapconcat (lambda (code)
949 ;; (cond ((symbolp code)
950 ;; (symbol-name code))
952 ;; (format "#x%04X" code))
955 ;; line-breaking code))))
959 (insert (format "(%-18s " name))
960 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
963 (setq cell (car value))
964 (if (and (consp cell)
966 (setq ret (condition-case nil
974 (setq key (car (car rest)))
975 (if (find-charset key)
976 (setq cal (cons key cal))
977 (setq al (cons key al)))
978 (setq rest (cdr rest)))
981 (insert-char-attributes ret
984 (setq separator lbs))
987 (insert (prin1-to-string cell))
988 (setq separator " "))
989 (setq value (cdr value)))
991 (insert line-breaking))
993 (insert (format "(%-18s . %S)%s"
997 (setq attributes (cdr attributes)))
998 (while ccs-attributes
999 (setq name (car ccs-attributes))
1000 (if (and (eq name (charset-name name))
1001 (setq value (get-char-attribute char name)))
1004 (cond ((memq name '(ideograph-daikanwa
1008 (if has-long-ccs-name
1009 "(%-26s . %05d)\t; %c%s"
1010 "(%-18s . %05d)\t; %c%s"))
1012 (if has-long-ccs-name
1013 "(%-26s . %06d)\t; %c%s"
1014 "(%-18s . %06d)\t; %c%s"))
1015 ((>= (charset-dimension name) 2)
1016 (if has-long-ccs-name
1017 "(%-26s . #x%04X)\t; %c%s"
1018 "(%-18s . #x%04X)\t; %c%s"))
1020 (if has-long-ccs-name
1021 "(%-26s . #x%02X)\t; %c%s"
1022 "(%-18s . #x%02X)\t; %c%s")))
1024 (if (= (charset-iso-graphic-plane name) 1)
1026 (cond ((= (charset-dimension name) 1)
1028 ((= (charset-dimension name) 2)
1030 ((= (charset-dimension name) 3)
1034 (char-db-decode-isolated-char name value)
1036 (setq ccs-attributes (cdr ccs-attributes)))
1039 (defun insert-char-data (char &optional readable
1040 attributes ccs-attributes)
1042 (narrow-to-region (point)(point))
1043 (insert "(define-char
1045 (insert-char-attributes char readable
1046 attributes ccs-attributes)
1048 (goto-char (point-min))
1049 (while (re-search-forward "[ \t]+$" nil t)
1052 (goto-char (point-min))
1053 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1054 (let ((column (current-column))
1055 (indent-tabs-mode t))
1056 (delete-region (match-beginning 0) (point))
1057 (indent-to column)))
1058 (goto-char (point-max))
1059 ;; (tabify (point-min)(point-max))
1062 (defun insert-char-data-with-variant (char &optional printable
1064 script excluded-script)
1065 (insert-char-data char printable)
1066 (let ((variants (or (char-variants char)
1067 (let ((ucs (get-char-attribute char '->ucs)))
1069 (delete char (char-variants (int-char ucs)))))))
1071 (setq variants (sort variants #'<))
1073 (setq variant (car variants))
1074 (if (and (or (null script)
1075 (null (setq vs (get-char-attribute variant 'script)))
1077 (or (null excluded-script)
1078 (null (setq vs (get-char-attribute variant 'script)))
1079 (not (memq excluded-script vs))))
1080 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1081 (insert-char-data variant printable)))
1082 (setq variants (cdr variants))
1085 (defun insert-char-range-data (min max &optional script excluded-script)
1088 (while (<= code max)
1089 (setq char (decode-char '=ucs code))
1090 (if (encode-char char '=ucs 'defined-only)
1091 (insert-char-data-with-variant char nil 'no-ucs-variant
1092 script excluded-script))
1093 (setq code (1+ code)))))
1095 (defun write-char-range-data-to-file (min max file
1096 &optional script excluded-script)
1097 (let ((coding-system-for-write 'utf-8))
1099 (insert-char-range-data min max script excluded-script)
1100 (write-region (point-min)(point-max) file))))
1102 (defvar what-character-original-window-configuration)
1105 (defun what-char-definition (char)
1106 (interactive (list (char-after)))
1107 (let ((buf (get-buffer-create "*Character Description*"))
1108 (the-buf (current-buffer))
1109 (win-conf (current-window-configuration)))
1111 (make-local-variable 'what-character-original-window-configuration)
1112 (setq what-character-original-window-configuration win-conf)
1113 (setq buffer-read-only nil)
1117 (insert-char-data-with-variant char 'printable)
1118 (unless (char-attribute-alist char)
1119 (insert (format ";; = %c\n"
1120 (let* ((rest (split-char char))
1124 (setq code (logior (lsh code 8)
1126 (decode-char ccs code)))))
1127 ;; (char-db-update-comment)
1128 (set-buffer-modified-p nil)
1129 (view-mode the-buf (lambda (buf)
1130 (set-window-configuration
1131 what-character-original-window-configuration)
1133 (goto-char (point-min)))
1135 (set-window-configuration
1136 what-character-original-window-configuration)
1137 (signal (car err) (cdr err)))))))
1139 (provide 'char-db-util)
1141 ;;; char-db-util.el ends here