Mercurial > emacs
annotate lisp/international/ja-dic-cnv.el @ 106320:4c6acb151625
(describe-char-unidata-list): Use lowercase name
for "Unicode name" like in other tags.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sun, 29 Nov 2009 23:55:42 +0000 |
parents | 7f0c795dd2e7 |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36681
diff
changeset
|
1 ;;; ja-dic-cnv.el --- convert a Japanese dictionary (SKK-JISYO.L) to Emacs Lisp |
31164 | 2 |
74605
6ee41fdd69ff
Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents:
74544
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 |
62274 | 5 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
6 ;; Registration Number H14PRO021 | |
31164 | 7 |
106255
7f0c795dd2e7
* international/isearch-x.el, international/ja-dic-cnv.el,
Kevin Ryde <user42@zip.com.au>
parents:
105813
diff
changeset
|
8 ;; Keywords: i18n, mule, multilingual, Japanese |
31164 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
94664
889bc336b89b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
31164 | 13 ;; it under the terms of the GNU General Public License as published by |
94664
889bc336b89b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
889bc336b89b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
31164 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94664
889bc336b89b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
31164 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; SKK is a Japanese input method running on Mule created by Masahiko | |
28 ;; Sato <masahiko@sato.riec.tohoku.ac.jp>. Here we provide utilities | |
29 ;; to handle a dictionary distributed with SKK so that a different | |
30 ;; input method (e.g. quail-japanese) can utilize the dictionary. | |
31 | |
32 ;; The format of SKK dictionary is quite simple. Each line has the | |
33 ;; form "KANASTRING /CONV1/CONV2/.../" which means KANASTRING ($B2>L>J8(B | |
34 ;; $B;zNs(B) can be converted to one of CONVi. CONVi is a Kanji ($B4A;z(B) | |
35 ;; and Kana ($B2>L>(B) mixed string. | |
36 ;; | |
37 ;; KANASTRING may have a trailing ASCII letter for Okurigana ($BAw$j2>L>(B) | |
38 ;; information. For instance, the trailing letter `k' means that one | |
39 ;; of the following Okurigana is allowed: $B$+$-$/$1$3(B. So, in that | |
40 ;; case, the string "KANASTRING$B$/(B" can be converted to one of "CONV1$B$/(B", | |
41 ;; CONV2$B$/(B, ... | |
42 | |
43 ;;; Code: | |
44 | |
45 ;; Name of a file to generate from SKK dictionary. | |
46 (defvar ja-dic-filename "ja-dic.el") | |
47 | |
48 ;; To make a generated ja-dic.el smaller. | |
88406
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
49 (define-coding-system 'iso-2022-7bit-short |
31164 | 50 "Like `iso-2022-7bit' but no ASCII designation before SPC." |
88406
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
51 :coding-type 'iso-2022 |
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
52 :mnemonic ?J |
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
53 :charset-list 'iso-2022 |
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
54 :designation [(ascii t) nil nil nil] |
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
55 :flags '(short 7-bit designation)) |
31164 | 56 |
57 (defun skkdic-convert-okuri-ari (skkbuf buf) | |
58 (message "Processing OKURI-ARI entries ...") | |
59 (goto-char (point-min)) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
60 (with-current-buffer buf |
31164 | 61 (insert ";; Setting okuri-ari entries.\n" |
62 "(skkdic-set-okuri-ari\n")) | |
63 (while (not (eobp)) | |
64 (let ((from (point)) | |
65 to) | |
66 (end-of-line) | |
67 (setq to (point)) | |
68 | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
69 (with-current-buffer buf |
31164 | 70 (insert-buffer-substring skkbuf from to) |
71 (beginning-of-line) | |
72 (insert "\"") | |
73 (search-forward " ") | |
74 (delete-char 1) ; delete the first '/' | |
75 (let ((p (point))) | |
76 (end-of-line) | |
77 (delete-char -1) ; delete the last '/' | |
78 (subst-char-in-region p (point) ?/ ? 'noundo)) | |
79 (insert "\"\n")) | |
80 | |
81 (forward-line 1))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
82 (with-current-buffer buf |
31164 | 83 (insert ")\n\n"))) |
84 | |
85 (defconst skkdic-postfix-list '(skkdic-postfix-list)) | |
86 | |
87 (defconst skkdic-postfix-data | |
88 '(("$B$$$-(B" "$B9T(B") | |
89 ("$B$,$+$j(B" "$B78(B") | |
90 ("$B$,$/(B" "$B3X(B") | |
91 ("$B$,$o(B" "$B@n(B") | |
92 ("$B$7$c(B" "$B<R(B") | |
93 ("$B$7$e$&(B" "$B=8(B") | |
94 ("$B$7$g$&(B" "$B>^(B" "$B>k(B") | |
95 ("$B$8$g$&(B" "$B>k(B") | |
96 ("$B$;$s(B" "$B@~(B") | |
97 ("$B$@$1(B" "$B3Y(B") | |
98 ("$B$A$c$/(B" "$BCe(B") | |
99 ("$B$F$s(B" "$BE9(B") | |
100 ("$B$H$&$2(B" "$BF=(B") | |
101 ("$B$I$*$j(B" "$BDL$j(B") | |
102 ("$B$d$^(B" "$B;3(B") | |
103 ("$B$P$7(B" "$B66(B") | |
104 ("$B$O$D(B" "$BH/(B") | |
105 ("$B$b$/(B" "$BL\(B") | |
106 ("$B$f$-(B" "$B9T(B"))) | |
107 | |
108 (defun skkdic-convert-postfix (skkbuf buf) | |
109 (message "Processing POSTFIX entries ...") | |
110 (goto-char (point-min)) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
111 (with-current-buffer buf |
31164 | 112 (insert ";; Setting postfix entries.\n" |
113 "(skkdic-set-postfix\n")) | |
114 | |
115 ;; Initialize SKKDIC-POSTFIX-LIST by predefined data | |
116 ;; SKKDIC-POSTFIX-DATA. | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
117 (with-current-buffer buf |
31164 | 118 (let ((l skkdic-postfix-data) |
119 kana candidates entry) | |
120 (while l | |
121 (setq kana (car (car l)) candidates (cdr (car l))) | |
122 (insert "\"" kana) | |
123 (while candidates | |
124 (insert " " (car candidates)) | |
125 (setq entry (lookup-nested-alist (car candidates) | |
126 skkdic-postfix-list nil nil t)) | |
127 (if (consp (car entry)) | |
128 (setcar entry (cons kana (car entry))) | |
129 (set-nested-alist (car candidates) (list kana) | |
130 skkdic-postfix-list)) | |
131 (setq candidates (cdr candidates))) | |
132 (insert "\"\n") | |
133 (setq l (cdr l))))) | |
134 | |
135 ;; Search postfix entries. | |
136 (while (re-search-forward "^[#<>?]\\(\\(\\cH\\|$B!<(B\\)+\\) " nil t) | |
137 (let ((kana (match-string 1)) | |
138 str candidates) | |
139 (while (looking-at "/[#0-9 ]*\\([^/\n]*\\)/") | |
140 (setq str (match-string 1)) | |
141 (if (not (member str candidates)) | |
142 (setq candidates (cons str candidates))) | |
143 (goto-char (match-end 1))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
144 (with-current-buffer buf |
31164 | 145 (insert "\"" kana) |
146 (while candidates | |
147 (insert " " (car candidates)) | |
148 (let ((entry (lookup-nested-alist (car candidates) | |
149 skkdic-postfix-list nil nil t))) | |
150 (if (consp (car entry)) | |
151 (if (not (member kana (car entry))) | |
152 (setcar entry (cons kana (car entry)))) | |
153 (set-nested-alist (car candidates) (list kana) | |
154 skkdic-postfix-list))) | |
155 (setq candidates (cdr candidates))) | |
156 (insert "\"\n")))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
157 (with-current-buffer buf |
31164 | 158 (insert ")\n\n"))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46671
diff
changeset
|
159 |
31164 | 160 (defconst skkdic-prefix-list '(skkdic-prefix-list)) |
161 | |
162 (defun skkdic-convert-prefix (skkbuf buf) | |
163 (message "Processing PREFIX entries ...") | |
164 (goto-char (point-min)) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
165 (with-current-buffer buf |
31164 | 166 (insert ";; Setting prefix entries.\n" |
167 "(skkdic-set-prefix\n")) | |
168 (save-excursion | |
169 (while (re-search-forward "^\\(\\(\\cH\\|$B!<(B\\)+\\)[<>?] " nil t) | |
170 (let ((kana (match-string 1)) | |
171 str candidates) | |
172 (while (looking-at "/\\([^/\n]+\\)/") | |
173 (setq str (match-string 1)) | |
174 (if (not (member str candidates)) | |
175 (setq candidates (cons str candidates))) | |
176 (goto-char (match-end 1))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
177 (with-current-buffer buf |
31164 | 178 (insert "\"" kana) |
179 (while candidates | |
180 (insert " " (car candidates)) | |
181 (set-nested-alist (car candidates) kana skkdic-prefix-list) | |
182 (setq candidates (cdr candidates))) | |
183 (insert "\"\n"))))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
184 (with-current-buffer buf |
31164 | 185 (insert ")\n\n"))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46671
diff
changeset
|
186 |
31164 | 187 ;; FROM and TO point the head and tail of "/J../J../.../". |
188 (defun skkdic-get-candidate-list (from to) | |
189 (let (candidates) | |
190 (goto-char from) | |
34626
6e98a6e86b7f
(skkdic-get-candidate-list): Fix the regexp to search for candidates.
Kenichi Handa <handa@m17n.org>
parents:
34532
diff
changeset
|
191 (while (re-search-forward "/[^/ \n]+" to t) |
31164 | 192 (setq candidates (cons (buffer-substring (1+ (match-beginning 0)) |
193 (match-end 0)) | |
194 candidates))) | |
195 candidates)) | |
196 | |
197 ;; Return entry for STR from nested alist ALIST. | |
198 (defsubst skkdic-get-entry (str alist) | |
199 (car (lookup-nested-alist str alist nil nil t))) | |
200 | |
201 | |
202 (defconst skkdic-word-list '(skkdic-word-list)) | |
203 | |
204 ;; Return t if substring of STR (between FROM and TO) can be broken up | |
205 ;; to chunks all of which can be derived from another entry in SKK | |
206 ;; dictionary. SKKBUF is the buffer where the original SKK dictionary | |
78484
edc666d07b2c
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78310
diff
changeset
|
207 ;; is visited, KANA is the current entry for STR. FIRST is t only if |
edc666d07b2c
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78310
diff
changeset
|
208 ;; this is called at top level. |
31164 | 209 |
210 (defun skkdic-breakup-string (skkbuf kana str from to &optional first) | |
211 (let ((len (- to from))) | |
212 (or (and (>= len 2) | |
213 (let ((min-idx (+ from 2)) | |
214 (idx (if first (1- to ) to)) | |
215 (found nil)) | |
216 (while (and (not found) (>= idx min-idx)) | |
217 (let ((kana2-list (skkdic-get-entry | |
218 (substring str from idx) | |
219 skkdic-word-list))) | |
220 (if (or (and (consp kana2-list) | |
221 (let ((kana-len (length kana)) | |
222 kana2) | |
223 (catch 'skkdic-tag | |
224 (while kana2-list | |
225 (setq kana2 (car kana2-list)) | |
226 (if (string-match kana2 kana) | |
227 (throw 'skkdic-tag t)) | |
228 (setq kana2-list (cdr kana2-list))))) | |
229 (or (= idx to) | |
230 (skkdic-breakup-string skkbuf kana str | |
231 idx to))) | |
232 (and (stringp kana2-list) | |
233 (string-match kana2-list kana))) | |
234 (setq found t) | |
235 (setq idx (1- idx))))) | |
236 found)) | |
237 (and first | |
238 (> len 2) | |
239 (let ((kana2 (skkdic-get-entry | |
240 (substring str from (1+ from)) | |
241 skkdic-prefix-list))) | |
242 (and (stringp kana2) | |
243 (eq (string-match kana2 kana) 0))) | |
244 (skkdic-breakup-string skkbuf kana str (1+ from) to)) | |
245 (and (not first) | |
246 (>= len 1) | |
247 (let ((kana2-list (skkdic-get-entry | |
248 (substring str from to) | |
249 skkdic-postfix-list))) | |
250 (and (consp kana2-list) | |
251 (let (kana2) | |
252 (catch 'skkdic-tag | |
253 (while kana2-list | |
254 (setq kana2 (car kana2-list)) | |
255 (if (string= kana2 | |
256 (substring kana (- (length kana2)))) | |
257 (throw 'skkdic-tag t)) | |
258 (setq kana2-list (cdr kana2-list))))))))))) | |
259 | |
260 ;; Return list of candidates which excludes some from CANDIDATES. | |
261 ;; Excluded candidates can be derived from another entry. | |
262 | |
263 (defun skkdic-reduced-candidates (skkbuf kana candidates) | |
264 (let (elt l) | |
265 (while candidates | |
266 (setq elt (car candidates)) | |
267 (if (or (= (length elt) 1) | |
268 (and (string-match "^\\cj" elt) | |
269 (not (skkdic-breakup-string skkbuf kana elt 0 (length elt) | |
270 'first)))) | |
271 (setq l (cons elt l))) | |
272 (setq candidates (cdr candidates))) | |
273 (nreverse l))) | |
274 | |
51055
b3d9bd5b31b8
(skkdic-okuri-nasi-entries, skkdic-okuri-nasi-entries-count):
John Paul Wallington <jpw@pobox.com>
parents:
49598
diff
changeset
|
275 (defvar skkdic-okuri-nasi-entries (list nil)) |
b3d9bd5b31b8
(skkdic-okuri-nasi-entries, skkdic-okuri-nasi-entries-count):
John Paul Wallington <jpw@pobox.com>
parents:
49598
diff
changeset
|
276 (defvar skkdic-okuri-nasi-entries-count 0) |
31164 | 277 |
278 (defun skkdic-collect-okuri-nasi () | |
279 (message "Collecting OKURI-NASI entries ...") | |
280 (save-excursion | |
281 (let ((prev-ratio 0) | |
282 ratio) | |
283 (while (re-search-forward "^\\(\\(\\cH\\|$B!<(B\\)+\\) \\(/\\cj.*\\)/$" | |
284 nil t) | |
285 (let ((kana (match-string 1)) | |
286 (candidates (skkdic-get-candidate-list (match-beginning 3) | |
287 (match-end 3)))) | |
288 (setq skkdic-okuri-nasi-entries | |
289 (cons (cons kana candidates) skkdic-okuri-nasi-entries) | |
290 skkdic-okuri-nasi-entries-count | |
291 (1+ skkdic-okuri-nasi-entries-count)) | |
292 (setq ratio (floor (/ (* (point) 100.0) (point-max)))) | |
293 (if (/= ratio prev-ratio) | |
294 (progn | |
295 (message "collected %2d%% %s ..." ratio kana) | |
296 (setq prev-ratio ratio))) | |
297 (while candidates | |
298 (let ((entry (lookup-nested-alist (car candidates) | |
299 skkdic-word-list nil nil t))) | |
300 (if (consp (car entry)) | |
301 (setcar entry (cons kana (car entry))) | |
302 (set-nested-alist (car candidates) (list kana) | |
303 skkdic-word-list))) | |
304 (setq candidates (cdr candidates)))))))) | |
305 | |
306 (defun skkdic-convert-okuri-nasi (skkbuf buf) | |
307 (message "Processing OKURI-NASI entries ...") | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
308 (with-current-buffer buf |
31164 | 309 (insert ";; Setting okuri-nasi entries.\n" |
310 "(skkdic-set-okuri-nasi\n") | |
311 (let ((l (nreverse skkdic-okuri-nasi-entries)) | |
312 (count 0) | |
313 (prev-ratio 0) | |
314 ratio) | |
315 (while l | |
316 (let ((kana (car (car l))) | |
317 (candidates (cdr (car l)))) | |
318 (setq ratio (/ (* count 1000) skkdic-okuri-nasi-entries-count) | |
319 count (1+ count)) | |
320 (if (/= prev-ratio (/ ratio 10)) | |
321 (progn | |
322 (message "processed %2d%% %s ..." (/ ratio 10) kana) | |
323 (setq prev-ratio (/ ratio 10)))) | |
324 (if (setq candidates | |
325 (skkdic-reduced-candidates skkbuf kana candidates)) | |
326 (progn | |
327 (insert "\"" kana) | |
328 (while candidates | |
329 (insert " " (car candidates)) | |
330 (setq candidates (cdr candidates))) | |
331 (insert "\"\n")))) | |
332 (setq l (cdr l)))) | |
333 (insert ")\n\n"))) | |
334 | |
335 (defun skkdic-convert (filename &optional dirname) | |
73796
3da9d5d6d1dc
(skkdic-convert): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
336 "Generate Emacs Lisp file form Japanese dictionary file FILENAME. |
31164 | 337 The format of the dictionary file should be the same as SKK dictionaries. |
338 Optional argument DIRNAME if specified is the directory name under which | |
339 the generated Emacs Lisp is saved. | |
340 The name of generated file is specified by the variable `ja-dic-filename'." | |
341 (interactive "FSKK dictionary file: ") | |
342 (message "Reading file \"%s\" ..." filename) | |
343 (let* ((coding-system-for-read 'euc-japan) | |
344 (skkbuf(find-file-noselect (expand-file-name filename))) | |
345 (buf (get-buffer-create "*skkdic-work*"))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
346 ;; Setup and generate the header part of working buffer. |
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
347 (with-current-buffer buf |
31164 | 348 (erase-buffer) |
349 (buffer-disable-undo) | |
46671
1c5996975536
(skkdic-convert): Add coding cookie.
Dave Love <fx@gnu.org>
parents:
38479
diff
changeset
|
350 (insert ";;; ja-dic.el --- dictionary for Japanese input method" |
75497 | 351 " -*-coding: iso-2022-jp; byte-compile-disable-print-circle:t; -*-\n" |
31164 | 352 ";;\tGenerated by the command `skkdic-convert'\n" |
353 ";;\tDate: " (current-time-string) "\n" | |
354 ";;\tOriginal SKK dictionary file: " | |
75395
05d001ce4826
(skkdic-convert): Insert a relative
Kenichi Handa <handa@m17n.org>
parents:
75364
diff
changeset
|
355 (file-relative-name (expand-file-name filename) dirname) |
31164 | 356 "\n\n" |
38479
758a6e658e72
Doc and coding conventions fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
38414
diff
changeset
|
357 ";; This file is part of GNU Emacs.\n\n" |
758a6e658e72
Doc and coding conventions fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
38414
diff
changeset
|
358 ";;; Commentary:\n\n" |
31164 | 359 ";; Do byte-compile this file again after any modification.\n\n" |
360 ";;; Start of the header of the original SKK dictionary.\n\n") | |
361 (set-buffer skkbuf) | |
362 (widen) | |
363 (goto-char 1) | |
364 (let (pos) | |
365 (search-forward ";; okuri-ari") | |
366 (forward-line 1) | |
367 (setq pos (point)) | |
368 (set-buffer buf) | |
369 (insert-buffer-substring skkbuf 1 pos)) | |
370 (insert "\n" | |
31196
28b5eff78c33
(skkdic-convert): Insert (require 'ja-dic-cnv), not (require
Kenichi Handa <handa@m17n.org>
parents:
31164
diff
changeset
|
371 ";;; Code:\n\n(eval-when-compile (require 'ja-dic-cnv))\n\n") |
31164 | 372 |
373 ;; Generate the body part of working buffer. | |
374 (set-buffer skkbuf) | |
375 (let ((from (point)) | |
376 to) | |
377 ;; Convert okuri-ari entries. | |
378 (search-forward ";; okuri-nasi") | |
379 (beginning-of-line) | |
380 (setq to (point)) | |
381 (narrow-to-region from to) | |
382 (skkdic-convert-okuri-ari skkbuf buf) | |
383 (widen) | |
384 | |
385 ;; Convert okuri-nasi postfix entries. | |
386 (goto-char to) | |
387 (forward-line 1) | |
388 (setq from (point)) | |
389 (re-search-forward "^\\cH") | |
390 (setq to (match-beginning 0)) | |
391 (narrow-to-region from to) | |
392 (skkdic-convert-postfix skkbuf buf) | |
393 (widen) | |
394 | |
395 ;; Convert okuri-nasi prefix entries. | |
396 (goto-char to) | |
397 (skkdic-convert-prefix skkbuf buf) | |
398 | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46671
diff
changeset
|
399 ;; |
31164 | 400 (skkdic-collect-okuri-nasi) |
401 | |
402 ;; Convert okuri-nasi general entries. | |
403 (skkdic-convert-okuri-nasi skkbuf buf) | |
404 | |
405 ;; Postfix | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
406 (with-current-buffer buf |
31164 | 407 (goto-char (point-max)) |
38479
758a6e658e72
Doc and coding conventions fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
38414
diff
changeset
|
408 (insert ";;\n(provide 'ja-dic)\n\n;;; ja-dic.el ends here\n"))) |
31164 | 409 |
410 ;; Save the working buffer. | |
411 (set-buffer buf) | |
412 (set-visited-file-name (expand-file-name ja-dic-filename dirname) t) | |
413 (set-buffer-file-coding-system 'iso-2022-7bit-short) | |
414 (save-buffer 0)) | |
415 (kill-buffer skkbuf) | |
416 (switch-to-buffer buf))) | |
417 | |
418 (defun batch-skkdic-convert () | |
419 "Run `skkdic-convert' on the files remaining on the command line. | |
420 Use this from the command line, with `-batch'; | |
421 it won't work in an interactive Emacs. | |
422 For example, invoke: | |
423 % emacs -batch -l ja-dic-cnv -f batch-skkdic-convert SKK-JISYO.L | |
424 to generate \"ja-dic.el\" from SKK dictionary file \"SKK-JISYO.L\". | |
425 To get complete usage, invoke: | |
426 % emacs -batch -l ja-dic-cnv -f batch-skkdic-convert -h" | |
427 (defvar command-line-args-left) ; Avoid compiler warning. | |
428 (if (not noninteractive) | |
429 (error "`batch-skkdic-convert' should be used only with -batch")) | |
430 (if (string= (car command-line-args-left) "-h") | |
431 (progn | |
432 (message "To convert SKK-JISYO.L into skkdic.el:") | |
433 (message " %% emacs -batch -l ja-dic-cnv -f batch-skkdic-convert SKK-JISYO.L") | |
434 (message "To convert SKK-JISYO.L into DIR/ja-dic.el:") | |
435 (message " %% emacs -batch -l ja-dic-cnv -f batch-skkdic-convert -dir DIR SKK-JISYO.L")) | |
436 (let (targetdir filename) | |
437 (if (string= (car command-line-args-left) "-dir") | |
438 (progn | |
439 (setq command-line-args-left (cdr command-line-args-left)) | |
440 (setq targetdir (expand-file-name (car command-line-args-left))) | |
441 (setq command-line-args-left (cdr command-line-args-left)))) | |
442 (setq filename (expand-file-name (car command-line-args-left))) | |
443 (message "Converting %s to %s ..." filename ja-dic-filename) | |
444 (message "It takes around 10 minutes even on Sun SS20.") | |
445 (skkdic-convert filename targetdir) | |
446 (message "Do byte-compile the created file by:") | |
447 (message " %% emacs -batch -f batch-byte-compile %s" ja-dic-filename) | |
448 )) | |
449 (kill-emacs 0)) | |
450 | |
451 | |
452 ;; The following macros are expanded at byte-compiling time so that | |
453 ;; compiled code can be loaded quickly. | |
454 | |
455 (defun skkdic-get-kana-compact-codes (kana) | |
456 (let* ((len (length kana)) | |
457 (vec (make-vector len 0)) | |
458 (i 0) | |
459 ch) | |
460 (while (< i len) | |
461 (setq ch (aref kana i)) | |
462 (aset vec i | |
463 (if (< ch 128) ; CH is an ASCII letter for OKURIGANA, | |
464 (- ch) ; represented by a negative code. | |
465 (if (= ch ?$B!<(B) ; `$B!<(B' is represented by 0. | |
466 0 | |
88406
934ee50a6eb3
(skkdic-get-kana-compact-codes): Call encode-char instead of
Kenichi Handa <handa@m17n.org>
parents:
38479
diff
changeset
|
467 (- (logand (encode-char ch 'japanese-jisx0208) #xFF) 32)))) |
31164 | 468 (setq i (1+ i))) |
469 vec)) | |
470 | |
471 (defun skkdic-extract-conversion-data (entry) | |
472 (string-match "^\\cj+[a-z]* " entry) | |
473 (let ((kana (substring entry (match-beginning 0) (1- (match-end 0)))) | |
474 (i (match-end 0)) | |
475 candidates) | |
476 (while (string-match "[^ ]+" entry i) | |
477 (setq candidates (cons (match-string 0 entry) candidates)) | |
478 (setq i (match-end 0))) | |
479 (cons (skkdic-get-kana-compact-codes kana) candidates))) | |
480 | |
481 (defmacro skkdic-set-okuri-ari (&rest entries) | |
482 `(defconst skkdic-okuri-ari | |
483 ',(let ((l entries) | |
484 (map '(skkdic-okuri-ari)) | |
485 entry) | |
486 (while l | |
487 (setq entry (skkdic-extract-conversion-data (car l))) | |
488 (set-nested-alist (car entry) (cdr entry) map) | |
489 (setq l (cdr l))) | |
490 map))) | |
491 | |
492 (defmacro skkdic-set-postfix (&rest entries) | |
493 `(defconst skkdic-postfix | |
494 ',(let ((l entries) | |
495 (map '(nil)) | |
496 (longest 1) | |
497 len entry) | |
498 (while l | |
499 (setq entry (skkdic-extract-conversion-data (car l))) | |
500 (setq len (length (car entry))) | |
501 (if (> len longest) | |
502 (setq longest len)) | |
503 (let ((entry2 (lookup-nested-alist (car entry) map nil nil t))) | |
504 (if (consp (car entry2)) | |
505 (let ((conversions (cdr entry))) | |
506 (while conversions | |
507 (if (not (member (car conversions) (car entry2))) | |
508 (setcar entry2 (cons (car conversions) (car entry2)))) | |
509 (setq conversions (cdr conversions)))) | |
510 (set-nested-alist (car entry) (cdr entry) map))) | |
511 (setq l (cdr l))) | |
512 (setcar map longest) | |
513 map))) | |
514 | |
515 (defmacro skkdic-set-prefix (&rest entries) | |
516 `(defconst skkdic-prefix | |
517 ',(let ((l entries) | |
518 (map '(nil)) | |
519 (longest 1) | |
520 len entry) | |
521 (while l | |
522 (setq entry (skkdic-extract-conversion-data (car l))) | |
523 (setq len (length (car entry))) | |
524 (if (> len longest) | |
525 (setq longest len)) | |
526 (let ((entry2 (lookup-nested-alist (car entry) map len nil t))) | |
527 (if (consp (car entry2)) | |
528 (let ((conversions (cdr entry))) | |
529 (while conversions | |
530 (if (not (member (car conversions) (car entry2))) | |
531 (setcar entry2 (cons (car conversions) (car entry2)))) | |
532 (setq conversions (cdr conversions)))) | |
533 (set-nested-alist (car entry) (cdr entry) map len))) | |
534 (setq l (cdr l))) | |
535 (setcar map longest) | |
536 map))) | |
537 | |
538 (defmacro skkdic-set-okuri-nasi (&rest entries) | |
539 `(defconst skkdic-okuri-nasi | |
540 ',(let ((l entries) | |
541 (map '(skdic-okuri-nasi)) | |
542 (count 0) | |
543 entry) | |
544 (while l | |
545 (setq count (1+ count)) | |
34532
dad96251e889
(skkdic-set-okuri-nasi): Show
Kenichi Handa <handa@m17n.org>
parents:
31196
diff
changeset
|
546 (if (= (% count 10000) 0) |
87170
e50a2e215441
* erc-stamp.el (erc-echo-timestamp):
David Kastrup <dak@gnu.org>
parents:
78484
diff
changeset
|
547 (message "%d entries" count)) |
31164 | 548 (setq entry (skkdic-extract-conversion-data (car l))) |
549 (set-nested-alist (car entry) (cdr entry) map) | |
550 (setq l (cdr l))) | |
551 map))) | |
552 | |
553 (provide 'ja-dic-cnv) | |
554 | |
36681
8f93fc285ff3
Add coding: tag in Loval Vairables: section.
Kenichi Handa <handa@m17n.org>
parents:
34626
diff
changeset
|
555 ;; Local Variables: |
8f93fc285ff3
Add coding: tag in Loval Vairables: section.
Kenichi Handa <handa@m17n.org>
parents:
34626
diff
changeset
|
556 ;; coding: iso-2022-7bit |
8f93fc285ff3
Add coding: tag in Loval Vairables: section.
Kenichi Handa <handa@m17n.org>
parents:
34626
diff
changeset
|
557 ;; End: |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36681
diff
changeset
|
558 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
559 ;; arch-tag: dec06fb0-8118-45b1-80d7-dc360b6fd3b2 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36681
diff
changeset
|
560 ;;; ja-dic-cnv.el ends here |