1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of XEmacs CHISE.
10 ;; XEmacs CHISE 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 CHISE 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 CHISE; 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-feature-domains
73 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
74 jis-x0213 misc unknown))
76 (defvar char-db-ignored-attributes nil)
79 (defun char-ref= (cr1 cr2)
80 (cond ((char-ref-p cr1)
82 (char-spec= (plist-get cr1 :char)
83 (plist-get cr2 :char))
84 (char-spec= (plist-get cr1 :char) cr2)))
92 (defun char-spec= (cs1 cs2)
96 (eq cs1 (find-char cs2)))
98 (eq (find-char cs1) cs2)
99 (eq (find-char cs1) (find-char cs2)))))
101 (defun char-attribute-name< (ka kb)
106 (if (<= (charset-id ka) 0)
107 (if (<= (charset-id kb) 0)
109 ((= (charset-dimension ka)
110 (charset-dimension kb))
111 (> (charset-id ka)(charset-id kb)))
113 (> (charset-dimension ka)
114 (charset-dimension kb))
117 (if (<= (charset-id kb) 0)
119 (< (charset-id ka)(charset-id kb)))))
128 (string< (symbol-name ka)
134 (defvar char-db-coded-charset-priority-list
149 japanese-jisx0208-1978
190 (defun char-db-make-char-spec (char)
192 (cond ((characterp char)
193 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
194 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
195 (setq char-spec (list (cons '=ucs ret)))
196 (cond ((setq ret (get-char-attribute char 'name))
197 (setq char-spec (cons (cons 'name ret) char-spec))
199 ((setq ret (get-char-attribute char 'name*))
200 (setq char-spec (cons (cons 'name* ret) char-spec))
205 (let ((rest char-db-coded-charset-priority-list)
208 (setq ccs (charset-name
209 (find-charset (car rest))))
211 (encode-char char ccs
213 (throw 'tag (cons ccs ret)))
214 (setq rest (cdr rest))))))
215 (setq char-spec (list ret))
216 (dolist (ccs (delq (car ret) (charset-list)))
217 (if (and (or (charset-iso-final-char ccs)
223 (setq ret (encode-char char ccs 'defined-only)))
224 (setq char-spec (cons (cons ccs ret) char-spec))))
226 (setq char-spec (split-char char)))
227 (cond ((setq ret (get-char-attribute char 'name))
228 (setq char-spec (cons (cons 'name ret) char-spec))
230 ((setq ret (get-char-attribute char 'name*))
231 (setq char-spec (cons (cons 'name* ret) char-spec))
238 (defun char-db-insert-char-spec (char &optional readable column
241 (setq column (current-column)))
242 (let (char-spec al cal key temp-char)
243 (setq char-spec (char-db-make-char-spec char))
244 (unless (or (characterp char) ; char
246 (setq char (find-char char-spec))
248 ;; define temporary character
249 ;; Current implementation is dirty.
250 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
252 (remove-char-attribute temp-char 'ideograph-daikanwa)
253 (setq char temp-char))
257 (setq key (car (car char-spec)))
258 (unless (memq key char-db-ignored-attributes)
259 (if (find-charset key)
260 (if (encode-char char key 'defined-only)
261 (setq cal (cons key cal)))
262 (setq al (cons key al))))
263 (setq char-spec (cdr char-spec)))
265 (setq char-spec (char-db-make-char-spec char))
267 (setq key (car (car char-spec)))
268 (unless (memq key char-db-ignored-attributes)
269 (if (find-charset key)
270 (setq cal (cons key cal))
271 (setq al (cons key al))))
272 (setq char-spec (cdr char-spec)))
275 (memq 'ideographic-structure al))
276 (push 'ideographic-structure al))
277 (dolist (feature required-features)
278 (if (find-charset feature)
279 (if (encode-char char feature 'defined-only)
280 (setq cal (adjoin feature cal)))
281 (setq al (adjoin feature 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 (encode-char ret '=gt 'defined-only)))
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 sources required-features)
477 (when (and (memq 'name attributes)
478 (setq value (get-char-attribute char 'name)))
480 (if (> (+ (current-column) (length value)) 48)
483 value line-breaking))
484 (setq attributes (delq 'name attributes))
486 (when (and (memq 'name* attributes)
487 (setq value (get-char-attribute char 'name*)))
489 (if (> (+ (current-column) (length value)) 48)
492 value line-breaking))
493 (setq attributes (delq 'name* attributes))
495 (when (and (memq 'script attributes)
496 (setq value (get-char-attribute char 'script)))
497 (insert (format "(script\t\t%s)%s"
498 (mapconcat (function prin1-to-string)
501 (setq attributes (delq 'script attributes))
503 (dolist (name '(=>ucs =>ucs*))
504 (when (and (memq name attributes)
505 (setq value (get-char-attribute char name)))
506 (insert (format "(%-18s . #x%04X)\t; %c%s"
507 name value (decode-char '=ucs value)
509 (setq attributes (delq name attributes))))
510 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
511 (when (and (memq name attributes)
512 (setq value (get-char-attribute char name)))
513 (insert (format "(%-18s . #x%04X)\t; %c%s"
518 (symbol-name name) 2)))
521 (setq attributes (delq name attributes))
523 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
524 ;; (when (and (memq name attributes)
525 ;; (setq value (get-char-attribute char name)))
526 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
529 ;; (substring (symbol-name name) 6)))
531 ;; (decode-char (intern
534 ;; (symbol-name name) 6)))
537 ;; (setq attributes (delq name attributes))))
538 ;; (when (and (memq '->ucs attributes)
539 ;; (setq value (get-char-attribute char '->ucs)))
540 ;; (insert (format (if char-db-convert-obsolete-format
541 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
542 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
543 ;; value (decode-char '=ucs value)
545 ;; (setq attributes (delq '->ucs attributes))
547 (dolist (name '(=>daikanwa))
548 (when (and (memq name attributes)
549 (setq value (get-char-attribute char name)))
552 (format "(%-18s . %05d)\t; %c%s"
553 name value (decode-char '=daikanwa value)
555 (format "(%-18s %s)\t; %c%s"
557 (mapconcat #'prin1-to-string
559 (char-representative-of-daikanwa char)
561 (setq attributes (delq name attributes))))
562 (when (and (memq 'general-category attributes)
563 (setq value (get-char-attribute char 'general-category)))
565 "(general-category\t%s) ; %s%s"
566 (mapconcat (lambda (cell)
569 (cond ((rassoc value unidata-normative-category-alist)
570 "Normative Category")
571 ((rassoc value unidata-informative-category-alist)
572 "Informative Category")
576 (setq attributes (delq 'general-category attributes))
578 (when (and (memq 'bidi-category attributes)
579 (setq value (get-char-attribute char 'bidi-category)))
580 (insert (format "(bidi-category\t. %S)%s"
583 (setq attributes (delq 'bidi-category attributes))
585 (unless (or (not (memq 'mirrored attributes))
586 (eq (setq value (get-char-attribute char 'mirrored 'empty))
588 (insert (format "(mirrored\t\t. %S)%s"
591 (setq attributes (delq 'mirrored attributes))
594 ((and (memq 'decimal-digit-value attributes)
595 (setq value (get-char-attribute char 'decimal-digit-value)))
596 (insert (format "(decimal-digit-value . %S)%s"
599 (setq attributes (delq 'decimal-digit-value attributes))
600 (when (and (memq 'digit-value attributes)
601 (setq value (get-char-attribute char 'digit-value)))
602 (insert (format "(digit-value\t . %S)%s"
605 (setq attributes (delq 'digit-value attributes))
607 (when (and (memq 'numeric-value attributes)
608 (setq value (get-char-attribute char 'numeric-value)))
609 (insert (format "(numeric-value\t . %S)%s"
612 (setq attributes (delq 'numeric-value attributes))
616 (when (and (memq 'digit-value attributes)
617 (setq value (get-char-attribute char 'digit-value)))
618 (insert (format "(digit-value\t. %S)%s"
621 (setq attributes (delq 'digit-value attributes))
623 (when (and (memq 'numeric-value attributes)
624 (setq value (get-char-attribute char 'numeric-value)))
625 (insert (format "(numeric-value\t. %S)%s"
628 (setq attributes (delq 'numeric-value attributes))
630 (when (and (memq 'iso-10646-comment attributes)
631 (setq value (get-char-attribute char 'iso-10646-comment)))
632 (insert (format "(iso-10646-comment\t. %S)%s"
635 (setq attributes (delq 'iso-10646-comment attributes))
637 (when (and (memq 'morohashi-daikanwa attributes)
638 (setq value (get-char-attribute char 'morohashi-daikanwa)))
639 (insert (format "(morohashi-daikanwa\t%s)%s"
640 (mapconcat (function prin1-to-string) value " ")
642 (setq attributes (delq 'morohashi-daikanwa attributes))
646 (when (and (memq 'ideographic-radical attributes)
647 (setq value (get-char-attribute char 'ideographic-radical)))
649 (insert (format "(ideographic-radical . %S)\t; %c%s"
651 (aref ideographic-radicals radical)
653 (setq attributes (delq 'ideographic-radical attributes))
656 (dolist (domain char-db-feature-domains)
657 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
658 (when (and (memq key attributes)
659 (setq value (get-char-attribute char key)))
661 (insert (format "(%s . %S)\t; %c%s"
664 (aref ideographic-radicals radical)
666 (setq attributes (delq key attributes))
668 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
669 (when (and (memq key attributes)
670 (setq value (get-char-attribute char key)))
672 (insert (format "(%s . %S)%s"
676 (setq attributes (delq key attributes))
678 (setq key (intern (format "%s@%s" 'total-strokes domain)))
679 (when (and (memq key attributes)
680 (setq value (get-char-attribute char key)))
681 (insert (format "(%s . %S)%s"
685 (setq attributes (delq key attributes))
687 (dolist (feature '(ideographic-radical
690 (setq key (intern (format "%s@%s*sources" feature domain)))
691 (when (and (memq key attributes)
692 (setq value (get-char-attribute char key)))
693 (insert (format "(%s%s" key line-breaking))
695 (insert (format " %s" cell)))
697 (insert line-breaking)
698 (setq attributes (delq key attributes))
701 (when (and (memq 'ideographic-strokes attributes)
702 (setq value (get-char-attribute char 'ideographic-strokes)))
704 (insert (format "(ideographic-strokes . %S)%s"
707 (setq attributes (delq 'ideographic-strokes attributes))
709 (when (and (memq 'kangxi-radical attributes)
710 (setq value (get-char-attribute char 'kangxi-radical)))
711 (unless (eq value radical)
712 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
714 (aref ideographic-radicals value)
717 (setq radical value)))
718 (setq attributes (delq 'kangxi-radical attributes))
720 (when (and (memq 'kangxi-strokes attributes)
721 (setq value (get-char-attribute char 'kangxi-strokes)))
722 (unless (eq value strokes)
723 (insert (format "(kangxi-strokes\t . %S)%s"
727 (setq strokes value)))
728 (setq attributes (delq 'kangxi-strokes attributes))
730 (when (and (memq 'japanese-radical attributes)
731 (setq value (get-char-attribute char 'japanese-radical)))
732 (unless (eq value radical)
733 (insert (format "(japanese-radical\t . %S)\t; %c%s"
735 (aref ideographic-radicals value)
738 (setq radical value)))
739 (setq attributes (delq 'japanese-radical attributes))
741 (when (and (memq 'japanese-strokes attributes)
742 (setq value (get-char-attribute char 'japanese-strokes)))
743 (unless (eq value strokes)
744 (insert (format "(japanese-strokes\t . %S)%s"
748 (setq strokes value)))
749 (setq attributes (delq 'japanese-strokes attributes))
751 (when (and (memq 'cns-radical attributes)
752 (setq value (get-char-attribute char 'cns-radical)))
753 (insert (format "(cns-radical\t . %S)\t; %c%s"
755 (aref ideographic-radicals value)
757 (setq attributes (delq 'cns-radical attributes))
759 (when (and (memq 'cns-strokes attributes)
760 (setq value (get-char-attribute char 'cns-strokes)))
761 (unless (eq value strokes)
762 (insert (format "(cns-strokes\t . %S)%s"
766 (setq strokes value)))
767 (setq attributes (delq 'cns-strokes attributes))
769 (when (and (memq 'shinjigen-1-radical attributes)
770 (setq value (get-char-attribute char 'shinjigen-1-radical)))
771 (unless (eq value radical)
772 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
774 (aref ideographic-radicals value)
777 (setq radical value)))
778 (setq attributes (delq 'shinjigen-1-radical attributes))
780 (when (and (memq 'ideographic- attributes)
781 (setq value (get-char-attribute char 'ideographic-)))
782 (insert "(ideographic- ")
783 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
786 (setq cell (car value))
788 (setq cell (decode-char '=ucs cell)))
789 (cond ((characterp cell)
793 (insert (format "%S" cell))
794 (char-db-insert-char-spec cell readable))
795 (setq separator lbs))
799 (if (consp (car cell))
800 (char-db-insert-char-spec cell readable)
801 (char-db-insert-char-reference cell readable))
802 (setq separator lbs))
806 (insert (prin1-to-string cell))
807 (setq separator " ")))
808 (setq value (cdr value)))
810 (insert line-breaking)
811 (setq attributes (delq 'ideographic- attributes)))
812 (when (and (memq 'total-strokes attributes)
813 (setq value (get-char-attribute char 'total-strokes)))
814 (insert (format "(total-strokes . %S)%s"
817 (setq attributes (delq 'total-strokes attributes))
819 (when (and (memq '->ideograph attributes)
820 (setq value (get-char-attribute char '->ideograph)))
821 (insert (format "(->ideograph\t%s)%s"
822 (mapconcat (lambda (code)
823 (cond ((symbolp code)
826 (format "#x%04X" code))
829 line-breaking code))))
832 (setq attributes (delq '->ideograph attributes))
834 (when (and (memq '->decomposition attributes)
835 (setq value (get-char-attribute char '->decomposition)))
836 (insert (format "(->decomposition\t%s)%s"
837 (mapconcat (lambda (code)
838 (cond ((symbolp code)
847 (format "#x%04X" code))
849 (format "%s%S" line-breaking code))))
852 (setq attributes (delq '->decomposition attributes))
854 (if (equal (get-char-attribute char '->titlecase)
855 (get-char-attribute char '->uppercase))
856 (setq attributes (delq '->titlecase attributes)))
857 (when (and (memq '->mojikyo attributes)
858 (setq value (get-char-attribute char '->mojikyo)))
859 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
860 value (decode-char 'mojikyo value)
862 (setq attributes (delq '->mojikyo attributes))
864 (when (and (memq 'hanyu-dazidian-vol attributes)
865 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
866 (insert (format "(hanyu-dazidian-vol . %d)%s"
867 value line-breaking))
868 (setq attributes (delq 'hanyu-dazidian-vol attributes))
870 (when (and (memq 'hanyu-dazidian-page attributes)
871 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
872 (insert (format "(hanyu-dazidian-page . %d)%s"
873 value line-breaking))
874 (setq attributes (delq 'hanyu-dazidian-page attributes))
876 (when (and (memq 'hanyu-dazidian-char attributes)
877 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
878 (insert (format "(hanyu-dazidian-char . %d)%s"
879 value line-breaking))
880 (setq attributes (delq 'hanyu-dazidian-char attributes))
882 (setq rest ccs-attributes)
885 (setq value (get-char-attribute char (car rest)))
887 (if (>= (length (symbol-name (car rest))) 19)
889 (setq has-long-ccs-name t)
893 (setq rest (cdr rest)))
895 (setq name (car attributes))
896 (if (setq value (get-char-attribute char name))
897 (cond ((string-match "^=>ucs@" (symbol-name name))
898 (insert (format "(%-18s . #x%04X)\t; %c%s"
899 name value (decode-char '=ucs value)
902 ((eq name 'jisx0208-1978/4X)
903 (insert (format "(%-18s . #x%04X)%s"
906 ((or (eq name 'ideographic-structure)
907 (eq name 'ideographic-)
908 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
909 (insert (format "(%-18s%s " name line-breaking))
910 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
913 (setq cell (car value))
915 (setq cell (decode-char '=ucs cell)))
916 (cond ((eq name '->unified)
919 (let ((char-db-ignored-attributes
921 char-db-ignored-attributes)))
922 (insert-char-attributes cell readable))
923 (setq separator lbs))
928 (intern (format "%s*sources" name))))
929 (setq required-features nil)
930 (dolist (source sources)
931 (setq required-features
935 (format "=%s" source))))
939 (when (string-match "@JP" (symbol-name name))
940 (setq required-features
941 (union required-features
952 (insert (format "%S" cell))
953 (char-db-insert-char-spec cell readable
956 (setq separator lbs))
960 (if (consp (car cell))
961 (char-db-insert-char-spec cell readable)
962 (char-db-insert-char-reference cell readable))
963 (setq separator lbs))
967 (insert (prin1-to-string cell))
968 (setq separator " ")))
969 (setq value (cdr value)))
971 (insert line-breaking))
972 ((memq name '(ideograph=
973 original-ideograph-of
977 ;; simplified-ideograph-of
979 ;; ideographic-different-form-of
981 (insert (format "(%-18s%s " name line-breaking))
982 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
985 (setq cell (car value))
986 (if (and (consp cell)
991 (char-db-insert-alist cell readable)
992 (setq separator lbs))
995 (insert (prin1-to-string cell))
996 (setq separator " "))
997 (setq value (cdr value)))
999 (insert line-breaking))
1001 (insert (format "(%-18s " name))
1002 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1004 (while (consp value)
1005 (setq cell (car value))
1006 (if (and (consp cell)
1008 (setq ret (condition-case nil
1016 (setq key (car (car rest)))
1017 (if (find-charset key)
1018 (setq cal (cons key cal))
1019 (setq al (cons key al)))
1020 (setq rest (cdr rest)))
1023 (insert-char-attributes ret
1026 (setq separator lbs))
1029 (insert (prin1-to-string cell))
1030 (setq separator " "))
1031 (setq value (cdr value)))
1033 (insert line-breaking))
1035 (insert (format "(%-18s . %S)%s"
1039 (setq attributes (cdr attributes)))
1040 (while ccs-attributes
1041 (setq name (charset-name (car ccs-attributes)))
1042 (if (and (not (memq name dest-ccss))
1044 (setq value (get-char-attribute char name))
1045 (setq dest-ccss (cons name dest-ccss))))
1048 (cond ((memq name '(=daikanwa
1049 =daikanwa-rev1 =daikanwa-rev2
1051 (if has-long-ccs-name
1052 "(%-26s . %05d)\t; %c%s"
1053 "(%-18s . %05d)\t; %c%s"))
1055 (if has-long-ccs-name
1056 "(%-26s . %06d)\t; %c%s"
1057 "(%-18s . %06d)\t; %c%s"))
1058 ((>= (charset-dimension name) 2)
1059 (if has-long-ccs-name
1060 "(%-26s . #x%04X)\t; %c%s"
1061 "(%-18s . #x%04X)\t; %c%s"))
1063 (if has-long-ccs-name
1064 "(%-26s . #x%02X)\t; %c%s"
1065 "(%-18s . #x%02X)\t; %c%s")))
1067 (if (= (charset-iso-graphic-plane name) 1)
1069 (cond ((= (charset-dimension name) 1)
1071 ((= (charset-dimension name) 2)
1073 ((= (charset-dimension name) 3)
1077 (char-db-decode-isolated-char name value)
1079 (setq ccs-attributes (cdr ccs-attributes)))
1082 (defun insert-char-data (char &optional readable
1083 attributes ccs-attributes)
1085 (narrow-to-region (point)(point))
1086 (insert "(define-char
1088 (insert-char-attributes char readable
1089 attributes ccs-attributes)
1091 (goto-char (point-min))
1092 (while (re-search-forward "[ \t]+$" nil t)
1095 (goto-char (point-min))
1096 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1097 (let ((column (current-column))
1098 (indent-tabs-mode t))
1099 (delete-region (match-beginning 0) (point))
1100 (indent-to column)))
1101 (goto-char (point-max))
1102 ;; (tabify (point-min)(point-max))
1105 (defun insert-char-data-with-variant (char &optional printable
1107 script excluded-script)
1108 (insert-char-data char printable)
1109 (let ((variants (or (char-variants char)
1110 (let ((ucs (get-char-attribute char '->ucs)))
1112 (delete char (char-variants (int-char ucs)))))))
1114 (setq variants (sort variants #'<))
1116 (setq variant (car variants))
1117 (if (and (or (null script)
1118 (null (setq vs (get-char-attribute variant 'script)))
1120 (or (null excluded-script)
1121 (null (setq vs (get-char-attribute variant 'script)))
1122 (not (memq excluded-script vs))))
1123 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1124 (insert-char-data variant printable)))
1125 (setq variants (cdr variants))
1128 (defun insert-char-range-data (min max &optional script excluded-script)
1131 (while (<= code max)
1132 (setq char (decode-char '=ucs code))
1133 (if (encode-char char '=ucs 'defined-only)
1134 (insert-char-data-with-variant char nil 'no-ucs-unified
1135 script excluded-script))
1136 (setq code (1+ code)))))
1138 (defun write-char-range-data-to-file (min max file
1139 &optional script excluded-script)
1140 (let ((coding-system-for-write 'utf-8-mcs))
1142 (insert ";; -*- coding: utf-8-mcs -*-\n")
1143 (insert-char-range-data min max script excluded-script)
1144 (write-region (point-min)(point-max) file))))
1146 (defvar what-character-original-window-configuration)
1149 (defun what-char-definition (char)
1150 (interactive (list (char-after)))
1151 (let ((buf (get-buffer-create "*Character Description*"))
1152 (the-buf (current-buffer))
1153 (win-conf (current-window-configuration)))
1155 (make-local-variable 'what-character-original-window-configuration)
1156 (setq what-character-original-window-configuration win-conf)
1157 (setq buffer-read-only nil)
1161 (insert-char-data-with-variant char 'printable)
1162 (unless (char-attribute-alist char)
1163 (insert (format ";; = %c\n"
1164 (let* ((rest (split-char char))
1168 (setq code (logior (lsh code 8)
1170 (decode-char ccs code)))))
1171 ;; (char-db-update-comment)
1172 (set-buffer-modified-p nil)
1173 (view-mode the-buf (lambda (buf)
1174 (set-window-configuration
1175 what-character-original-window-configuration)
1177 (goto-char (point-min)))
1179 (set-window-configuration
1180 what-character-original-window-configuration)
1181 (signal (car err) (cdr err)))))))
1183 (provide 'char-db-util)
1185 ;;; char-db-util.el ends here