1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002 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 (int-char (+ #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 "^chinese-big5" (symbol-name (car rest))))
137 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
138 (unless (memq 'ideograph-gt dest)
139 (setq dest (cons 'ideograph-gt dest))))
141 (setq dest (cons (car rest) dest)))))
142 (setq rest (cdr rest)))
143 (append (sort dest #'char-attribute-name<)
144 '(chinese-big5-cdp chinese-big5-eten chinese-big5))))
146 (defun char-db-make-char-spec (char)
148 (cond ((characterp char)
149 (cond ((and (setq ret (get-char-attribute char 'ucs))
150 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
151 (setq char-spec (list (cons 'ucs ret)))
152 (if (setq ret (get-char-attribute char 'name))
153 (setq char-spec (cons (cons 'name ret) char-spec)))
156 (let ((default-coded-charset-priority-list
157 char-db-coded-charset-priority-list))
159 (setq char-spec (list ret))
160 (dolist (ccs (delq (car ret) (charset-list)))
161 (if (or (and (charset-iso-final-char ccs)
162 (setq ret (get-char-attribute char ccs)))
163 (eq ccs 'ideograph-daikanwa))
164 (setq char-spec (cons (cons ccs ret) char-spec))))
166 (setq char-spec (split-char char)))
167 (if (setq ret (get-char-attribute char 'name))
168 (setq char-spec (cons (cons 'name ret) char-spec)))
174 (defun char-db-insert-char-spec (char &optional readable column)
176 (setq column (current-column)))
177 (let (char-spec ret al cal key temp-char)
178 (setq char-spec (char-db-make-char-spec char))
179 ;; (cond ((characterp char)
180 ;; (cond ((and (setq ret (get-char-attribute char 'ucs))
181 ;; (not (and (<= #xE000 ret)(<= ret #xF8FF))))
182 ;; (setq char-spec (list (cons 'ucs ret)))
183 ;; (if (setq ret (get-char-attribute char 'name))
184 ;; (setq char-spec (cons (cons 'name ret) char-spec)))
187 ;; (let ((default-coded-charset-priority-list
188 ;; char-db-coded-charset-priority-list))
189 ;; (split-char char)))
190 ;; (setq char-spec (list ret))
191 ;; (dolist (ccs (delq (car ret) (charset-list)))
192 ;; (if (or (and (charset-iso-final-char ccs)
193 ;; (setq ret (get-char-attribute char ccs)))
194 ;; (eq ccs 'ideograph-daikanwa))
195 ;; (setq char-spec (cons (cons ccs ret) char-spec))))
196 ;; (if (null char-spec)
197 ;; (setq char-spec (split-char char)))
198 ;; (if (setq ret (get-char-attribute char 'name))
199 ;; (setq char-spec (cons (cons 'name ret) char-spec)))
202 ;; (setq char-spec char)
204 (unless (or (characterp char) ; char
206 (setq char (find-char char-spec))
208 ;; define temporary character
209 ;; Current implementation is dirty.
210 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
212 (remove-char-attribute temp-char 'ideograph-daikanwa)
213 (setq char temp-char))
217 (setq key (car (car char-spec)))
218 (unless (memq key char-db-ignored-attributes)
219 (if (find-charset key)
220 (if (get-char-attribute char key)
221 (setq cal (cons key cal)))
222 (setq al (cons key al))))
223 (setq char-spec (cdr char-spec)))
225 (setq char-spec (char-db-make-char-spec char))
227 (setq key (car (car char-spec)))
228 (unless (memq key char-db-ignored-attributes)
229 (if (find-charset key)
230 (setq cal (cons key cal))
231 (setq al (cons key al))))
232 (setq char-spec (cdr char-spec)))
235 (memq 'ideographic-structure al))
236 (push 'ideographic-structure al))
237 (insert-char-attributes char
241 ;; undefine temporary character
242 ;; Current implementation is dirty.
243 (setq char-spec (char-attribute-alist temp-char))
245 (remove-char-attribute temp-char (car (car char-spec)))
246 (setq char-spec (cdr char-spec))))))
248 (defun char-db-insert-alist (alist &optional readable column)
250 (setq column (current-column)))
252 (concat "\n" (make-string (1+ column) ?\ )))
255 lbs cell rest separator)
258 (setq name (car (car alist))
259 value (cdr (car alist)))
260 (cond ((eq name 'char)
262 (if (setq ret (condition-case nil
269 (setq key (car (car value)))
270 (if (find-charset key)
271 (setq cal (cons key cal))
272 (setq al (cons key al)))
273 (setq value (cdr value)))
274 (insert-char-attributes ret
277 (insert (prin1-to-string value)))
279 (insert line-breaking))
281 (insert (format "(%-18s " name))
282 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
284 (setq cell (car value))
285 (if (and (consp cell)
287 (setq ret (condition-case nil
296 (setq key (car (car rest)))
297 (if (find-charset key)
298 (setq cal (cons key cal))
299 (setq al (cons key al)))
300 (setq rest (cdr rest)))
303 (insert-char-attributes ret
306 (setq separator lbs))
309 (insert (prin1-to-string cell))
310 (setq separator " "))
311 (setq value (cdr value)))
313 (insert line-breaking))
315 (insert (format "(%-18s . %S)%s"
318 (setq alist (cdr alist))))
321 (defun char-db-insert-char-reference (plist &optional readable column)
323 (setq column (current-column)))
325 (concat "\n" (make-string (1+ column) ?\ )))
330 (setq name (pop plist))
331 (setq value (pop plist))
332 (cond ((eq name :char)
335 (cond ((numberp value)
336 (setq value (decode-char 'ucs value)))
338 ;; (setq value (or (find-char value)
341 (char-db-insert-char-spec value readable)
342 (insert line-breaking)
345 (insert (format "%s%s\t%d ; %c%s"
348 (aref ideographic-radicals value)
352 (insert (format "%s%s\t%S" separator name value))
353 (setq separator line-breaking)))
357 (defun char-db-decode-isolated-char (ccs code-point)
360 (cond ((eq ccs 'arabic-iso8859-6)
361 (decode-char ccs code-point))
362 ((and (memq ccs '(ideograph-gt-pj-1
373 (setq ret (decode-char ccs code-point))
374 (setq ret (get-char-attribute ret 'ideograph-gt)))
375 (decode-builtin-char 'ideograph-gt ret))
377 (decode-builtin-char ccs code-point))))
378 (cond ((and (<= 0 (char-int ret))
379 (<= (char-int ret) #x1F))
380 (decode-char 'ucs (+ #x2400 (char-int ret))))
381 ((= (char-int ret) #x7F)
385 (defvar char-db-convert-obsolete-format t)
387 (defun insert-char-attributes (char &optional readable
388 attributes ccs-attributes
393 (if (consp attributes)
395 (dolist (name attributes)
396 (unless (memq name char-db-ignored-attributes)
399 (dolist (name (char-attribute-list))
400 (unless (memq name char-db-ignored-attributes)
401 (if (find-charset name)
405 #'char-attribute-name<))
407 (sort (if ccs-attributes
410 (dolist (name ccs-attributes)
411 (unless (memq name char-db-ignored-attributes)
416 (dolist (name (charset-list))
417 (unless (memq name char-db-ignored-attributes)
420 #'char-attribute-name<)))
422 (setq column (current-column)))
423 (let (name value has-long-ccs-name rest
426 (concat "\n" (make-string (1+ column) ?\ )))
427 lbs cell separator ret
430 (when (and (memq 'name attributes)
431 (setq value (get-char-attribute char 'name)))
433 (if (> (+ (current-column) (length value)) 48)
436 value line-breaking))
437 (setq attributes (delq 'name attributes))
439 (when (and (memq 'script attributes)
440 (setq value (get-char-attribute char 'script)))
441 (insert (format "(script\t\t%s)%s"
442 (mapconcat (function prin1-to-string)
445 (setq attributes (delq 'script attributes))
447 (when (and (memq '=>ucs attributes)
448 (setq value (get-char-attribute char '=>ucs)))
449 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
450 value (decode-char 'ucs value)
452 (setq attributes (delq '=>ucs attributes))
454 (when (and (memq '=>ucs* attributes)
455 (setq value (get-char-attribute char '=>ucs*)))
456 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
457 value (decode-char 'ucs value)
459 (setq attributes (delq '=>ucs* attributes))
461 (when (and (memq '=>ucs-gb attributes)
462 (setq value (get-char-attribute char '=>ucs-gb)))
463 (insert (format "(=>ucs-gb\t\t. #x%04X)\t; %c%s"
464 value (decode-char 'ucs value)
466 (setq attributes (delq '=>ucs-gb attributes))
468 (when (and (memq '=>ucs-cns attributes)
469 (setq value (get-char-attribute char '=>ucs-cns)))
470 (insert (format "(=>ucs-cns\t\t. #x%04X)\t; %c%s"
471 value (decode-char 'ucs-cns value)
473 (setq attributes (delq '=>ucs-cns attributes))
475 (when (and (memq '=>ucs-jis attributes)
476 (setq value (get-char-attribute char '=>ucs-jis)))
477 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
478 value (decode-char 'ucs-jis value)
480 (setq attributes (delq '=>ucs-jis attributes))
482 (when (and (memq '->ucs attributes)
483 (setq value (get-char-attribute char '->ucs)))
484 (insert (format (if char-db-convert-obsolete-format
485 "(=>ucs\t\t. #x%04X)\t; %c%s"
486 "(->ucs\t\t. #x%04X)\t; %c%s")
487 value (decode-char 'ucs value)
489 (setq attributes (delq '->ucs attributes))
491 (when (and (memq 'general-category attributes)
492 (setq value (get-char-attribute char 'general-category)))
494 "(general-category\t%s) ; %s%s"
495 (mapconcat (lambda (cell)
498 (cond ((rassoc value unidata-normative-category-alist)
499 "Normative Category")
500 ((rassoc value unidata-informative-category-alist)
501 "Informative Category")
505 (setq attributes (delq 'general-category attributes))
507 (when (and (memq 'bidi-category attributes)
508 (setq value (get-char-attribute char 'bidi-category)))
509 (insert (format "(bidi-category\t. %S)%s"
512 (setq attributes (delq 'bidi-category attributes))
514 (unless (or (not (memq 'mirrored attributes))
515 (eq (setq value (get-char-attribute char 'mirrored 'empty))
517 (insert (format "(mirrored\t\t. %S)%s"
520 (setq attributes (delq 'mirrored attributes))
523 ((and (memq 'decimal-digit-value attributes)
524 (setq value (get-char-attribute char 'decimal-digit-value)))
525 (insert (format "(decimal-digit-value . %S)%s"
528 (setq attributes (delq 'decimal-digit-value attributes))
529 (when (and (memq 'digit-value attributes)
530 (setq value (get-char-attribute char 'digit-value)))
531 (insert (format "(digit-value\t . %S)%s"
534 (setq attributes (delq 'digit-value attributes))
536 (when (and (memq 'numeric-value attributes)
537 (setq value (get-char-attribute char 'numeric-value)))
538 (insert (format "(numeric-value\t . %S)%s"
541 (setq attributes (delq 'numeric-value attributes))
545 (when (and (memq 'digit-value attributes)
546 (setq value (get-char-attribute char 'digit-value)))
547 (insert (format "(digit-value\t. %S)%s"
550 (setq attributes (delq 'digit-value attributes))
552 (when (and (memq 'numeric-value attributes)
553 (setq value (get-char-attribute char 'numeric-value)))
554 (insert (format "(numeric-value\t. %S)%s"
557 (setq attributes (delq 'numeric-value attributes))
559 (when (and (memq 'iso-10646-comment attributes)
560 (setq value (get-char-attribute char 'iso-10646-comment)))
561 (insert (format "(iso-10646-comment\t. %S)%s"
564 (setq attributes (delq 'iso-10646-comment attributes))
566 (when (and (memq 'morohashi-daikanwa attributes)
567 (setq value (get-char-attribute char 'morohashi-daikanwa)))
568 (insert (format "(morohashi-daikanwa\t%s)%s"
569 (mapconcat (function prin1-to-string) value " ")
571 (setq attributes (delq 'morohashi-daikanwa attributes))
575 (when (and (memq 'ideographic-radical attributes)
576 (setq value (get-char-attribute char 'ideographic-radical)))
578 (insert (format "(ideographic-radical . %S)\t; %c%s"
580 (aref ideographic-radicals radical)
582 (setq attributes (delq 'ideographic-radical attributes))
584 (when (and (memq 'ideographic-strokes attributes)
585 (setq value (get-char-attribute char 'ideographic-strokes)))
587 (insert (format "(ideographic-strokes . %S)%s"
590 (setq attributes (delq 'ideographic-strokes attributes))
592 (when (and (memq 'kangxi-radical attributes)
593 (setq value (get-char-attribute char 'kangxi-radical)))
594 (unless (eq value radical)
595 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
597 (aref ideographic-radicals value)
600 (setq radical value)))
601 (setq attributes (delq 'kangxi-radical attributes))
603 (when (and (memq 'kangxi-strokes attributes)
604 (setq value (get-char-attribute char 'kangxi-strokes)))
605 (unless (eq value strokes)
606 (insert (format "(kangxi-strokes\t . %S)%s"
610 (setq strokes value)))
611 (setq attributes (delq 'kangxi-strokes attributes))
613 (when (and (memq 'japanese-radical attributes)
614 (setq value (get-char-attribute char 'japanese-radical)))
615 (unless (eq value radical)
616 (insert (format "(japanese-radical\t . %S)\t; %c%s"
618 (aref ideographic-radicals value)
621 (setq radical value)))
622 (setq attributes (delq 'japanese-radical attributes))
624 (when (and (memq 'japanese-strokes attributes)
625 (setq value (get-char-attribute char 'japanese-strokes)))
626 (unless (eq value strokes)
627 (insert (format "(japanese-strokes\t . %S)%s"
631 (setq strokes value)))
632 (setq attributes (delq 'japanese-strokes attributes))
634 (when (and (memq 'cns-radical attributes)
635 (setq value (get-char-attribute char 'cns-radical)))
636 (insert (format "(cns-radical\t . %S)\t; %c%s"
638 (aref ideographic-radicals value)
640 (setq attributes (delq 'cns-radical attributes))
642 (when (and (memq 'cns-strokes attributes)
643 (setq value (get-char-attribute char 'cns-strokes)))
644 (unless (eq value strokes)
645 (insert (format "(cns-strokes\t . %S)%s"
649 (setq strokes value)))
650 (setq attributes (delq 'cns-strokes attributes))
652 (when (and (memq 'shinjigen-1-radical attributes)
653 (setq value (get-char-attribute char 'shinjigen-1-radical)))
654 (unless (eq value radical)
655 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
657 (aref ideographic-radicals value)
660 (setq radical value)))
661 (setq attributes (delq 'shinjigen-1-radical attributes))
663 (when (and (memq 'ideographic- attributes)
664 (setq value (get-char-attribute char 'ideographic-)))
665 (insert "(ideographic- ")
666 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
669 (setq cell (car value))
671 (setq cell (decode-char 'ucs cell)))
672 (cond ((characterp cell)
676 (insert (format "%S" cell))
677 (char-db-insert-char-spec cell readable))
678 (setq separator lbs))
682 (if (consp (car cell))
683 (char-db-insert-char-spec cell readable)
684 (char-db-insert-char-reference cell readable))
685 (setq separator lbs))
689 (insert (prin1-to-string cell))
690 (setq separator " ")))
691 (setq value (cdr value)))
693 (insert line-breaking)
694 (setq attributes (delq 'ideographic- attributes)))
695 (when (and (memq 'total-strokes attributes)
696 (setq value (get-char-attribute char 'total-strokes)))
697 (insert (format "(total-strokes . %S)%s"
700 (setq attributes (delq 'total-strokes attributes))
702 (when (and (memq '->ideograph attributes)
703 (setq value (get-char-attribute char '->ideograph)))
704 (insert (format "(->ideograph\t%s)%s"
705 (mapconcat (lambda (code)
706 (cond ((symbolp code)
709 (format "#x%04X" code))
712 line-breaking code))))
715 (setq attributes (delq '->ideograph attributes))
717 (when (and (memq '->decomposition attributes)
718 (setq value (get-char-attribute char '->decomposition)))
719 (insert (format "(->decomposition\t%s)%s"
720 (mapconcat (lambda (code)
721 (cond ((symbolp code)
730 (format "#x%04X" code))
732 (format "%s%S" line-breaking code))))
735 (setq attributes (delq '->decomposition attributes))
737 (if (equal (get-char-attribute char '->titlecase)
738 (get-char-attribute char '->uppercase))
739 (setq attributes (delq '->titlecase attributes)))
740 (when (and (memq '->mojikyo attributes)
741 (setq value (get-char-attribute char '->mojikyo)))
742 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
743 value (decode-char 'mojikyo value)
745 (setq attributes (delq '->mojikyo attributes))
747 (when (and (memq 'hanyu-dazidian-vol attributes)
748 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
749 (insert (format "(hanyu-dazidian-vol . %d)%s"
750 value line-breaking))
751 (setq attributes (delq 'hanyu-dazidian-vol attributes))
753 (when (and (memq 'hanyu-dazidian-page attributes)
754 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
755 (insert (format "(hanyu-dazidian-page . %d)%s"
756 value line-breaking))
757 (setq attributes (delq 'hanyu-dazidian-page attributes))
759 (when (and (memq 'hanyu-dazidian-char attributes)
760 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
761 (insert (format "(hanyu-dazidian-char . %d)%s"
762 value line-breaking))
763 (setq attributes (delq 'hanyu-dazidian-char attributes))
766 (when (memq '->ucs-variants attributes)
767 (setq attributes (delq '->ucs-variants attributes))
769 (when (memq 'composition attributes)
770 (setq attributes (delq 'composition attributes))
772 (setq rest ccs-attributes)
775 (setq value (get-char-attribute char (car rest)))
777 (if (>= (length (symbol-name (car rest))) 19)
779 (setq has-long-ccs-name t)
783 (setq rest (cdr rest)))
785 (setq name (car attributes))
786 (if (setq value (get-char-attribute char name))
787 (cond ((eq name 'jisx0208-1978/4X)
788 (insert (format "(%-18s . #x%04X)%s"
791 ((or (eq name 'ideographic-structure)
792 (eq name 'ideographic-)
793 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
794 (insert (format "(%-18s%s " name line-breaking))
795 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
798 (setq cell (car value))
800 (setq cell (decode-char 'ucs cell)))
801 (cond ((characterp cell)
805 (insert (format "%S" cell))
806 (char-db-insert-char-spec cell readable))
807 (setq separator lbs))
811 (if (consp (car cell))
812 (char-db-insert-char-spec cell readable)
813 (char-db-insert-char-reference cell readable))
814 (setq separator lbs))
818 (insert (prin1-to-string cell))
819 (setq separator " ")))
820 (setq value (cdr value)))
822 (insert line-breaking))
823 ((memq name '(ideograph=
824 original-ideograph-of
828 simplified-ideograph-of
830 ideographic-different-form-of))
831 (insert (format "(%-18s%s " name line-breaking))
832 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
835 (setq cell (car value))
836 (if (and (consp cell)
841 (char-db-insert-alist cell readable)
842 (setq separator lbs))
845 (insert (prin1-to-string cell))
846 (setq separator " "))
847 (setq value (cdr value)))
849 (insert line-breaking))
850 ;; ((string-match "^->" (symbol-name name))
852 ;; (format "(%-18s %s)%s"
854 ;; (mapconcat (lambda (code)
855 ;; (cond ((symbolp code)
856 ;; (symbol-name code))
858 ;; (format "#x%04X" code))
861 ;; line-breaking code))))
865 (insert (format "(%-18s " name))
866 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
869 (setq cell (car value))
870 (if (and (consp cell)
872 (setq ret (condition-case nil
880 (setq key (car (car rest)))
881 (if (find-charset key)
882 (setq cal (cons key cal))
883 (setq al (cons key al)))
884 (setq rest (cdr rest)))
887 (insert-char-attributes ret
890 (setq separator lbs))
893 (insert (prin1-to-string cell))
894 (setq separator " "))
895 (setq value (cdr value)))
897 (insert line-breaking))
899 (insert (format "(%-18s . %S)%s"
903 (setq attributes (cdr attributes)))
904 (while ccs-attributes
905 (setq name (car ccs-attributes))
906 (if (and (eq name (charset-name name))
907 (setq value (get-char-attribute char name)))
910 (cond ((memq name '(ideograph-daikanwa-2
914 (if has-long-ccs-name
915 "(%-26s . %05d)\t; %c%s"
916 "(%-18s . %05d)\t; %c%s"))
918 (if has-long-ccs-name
919 "(%-26s . %06d)\t; %c%s"
920 "(%-18s . %06d)\t; %c%s"))
922 (if has-long-ccs-name
923 "(%-26s . #x%04X)\t; %c%s"
924 "(%-18s . #x%04X)\t; %c%s"))
926 (if has-long-ccs-name
927 "(%-26s . #x%02X)\t; %c%s"
928 "(%-18s . #x%02X)\t; %c%s")))
930 (if (= (charset-iso-graphic-plane name) 1)
932 (cond ((= (charset-dimension name) 1)
934 ((= (charset-dimension name) 2)
936 ((= (charset-dimension name) 3)
940 (char-db-decode-isolated-char name value)
942 (setq ccs-attributes (cdr ccs-attributes)))
945 (defun insert-char-data (char &optional readable
946 attributes ccs-attributes)
948 (narrow-to-region (point)(point))
949 (insert "(define-char
951 (insert-char-attributes char readable
952 attributes ccs-attributes)
954 (goto-char (point-min))
955 (while (re-search-forward "[ \t]+$" nil t)
957 (goto-char (point-max))
958 (tabify (point-min)(point-max))
961 (defun insert-char-data-with-variant (char &optional printable
963 script excluded-script)
964 (insert-char-data char printable)
965 (let ((variants (or (char-variants char)
966 (let ((ucs (get-char-attribute char '->ucs)))
968 (delete char (char-variants (int-char ucs)))))))
970 (setq variants (sort variants #'<))
972 (setq variant (car variants))
973 (if (and (or (null script)
974 (null (setq vs (get-char-attribute variant 'script)))
976 (or (null excluded-script)
977 (null (setq vs (get-char-attribute variant 'script)))
978 (not (memq excluded-script vs))))
979 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
980 (insert-char-data variant printable)))
981 (setq variants (cdr variants))
984 (defun insert-char-range-data (min max &optional script excluded-script)
988 (setq char (decode-char 'ucs code))
989 (if (get-char-attribute char 'ucs)
990 (insert-char-data-with-variant char nil 'no-ucs-variant
991 script excluded-script))
992 (setq code (1+ code))
995 (defun write-char-range-data-to-file (min max file
996 &optional script excluded-script)
997 (let ((coding-system-for-write 'utf-8))
999 (insert-char-range-data min max script excluded-script)
1000 (write-region (point-min)(point-max) file))))
1002 (defvar what-character-original-window-configuration)
1005 (defun what-char-definition (char)
1006 (interactive (list (char-after)))
1007 (let ((buf (get-buffer-create "*Character Description*"))
1008 (the-buf (current-buffer))
1009 (win-conf (current-window-configuration)))
1011 (make-local-variable 'what-character-original-window-configuration)
1012 (setq what-character-original-window-configuration win-conf)
1013 (setq buffer-read-only nil)
1017 (insert-char-data-with-variant char 'printable)
1018 (unless (char-attribute-alist char)
1019 (insert (format ";; = %c\n"
1020 (let* ((rest (split-char char))
1024 (setq code (logior (lsh code 8)
1026 (decode-char ccs code)))))
1027 ;; (char-db-update-comment)
1028 (set-buffer-modified-p nil)
1029 (view-mode the-buf (lambda (buf)
1030 (set-window-configuration
1031 what-character-original-window-configuration)
1033 (goto-char (point-min)))
1035 (set-window-configuration
1036 what-character-original-window-configuration)
1037 (signal (car err) (cdr err)))))))
1039 (provide 'char-db-util)
1041 ;;; char-db-util.el ends here