2 (require 'cwiki-common)
4 (setq www-format-char-img-style "vertical-align:middle;")
6 (defun decode-url-string (string &optional coding-system)
7 (if (> (length string) 0)
10 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
11 (setq dest (concat dest
12 (substring string i (match-beginning 0))
15 (string-to-int (match-string 1 string) 16))))
18 (concat dest (substring string i))
21 (defconst www-ids-find-version "0.26")
23 (defvar www-ids-find-ideographic-products-file-name
24 (expand-file-name "ideographic-products"
29 chise-system-db-directory))))
31 (defvar www-ids-find-char-viewer-url
32 "/est/view/character/")
34 (defvar www-ids-find-chise-link-map-url-prefix
35 "http://fonts.jp/chise_linkmap/map.cgi?code=")
37 (defvar www-ids-find-tang-chars-file-name
38 "~tomo/projects/chise/ids/www/tang-chars.udd")
40 (defun www-ids-find-format-char (c &optional code-desc)
42 (format "<a href=\"%s%s\">%s</a>"
43 www-ids-find-char-viewer-url
44 (www-uri-encode-object c)
45 (www-format-encode-string (char-to-string c))))
46 ;; (let ((str (encode-coding-string (format "%c" c) 'utf-8-er))
51 ;; ((string-match "&CB\\([0-9]+\\);" str)
52 ;; (setq code (string-to-int (match-string 1 str)))
53 ;; (insert (format "<a href=\"%s"
54 ;; www-ids-find-char-viewer-url))
56 ;; (insert (format "\"><img alt=\"CB%05d\" src=\"/glyphs/cb-gaiji/%02d/CB%05d.gif\">\n"
57 ;; code (/ code 1000) code))
59 ;; (insert (format "CB%05d</a>" code)))
61 ;; ((string-match "&JC3-\\([0-9A-F]+\\);" str)
62 ;; (setq code (string-to-int (match-string 1 str) 16))
63 ;; (insert (format "<a href=\"%s"
64 ;; www-ids-find-char-viewer-url))
66 ;; (insert (format "\"><img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">\n"
69 ;; (insert (format "JC3-%04X</a>" code)))
71 ;; ((string-match "&J\\(78\\|83\\|90\\|SP\\)-\\([0-9A-F]+\\);" str)
72 ;; (setq plane (match-string 1 str)
73 ;; code (string-to-int (match-string 2 str) 16))
74 ;; (insert (format "<a href=\"%s"
75 ;; www-ids-find-char-viewer-url))
77 ;; (insert (format "\"><img alt=\"J%s-%04X\" src=\"/glyphs/JIS-%s/%02d-%02d.gif\">\n"
79 ;; (- (lsh code -8) 32)
80 ;; (- (logand code 255) 32)))
82 ;; (insert (format "J%s-%04X</a>" plane code)))
84 ;; ((string-match "&G\\([01]\\)-\\([0-9A-F]+\\);" str)
85 ;; (setq plane (string-to-int (match-string 1 str))
86 ;; code (string-to-int (match-string 2 str) 16))
87 ;; (insert (format "<a href=\"%s"
88 ;; www-ids-find-char-viewer-url))
90 ;; (insert (format "\"><img alt=\"G%d-%04X\" src=\"/glyphs/GB%d/%02d-%02d.gif\">\n"
92 ;; (- (lsh code -8) 32)
93 ;; (- (logand code 255) 32)))
95 ;; (insert (format "G%d-%04X</a>" plane code)))
97 ;; ((string-match "&C\\([1-7]\\)-\\([0-9A-F]+\\);" str)
98 ;; (setq plane (string-to-int (match-string 1 str))
99 ;; code (string-to-int (match-string 2 str) 16))
100 ;; (insert (format "<a href=\"%s"
101 ;; www-ids-find-char-viewer-url))
103 ;; (insert (format "\"><img alt=\"C%d-%04X\" src=\"/glyphs/CNS%d/%04X.gif\">\n"
104 ;; plane code plane code))
106 ;; (insert (format "C%d-%04X</a>" plane code)))
108 ;; ((string-match "&ZOB-\\([0-9]+\\);" str)
109 ;; (setq code (string-to-int (match-string 1 str)))
110 ;; (insert (format "<a href=\"%s"
111 ;; www-ids-find-char-viewer-url))
113 ;; (insert (format "\"><img alt=\"ZOB-%04d\" src=\"/glyphs/ZOB-1968/%04d.png\">\n"
116 ;; (insert (format "ZOB-%04d</a>" code)))
119 ;; (insert (format "<a href=\"%s"
120 ;; www-ids-find-char-viewer-url))
123 ;; (mapconcat (lambda (c)
124 ;; (if (<= (char-int c) #x7F)
125 ;; (char-to-string c)
126 ;; (format "%%%02X" c)))
132 ;; (goto-char (point-min))
133 ;; (while (search-forward "&" nil t)
134 ;; (replace-match "&" t 'literal))
135 ;; (buffer-string))))
138 (defun www-ids-find-format-line (c is)
140 (princ "<span class=\"entry\">")
141 (www-ids-find-format-char c 'code-desc)
144 (or (if (setq ucs (or (char-ucs c)
145 (encode-char c 'ucs)))
147 " <a href=\"http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=%X\">%s</a>"
149 (cond ((<= ucs #xFFFF)
150 (format "U+%04X" ucs))
152 (format "U-%08X" ucs))))
156 (format " <a href=\"%s%X\">(link map)</a>"
157 www-ids-find-chise-link-map-url-prefix ucs)))
160 (setq ids (ideographic-structure-to-ids is))
163 (princ "<span class=\"ids\">")
165 (www-ids-find-format-char (aref ids i))
171 www-ids-find-tang-chars-file-name)
172 (goto-char (point-min))
173 (re-search-forward (format "^%d$" ucs) nil t)))
175 (format " <a href=\"http://coe21.zinbun.kyoto-u.ac.jp/djvuchar?query=%s\">"
178 (format "%%%02X" (char-int c)))
179 (encode-coding-string (char-to-string c)
182 (princ (encode-coding-string "
\e$B"M
\e(B[
\e$BEbBeBsK\
\e(B]</a>" 'utf-8-jp-er)))
185 (defun www-ids-insert-chars-including-components (components
186 &optional ignored-chars)
187 (let ((products (ideographic-products-find components))
188 is as bs len ignore-children)
189 (setq len (length products))
191 (setq ignore-children t)
193 (encode-coding-string
194 "<p>
\e$B7k2L$,B?$9$.$k$?$a!":F5"E*8!:w$r>JN,$7$^$7$?!#
\e(B</p>"
198 (www-ids-find-format-char c))
202 ;; (setq ignore-children t)
207 (sort (copy-list products)
209 (< (char-int a)(char-int b))))
212 (sort (copy-list products)
214 (if (setq as (char-total-strokes a))
215 (if (setq bs (char-total-strokes b))
217 (< (char-int a)(char-int b))
220 (< (char-int a)(char-int b)))))
223 (sort (copy-list products)
225 (if (setq as (char-total-strokes a))
226 (if (setq bs (char-total-strokes b))
228 (ideograph-char< a b)
231 (ideograph-char< a b))))
233 (unless (memq c ignored-chars)
234 (setq is (char-feature c 'ideographic-structure))
236 (www-ids-find-format-line c is)
237 (unless ignore-children
240 (www-ids-insert-chars-including-components
242 (cons c ignored-chars)))
250 (defun www-batch-ids-find ()
251 (let ((components (car command-line-args-left))
252 (coded-charset-entity-reference-alist
254 '(=cns11643-1 "C1-" 4 X)
255 '(=cns11643-2 "C2-" 4 X)
256 '(=cns11643-3 "C3-" 4 X)
257 '(=cns11643-4 "C4-" 4 X)
258 '(=cns11643-5 "C5-" 4 X)
259 '(=cns11643-6 "C6-" 4 X)
260 '(=cns11643-7 "C7-" 4 X)
262 '(=gb12345 "G1-" 4 X)
263 '(=jis-x0208@1990 "J90-" 4 X)
264 '(=jis-x0212 "JSP-" 4 X)
266 '(=jef-china3 "JC3-" 4 X)
267 '(=jis-x0208@1978 "J78-" 4 X)
268 '(=jis-x0208@1983 "J83-" 4 X)
269 '(=daikanwa "M-" 5 d)
270 coded-charset-entity-reference-alist))
272 (setq command-line-args-left (cdr command-line-args-left))
274 ((stringp components)
275 (if (string-match "^components=" components)
276 (setq components (substring components (match-end 0))))
278 (if (> (length components) 0)
279 (decode-url-string components 'utf-8-er)
283 (setq components nil)
285 (princ "Content-Type: text/html; charset=UTF-8
287 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
288 \"http://www.w3.org/TR/html4/loose.dtd\">
291 <title>CHISE IDS Find</title>
292 <style type=\"text/css\">
294 .entry { font-size: 36px; }
295 .entry a img { height: 36px; }
296 .ids { font-size: 24px; }
297 .ids a img { height: 24px; }
298 img { vertical-align:middle; }
299 a { text-decoration:none; }
301 li { margin: 0 0 -0.2em; }
309 (princ (encode-coding-string "CHISE IDS
\e$B4A;z8!:w
\e(B" 'utf-8-jp-er))
313 (princ www-ids-find-version)
314 (princ (format-time-string
315 " (Last-modified: %Y-%m-%d %H:%M:%S)"
318 www-ids-find-ideographic-products-file-name))))
322 <form action=\"/ids-find\" method=\"GET\">
324 (princ (encode-coding-string "
\e$BItIJJ8;zNs
\e(B" 'utf-8-jp-er))
325 (princ " <input type=\"text\" name=\"components\" size=\"30\" maxlength=\"30\" value=\"")
326 (if (> (length components) 0)
327 (princ (encode-coding-string components 'utf-8-er)))
329 <input type=\"submit\" value=\"")
330 (princ (encode-coding-string "
\e$B8!:w3+;O
\e(B" 'utf-8-jp-er))
335 (unless (file-newer-than-file-p
336 www-ids-find-ideographic-products-file-name
337 (locate-file (car command-line-args) exec-path))
338 (princ (encode-coding-string "<hr>
340 \e$B8=:_!"%7%9%F%`$N99?7:n6HCf$G$9!#$7$P$i$/$*BT$A$/$@$5$$!#
\e(B
343 ;; (setq components nil)
347 ;; (map-char-attribute
349 ;; (when (every (lambda (p)
350 ;; (ideographic-structure-member p v))
352 ;; (princ (encode-coding-string
353 ;; (ids-find-format-line c v)
358 ;; 'ideographic-structure)
359 (when (= (length components) 1)
360 (www-ids-find-format-line (aref components 0)
361 (char-feature (aref components 0)
362 'ideographic-structure)))
363 ;; (dolist (c (ideographic-products-find components))
364 ;; (setq is (char-feature c 'ideographic-structure))
365 ;; ;; to avoid problems caused by wrong indexes
366 ;; (when (every (lambda (c)
367 ;; (ideographic-structure-member c is))
369 ;; (www-ids-find-format-line c is)))
371 (www-ids-insert-chars-including-components components)
375 (princ (encode-coding-string "<hr>
377 \e$B;XDj$7$?ItIJ$rA4$F4^$`4A;z$N0lMw$rI=<($7$^$9!#
\e(B
379 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))
380 (princ (encode-coding-string "
384 <li><a href=\"http://www.shuiren.org/chuden/toyoshi/syoseki/chise_ids.html\"
385 >
\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
386 href=\"http://www.shuiren.org/\">
\e$B?g?MDb
\e(B</a>
\e$B!K$K$h$k2r@b
\e(B
389 <li><a href=\"http://www.karitsu.org/tools/firefox_plugin.htm\"
390 >Firefox
\e$BMQ
\e(B plugin</a> by
\e$B=);3M[0lO:$5$s!J
\e(B<a href=\"http://www.karitsu.org/\"
391 >
\e$B2aN)c7
\e(B</a>
\e$B!K
\e(B
394 <li><a href=\"http://cvs.m17n.org/viewcvs/chise/ids/www/www-ids-find.el?view=markup\"
395 >www-ids-find.el (source file (Emacs Lisp part))
396 <li><a href=\"http://www.chise.org/ids/\"
397 >
\e$B!V
\e(BCHISE
\e$B4A;z9=B$>pJs%G!<%?%Y!<%9!W
\e(B</a>
398 <li><a href=\"http://fonts.jp/chise_linkmap/\"
399 >
\e$B!V
\e(Bchise_linkmap : CHISE
\e$B4A;zO"4D?^!W
\e(B</a> by
\e$B>eCO9(0l$5$s
\e(B
400 <li><a href=\"http://www.chise.org/\"
404 <li><a href=\"http://coe21.zinbun.kyoto-u.ac.jp/djvuchar\"
405 >
\e$B!VBsK\J8;z%G!<%?%Y!<%9!W
\e(B</a> by
406 <a href=\"http://coe21.zinbun.kyoto-u.ac.jp/\"
407 >
\e$B5~ETBg3X
\e(B21
\e$B@$5*
\e(BCOE
\e$B!VEl%"%8%"@$3&$N?MJ8>pJs3X8&5f650i5rE@!W
\e(B</a>
408 <li><a href=\"http://www.unicode.org/\"
416 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2015 <a href=\"http://kanji.zinbun.kyoto-u.ac.jp/~tomo/\"
417 >MORIOKA Tomohiko</a>")
421 href=\"http://www.chise.org/xemacs/\"
422 >XEmacs CHISE</a> %s."
423 (encode-coding-string xemacs-chise-version 'utf-8-jp-er)))