New file.
[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-member-compare-parts (part s-part)
28   (let (ret)
29     (cond ((char-ref= part s-part
30                       (lambda (c1 c2)
31                         (or (eq c1 c2)
32                             (and c1 c2
33                                  (eq (char-ucs c1)(char-ucs c2)))))))
34           ((listp s-part)
35            (if (setq ret (assq 'ideographic-structure s-part))
36                (ideographic-structure-member part (cdr ret))))
37           ((setq ret (get-char-attribute s-part 'ideographic-structure))
38            (ideographic-structure-member part ret)))))
39
40 (defun ideographic-structure-member (part structure)
41   (or (progn
42         (setq structure (cdr structure))
43         (ideographic-structure-member-compare-parts part (car structure)))
44       (progn
45         (setq structure (cdr structure))
46         (ideographic-structure-member-compare-parts part (car structure)))
47       (progn
48         (setq structure (cdr structure))
49         (and (car structure)
50              (ideographic-structure-member-compare-parts
51               part (car structure))))))
52
53 ;;;###autoload
54 (defun ideographic-structure-search-chars (parts)
55   "Search Ideographs by PARTS."
56   (interactive "sParts : ")
57   (with-current-buffer (get-buffer-create " *ids-chars*")
58     (setq buffer-read-only nil)
59     (erase-buffer)
60     (map-char-attribute
61      (lambda (c v)
62        (when (every
63               (lambda (p)
64                 ;; (member* p v :test #'char-ref=)
65                 (ideographic-structure-member p v))
66               parts)
67          (insert (format "%c\t%s\n"
68                          c
69                          (or (ideographic-structure-to-ids v)
70                              v))))
71        nil)
72      'ideographic-structure)
73     (goto-char (point-min)))
74   (view-buffer " *ids-chars*"))
75
76
77 ;;; @ End.
78 ;;;
79
80 (provide 'ids-find)
81
82 ;;; ids-find.el ends here