1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
4 (setq file-name-coding-system 'utf-8-mcs-er)
7 (concord-assign-genre 'creator@ruimoku "/usr/local/var/ruimoku/db")
8 (concord-assign-genre 'person-name@ruimoku "/usr/local/var/ruimoku/db")
10 (concord-assign-genre 'journal-volume@ruimoku "/usr/local/var/ruimoku/db")
11 (concord-assign-genre 'article@ruimoku "/usr/local/var/ruimoku/db")
12 (concord-assign-genre 'book@ruimoku "/usr/local/var/ruimoku/db")
14 (concord-assign-genre 'classification@ruimoku "/usr/local/var/ruimoku/db")
15 (concord-assign-genre 'region@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
17 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
18 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
21 (defvar chise-wiki-view-url "view.cgi")
22 (defvar chise-wiki-edit-url "edit.cgi")
24 (defvar chise-wiki-bitmap-glyphs-url
25 "http://chise.zinbun.kyoto-u.ac.jp/glyphs")
27 (defvar chise-wiki-glyph-cgi-url
28 "http://chise.zinbun.kyoto-u.ac.jp/chisewiki/glyph.cgi")
30 (defvar chise-wiki-displayed-features nil)
32 (defun decode-uri-string (string &optional coding-system)
33 (if (> (length string) 0)
37 (mapconcat (lambda (char)
40 (char-to-string char)))
42 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
43 (setq dest (concat dest
44 (substring string i (match-beginning 0))
47 (string-to-int (match-string 1 string) 16))))
50 (concat dest (substring string i))
53 (defun www-feature-type (feature-name)
54 (or (char-feature-property feature-name 'type)
55 (let ((str (symbol-name feature-name)))
57 ((string-match "\\*note\\(@[^*]+\\)?$" str)
59 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
61 ((string-match "\\*" str)
63 ((string-match "^\\(->\\|<-\\)" str)
65 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
69 (defun www-feature-format (feature-name)
70 (or (char-feature-property feature-name 'format)
72 (setq fn feature-name)
73 (while (and (setq parent (char-feature-name-parent fn))
75 (char-feature-property
79 '((name) " : " (value))))
81 (defun www-feature-value-format (feature-name)
82 (or (char-feature-property feature-name 'value-format)
84 (setq fn feature-name)
85 (while (and (setq parent (char-feature-name-parent fn))
87 (char-feature-property
88 parent 'value-format))))
91 (let ((type (www-feature-type feature-name)))
92 (cond ((eq type 'relation)
93 'space-separated-char-list)
99 (if (find-charset feature-name)
100 (if (and (= (charset-dimension feature-name) 2)
101 (= (charset-chars feature-name) 94))
103 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
104 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
106 (defun char-feature-name-at-domain (feature-name domain)
108 (let ((name (symbol-name feature-name)))
110 ((string-match "@[^*]+$" name)
111 (intern (format "%s/%s" name domain))
114 (intern (format "%s@%s" name domain))
118 (defun char-feature-name-parent (feature-name)
119 (let ((name (symbol-name feature-name)))
120 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
121 (intern (substring name 0 (car (last (match-data) 2)))))))
123 (defun char-feature-name-domain (feature-name)
124 (let ((name (symbol-name feature-name)))
125 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
126 (intern (substring name (1+ (match-beginning 0)))))))
128 (defun char-feature-name-sans-versions (feature)
129 (let ((feature-name (symbol-name feature)))
130 (if (string-match "[@/]\\$rev=latest$" feature-name)
131 (intern (substring feature-name 0 (match-beginning 0)))
134 (defun est-object-genre (object)
135 (if (characterp object)
137 (concord-object-genre object)))
139 (defun www-get-feature-value (object feature)
140 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
143 (mount-char-attribute-table latest-feature)
144 (or (char-feature object latest-feature)
145 (char-feature object feature))
148 (or (condition-case nil
149 (concord-object-get object latest-feature)
152 (concord-object-get object feature)
156 (defun get-previous-code-point (ccs code)
157 (let ((chars (charset-chars ccs))
158 (dim (charset-dimension ccs))
160 mask byte-min byte-max
183 (setq bytes (make-vector dim 0))
185 (aset bytes i (logand (lsh code (* i -8)) mask))
188 (while (and (< i dim)
190 (aset bytes i (1- (aref bytes i)))
191 (< (aref bytes i) byte-min)))
192 (aset bytes i byte-max)
195 (setq dest (aref bytes 0)
198 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
202 (defun get-next-code-point (ccs code)
203 (let ((chars (charset-chars ccs))
204 (dim (charset-dimension ccs))
206 mask byte-min byte-max
229 (setq bytes (make-vector dim 0))
231 (aset bytes i (logand (lsh code (* i -8)) mask))
234 (while (and (< i dim)
236 (aset bytes i (1+ (aref bytes i)))
237 (> (aref bytes i) byte-max)))
238 (aset bytes i byte-min)
241 (setq dest (aref bytes 0)
244 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
248 (defun find-previous-defined-code-point (ccs code)
249 (let ((i (get-previous-code-point ccs code))
252 ((eq ccs '=jis-x0208)
253 (setq ccs '=jis-x0208@1990))
254 ((eq ccs '=jis-x0213-1)
255 (setq ccs '=jis-x0213-1@2004)))
258 (null (setq char (decode-char ccs i
259 (unless (eq ccs '=ucs)
261 (setq i (get-previous-code-point ccs i)))
264 (defun find-next-defined-code-point (ccs code)
265 (let ((i (get-next-code-point ccs code))
267 (setq max (+ code 1000))
269 ((eq ccs '=jis-x0208)
270 (setq ccs '=jis-x0208@1990))
271 ((eq ccs '=jis-x0213-1)
272 (setq ccs '=jis-x0213-1@2004)))
275 (null (setq char (decode-char ccs i
276 (unless (eq ccs '=ucs)
278 (setq i (get-next-code-point ccs i)))
282 ;;; @ URI representation
285 (defun www-uri-decode-feature-name (uri-feature)
288 ((string-match "^from\\." uri-feature)
289 (intern (format "<-%s" (substring uri-feature (match-end 0))))
291 ((string-match "^to\\." uri-feature)
292 (intern (format "->%s" (substring uri-feature (match-end 0))))
294 ((string-match "^rep\\." uri-feature)
295 (intern (format "=%s" (substring uri-feature (match-end 0))))
297 ((string-match "^g\\." uri-feature)
298 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
300 ((string-match "^gi\\." uri-feature)
301 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
303 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
304 (intern (format "=>>%s%s"
305 (make-string (string-to-int
306 (match-string 1 uri-feature))
308 (substring uri-feature (match-end 0))))
310 ((string-match "^a\\." uri-feature)
311 (intern (format "=>%s" (substring uri-feature (match-end 0))))
313 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
314 (intern (format "%s>%s"
315 (make-string (string-to-int
316 (match-string 1 uri-feature))
318 (substring uri-feature (match-end 0))))
320 ((and (setq feature (intern (format "=>%s" uri-feature)))
321 (find-charset feature))
323 ((and (setq feature (intern (format "=>>%s" uri-feature)))
324 (find-charset feature))
326 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
327 (find-charset feature))
329 ((and (setq feature (intern (format "=%s" uri-feature)))
330 (find-charset feature))
332 (t (intern uri-feature)))))
334 (defun www-uri-encode-feature-name (feature-name)
335 (setq feature-name (symbol-name feature-name))
337 ((string-match "^=\\([^=>]+\\)" feature-name)
338 (concat "rep." (substring feature-name (match-beginning 1)))
340 ((string-match "^=>>\\([^=>]+\\)" feature-name)
341 (concat "g." (substring feature-name (match-beginning 1)))
343 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
344 (concat "gi." (substring feature-name (match-beginning 1)))
346 ((string-match "^=>>\\(>+\\)" feature-name)
348 (length (match-string 1 feature-name))
349 (substring feature-name (match-end 1)))
351 ((string-match "^=>\\([^=>]+\\)" feature-name)
352 (concat "a." (substring feature-name (match-beginning 1)))
354 ((string-match "^\\(=+\\)>" feature-name)
356 (length (match-string 1 feature-name))
357 (substring feature-name (match-end 0)))
359 ((string-match "^->" feature-name)
360 (concat "to." (substring feature-name (match-end 0)))
362 ((string-match "^<-" feature-name)
363 (concat "from." (substring feature-name (match-end 0)))
367 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
368 (format "%s?feature=%s&char=%s"
369 chise-wiki-view-url uri-feature-name uri-char))
371 (defun www-uri-decode-object (genre char-rep)
374 ((string-match "\\(%3A\\|:\\)" char-rep)
375 (setq ccs (substring char-rep 0 (match-beginning 0))
376 cpos (substring char-rep (match-end 0)))
377 (setq ccs (www-uri-decode-feature-name ccs))
379 ((string-match "^0x" cpos)
381 (string-to-number (substring cpos (match-end 0)) 16))
384 (setq cpos (car (read-from-string cpos)))
386 (if (and (eq genre 'character)
388 (decode-char ccs cpos)
389 (concord-decode-object ccs cpos genre))
392 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
394 ((eq genre 'character)
395 (when (= (length char-rep) 1)
399 (concord-decode-object
400 '=id (www-uri-decode-feature-name char-rep) 'feature)
403 (concord-decode-object
404 '=id (car (read-from-string char-rep)) genre)
407 (defun www-uri-encode-object (object)
408 (if (characterp object)
409 (if (encode-char object '=ucs)
412 (format "%%%02X" byte))
413 (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
415 (let ((ccs-list '(; =ucs
416 =cns11643-1 =cns11643-2 =cns11643-3
417 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
419 =jis-x0208 =jis-x0208@1990
422 =jis-x0213-1@2000 =jis-x0213-1@2004
423 =jis-x0208@1983 =jis-x0208@1978
424 =zinbun-oracle =>zinbun-oracle
427 =>>jis-x0208 =>>jis-x0213-1
428 =>jis-x0208 =>jis-x0213-1
435 (setq ccs (pop ccs-list))
436 (not (setq ret (encode-char object ccs 'defined-only)))))
439 (www-uri-encode-feature-name ccs)
441 ((and (setq ccs (car (split-char object)))
442 (setq ret (encode-char object ccs)))
444 (www-uri-encode-feature-name ccs)
447 (format "system-char-id:0x%X"
448 (encode-char object 'system-char-id))
450 (format "rep.id:%s" (concord-object-id object))))
452 (defun est-format-object (object)
453 (if (characterp object)
454 (char-to-string object)
455 (format "%s" (concord-object-id object))))
458 ;;; @ Feature name presentation
461 (defun www-format-feature-name-default (feature-name)
465 (symbol-name feature-name)
469 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
470 (let ((str (symbol-name feature-name))
473 ((string-match "\\*[^*]+$" str)
474 (setq base (substring str 0 (match-beginning 0))
475 meta (substring str (match-beginning 0)))
476 (concat (www-format-feature-name* (intern base) lang)
479 (www-format-feature-name-default feature-name)
482 (defun www-format-feature-name-as-rel-to (feature-name)
483 (concat "\u2192" (substring (symbol-name feature-name) 2)))
485 (defun www-format-feature-name-as-rel-from (feature-name)
486 (concat "\u2190" (substring (symbol-name feature-name) 2)))
488 (defun www-format-feature-name-as-CCS (feature-name)
491 (symbol-name feature-name)
493 (dest (upcase (pop rest))))
494 (when (string-match "^=+>*" dest)
495 (setq dest (concat (substring dest 0 (match-end 0))
497 (substring dest (match-end 0)))))
501 (setq dest (concat dest " " (upcase (pop rest)))))
502 (if (string-match "^[0-9]+$" (car rest))
503 (concat dest "-" (car rest))
504 (concat dest " " (upcase (car rest))))
508 (defun www-format-feature-name* (feature-name &optional lang)
509 (let (name fn parent ret)
512 (char-feature-property
514 (intern (format "name@%s" lang))))
515 (char-feature-property
516 feature-name 'name)))
517 ((and (setq name (symbol-name feature-name))
518 (string-match "\\*" name))
519 (www-format-feature-name-as-metadata feature-name lang))
521 (setq fn feature-name)
522 (while (and (setq parent (char-feature-name-parent fn))
525 (char-feature-property
527 (intern (format "name@%s" lang))))
528 (char-feature-property
533 (concat ret (substring (symbol-name feature-name)
534 (length (symbol-name parent)))))
535 ((find-charset feature-name)
536 (www-format-feature-name-as-CCS feature-name))
537 ((string-match "^\\(->\\)" name)
538 (www-format-feature-name-as-rel-to feature-name))
539 ((string-match "^\\(<-\\)" name)
540 (www-format-feature-name-as-rel-from feature-name))
542 (www-format-feature-name-default feature-name)
546 (defun www-format-feature-name (feature-name &optional lang)
547 (www-format-encode-string
548 (www-format-feature-name* feature-name lang)))
551 ;;; @ Feature value presentation
554 (defun www-format-value-as-kuten (value)
556 (- (lsh value -8) 32)
557 (- (logand value 255) 32)))
559 (defun www-format-value-default (value &optional without-tags)
563 (www-format-encode-string
567 (www-format-encode-string (format "%S" value) without-tags)))
569 (defun www-format-value-as-char-list (value &optional without-tags)
574 (www-format-encode-string
575 (format (if (characterp unit)
580 (let (genre-o name-f ret)
582 (if (characterp unit)
583 (format "<a href=\"%s?char=%s\">%s</a>"
585 (www-uri-encode-object unit)
586 (www-format-encode-string (char-to-string unit)))
587 (format "<a href=\"%s?%s=%s\">%s</a>"
589 (concord-object-genre unit)
590 (concord-object-id unit)
593 (www-get-feature-value
597 (concord-decode-object
599 (concord-object-genre unit)
601 (www-get-feature-value
603 'object-representation-format)
605 (www-format-eval-feature-value
606 unit name-f nil nil nil ret
607 'without-tags 'without-edit)
610 (www-format-encode-string
615 (www-format-encode-string (format "%s" value) without-tags)))
617 (defun www-format-value-as-domain-list (value &optional without-tags)
618 (let (name source0 source num dest rest unit start end ddest)
627 (setq unit (pop rest))
629 (setq name (symbol-name unit)))
634 ((string-match "^zob1968=" name)
635 (setq source (intern (substring name 0 (match-end 0)))
636 num (substring name (match-end 0)))
637 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
638 (setq start (string-to-number
639 (match-string 1 num))
640 end (string-to-number
641 (match-string 2 num)))
642 (setq start (string-to-number num)
645 (if (eq source source0)
647 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
649 (setq source0 source)
651 " <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/\">%s</a>=<a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
652 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
654 (setq start (1+ start))
655 (while (<= start end)
660 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
662 (setq start (1+ start)))
666 (if (eq source source0)
668 (setq source0 source)
672 (www-format-encode-string (format "%s" value) without-tags))))
674 (defun www-format-value-as-ids (value &optional without-tags)
679 (www-format-encode-string
680 (format (if (characterp unit)
686 (if (characterp unit)
687 (format "<a href=\"%s?char=%s\">%s</a>"
689 (www-uri-encode-object unit)
690 (www-format-encode-string (char-to-string unit)))
691 (www-format-encode-string (format "%s" unit)))))
692 (ideographic-structure-to-ids value) " ")
693 (www-format-encode-string (format "%s" value) without-tags)))
695 (defun www-format-value-as-S-exp (value &optional without-tags)
696 (www-format-encode-string (format "%S" value) without-tags))
698 (defun www-format-value-as-HEX (value)
701 (www-format-value-as-S-exp value)))
703 (defun www-format-value-as-CCS-default (value)
706 (www-format-value-as-HEX value)
708 (www-format-value-as-S-exp value)))
710 (defun www-format-value-as-CCS-94x94 (value)
712 (format "0x%s [%s] (%d)"
713 (www-format-value-as-HEX value)
714 (www-format-value-as-kuten value)
716 (www-format-value-as-S-exp value)))
718 (defun www-format-value-as-kangxi-radical (value)
719 (if (and (integerp value)
722 (www-format-encode-string
723 (format "%c" (ideographic-radical value)))
724 (www-format-value-as-S-exp value)))
726 (defun www-format-value (object feature-name
727 &optional value format
728 without-tags without-edit)
730 (setq value (www-get-feature-value object feature-name)))
731 (www-format-apply-value object feature-name
732 format nil value nil nil
733 without-tags without-edit)
737 ;;; @ format evaluator
740 (defun www-format-encode-string (string &optional without-tags)
743 (let (plane code start end char variants ret rret)
744 (goto-char (point-min))
745 (while (search-forward "<" nil t)
746 (replace-match "<" nil t))
747 (goto-char (point-min))
748 (while (search-forward ">" nil t)
749 (replace-match ">" nil t))
751 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
752 (let ((coded-charset-entity-reference-alist
755 '(=cns11643-1 "C1-" 4 X)
756 '(=cns11643-2 "C2-" 4 X)
757 '(=cns11643-3 "C3-" 4 X)
758 '(=cns11643-4 "C4-" 4 X)
759 '(=cns11643-5 "C5-" 4 X)
760 '(=cns11643-6 "C6-" 4 X)
761 '(=cns11643-7 "C7-" 4 X)
763 '(=gb12345 "G1-" 4 X)
764 '(=jis-x0208@1990 "J90-" 4 X)
765 '(=jis-x0212 "JSP-" 4 X)
767 '(=jis-x0208@1997 "J97-" 4 X)
768 '(=jis-x0208@1978 "J78-" 4 X)
769 '(=jis-x0208@1983 "J83-" 4 X)
770 '(=ruimoku-v6 "RUI6-" 4 X)
771 '(=zinbun-oracle "ZOB-" 4 d)
772 '(=jef-china3 "JC3-" 4 X)
773 '(=daikanwa "M-" 5 d)
774 coded-charset-entity-reference-alist)))
775 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
777 (goto-char (point-min))
778 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
779 (setq code (string-to-int (match-string 1)))
781 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
783 chise-wiki-bitmap-glyphs-url
787 (goto-char (point-min))
788 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
789 (setq plane (match-string 1)
790 code (string-to-int (match-string 2) 16))
792 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
794 chise-wiki-bitmap-glyphs-url
797 (- (logand code 255) 32))
800 (goto-char (point-min))
801 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
802 (setq plane (string-to-int (match-string 1))
803 code (string-to-int (match-string 2) 16))
805 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
807 chise-wiki-bitmap-glyphs-url
810 (- (logand code 255) 32))
813 (goto-char (point-min))
814 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
815 (setq plane (string-to-int (match-string 1))
816 code (string-to-int (match-string 2) 16))
818 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
820 chise-wiki-bitmap-glyphs-url
824 (goto-char (point-min))
825 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
826 (setq code (string-to-int (match-string 1) 16))
828 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
832 (goto-char (point-min))
833 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
834 (setq code (string-to-int (match-string 2)))
836 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
838 chise-wiki-bitmap-glyphs-url
842 (goto-char (point-min))
843 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
844 (setq code (string-to-int (match-string 2)))
846 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
848 chise-wiki-glyph-cgi-url
852 (goto-char (point-min))
853 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
854 (setq code (string-to-int (match-string 2)))
856 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
858 chise-wiki-glyph-cgi-url
862 (goto-char (point-min))
863 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
864 (setq code (string-to-int (match-string 1) 16))
866 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
868 chise-wiki-glyph-cgi-url
872 (goto-char (point-min))
873 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
874 (setq code (string-to-int (match-string 1) 16))
876 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
878 chise-wiki-glyph-cgi-url
882 (goto-char (point-min))
883 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
884 (setq code (string-to-int (match-string 1) 16))
886 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
888 chise-wiki-glyph-cgi-url
892 (goto-char (point-min))
893 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
894 (setq code (string-to-int (match-string 2) 16))
896 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
901 (goto-char (point-min))
902 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
903 (setq code (string-to-int (match-string 1) 16))
904 (setq start (match-beginning 0)
906 (setq char (decode-char 'system-char-id code))
909 (or (www-get-feature-value char '->subsumptive)
910 (www-get-feature-value char '->denotational)))
913 (setq ret (www-format-encode-string
914 (char-to-string (car variants))))
915 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
916 (setq variants (cdr variants)))
918 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
920 (delete-region start end)
923 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
924 (www-get-feature-value char 'ideographic-structure)))
929 (if (characterp (setq rret (find-char ch)))
932 (www-format-encode-string
933 (char-to-string ch) without-tags)
934 (www-format-encode-string
935 (format "%S" ch) without-tags)))
939 (delete-region start end)
943 ;; (goto-char (point-min))
944 ;; (while (search-forward ">-" nil t)
945 ;; (replace-match "&GT-" t 'literal))
948 (defun www-format-props-to-string (props &optional format)
950 (setq format (plist-get props :format)))
952 (plist-get props :flag)
953 ;; (if (plist-get props :zero-padding)
955 (if (plist-get props :len)
957 (let ((ret (plist-get props :len)))
962 ((eq format 'decimal) "d")
963 ((eq format 'hex) "x")
964 ((eq format 'HEX) "X")
965 ((eq format 'S-exp) "S")
968 (defun www-format-apply-value (object feature-name
970 &optional uri-object uri-feature
971 without-tags without-edit)
975 ((memq format '(decimal hex HEX))
977 (format (www-format-props-to-string props format)
979 (www-format-encode-string
983 ((eq format 'wiki-text)
985 (www-xml-format-list value)
986 (www-format-eval-list value object feature-name nil uri-object
987 without-tags without-edit))
990 (www-format-encode-string
991 (format (www-format-props-to-string props format)
995 (www-format-value-as-kuten value))
996 ((eq format 'kangxi-radical)
997 (www-format-value-as-kangxi-radical value))
998 ((eq format 'space-separated-char-list)
999 (www-format-value-as-char-list value without-tags))
1000 ((eq format 'space-separated-ids)
1001 (www-format-value-as-ids value without-tags))
1002 ((eq format 'space-separated-domain-list)
1003 (www-format-value-as-domain-list value without-tags))
1004 ((eq format 'string)
1005 (www-format-encode-string (format "%s" value) without-tags)
1008 (www-format-value-default value without-tags)
1011 (if (or without-tags
1013 (eq (plist-get props :mode) 'peek))
1015 (format "%s <a href=\"%s?%s=%s&feature=%s&format=%s\"
1016 ><input type=\"submit\" value=\"edit\" /></a>"
1019 (est-object-genre object)
1020 uri-object uri-feature format))))
1022 (defun www-format-eval-feature-value (object
1024 &optional format lang uri-object value
1025 without-tags without-edit)
1027 (setq value (www-get-feature-value object feature-name)))
1029 (setq format (www-feature-value-format feature-name)))
1032 (www-format-apply-value
1035 uri-object (www-uri-encode-feature-name feature-name)
1036 without-tags without-edit)
1039 (cond ((null (cdr format))
1040 (setq format (car format))
1041 (www-format-apply-value
1043 (car format) (nth 1 format) value
1044 uri-object (www-uri-encode-feature-name feature-name)
1045 without-tags without-edit)
1048 (www-format-eval-list format object feature-name lang uri-object
1049 without-tags without-edit)
1052 (defun www-format-eval-unit (exp object feature-name
1053 &optional lang uri-object value
1054 without-tags without-edit)
1056 (setq value (www-get-feature-value object feature-name)))
1058 (setq uri-object (www-uri-encode-object object)))
1060 ((stringp exp) (www-format-encode-string exp))
1064 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1065 S-exp string default))
1066 (let ((fn (plist-get (nth 1 exp) :feature))
1067 domain domain-fn ret)
1070 (setq fn (intern fn)))
1071 (setq domain (char-feature-name-domain feature-name))
1072 (setq domain-fn (char-feature-name-at-domain fn domain))
1073 (if (setq ret (www-get-feature-value object domain-fn))
1074 (setq feature-name domain-fn
1076 (setq feature-name fn
1077 value (www-get-feature-value object fn)))
1078 (push feature-name chise-wiki-displayed-features)
1080 (if (eq (car exp) 'value)
1081 (www-format-eval-feature-value object feature-name
1082 (plist-get (nth 1 exp) :format)
1083 lang uri-object value
1084 without-tags without-edit)
1085 (www-format-apply-value
1087 (car exp) (nth 1 exp) value
1088 uri-object (www-uri-encode-feature-name feature-name)
1089 without-tags without-edit))
1091 ((eq (car exp) 'name)
1092 (let ((fn (plist-get (nth 1 exp) :feature))
1095 (setq domain (char-feature-name-domain feature-name))
1097 (setq fn (intern fn)))
1098 (setq domain-fn (char-feature-name-at-domain fn domain))
1099 (setq feature-name domain-fn)))
1101 (www-format-feature-name feature-name lang)
1102 (format "<a href=\"%s\">%s</a>"
1103 (www-uri-make-feature-name-url
1104 (www-uri-encode-feature-name feature-name)
1106 (www-format-feature-name feature-name lang))
1109 ((eq (car exp) 'name-url)
1110 (let ((fn (plist-get (nth 1 exp) :feature))
1113 (setq domain (char-feature-name-domain feature-name))
1115 (setq fn (intern fn)))
1116 (setq domain-fn (char-feature-name-at-domain fn domain))
1117 (setq feature-name domain-fn)))
1118 (www-uri-make-feature-name-url
1119 (www-uri-encode-feature-name feature-name)
1122 ((eq (car exp) 'domain-name)
1123 (let ((domain (char-feature-name-domain feature-name)))
1125 (format "@%s" domain))))
1126 ((eq (car exp) 'prev-char)
1129 (let ((prev-char (find-previous-defined-code-point
1130 feature-name value)))
1132 (format "\n<a href=\"%s?char=%s\">%s</a>"
1134 (www-uri-encode-object prev-char)
1135 "<input type=\"submit\" value=\"-\" />"
1136 ;; (www-format-encode-string
1137 ;; (char-to-string prev-char))
1141 ((eq (car exp) 'next-char)
1144 (let ((next-char (find-next-defined-code-point
1145 feature-name value)))
1147 (format "<a href=\"%s?char=%s\">%s</a>"
1149 (www-uri-encode-object next-char)
1150 "<input type=\"submit\" value=\"+\" />"
1151 ;; (www-format-encode-string
1152 ;; (char-to-string next-char))
1156 ((eq (car exp) 'link)
1158 (www-format-eval-list (nthcdr 2 exp)
1159 object feature-name lang uri-object
1160 without-tags without-edit)
1165 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1166 object feature-name lang uri-object
1167 'without-tags 'without-edit)
1168 (www-format-eval-list (nthcdr 2 exp)
1169 object feature-name lang uri-object
1170 without-tags without-edit)))
1177 (www-format-eval-list (nthcdr 2 exp) object feature-name
1179 without-tags without-edit)
1182 (defun www-format-eval-list (format-list object feature-name
1183 &optional lang uri-object
1184 without-tags without-edit)
1185 (if (consp format-list)
1188 (www-format-eval-unit exp object feature-name lang uri-object
1189 nil without-tags without-edit))
1191 (www-format-eval-unit format-list object feature-name lang uri-object
1192 nil without-tags without-edit)))
1195 ;;; @ HTML generator
1198 (defun www-html-display-text (text)
1202 (goto-char (point-min))
1203 (while (search-forward "<" nil t)
1204 (replace-match "<" nil t))
1205 (goto-char (point-min))
1206 (while (search-forward ">" nil t)
1207 (replace-match ">" nil t))
1208 (goto-char (point-min))
1209 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1211 (format "<a href=\"%s\">%s</a>"
1215 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1216 (goto-char (point-min))
1217 (while (search-forward ">-" nil t)
1218 (replace-match "&GT-" nil t))
1221 (defun www-html-display-paragraph (text)
1223 (www-html-display-text text)
1230 (defvar coded-charset-GlyphWiki-id-alist
1231 '((=ucs "u" 4 x nil)
1232 (=ucs@JP "u" 4 x nil)
1233 (=ucs@jis "u" 4 x nil)
1234 (=ucs@gb "u" 4 x "-g")
1235 (=ucs@cns "u" 4 x "-t")
1236 (=ucs@ks "u" 4 x "-k")
1237 (=ucs@iso "u" 4 x "-u")
1238 (=ucs@unicode "u" 4 x "-us")
1239 (=adobe-japan1-6 "aj1-" 5 d nil)
1241 (=big5-cdp "cdp-" 4 x nil)
1242 (=cbeta "cb" 5 d nil)
1243 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1244 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1245 (=jis-x0208@1978 "j78-" 4 x nil)
1246 (=jis-x0208@1983 "j83-" 4 x nil)
1247 (=jis-x0208@1990 "j90-" 4 x nil)
1248 (=jis-x0212 "jsp-" 4 x nil)
1249 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1250 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1251 (=jis-x0213-2 "jx2-" 4 x nil)
1252 (=cns11643-1 "c1-" 4 x nil)
1253 (=cns11643-2 "c2-" 4 x nil)
1254 (=cns11643-3 "c3-" 4 x nil)
1255 (=cns11643-4 "c4-" 4 x nil)
1256 (=cns11643-5 "c5-" 4 x nil)
1257 (=cns11643-6 "c6-" 4 x nil)
1258 (=cns11643-7 "c7-" 4 x nil)
1259 (=daikanwa "dkw-" 5 d nil)
1260 (=gt-k "gt-k" 5 d nil)
1261 (=jef-china3 "jc3-" 4 x nil)
1262 (=big5 "b-" 4 x nil)
1263 (=ks-x1001 "k0-" 4 x nil)
1266 (defun char-GlyphWiki-id (char)
1267 (let ((rest coded-charset-GlyphWiki-id-alist)
1270 (setq spec (pop rest))
1271 (null (setq ret (char-feature char (car spec))))))
1274 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1276 ((and (or (encode-char char '=jis-x0208@1990)
1277 (encode-char char '=jis-x0212)
1278 (encode-char char '=jis-x0213-1))
1279 (setq code (encode-char char '=ucs@jis)))
1280 (format "u%04x" code)
1282 ((and (or (encode-char char '=gb2312)
1283 (encode-char char '=gb12345))
1284 (setq code (encode-char char '=ucs@gb)))
1285 (format "u%04x-g" code)
1287 ((and (or (encode-char char '=cns11643-1)
1288 (encode-char char '=cns11643-2)
1289 (encode-char char '=cns11643-3)
1290 (encode-char char '=cns11643-4)
1291 (encode-char char '=cns11643-5)
1292 (encode-char char '=cns11643-6)
1293 (encode-char char '=cns11643-7))
1294 (setq code (encode-char char '=ucs@cns)))
1295 (format "u%04x-t" code)
1297 ((and (encode-char char '=ks-x1001)
1298 (setq code (encode-char char '=ucs@ks)))
1299 (format "u%04x-k" code)
1301 (format (format "%s%%0%d%s%s"
1305 (or (nth 4 spec) ""))
1312 (provide 'cwiki-common)
1314 ;;; cwiki-common.el ends here