Mercurial > emacs
annotate lisp/international/skkdic-utl.el @ 18156:f7296dc03177
(describe-chinese-environment-map):
Renamed from describe-chinese-support-map.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 07 Jun 1997 05:54:32 +0000 |
parents | a3ca5e15c82a |
children | 8b4a66c66dd6 |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1 ;;; skkdic-utl.el --- Utility functions for handling SKK dictionary |
17052 | 2 |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
5 | |
6 ;; Keywords: mule, multilingual, Japanese, SKK | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
17052 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; SKK is a free Japanese input method running on Mule created by | |
28 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. A dictionary of | |
29 ;; SKK can be converted by `skkdic-convert' (skkdic-conv.el) to a file | |
30 ;; "skkdic.el" in which the dictionary entries are defined in the | |
31 ;; format which can be handled by the following functions. | |
32 | |
33 ;;; Code: | |
34 | |
35 (defvar skkdic-okuri-ari nil | |
36 "OKURI-ARI entries of SKK dictionary.") | |
37 (defvar skkdic-postfix nil | |
38 "POSTFIX entries of SKK dictionary.") | |
39 (defvar skkdic-prefix nil | |
40 "PREFIX entries of SKK dictionary.") | |
41 (defvar skkdic-okuri-nasi nil | |
42 "OKURI-NASI entries of SKK dictionary.") | |
43 | |
44 ;; Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry. | |
45 (defconst skkdic-okurigana-table | |
46 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u) | |
47 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o) | |
48 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k) | |
49 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g) | |
50 (?$B$5(B . ?s) (?$B$6(B . ?z) (?$B$7(B . ?s) (?$B$8(B . ?j) (?$B$9(B . ?s) | |
51 (?$B$:(B . ?z) (?$B$;(B . ?s) (?$B$<(B . ?z) (?$B$=(B . ?s) (?$B$>(B . ?z) | |
52 (?$B$?(B . ?t) (?$B$@(B . ?d) (?$B$A(B . ?t) (?$B$B(B . ?d) (?$B$C(B . ?t) | |
53 (?$B$D(B . ?t) (?$B$E(B . ?d) (?$B$F(B . ?t) (?$B$G(B . ?d) (?$B$H(B . ?t) (?$B$I(B . ?d) | |
54 (?$B$J(B . ?n) (?$B$K(B . ?n) (?$B$L(B . ?n) (?$B$M(B . ?n) (?$B$N(B . ?n) | |
55 (?$B$O(B . ?h) (?$B$P(B . ?b) (?$B$Q(B . ?p) (?$B$R(B . ?h) (?$B$S(B . ?b) | |
56 (?$B$T(B . ?p) (?$B$U(B . ?h) (?$B$V(B . ?b) (?$B$W(B . ?p) (?$B$X(B . ?h) | |
57 (?$B$Y(B . ?b) (?$B$Z(B . ?p) (?$B$[(B . ?h) (?$B$\(B . ?b) (?$B$](B . ?p) | |
58 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m) | |
59 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y) | |
60 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r) | |
61 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w) | |
62 (?$B$s(B . ?n) | |
63 )) | |
64 | |
65 (defconst skkdic-jbytes | |
66 (charset-bytes 'japanese-jisx0208)) | |
67 | |
68 (defun skkdic-merge-head-and-tail (heads tails postfix) | |
69 (let ((min-len (* skkdic-jbytes 2)) | |
70 l) | |
71 (while heads | |
72 (if (or (not postfix) | |
73 (>= (length (car heads)) min-len)) | |
74 (let ((tail tails)) | |
75 (while tail | |
76 (if (or postfix | |
77 (>= (length (car tail)) min-len)) | |
78 (setq l (cons (concat (car heads) (car tail)) l))) | |
79 (setq tail (cdr tail))))) | |
80 (setq heads (cdr heads))) | |
81 l)) | |
82 | |
83 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B))) | |
84 | |
85 (defun skkdic-lookup-key (seq len &optional postfix) | |
86 "Return a list of conversion string for sequence SEQ of length LEN. | |
87 | |
88 SEQ is a vector of Kana characters to be converted by SKK dictionary. | |
89 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ | |
90 are took into account. | |
91 | |
92 Postfixes are handled only if the optional argument POSTFIX is non-nil." | |
93 (or skkdic-okuri-nasi | |
94 (condition-case err | |
95 (load-library "skk/skkdic") | |
96 (error (ding) | |
97 (with-output-to-temp-buffer "*Help*" | |
98 (princ "The library `skkdic' can't be loaded. | |
99 | |
100 The most common case is that you have not yet installed the library | |
101 included in LEIM (Libraries of Emacs Input Method) which is | |
102 distributed separately from Emacs. | |
103 | |
104 LEIM is available from the same ftp directory as Emacs.")) | |
105 (signal (car err) (cdr err))))) | |
106 | |
107 (let ((vec (make-vector len 0)) | |
108 (i 0) | |
109 entry) | |
110 ;; At first, generate vector VEC from SEQ for looking up SKK | |
111 ;; alists. Nth element in VEC corresponds to Nth element in SEQ. | |
112 ;; The values are decided as follows. | |
113 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0, | |
114 ;; Else if SEQ[N] is a Hiragana character, VEC[N] is: | |
115 ;; ((The 2nd position code o SEQ[N]) - 32), | |
116 ;; ELse VEC[N] is 128. | |
117 (while (< i len) | |
118 (let ((ch (aref seq i)) | |
119 elts) | |
120 (if (= ch ?$B!<(B) | |
121 (aset vec i 0) | |
122 (setq elts (split-char ch)) | |
123 (if (and (eq (car elts) 'japanese-jisx0208) | |
124 (= (nth 1 elts) skkdic-jisx0208-hiragana-block)) | |
125 (aset vec i (- (nth 2 elts) 32)) | |
126 (aset vec i 128)))) | |
127 (setq i (1+ i))) | |
128 | |
129 ;; Search OKURI-NASI entries. | |
130 (setq entry (lookup-nested-alist vec skkdic-okuri-nasi len 0 t)) | |
131 (if (consp (car entry)) | |
132 (setq entry (copy-sequence (car entry))) | |
133 (setq entry nil)) | |
134 | |
135 (if postfix | |
136 ;; Search OKURI-NASI entries with postfixes. | |
137 (let ((break (max (- len (car skkdic-postfix)) 1)) | |
138 entry-head entry-postfix entry2) | |
139 (while (< break len) | |
140 (if (and (setq entry-head | |
141 (lookup-nested-alist vec skkdic-okuri-nasi | |
142 break 0 t)) | |
143 (consp (car entry-head)) | |
144 (setq entry-postfix | |
145 (lookup-nested-alist vec skkdic-postfix | |
146 len break t)) | |
147 (consp (car entry-postfix)) | |
148 (setq entry2 (skkdic-merge-head-and-tail | |
149 (car entry-head) (car entry-postfix) t))) | |
150 (if entry | |
151 (nconc entry entry2) | |
152 (setq entry entry2))) | |
153 (setq break (1+ break))))) | |
154 | |
155 ;; Search OKURI-NASI entries with prefixes. | |
156 (let ((break (min (car skkdic-prefix) (- len 2))) | |
157 entry-prefix entry-tail entry2) | |
158 (while (> break 0) | |
159 (if (and (setq entry-prefix | |
160 (lookup-nested-alist vec skkdic-prefix break 0 t)) | |
161 (consp (car entry-prefix)) | |
162 (setq entry-tail | |
163 (lookup-nested-alist vec skkdic-okuri-nasi len break t)) | |
164 (consp (car entry-tail)) | |
165 (setq entry2 (skkdic-merge-head-and-tail | |
166 (car entry-prefix) (car entry-tail) nil))) | |
167 (if entry | |
168 (nconc entry entry2) | |
169 (setq entry entry2))) | |
170 (setq break (1- break)))) | |
171 | |
172 ;; Search OKURI-ARI entries. | |
173 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table)) | |
174 orig-element entry2) | |
175 (if okurigana | |
176 (progn | |
177 (setq orig-element (aref vec (1- len))) | |
178 (aset vec (1- len) (- (cdr okurigana))) | |
179 (if (and (setq entry2 (lookup-nested-alist vec skkdic-okuri-ari | |
180 len 0 t)) | |
181 (consp (car entry2))) | |
182 (progn | |
183 (setq entry2 (copy-sequence (car entry2))) | |
184 (let ((l entry2) | |
185 (okuri (char-to-string (aref seq (1- len))))) | |
186 (while l | |
187 (setcar l (concat (car l) okuri)) | |
188 (setq l (cdr l))) | |
189 (if entry | |
190 (nconc entry entry2) | |
191 (setq entry entry2))))) | |
192 (aset vec (1- len) orig-element)))) | |
193 | |
194 entry)) | |
195 | |
196 ;; | |
197 (provide 'skkdic-utl) | |
198 | |
199 ;; skkdic-utl.el ends here |