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)
77 (defun char-ref= (cr1 cr2)
78 (cond ((char-ref-p cr1)
80 (char-spec= (plist-get cr1 :char)
81 (plist-get cr2 :char))
82 (char-spec= (plist-get cr1 :char) cr2)))
90 (defun char-spec= (cs1 cs2)
94 (eq cs1 (find-char cs2)))
96 (eq (find-char cs1) cs2)
97 (eq (find-char cs1) (find-char cs2)))))
99 (defun char-attribute-name< (ka kb)
105 ((= (charset-dimension ka)
106 (charset-dimension kb))
107 (cond ((= (charset-chars ka)(charset-chars kb))
108 (if (charset-iso-final-char ka)
110 ((>= (charset-iso-final-char ka) ?@)
111 (if (and (charset-iso-final-char kb)
112 (>= (charset-iso-final-char kb) ?@))
113 (< (charset-iso-final-char ka)
114 (charset-iso-final-char kb))
117 (if (charset-iso-final-char kb)
118 (if (>= (charset-iso-final-char kb) ?@)
120 (< (charset-iso-final-char ka)
121 (charset-iso-final-char kb)))
123 (if (charset-iso-final-char kb)
125 (< (charset-id ka)(charset-id kb)))))
126 ((<= (charset-chars ka)(charset-chars kb)))))
128 (< (charset-dimension ka)
129 (charset-dimension kb))
139 (string< (symbol-name ka)
145 (defvar char-db-coded-charset-priority-list
146 (let ((rest default-coded-charset-priority-list)
149 (when (symbolp (car rest))
150 (cond ((memq (car rest)
159 ((string-match "^chinese-big5" (symbol-name (car rest))))
160 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
161 (unless (memq 'ideograph-gt dest)
162 (setq dest (cons 'ideograph-gt dest))))
164 (setq dest (cons (car rest) dest)))))
165 (setq rest (cdr rest)))
166 (append (sort dest #'char-attribute-name<)
167 '(chinese-big5-cdp chinese-big5-eten chinese-big5))))
169 (defun char-db-insert-char-spec (char &optional readable column)
171 (setq column (current-column)))
172 (let (char-spec ret al cal key temp-char)
173 (cond ((characterp char)
174 (cond ((and (setq ret (get-char-attribute char 'ucs))
175 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
176 (setq char-spec (list (cons 'ucs ret)))
177 (if (setq ret (get-char-attribute char 'name))
178 (setq char-spec (cons (cons 'name ret) char-spec)))
181 (let ((default-coded-charset-priority-list
182 char-db-coded-charset-priority-list))
184 (setq char-spec (list ret))
185 (dolist (ccs (delq (car ret) (charset-list)))
186 (if (or (and (charset-iso-final-char ccs)
187 (setq ret (get-char-attribute char ccs)))
188 (eq ccs 'ideograph-daikanwa))
189 (setq char-spec (cons (cons ccs ret) char-spec))))
191 (setq char-spec (split-char char)))
192 (if (setq ret (get-char-attribute char 'name))
193 (setq char-spec (cons (cons 'name ret) char-spec)))
196 (setq char-spec char)
200 (setq char (find-char char-spec))
202 ;; define temporary character
203 ;; Current implementation is dirty.
204 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
206 (remove-char-attribute temp-char 'ideograph-daikanwa)
207 (setq char temp-char))
211 (setq key (car (car char-spec)))
212 (unless (memq key char-db-ignored-attributes)
213 (if (find-charset key)
214 (setq cal (cons key cal))
215 (setq al (cons key al))))
216 (setq char-spec (cdr char-spec)))
218 (memq 'ideographic-structure al))
219 (push 'ideographic-structure al))
220 (insert-char-attributes char
224 ;; undefine temporary character
225 ;; Current implementation is dirty.
226 (setq char-spec (char-attribute-alist temp-char))
228 (remove-char-attribute temp-char (car (car char-spec)))
229 (setq char-spec (cdr char-spec))))))
231 (defun char-db-insert-alist (alist &optional readable column)
233 (setq column (current-column)))
235 (concat "\n" (make-string (1+ column) ?\ )))
238 lbs cell rest separator)
241 (setq name (car (car alist))
242 value (cdr (car alist)))
243 (cond ((eq name 'char)
245 (if (setq ret (condition-case nil
252 (setq key (car (car value)))
253 (if (find-charset key)
254 (setq cal (cons key cal))
255 (setq al (cons key al)))
256 (setq value (cdr value)))
257 (insert-char-attributes ret
260 (insert (prin1-to-string value)))
262 (insert line-breaking))
264 (insert (format "(%-18s " name))
265 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
267 (setq cell (car value))
268 (if (and (consp cell)
270 (setq ret (condition-case nil
279 (setq key (car (car rest)))
280 (if (find-charset key)
281 (setq cal (cons key cal))
282 (setq al (cons key al)))
283 (setq rest (cdr rest)))
286 (insert-char-attributes ret
289 (setq separator lbs))
292 (insert (prin1-to-string cell))
293 (setq separator " "))
294 (setq value (cdr value)))
296 (insert line-breaking))
298 (insert (format "(%-18s . %S)%s"
301 (setq alist (cdr alist))))
304 (defun char-db-insert-char-reference (plist &optional readable column)
306 (setq column (current-column)))
308 (concat "\n" (make-string (1+ column) ?\ )))
313 (setq name (pop plist))
314 (setq value (pop plist))
315 (cond ((eq name :char)
318 (cond ((numberp value)
319 (setq value (decode-char 'ucs value)))
321 ;; (setq value (or (find-char value)
324 (char-db-insert-char-spec value readable)
325 (insert line-breaking)
328 (insert (format "%s%s\t%d ; %c%s"
331 (aref ideographic-radicals value)
335 (insert (format "%s%s\t%S" separator name value))
336 (setq separator line-breaking)))
340 (defun char-db-decode-isolated-char (ccs code-point)
343 (cond ((eq ccs 'arabic-iso8859-6)
344 (decode-char ccs code-point))
345 ((and (memq ccs '(ideograph-gt-pj-1
356 (setq ret (decode-char ccs code-point))
357 (setq ret (get-char-attribute ret 'ideograph-gt)))
358 (decode-builtin-char 'ideograph-gt ret))
360 (decode-builtin-char ccs code-point))))
361 (cond ((and (<= 0 (char-int ret))
362 (<= (char-int ret) #x1F))
363 (decode-char 'ucs (+ #x2400 (char-int ret))))
364 ((= (char-int ret) #x7F)
368 (defvar char-db-convert-obsolete-format t)
370 (defun insert-char-attributes (char &optional readable
371 attributes ccs-attributes
376 (if (consp attributes)
378 (dolist (name attributes)
379 (unless (memq name char-db-ignored-attributes)
382 (dolist (name (char-attribute-list))
383 (unless (memq name char-db-ignored-attributes)
384 (if (find-charset name)
388 #'char-attribute-name<))
390 (sort (if ccs-attributes
393 (dolist (name ccs-attributes)
394 (unless (memq name char-db-ignored-attributes)
399 (dolist (name (charset-list))
400 (unless (memq name char-db-ignored-attributes)
403 #'char-attribute-name<)))
405 (setq column (current-column)))
406 (let (name value has-long-ccs-name rest
409 (concat "\n" (make-string (1+ column) ?\ )))
410 lbs cell separator ret
413 (when (and (memq 'name attributes)
414 (setq value (get-char-attribute char 'name)))
416 (if (> (+ (current-column) (length value)) 48)
419 value line-breaking))
420 (setq attributes (delq 'name attributes))
422 (when (and (memq 'script attributes)
423 (setq value (get-char-attribute char 'script)))
424 (insert (format "(script\t\t%s)%s"
425 (mapconcat (function prin1-to-string)
428 (setq attributes (delq 'script attributes))
430 (when (and (memq '=>ucs attributes)
431 (setq value (get-char-attribute char '=>ucs)))
432 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
433 value (decode-char 'ucs value)
435 (setq attributes (delq '=>ucs attributes))
437 (when (and (memq '=>ucs* attributes)
438 (setq value (get-char-attribute char '=>ucs*)))
439 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
440 value (decode-char 'ucs value)
442 (setq attributes (delq '=>ucs* attributes))
444 (when (and (memq '=>ucs-jis attributes)
445 (setq value (get-char-attribute char '=>ucs-jis)))
446 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
447 value (decode-char 'ucs value)
449 (setq attributes (delq '=>ucs-jis attributes))
451 (when (and (memq '->ucs attributes)
452 (setq value (get-char-attribute char '->ucs)))
453 (insert (format (if char-db-convert-obsolete-format
454 "(=>ucs\t\t. #x%04X)\t; %c%s"
455 "(->ucs\t\t. #x%04X)\t; %c%s")
456 value (decode-char 'ucs value)
458 (setq attributes (delq '->ucs attributes))
460 (when (and (memq 'general-category attributes)
461 (setq value (get-char-attribute char 'general-category)))
463 "(general-category\t%s) ; %s%s"
464 (mapconcat (lambda (cell)
467 (cond ((rassoc value unidata-normative-category-alist)
468 "Normative Category")
469 ((rassoc value unidata-informative-category-alist)
470 "Informative Category")
474 (setq attributes (delq 'general-category attributes))
476 (when (and (memq 'bidi-category attributes)
477 (setq value (get-char-attribute char 'bidi-category)))
478 (insert (format "(bidi-category\t. %S)%s"
481 (setq attributes (delq 'bidi-category attributes))
483 (unless (or (not (memq 'mirrored attributes))
484 (eq (setq value (get-char-attribute char 'mirrored 'empty))
486 (insert (format "(mirrored\t\t. %S)%s"
489 (setq attributes (delq 'mirrored attributes))
492 ((and (memq 'decimal-digit-value attributes)
493 (setq value (get-char-attribute char 'decimal-digit-value)))
494 (insert (format "(decimal-digit-value . %S)%s"
497 (setq attributes (delq 'decimal-digit-value attributes))
498 (when (and (memq 'digit-value attributes)
499 (setq value (get-char-attribute char 'digit-value)))
500 (insert (format "(digit-value\t . %S)%s"
503 (setq attributes (delq 'digit-value attributes))
505 (when (and (memq 'numeric-value attributes)
506 (setq value (get-char-attribute char 'numeric-value)))
507 (insert (format "(numeric-value\t . %S)%s"
510 (setq attributes (delq 'numeric-value attributes))
514 (when (and (memq 'digit-value attributes)
515 (setq value (get-char-attribute char 'digit-value)))
516 (insert (format "(digit-value\t. %S)%s"
519 (setq attributes (delq 'digit-value attributes))
521 (when (and (memq 'numeric-value attributes)
522 (setq value (get-char-attribute char 'numeric-value)))
523 (insert (format "(numeric-value\t. %S)%s"
526 (setq attributes (delq 'numeric-value attributes))
528 (when (and (memq 'iso-10646-comment attributes)
529 (setq value (get-char-attribute char 'iso-10646-comment)))
530 (insert (format "(iso-10646-comment\t. %S)%s"
533 (setq attributes (delq 'iso-10646-comment attributes))
535 (when (and (memq 'morohashi-daikanwa attributes)
536 (setq value (get-char-attribute char 'morohashi-daikanwa)))
537 (insert (format "(morohashi-daikanwa\t%s)%s"
538 (mapconcat (function prin1-to-string) value " ")
540 (setq attributes (delq 'morohashi-daikanwa attributes))
544 (when (and (memq 'ideographic-radical attributes)
545 (setq value (get-char-attribute char 'ideographic-radical)))
547 (insert (format "(ideographic-radical . %S)\t; %c%s"
549 (aref ideographic-radicals radical)
551 (setq attributes (delq 'ideographic-radical attributes))
553 (when (and (memq 'ideographic-strokes attributes)
554 (setq value (get-char-attribute char 'ideographic-strokes)))
556 (insert (format "(ideographic-strokes . %S)%s"
559 (setq attributes (delq 'ideographic-strokes attributes))
561 (when (and (memq 'kangxi-radical attributes)
562 (setq value (get-char-attribute char 'kangxi-radical)))
563 (unless (eq value radical)
564 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
566 (aref ideographic-radicals value)
569 (setq radical value)))
570 (setq attributes (delq 'kangxi-radical attributes))
572 (when (and (memq 'kangxi-strokes attributes)
573 (setq value (get-char-attribute char 'kangxi-strokes)))
574 (unless (eq value strokes)
575 (insert (format "(kangxi-strokes\t . %S)%s"
579 (setq strokes value)))
580 (setq attributes (delq 'kangxi-strokes attributes))
582 (when (and (memq 'japanese-radical attributes)
583 (setq value (get-char-attribute char 'japanese-radical)))
584 (unless (eq value radical)
585 (insert (format "(japanese-radical\t . %S)\t; %c%s"
587 (aref ideographic-radicals value)
590 (setq radical value)))
591 (setq attributes (delq 'japanese-radical attributes))
593 (when (and (memq 'japanese-strokes attributes)
594 (setq value (get-char-attribute char 'japanese-strokes)))
595 (unless (eq value strokes)
596 (insert (format "(japanese-strokes\t . %S)%s"
600 (setq strokes value)))
601 (setq attributes (delq 'japanese-strokes attributes))
603 (when (and (memq 'cns-radical attributes)
604 (setq value (get-char-attribute char 'cns-radical)))
605 (insert (format "(cns-radical\t . %S)\t; %c%s"
607 (aref ideographic-radicals value)
609 (setq attributes (delq 'cns-radical attributes))
611 (when (and (memq 'cns-strokes attributes)
612 (setq value (get-char-attribute char 'cns-strokes)))
613 (unless (eq value strokes)
614 (insert (format "(cns-strokes\t . %S)%s"
618 (setq strokes value)))
619 (setq attributes (delq 'cns-strokes attributes))
621 (when (and (memq 'shinjigen-1-radical attributes)
622 (setq value (get-char-attribute char 'shinjigen-1-radical)))
623 (unless (eq value radical)
624 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
626 (aref ideographic-radicals value)
629 (setq radical value)))
630 (setq attributes (delq 'shinjigen-1-radical attributes))
632 (when (and (memq 'ideographic- attributes)
633 (setq value (get-char-attribute char 'ideographic-)))
634 (insert "(ideographic- ")
635 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
638 (setq cell (car value))
640 (setq cell (decode-char 'ucs cell)))
641 (cond ((characterp cell)
645 (insert (format "%S" cell))
646 (char-db-insert-char-spec cell readable))
647 (setq separator lbs))
651 (if (consp (car cell))
652 (char-db-insert-char-spec cell readable)
653 (char-db-insert-char-reference cell readable))
654 (setq separator lbs))
658 (insert (prin1-to-string cell))
659 (setq separator " ")))
660 (setq value (cdr value)))
662 (insert line-breaking)
663 (setq attributes (delq 'ideographic- attributes)))
664 (when (and (memq 'total-strokes attributes)
665 (setq value (get-char-attribute char 'total-strokes)))
666 (insert (format "(total-strokes . %S)%s"
669 (setq attributes (delq 'total-strokes attributes))
671 (when (and (memq '->ideograph attributes)
672 (setq value (get-char-attribute char '->ideograph)))
673 (insert (format "(->ideograph\t%s)%s"
674 (mapconcat (lambda (code)
675 (cond ((symbolp code)
678 (format "#x%04X" code))
681 line-breaking code))))
684 (setq attributes (delq '->ideograph attributes))
686 (when (and (memq '->decomposition attributes)
687 (setq value (get-char-attribute char '->decomposition)))
688 (insert (format "(->decomposition\t%s)%s"
689 (mapconcat (lambda (code)
690 (cond ((symbolp code)
699 (format "#x%04X" code))
701 (format "%s%S" line-breaking code))))
704 (setq attributes (delq '->decomposition attributes))
706 (if (equal (get-char-attribute char '->titlecase)
707 (get-char-attribute char '->uppercase))
708 (setq attributes (delq '->titlecase attributes)))
709 (when (and (memq '->mojikyo attributes)
710 (setq value (get-char-attribute char '->mojikyo)))
711 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
712 value (decode-char 'mojikyo value)
714 (setq attributes (delq '->mojikyo attributes))
716 (when (and (memq 'hanyu-dazidian-vol attributes)
717 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
718 (insert (format "(hanyu-dazidian-vol . %d)%s"
719 value line-breaking))
720 (setq attributes (delq 'hanyu-dazidian-vol attributes))
722 (when (and (memq 'hanyu-dazidian-page attributes)
723 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
724 (insert (format "(hanyu-dazidian-page . %d)%s"
725 value line-breaking))
726 (setq attributes (delq 'hanyu-dazidian-page attributes))
728 (when (and (memq 'hanyu-dazidian-char attributes)
729 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
730 (insert (format "(hanyu-dazidian-char . %d)%s"
731 value line-breaking))
732 (setq attributes (delq 'hanyu-dazidian-char attributes))
735 (when (memq '->ucs-variants attributes)
736 (setq attributes (delq '->ucs-variants attributes))
738 (when (memq 'composition attributes)
739 (setq attributes (delq 'composition attributes))
741 (setq rest ccs-attributes)
744 (setq value (get-char-attribute char (car rest)))
746 (if (>= (length (symbol-name (car rest))) 19)
748 (setq has-long-ccs-name t)
752 (setq rest (cdr rest)))
754 (setq name (car attributes))
755 (if (setq value (get-char-attribute char name))
756 (cond ((eq name 'jisx0208-1978/4X)
757 (insert (format "(%-18s . #x%04X)%s"
760 ((or (eq name 'ideographic-structure)
761 (eq name 'ideographic-)
762 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
763 ;; (memq name '(->lowercase
764 ;; ->uppercase ->titlecase
765 ;; ->fullwidth <-fullwidth
767 ;; ->vulgar-ideograph <-vulgar-ideograph
768 ;; ->ancient-ideograph <-ancient-ideograph
769 ;; ->original-ideograph <-original-ideograph
770 ;; ->simplified-ideograph <-simplified-ideograph
771 ;; ->wrong-ideograph <-wrong-ideograph
773 ;; ->ideographic-variants
775 ;; ->radical <-radical
776 ;; ->bopomofo <-bopomofo
777 ;; ->ideographic <-ideographic
778 ;; ideographic-structure))
779 (insert (format "(%-18s%s " name line-breaking))
780 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
783 (setq cell (car value))
785 (setq cell (decode-char 'ucs cell)))
786 (cond ((characterp cell)
790 (insert (format "%S" cell))
791 (char-db-insert-char-spec cell readable))
792 (setq separator lbs))
796 (if (consp (car cell))
797 (char-db-insert-char-spec cell readable)
798 (char-db-insert-char-reference cell readable))
799 (setq separator lbs))
803 (insert (prin1-to-string cell))
804 (setq separator " ")))
805 (setq value (cdr value)))
807 (insert line-breaking))
808 ((memq name '(ideograph=
809 original-ideograph-of
813 simplified-ideograph-of
815 ideographic-different-form-of))
816 (insert (format "(%-18s%s " name line-breaking))
817 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
820 (setq cell (car value))
821 (if (and (consp cell)
826 (char-db-insert-alist cell readable)
827 (setq separator lbs))
830 (insert (prin1-to-string cell))
831 (setq separator " "))
832 (setq value (cdr value)))
834 (insert line-breaking))
835 ;; ((string-match "^->" (symbol-name name))
837 ;; (format "(%-18s %s)%s"
839 ;; (mapconcat (lambda (code)
840 ;; (cond ((symbolp code)
841 ;; (symbol-name code))
843 ;; (format "#x%04X" code))
846 ;; line-breaking code))))
850 (insert (format "(%-18s " name))
851 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
854 (setq cell (car value))
855 (if (and (consp cell)
857 (setq ret (condition-case nil
865 (setq key (car (car rest)))
866 (if (find-charset key)
867 (setq cal (cons key cal))
868 (setq al (cons key al)))
869 (setq rest (cdr rest)))
872 (insert-char-attributes ret
875 (setq separator lbs))
878 (insert (prin1-to-string cell))
879 (setq separator " "))
880 (setq value (cdr value)))
882 (insert line-breaking))
884 (insert (format "(%-18s . %S)%s"
888 (setq attributes (cdr attributes)))
889 (while ccs-attributes
890 (setq name (car ccs-attributes))
891 (if (and (eq name (charset-name name))
892 (setq value (get-char-attribute char name)))
895 (cond ((memq name '(ideograph-daikanwa-2
899 (if has-long-ccs-name
900 "(%-26s . %05d)\t; %c%s"
901 "(%-18s . %05d)\t; %c%s"))
903 (if has-long-ccs-name
904 "(%-26s . %06d)\t; %c%s"
905 "(%-18s . %06d)\t; %c%s"))
907 (if has-long-ccs-name
908 "(%-26s . #x%04X)\t; %c%s"
909 "(%-18s . #x%04X)\t; %c%s"))
911 (if has-long-ccs-name
912 "(%-26s . #x%02X)\t; %c%s"
913 "(%-18s . #x%02X)\t; %c%s")))
915 (if (= (charset-iso-graphic-plane name) 1)
917 (cond ((= (charset-dimension name) 1)
919 ((= (charset-dimension name) 2)
921 ((= (charset-dimension name) 3)
925 (char-db-decode-isolated-char name value)
927 (setq ccs-attributes (cdr ccs-attributes)))
930 (defun insert-char-data (char &optional readable
931 attributes ccs-attributes)
933 (narrow-to-region (point)(point))
934 (insert "(define-char
936 (insert-char-attributes char readable
937 attributes ccs-attributes)
939 (goto-char (point-min))
940 (while (re-search-forward "[ \t]+$" nil t)
942 (goto-char (point-max))
943 (tabify (point-min)(point-max))
947 (defun char-db-update-comment ()
950 (goto-char (point-min))
951 (let (cdef table char)
952 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
953 (goto-char (match-beginning 1))
954 (setq cdef (read (current-buffer)))
955 (when (find-charset (car cdef))
956 (goto-char (match-end 0))
959 (not (eq (car cdef) 'ideograph-daikanwa))
960 (or (memq (car cdef) '(ascii latin-viscii-upper
964 japanese-jisx0213-2))
965 (= (char-int (charset-iso-final-char (car cdef)))
967 (apply (function make-char) cdef)
968 (if (setq table (charset-mapping-table (car cdef)))
969 (set-charset-mapping-table (car cdef) nil))
971 (apply (function make-char) cdef)
973 (set-charset-mapping-table (car cdef) table)))))
974 (when (not (or (< (char-int char) 32)
975 (and (<= 128 (char-int char))
976 (< (char-int char) 160))))
977 (delete-region (point) (point-at-eol))
978 (insert (format "\t; %c" char)))
981 (defun insert-char-data-with-variant (char &optional printable
983 script excluded-script)
984 (insert-char-data char printable)
985 (let ((variants (or (char-variants char)
986 (let ((ucs (get-char-attribute char '->ucs)))
988 (delete char (char-variants (int-char ucs)))))))
990 (setq variants (sort variants #'<))
992 (setq variant (car variants))
993 (if (and (or (null script)
994 (null (setq vs (get-char-attribute variant 'script)))
996 (or (null excluded-script)
997 (null (setq vs (get-char-attribute variant 'script)))
998 (not (memq excluded-script vs))))
999 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
1000 (insert-char-data variant printable)))
1001 (setq variants (cdr variants))
1004 (defun insert-char-range-data (min max &optional script excluded-script)
1007 (while (<= code max)
1008 (setq char (decode-char 'ucs code))
1009 (if (get-char-attribute char 'ucs)
1010 (insert-char-data-with-variant char nil 'no-ucs-variant
1011 script excluded-script))
1012 (setq code (1+ code))
1015 (defun write-char-range-data-to-file (min max file
1016 &optional script excluded-script)
1017 (let ((coding-system-for-write 'utf-8))
1019 (insert-char-range-data min max script excluded-script)
1020 (write-region (point-min)(point-max) file))))
1022 (defvar what-character-original-window-configuration)
1025 (defun what-char-definition (char)
1026 (interactive (list (char-after)))
1027 (let ((buf (get-buffer-create "*Character Description*"))
1028 (the-buf (current-buffer))
1029 (win-conf (current-window-configuration)))
1031 (make-local-variable 'what-character-original-window-configuration)
1032 (setq what-character-original-window-configuration win-conf)
1033 (setq buffer-read-only nil)
1037 (insert-char-data-with-variant char 'printable)
1038 (unless (char-attribute-alist char)
1039 (insert (format ";; = %c\n"
1040 (let* ((rest (split-char char))
1044 (setq code (logior (lsh code 8)
1046 (decode-char ccs code)))))
1047 ;; (char-db-update-comment)
1048 (set-buffer-modified-p nil)
1049 (view-mode the-buf (lambda (buf)
1050 (set-window-configuration
1051 what-character-original-window-configuration)
1053 (goto-char (point-min)))
1055 (set-window-configuration
1056 what-character-original-window-configuration)
1057 (signal (car err) (cdr err)))))))
1059 (provide 'char-db-util)
1061 ;;; char-db-util.el ends here