1 ;;; iddef.el --- Parser and utility for IDDef format files.
3 ;; Copyright (C) 2001 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: IDDef, IDS, IDC, Ideographs, UCS, Unicode
8 ;; This file is a part of Tomoyo-Tools.
10 ;; This program 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 ;; This program 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 this program; 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.
27 ;; IDDef is a tab-separated format to describe some
28 ;; character-attributes of each Ideographs mainly for Ideographic
37 (defun iddef-read-buffer (buffer)
38 (with-current-buffer buffer
39 (goto-char (point-min))
44 (while (re-search-forward
45 "^U\\+\\([0-9A-F]+\\)\t\\([0-9]+\\)\t[^\t]+\t\\([^\t\n]+\\)"
47 (setq ucs (string-to-int (match-string 1) 16)
48 radical (string-to-int (match-string 2))
50 (setq ret (ids-parse-string seq))
51 (when (and (consp ret)
53 (setq struct (cdr (assq 'ideographic-structure ret)))))
54 (setq char (decode-char 'ucs ucs))
55 (unless (get-char-attribute char 'ideograph-daikanwa)
56 (when (and (setq morohashi
57 (get-char-attribute char 'morohashi-daikanwa))
58 (>= (length morohashi) 3))
60 (if (= (nth 1 morohashi) 0)
61 (decode-char 'ideograph-daikanwa
62 (setq morohashi (car morohashi)))
63 (setq morohashi (list (car morohashi)
65 (map-char-attribute (lambda (char val)
66 (if (equal morohashi val)
68 'morohashi-daikanwa)))
69 (unless (get-char-attribute m-chr 'ucs)
72 'ideographic-structure
73 (ideographic-structure-convert-to-daikanwa struct)))))
74 (put-char-attribute char 'ideographic-structure struct)
76 (get-char-attribute char '->same-ideograph)
77 (get-char-attribute char '->identical)))
79 (cond ((characterp ref) ref)
81 (find-char (plist-get ref :char)))
84 (unless (get-char-attribute ret 'ucs)
85 (put-char-attribute ret 'ideographic-structure struct))))
89 (defun iddef-read-file (file)
90 (interactive "fIDDef file : ")
92 (let ((coding-system-for-read 'utf-8))
93 (insert-file-contents file))
94 (iddef-read-buffer (current-buffer))))
102 ;;; iddef.el ends here