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)))
70 ;; (unless (charset-iso-final-char (car (split-char (aref v 34))))
71 ;; (aset v 34 (make-char 'chinese-gb2312 #x62 #x3A)))
74 (defvar char-db-ignored-attributes nil)
76 (defun char-attribute-name< (ka kb)
82 ((= (charset-dimension ka)
83 (charset-dimension kb))
84 (cond ((= (charset-chars ka)(charset-chars kb))
85 (if (charset-iso-final-char ka)
87 ((>= (charset-iso-final-char ka) ?@)
88 (if (and (charset-iso-final-char kb)
89 (>= (charset-iso-final-char kb) ?@))
90 (< (charset-iso-final-char ka)
91 (charset-iso-final-char kb))
94 (if (charset-iso-final-char kb)
95 (if (>= (charset-iso-final-char kb) ?@)
97 (< (charset-iso-final-char ka)
98 (charset-iso-final-char kb)))
100 (if (charset-iso-final-char kb)
102 (< (charset-id ka)(charset-id kb)))))
103 ((<= (charset-chars ka)(charset-chars kb)))))
105 (< (charset-dimension ka)
106 (charset-dimension kb))
116 (string< (symbol-name ka)
122 (defvar char-db-coded-charset-priority-list
123 (let ((rest default-coded-charset-priority-list)
126 (when (symbolp (car rest))
127 (cond ((memq (car rest)
136 ((string-match "^ideograph-cbeta" (symbol-name (car rest))))
137 ((string-match "^china3-jef" (symbol-name (car rest))))
138 ((string-match "^chinese-big5" (symbol-name (car rest))))
139 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
140 (unless (memq 'ideograph-gt dest)
141 (setq dest (cons 'ideograph-gt dest))))
143 (setq dest (cons (car rest) dest)))))
144 (setq rest (cdr rest)))
145 (append (sort dest #'char-attribute-name<)
146 '(chinese-big5-cdp ideograph-cbeta china3-jef
147 chinese-big5-eten chinese-big5))))
149 (defun char-db-make-char-spec (char)
151 (cond ((characterp char)
152 (cond ((and (setq ret (get-char-attribute char 'ucs))
153 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
154 (setq char-spec (list (cons 'ucs ret)))
155 (cond ((setq ret (get-char-attribute char 'name))
156 (setq char-spec (cons (cons 'name ret) char-spec))
158 ((setq ret (get-char-attribute char 'name*))
159 (setq char-spec (cons (cons 'name* ret) char-spec))
163 (let ((default-coded-charset-priority-list
164 char-db-coded-charset-priority-list))
166 (setq char-spec (list ret))
167 (dolist (ccs (delq (car ret) (charset-list)))
168 (if (or (and (charset-iso-final-char ccs)
169 (setq ret (get-char-attribute char ccs)))
170 (eq ccs 'ideograph-daikanwa))
171 (setq char-spec (cons (cons ccs ret) char-spec))))
173 (setq char-spec (split-char char)))
174 (cond ((setq ret (get-char-attribute char 'name))
175 (setq char-spec (cons (cons 'name ret) char-spec))
177 ((setq ret (get-char-attribute char 'name*))
178 (setq char-spec (cons (cons 'name* ret) char-spec))
185 (defun char-db-insert-char-spec (char &optional readable column)
187 (setq column (current-column)))
188 (let (char-spec ret al cal key temp-char)
189 (setq char-spec (char-db-make-char-spec char))
190 (unless (or (characterp char) ; char
192 (setq char (find-char char-spec))
194 ;; define temporary character
195 ;; Current implementation is dirty.
196 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
198 (remove-char-attribute temp-char 'ideograph-daikanwa)
199 (setq char temp-char))
203 (setq key (car (car char-spec)))
204 (unless (memq key char-db-ignored-attributes)
205 (if (find-charset key)
206 (if (get-char-attribute char key)
207 (setq cal (cons key cal)))
208 (setq al (cons key al))))
209 (setq char-spec (cdr char-spec)))
211 (setq char-spec (char-db-make-char-spec char))
213 (setq key (car (car char-spec)))
214 (unless (memq key char-db-ignored-attributes)
215 (if (find-charset key)
216 (setq cal (cons key cal))
217 (setq al (cons key al))))
218 (setq char-spec (cdr char-spec)))
221 (memq 'ideographic-structure al))
222 (push 'ideographic-structure al))
223 (insert-char-attributes char
227 ;; undefine temporary character
228 ;; Current implementation is dirty.
229 (setq char-spec (char-attribute-alist temp-char))
231 (remove-char-attribute temp-char (car (car char-spec)))
232 (setq char-spec (cdr char-spec))))))
234 (defun char-db-insert-alist (alist &optional readable column)
236 (setq column (current-column)))
238 (concat "\n" (make-string (1+ column) ?\ )))
241 lbs cell rest separator)
244 (setq name (car (car alist))
245 value (cdr (car alist)))
246 (cond ((eq name 'char)
248 (if (setq ret (condition-case nil
255 (setq key (car (car value)))
256 (if (find-charset key)
257 (setq cal (cons key cal))
258 (setq al (cons key al)))
259 (setq value (cdr value)))
260 (insert-char-attributes ret
263 (insert (prin1-to-string value)))
265 (insert line-breaking))
267 (insert (format "(%-18s " name))
268 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
270 (setq cell (car value))
271 (if (and (consp cell)
273 (setq ret (condition-case nil
282 (setq key (car (car rest)))
283 (if (find-charset key)
284 (setq cal (cons key cal))
285 (setq al (cons key al)))
286 (setq rest (cdr rest)))
289 (insert-char-attributes ret
292 (setq separator lbs))
295 (insert (prin1-to-string cell))
296 (setq separator " "))
297 (setq value (cdr value)))
299 (insert line-breaking))
301 (insert (format "(%-18s . %S)%s"
304 (setq alist (cdr alist))))
307 (defun char-db-insert-char-reference (plist &optional readable column)
309 (setq column (current-column)))
311 (concat "\n" (make-string (1+ column) ?\ )))
316 (setq name (pop plist))
317 (setq value (pop plist))
318 (cond ((eq name :char)
321 (cond ((numberp value)
322 (setq value (decode-char 'ucs value)))
324 ;; (setq value (or (find-char value)
327 (char-db-insert-char-spec value readable)
328 (insert line-breaking)
331 (insert (format "%s%s\t%d ; %c%s"
334 (aref ideographic-radicals value)
338 (insert (format "%s%s\t%S" separator name value))
339 (setq separator line-breaking)))
343 (defun char-db-decode-isolated-char (ccs code-point)
346 (cond ((eq ccs 'arabic-iso8859-6)
347 (decode-char ccs code-point))
348 ((and (memq ccs '(ideograph-gt-pj-1
359 (setq ret (decode-char ccs code-point))
360 (setq ret (get-char-attribute ret 'ideograph-gt)))
361 (decode-builtin-char 'ideograph-gt ret))
363 (decode-builtin-char ccs code-point))))
364 (cond ((and (<= 0 (char-int ret))
365 (<= (char-int ret) #x1F))
366 (decode-char 'ucs (+ #x2400 (char-int ret))))
367 ((= (char-int ret) #x7F)
371 (defvar char-db-convert-obsolete-format t)
373 (defun insert-char-attributes (char &optional readable
374 attributes ccs-attributes
379 (if (consp attributes)
381 (dolist (name attributes)
382 (unless (memq name char-db-ignored-attributes)
385 (dolist (name (char-attribute-list))
386 (unless (memq name char-db-ignored-attributes)
387 (if (find-charset name)
391 #'char-attribute-name<))
393 (sort (if ccs-attributes
396 (dolist (name ccs-attributes)
397 (unless (memq name char-db-ignored-attributes)
402 (dolist (name (charset-list))
403 (unless (memq name char-db-ignored-attributes)
406 #'char-attribute-name<)))
408 (setq column (current-column)))
409 (let (name value has-long-ccs-name rest
412 (concat "\n" (make-string (1+ column) ?\ )))
413 lbs cell separator ret
416 (when (and (memq 'name attributes)
417 (setq value (get-char-attribute char 'name)))
419 (if (> (+ (current-column) (length value)) 48)
422 value line-breaking))
423 (setq attributes (delq 'name attributes))
425 (when (and (memq 'name* attributes)
426 (setq value (get-char-attribute char 'name*)))
428 (if (> (+ (current-column) (length value)) 48)
431 value line-breaking))
432 (setq attributes (delq 'name* attributes))
434 (when (and (memq 'script attributes)
435 (setq value (get-char-attribute char 'script)))
436 (insert (format "(script\t\t%s)%s"
437 (mapconcat (function prin1-to-string)
440 (setq attributes (delq 'script attributes))
442 (when (and (memq '=>ucs attributes)
443 (setq value (get-char-attribute char '=>ucs)))
444 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
445 value (decode-char 'ucs value)
447 (setq attributes (delq '=>ucs attributes))
449 (when (and (memq '=>ucs* attributes)
450 (setq value (get-char-attribute char '=>ucs*)))
451 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
452 value (decode-char 'ucs value)
454 (setq attributes (delq '=>ucs* attributes))
456 (when (and (memq '=>ucs-gb attributes)
457 (setq value (get-char-attribute char '=>ucs-gb)))
458 (insert (format "(=>ucs-gb\t\t. #x%04X)\t; %c%s"
459 value (decode-char 'ucs value)
461 (setq attributes (delq '=>ucs-gb attributes))
463 (when (and (memq '=>ucs-cns attributes)
464 (setq value (get-char-attribute char '=>ucs-cns)))
465 (insert (format "(=>ucs-cns\t\t. #x%04X)\t; %c%s"
466 value (decode-char 'ucs-cns value)
468 (setq attributes (delq '=>ucs-cns attributes))
470 (when (and (memq '=>ucs-jis attributes)
471 (setq value (get-char-attribute char '=>ucs-jis)))
472 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
473 value (decode-char 'ucs-jis value)
475 (setq attributes (delq '=>ucs-jis attributes))
477 (when (and (memq '=>ucs-ks attributes)
478 (setq value (get-char-attribute char '=>ucs-ks)))
479 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
480 value (decode-char 'ucs-ks value)
482 (setq attributes (delq '=>ucs-ks attributes))
484 (when (and (memq '->ucs attributes)
485 (setq value (get-char-attribute char '->ucs)))
486 (insert (format (if char-db-convert-obsolete-format
487 "(=>ucs\t\t. #x%04X)\t; %c%s"
488 "(->ucs\t\t. #x%04X)\t; %c%s")
489 value (decode-char 'ucs value)
491 (setq attributes (delq '->ucs attributes))
493 (when (and (memq 'general-category attributes)
494 (setq value (get-char-attribute char 'general-category)))
496 "(general-category\t%s) ; %s%s"
497 (mapconcat (lambda (cell)
500 (cond ((rassoc value unidata-normative-category-alist)
501 "Normative Category")
502 ((rassoc value unidata-informative-category-alist)
503 "Informative Category")
507 (setq attributes (delq 'general-category attributes))
509 (when (and (memq 'bidi-category attributes)
510 (setq value (get-char-attribute char 'bidi-category)))
511 (insert (format "(bidi-category\t. %S)%s"
514 (setq attributes (delq 'bidi-category attributes))
516 (unless (or (not (memq 'mirrored attributes))
517 (eq (setq value (get-char-attribute char 'mirrored 'empty))
519 (insert (format "(mirrored\t\t. %S)%s"
522 (setq attributes (delq 'mirrored attributes))
525 ((and (memq 'decimal-digit-value attributes)
526 (setq value (get-char-attribute char 'decimal-digit-value)))
527 (insert (format "(decimal-digit-value . %S)%s"
530 (setq attributes (delq 'decimal-digit-value attributes))
531 (when (and (memq 'digit-value attributes)
532 (setq value (get-char-attribute char 'digit-value)))
533 (insert (format "(digit-value\t . %S)%s"
536 (setq attributes (delq 'digit-value attributes))
538 (when (and (memq 'numeric-value attributes)
539 (setq value (get-char-attribute char 'numeric-value)))
540 (insert (format "(numeric-value\t . %S)%s"
543 (setq attributes (delq 'numeric-value attributes))
547 (when (and (memq 'digit-value attributes)
548 (setq value (get-char-attribute char 'digit-value)))
549 (insert (format "(digit-value\t. %S)%s"
552 (setq attributes (delq 'digit-value attributes))
554 (when (and (memq 'numeric-value attributes)
555 (setq value (get-char-attribute char 'numeric-value)))
556 (insert (format "(numeric-value\t. %S)%s"
559 (setq attributes (delq 'numeric-value attributes))
561 (when (and (memq 'iso-10646-comment attributes)
562 (setq value (get-char-attribute char 'iso-10646-comment)))
563 (insert (format "(iso-10646-comment\t. %S)%s"
566 (setq attributes (delq 'iso-10646-comment attributes))
568 (when (and (memq 'morohashi-daikanwa attributes)
569 (setq value (get-char-attribute char 'morohashi-daikanwa)))
570 (insert (format "(morohashi-daikanwa\t%s)%s"
571 (mapconcat (function prin1-to-string) value " ")
573 (setq attributes (delq 'morohashi-daikanwa attributes))
577 (when (and (memq 'ideographic-radical attributes)
578 (setq value (get-char-attribute char 'ideographic-radical)))
580 (insert (format "(ideographic-radical . %S)\t; %c%s"
582 (aref ideographic-radicals radical)
584 (setq attributes (delq 'ideographic-radical attributes))
586 (when (and (memq 'ideographic-strokes attributes)
587 (setq value (get-char-attribute char 'ideographic-strokes)))
589 (insert (format "(ideographic-strokes . %S)%s"
592 (setq attributes (delq 'ideographic-strokes attributes))
594 (when (and (memq 'kangxi-radical attributes)
595 (setq value (get-char-attribute char 'kangxi-radical)))
596 (unless (eq value radical)
597 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
599 (aref ideographic-radicals value)
602 (setq radical value)))
603 (setq attributes (delq 'kangxi-radical attributes))
605 (when (and (memq 'kangxi-strokes attributes)
606 (setq value (get-char-attribute char 'kangxi-strokes)))
607 (unless (eq value strokes)
608 (insert (format "(kangxi-strokes\t . %S)%s"
612 (setq strokes value)))
613 (setq attributes (delq 'kangxi-strokes attributes))
615 (when (and (memq 'japanese-radical attributes)
616 (setq value (get-char-attribute char 'japanese-radical)))
617 (unless (eq value radical)
618 (insert (format "(japanese-radical\t . %S)\t; %c%s"
620 (aref ideographic-radicals value)
623 (setq radical value)))
624 (setq attributes (delq 'japanese-radical attributes))
626 (when (and (memq 'japanese-strokes attributes)
627 (setq value (get-char-attribute char 'japanese-strokes)))
628 (unless (eq value strokes)
629 (insert (format "(japanese-strokes\t . %S)%s"
633 (setq strokes value)))
634 (setq attributes (delq 'japanese-strokes attributes))
636 (when (and (memq 'cns-radical attributes)
637 (setq value (get-char-attribute char 'cns-radical)))
638 (insert (format "(cns-radical\t . %S)\t; %c%s"
640 (aref ideographic-radicals value)
642 (setq attributes (delq 'cns-radical attributes))
644 (when (and (memq 'cns-strokes attributes)
645 (setq value (get-char-attribute char 'cns-strokes)))
646 (unless (eq value strokes)
647 (insert (format "(cns-strokes\t . %S)%s"
651 (setq strokes value)))
652 (setq attributes (delq 'cns-strokes attributes))
654 (when (and (memq 'shinjigen-1-radical attributes)
655 (setq value (get-char-attribute char 'shinjigen-1-radical)))
656 (unless (eq value radical)
657 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
659 (aref ideographic-radicals value)
662 (setq radical value)))
663 (setq attributes (delq 'shinjigen-1-radical attributes))
665 (when (and (memq 'ideographic- attributes)
666 (setq value (get-char-attribute char 'ideographic-)))
667 (insert "(ideographic- ")
668 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
671 (setq cell (car value))
673 (setq cell (decode-char 'ucs cell)))
674 (cond ((characterp cell)
678 (insert (format "%S" cell))
679 (char-db-insert-char-spec cell readable))
680 (setq separator lbs))
684 (if (consp (car cell))
685 (char-db-insert-char-spec cell readable)
686 (char-db-insert-char-reference cell readable))
687 (setq separator lbs))
691 (insert (prin1-to-string cell))
692 (setq separator " ")))
693 (setq value (cdr value)))
695 (insert line-breaking)
696 (setq attributes (delq 'ideographic- attributes)))
697 (when (and (memq 'total-strokes attributes)
698 (setq value (get-char-attribute char 'total-strokes)))
699 (insert (format "(total-strokes . %S)%s"
702 (setq attributes (delq 'total-strokes attributes))
704 (when (and (memq '->ideograph attributes)
705 (setq value (get-char-attribute char '->ideograph)))
706 (insert (format "(->ideograph\t%s)%s"
707 (mapconcat (lambda (code)
708 (cond ((symbolp code)
711 (format "#x%04X" code))
714 line-breaking code))))
717 (setq attributes (delq '->ideograph attributes))
719 (when (and (memq '->decomposition attributes)
720 (setq value (get-char-attribute char '->decomposition)))
721 (insert (format "(->decomposition\t%s)%s"
722 (mapconcat (lambda (code)
723 (cond ((symbolp code)
732 (format "#x%04X" code))
734 (format "%s%S" line-breaking code))))
737 (setq attributes (delq '->decomposition attributes))
739 (if (equal (get-char-attribute char '->titlecase)
740 (get-char-attribute char '->uppercase))
741 (setq attributes (delq '->titlecase attributes)))
742 (when (and (memq '->mojikyo attributes)
743 (setq value (get-char-attribute char '->mojikyo)))
744 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
745 value (decode-char 'mojikyo value)
747 (setq attributes (delq '->mojikyo attributes))
749 (when (and (memq 'hanyu-dazidian-vol attributes)
750 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
751 (insert (format "(hanyu-dazidian-vol . %d)%s"
752 value line-breaking))
753 (setq attributes (delq 'hanyu-dazidian-vol attributes))
755 (when (and (memq 'hanyu-dazidian-page attributes)
756 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
757 (insert (format "(hanyu-dazidian-page . %d)%s"
758 value line-breaking))
759 (setq attributes (delq 'hanyu-dazidian-page attributes))
761 (when (and (memq 'hanyu-dazidian-char attributes)
762 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
763 (insert (format "(hanyu-dazidian-char . %d)%s"
764 value line-breaking))
765 (setq attributes (delq 'hanyu-dazidian-char attributes))
768 (when (memq '->ucs-variants attributes)
769 (setq attributes (delq '->ucs-variants attributes))
771 (when (memq 'composition attributes)
772 (setq attributes (delq 'composition attributes))
774 (setq rest ccs-attributes)
777 (setq value (get-char-attribute char (car rest)))
779 (if (>= (length (symbol-name (car rest))) 19)
781 (setq has-long-ccs-name t)
785 (setq rest (cdr rest)))
787 (setq name (car attributes))
788 (if (setq value (get-char-attribute char name))
789 (cond ((eq name 'jisx0208-1978/4X)
790 (insert (format "(%-18s . #x%04X)%s"
793 ((or (eq name 'ideographic-structure)
794 (eq name 'ideographic-)
795 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
796 (insert (format "(%-18s%s " name line-breaking))
797 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
800 (setq cell (car value))
802 (setq cell (decode-char 'ucs cell)))
803 (cond ((characterp cell)
807 (insert (format "%S" cell))
808 (char-db-insert-char-spec cell readable))
809 (setq separator lbs))
813 (if (consp (car cell))
814 (char-db-insert-char-spec cell readable)
815 (char-db-insert-char-reference cell readable))
816 (setq separator lbs))
820 (insert (prin1-to-string cell))
821 (setq separator " ")))
822 (setq value (cdr value)))
824 (insert line-breaking))
825 ((memq name '(ideograph=
826 original-ideograph-of
830 simplified-ideograph-of
832 ideographic-different-form-of))
833 (insert (format "(%-18s%s " name line-breaking))
834 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
837 (setq cell (car value))
838 (if (and (consp cell)
843 (char-db-insert-alist cell readable)
844 (setq separator lbs))
847 (insert (prin1-to-string cell))
848 (setq separator " "))
849 (setq value (cdr value)))
851 (insert line-breaking))
852 ;; ((string-match "^->" (symbol-name name))
854 ;; (format "(%-18s %s)%s"
856 ;; (mapconcat (lambda (code)
857 ;; (cond ((symbolp code)
858 ;; (symbol-name code))
860 ;; (format "#x%04X" code))
863 ;; line-breaking code))))
867 (insert (format "(%-18s " name))
868 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
871 (setq cell (car value))
872 (if (and (consp cell)
874 (setq ret (condition-case nil
882 (setq key (car (car rest)))
883 (if (find-charset key)
884 (setq cal (cons key cal))
885 (setq al (cons key al)))
886 (setq rest (cdr rest)))
889 (insert-char-attributes ret
892 (setq separator lbs))
895 (insert (prin1-to-string cell))
896 (setq separator " "))
897 (setq value (cdr value)))
899 (insert line-breaking))
901 (insert (format "(%-18s . %S)%s"
905 (setq attributes (cdr attributes)))
906 (while ccs-attributes
907 (setq name (car ccs-attributes))
908 (if (and (eq name (charset-name name))
909 (setq value (get-char-attribute char name)))
912 (cond ((memq name '(ideograph-daikanwa-2
917 (if has-long-ccs-name
918 "(%-26s . %05d)\t; %c%s"
919 "(%-18s . %05d)\t; %c%s"))
921 (if has-long-ccs-name
922 "(%-26s . %06d)\t; %c%s"
923 "(%-18s . %06d)\t; %c%s"))
924 ((>= (charset-dimension name) 2) ; (eq name 'ucs)
925 (if has-long-ccs-name
926 "(%-26s . #x%04X)\t; %c%s"
927 "(%-18s . #x%04X)\t; %c%s"))
929 (if has-long-ccs-name
930 "(%-26s . #x%02X)\t; %c%s"
931 "(%-18s . #x%02X)\t; %c%s")))
933 (if (= (charset-iso-graphic-plane name) 1)
935 (cond ((= (charset-dimension name) 1)
937 ((= (charset-dimension name) 2)
939 ((= (charset-dimension name) 3)
943 (char-db-decode-isolated-char name value)
945 (setq ccs-attributes (cdr ccs-attributes)))
948 (defun insert-char-data (char &optional readable
949 attributes ccs-attributes)
951 (narrow-to-region (point)(point))
952 (insert "(define-char
954 (insert-char-attributes char readable
955 attributes ccs-attributes)
957 (goto-char (point-min))
958 (while (re-search-forward "[ \t]+$" nil t)
960 (goto-char (point-max))
961 (tabify (point-min)(point-max))
964 (defun insert-char-data-with-variant (char &optional printable
966 script excluded-script)
967 (insert-char-data char printable)
968 (let ((variants (or (char-variants char)
969 (let ((ucs (get-char-attribute char '->ucs)))
971 (delete char (char-variants (int-char ucs)))))))
973 (setq variants (sort variants #'<))
975 (setq variant (car variants))
976 (if (and (or (null script)
977 (null (setq vs (get-char-attribute variant 'script)))
979 (or (null excluded-script)
980 (null (setq vs (get-char-attribute variant 'script)))
981 (not (memq excluded-script vs))))
982 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
983 (insert-char-data variant printable)))
984 (setq variants (cdr variants))
987 (defun insert-char-range-data (min max &optional script excluded-script)
991 (setq char (decode-char 'ucs code))
992 (if (get-char-attribute char 'ucs)
993 (insert-char-data-with-variant char nil 'no-ucs-variant
994 script excluded-script))
995 (setq code (1+ code))
998 (defun write-char-range-data-to-file (min max file
999 &optional script excluded-script)
1000 (let ((coding-system-for-write 'utf-8))
1002 (insert-char-range-data min max script excluded-script)
1003 (write-region (point-min)(point-max) file))))
1005 (defvar what-character-original-window-configuration)
1008 (defun what-char-definition (char)
1009 (interactive (list (char-after)))
1010 (let ((buf (get-buffer-create "*Character Description*"))
1011 (the-buf (current-buffer))
1012 (win-conf (current-window-configuration)))
1014 (make-local-variable 'what-character-original-window-configuration)
1015 (setq what-character-original-window-configuration win-conf)
1016 (setq buffer-read-only nil)
1020 (insert-char-data-with-variant char 'printable)
1021 (unless (char-attribute-alist char)
1022 (insert (format ";; = %c\n"
1023 (let* ((rest (split-char char))
1027 (setq code (logior (lsh code 8)
1029 (decode-char ccs code)))))
1030 ;; (char-db-update-comment)
1031 (set-buffer-modified-p nil)
1032 (view-mode the-buf (lambda (buf)
1033 (set-window-configuration
1034 what-character-original-window-configuration)
1036 (goto-char (point-min)))
1038 (set-window-configuration
1039 what-character-original-window-configuration)
1040 (signal (car err) (cdr err)))))))
1042 (provide 'char-db-util)
1044 ;;; char-db-util.el ends here