New file.
[chise/ids.git] / www / www-ids-find.el
1 (require 'ids-find)
2
3 (defun decode-url-string (string &optional coding-system)
4   (if (> (length string) 0)
5       (let ((i 0)
6             dest)
7         (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
8           (setq dest (concat dest
9                              (substring string i (match-beginning 0))
10                              (char-to-string
11                               (int-char
12                                (string-to-int (match-string 1 string) 16))))
13                 i (match-end 0)))
14         (decode-coding-string
15          (concat dest (substring string i))
16          coding-system))))
17
18 (let ((components (car command-line-args-left))
19       is)
20   (setq command-line-args-left (cdr command-line-args-left))
21   (cond
22    ((stringp components)
23     (if (string-match "^components=" components)
24         (setq components (substring components (match-end 0))))
25     (setq components
26           (if (> (length components) 0)
27               (decode-url-string components 'utf-8-jp-er)
28             nil))
29     )
30    (t
31     (setq components nil)
32     ))
33   (princ "Content-Type: text/html; charset=\"UTF-8\"
34
35 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
36             \"http://www.w3.org/TR/html4/loose.dtd\">
37 <html lang=\"ja\">
38 <head>
39 <title>CHISE IDS Find</title>
40 </head>
41
42 <body>
43
44 <h1>")
45   (princ (encode-coding-string "CHISE IDS \e$B4A;z8!:w\e(B" 'utf-8-jp-er))
46   (princ "</h1>
47 <p>
48 <form action=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/ids-find\" method=\"GET\">
49 ")
50   (princ (encode-coding-string "\e$BItIJJ8;zNs\e(B" 'utf-8-jp-er))
51   (princ " <input type=\"text\" name=\"components\" size=\"30\" maxlength=\"30\" value=\"")
52   (if (> (length components) 0)
53       (princ (encode-coding-string components 'utf-8-er)))
54   (princ "\">
55 <input type=\"submit\" value=\"")
56   (princ (encode-coding-string "\e$B8!:w3+;O\e(B" 'utf-8-jp-er))
57   (princ "\">
58 </form>
59
60 ")
61   (when components
62     ;; (map-char-attribute
63     ;;  (lambda (c v)
64     ;;    (when (every (lambda (p)
65     ;;                   (ideographic-structure-member p v))
66     ;;                 components)
67     ;;      (princ (encode-coding-string
68     ;;              (ids-find-format-line c v)
69     ;;              'utf-8-jp-er))
70     ;;      (princ "<br>\n")
71     ;;      )
72     ;;    nil)
73     ;;  'ideographic-structure)
74     (dolist (c (ideographic-products-find components))
75       (setq is (char-feature c 'ideographic-structure))
76       ;; to avoid problems caused by wrong indexes
77       (when (every (lambda (c)
78                      (ideographic-structure-member c is))
79                    components)
80         (princ (encode-coding-string (ids-find-format-line c is)
81                                      'utf-8-jp-er))
82         (princ "<br>\n")
83         ))
84     )
85   (princ "
86 </body>
87 </html>
88 "))