(ideographic-structure-char=): New function; check `<-radical'
[chise/ids.git] / ids-find.el
1 ;;; ids-find.el --- search utility based on Ideographic-structures
2
3 ;; Copyright (C) 2002 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: Kanji, Ideographs, search, IDS
7
8 ;; This file is a part of Tomoyo-Tools.
9
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.
14
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.
19
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.
24
25 ;;; Code:
26
27 (defun ideographic-structure-char= (c1 c2)
28   (or (eq c1 c2)
29       (and c1 c2
30            (or (eq (char-ucs c1)(char-ucs c2))
31                (let ((m1 (car (get-char-attribute c1 '<-radical)))
32                      (m2 (car (get-char-attribute c2 '<-radical))))
33                  (unless (characterp m1)
34                    (setq m1 (or (find-char m1))))
35                  (unless (characterp m2)
36                    (setq m2 (find-char m2)))
37                  (when (or m1 m2)
38                    (ideographic-structure-char= m1 m2)))))))
39
40 (defun ideographic-structure-member-compare-parts (part s-part)
41   (let (ret)
42     (cond ((char-ref= part s-part #'ideographic-structure-char=))
43           ((listp s-part)
44            (if (setq ret (assq 'ideographic-structure s-part))
45                (ideographic-structure-member part (cdr ret))))
46           ((setq ret (get-char-attribute s-part 'ideographic-structure))
47            (ideographic-structure-member part ret)))))
48
49 (defun ideographic-structure-member (part structure)
50   (or (progn
51         (setq structure (cdr structure))
52         (ideographic-structure-member-compare-parts part (car structure)))
53       (progn
54         (setq structure (cdr structure))
55         (ideographic-structure-member-compare-parts part (car structure)))
56       (progn
57         (setq structure (cdr structure))
58         (and (car structure)
59              (ideographic-structure-member-compare-parts
60               part (car structure))))))
61
62 ;;;###autoload
63 (defun ideographic-structure-search-chars (parts)
64   "Search Ideographs by PARTS."
65   (interactive "sParts : ")
66   (with-current-buffer (get-buffer-create " *ids-chars*")
67     (setq buffer-read-only nil)
68     (erase-buffer)
69     (map-char-attribute
70      (lambda (c v)
71        (when (every
72               (lambda (p)
73                 ;; (member* p v :test #'char-ref=)
74                 (ideographic-structure-member p v))
75               parts)
76          (insert (format "%c\t%s\n"
77                          c
78                          (or (ideographic-structure-to-ids v)
79                              v))))
80        nil)
81      'ideographic-structure)
82     (goto-char (point-min)))
83   (view-buffer " *ids-chars*"))
84
85
86 ;;; @ End.
87 ;;;
88
89 (provide 'ids-find)
90
91 ;;; ids-find.el ends here