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")
9 (concord-assign-genre 'journal-volume@ruimoku "/usr/local/var/ruimoku/db")
10 (concord-assign-genre 'article@ruimoku "/usr/local/var/ruimoku/db")
11 (concord-assign-genre 'book@ruimoku "/usr/local/var/ruimoku/db")
13 (concord-assign-genre 'classification@ruimoku "/usr/local/var/ruimoku/db")
14 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
15 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
19 (defvar chise-wiki-view-url "view.cgi")
20 (defvar chise-wiki-edit-url "edit.cgi")
22 (defvar chise-wiki-bitmap-glyphs-url
23 "http://chise.zinbun.kyoto-u.ac.jp/glyphs")
25 (defvar chise-wiki-glyph-cgi-url
26 "http://chise.zinbun.kyoto-u.ac.jp/chisewiki/glyph.cgi")
28 (defvar chise-wiki-displayed-features nil)
30 (defun decode-uri-string (string &optional coding-system)
31 (if (> (length string) 0)
35 (mapconcat (lambda (char)
38 (char-to-string char)))
40 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
41 (setq dest (concat dest
42 (substring string i (match-beginning 0))
45 (string-to-int (match-string 1 string) 16))))
48 (concat dest (substring string i))
51 (defun www-feature-type (feature-name)
52 (or (char-feature-property feature-name 'type)
53 (let ((str (symbol-name feature-name)))
55 ((string-match "\\*note\\(@[^*]+\\)?$" str)
57 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
59 ((string-match "\\*" str)
61 ((string-match "^\\(->\\|<-\\)" str)
63 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
67 (defun www-feature-format (feature-name)
68 (or (char-feature-property feature-name 'format)
70 (setq fn feature-name)
71 (while (and (setq parent (char-feature-name-parent fn))
73 (char-feature-property
77 '((name) " : " (value))))
79 (defun www-feature-value-format (feature-name)
80 (or (char-feature-property feature-name 'value-format)
82 (setq fn feature-name)
83 (while (and (setq parent (char-feature-name-parent fn))
85 (char-feature-property
86 parent 'value-format))))
89 (let ((type (www-feature-type feature-name)))
90 (cond ((eq type 'relation)
91 'space-separated-char-list)
97 (if (find-charset feature-name)
98 (if (and (= (charset-dimension feature-name) 2)
99 (= (charset-chars feature-name) 94))
101 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
102 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
104 (defun char-feature-name-at-domain (feature-name domain)
106 (let ((name (symbol-name feature-name)))
108 ((string-match "@[^*]+$" name)
109 (intern (format "%s/%s" name domain))
112 (intern (format "%s@%s" name domain))
116 (defun char-feature-name-parent (feature-name)
117 (let ((name (symbol-name feature-name)))
118 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
119 (intern (substring name 0 (car (last (match-data) 2)))))))
121 (defun char-feature-name-domain (feature-name)
122 (let ((name (symbol-name feature-name)))
123 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
124 (intern (substring name (1+ (match-beginning 0)))))))
126 (defun char-feature-name-sans-versions (feature)
127 (let ((feature-name (symbol-name feature)))
128 (if (string-match "[@/]\\$rev=latest$" feature-name)
129 (intern (substring feature-name 0 (match-beginning 0)))
132 (defun www-get-feature-value (object feature)
133 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
136 (mount-char-attribute-table latest-feature)
137 (or (char-feature object latest-feature)
138 (char-feature object feature))
141 (or (concord-object-get object latest-feature)
142 (concord-object-get object feature))
145 (defun get-previous-code-point (ccs code)
146 (let ((chars (charset-chars ccs))
147 (dim (charset-dimension ccs))
149 mask byte-min byte-max
172 (setq bytes (make-vector dim 0))
174 (aset bytes i (logand (lsh code (* i -8)) mask))
177 (while (and (< i dim)
179 (aset bytes i (1- (aref bytes i)))
180 (< (aref bytes i) byte-min)))
181 (aset bytes i byte-max)
184 (setq dest (aref bytes 0)
187 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
191 (defun get-next-code-point (ccs code)
192 (let ((chars (charset-chars ccs))
193 (dim (charset-dimension ccs))
195 mask byte-min byte-max
218 (setq bytes (make-vector dim 0))
220 (aset bytes i (logand (lsh code (* i -8)) mask))
223 (while (and (< i dim)
225 (aset bytes i (1+ (aref bytes i)))
226 (> (aref bytes i) byte-max)))
227 (aset bytes i byte-min)
230 (setq dest (aref bytes 0)
233 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
237 (defun find-previous-defined-code-point (ccs code)
238 (let ((i (get-previous-code-point ccs code))
241 ((eq ccs '=jis-x0208)
242 (setq ccs '=jis-x0208@1990))
243 ((eq ccs '=jis-x0213-1)
244 (setq ccs '=jis-x0213-1@2004)))
247 (null (setq char (decode-char ccs i
248 (unless (eq ccs '=ucs)
250 (setq i (get-previous-code-point ccs i)))
253 (defun find-next-defined-code-point (ccs code)
254 (let ((i (get-next-code-point ccs code))
256 (setq max (+ code 1000))
258 ((eq ccs '=jis-x0208)
259 (setq ccs '=jis-x0208@1990))
260 ((eq ccs '=jis-x0213-1)
261 (setq ccs '=jis-x0213-1@2004)))
264 (null (setq char (decode-char ccs i
265 (unless (eq ccs '=ucs)
267 (setq i (get-next-code-point ccs i)))
271 ;;; @ URI representation
274 (defun www-uri-decode-feature-name (uri-feature)
277 ((string-match "^from\\." uri-feature)
278 (intern (format "<-%s" (substring uri-feature (match-end 0))))
280 ((string-match "^to\\." uri-feature)
281 (intern (format "->%s" (substring uri-feature (match-end 0))))
283 ((string-match "^rep\\." uri-feature)
284 (intern (format "=%s" (substring uri-feature (match-end 0))))
286 ((string-match "^g\\." uri-feature)
287 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
289 ((string-match "^gi\\." uri-feature)
290 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
292 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
293 (intern (format "=>>%s%s"
294 (make-string (string-to-int
295 (match-string 1 uri-feature))
297 (substring uri-feature (match-end 0))))
299 ((string-match "^a\\." uri-feature)
300 (intern (format "=>%s" (substring uri-feature (match-end 0))))
302 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
303 (intern (format "%s>%s"
304 (make-string (string-to-int
305 (match-string 1 uri-feature))
307 (substring uri-feature (match-end 0))))
309 ((and (setq feature (intern (format "=>%s" uri-feature)))
310 (find-charset feature))
312 ((and (setq feature (intern (format "=>>%s" uri-feature)))
313 (find-charset feature))
315 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
316 (find-charset feature))
318 ((and (setq feature (intern (format "=%s" uri-feature)))
319 (find-charset feature))
321 (t (intern uri-feature)))))
323 (defun www-uri-encode-feature-name (feature-name)
324 (setq feature-name (symbol-name feature-name))
326 ((string-match "^=\\([^=>]+\\)" feature-name)
327 (concat "rep." (substring feature-name (match-beginning 1)))
329 ((string-match "^=>>\\([^=>]+\\)" feature-name)
330 (concat "g." (substring feature-name (match-beginning 1)))
332 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
333 (concat "gi." (substring feature-name (match-beginning 1)))
335 ((string-match "^=>>\\(>+\\)" feature-name)
337 (length (match-string 1 feature-name))
338 (substring feature-name (match-end 1)))
340 ((string-match "^=>\\([^=>]+\\)" feature-name)
341 (concat "a." (substring feature-name (match-beginning 1)))
343 ((string-match "^\\(=+\\)>" feature-name)
345 (length (match-string 1 feature-name))
346 (substring feature-name (match-end 0)))
348 ((string-match "^->" feature-name)
349 (concat "to." (substring feature-name (match-end 0)))
351 ((string-match "^<-" feature-name)
352 (concat "from." (substring feature-name (match-end 0)))
356 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
357 (format "%s?feature=%s&char=%s"
358 chise-wiki-view-url uri-feature-name uri-char))
360 (defun www-uri-decode-object (genre char-rep)
363 ((string-match "\\(%3A\\|:\\)" char-rep)
364 (setq ccs (substring char-rep 0 (match-beginning 0))
365 cpos (substring char-rep (match-end 0)))
366 (setq ccs (www-uri-decode-feature-name ccs))
368 ((string-match "^0x" cpos)
370 (string-to-number (substring cpos (match-end 0)) 16))
373 (setq cpos (car (read-from-string cpos)))
375 (if (and (eq genre 'character)
377 (decode-char ccs cpos)
378 (concord-decode-object ccs cpos genre))
381 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
383 ((eq genre 'character)
384 (when (= (length char-rep) 1)
388 (concord-decode-object
389 '=id (www-uri-decode-feature-name char-rep) 'feature)
392 (concord-decode-object
393 '=id (car (read-from-string char-rep)) genre)
396 (defun www-uri-encode-object (object)
397 (if (characterp object)
398 (if (encode-char object '=ucs)
401 (format "%%%02X" byte))
402 (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
404 (let ((ccs-list '(; =ucs
405 =cns11643-1 =cns11643-2 =cns11643-3
406 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
408 =jis-x0208 =jis-x0208@1990
411 =jis-x0213-1@2000 =jis-x0213-1@2004
412 =jis-x0208@1983 =jis-x0208@1978
413 =zinbun-oracle =>zinbun-oracle
416 =>>jis-x0208 =>>jis-x0213-1
417 =>jis-x0208 =>jis-x0213-1
424 (setq ccs (pop ccs-list))
425 (not (setq ret (encode-char object ccs 'defined-only)))))
428 (www-uri-encode-feature-name ccs)
430 ((and (setq ccs (car (split-char object)))
431 (setq ret (encode-char object ccs)))
433 (www-uri-encode-feature-name ccs)
436 (format "system-char-id:0x%X"
437 (encode-char object 'system-char-id))
439 (format "rep.id:%s" (concord-object-id object))))
441 (defun est-format-object (object)
442 (if (characterp object)
443 (char-to-string object)
444 (format "%s" (concord-object-id object))))
447 ;;; @ Feature name presentation
450 (defun www-format-feature-name-default (feature-name)
454 (symbol-name feature-name)
458 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
459 (let ((str (symbol-name feature-name))
462 ((string-match "\\*[^*]+$" str)
463 (setq base (substring str 0 (match-beginning 0))
464 meta (substring str (match-beginning 0)))
465 (concat (www-format-feature-name* (intern base) lang)
468 (www-format-feature-name-default feature-name)
471 (defun www-format-feature-name-as-rel-to (feature-name)
472 (concat "\u2192" (substring (symbol-name feature-name) 2)))
474 (defun www-format-feature-name-as-rel-from (feature-name)
475 (concat "\u2190" (substring (symbol-name feature-name) 2)))
477 (defun www-format-feature-name-as-CCS (feature-name)
480 (symbol-name feature-name)
482 (dest (upcase (pop rest))))
483 (when (string-match "^=+>*" dest)
484 (setq dest (concat (substring dest 0 (match-end 0))
486 (substring dest (match-end 0)))))
490 (setq dest (concat dest " " (upcase (pop rest)))))
491 (if (string-match "^[0-9]+$" (car rest))
492 (concat dest "-" (car rest))
493 (concat dest " " (upcase (car rest))))
497 (defun www-format-feature-name* (feature-name &optional lang)
498 (let (name fn parent ret)
501 (char-feature-property
503 (intern (format "name@%s" lang))))
504 (char-feature-property
505 feature-name 'name)))
506 ((and (setq name (symbol-name feature-name))
507 (string-match "\\*" name))
508 (www-format-feature-name-as-metadata feature-name lang))
510 (setq fn feature-name)
511 (while (and (setq parent (char-feature-name-parent fn))
514 (char-feature-property
516 (intern (format "name@%s" lang))))
517 (char-feature-property
522 (concat ret (substring (symbol-name feature-name)
523 (length (symbol-name parent)))))
524 ((find-charset feature-name)
525 (www-format-feature-name-as-CCS feature-name))
526 ((string-match "^\\(->\\)" name)
527 (www-format-feature-name-as-rel-to feature-name))
528 ((string-match "^\\(<-\\)" name)
529 (www-format-feature-name-as-rel-from feature-name))
531 (www-format-feature-name-default feature-name)
535 (defun www-format-feature-name (feature-name &optional lang)
536 (www-format-encode-string
537 (www-format-feature-name* feature-name lang)))
540 ;;; @ Feature value presentation
543 (defun www-format-value-as-kuten (value)
545 (- (lsh value -8) 32)
546 (- (logand value 255) 32)))
548 (defun www-format-value-default (value &optional without-tags)
552 (www-format-encode-string
556 (www-format-encode-string (format "%S" value) without-tags)))
558 (defun www-format-value-as-char-list (value &optional without-tags)
563 (www-format-encode-string
564 (format (if (characterp unit)
569 (let (genre-o name-f ret)
571 (if (characterp unit)
572 (format "<a href=\"%s?char=%s\">%s</a>"
574 (www-uri-encode-object unit)
575 (www-format-encode-string (char-to-string unit)))
576 (format "<a href=\"%s?%s=%s\">%s</a>"
578 (concord-object-genre unit)
579 (concord-object-id unit)
582 (www-get-feature-value
586 (concord-decode-object
588 (concord-object-genre unit)
590 (www-get-feature-value genre-o 'name)
592 (www-format-eval-feature-value
593 unit name-f nil nil nil ret
594 'without-tags 'without-edit)
597 (www-format-encode-string
602 (www-format-encode-string (format "%s" value) without-tags)))
604 (defun www-format-value-as-domain-list (value &optional without-tags)
605 (let (name source0 source num dest rest unit start end ddest)
614 (setq unit (pop rest))
616 (setq name (symbol-name unit)))
621 ((string-match "^zob1968=" name)
622 (setq source (intern (substring name 0 (match-end 0)))
623 num (substring name (match-end 0)))
624 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
625 (setq start (string-to-number
626 (match-string 1 num))
627 end (string-to-number
628 (match-string 2 num)))
629 (setq start (string-to-number num)
632 (if (eq source source0)
634 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
636 (setq source0 source)
638 " <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>"
639 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
641 (setq start (1+ start))
642 (while (<= start end)
647 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
649 (setq start (1+ start)))
653 (if (eq source source0)
655 (setq source0 source)
659 (www-format-encode-string (format "%s" value) without-tags))))
661 (defun www-format-value-as-ids (value &optional without-tags)
666 (www-format-encode-string
667 (format (if (characterp unit)
673 (if (characterp unit)
674 (format "<a href=\"%s?char=%s\">%s</a>"
676 (www-uri-encode-object unit)
677 (www-format-encode-string (char-to-string unit)))
678 (www-format-encode-string (format "%s" unit)))))
679 (ideographic-structure-to-ids value) " ")
680 (www-format-encode-string (format "%s" value) without-tags)))
682 (defun www-format-value-as-S-exp (value &optional without-tags)
683 (www-format-encode-string (format "%S" value) without-tags))
685 (defun www-format-value-as-HEX (value)
688 (www-format-value-as-S-exp value)))
690 (defun www-format-value-as-CCS-default (value)
693 (www-format-value-as-HEX value)
695 (www-format-value-as-S-exp value)))
697 (defun www-format-value-as-CCS-94x94 (value)
699 (format "0x%s [%s] (%d)"
700 (www-format-value-as-HEX value)
701 (www-format-value-as-kuten value)
703 (www-format-value-as-S-exp value)))
705 (defun www-format-value-as-kangxi-radical (value)
706 (if (and (integerp value)
709 (www-format-encode-string
710 (format "%c" (ideographic-radical value)))
711 (www-format-value-as-S-exp value)))
713 (defun www-format-value (object feature-name
714 &optional value format
715 without-tags without-edit)
717 (setq value (www-get-feature-value object feature-name)))
718 (www-format-apply-value object feature-name
719 format nil value nil nil
720 without-tags without-edit)
724 ;;; @ format evaluator
727 (defun www-format-encode-string (string &optional without-tags)
730 (let (plane code start end char variants ret rret)
731 (goto-char (point-min))
732 (while (search-forward "<" nil t)
733 (replace-match "<" nil t))
734 (goto-char (point-min))
735 (while (search-forward ">" nil t)
736 (replace-match ">" nil t))
738 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
739 (let ((coded-charset-entity-reference-alist
742 '(=cns11643-1 "C1-" 4 X)
743 '(=cns11643-2 "C2-" 4 X)
744 '(=cns11643-3 "C3-" 4 X)
745 '(=cns11643-4 "C4-" 4 X)
746 '(=cns11643-5 "C5-" 4 X)
747 '(=cns11643-6 "C6-" 4 X)
748 '(=cns11643-7 "C7-" 4 X)
750 '(=gb12345 "G1-" 4 X)
751 '(=jis-x0208@1990 "J90-" 4 X)
752 '(=jis-x0212 "JSP-" 4 X)
754 '(=jis-x0208@1997 "J97-" 4 X)
755 '(=jis-x0208@1978 "J78-" 4 X)
756 '(=jis-x0208@1983 "J83-" 4 X)
757 '(=ruimoku-v6 "RUI6-" 4 X)
758 '(=zinbun-oracle "ZOB-" 4 d)
759 '(=jef-china3 "JC3-" 4 X)
760 '(=daikanwa "M-" 5 d)
761 coded-charset-entity-reference-alist)))
762 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
764 (goto-char (point-min))
765 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
766 (setq code (string-to-int (match-string 1)))
768 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
770 chise-wiki-bitmap-glyphs-url
774 (goto-char (point-min))
775 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
776 (setq plane (match-string 1)
777 code (string-to-int (match-string 2) 16))
779 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
781 chise-wiki-bitmap-glyphs-url
784 (- (logand code 255) 32))
787 (goto-char (point-min))
788 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
789 (setq plane (string-to-int (match-string 1))
790 code (string-to-int (match-string 2) 16))
792 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
794 chise-wiki-bitmap-glyphs-url
797 (- (logand code 255) 32))
800 (goto-char (point-min))
801 (while (re-search-forward "&C\\([1-7]\\)-\\([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=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
807 chise-wiki-bitmap-glyphs-url
811 (goto-char (point-min))
812 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
813 (setq code (string-to-int (match-string 1) 16))
815 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
819 (goto-char (point-min))
820 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
821 (setq code (string-to-int (match-string 2)))
823 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
825 chise-wiki-bitmap-glyphs-url
829 (goto-char (point-min))
830 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
831 (setq code (string-to-int (match-string 2)))
833 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
835 chise-wiki-glyph-cgi-url
839 (goto-char (point-min))
840 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
841 (setq code (string-to-int (match-string 2)))
843 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
845 chise-wiki-glyph-cgi-url
849 (goto-char (point-min))
850 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
851 (setq code (string-to-int (match-string 1) 16))
853 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
855 chise-wiki-glyph-cgi-url
859 (goto-char (point-min))
860 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
861 (setq code (string-to-int (match-string 1) 16))
863 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
865 chise-wiki-glyph-cgi-url
869 (goto-char (point-min))
870 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
871 (setq code (string-to-int (match-string 1) 16))
873 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
875 chise-wiki-glyph-cgi-url
879 (goto-char (point-min))
880 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
881 (setq code (string-to-int (match-string 2) 16))
883 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
888 (goto-char (point-min))
889 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
890 (setq code (string-to-int (match-string 1) 16))
891 (setq start (match-beginning 0)
893 (setq char (decode-char 'system-char-id code))
896 (or (www-get-feature-value char '->subsumptive)
897 (www-get-feature-value char '->denotational)))
900 (setq ret (www-format-encode-string
901 (char-to-string (car variants))))
902 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
903 (setq variants (cdr variants)))
905 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
907 (delete-region start end)
910 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
911 (www-get-feature-value char 'ideographic-structure)))
916 (if (characterp (setq rret (find-char ch)))
919 (www-format-encode-string
920 (char-to-string ch) without-tags)
921 (www-format-encode-string
922 (format "%S" ch) without-tags)))
926 (delete-region start end)
930 ;; (goto-char (point-min))
931 ;; (while (search-forward ">-" nil t)
932 ;; (replace-match "&GT-" t 'literal))
935 (defun www-format-props-to-string (props &optional format)
937 (setq format (plist-get props :format)))
939 (plist-get props :flag)
940 ;; (if (plist-get props :zero-padding)
942 (if (plist-get props :len)
944 (let ((ret (plist-get props :len)))
949 ((eq format 'decimal) "d")
950 ((eq format 'hex) "x")
951 ((eq format 'HEX) "X")
952 ((eq format 'S-exp) "S")
955 (defun www-format-apply-value (object feature-name
957 &optional uri-object uri-feature
958 without-tags without-edit)
962 ((memq format '(decimal hex HEX))
964 (format (www-format-props-to-string props format)
966 (www-format-encode-string
970 ((eq format 'wiki-text)
972 (www-xml-format-list value)
973 (www-format-eval-list value object feature-name nil uri-object
974 without-tags without-edit))
977 (www-format-encode-string
978 (format (www-format-props-to-string props format)
982 (www-format-value-as-kuten value))
983 ((eq format 'kangxi-radical)
984 (www-format-value-as-kangxi-radical value))
985 ((eq format 'space-separated-char-list)
986 (www-format-value-as-char-list value without-tags))
987 ((eq format 'space-separated-ids)
988 (www-format-value-as-ids value without-tags))
989 ((eq format 'space-separated-domain-list)
990 (www-format-value-as-domain-list value without-tags))
992 (www-format-encode-string (format "%s" value) without-tags)
995 (www-format-value-default value without-tags)
1000 (eq (plist-get props :mode) 'peek))
1002 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
1003 ><input type=\"submit\" value=\"edit\" /></a>"
1006 uri-object uri-feature format))))
1008 (defun www-format-eval-feature-value (object
1010 &optional format lang uri-object value
1011 without-tags without-edit)
1013 (setq value (www-get-feature-value object feature-name)))
1015 (setq format (www-feature-value-format feature-name)))
1018 (www-format-apply-value
1021 uri-object (www-uri-encode-feature-name feature-name)
1022 without-tags without-edit)
1025 (cond ((null (cdr format))
1026 (setq format (car format))
1027 (www-format-apply-value
1029 (car format) (nth 1 format) value
1030 uri-object (www-uri-encode-feature-name feature-name)
1031 without-tags without-edit)
1034 (www-format-eval-list format object feature-name lang uri-object
1035 without-tags without-edit)
1038 (defun www-format-eval-unit (exp object feature-name
1039 &optional lang uri-object value
1040 without-tags without-edit)
1042 (setq value (www-get-feature-value object feature-name)))
1044 (setq uri-object (www-uri-encode-object object)))
1046 ((stringp exp) (www-format-encode-string exp))
1050 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1051 S-exp string default))
1052 (let ((fn (plist-get (nth 1 exp) :feature))
1053 domain domain-fn ret)
1056 (setq fn (intern fn)))
1057 (setq domain (char-feature-name-domain feature-name))
1058 (setq domain-fn (char-feature-name-at-domain fn domain))
1059 (if (setq ret (www-get-feature-value object domain-fn))
1060 (setq feature-name domain-fn
1062 (setq feature-name fn
1063 value (www-get-feature-value object fn)))
1064 (push feature-name chise-wiki-displayed-features)
1066 (if (eq (car exp) 'value)
1067 (www-format-eval-feature-value object feature-name
1068 (plist-get (nth 1 exp) :format)
1069 lang uri-object value
1070 without-tags without-edit)
1071 (www-format-apply-value
1073 (car exp) (nth 1 exp) value
1074 uri-object (www-uri-encode-feature-name feature-name)
1075 without-tags without-edit))
1077 ((eq (car exp) 'name)
1078 (let ((fn (plist-get (nth 1 exp) :feature))
1081 (setq domain (char-feature-name-domain feature-name))
1083 (setq fn (intern fn)))
1084 (setq domain-fn (char-feature-name-at-domain fn domain))
1085 (setq feature-name domain-fn)))
1087 (www-format-feature-name feature-name lang)
1088 (format "<a href=\"%s\">%s</a>"
1089 (www-uri-make-feature-name-url
1090 (www-uri-encode-feature-name feature-name)
1092 (www-format-feature-name feature-name lang))
1095 ((eq (car exp) 'name-url)
1096 (let ((fn (plist-get (nth 1 exp) :feature))
1099 (setq domain (char-feature-name-domain feature-name))
1101 (setq fn (intern fn)))
1102 (setq domain-fn (char-feature-name-at-domain fn domain))
1103 (setq feature-name domain-fn)))
1104 (www-uri-make-feature-name-url
1105 (www-uri-encode-feature-name feature-name)
1108 ((eq (car exp) 'domain-name)
1109 (let ((domain (char-feature-name-domain feature-name)))
1111 (format "@%s" domain))))
1112 ((eq (car exp) 'prev-char)
1115 (let ((prev-char (find-previous-defined-code-point
1116 feature-name value)))
1118 (format "\n<a href=\"%s?char=%s\">%s</a>"
1120 (www-uri-encode-object prev-char)
1121 "<input type=\"submit\" value=\"-\" />"
1122 ;; (www-format-encode-string
1123 ;; (char-to-string prev-char))
1127 ((eq (car exp) 'next-char)
1130 (let ((next-char (find-next-defined-code-point
1131 feature-name value)))
1133 (format "<a href=\"%s?char=%s\">%s</a>"
1135 (www-uri-encode-object next-char)
1136 "<input type=\"submit\" value=\"+\" />"
1137 ;; (www-format-encode-string
1138 ;; (char-to-string next-char))
1142 ((eq (car exp) 'link)
1144 (www-format-eval-list (nthcdr 2 exp)
1145 object feature-name lang uri-object
1146 without-tags without-edit)
1151 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1152 object feature-name lang uri-object
1153 'without-tags 'without-edit)
1154 (www-format-eval-list (nthcdr 2 exp)
1155 object feature-name lang uri-object
1156 without-tags without-edit)))
1163 (www-format-eval-list (nthcdr 2 exp) object feature-name
1165 without-tags without-edit)
1168 (defun www-format-eval-list (format-list object feature-name
1169 &optional lang uri-object
1170 without-tags without-edit)
1171 (if (consp format-list)
1174 (www-format-eval-unit exp object feature-name lang uri-object
1175 nil without-tags without-edit))
1177 (www-format-eval-unit format-list object feature-name lang uri-object
1178 nil without-tags without-edit)))
1184 (defun www-xml-format-props (props)
1188 (setq key (pop props)
1191 (setq key (symbol-name key)))
1192 (if (eq (aref key 0) ?:)
1193 (setq key (substring key 1)))
1195 (format "%s %s=\"%s\""
1197 (www-format-encode-string
1198 (format "%s" val) 'without-tags))))
1201 (defun www-xml-format-unit (format-unit)
1202 (let (name props children ret)
1204 ((stringp format-unit)
1205 (mapconcat (lambda (c)
1208 ;; ((eq c ?<) "&lt;")
1209 ;; ((eq c ?>) "&gt;")
1211 (char-to-string c))))
1212 (www-format-encode-string format-unit 'without-tags)
1215 ((consp format-unit)
1216 (setq name (car format-unit)
1217 props (nth 1 format-unit)
1218 children (nthcdr 2 format-unit))
1219 (when (eq name 'link)
1220 (setq ret (plist-get props :ref))
1221 (unless (stringp ret)
1222 (setq props (plist-remprop (copy-list props) :ref))
1224 (cons (list* 'ref nil ret)
1227 (format "<%s%s>%s</%s>"
1230 (www-xml-format-props props)
1232 (www-xml-format-list children)
1235 name (www-xml-format-props props)))
1238 (format "%s" format-unit)))))
1240 (defun www-xml-format-list (format-list)
1241 (if (atom format-list)
1242 (www-xml-format-unit format-list)
1243 (mapconcat #'www-xml-format-unit
1247 ;;; @ HTML generator
1250 (defun www-html-display-text (text)
1254 (goto-char (point-min))
1255 (while (search-forward "<" nil t)
1256 (replace-match "<" nil t))
1257 (goto-char (point-min))
1258 (while (search-forward ">" nil t)
1259 (replace-match ">" nil t))
1260 (goto-char (point-min))
1261 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1263 (format "<a href=\"%s\">%s</a>"
1267 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1268 (goto-char (point-min))
1269 (while (search-forward ">-" nil t)
1270 (replace-match "&GT-" nil t))
1273 (defun www-html-display-paragraph (text)
1275 (www-html-display-text text)
1282 (defvar coded-charset-GlyphWiki-id-alist
1283 '((=ucs "u" 4 x nil)
1284 (=ucs@JP "u" 4 x nil)
1285 (=ucs@jis "u" 4 x nil)
1286 (=ucs@gb "u" 4 x "-g")
1287 (=ucs@cns "u" 4 x "-t")
1288 (=ucs@ks "u" 4 x "-k")
1289 (=ucs@iso "u" 4 x "-u")
1290 (=ucs@unicode "u" 4 x "-us")
1291 (=adobe-japan1-6 "aj1-" 5 d nil)
1293 (=big5-cdp "cdp-" 4 x nil)
1294 (=cbeta "cb" 5 d nil)
1295 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1296 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1297 (=jis-x0208@1978 "j78-" 4 x nil)
1298 (=jis-x0208@1983 "j83-" 4 x nil)
1299 (=jis-x0208@1990 "j90-" 4 x nil)
1300 (=jis-x0212 "jsp-" 4 x nil)
1301 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1302 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1303 (=jis-x0213-2 "jx2-" 4 x nil)
1304 (=cns11643-1 "c1-" 4 x nil)
1305 (=cns11643-2 "c2-" 4 x nil)
1306 (=cns11643-3 "c3-" 4 x nil)
1307 (=cns11643-4 "c4-" 4 x nil)
1308 (=cns11643-5 "c5-" 4 x nil)
1309 (=cns11643-6 "c6-" 4 x nil)
1310 (=cns11643-7 "c7-" 4 x nil)
1311 (=daikanwa "dkw-" 5 d nil)
1312 (=gt-k "gt-k" 5 d nil)
1313 (=jef-china3 "jc3-" 4 x nil)
1314 (=big5 "b-" 4 x nil)
1315 (=ks-x1001 "k0-" 4 x nil)
1318 (defun char-GlyphWiki-id (char)
1319 (let ((rest coded-charset-GlyphWiki-id-alist)
1322 (setq spec (pop rest))
1323 (null (setq ret (char-feature char (car spec))))))
1326 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1328 ((and (or (encode-char char '=jis-x0208@1990)
1329 (encode-char char '=jis-x0212)
1330 (encode-char char '=jis-x0213-1))
1331 (setq code (encode-char char '=ucs@jis)))
1332 (format "u%04x" code)
1334 ((and (or (encode-char char '=gb2312)
1335 (encode-char char '=gb12345))
1336 (setq code (encode-char char '=ucs@gb)))
1337 (format "u%04x-g" code)
1339 ((and (or (encode-char char '=cns11643-1)
1340 (encode-char char '=cns11643-2)
1341 (encode-char char '=cns11643-3)
1342 (encode-char char '=cns11643-4)
1343 (encode-char char '=cns11643-5)
1344 (encode-char char '=cns11643-6)
1345 (encode-char char '=cns11643-7))
1346 (setq code (encode-char char '=ucs@cns)))
1347 (format "u%04x-t" code)
1349 ((and (encode-char char '=ks-x1001)
1350 (setq code (encode-char char '=ucs@ks)))
1351 (format "u%04x-k" code)
1353 (format (format "%s%%0%d%s%s"
1357 (or (nth 4 spec) ""))
1364 (provide 'cwiki-common)
1366 ;;; cwiki-common.el ends here