Add/modify some IDSs.
[chise/ids.git] / www / www-ids-find.el
index 5b43c9c..84c6e9e 100644 (file)
         (concat dest (substring string i))
         coding-system))))
 
+(defconst www-ids-find-version "0.22.3")
+
+(defvar www-ids-find-ideographic-products-file-name
+  (expand-file-name "ideographic-products"
+                   (expand-file-name
+                    "feature"
+                    (expand-file-name
+                     "character"
+                     chise-system-db-directory))))
+
 (defvar www-ids-find-tang-chars-file-name
   "~tomo/projects/chise/ids/www/tang-chars.udd")
 
 (defun www-ids-find-format-line (c is)
   (let ((str (encode-coding-string (format "%c" c) 'utf-8-er))
-       code ucs)
+       plane code ucs)
     (princ
      (with-temp-buffer
        (cond
                         code code))
         (insert (format "JC3-%04X</a>" code))
         )
-       (t
+       ((string-match "&J\\(78\\|83\\|90\\|SP\\)-\\([0-9A-F]+\\);" str)
+        (setq plane (match-string 1 str)
+              code (string-to-int (match-string 2 str) 16))
+        (insert "<a href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=")
+        (insert str)
+        (insert (format "\"><img alt=\"J%s-%04X\" src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/JIS-%s/%02d-%02d.gif\">\n"
+                        plane code plane
+                        (- (lsh code -8) 32)
+                        (- (logand code 255) 32)))
+        (insert (format "J%s-%04X</a>" plane code))
+        )
+       ((string-match "&G\\([01]\\)-\\([0-9A-F]+\\);" str)
+        (setq plane (string-to-int (match-string 1 str))
+              code (string-to-int (match-string 2 str) 16))
+        (insert "<a href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=")
+        (insert str)
+        (insert (format "\"><img alt=\"G%d-%04X\" src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/GB%d/%02d-%02d.gif\">\n"
+                        plane code plane
+                        (- (lsh code -8) 32)
+                        (- (logand code 255) 32)))
+        (insert (format "G%d-%04X</a>" plane code))
+        )
+       ((string-match "&C\\([1-7]\\)-\\([0-9A-F]+\\);" str)
+        (setq plane (string-to-int (match-string 1 str))
+              code (string-to-int (match-string 2 str) 16))
+        (insert "<a href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=")
+        (insert str)
+        (insert (format "\"><img alt=\"C%d-%04X\" src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/CNS%d/%04X.gif\">\n"
+                        plane code plane code))
+        (insert (format "C%d-%04X</a>" plane code))
+        )
+       ((string-match "&ZOB-\\([0-9]+\\);" str)
+        (setq code (string-to-int (match-string 1 str)))
         (insert "<a href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=")
         (insert str)
+        (insert (format "\"><img alt=\"ZOB-%04d\" src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/ZOB-1968/%04d.png\">\n"
+                        code code))
+        (insert (format "ZOB-%04d</a>" code))
+        )
+       (t
+        (insert "<a href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=")
+         ;; (insert str)
+        (insert
+         (mapconcat (lambda (c)
+                      (if (<= (char-int c) #x7F)
+                          (char-to-string c)
+                        (format "%%%02X" c)))
+                    str ""))
         (insert "\">")
         (insert str)
         (insert "</a>")
     (princ
      (or (if (setq ucs (or (char-ucs c)
                           (encode-char c 'ucs)))
-            (format " <a href=\"http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=%X\">%s</a>"
-                    ucs
-                    (cond ((<= ucs #xFFFF)
-                           (format "U+%04X" ucs))
-                          ((<= ucs #x10FFFF)
-                           (format "U-%08X" ucs))))
+            (format
+             " <a href=\"http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=%X\">%s</a>"
+             ucs
+             (cond ((<= ucs #xFFFF)
+                    (format "U+%04X" ucs))
+                   ((<= ucs #x10FFFF)
+                    (format "U-%08X" ucs))))
           "          ")))
+    (when ucs
+      (princ
+       (format " <a href=\"http://geta.mag.keio.ac.jp/chiseperl/map.cgi?code=%X\">(link map)</a>"
+              ucs)))
     (princ " ")
     (when is
       (princ
       (princ (encode-coding-string "\e$B"M\e(B[\e$BEbBeBsK\\e(B]</a>" 'utf-8-jp-er)))
     (princ "<br>\n")))
 
+(defun www-ids-insert-chars-including-components (components
+                                                 &optional ignored-chars)
+  (let ((products (copy-list (ideographic-products-find components)))
+       is as bs) 
+    (dolist (c (cond
+               ((> (length products) 10000)
+                products)
+               ((> (length products) 4096)
+                (sort products
+                      (lambda (a b)
+                        (< (char-int a)(char-int b))))
+                )
+               ((> (length products) 512)
+                (sort products
+                      (lambda (a b)
+                        (if (setq as (char-total-strokes a))
+                            (if (setq bs (char-total-strokes b))
+                                (if (= as bs)
+                                    (< (char-int a)(char-int b))
+                                  (< as bs))
+                              t)
+                          (< (char-int a)(char-int b)))))
+                )
+               (t
+                (sort products
+                      (lambda (a b)
+                        (if (setq as (char-total-strokes a))
+                            (if (setq bs (char-total-strokes b))
+                                (if (= as bs)
+                                    (ideograph-char< a b)
+                                  (< as bs))
+                              t)
+                          (ideograph-char< a b))))
+                )))
+      (unless (memq c ignored-chars)
+       (setq is (char-feature c 'ideographic-structure))
+       (princ "<li>")
+       (www-ids-find-format-line c is)
+       (princ "<ul>\n")
+       (setq ignored-chars
+             (www-ids-insert-chars-including-components
+              (char-to-string c)
+              (cons c ignored-chars)))
+       (princ "</ul>\n")
+       )
+      ))
+  ignored-chars)
+
 (defun www-batch-ids-find ()
   (let ((components (car command-line-args-left))
        (coded-charset-entity-reference-alist
         (list*
-         '(=cbeta      "CB" 5 d)
-         '(=jef-china3 "JC3-" 4 X)
+         '(=cns11643-1         "C1-" 4 X)
+         '(=cns11643-2         "C2-" 4 X)
+         '(=cns11643-3         "C3-" 4 X)
+         '(=cns11643-4         "C4-" 4 X)
+         '(=cns11643-5         "C5-" 4 X)
+         '(=cns11643-6         "C6-" 4 X)
+         '(=cns11643-7         "C7-" 4 X)
+         '(=gb2312             "G0-" 4 X)
+         '(=gb12345            "G1-" 4 X)
+         '(=jis-x0208@1990     "J90-" 4 X)
+         '(=jis-x0212          "JSP-" 4 X)
+         '(=cbeta              "CB" 5 d)
+         '(=jef-china3         "JC3-" 4 X)
+         '(=jis-x0208@1978     "J78-" 4 X)
+         '(=jis-x0208@1983     "J83-" 4 X)
+         '(=daikanwa           "M-" 5 d)
          coded-charset-entity-reference-alist))
-       is)
+       )
     (setq command-line-args-left (cdr command-line-args-left))
     (cond
      ((stringp components)
      (t
       (setq components nil)
       ))
-    (princ "Content-Type: text/html; charset=\"UTF-8\"
+    (princ "Content-Type: text/html; charset=UTF-8
 
 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
             \"http://www.w3.org/TR/html4/loose.dtd\">
 
 <h1>")
     (princ (encode-coding-string "CHISE IDS \e$B4A;z8!:w\e(B" 'utf-8-jp-er))
-    (princ "</h1>
+    (princ "</h1>")
+    (princ "
+<p>Version ")
+    (princ www-ids-find-version)
+    (princ (format-time-string
+           " (Last-modified: %Y-%m-%d %H:%M:%S)"
+           (nth 5
+                (file-attributes
+                 www-ids-find-ideographic-products-file-name))))
+    (princ "
+<p>
+Copyright (C) 2005 <a href=\"http://kanji.zinbun.kyoto-u.ac.jp/~tomo/\"
+>MORIOKA Tomohiko</a>
+<hr>
 <p>
 <form action=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/ids-find\" method=\"GET\">
 ")
 </form>
 
 ")
+    (unless (file-newer-than-file-p
+            www-ids-find-ideographic-products-file-name
+            (locate-file (car command-line-args) exec-path))
+      (princ (encode-coding-string "<hr>
+<p>
+\e$B8=:_!"%7%9%F%`$N99?7:n6HCf$G$9!#$7$P$i$/$*BT$A$/$@$5$$!#\e(B
+<hr>
+" 'utf-8-jp-er))
+      ;; (setq components nil)
+      )
     (cond
      (components
       ;; (map-char-attribute
        (www-ids-find-format-line (aref components 0)
                                  (char-feature (aref components 0)
                                                'ideographic-structure)))
-      (dolist (c (ideographic-products-find components))
-       (setq is (char-feature c 'ideographic-structure))
-       ;; to avoid problems caused by wrong indexes
-       (when (every (lambda (c)
-                      (ideographic-structure-member c is))
-                    components)
-         (www-ids-find-format-line c is)))
+      ;; (dolist (c (ideographic-products-find components))
+      ;;   (setq is (char-feature c 'ideographic-structure))
+      ;;   ;; to avoid problems caused by wrong indexes
+      ;;   (when (every (lambda (c)
+      ;;                  (ideographic-structure-member c is))
+      ;;                components)
+      ;;     (www-ids-find-format-line c is)))
+      (princ "<ul>\n")
+      (www-ids-insert-chars-including-components components)
+      (princ "</ul>\n")
       )
      (t
       (princ (encode-coding-string "<hr>
 \e$B;XDj$7$?ItIJ$rA4$F4^$`4A;z$N0lMw$rI=<($7$^$9!#\e(B
 <p>
 CHISE \e$B$GMQ$$$i$l$k<BBV;2>H7A<0!JNc!'\e(B&amp;M-00256;\e$B!K$GItIJ$r;XDj$9$k;v$b$G$-$^$9!#\e(B" 'utf-8-jp-er))
+      (princ (encode-coding-string "
+<p>
+\[Links\]
+<ul>
+<li><a href=\"http://www.shuiren.org/chuden/toyoshi/syoseki/chise_ids.html\"
+>\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
+href=\"http://www.shuiren.org/\">\e$B?g?MDb\e(B</a>\e$B!K$K$h$k2r@b\e(B
+</ul>
+<ul>
+<li><a href=\"http://www.karitsu.org/tools/firefox_plugin.htm\"
+>Firefox \e$BMQ\e(B plugin</a> by \e$B=);3M[0lO:$5$s!J\e(B<a href=\"http://www.karitsu.org/\"
+>\e$B2aN)c7\e(B</a>\e$B!K\e(B
+</ul>
+<ul>
+<li><a href=\"http://cvs.m17n.org/viewcvs/chise/ids/www/www-ids-find.el?view=markup\"
+>www-ids-find.el (source file (Emacs Lisp part))
+<li><a href=\"http://kanji.zinbun.kyoto-u.ac.jp/projects/chise/ids/\"
+>\e$B!V\e(BCHISE \e$B4A;z9=B$>pJs%G!<%?%Y!<%9!W\e(B</a>
+<li><a href=\"http://fonts.jp/chise_linkmap/\"
+>\e$B!V\e(Bchise_linkmap : CHISE \e$B4A;zO"4D?^!W\e(B</a> by \e$B>eCO9(0l$5$s\e(B
+<li><a href=\"http://kanji.zinbun.kyoto-u.ac.jp/projects/chise/\"
+>CHISE Project</a>
+</ul>
+<ul>
+<li><a href=\"http://coe21.zinbun.kyoto-u.ac.jp/djvuchar\"
+>\e$B!VBsK\J8;z%G!<%?%Y!<%9!W\e(B</a> by
+<a href=\"http://coe21.zinbun.kyoto-u.ac.jp/\"
+>\e$B5~ETBg3X\e(B21\e$B@$5*\e(BCOE\e$B!VEl%"%8%"@$3&$N?MJ8>pJs3X8&5f650i5rE@!W\e(B</a>
+<li><a href=\"http://www.unicode.org/\"
+>Unicode</a>
+</ul>"
+ 'utf-8-jp-er))
+
       ))
     (princ "<hr>")
     (princ