annotate lisp/international/ja-dic-cnv.el @ 32609:350e0378e6f9

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