(ids-read-buffer): Add setting for CDP-HHHH and HZKdd-HHHH.
[chise/ids.git] / ids-read.el
1 ;;; ids-read.el --- Reader for IDS-* files
2
3 ;; Copyright (C) 2002,2003 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: IDS, IDC, Ideographs, UCS, Unicode
7
8 ;; This file is a part of IDS.
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 (require 'ids)
28
29 ;;;###autoload
30 (defun ids-read-buffer (buffer &optional simplify soft)
31   (interactive "bBuffer = \nP")
32   (save-excursion
33     (set-buffer buffer)
34     (goto-char (point-min))
35     (let (line chs ids code char structure)
36       (while (not (eobp))
37         (unless (looking-at ";")
38           (setq line
39                 (split-string
40                  (buffer-substring (point-at-bol)(point-at-eol))
41                  "\t"))
42           (setq chs (car line)
43                 ids (nth 2 line))
44           (setq char
45                 (cond
46                  ((string-match "U[-+]\\([0-9A-F]+\\)" chs)
47                   (decode-char 'ucs
48                                (string-to-int (match-string 1 chs) 16)))
49                  ((string-match "J90-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)"
50                                 chs)
51                   (decode-char 'japanese-jisx0208-1990
52                                (string-to-int (match-string 1 chs) 16)))
53                  ((string-match "CDP-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)"
54                                 chs)
55                   (decode-char '=big5-cdp
56                                (string-to-int (match-string 1 chs) 16)))
57                  ((string-match
58                    "HZK\\([0-9][0-9]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\)"
59                    chs)
60                   (decode-char (intern
61                                 (format "=hanziku-%d"
62                                         (string-to-int (match-string 1))))
63                                (string-to-int (match-string 2 chs) 16)))
64                  ((string-match "M-\\([0-9]+\\)'" chs)
65                   (setq code (string-to-int (match-string 1 chs)))
66                   (map-char-attribute
67                    (lambda (key val)
68                      (if (and (eq (car val) code)
69                               (eq (nth 1 val) 1)
70                               (null (nthcdr 2 val)))
71                          key))
72                    'morohashi-daikanwa))
73                  ((string-match "M-\\([0-9]+\\)\"" chs)
74                   (setq code (string-to-int (match-string 1 chs)))
75                   (map-char-attribute
76                    (lambda (key val)
77                      (if (and (eq (car val) code)
78                               (eq (nth 1 val) 2)
79                               (null (nthcdr 2 val)))
80                          key))
81                    'morohashi-daikanwa))
82                  ((string-match "M-\\([0-9]+\\)" chs)
83                   (decode-char 'ideograph-daikanwa
84                                (string-to-int (match-string 1 chs))))
85                  ((string-match "MH-\\([0-9]+\\)" chs)
86                   (setq code (string-to-int (match-string 1 chs)))
87                   (map-char-attribute
88                    (lambda (key val)
89                      (if (and (eq (car val) 'ho)
90                               (eq (nth 1 val) code)
91                               (null (nthcdr 2 val)))
92                          key))
93                    'morohashi-daikanwa))
94                  ((string-match "CB\\([0-9]+\\)" chs)
95                   (decode-char 'ideograph-cbeta
96                                (string-to-int (match-string 1 chs))))
97                  ))
98           (when (and char
99                      (or (not soft)
100                          (null
101                           (get-char-attribute char 'ideographic-structure)))
102                      (>= (length ids) 3)
103                      (not (string-match "\\?" ids))
104                      (consp (setq structure (ids-parse-string ids simplify))))
105             (put-char-attribute char
106                                 'ideographic-structure
107                                 (cdr (car structure))))
108           )
109         (forward-line)
110         ))))
111
112 ;;;###autoload
113 (defun ids-read-file (file &optional simplify soft)
114   (interactive "fIDS file = \nP")
115   (with-temp-buffer
116     (insert-file-contents file)
117     (ids-read-buffer (current-buffer) simplify soft)))
118
119
120 ;;; @ End.
121 ;;;
122
123 (provide 'ids-read)
124
125 ;;; ids-read.el ends here