2 (require 'cwiki-common)
4 (defun decode-url-string (string &optional coding-system)
5 (if (> (length string) 0)
8 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
9 (setq dest (concat dest
10 (substring string i (match-beginning 0))
13 (string-to-int (match-string 1 string) 16))))
16 (concat dest (substring string i))
19 (defconst www-ids-find-version "0.26")
21 (defvar www-ids-find-ideographic-products-file-name
22 (expand-file-name "ideographic-products"
27 chise-system-db-directory))))
29 (defvar www-ids-find-char-viewer-url
30 "/est/view/character/")
32 (defvar www-ids-find-chise-link-map-url-prefix
33 "http://fonts.jp/chise_linkmap/map.cgi?code=")
35 (defvar www-ids-find-tang-chars-file-name
36 "~tomo/projects/chise/ids/www/tang-chars.udd")
38 (defun www-ids-find-format-char (c &optional code-desc)
40 (format "<a href=\"%s%s\">%s</a>"
41 www-ids-find-char-viewer-url
42 (www-uri-encode-object c)
43 (www-format-encode-string (char-to-string c))))
44 ;; (let ((str (encode-coding-string (format "%c" c) 'utf-8-er))
49 ;; ((string-match "&CB\\([0-9]+\\);" str)
50 ;; (setq code (string-to-int (match-string 1 str)))
51 ;; (insert (format "<a href=\"%s"
52 ;; www-ids-find-char-viewer-url))
54 ;; (insert (format "\"><img alt=\"CB%05d\" src=\"/glyphs/cb-gaiji/%02d/CB%05d.gif\">\n"
55 ;; code (/ code 1000) code))
57 ;; (insert (format "CB%05d</a>" code)))
59 ;; ((string-match "&JC3-\\([0-9A-F]+\\);" str)
60 ;; (setq code (string-to-int (match-string 1 str) 16))
61 ;; (insert (format "<a href=\"%s"
62 ;; www-ids-find-char-viewer-url))
64 ;; (insert (format "\"><img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">\n"
67 ;; (insert (format "JC3-%04X</a>" code)))
69 ;; ((string-match "&J\\(78\\|83\\|90\\|SP\\)-\\([0-9A-F]+\\);" str)
70 ;; (setq plane (match-string 1 str)
71 ;; code (string-to-int (match-string 2 str) 16))
72 ;; (insert (format "<a href=\"%s"
73 ;; www-ids-find-char-viewer-url))
75 ;; (insert (format "\"><img alt=\"J%s-%04X\" src=\"/glyphs/JIS-%s/%02d-%02d.gif\">\n"
77 ;; (- (lsh code -8) 32)
78 ;; (- (logand code 255) 32)))
80 ;; (insert (format "J%s-%04X</a>" plane code)))
82 ;; ((string-match "&G\\([01]\\)-\\([0-9A-F]+\\);" str)
83 ;; (setq plane (string-to-int (match-string 1 str))
84 ;; code (string-to-int (match-string 2 str) 16))
85 ;; (insert (format "<a href=\"%s"
86 ;; www-ids-find-char-viewer-url))
88 ;; (insert (format "\"><img alt=\"G%d-%04X\" src=\"/glyphs/GB%d/%02d-%02d.gif\">\n"
90 ;; (- (lsh code -8) 32)
91 ;; (- (logand code 255) 32)))
93 ;; (insert (format "G%d-%04X</a>" plane code)))
95 ;; ((string-match "&C\\([1-7]\\)-\\([0-9A-F]+\\);" str)
96 ;; (setq plane (string-to-int (match-string 1 str))
97 ;; code (string-to-int (match-string 2 str) 16))
98 ;; (insert (format "<a href=\"%s"
99 ;; www-ids-find-char-viewer-url))
101 ;; (insert (format "\"><img alt=\"C%d-%04X\" src=\"/glyphs/CNS%d/%04X.gif\">\n"
102 ;; plane code plane code))
104 ;; (insert (format "C%d-%04X</a>" plane code)))
106 ;; ((string-match "&ZOB-\\([0-9]+\\);" str)
107 ;; (setq code (string-to-int (match-string 1 str)))
108 ;; (insert (format "<a href=\"%s"
109 ;; www-ids-find-char-viewer-url))
111 ;; (insert (format "\"><img alt=\"ZOB-%04d\" src=\"/glyphs/ZOB-1968/%04d.png\">\n"
114 ;; (insert (format "ZOB-%04d</a>" code)))
117 ;; (insert (format "<a href=\"%s"
118 ;; www-ids-find-char-viewer-url))
121 ;; (mapconcat (lambda (c)
122 ;; (if (<= (char-int c) #x7F)
123 ;; (char-to-string c)
124 ;; (format "%%%02X" c)))
130 ;; (goto-char (point-min))
131 ;; (while (search-forward "&" nil t)
132 ;; (replace-match "&" t 'literal))
133 ;; (buffer-string))))
136 (defun www-ids-find-format-line (c is)
138 (www-ids-find-format-char c 'code-desc)
140 (or (if (setq ucs (or (char-ucs c)
141 (encode-char c 'ucs)))
143 " <a href=\"http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=%X\">%s</a>"
145 (cond ((<= ucs #xFFFF)
146 (format "U+%04X" ucs))
148 (format "U-%08X" ucs))))
152 (format " <a href=\"%s%X\">(link map)</a>"
153 www-ids-find-chise-link-map-url-prefix ucs)))
156 (setq ids (ideographic-structure-to-ids is))
160 (www-ids-find-format-char (aref ids i))
165 www-ids-find-tang-chars-file-name)
166 (goto-char (point-min))
167 (re-search-forward (format "^%d$" ucs) nil t)))
169 (format " <a href=\"http://coe21.zinbun.kyoto-u.ac.jp/djvuchar?query=%s\">"
172 (format "%%%02X" (char-int c)))
173 (encode-coding-string (char-to-string c)
176 (princ (encode-coding-string "
\e$B"M
\e(B[
\e$BEbBeBsK\
\e(B]</a>" 'utf-8-jp-er)))
179 (defun www-ids-insert-chars-including-components (components
180 &optional ignored-chars)
181 (let ((products (ideographic-products-find components))
182 is as bs len ignore-children)
183 (setq len (length products))
185 (setq ignore-children t)
187 (encode-coding-string
188 "<p>
\e$B7k2L$,B?$9$.$k$?$a!":F5"E*8!:w$r>JN,$7$^$7$?!#
\e(B</p>"
192 (www-ids-find-format-char c))
196 ;; (setq ignore-children t)
201 (sort (copy-list products)
203 (< (char-int a)(char-int b))))
206 (sort (copy-list products)
208 (if (setq as (char-total-strokes a))
209 (if (setq bs (char-total-strokes b))
211 (< (char-int a)(char-int b))
214 (< (char-int a)(char-int b)))))
217 (sort (copy-list products)
219 (if (setq as (char-total-strokes a))
220 (if (setq bs (char-total-strokes b))
222 (ideograph-char< a b)
225 (ideograph-char< a b))))
227 (unless (memq c ignored-chars)
228 (setq is (char-feature c 'ideographic-structure))
230 (www-ids-find-format-line c is)
231 (unless ignore-children
234 (www-ids-insert-chars-including-components
236 (cons c ignored-chars)))
244 (defun www-batch-ids-find ()
245 (let ((components (car command-line-args-left))
246 (coded-charset-entity-reference-alist
248 '(=cns11643-1 "C1-" 4 X)
249 '(=cns11643-2 "C2-" 4 X)
250 '(=cns11643-3 "C3-" 4 X)
251 '(=cns11643-4 "C4-" 4 X)
252 '(=cns11643-5 "C5-" 4 X)
253 '(=cns11643-6 "C6-" 4 X)
254 '(=cns11643-7 "C7-" 4 X)
256 '(=gb12345 "G1-" 4 X)
257 '(=jis-x0208@1990 "J90-" 4 X)
258 '(=jis-x0212 "JSP-" 4 X)
260 '(=jef-china3 "JC3-" 4 X)
261 '(=jis-x0208@1978 "J78-" 4 X)
262 '(=jis-x0208@1983 "J83-" 4 X)
263 '(=daikanwa "M-" 5 d)
264 coded-charset-entity-reference-alist))
266 (setq command-line-args-left (cdr command-line-args-left))
268 ((stringp components)
269 (if (string-match "^components=" components)
270 (setq components (substring components (match-end 0))))
272 (if (> (length components) 0)
273 (decode-url-string components 'utf-8-er)
277 (setq components nil)
279 (princ "Content-Type: text/html; charset=UTF-8
281 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
282 \"http://www.w3.org/TR/html4/loose.dtd\">
285 <title>CHISE IDS Find</title>
291 (princ (encode-coding-string "CHISE IDS
\e$B4A;z8!:w
\e(B" 'utf-8-jp-er))
295 (princ www-ids-find-version)
296 (princ (format-time-string
297 " (Last-modified: %Y-%m-%d %H:%M:%S)"
300 www-ids-find-ideographic-products-file-name))))
304 <form action=\"/ids-find\" method=\"GET\">
306 (princ (encode-coding-string "
\e$BItIJJ8;zNs
\e(B" 'utf-8-jp-er))
307 (princ " <input type=\"text\" name=\"components\" size=\"30\" maxlength=\"30\" value=\"")
308 (if (> (length components) 0)
309 (princ (encode-coding-string components 'utf-8-er)))
311 <input type=\"submit\" value=\"")
312 (princ (encode-coding-string "
\e$B8!:w3+;O
\e(B" 'utf-8-jp-er))
317 (unless (file-newer-than-file-p
318 www-ids-find-ideographic-products-file-name
319 (locate-file (car command-line-args) exec-path))
320 (princ (encode-coding-string "<hr>
322 \e$B8=:_!"%7%9%F%`$N99?7:n6HCf$G$9!#$7$P$i$/$*BT$A$/$@$5$$!#
\e(B
325 ;; (setq components nil)
329 ;; (map-char-attribute
331 ;; (when (every (lambda (p)
332 ;; (ideographic-structure-member p v))
334 ;; (princ (encode-coding-string
335 ;; (ids-find-format-line c v)
340 ;; 'ideographic-structure)
341 (when (= (length components) 1)
342 (www-ids-find-format-line (aref components 0)
343 (char-feature (aref components 0)
344 'ideographic-structure)))
345 ;; (dolist (c (ideographic-products-find components))
346 ;; (setq is (char-feature c 'ideographic-structure))
347 ;; ;; to avoid problems caused by wrong indexes
348 ;; (when (every (lambda (c)
349 ;; (ideographic-structure-member c is))
351 ;; (www-ids-find-format-line c is)))
353 (www-ids-insert-chars-including-components components)
357 (princ (encode-coding-string "<hr>
359 \e$B;XDj$7$?ItIJ$rA4$F4^$`4A;z$N0lMw$rI=<($7$^$9!#
\e(B
361 CHISE
\e$B$GMQ$$$i$l$k<BBV;2>H7A<0!JNc!'
\e(B&M-00256;
\e$B!K$GItIJ$r;XDj$9$k;v$b$G$-$^$9!#
\e(B" 'utf-8-jp-er))
362 (princ (encode-coding-string "
366 <li><a href=\"http://www.shuiren.org/chuden/toyoshi/syoseki/chise_ids.html\"
367 >
\e$B!V
\e(BCHISE IDS FIND
\e$B$G4A;z$r8!:w!W
\e(B</a>
\e$B!=
\e(B
\e$B;3ED?r?N$5$s!J
\e(B<a
368 href=\"http://www.shuiren.org/\">
\e$B?g?MDb
\e(B</a>
\e$B!K$K$h$k2r@b
\e(B
371 <li><a href=\"http://www.karitsu.org/tools/firefox_plugin.htm\"
372 >Firefox
\e$BMQ
\e(B plugin</a> by
\e$B=);3M[0lO:$5$s!J
\e(B<a href=\"http://www.karitsu.org/\"
373 >
\e$B2aN)c7
\e(B</a>
\e$B!K
\e(B
376 <li><a href=\"http://cvs.m17n.org/viewcvs/chise/ids/www/www-ids-find.el?view=markup\"
377 >www-ids-find.el (source file (Emacs Lisp part))
378 <li><a href=\"http://www.chise.org/ids/\"
379 >
\e$B!V
\e(BCHISE
\e$B4A;z9=B$>pJs%G!<%?%Y!<%9!W
\e(B</a>
380 <li><a href=\"http://fonts.jp/chise_linkmap/\"
381 >
\e$B!V
\e(Bchise_linkmap : CHISE
\e$B4A;zO"4D?^!W
\e(B</a> by
\e$B>eCO9(0l$5$s
\e(B
382 <li><a href=\"http://www.chise.org/\"
386 <li><a href=\"http://coe21.zinbun.kyoto-u.ac.jp/djvuchar\"
387 >
\e$B!VBsK\J8;z%G!<%?%Y!<%9!W
\e(B</a> by
388 <a href=\"http://coe21.zinbun.kyoto-u.ac.jp/\"
389 >
\e$B5~ETBg3X
\e(B21
\e$B@$5*
\e(BCOE
\e$B!VEl%"%8%"@$3&$N?MJ8>pJs3X8&5f650i5rE@!W
\e(B</a>
390 <li><a href=\"http://www.unicode.org/\"
398 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2015 <a href=\"http://kanji.zinbun.kyoto-u.ac.jp/~tomo/\"
399 >MORIOKA Tomohiko</a>")
403 href=\"http://www.chise.org/xemacs/\"
404 >XEmacs CHISE</a> %s."
405 (encode-coding-string xemacs-chise-version 'utf-8-jp-er)))