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-insert-char-spec (char &optional readable column)
148 (setq column (current-column)))
149 (let (char-spec ret al cal key temp-char)
150 (cond ((characterp char)
151 (cond ((and (setq ret (get-char-attribute char 'ucs))
152 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
153 (setq char-spec (list (cons 'ucs ret)))
154 (if (setq ret (get-char-attribute char 'name))
155 (setq char-spec (cons (cons 'name ret) char-spec)))
158 (let ((default-coded-charset-priority-list
159 char-db-coded-charset-priority-list))
161 (setq char-spec (list ret))
162 (dolist (ccs (delq (car ret) (charset-list)))
163 (if (or (and (charset-iso-final-char ccs)
164 (setq ret (get-char-attribute char ccs)))
165 (eq ccs 'ideograph-daikanwa))
166 (setq char-spec (cons (cons ccs ret) char-spec))))
168 (setq char-spec (split-char char)))
169 (if (setq ret (get-char-attribute char 'name))
170 (setq char-spec (cons (cons 'name ret) char-spec)))
173 (setq char-spec char)
177 (setq char (find-char char-spec))
179 ;; define temporary character
180 ;; Current implementation is dirty.
181 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
183 (remove-char-attribute temp-char 'ideograph-daikanwa)
184 (setq char temp-char))
188 (setq key (car (car char-spec)))
189 (unless (memq key char-db-ignored-attributes)
190 (if (find-charset key)
191 (setq cal (cons key cal))
192 (setq al (cons key al))))
193 (setq char-spec (cdr char-spec)))
195 (memq 'ideographic-structure al))
196 (push 'ideographic-structure al))
197 (insert-char-attributes char
201 ;; undefine temporary character
202 ;; Current implementation is dirty.
203 (setq char-spec (char-attribute-alist temp-char))
205 (remove-char-attribute temp-char (car (car char-spec)))
206 (setq char-spec (cdr char-spec))))))
208 (defun char-db-insert-alist (alist &optional readable column)
210 (setq column (current-column)))
212 (concat "\n" (make-string (1+ column) ?\ )))
215 lbs cell rest separator)
218 (setq name (car (car alist))
219 value (cdr (car alist)))
220 (cond ((eq name 'char)
222 (if (setq ret (condition-case nil
229 (setq key (car (car value)))
230 (if (find-charset key)
231 (setq cal (cons key cal))
232 (setq al (cons key al)))
233 (setq value (cdr value)))
234 (insert-char-attributes ret
237 (insert (prin1-to-string value)))
239 (insert line-breaking))
241 (insert (format "(%-18s " name))
242 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
244 (setq cell (car value))
245 (if (and (consp cell)
247 (setq ret (condition-case nil
256 (setq key (car (car rest)))
257 (if (find-charset key)
258 (setq cal (cons key cal))
259 (setq al (cons key al)))
260 (setq rest (cdr rest)))
263 (insert-char-attributes ret
266 (setq separator lbs))
269 (insert (prin1-to-string cell))
270 (setq separator " "))
271 (setq value (cdr value)))
273 (insert line-breaking))
275 (insert (format "(%-18s . %S)%s"
278 (setq alist (cdr alist))))
281 (defun char-db-insert-char-reference (plist &optional readable column)
283 (setq column (current-column)))
285 (concat "\n" (make-string (1+ column) ?\ )))
290 (setq name (pop plist))
291 (setq value (pop plist))
292 (cond ((eq name :char)
295 (cond ((numberp value)
296 (setq value (decode-char 'ucs value)))
298 ;; (setq value (or (find-char value)
301 (char-db-insert-char-spec value readable)
302 (insert line-breaking)
305 (insert (format "%s%s\t%d ; %c%s"
308 (aref ideographic-radicals value)
312 (insert (format "%s%s\t%S" separator name value))
313 (setq separator line-breaking)))
317 (defun char-db-decode-isolated-char (ccs code-point)
320 (cond ((eq ccs 'arabic-iso8859-6)
321 (decode-char ccs code-point))
322 ((and (memq ccs '(ideograph-gt-pj-1
333 (setq ret (decode-char ccs code-point))
334 (setq ret (get-char-attribute ret 'ideograph-gt)))
335 (decode-builtin-char 'ideograph-gt ret))
337 (decode-builtin-char ccs code-point))))
338 (cond ((and (<= 0 (char-int ret))
339 (<= (char-int ret) #x1F))
340 (decode-char 'ucs (+ #x2400 (char-int ret))))
341 ((= (char-int ret) #x7F)
345 (defvar char-db-convert-obsolete-format t)
347 (defun insert-char-attributes (char &optional readable
348 attributes ccs-attributes
353 (if (consp attributes)
355 (dolist (name attributes)
356 (unless (memq name char-db-ignored-attributes)
359 (dolist (name (char-attribute-list))
360 (unless (memq name char-db-ignored-attributes)
361 (if (find-charset name)
365 #'char-attribute-name<))
367 (sort (if ccs-attributes
370 (dolist (name ccs-attributes)
371 (unless (memq name char-db-ignored-attributes)
376 (dolist (name (charset-list))
377 (unless (memq name char-db-ignored-attributes)
380 #'char-attribute-name<)))
382 (setq column (current-column)))
383 (let (name value has-long-ccs-name rest
386 (concat "\n" (make-string (1+ column) ?\ )))
387 lbs cell separator ret
390 (when (and (memq 'name attributes)
391 (setq value (get-char-attribute char 'name)))
393 (if (> (+ (current-column) (length value)) 48)
396 value line-breaking))
397 (setq attributes (delq 'name attributes))
399 (when (and (memq 'script attributes)
400 (setq value (get-char-attribute char 'script)))
401 (insert (format "(script\t\t%s)%s"
402 (mapconcat (function prin1-to-string)
405 (setq attributes (delq 'script attributes))
407 (when (and (memq '=>ucs attributes)
408 (setq value (get-char-attribute char '=>ucs)))
409 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
410 value (decode-char 'ucs value)
412 (setq attributes (delq '=>ucs attributes))
414 (when (and (memq '=>ucs* attributes)
415 (setq value (get-char-attribute char '=>ucs*)))
416 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
417 value (decode-char 'ucs value)
419 (setq attributes (delq '=>ucs* attributes))
421 (when (and (memq '=>ucs-jis attributes)
422 (setq value (get-char-attribute char '=>ucs-jis)))
423 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
424 value (decode-char 'ucs value)
426 (setq attributes (delq '=>ucs-jis attributes))
428 (when (and (memq '->ucs attributes)
429 (setq value (get-char-attribute char '->ucs)))
430 (insert (format (if char-db-convert-obsolete-format
431 "(=>ucs\t\t. #x%04X)\t; %c%s"
432 "(->ucs\t\t. #x%04X)\t; %c%s")
433 value (decode-char 'ucs value)
435 (setq attributes (delq '->ucs attributes))
437 (when (and (memq 'general-category attributes)
438 (setq value (get-char-attribute char 'general-category)))
440 "(general-category\t%s) ; %s%s"
441 (mapconcat (lambda (cell)
444 (cond ((rassoc value unidata-normative-category-alist)
445 "Normative Category")
446 ((rassoc value unidata-informative-category-alist)
447 "Informative Category")
451 (setq attributes (delq 'general-category attributes))
453 (when (and (memq 'bidi-category attributes)
454 (setq value (get-char-attribute char 'bidi-category)))
455 (insert (format "(bidi-category\t. %S)%s"
458 (setq attributes (delq 'bidi-category attributes))
460 (unless (or (not (memq 'mirrored attributes))
461 (eq (setq value (get-char-attribute char 'mirrored 'empty))
463 (insert (format "(mirrored\t\t. %S)%s"
466 (setq attributes (delq 'mirrored attributes))
469 ((and (memq 'decimal-digit-value attributes)
470 (setq value (get-char-attribute char 'decimal-digit-value)))
471 (insert (format "(decimal-digit-value . %S)%s"
474 (setq attributes (delq 'decimal-digit-value attributes))
475 (when (and (memq 'digit-value attributes)
476 (setq value (get-char-attribute char 'digit-value)))
477 (insert (format "(digit-value\t . %S)%s"
480 (setq attributes (delq 'digit-value attributes))
482 (when (and (memq 'numeric-value attributes)
483 (setq value (get-char-attribute char 'numeric-value)))
484 (insert (format "(numeric-value\t . %S)%s"
487 (setq attributes (delq 'numeric-value attributes))
491 (when (and (memq 'digit-value attributes)
492 (setq value (get-char-attribute char 'digit-value)))
493 (insert (format "(digit-value\t. %S)%s"
496 (setq attributes (delq 'digit-value attributes))
498 (when (and (memq 'numeric-value attributes)
499 (setq value (get-char-attribute char 'numeric-value)))
500 (insert (format "(numeric-value\t. %S)%s"
503 (setq attributes (delq 'numeric-value attributes))
505 (when (and (memq 'iso-10646-comment attributes)
506 (setq value (get-char-attribute char 'iso-10646-comment)))
507 (insert (format "(iso-10646-comment\t. %S)%s"
510 (setq attributes (delq 'iso-10646-comment attributes))
512 (when (and (memq 'morohashi-daikanwa attributes)
513 (setq value (get-char-attribute char 'morohashi-daikanwa)))
514 (insert (format "(morohashi-daikanwa\t%s)%s"
515 (mapconcat (function prin1-to-string) value " ")
517 (setq attributes (delq 'morohashi-daikanwa attributes))
521 (when (and (memq 'ideographic-radical attributes)
522 (setq value (get-char-attribute char 'ideographic-radical)))
524 (insert (format "(ideographic-radical . %S)\t; %c%s"
526 (aref ideographic-radicals radical)
528 (setq attributes (delq 'ideographic-radical attributes))
530 (when (and (memq 'ideographic-strokes attributes)
531 (setq value (get-char-attribute char 'ideographic-strokes)))
533 (insert (format "(ideographic-strokes . %S)%s"
536 (setq attributes (delq 'ideographic-strokes attributes))
538 (when (and (memq 'kangxi-radical attributes)
539 (setq value (get-char-attribute char 'kangxi-radical)))
540 (unless (eq value radical)
541 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
543 (aref ideographic-radicals value)
546 (setq radical value)))
547 (setq attributes (delq 'kangxi-radical attributes))
549 (when (and (memq 'kangxi-strokes attributes)
550 (setq value (get-char-attribute char 'kangxi-strokes)))
551 (unless (eq value strokes)
552 (insert (format "(kangxi-strokes\t . %S)%s"
556 (setq strokes value)))
557 (setq attributes (delq 'kangxi-strokes attributes))
559 (when (and (memq 'japanese-radical attributes)
560 (setq value (get-char-attribute char 'japanese-radical)))
561 (unless (eq value radical)
562 (insert (format "(japanese-radical\t . %S)\t; %c%s"
564 (aref ideographic-radicals value)
567 (setq radical value)))
568 (setq attributes (delq 'japanese-radical attributes))
570 (when (and (memq 'japanese-strokes attributes)
571 (setq value (get-char-attribute char 'japanese-strokes)))
572 (unless (eq value strokes)
573 (insert (format "(japanese-strokes\t . %S)%s"
577 (setq strokes value)))
578 (setq attributes (delq 'japanese-strokes attributes))
580 (when (and (memq 'cns-radical attributes)
581 (setq value (get-char-attribute char 'cns-radical)))
582 (insert (format "(cns-radical\t . %S)\t; %c%s"
584 (aref ideographic-radicals value)
586 (setq attributes (delq 'cns-radical attributes))
588 (when (and (memq 'cns-strokes attributes)
589 (setq value (get-char-attribute char 'cns-strokes)))
590 (unless (eq value strokes)
591 (insert (format "(cns-strokes\t . %S)%s"
595 (setq strokes value)))
596 (setq attributes (delq 'cns-strokes attributes))
598 (when (and (memq 'shinjigen-1-radical attributes)
599 (setq value (get-char-attribute char 'shinjigen-1-radical)))
600 (unless (eq value radical)
601 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
603 (aref ideographic-radicals value)
606 (setq radical value)))
607 (setq attributes (delq 'shinjigen-1-radical attributes))
609 (when (and (memq 'ideographic- attributes)
610 (setq value (get-char-attribute char 'ideographic-)))
611 (insert "(ideographic- ")
612 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
615 (setq cell (car value))
617 (setq cell (decode-char 'ucs cell)))
618 (cond ((characterp cell)
622 (insert (format "%S" cell))
623 (char-db-insert-char-spec cell readable))
624 (setq separator lbs))
628 (if (consp (car cell))
629 (char-db-insert-char-spec cell readable)
630 (char-db-insert-char-reference cell readable))
631 (setq separator lbs))
635 (insert (prin1-to-string cell))
636 (setq separator " ")))
637 (setq value (cdr value)))
639 (insert line-breaking)
640 (setq attributes (delq 'ideographic- attributes)))
641 (when (and (memq 'total-strokes attributes)
642 (setq value (get-char-attribute char 'total-strokes)))
643 (insert (format "(total-strokes . %S)%s"
646 (setq attributes (delq 'total-strokes attributes))
648 (when (and (memq '->ideograph attributes)
649 (setq value (get-char-attribute char '->ideograph)))
650 (insert (format "(->ideograph\t%s)%s"
651 (mapconcat (lambda (code)
652 (cond ((symbolp code)
655 (format "#x%04X" code))
658 line-breaking code))))
661 (setq attributes (delq '->ideograph attributes))
663 (when (and (memq '->decomposition attributes)
664 (setq value (get-char-attribute char '->decomposition)))
665 (insert (format "(->decomposition\t%s)%s"
666 (mapconcat (lambda (code)
667 (cond ((symbolp code)
676 (format "#x%04X" code))
678 (format "%s%S" line-breaking code))))
681 (setq attributes (delq '->decomposition attributes))
683 (if (equal (get-char-attribute char '->titlecase)
684 (get-char-attribute char '->uppercase))
685 (setq attributes (delq '->titlecase attributes)))
686 (when (and (memq '->mojikyo attributes)
687 (setq value (get-char-attribute char '->mojikyo)))
688 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
689 value (decode-char 'mojikyo value)
691 (setq attributes (delq '->mojikyo attributes))
693 (when (and (memq 'hanyu-dazidian-vol attributes)
694 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
695 (insert (format "(hanyu-dazidian-vol . %d)%s"
696 value line-breaking))
697 (setq attributes (delq 'hanyu-dazidian-vol attributes))
699 (when (and (memq 'hanyu-dazidian-page attributes)
700 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
701 (insert (format "(hanyu-dazidian-page . %d)%s"
702 value line-breaking))
703 (setq attributes (delq 'hanyu-dazidian-page attributes))
705 (when (and (memq 'hanyu-dazidian-char attributes)
706 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
707 (insert (format "(hanyu-dazidian-char . %d)%s"
708 value line-breaking))
709 (setq attributes (delq 'hanyu-dazidian-char attributes))
712 (when (memq '->ucs-variants attributes)
713 (setq attributes (delq '->ucs-variants attributes))
715 (when (memq 'composition attributes)
716 (setq attributes (delq 'composition attributes))
718 (setq rest ccs-attributes)
721 (setq value (get-char-attribute char (car rest)))
723 (if (>= (length (symbol-name (car rest))) 19)
725 (setq has-long-ccs-name t)
729 (setq rest (cdr rest)))
731 (setq name (car attributes))
732 (if (setq value (get-char-attribute char name))
733 (cond ((eq name 'jisx0208-1978/4X)
734 (insert (format "(%-18s . #x%04X)%s"
737 ((or (eq name 'ideographic-structure)
738 (eq name 'ideographic-)
739 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
740 ;; (memq name '(->lowercase
741 ;; ->uppercase ->titlecase
742 ;; ->fullwidth <-fullwidth
744 ;; ->vulgar-ideograph <-vulgar-ideograph
745 ;; ->ancient-ideograph <-ancient-ideograph
746 ;; ->original-ideograph <-original-ideograph
747 ;; ->simplified-ideograph <-simplified-ideograph
748 ;; ->wrong-ideograph <-wrong-ideograph
750 ;; ->ideographic-variants
752 ;; ->radical <-radical
753 ;; ->bopomofo <-bopomofo
754 ;; ->ideographic <-ideographic
755 ;; ideographic-structure))
756 (insert (format "(%-18s%s " name line-breaking))
757 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
760 (setq cell (car value))
762 (setq cell (decode-char 'ucs cell)))
763 (cond ((characterp cell)
767 (insert (format "%S" cell))
768 (char-db-insert-char-spec cell readable))
769 (setq separator lbs))
773 (if (consp (car cell))
774 (char-db-insert-char-spec cell readable)
775 (char-db-insert-char-reference cell readable))
776 (setq separator lbs))
780 (insert (prin1-to-string cell))
781 (setq separator " ")))
782 (setq value (cdr value)))
784 (insert line-breaking))
785 ((memq name '(ideograph=
786 original-ideograph-of
790 simplified-ideograph-of
792 ideographic-different-form-of))
793 (insert (format "(%-18s%s " name line-breaking))
794 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
797 (setq cell (car value))
798 (if (and (consp cell)
803 (char-db-insert-alist cell readable)
804 (setq separator lbs))
807 (insert (prin1-to-string cell))
808 (setq separator " "))
809 (setq value (cdr value)))
811 (insert line-breaking))
812 ;; ((string-match "^->" (symbol-name name))
814 ;; (format "(%-18s %s)%s"
816 ;; (mapconcat (lambda (code)
817 ;; (cond ((symbolp code)
818 ;; (symbol-name code))
820 ;; (format "#x%04X" code))
823 ;; line-breaking code))))
827 (insert (format "(%-18s " name))
828 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
831 (setq cell (car value))
832 (if (and (consp cell)
834 (setq ret (condition-case nil
842 (setq key (car (car rest)))
843 (if (find-charset key)
844 (setq cal (cons key cal))
845 (setq al (cons key al)))
846 (setq rest (cdr rest)))
849 (insert-char-attributes ret
852 (setq separator lbs))
855 (insert (prin1-to-string cell))
856 (setq separator " "))
857 (setq value (cdr value)))
859 (insert line-breaking))
861 (insert (format "(%-18s . %S)%s"
865 (setq attributes (cdr attributes)))
866 (while ccs-attributes
867 (setq name (car ccs-attributes))
868 (if (and (eq name (charset-name name))
869 (setq value (get-char-attribute char name)))
872 (cond ((memq name '(ideograph-daikanwa-2
876 (if has-long-ccs-name
877 "(%-26s . %05d)\t; %c%s"
878 "(%-18s . %05d)\t; %c%s"))
880 (if has-long-ccs-name
881 "(%-26s . %06d)\t; %c%s"
882 "(%-18s . %06d)\t; %c%s"))
884 (if has-long-ccs-name
885 "(%-26s . #x%04X)\t; %c%s"
886 "(%-18s . #x%04X)\t; %c%s"))
888 (if has-long-ccs-name
889 "(%-26s . #x%02X)\t; %c%s"
890 "(%-18s . #x%02X)\t; %c%s")))
892 (if (= (charset-iso-graphic-plane name) 1)
894 (cond ((= (charset-dimension name) 1)
896 ((= (charset-dimension name) 2)
898 ((= (charset-dimension name) 3)
902 (char-db-decode-isolated-char name value)
904 (setq ccs-attributes (cdr ccs-attributes)))
907 (defun insert-char-data (char &optional readable
908 attributes ccs-attributes)
910 (narrow-to-region (point)(point))
911 (insert "(define-char
913 (insert-char-attributes char readable
914 attributes ccs-attributes)
916 (goto-char (point-min))
917 (while (re-search-forward "[ \t]+$" nil t)
919 (goto-char (point-max))
920 (tabify (point-min)(point-max))
924 (defun char-db-update-comment ()
927 (goto-char (point-min))
928 (let (cdef table char)
929 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
930 (goto-char (match-beginning 1))
931 (setq cdef (read (current-buffer)))
932 (when (find-charset (car cdef))
933 (goto-char (match-end 0))
936 (not (eq (car cdef) 'ideograph-daikanwa))
937 (or (memq (car cdef) '(ascii latin-viscii-upper
941 japanese-jisx0213-2))
942 (= (char-int (charset-iso-final-char (car cdef)))
944 (apply (function make-char) cdef)
945 (if (setq table (charset-mapping-table (car cdef)))
946 (set-charset-mapping-table (car cdef) nil))
948 (apply (function make-char) cdef)
950 (set-charset-mapping-table (car cdef) table)))))
951 (when (not (or (< (char-int char) 32)
952 (and (<= 128 (char-int char))
953 (< (char-int char) 160))))
954 (delete-region (point) (point-at-eol))
955 (insert (format "\t; %c" char)))
958 (defun insert-char-data-with-variant (char &optional printable
960 script excluded-script)
961 (insert-char-data char printable)
962 (let ((variants (or (char-variants char)
963 (let ((ucs (get-char-attribute char '->ucs)))
965 (delete char (char-variants (int-char ucs)))))))
967 (setq variants (sort variants #'<))
969 (setq variant (car variants))
970 (if (and (or (null script)
971 (null (setq vs (get-char-attribute variant 'script)))
973 (or (null excluded-script)
974 (null (setq vs (get-char-attribute variant 'script)))
975 (not (memq excluded-script vs))))
976 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
977 (insert-char-data variant printable)))
978 (setq variants (cdr variants))
981 (defun insert-char-range-data (min max &optional script excluded-script)
985 (setq char (decode-char 'ucs code))
986 (if (get-char-attribute char 'ucs)
987 (insert-char-data-with-variant char nil 'no-ucs-variant
988 script excluded-script))
989 (setq code (1+ code))
992 (defun write-char-range-data-to-file (min max file
993 &optional script excluded-script)
994 (let ((coding-system-for-write 'utf-8))
996 (insert-char-range-data min max script excluded-script)
997 (write-region (point-min)(point-max) file))))
999 (defvar what-character-original-window-configuration)
1002 (defun what-char-definition (char)
1003 (interactive (list (char-after)))
1004 (let ((buf (get-buffer-create "*Character Description*"))
1005 (the-buf (current-buffer))
1006 (win-conf (current-window-configuration)))
1008 (make-local-variable 'what-character-original-window-configuration)
1009 (setq what-character-original-window-configuration win-conf)
1010 (setq buffer-read-only nil)
1014 (insert-char-data-with-variant char 'printable)
1015 (unless (char-attribute-alist char)
1016 (insert (format ";; = %c\n"
1017 (let* ((rest (split-char char))
1021 (setq code (logior (lsh code 8)
1023 (decode-char ccs code)))))
1024 ;; (char-db-update-comment)
1025 (set-buffer-modified-p nil)
1026 (view-mode the-buf (lambda (buf)
1027 (set-window-configuration
1028 what-character-original-window-configuration)
1030 (goto-char (point-min)))
1032 (set-window-configuration
1033 what-character-original-window-configuration)
1034 (signal (car err) (cdr err)))))))
1036 (provide 'char-db-util)
1038 ;;; char-db-util.el ends here