1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998, 1999 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: UTF-2000, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of UTF-2000.
10 ;; UTF-2000 is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; UTF-2000 is distributed in the hope that it will be useful, but
16 ;; 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; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
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 (if (< (charset-iso-final-char (car (split-char (aref v 34)))) ?0)
71 (aset v 34 (make-char 'chinese-gb2312 #x62 #x3A)))
74 (defun char-attribute-name< (ka kb)
80 ((= (charset-dimension ka)
81 (charset-dimension kb))
82 (cond ((= (charset-chars ka)(charset-chars kb))
84 ((>= (charset-iso-final-char ka) ?@)
85 (if (>= (charset-iso-final-char kb) ?@)
86 (< (charset-iso-final-char ka)
87 (charset-iso-final-char kb))
89 ((>= (charset-iso-final-char ka) ?0)
91 ((>= (charset-iso-final-char kb) ?@)
93 ((>= (charset-iso-final-char kb) ?0)
94 (< (charset-iso-final-char ka)
95 (charset-iso-final-char kb)))
97 ((<= (charset-chars ka)(charset-chars kb)))))
99 (< (charset-dimension ka)
100 (charset-dimension kb))
110 (string< (symbol-name ka)
116 (defun insert-char-data (char)
117 (let ((data (char-attribute-alist char))
118 cell ret has-long-ccs-name rest)
121 (narrow-to-region (point)(point))
122 (insert "(define-char
124 (when (setq cell (assq 'name data))
125 (setq cell (cdr cell))
127 (if (> (length cell) 47)
133 (setq data (del-alist 'name data))
135 (when (setq cell (assq 'name data))
136 (setq cell (cdr cell))
138 (if (> (length cell) 47)
144 (setq data (del-alist 'name data))
146 (when (setq cell (assq 'ucs data))
147 (setq cell (cdr cell))
148 (insert (format "(ucs\t\t. #x%04X)
151 (setq data (del-alist 'ucs data))
153 (when (setq cell (assq '->ucs data))
154 (setq cell (cdr cell))
155 (insert (format "(->ucs\t\t. #x%04X)
158 (setq data (del-alist '->ucs data))
160 (when (setq cell (assq 'general-category data))
161 (setq ret (cdr cell))
163 "(general-category\t%s) ; %s
165 (mapconcat (lambda (cell)
168 (cond ((rassoc (cdr cell)
169 unidata-normative-category-alist)
170 "Normative Category")
172 unidata-informative-category-alist)
173 "Informative Category")
175 "Unknown Category"))))
176 (setq data (del-alist 'general-category data))
178 (when (setq cell (assq 'bidi-category data))
179 (setq cell (cdr cell))
180 (insert (format "(bidi-category\t. %S)
183 (setq data (del-alist 'bidi-category data))
185 (when (setq cell (assq 'mirrored data))
186 (setq cell (cdr cell))
187 (insert (format "(mirrored\t\t. %S)
190 (setq data (del-alist 'mirrored data))
193 ((setq cell (assq 'decimal-digit-value data))
194 (setq cell (cdr cell))
195 (insert (format "(decimal-digit-value . %S)
198 (setq data (del-alist 'decimal-digit-value data))
199 (when (setq cell (assq 'digit-value data))
200 (setq cell (cdr cell))
201 (insert (format "(digit-value\t . %S)
204 (setq data (del-alist 'digit-value data))
206 (when (setq cell (assq 'numeric-value data))
207 (setq cell (cdr cell))
208 (insert (format "(numeric-value\t . %S)
211 (setq data (del-alist 'numeric-value data))
215 (when (setq cell (assq 'digit-value data))
216 (setq cell (cdr cell))
217 (insert (format "(digit-value\t. %S)
220 (setq data (del-alist 'digit-value data))
222 (when (setq cell (assq 'numeric-value data))
223 (setq cell (cdr cell))
224 (insert (format "(numeric-value\t. %S)
227 (setq data (del-alist 'numeric-value data))
229 (when (setq cell (assq 'iso-10646-comment data))
230 (setq cell (cdr cell))
231 (insert (format "(iso-10646-comment\t. %S)
234 (setq data (del-alist 'iso-10646-comment data))
236 (when (setq cell (assq 'morohashi-daikanwa data))
237 (setq cell (cdr cell))
238 (insert (format "(morohashi-daikanwa\t%s)
240 (mapconcat (function prin1-to-string) cell " ")))
241 (setq data (del-alist 'morohashi-daikanwa data))
243 (when (setq cell (assq 'ideographic-radical data))
244 (setq cell (cdr cell))
245 (insert (format "(ideographic-radical . %S)\t; %c
248 (aref ideographic-radicals cell)))
249 (setq data (del-alist 'ideographic-radical data))
252 ((setq cell (assq 'ideographic-strokes data))
253 (setq cell (cdr cell))
254 (insert (format "(ideographic-strokes . %S)
257 (setq data (del-alist 'ideographic-strokes data))
258 (when (setq cell (assq 'total-strokes data))
259 (setq cell (cdr cell))
260 (insert (format "(total-strokes\t . %S)
263 (setq data (del-alist 'total-strokes data))
265 ((setq cell (assq 'total-strokes data))
266 (setq cell (cdr cell))
267 (insert (format "(total-strokes\t. %S)
270 (setq data (del-alist 'total-strokes data))
272 (when (setq cell (assq '->decomposition data))
273 (setq cell (cdr cell))
274 (insert (format "(->decomposition\t%s)
276 (mapconcat (lambda (code)
277 (cond ((symbolp code)
280 (format "#x%04X" code))
282 (format "\n %S" code))))
284 (setq data (del-alist '->decomposition data))
286 (when (setq cell (assq '->uppercase data))
287 (setq cell (cdr cell))
288 (insert (format "(->uppercase\t%s)
290 (mapconcat (lambda (code)
291 (cond ((symbolp code)
294 (format "#x%04X" code))
296 (format "\n %S" code))))
298 (setq data (del-alist '->uppercase data))
300 (when (setq cell (assq '->lowercase data))
301 (setq cell (cdr cell))
302 (insert (format "(->lowercase\t%s)
304 (mapconcat (lambda (code)
305 (cond ((symbolp code)
308 (format "#x%04X" code))
310 (format "\n %S" code))))
312 (setq data (del-alist '->lowercase data))
314 (when (setq cell (assq '->titlecase data))
315 (setq cell (cdr cell))
316 (insert (format "(->titlecase\t%s)
318 (mapconcat (lambda (code)
319 (cond ((symbolp code)
322 (format "#x%04X" code))
324 (format "\n %S" code))))
326 (setq data (del-alist '->titlecase data))
331 (char-attribute-name< (car a)(car b)))))
335 (setq cell (car rest))
336 (if (setq ret (find-charset (car cell)))
337 (if (>= (length (symbol-name (charset-name ret))) 19)
339 (setq has-long-ccs-name t)
343 (setq rest (cdr rest)))
345 (setq cell (car data))
346 (cond ((setq ret (find-charset (car cell)))
349 (if has-long-ccs-name
359 (if (= (charset-iso-graphic-plane ret) 1)
363 ((string-match "^->" (symbol-name (car cell)))
368 (mapconcat (lambda (code)
369 (cond ((symbolp code)
372 (format "#x%04X" code))
374 (format "\n %S" code))))
377 (insert (format "(%-18s %s)
380 (mapconcat (function prin1-to-string)
383 (insert (format "(%-18s . %S)
385 (car cell)(cdr cell)))
387 (setq data (cdr data)))
389 (goto-char (point-min))
390 (while (re-search-forward "[ \t]+$" nil t)
392 (goto-char (point-max))
393 (tabify (point-min)(point-max))
397 (defun char-db-update-comment ()
400 (goto-char (point-min))
401 (let (cdef table char)
402 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
403 (goto-char (match-beginning 1))
404 (setq cdef (read (current-buffer)))
405 (when (find-charset (car cdef))
406 (goto-char (match-end 0))
408 (if (or (memq (car cdef) '(ascii latin-viscii-upper
411 (= (char-int (charset-iso-final-char (car cdef))) 0))
412 (apply (function make-char) cdef)
413 (if (setq table (charset-mapping-table (car cdef)))
414 (set-charset-mapping-table (car cdef) nil))
416 (apply (function make-char) cdef)
418 (set-charset-mapping-table (car cdef) table)))))
419 (when (not (or (< (char-int char) 32)
420 (and (<= 128 (char-int char))
421 (< (char-int char) 160))))
422 (delete-region (point) (point-at-eol))
423 (insert (format "\t; %c" char)))
426 (defun insert-char-data-with-variant (char)
427 (insert-char-data char)
428 (let ((variants (char-variants char)))
430 (insert-char-data (car variants))
431 (setq variants (cdr variants))
434 (defun insert-char-range-data (min max)
438 (setq char (int-char code))
439 (insert-char-data-with-variant char)
440 (setq code (1+ code))
443 (defun write-char-range-data-to-file (min max file)
445 (insert-char-range-data min max)
446 (write-region (point-min)(point-max) file)))
448 (defvar what-character-original-window-configuration)
451 (defun what-char-definition (char)
452 (interactive (list (char-after)))
453 (let ((buf (get-buffer-create "*Character Description*"))
454 (the-buf (current-buffer))
455 (win-conf (current-window-configuration)))
457 (make-local-variable 'what-character-original-window-configuration)
458 (setq what-character-original-window-configuration win-conf)
459 (setq buffer-read-only nil)
463 (insert-char-data-with-variant char)
464 (char-db-update-comment)
465 (set-buffer-modified-p nil)
466 (view-mode the-buf (lambda (buf)
467 (set-window-configuration
468 what-character-original-window-configuration)
470 (goto-char (point-min)))
472 (set-window-configuration
473 what-character-original-window-configuration)
474 (signal (car err) (cdr err)))))))
476 (provide 'char-db-util)
478 ;;; char-db-util.el ends here