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 "^mojikyo-" (symbol-name (car rest))))
160 ((string-match "^chinese-big5" (symbol-name (car rest))))
161 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
162 (unless (memq 'ideograph-gt dest)
163 (setq dest (cons 'ideograph-gt dest))))
165 (setq dest (cons (car rest) dest)))))
166 (setq rest (cdr rest)))
167 (append (sort dest #'char-attribute-name<)
168 '(chinese-big5-cdp chinese-big5-eten chinese-big5))))
170 (defun char-db-insert-char-spec (char &optional readable column)
172 (setq column (current-column)))
173 (let (char-spec ret al cal key temp-char)
174 (cond ((characterp char)
175 (cond ((and (setq ret (get-char-attribute char 'ucs))
176 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
177 (setq char-spec (list (cons 'ucs ret)))
178 (if (setq ret (get-char-attribute char 'name))
179 (setq char-spec (cons (cons 'name ret) char-spec)))
182 (let ((default-coded-charset-priority-list
183 char-db-coded-charset-priority-list))
185 (setq char-spec (list ret))
186 (dolist (ccs (delq (car ret) (charset-list)))
187 (if (or (and (charset-iso-final-char ccs)
188 (setq ret (get-char-attribute char ccs)))
189 (eq ccs 'ideograph-daikanwa))
190 (setq char-spec (cons (cons ccs ret) char-spec))))
192 (setq char-spec (split-char char)))
193 (if (setq ret (get-char-attribute char 'name))
194 (setq char-spec (cons (cons 'name ret) char-spec)))
197 (setq char-spec char)
201 (setq char (find-char char-spec))
203 ;; define temporary character
204 ;; Current implementation is dirty.
205 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
207 (remove-char-attribute temp-char 'ideograph-daikanwa)
208 (setq char temp-char))
212 (setq key (car (car char-spec)))
213 (unless (memq key char-db-ignored-attributes)
214 (if (find-charset key)
215 (setq cal (cons key cal))
216 (setq al (cons key al))))
217 (setq char-spec (cdr char-spec)))
219 (memq 'ideographic-structure al))
220 (push 'ideographic-structure al))
221 (insert-char-attributes char
225 ;; undefine temporary character
226 ;; Current implementation is dirty.
227 (setq char-spec (char-attribute-alist temp-char))
229 (remove-char-attribute temp-char (car (car char-spec)))
230 (setq char-spec (cdr char-spec))))))
232 (defun char-db-insert-alist (alist &optional readable column)
234 (setq column (current-column)))
236 (concat "\n" (make-string (1+ column) ?\ )))
239 lbs cell rest separator)
242 (setq name (car (car alist))
243 value (cdr (car alist)))
244 (cond ((eq name 'char)
246 (if (setq ret (condition-case nil
253 (setq key (car (car value)))
254 (if (find-charset key)
255 (setq cal (cons key cal))
256 (setq al (cons key al)))
257 (setq value (cdr value)))
258 (insert-char-attributes ret
261 (insert (prin1-to-string value)))
263 (insert line-breaking))
265 (insert (format "(%-18s " name))
266 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
268 (setq cell (car value))
269 (if (and (consp cell)
271 (setq ret (condition-case nil
280 (setq key (car (car rest)))
281 (if (find-charset key)
282 (setq cal (cons key cal))
283 (setq al (cons key al)))
284 (setq rest (cdr rest)))
287 (insert-char-attributes ret
290 (setq separator lbs))
293 (insert (prin1-to-string cell))
294 (setq separator " "))
295 (setq value (cdr value)))
297 (insert line-breaking))
299 (insert (format "(%-18s . %S)%s"
302 (setq alist (cdr alist))))
305 (defun char-db-insert-char-reference (plist &optional readable column)
307 (setq column (current-column)))
309 (concat "\n" (make-string (1+ column) ?\ )))
314 (setq name (pop plist))
315 (setq value (pop plist))
316 (cond ((eq name :char)
319 (cond ((numberp value)
320 (setq value (decode-char 'ucs value)))
322 ;; (setq value (or (find-char value)
325 (char-db-insert-char-spec value readable)
326 (insert line-breaking)
329 (insert (format "%s%s\t%d ; %c%s"
332 (aref ideographic-radicals value)
336 (insert (format "%s%s\t%S" separator name value))
337 (setq separator line-breaking)))
341 (defun char-db-decode-isolated-char (ccs code-point)
344 (cond ((eq ccs 'arabic-iso8859-6)
345 (decode-char ccs code-point))
346 ((and (memq ccs '(ideograph-gt-pj-1
357 (setq ret (decode-char ccs code-point))
358 (setq ret (get-char-attribute ret 'ideograph-gt)))
359 (decode-builtin-char 'ideograph-gt ret))
361 (decode-builtin-char ccs code-point))))
362 (cond ((and (<= 0 (char-int ret))
363 (<= (char-int ret) #x1F))
364 (decode-char 'ucs (+ #x2400 (char-int ret))))
365 ((= (char-int ret) #x7F)
369 (defvar char-db-convert-obsolete-format t)
371 (defun insert-char-attributes (char &optional readable
372 attributes ccs-attributes
377 (if (consp attributes)
379 (dolist (name attributes)
380 (unless (memq name char-db-ignored-attributes)
383 (dolist (name (char-attribute-list))
384 (unless (memq name char-db-ignored-attributes)
385 (if (find-charset name)
389 #'char-attribute-name<))
391 (sort (if ccs-attributes
394 (dolist (name ccs-attributes)
395 (unless (memq name char-db-ignored-attributes)
400 (dolist (name (charset-list))
401 (unless (memq name char-db-ignored-attributes)
404 #'char-attribute-name<)))
406 (setq column (current-column)))
407 (let (name value has-long-ccs-name rest
410 (concat "\n" (make-string (1+ column) ?\ )))
411 lbs cell separator ret
414 (when (and (memq 'name attributes)
415 (setq value (get-char-attribute char 'name)))
417 (if (> (+ (current-column) (length value)) 48)
420 value line-breaking))
421 (setq attributes (delq 'name attributes))
423 (when (and (memq 'script attributes)
424 (setq value (get-char-attribute char 'script)))
425 (insert (format "(script\t\t%s)%s"
426 (mapconcat (function prin1-to-string)
429 (setq attributes (delq 'script attributes))
431 (when (and (memq '=>ucs attributes)
432 (setq value (get-char-attribute char '=>ucs)))
433 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
434 value (decode-char 'ucs value)
436 (setq attributes (delq '=>ucs attributes))
438 (when (and (memq '=>ucs* attributes)
439 (setq value (get-char-attribute char '=>ucs*)))
440 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
441 value (decode-char 'ucs value)
443 (setq attributes (delq '=>ucs* attributes))
445 (when (and (memq '=>ucs-jis attributes)
446 (setq value (get-char-attribute char '=>ucs-jis)))
447 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
448 value (decode-char 'ucs value)
450 (setq attributes (delq '=>ucs-jis attributes))
452 (when (and (memq '->ucs attributes)
453 (setq value (get-char-attribute char '->ucs)))
454 (insert (format (if char-db-convert-obsolete-format
455 "(=>ucs\t\t. #x%04X)\t; %c%s"
456 "(->ucs\t\t. #x%04X)\t; %c%s")
457 value (decode-char 'ucs value)
459 (setq attributes (delq '->ucs attributes))
461 (when (and (memq 'general-category attributes)
462 (setq value (get-char-attribute char 'general-category)))
464 "(general-category\t%s) ; %s%s"
465 (mapconcat (lambda (cell)
468 (cond ((rassoc value unidata-normative-category-alist)
469 "Normative Category")
470 ((rassoc value unidata-informative-category-alist)
471 "Informative Category")
475 (setq attributes (delq 'general-category attributes))
477 (when (and (memq 'bidi-category attributes)
478 (setq value (get-char-attribute char 'bidi-category)))
479 (insert (format "(bidi-category\t. %S)%s"
482 (setq attributes (delq 'bidi-category attributes))
484 (unless (or (not (memq 'mirrored attributes))
485 (eq (setq value (get-char-attribute char 'mirrored 'empty))
487 (insert (format "(mirrored\t\t. %S)%s"
490 (setq attributes (delq 'mirrored attributes))
493 ((and (memq 'decimal-digit-value attributes)
494 (setq value (get-char-attribute char 'decimal-digit-value)))
495 (insert (format "(decimal-digit-value . %S)%s"
498 (setq attributes (delq 'decimal-digit-value attributes))
499 (when (and (memq 'digit-value attributes)
500 (setq value (get-char-attribute char 'digit-value)))
501 (insert (format "(digit-value\t . %S)%s"
504 (setq attributes (delq 'digit-value attributes))
506 (when (and (memq 'numeric-value attributes)
507 (setq value (get-char-attribute char 'numeric-value)))
508 (insert (format "(numeric-value\t . %S)%s"
511 (setq attributes (delq 'numeric-value attributes))
515 (when (and (memq 'digit-value attributes)
516 (setq value (get-char-attribute char 'digit-value)))
517 (insert (format "(digit-value\t. %S)%s"
520 (setq attributes (delq 'digit-value attributes))
522 (when (and (memq 'numeric-value attributes)
523 (setq value (get-char-attribute char 'numeric-value)))
524 (insert (format "(numeric-value\t. %S)%s"
527 (setq attributes (delq 'numeric-value attributes))
529 (when (and (memq 'iso-10646-comment attributes)
530 (setq value (get-char-attribute char 'iso-10646-comment)))
531 (insert (format "(iso-10646-comment\t. %S)%s"
534 (setq attributes (delq 'iso-10646-comment attributes))
536 (when (and (memq 'morohashi-daikanwa attributes)
537 (setq value (get-char-attribute char 'morohashi-daikanwa)))
538 (insert (format "(morohashi-daikanwa\t%s)%s"
539 (mapconcat (function prin1-to-string) value " ")
541 (setq attributes (delq 'morohashi-daikanwa attributes))
543 ;; (when (and (memq 'hanyu-dazidian attributes)
544 ;; (setq value (get-char-attribute char 'hanyu-dazidian)))
545 ;; (insert (format "(hanyu-dazidian %s)%s"
546 ;; (mapconcat #'number-to-string value " ")
548 ;; (setq attributes (delq 'hanyu-dazidian attributes))
552 (when (and (memq 'ideographic-radical attributes)
553 (setq value (get-char-attribute char 'ideographic-radical)))
555 (insert (format "(ideographic-radical . %S)\t; %c%s"
557 (aref ideographic-radicals radical)
559 (setq attributes (delq 'ideographic-radical attributes))
561 (when (and (memq 'ideographic-strokes attributes)
562 (setq value (get-char-attribute char 'ideographic-strokes)))
564 (insert (format "(ideographic-strokes . %S)%s"
567 (setq attributes (delq 'ideographic-strokes attributes))
569 (when (and (memq 'kangxi-radical attributes)
570 (setq value (get-char-attribute char 'kangxi-radical)))
571 (unless (eq value radical)
572 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
574 (aref ideographic-radicals value)
577 (setq radical value)))
578 (setq attributes (delq 'kangxi-radical attributes))
580 (when (and (memq 'kangxi-strokes attributes)
581 (setq value (get-char-attribute char 'kangxi-strokes)))
582 (unless (eq value strokes)
583 (insert (format "(kangxi-strokes\t . %S)%s"
587 (setq strokes value)))
588 (setq attributes (delq 'kangxi-strokes attributes))
590 (when (and (memq 'japanese-radical attributes)
591 (setq value (get-char-attribute char 'japanese-radical)))
592 (unless (eq value radical)
593 (insert (format "(japanese-radical\t . %S)\t; %c%s"
595 (aref ideographic-radicals value)
598 (setq radical value)))
599 (setq attributes (delq 'japanese-radical attributes))
601 (when (and (memq 'japanese-strokes attributes)
602 (setq value (get-char-attribute char 'japanese-strokes)))
603 (unless (eq value strokes)
604 (insert (format "(japanese-strokes\t . %S)%s"
608 (setq strokes value)))
609 (setq attributes (delq 'japanese-strokes attributes))
611 (when (and (memq 'cns-radical attributes)
612 (setq value (get-char-attribute char 'cns-radical)))
613 (insert (format "(cns-radical\t . %S)\t; %c%s"
615 (aref ideographic-radicals value)
617 (setq attributes (delq 'cns-radical attributes))
619 (when (and (memq 'cns-strokes attributes)
620 (setq value (get-char-attribute char 'cns-strokes)))
621 (unless (eq value strokes)
622 (insert (format "(cns-strokes\t . %S)%s"
626 (setq strokes value)))
627 (setq attributes (delq 'cns-strokes attributes))
629 (when (and (memq 'shinjigen-1-radical attributes)
630 (setq value (get-char-attribute char 'shinjigen-1-radical)))
631 (unless (eq value radical)
632 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
634 (aref ideographic-radicals value)
637 (setq radical value)))
638 (setq attributes (delq 'shinjigen-1-radical attributes))
640 (when (and (memq 'ideographic- attributes)
641 (setq value (get-char-attribute char 'ideographic-)))
642 (insert "(ideographic- ")
643 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
646 (setq cell (car value))
648 (setq cell (decode-char 'ucs cell)))
649 (cond ((characterp cell)
653 (insert (format "%S" cell))
654 (char-db-insert-char-spec cell readable))
655 (setq separator lbs))
659 (if (consp (car cell))
660 (char-db-insert-char-spec cell readable)
661 (char-db-insert-char-reference cell readable))
662 (setq separator lbs))
666 (insert (prin1-to-string cell))
667 (setq separator " ")))
668 (setq value (cdr value)))
670 (insert line-breaking)
671 (setq attributes (delq 'ideographic- attributes)))
672 (when (and (memq 'total-strokes attributes)
673 (setq value (get-char-attribute char 'total-strokes)))
674 (insert (format "(total-strokes . %S)%s"
677 (setq attributes (delq 'total-strokes attributes))
679 (when (and (memq '->ideograph attributes)
680 (setq value (get-char-attribute char '->ideograph)))
681 (insert (format "(->ideograph\t%s)%s"
682 (mapconcat (lambda (code)
683 (cond ((symbolp code)
686 (format "#x%04X" code))
689 line-breaking code))))
692 (setq attributes (delq '->ideograph attributes))
694 (when (and (memq '->decomposition attributes)
695 (setq value (get-char-attribute char '->decomposition)))
696 (insert (format "(->decomposition\t%s)%s"
697 (mapconcat (lambda (code)
698 (cond ((symbolp code)
707 (format "#x%04X" code))
709 (format "%s%S" line-breaking code))))
712 (setq attributes (delq '->decomposition attributes))
714 (if (equal (get-char-attribute char '->titlecase)
715 (get-char-attribute char '->uppercase))
716 (setq attributes (delq '->titlecase attributes)))
717 (when (and (memq '->mojikyo attributes)
718 (setq value (get-char-attribute char '->mojikyo)))
719 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
720 value (decode-char 'mojikyo value)
722 (setq attributes (delq '->mojikyo attributes))
724 (when (and (memq 'hanyu-dazidian-vol attributes)
725 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
726 (insert (format "(hanyu-dazidian-vol . %d)%s"
727 value line-breaking))
728 (setq attributes (delq 'hanyu-dazidian-vol attributes))
730 (when (and (memq 'hanyu-dazidian-page attributes)
731 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
732 (insert (format "(hanyu-dazidian-page . %d)%s"
733 value line-breaking))
734 (setq attributes (delq 'hanyu-dazidian-page attributes))
736 (when (and (memq 'hanyu-dazidian-char attributes)
737 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
738 (insert (format "(hanyu-dazidian-char . %d)%s"
739 value line-breaking))
740 (setq attributes (delq 'hanyu-dazidian-char attributes))
742 (setq rest ccs-attributes)
745 (setq value (get-char-attribute char (car rest)))
747 (if (>= (length (symbol-name (car rest))) 19)
749 (setq has-long-ccs-name t)
753 (setq rest (cdr rest)))
755 (setq name (car attributes))
756 (if (setq value (get-char-attribute char name))
757 (cond ((eq name 'jisx0208-1978/4X)
758 (insert (format "(%-18s . #x%04X)%s"
761 ((or (eq name 'ideographic-structure)
762 (eq name 'ideographic-)
763 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
764 (insert (format "(%-18s%s " name line-breaking))
765 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
768 (setq cell (car value))
770 (setq cell (decode-char 'ucs cell)))
771 (cond ((characterp cell)
775 (insert (format "%S" cell))
776 (char-db-insert-char-spec cell readable))
777 (setq separator lbs))
781 (if (consp (car cell))
782 (char-db-insert-char-spec cell readable)
783 (char-db-insert-char-reference cell readable))
784 (setq separator lbs))
788 (insert (prin1-to-string cell))
789 (setq separator " ")))
790 (setq value (cdr value)))
792 (insert line-breaking))
793 ((memq name '(ideograph=
794 original-ideograph-of
798 simplified-ideograph-of
800 ideographic-different-form-of))
801 (insert (format "(%-18s%s " name line-breaking))
802 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
805 (setq cell (car value))
806 (if (and (consp cell)
811 (char-db-insert-alist cell readable)
812 (setq separator lbs))
815 (insert (prin1-to-string cell))
816 (setq separator " "))
817 (setq value (cdr value)))
819 (insert line-breaking))
820 ;; ((string-match "^->" (symbol-name name))
822 ;; (format "(%-18s %s)%s"
824 ;; (mapconcat (lambda (code)
825 ;; (cond ((symbolp code)
826 ;; (symbol-name code))
828 ;; (format "#x%04X" code))
831 ;; line-breaking code))))
835 (insert (format "(%-18s " name))
836 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
839 (setq cell (car value))
840 (if (and (consp cell)
842 (setq ret (condition-case nil
850 (setq key (car (car rest)))
851 (if (find-charset key)
852 (setq cal (cons key cal))
853 (setq al (cons key al)))
854 (setq rest (cdr rest)))
857 (insert-char-attributes ret
860 (setq separator lbs))
863 (insert (prin1-to-string cell))
864 (setq separator " "))
865 (setq value (cdr value)))
867 (insert line-breaking))
869 (insert (format "(%-18s . %S)%s"
873 (setq attributes (cdr attributes)))
874 (while ccs-attributes
875 (setq name (car ccs-attributes))
876 (if (and (eq name (charset-name name))
877 (setq value (get-char-attribute char name)))
880 (cond ((memq name '(ideograph-daikanwa-2
884 (if has-long-ccs-name
885 "(%-26s . %05d)\t; %c%s"
886 "(%-18s . %05d)\t; %c%s"))
888 (if has-long-ccs-name
889 "(%-26s . %06d)\t; %c%s"
890 "(%-18s . %06d)\t; %c%s"))
892 (if has-long-ccs-name
893 "(%-26s . #x%04X)\t; %c%s"
894 "(%-18s . #x%04X)\t; %c%s"))
896 (if has-long-ccs-name
897 "(%-26s . #x%02X)\t; %c%s"
898 "(%-18s . #x%02X)\t; %c%s")))
900 (if (= (charset-iso-graphic-plane name) 1)
902 (cond ((= (charset-dimension name) 1)
904 ((= (charset-dimension name) 2)
906 ((= (charset-dimension name) 3)
910 (char-db-decode-isolated-char name value)
912 (setq ccs-attributes (cdr ccs-attributes)))
915 (defun insert-char-data (char &optional readable
916 attributes ccs-attributes)
918 (narrow-to-region (point)(point))
919 (insert "(define-char
921 (insert-char-attributes char readable
922 attributes ccs-attributes)
924 (goto-char (point-min))
925 (while (re-search-forward "[ \t]+$" nil t)
927 (goto-char (point-max))
928 (tabify (point-min)(point-max))
932 (defun char-db-update-comment ()
935 (goto-char (point-min))
936 (let (cdef table char)
937 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
938 (goto-char (match-beginning 1))
939 (setq cdef (read (current-buffer)))
940 (when (find-charset (car cdef))
941 (goto-char (match-end 0))
944 (not (eq (car cdef) 'ideograph-daikanwa))
945 (or (memq (car cdef) '(ascii latin-viscii-upper
949 japanese-jisx0213-2))
950 (= (char-int (charset-iso-final-char (car cdef)))
952 (apply (function make-char) cdef)
953 (if (setq table (charset-mapping-table (car cdef)))
954 (set-charset-mapping-table (car cdef) nil))
956 (apply (function make-char) cdef)
958 (set-charset-mapping-table (car cdef) table)))))
959 (when (not (or (< (char-int char) 32)
960 (and (<= 128 (char-int char))
961 (< (char-int char) 160))))
962 (delete-region (point) (point-at-eol))
963 (insert (format "\t; %c" char)))
966 (defun insert-char-data-with-variant (char &optional printable
968 script excluded-script)
969 (insert-char-data char printable)
970 (let ((variants (or (char-variants char)
971 (let ((ucs (get-char-attribute char '->ucs)))
973 (delete char (char-variants (int-char ucs)))))))
975 (setq variants (sort variants #'<))
977 (setq variant (car variants))
978 (if (and (or (null script)
979 (null (setq vs (get-char-attribute variant 'script)))
981 (or (null excluded-script)
982 (null (setq vs (get-char-attribute variant 'script)))
983 (not (memq excluded-script vs))))
984 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
985 (insert-char-data variant printable)))
986 (setq variants (cdr variants))
989 (defun insert-char-range-data (min max &optional script excluded-script)
993 (setq char (decode-char 'ucs code))
994 (if (get-char-attribute char 'ucs)
995 (insert-char-data-with-variant char nil 'no-ucs-variant
996 script excluded-script))
997 (setq code (1+ code))
1000 (defun write-char-range-data-to-file (min max file
1001 &optional script excluded-script)
1002 (let ((coding-system-for-write 'utf-8))
1004 (insert-char-range-data min max script excluded-script)
1005 (write-region (point-min)(point-max) file))))
1007 (defvar what-character-original-window-configuration)
1010 (defun what-char-definition (char)
1011 (interactive (list (char-after)))
1012 (let ((buf (get-buffer-create "*Character Description*"))
1013 (the-buf (current-buffer))
1014 (win-conf (current-window-configuration)))
1016 (make-local-variable 'what-character-original-window-configuration)
1017 (setq what-character-original-window-configuration win-conf)
1018 (setq buffer-read-only nil)
1022 (insert-char-data-with-variant char 'printable)
1023 (unless (char-attribute-alist char)
1024 (insert (format ";; = %c\n"
1025 (let* ((rest (split-char char))
1029 (setq code (logior (lsh code 8)
1031 (decode-char ccs code)))))
1032 ;; (char-db-update-comment)
1033 (set-buffer-modified-p nil)
1034 (view-mode the-buf (lambda (buf)
1035 (set-window-configuration
1036 what-character-original-window-configuration)
1038 (goto-char (point-min)))
1040 (set-window-configuration
1041 what-character-original-window-configuration)
1042 (signal (car err) (cdr err)))))))
1044 (provide 'char-db-util)
1046 ;;; char-db-util.el ends here