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-feature-domains
73 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b))
75 (defvar char-db-ignored-attributes nil)
77 (defun char-attribute-name< (ka kb)
83 ((= (charset-dimension ka)
84 (charset-dimension kb))
85 (cond ((= (charset-chars ka)(charset-chars kb))
86 (if (charset-iso-final-char ka)
88 ((>= (charset-iso-final-char ka) ?@)
89 (if (and (charset-iso-final-char kb)
90 (>= (charset-iso-final-char kb) ?@))
91 (< (charset-iso-final-char ka)
92 (charset-iso-final-char kb))
95 (if (charset-iso-final-char kb)
96 (if (>= (charset-iso-final-char kb) ?@)
98 (< (charset-iso-final-char ka)
99 (charset-iso-final-char kb)))
101 (if (charset-iso-final-char kb)
103 (< (charset-id ka)(charset-id kb)))))
104 ((<= (charset-chars ka)(charset-chars kb)))))
106 (< (charset-dimension ka)
107 (charset-dimension kb))
117 (string< (symbol-name ka)
123 (defvar char-db-coded-charset-priority-list
138 japanese-jisx0208-1978
179 (defun char-db-make-char-spec (char)
181 (cond ((characterp char)
182 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
183 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
184 (setq char-spec (list (cons '=ucs ret)))
185 (cond ((setq ret (get-char-attribute char 'name))
186 (setq char-spec (cons (cons 'name ret) char-spec))
188 ((setq ret (get-char-attribute char 'name*))
189 (setq char-spec (cons (cons 'name* ret) char-spec))
194 (let ((rest char-db-coded-charset-priority-list)
197 (setq ccs (charset-name
198 (find-charset (car rest))))
200 (encode-char char ccs
202 (throw 'tag (cons ccs ret)))
203 (setq rest (cdr rest))))))
204 (setq char-spec (list ret))
205 (dolist (ccs (delq (car ret) (charset-list)))
206 (if (and (or (charset-iso-final-char ccs)
212 (setq ret (encode-char char ccs 'defined-only)))
213 (setq char-spec (cons (cons ccs ret) char-spec))))
215 (setq char-spec (split-char char)))
216 (cond ((setq ret (get-char-attribute char 'name))
217 (setq char-spec (cons (cons 'name ret) char-spec))
219 ((setq ret (get-char-attribute char 'name*))
220 (setq char-spec (cons (cons 'name* ret) char-spec))
227 (defun char-db-insert-char-spec (char &optional readable column)
229 (setq column (current-column)))
230 (let (char-spec ret al cal key temp-char)
231 (setq char-spec (char-db-make-char-spec char))
232 (unless (or (characterp char) ; char
234 (setq char (find-char char-spec))
236 ;; define temporary character
237 ;; Current implementation is dirty.
238 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
240 (remove-char-attribute temp-char 'ideograph-daikanwa)
241 (setq char temp-char))
245 (setq key (car (car char-spec)))
246 (unless (memq key char-db-ignored-attributes)
247 (if (find-charset key)
248 (if (encode-char char key 'defined-only)
249 (setq cal (cons key cal)))
250 (setq al (cons key al))))
251 (setq char-spec (cdr char-spec)))
253 (setq char-spec (char-db-make-char-spec char))
255 (setq key (car (car char-spec)))
256 (unless (memq key char-db-ignored-attributes)
257 (if (find-charset key)
258 (setq cal (cons key cal))
259 (setq al (cons key al))))
260 (setq char-spec (cdr char-spec)))
263 (memq 'ideographic-structure al))
264 (push 'ideographic-structure al))
265 (insert-char-attributes char
269 ;; undefine temporary character
270 ;; Current implementation is dirty.
271 (setq char-spec (char-attribute-alist temp-char))
273 (remove-char-attribute temp-char (car (car char-spec)))
274 (setq char-spec (cdr char-spec))))))
276 (defun char-db-insert-alist (alist &optional readable column)
278 (setq column (current-column)))
280 (concat "\n" (make-string (1+ column) ?\ )))
283 lbs cell rest separator)
286 (setq name (car (car alist))
287 value (cdr (car alist)))
288 (cond ((eq name 'char)
290 (if (setq ret (condition-case nil
297 (setq key (car (car value)))
298 (if (find-charset key)
299 (setq cal (cons key cal))
300 (setq al (cons key al)))
301 (setq value (cdr value)))
302 (insert-char-attributes ret
305 (insert (prin1-to-string value)))
307 (insert line-breaking))
309 (insert (format "(%-18s " name))
310 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
312 (setq cell (car value))
313 (if (and (consp cell)
315 (setq ret (condition-case nil
324 (setq key (car (car rest)))
325 (if (find-charset key)
326 (setq cal (cons key cal))
327 (setq al (cons key al)))
328 (setq rest (cdr rest)))
331 (insert-char-attributes ret
334 (setq separator lbs))
337 (insert (prin1-to-string cell))
338 (setq separator " "))
339 (setq value (cdr value)))
341 (insert line-breaking))
343 (insert (format "(%-18s . %S)%s"
346 (setq alist (cdr alist))))
349 (defun char-db-insert-char-reference (plist &optional readable column)
351 (setq column (current-column)))
353 (concat "\n" (make-string (1+ column) ?\ )))
358 (setq name (pop plist))
359 (setq value (pop plist))
360 (cond ((eq name :char)
363 (cond ((numberp value)
364 (setq value (decode-char '=ucs value)))
366 ;; (setq value (or (find-char value)
369 (char-db-insert-char-spec value readable)
370 (insert line-breaking)
373 (insert (format "%s%s\t%d ; %c%s"
376 (aref ideographic-radicals value)
380 (insert (format "%s%s\t%S" separator name value))
381 (setq separator line-breaking)))
385 (defun char-db-decode-isolated-char (ccs code-point)
388 (cond ((eq ccs 'arabic-iso8859-6)
389 (decode-char ccs code-point))
390 ((and (memq ccs '(=gt-pj-1
401 (setq ret (decode-char ccs code-point))
402 (setq ret (encode-char ret '=gt 'defined-only)))
403 (decode-builtin-char '=gt ret))
405 (decode-builtin-char ccs code-point))))
406 (cond ((and (<= 0 (char-int ret))
407 (<= (char-int ret) #x1F))
408 (decode-char '=ucs (+ #x2400 (char-int ret))))
409 ((= (char-int ret) #x7F)
413 (defvar char-db-convert-obsolete-format t)
415 (defun insert-char-attributes (char &optional readable
416 attributes ccs-attributes
421 (if (consp attributes)
423 (dolist (name attributes)
424 (unless (memq name char-db-ignored-attributes)
427 (dolist (name (char-attribute-list))
428 (unless (memq name char-db-ignored-attributes)
429 (if (find-charset name)
433 #'char-attribute-name<))
435 (sort (if ccs-attributes
438 (dolist (name ccs-attributes)
439 (unless (memq name char-db-ignored-attributes)
444 (dolist (name (charset-list))
445 (unless (memq name char-db-ignored-attributes)
448 #'char-attribute-name<)))
450 (setq column (current-column)))
451 (let (name value has-long-ccs-name rest
454 (concat "\n" (make-string (1+ column) ?\ )))
455 lbs cell separator ret
459 (when (and (memq 'name attributes)
460 (setq value (get-char-attribute char 'name)))
462 (if (> (+ (current-column) (length value)) 48)
465 value line-breaking))
466 (setq attributes (delq 'name attributes))
468 (when (and (memq 'name* attributes)
469 (setq value (get-char-attribute char 'name*)))
471 (if (> (+ (current-column) (length value)) 48)
474 value line-breaking))
475 (setq attributes (delq 'name* attributes))
477 (when (and (memq 'script attributes)
478 (setq value (get-char-attribute char 'script)))
479 (insert (format "(script\t\t%s)%s"
480 (mapconcat (function prin1-to-string)
483 (setq attributes (delq 'script attributes))
485 (dolist (name '(=>ucs =>ucs*))
486 (when (and (memq name attributes)
487 (setq value (get-char-attribute char name)))
488 (insert (format "(%-18s . #x%04X)\t; %c%s"
489 name value (decode-char '=ucs value)
491 (setq attributes (delq name attributes))))
492 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
493 (when (and (memq name attributes)
494 (setq value (get-char-attribute char name)))
495 (insert (format "(%-18s . #x%04X)\t; %c%s"
500 (symbol-name name) 2)))
503 (setq attributes (delq name attributes))
505 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
506 (when (and (memq name attributes)
507 (setq value (get-char-attribute char name)))
508 (insert (format "(%-18s . #x%04X)\t; %c%s"
511 (substring (symbol-name name) 6)))
516 (symbol-name name) 6)))
519 (setq attributes (delq name attributes))))
520 (when (and (memq '->ucs attributes)
521 (setq value (get-char-attribute char '->ucs)))
522 (insert (format (if char-db-convert-obsolete-format
523 "(=>ucs\t\t. #x%04X)\t; %c%s"
524 "(->ucs\t\t. #x%04X)\t; %c%s")
525 value (decode-char '=ucs value)
527 (setq attributes (delq '->ucs attributes))
529 (when (and (memq 'general-category attributes)
530 (setq value (get-char-attribute char 'general-category)))
532 "(general-category\t%s) ; %s%s"
533 (mapconcat (lambda (cell)
536 (cond ((rassoc value unidata-normative-category-alist)
537 "Normative Category")
538 ((rassoc value unidata-informative-category-alist)
539 "Informative Category")
543 (setq attributes (delq 'general-category attributes))
545 (when (and (memq 'bidi-category attributes)
546 (setq value (get-char-attribute char 'bidi-category)))
547 (insert (format "(bidi-category\t. %S)%s"
550 (setq attributes (delq 'bidi-category attributes))
552 (unless (or (not (memq 'mirrored attributes))
553 (eq (setq value (get-char-attribute char 'mirrored 'empty))
555 (insert (format "(mirrored\t\t. %S)%s"
558 (setq attributes (delq 'mirrored attributes))
561 ((and (memq 'decimal-digit-value attributes)
562 (setq value (get-char-attribute char 'decimal-digit-value)))
563 (insert (format "(decimal-digit-value . %S)%s"
566 (setq attributes (delq 'decimal-digit-value attributes))
567 (when (and (memq 'digit-value attributes)
568 (setq value (get-char-attribute char 'digit-value)))
569 (insert (format "(digit-value\t . %S)%s"
572 (setq attributes (delq 'digit-value attributes))
574 (when (and (memq 'numeric-value attributes)
575 (setq value (get-char-attribute char 'numeric-value)))
576 (insert (format "(numeric-value\t . %S)%s"
579 (setq attributes (delq 'numeric-value attributes))
583 (when (and (memq 'digit-value attributes)
584 (setq value (get-char-attribute char 'digit-value)))
585 (insert (format "(digit-value\t. %S)%s"
588 (setq attributes (delq 'digit-value attributes))
590 (when (and (memq 'numeric-value attributes)
591 (setq value (get-char-attribute char 'numeric-value)))
592 (insert (format "(numeric-value\t. %S)%s"
595 (setq attributes (delq 'numeric-value attributes))
597 (when (and (memq 'iso-10646-comment attributes)
598 (setq value (get-char-attribute char 'iso-10646-comment)))
599 (insert (format "(iso-10646-comment\t. %S)%s"
602 (setq attributes (delq 'iso-10646-comment attributes))
604 (when (and (memq 'morohashi-daikanwa attributes)
605 (setq value (get-char-attribute char 'morohashi-daikanwa)))
606 (insert (format "(morohashi-daikanwa\t%s)%s"
607 (mapconcat (function prin1-to-string) value " ")
609 (setq attributes (delq 'morohashi-daikanwa attributes))
613 (when (and (memq 'ideographic-radical attributes)
614 (setq value (get-char-attribute char 'ideographic-radical)))
616 (insert (format "(ideographic-radical . %S)\t; %c%s"
618 (aref ideographic-radicals radical)
620 (setq attributes (delq 'ideographic-radical attributes))
623 (dolist (domain char-db-feature-domains)
624 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
625 (when (and (memq key attributes)
626 (setq value (get-char-attribute char key)))
628 (insert (format "(%s . %S)\t; %c%s"
631 (aref ideographic-radicals radical)
633 (setq attributes (delq key attributes))
635 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
636 (when (and (memq key attributes)
637 (setq value (get-char-attribute char key)))
639 (insert (format "(%s . %S)%s"
643 (setq attributes (delq key attributes))
645 (setq key (intern (format "%s@%s" 'total-strokes domain)))
646 (when (and (memq key attributes)
647 (setq value (get-char-attribute char key)))
648 (insert (format "(%s . %S)%s"
652 (setq attributes (delq key attributes))
654 (dolist (feature '(ideographic-radical
657 (setq key (intern (format "%s@%s*sources" feature domain)))
658 (when (and (memq key attributes)
659 (setq value (get-char-attribute char key)))
660 (insert (format "(%s%s" key line-breaking))
662 (insert (format " %s" cell)))
664 (insert line-breaking)
665 (setq attributes (delq key attributes))
668 (when (and (memq 'ideographic-strokes attributes)
669 (setq value (get-char-attribute char 'ideographic-strokes)))
671 (insert (format "(ideographic-strokes . %S)%s"
674 (setq attributes (delq 'ideographic-strokes attributes))
676 (when (and (memq 'kangxi-radical attributes)
677 (setq value (get-char-attribute char 'kangxi-radical)))
678 (unless (eq value radical)
679 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
681 (aref ideographic-radicals value)
684 (setq radical value)))
685 (setq attributes (delq 'kangxi-radical attributes))
687 (when (and (memq 'kangxi-strokes attributes)
688 (setq value (get-char-attribute char 'kangxi-strokes)))
689 (unless (eq value strokes)
690 (insert (format "(kangxi-strokes\t . %S)%s"
694 (setq strokes value)))
695 (setq attributes (delq 'kangxi-strokes attributes))
697 (when (and (memq 'japanese-radical attributes)
698 (setq value (get-char-attribute char 'japanese-radical)))
699 (unless (eq value radical)
700 (insert (format "(japanese-radical\t . %S)\t; %c%s"
702 (aref ideographic-radicals value)
705 (setq radical value)))
706 (setq attributes (delq 'japanese-radical attributes))
708 (when (and (memq 'japanese-strokes attributes)
709 (setq value (get-char-attribute char 'japanese-strokes)))
710 (unless (eq value strokes)
711 (insert (format "(japanese-strokes\t . %S)%s"
715 (setq strokes value)))
716 (setq attributes (delq 'japanese-strokes attributes))
718 (when (and (memq 'cns-radical attributes)
719 (setq value (get-char-attribute char 'cns-radical)))
720 (insert (format "(cns-radical\t . %S)\t; %c%s"
722 (aref ideographic-radicals value)
724 (setq attributes (delq 'cns-radical attributes))
726 (when (and (memq 'cns-strokes attributes)
727 (setq value (get-char-attribute char 'cns-strokes)))
728 (unless (eq value strokes)
729 (insert (format "(cns-strokes\t . %S)%s"
733 (setq strokes value)))
734 (setq attributes (delq 'cns-strokes attributes))
736 (when (and (memq 'shinjigen-1-radical attributes)
737 (setq value (get-char-attribute char 'shinjigen-1-radical)))
738 (unless (eq value radical)
739 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
741 (aref ideographic-radicals value)
744 (setq radical value)))
745 (setq attributes (delq 'shinjigen-1-radical attributes))
747 (when (and (memq 'ideographic- attributes)
748 (setq value (get-char-attribute char 'ideographic-)))
749 (insert "(ideographic- ")
750 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
753 (setq cell (car value))
755 (setq cell (decode-char '=ucs cell)))
756 (cond ((characterp cell)
760 (insert (format "%S" cell))
761 (char-db-insert-char-spec cell readable))
762 (setq separator lbs))
766 (if (consp (car cell))
767 (char-db-insert-char-spec cell readable)
768 (char-db-insert-char-reference cell readable))
769 (setq separator lbs))
773 (insert (prin1-to-string cell))
774 (setq separator " ")))
775 (setq value (cdr value)))
777 (insert line-breaking)
778 (setq attributes (delq 'ideographic- attributes)))
779 (when (and (memq 'total-strokes attributes)
780 (setq value (get-char-attribute char 'total-strokes)))
781 (insert (format "(total-strokes . %S)%s"
784 (setq attributes (delq 'total-strokes attributes))
786 (when (and (memq '->ideograph attributes)
787 (setq value (get-char-attribute char '->ideograph)))
788 (insert (format "(->ideograph\t%s)%s"
789 (mapconcat (lambda (code)
790 (cond ((symbolp code)
793 (format "#x%04X" code))
796 line-breaking code))))
799 (setq attributes (delq '->ideograph attributes))
801 (when (and (memq '->decomposition attributes)
802 (setq value (get-char-attribute char '->decomposition)))
803 (insert (format "(->decomposition\t%s)%s"
804 (mapconcat (lambda (code)
805 (cond ((symbolp code)
814 (format "#x%04X" code))
816 (format "%s%S" line-breaking code))))
819 (setq attributes (delq '->decomposition attributes))
821 (if (equal (get-char-attribute char '->titlecase)
822 (get-char-attribute char '->uppercase))
823 (setq attributes (delq '->titlecase attributes)))
824 (when (and (memq '->mojikyo attributes)
825 (setq value (get-char-attribute char '->mojikyo)))
826 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
827 value (decode-char 'mojikyo value)
829 (setq attributes (delq '->mojikyo attributes))
831 (when (and (memq 'hanyu-dazidian-vol attributes)
832 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
833 (insert (format "(hanyu-dazidian-vol . %d)%s"
834 value line-breaking))
835 (setq attributes (delq 'hanyu-dazidian-vol attributes))
837 (when (and (memq 'hanyu-dazidian-page attributes)
838 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
839 (insert (format "(hanyu-dazidian-page . %d)%s"
840 value line-breaking))
841 (setq attributes (delq 'hanyu-dazidian-page attributes))
843 (when (and (memq 'hanyu-dazidian-char attributes)
844 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
845 (insert (format "(hanyu-dazidian-char . %d)%s"
846 value line-breaking))
847 (setq attributes (delq 'hanyu-dazidian-char attributes))
850 (when (memq '->ucs-unified attributes)
851 (setq attributes (delq '->ucs-unified attributes))
853 (when (memq 'composition attributes)
854 (setq attributes (delq 'composition attributes))
856 (setq rest ccs-attributes)
859 (setq value (get-char-attribute char (car rest)))
861 (if (>= (length (symbol-name (car rest))) 19)
863 (setq has-long-ccs-name t)
867 (setq rest (cdr rest)))
869 (setq name (car attributes))
870 (if (setq value (get-char-attribute char name))
871 (cond ((string-match "^=>ucs@" (symbol-name name))
872 (insert (format "(%-18s . #x%04X)\t; %c%s"
873 name value (decode-char '=ucs value)
876 ((eq name 'jisx0208-1978/4X)
877 (insert (format "(%-18s . #x%04X)%s"
880 ((or (eq name 'ideographic-structure)
881 (eq name 'ideographic-)
882 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
883 (insert (format "(%-18s%s " name line-breaking))
884 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
887 (setq cell (car value))
889 (setq cell (decode-char '=ucs cell)))
890 (cond ((characterp cell)
894 (insert (format "%S" cell))
895 (char-db-insert-char-spec cell readable))
896 (setq separator lbs))
900 (if (consp (car cell))
901 (char-db-insert-char-spec cell readable)
902 (char-db-insert-char-reference cell readable))
903 (setq separator lbs))
907 (insert (prin1-to-string cell))
908 (setq separator " ")))
909 (setq value (cdr value)))
911 (insert line-breaking))
912 ((memq name '(ideograph=
913 original-ideograph-of
917 simplified-ideograph-of
919 ideographic-different-form-of))
920 (insert (format "(%-18s%s " name line-breaking))
921 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
924 (setq cell (car value))
925 (if (and (consp cell)
930 (char-db-insert-alist cell readable)
931 (setq separator lbs))
934 (insert (prin1-to-string cell))
935 (setq separator " "))
936 (setq value (cdr value)))
938 (insert line-breaking))
939 ;; ((string-match "^->" (symbol-name name))
941 ;; (format "(%-18s %s)%s"
943 ;; (mapconcat (lambda (code)
944 ;; (cond ((symbolp code)
945 ;; (symbol-name code))
947 ;; (format "#x%04X" code))
950 ;; line-breaking code))))
954 (insert (format "(%-18s " name))
955 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
958 (setq cell (car value))
959 (if (and (consp cell)
961 (setq ret (condition-case nil
969 (setq key (car (car rest)))
970 (if (find-charset key)
971 (setq cal (cons key cal))
972 (setq al (cons key al)))
973 (setq rest (cdr rest)))
976 (insert-char-attributes ret
979 (setq separator lbs))
982 (insert (prin1-to-string cell))
983 (setq separator " "))
984 (setq value (cdr value)))
986 (insert line-breaking))
988 (insert (format "(%-18s . %S)%s"
992 (setq attributes (cdr attributes)))
993 (while ccs-attributes
994 (setq name (charset-name (car ccs-attributes)))
995 (if (and (not (memq name dest-ccss))
997 (setq value (get-char-attribute char name))
998 (setq dest-ccss (cons name dest-ccss))))
1001 (cond ((memq name '(=daikanwa
1002 =daikanwa-rev1 =daikanwa-rev2
1004 (if has-long-ccs-name
1005 "(%-26s . %05d)\t; %c%s"
1006 "(%-18s . %05d)\t; %c%s"))
1008 (if has-long-ccs-name
1009 "(%-26s . %06d)\t; %c%s"
1010 "(%-18s . %06d)\t; %c%s"))
1011 ((>= (charset-dimension name) 2)
1012 (if has-long-ccs-name
1013 "(%-26s . #x%04X)\t; %c%s"
1014 "(%-18s . #x%04X)\t; %c%s"))
1016 (if has-long-ccs-name
1017 "(%-26s . #x%02X)\t; %c%s"
1018 "(%-18s . #x%02X)\t; %c%s")))
1020 (if (= (charset-iso-graphic-plane name) 1)
1022 (cond ((= (charset-dimension name) 1)
1024 ((= (charset-dimension name) 2)
1026 ((= (charset-dimension name) 3)
1030 (char-db-decode-isolated-char name value)
1032 (setq ccs-attributes (cdr ccs-attributes)))
1035 (defun insert-char-data (char &optional readable
1036 attributes ccs-attributes)
1038 (narrow-to-region (point)(point))
1039 (insert "(define-char
1041 (insert-char-attributes char readable
1042 attributes ccs-attributes)
1044 (goto-char (point-min))
1045 (while (re-search-forward "[ \t]+$" nil t)
1048 (goto-char (point-min))
1049 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1050 (let ((column (current-column))
1051 (indent-tabs-mode t))
1052 (delete-region (match-beginning 0) (point))
1053 (indent-to column)))
1054 (goto-char (point-max))
1055 ;; (tabify (point-min)(point-max))
1058 (defun insert-char-data-with-variant (char &optional printable
1060 script excluded-script)
1061 (insert-char-data char printable)
1062 (let ((variants (or (char-variants char)
1063 (let ((ucs (get-char-attribute char '->ucs)))
1065 (delete char (char-variants (int-char ucs)))))))
1067 (setq variants (sort variants #'<))
1069 (setq variant (car variants))
1070 (if (and (or (null script)
1071 (null (setq vs (get-char-attribute variant 'script)))
1073 (or (null excluded-script)
1074 (null (setq vs (get-char-attribute variant 'script)))
1075 (not (memq excluded-script vs))))
1076 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1077 (insert-char-data variant printable)))
1078 (setq variants (cdr variants))
1081 (defun insert-char-range-data (min max &optional script excluded-script)
1084 (while (<= code max)
1085 (setq char (decode-char '=ucs code))
1086 (if (encode-char char '=ucs 'defined-only)
1087 (insert-char-data-with-variant char nil 'no-ucs-unified
1088 script excluded-script))
1089 (setq code (1+ code)))))
1091 (defun write-char-range-data-to-file (min max file
1092 &optional script excluded-script)
1093 (let ((coding-system-for-write 'utf-8))
1095 (insert-char-range-data min max script excluded-script)
1096 (write-region (point-min)(point-max) file))))
1098 (defvar what-character-original-window-configuration)
1101 (defun what-char-definition (char)
1102 (interactive (list (char-after)))
1103 (let ((buf (get-buffer-create "*Character Description*"))
1104 (the-buf (current-buffer))
1105 (win-conf (current-window-configuration)))
1107 (make-local-variable 'what-character-original-window-configuration)
1108 (setq what-character-original-window-configuration win-conf)
1109 (setq buffer-read-only nil)
1113 (insert-char-data-with-variant char 'printable)
1114 (unless (char-attribute-alist char)
1115 (insert (format ";; = %c\n"
1116 (let* ((rest (split-char char))
1120 (setq code (logior (lsh code 8)
1122 (decode-char ccs code)))))
1123 ;; (char-db-update-comment)
1124 (set-buffer-modified-p nil)
1125 (view-mode the-buf (lambda (buf)
1126 (set-window-configuration
1127 what-character-original-window-configuration)
1129 (goto-char (point-min)))
1131 (set-window-configuration
1132 what-character-original-window-configuration)
1133 (signal (car err) (cdr err)))))))
1135 (provide 'char-db-util)
1137 ;;; char-db-util.el ends here