1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
4 (setq file-name-coding-system 'utf-8-mcs-er)
6 (concord-assign-genre 'creator "/usr/local/var/ruimoku/db")
7 (concord-assign-genre 'bibliography "/usr/local/var/ruimoku/db")
8 (concord-assign-genre 'era "/usr/local/var/ruimoku/db")
9 (concord-assign-genre 'period "/usr/local/var/ruimoku/db")
10 (concord-assign-genre 'journal "/usr/local/var/ruimoku/db")
12 (defvar chise-wiki-view-url "view.cgi")
13 (defvar chise-wiki-edit-url "edit.cgi")
15 (defvar chise-wiki-bitmap-glyphs-url
16 "http://chise.zinbun.kyoto-u.ac.jp/glyphs")
18 (defvar chise-wiki-glyph-cgi-url
19 "http://chise.zinbun.kyoto-u.ac.jp/chisewiki/glyph.cgi")
21 (defvar chise-wiki-displayed-features nil)
23 (defun decode-uri-string (string &optional coding-system)
24 (if (> (length string) 0)
28 (mapconcat (lambda (char)
31 (char-to-string char)))
33 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
34 (setq dest (concat dest
35 (substring string i (match-beginning 0))
38 (string-to-int (match-string 1 string) 16))))
41 (concat dest (substring string i))
44 (defun www-feature-type (feature-name)
45 (or (char-feature-property feature-name 'type)
46 (let ((str (symbol-name feature-name)))
48 ((string-match "\\*note\\(@[^*]+\\)?$" str)
50 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
52 ((string-match "\\*" str)
54 ((string-match "^\\(->\\|<-\\)" str)
56 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
60 (defun www-feature-format (feature-name)
61 (or (char-feature-property feature-name 'format)
63 (setq fn feature-name)
64 (while (and (setq parent (char-feature-name-parent fn))
66 (char-feature-property
70 '((name) " : " (value))))
72 (defun www-feature-value-format (feature-name)
73 (or (char-feature-property feature-name 'value-format)
75 (setq fn feature-name)
76 (while (and (setq parent (char-feature-name-parent fn))
78 (char-feature-property
79 parent 'value-format))))
82 (let ((type (www-feature-type feature-name)))
83 (cond ((eq type 'relation)
84 'space-separated-char-list)
90 (if (find-charset feature-name)
91 (if (and (= (charset-dimension feature-name) 2)
92 (= (charset-chars feature-name) 94))
94 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
95 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
97 (defun char-feature-name-at-domain (feature-name domain)
99 (let ((name (symbol-name feature-name)))
101 ((string-match "@[^*]+$" name)
102 (intern (format "%s/%s" name domain))
105 (intern (format "%s@%s" name domain))
109 (defun char-feature-name-parent (feature-name)
110 (let ((name (symbol-name feature-name)))
111 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
112 (intern (substring name 0 (car (last (match-data) 2)))))))
114 (defun char-feature-name-domain (feature-name)
115 (let ((name (symbol-name feature-name)))
116 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
117 (intern (substring name (1+ (match-beginning 0)))))))
119 (defun char-feature-name-sans-versions (feature)
120 (let ((feature-name (symbol-name feature)))
121 (if (string-match "[@/]\\$rev=latest$" feature-name)
122 (intern (substring feature-name 0 (match-beginning 0)))
125 (defun www-get-feature-value (object feature)
126 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
129 (mount-char-attribute-table latest-feature)
130 (or (char-feature object latest-feature)
131 (char-feature object feature))
134 (or (concord-object-get object latest-feature)
135 (concord-object-get object feature))
138 (defun get-previous-code-point (ccs code)
139 (let ((chars (charset-chars ccs))
140 (dim (charset-dimension ccs))
142 mask byte-min byte-max
165 (setq bytes (make-vector dim 0))
167 (aset bytes i (logand (lsh code (* i -8)) mask))
170 (while (and (< i dim)
172 (aset bytes i (1- (aref bytes i)))
173 (< (aref bytes i) byte-min)))
174 (aset bytes i byte-max)
177 (setq dest (aref bytes 0)
180 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
184 (defun get-next-code-point (ccs code)
185 (let ((chars (charset-chars ccs))
186 (dim (charset-dimension ccs))
188 mask byte-min byte-max
211 (setq bytes (make-vector dim 0))
213 (aset bytes i (logand (lsh code (* i -8)) mask))
216 (while (and (< i dim)
218 (aset bytes i (1+ (aref bytes i)))
219 (> (aref bytes i) byte-max)))
220 (aset bytes i byte-min)
223 (setq dest (aref bytes 0)
226 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
230 (defun find-previous-defined-code-point (ccs code)
231 (let ((i (get-previous-code-point ccs code))
234 ((eq ccs '=jis-x0208)
235 (setq ccs '=jis-x0208@1990))
236 ((eq ccs '=jis-x0213-1)
237 (setq ccs '=jis-x0213-1@2004)))
240 (null (setq char (decode-char ccs i
241 (unless (eq ccs '=ucs)
243 (setq i (get-previous-code-point ccs i)))
246 (defun find-next-defined-code-point (ccs code)
247 (let ((i (get-next-code-point ccs code))
249 (setq max (+ code 1000))
251 ((eq ccs '=jis-x0208)
252 (setq ccs '=jis-x0208@1990))
253 ((eq ccs '=jis-x0213-1)
254 (setq ccs '=jis-x0213-1@2004)))
257 (null (setq char (decode-char ccs i
258 (unless (eq ccs '=ucs)
260 (setq i (get-next-code-point ccs i)))
264 ;;; @ URI representation
267 (defun www-uri-decode-feature-name (uri-feature)
270 ((string-match "^from\\." uri-feature)
271 (intern (format "<-%s" (substring uri-feature (match-end 0))))
273 ((string-match "^to\\." uri-feature)
274 (intern (format "->%s" (substring uri-feature (match-end 0))))
276 ((string-match "^rep\\." uri-feature)
277 (intern (format "=%s" (substring uri-feature (match-end 0))))
279 ((string-match "^g\\." uri-feature)
280 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
282 ((string-match "^gi\\." uri-feature)
283 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
285 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
286 (intern (format "=>>%s%s"
287 (make-string (string-to-int
288 (match-string 1 uri-feature))
290 (substring uri-feature (match-end 0))))
292 ((string-match "^a\\." uri-feature)
293 (intern (format "=>%s" (substring uri-feature (match-end 0))))
295 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
296 (intern (format "%s>%s"
297 (make-string (string-to-int
298 (match-string 1 uri-feature))
300 (substring uri-feature (match-end 0))))
302 ((and (setq feature (intern (format "=>%s" uri-feature)))
303 (find-charset feature))
305 ((and (setq feature (intern (format "=>>%s" uri-feature)))
306 (find-charset feature))
308 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
309 (find-charset feature))
311 ((and (setq feature (intern (format "=%s" uri-feature)))
312 (find-charset feature))
314 (t (intern uri-feature)))))
316 (defun www-uri-encode-feature-name (feature-name)
317 (setq feature-name (symbol-name feature-name))
319 ((string-match "^=\\([^=>]+\\)" feature-name)
320 (concat "rep." (substring feature-name (match-beginning 1)))
322 ((string-match "^=>>\\([^=>]+\\)" feature-name)
323 (concat "g." (substring feature-name (match-beginning 1)))
325 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
326 (concat "gi." (substring feature-name (match-beginning 1)))
328 ((string-match "^=>>\\(>+\\)" feature-name)
330 (length (match-string 1 feature-name))
331 (substring feature-name (match-end 1)))
333 ((string-match "^=>\\([^=>]+\\)" feature-name)
334 (concat "a." (substring feature-name (match-beginning 1)))
336 ((string-match "^\\(=+\\)>" feature-name)
338 (length (match-string 1 feature-name))
339 (substring feature-name (match-end 0)))
341 ((string-match "^->" feature-name)
342 (concat "to." (substring feature-name (match-end 0)))
344 ((string-match "^<-" feature-name)
345 (concat "from." (substring feature-name (match-end 0)))
349 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
350 (format "%s?feature=%s&char=%s"
351 chise-wiki-view-url uri-feature-name uri-char))
353 (defun www-uri-decode-object (genre char-rep)
356 ((string-match "\\(%3A\\|:\\)" char-rep)
357 (setq ccs (substring char-rep 0 (match-beginning 0))
358 cpos (substring char-rep (match-end 0)))
359 (setq ccs (www-uri-decode-feature-name ccs))
361 ((string-match "^0x" cpos)
363 (string-to-number (substring cpos (match-end 0)) 16))
366 (setq cpos (car (read-from-string cpos)))
368 (if (and (eq genre 'character)
370 (decode-char ccs cpos)
371 (concord-decode-object ccs cpos genre))
374 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
376 ((eq genre 'character)
377 (when (= (length char-rep) 1)
381 (concord-decode-object
382 '=id (www-uri-decode-feature-name char-rep) 'feature)
385 (concord-decode-object
386 '=id (car (read-from-string char-rep)) genre)
389 (defun www-uri-encode-object (object)
390 (if (characterp object)
391 (if (encode-char object '=ucs)
394 (format "%%%02X" byte))
395 (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
397 (let ((ccs-list '(; =ucs
398 =cns11643-1 =cns11643-2 =cns11643-3
399 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
401 =jis-x0208 =jis-x0208@1990
404 =jis-x0213-1@2000 =jis-x0213-1@2004
405 =jis-x0208@1983 =jis-x0208@1978
406 =zinbun-oracle =>zinbun-oracle
409 =>>jis-x0208 =>>jis-x0213-1
410 =>jis-x0208 =>jis-x0213-1
417 (setq ccs (pop ccs-list))
418 (not (setq ret (encode-char object ccs 'defined-only)))))
421 (www-uri-encode-feature-name ccs)
423 ((and (setq ccs (car (split-char object)))
424 (setq ret (encode-char object ccs)))
426 (www-uri-encode-feature-name ccs)
429 (format "system-char-id:0x%X"
430 (encode-char object 'system-char-id))
432 (format "rep.id:%s" (concord-object-id object))))
434 (defun est-format-object (object)
435 (if (characterp object)
436 (char-to-string object)
437 (format "%s" (concord-object-id object))))
440 ;;; @ Feature name presentation
443 (defun www-format-feature-name-default (feature-name)
447 (symbol-name feature-name)
451 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
452 (let ((str (symbol-name feature-name))
455 ((string-match "\\*[^*]+$" str)
456 (setq base (substring str 0 (match-beginning 0))
457 meta (substring str (match-beginning 0)))
458 (concat (www-format-feature-name* (intern base) lang)
461 (www-format-feature-name-default feature-name)
464 (defun www-format-feature-name-as-rel-to (feature-name)
465 (concat "\u2192" (substring (symbol-name feature-name) 2)))
467 (defun www-format-feature-name-as-rel-from (feature-name)
468 (concat "\u2190" (substring (symbol-name feature-name) 2)))
470 (defun www-format-feature-name-as-CCS (feature-name)
473 (symbol-name feature-name)
475 (dest (upcase (pop rest))))
476 (when (string-match "^=+>*" dest)
477 (setq dest (concat (substring dest 0 (match-end 0))
479 (substring dest (match-end 0)))))
483 (setq dest (concat dest " " (upcase (pop rest)))))
484 (if (string-match "^[0-9]+$" (car rest))
485 (concat dest "-" (car rest))
486 (concat dest " " (upcase (car rest))))
490 (defun www-format-feature-name* (feature-name &optional lang)
491 (let (name fn parent ret)
494 (char-feature-property
496 (intern (format "name@%s" lang))))
497 (char-feature-property
498 feature-name 'name)))
499 ((and (setq name (symbol-name feature-name))
500 (string-match "\\*" name))
501 (www-format-feature-name-as-metadata feature-name lang))
503 (setq fn feature-name)
504 (while (and (setq parent (char-feature-name-parent fn))
507 (char-feature-property
509 (intern (format "name@%s" lang))))
510 (char-feature-property
515 (concat ret (substring (symbol-name feature-name)
516 (length (symbol-name parent)))))
517 ((find-charset feature-name)
518 (www-format-feature-name-as-CCS feature-name))
519 ((string-match "^\\(->\\)" name)
520 (www-format-feature-name-as-rel-to feature-name))
521 ((string-match "^\\(<-\\)" name)
522 (www-format-feature-name-as-rel-from feature-name))
524 (www-format-feature-name-default feature-name)
528 (defun www-format-feature-name (feature-name &optional lang)
529 (www-format-encode-string
530 (www-format-feature-name* feature-name lang)))
533 ;;; @ Feature value presentation
536 (defun www-format-value-as-kuten (value)
538 (- (lsh value -8) 32)
539 (- (logand value 255) 32)))
541 (defun www-format-value-default (value &optional without-tags)
545 (www-format-encode-string
549 (www-format-encode-string (format "%S" value) without-tags)))
551 (defun www-format-value-as-char-list (value &optional without-tags)
556 (www-format-encode-string
557 (format (if (characterp unit)
562 (let (genre-o name-f ret)
564 (if (characterp unit)
565 (format "<a href=\"%s?char=%s\">%s</a>"
567 (www-uri-encode-object unit)
568 (www-format-encode-string (char-to-string unit)))
569 (format "<a href=\"%s?%s=%s\">%s</a>"
571 (concord-object-genre unit)
572 (concord-object-id unit)
575 (www-get-feature-value
579 (concord-decode-object
581 (concord-object-genre unit)
583 (www-get-feature-value genre-o 'name)
585 (www-format-eval-feature-value
586 unit name-f nil nil nil ret
587 'without-tags 'without-edit)
590 (www-format-encode-string
595 (www-format-encode-string (format "%s" value) without-tags)))
597 (defun www-format-value-as-domain-list (value &optional without-tags)
598 (let (name source0 source num dest rest unit start end ddest)
607 (setq unit (pop rest))
609 (setq name (symbol-name unit)))
614 ((string-match "^zob1968=" name)
615 (setq source (intern (substring name 0 (match-end 0)))
616 num (substring name (match-end 0)))
617 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
618 (setq start (string-to-number
619 (match-string 1 num))
620 end (string-to-number
621 (match-string 2 num)))
622 (setq start (string-to-number num)
625 (if (eq source source0)
627 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
629 (setq source0 source)
631 " <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>"
632 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
634 (setq start (1+ start))
635 (while (<= start end)
640 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
642 (setq start (1+ start)))
646 (if (eq source source0)
648 (setq source0 source)
652 (www-format-encode-string (format "%s" value) without-tags))))
654 (defun www-format-value-as-ids (value &optional without-tags)
659 (www-format-encode-string
660 (format (if (characterp unit)
666 (if (characterp unit)
667 (format "<a href=\"%s?char=%s\">%s</a>"
669 (www-uri-encode-object unit)
670 (www-format-encode-string (char-to-string unit)))
671 (www-format-encode-string (format "%s" unit)))))
672 (ideographic-structure-to-ids value) " ")
673 (www-format-encode-string (format "%s" value) without-tags)))
675 (defun www-format-value-as-S-exp (value &optional without-tags)
676 (www-format-encode-string (format "%S" value) without-tags))
678 (defun www-format-value-as-HEX (value)
681 (www-format-value-as-S-exp value)))
683 (defun www-format-value-as-CCS-default (value)
686 (www-format-value-as-HEX value)
688 (www-format-value-as-S-exp value)))
690 (defun www-format-value-as-CCS-94x94 (value)
692 (format "0x%s [%s] (%d)"
693 (www-format-value-as-HEX value)
694 (www-format-value-as-kuten value)
696 (www-format-value-as-S-exp value)))
698 (defun www-format-value-as-kangxi-radical (value)
699 (if (and (integerp value)
702 (www-format-encode-string
703 (format "%c" (ideographic-radical value)))
704 (www-format-value-as-S-exp value)))
706 (defun www-format-value (object feature-name
707 &optional value format
708 without-tags without-edit)
710 (setq value (www-get-feature-value object feature-name)))
711 (www-format-apply-value object feature-name
712 format nil value nil nil
713 without-tags without-edit)
717 ;;; @ format evaluator
720 (defun www-format-encode-string (string &optional without-tags)
723 (let (plane code start end char variants ret rret)
724 (goto-char (point-min))
725 (while (search-forward "<" nil t)
726 (replace-match "<" nil t))
727 (goto-char (point-min))
728 (while (search-forward ">" nil t)
729 (replace-match ">" nil t))
731 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
732 (let ((coded-charset-entity-reference-alist
735 '(=cns11643-1 "C1-" 4 X)
736 '(=cns11643-2 "C2-" 4 X)
737 '(=cns11643-3 "C3-" 4 X)
738 '(=cns11643-4 "C4-" 4 X)
739 '(=cns11643-5 "C5-" 4 X)
740 '(=cns11643-6 "C6-" 4 X)
741 '(=cns11643-7 "C7-" 4 X)
743 '(=gb12345 "G1-" 4 X)
744 '(=jis-x0208@1990 "J90-" 4 X)
745 '(=jis-x0212 "JSP-" 4 X)
747 '(=jis-x0208@1997 "J97-" 4 X)
748 '(=jis-x0208@1978 "J78-" 4 X)
749 '(=jis-x0208@1983 "J83-" 4 X)
750 '(=ruimoku-v6 "RUI6-" 4 X)
751 '(=zinbun-oracle "ZOB-" 4 d)
752 '(=jef-china3 "JC3-" 4 X)
753 '(=daikanwa "M-" 5 d)
754 coded-charset-entity-reference-alist)))
755 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
757 (goto-char (point-min))
758 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
759 (setq code (string-to-int (match-string 1)))
761 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
763 chise-wiki-bitmap-glyphs-url
767 (goto-char (point-min))
768 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
769 (setq plane (match-string 1)
770 code (string-to-int (match-string 2) 16))
772 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
774 chise-wiki-bitmap-glyphs-url
777 (- (logand code 255) 32))
780 (goto-char (point-min))
781 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
782 (setq plane (string-to-int (match-string 1))
783 code (string-to-int (match-string 2) 16))
785 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
787 chise-wiki-bitmap-glyphs-url
790 (- (logand code 255) 32))
793 (goto-char (point-min))
794 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
795 (setq plane (string-to-int (match-string 1))
796 code (string-to-int (match-string 2) 16))
798 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
800 chise-wiki-bitmap-glyphs-url
804 (goto-char (point-min))
805 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
806 (setq code (string-to-int (match-string 1) 16))
808 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
812 (goto-char (point-min))
813 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
814 (setq code (string-to-int (match-string 2)))
816 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
818 chise-wiki-bitmap-glyphs-url
822 (goto-char (point-min))
823 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
824 (setq code (string-to-int (match-string 2)))
826 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
828 chise-wiki-glyph-cgi-url
832 (goto-char (point-min))
833 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
834 (setq code (string-to-int (match-string 2)))
836 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
838 chise-wiki-glyph-cgi-url
842 (goto-char (point-min))
843 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
844 (setq code (string-to-int (match-string 1) 16))
846 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
848 chise-wiki-glyph-cgi-url
852 (goto-char (point-min))
853 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
854 (setq code (string-to-int (match-string 1) 16))
856 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
858 chise-wiki-glyph-cgi-url
862 (goto-char (point-min))
863 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
864 (setq code (string-to-int (match-string 1) 16))
866 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
868 chise-wiki-glyph-cgi-url
872 (goto-char (point-min))
873 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
874 (setq code (string-to-int (match-string 2) 16))
876 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
881 (goto-char (point-min))
882 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
883 (setq code (string-to-int (match-string 1) 16))
884 (setq start (match-beginning 0)
886 (setq char (decode-char 'system-char-id code))
889 (or (www-get-feature-value char '->subsumptive)
890 (www-get-feature-value char '->denotational)))
893 (setq ret (www-format-encode-string
894 (char-to-string (car variants))))
895 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
896 (setq variants (cdr variants)))
898 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
900 (delete-region start end)
903 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
904 (www-get-feature-value char 'ideographic-structure)))
909 (if (characterp (setq rret (find-char ch)))
912 (www-format-encode-string
913 (char-to-string ch) without-tags)
914 (www-format-encode-string
915 (format "%S" ch) without-tags)))
919 (delete-region start end)
923 ;; (goto-char (point-min))
924 ;; (while (search-forward ">-" nil t)
925 ;; (replace-match "&GT-" t 'literal))
928 (defun www-format-props-to-string (props &optional format)
930 (setq format (plist-get props :format)))
932 (plist-get props :flag)
933 ;; (if (plist-get props :zero-padding)
935 (if (plist-get props :len)
937 (let ((ret (plist-get props :len)))
942 ((eq format 'decimal) "d")
943 ((eq format 'hex) "x")
944 ((eq format 'HEX) "X")
945 ((eq format 'S-exp) "S")
948 (defun www-format-apply-value (object feature-name
950 &optional uri-object uri-feature
951 without-tags without-edit)
955 ((memq format '(decimal hex HEX))
957 (format (www-format-props-to-string props format)
959 (www-format-encode-string
963 ((eq format 'wiki-text)
965 (www-xml-format-list value)
966 (www-format-eval-list value object feature-name nil uri-object
967 without-tags without-edit))
970 (www-format-encode-string
971 (format (www-format-props-to-string props format)
975 (www-format-value-as-kuten value))
976 ((eq format 'kangxi-radical)
977 (www-format-value-as-kangxi-radical value))
978 ((eq format 'space-separated-char-list)
979 (www-format-value-as-char-list value without-tags))
980 ((eq format 'space-separated-ids)
981 (www-format-value-as-ids value without-tags))
982 ((eq format 'space-separated-domain-list)
983 (www-format-value-as-domain-list value without-tags))
985 (www-format-encode-string (format "%s" value) without-tags)
988 (www-format-value-default value without-tags)
993 (eq (plist-get props :mode) 'peek))
995 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
996 ><input type=\"submit\" value=\"edit\" /></a>"
999 uri-object uri-feature format))))
1001 (defun www-format-eval-feature-value (object
1003 &optional format lang uri-object value
1004 without-tags without-edit)
1006 (setq value (www-get-feature-value object feature-name)))
1008 (setq format (www-feature-value-format feature-name)))
1011 (www-format-apply-value
1014 uri-object (www-uri-encode-feature-name feature-name)
1015 without-tags without-edit)
1018 (cond ((null (cdr format))
1019 (setq format (car format))
1020 (www-format-apply-value
1022 (car format) (nth 1 format) value
1023 uri-object (www-uri-encode-feature-name feature-name)
1024 without-tags without-edit)
1027 (www-format-eval-list format object feature-name lang uri-object
1028 without-tags without-edit)
1031 (defun www-format-eval-unit (exp object feature-name
1032 &optional lang uri-object value
1033 without-tags without-edit)
1035 (setq value (www-get-feature-value object feature-name)))
1037 (setq uri-object (www-uri-encode-object object)))
1039 ((stringp exp) (www-format-encode-string exp))
1043 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1044 S-exp string default))
1045 (let ((fn (plist-get (nth 1 exp) :feature))
1046 domain domain-fn ret)
1049 (setq fn (intern fn)))
1050 (setq domain (char-feature-name-domain feature-name))
1051 (setq domain-fn (char-feature-name-at-domain fn domain))
1052 (if (setq ret (www-get-feature-value object domain-fn))
1053 (setq feature-name domain-fn
1055 (setq feature-name fn
1056 value (www-get-feature-value object fn)))
1057 (push feature-name chise-wiki-displayed-features)
1059 (if (eq (car exp) 'value)
1060 (www-format-eval-feature-value object feature-name
1061 (plist-get (nth 1 exp) :format)
1062 lang uri-object value
1063 without-tags without-edit)
1064 (www-format-apply-value
1066 (car exp) (nth 1 exp) value
1067 uri-object (www-uri-encode-feature-name feature-name)
1068 without-tags without-edit))
1070 ((eq (car exp) 'name)
1071 (let ((fn (plist-get (nth 1 exp) :feature))
1074 (setq domain (char-feature-name-domain feature-name))
1076 (setq fn (intern fn)))
1077 (setq domain-fn (char-feature-name-at-domain fn domain))
1078 (setq feature-name domain-fn)))
1080 (www-format-feature-name feature-name lang)
1081 (format "<a href=\"%s\">%s</a>"
1082 (www-uri-make-feature-name-url
1083 (www-uri-encode-feature-name feature-name)
1085 (www-format-feature-name feature-name lang))
1088 ((eq (car exp) 'name-url)
1089 (let ((fn (plist-get (nth 1 exp) :feature))
1092 (setq domain (char-feature-name-domain feature-name))
1094 (setq fn (intern fn)))
1095 (setq domain-fn (char-feature-name-at-domain fn domain))
1096 (setq feature-name domain-fn)))
1097 (www-uri-make-feature-name-url
1098 (www-uri-encode-feature-name feature-name)
1101 ((eq (car exp) 'domain-name)
1102 (let ((domain (char-feature-name-domain feature-name)))
1104 (format "@%s" domain))))
1105 ((eq (car exp) 'prev-char)
1108 (let ((prev-char (find-previous-defined-code-point
1109 feature-name value)))
1111 (format "\n<a href=\"%s?char=%s\">%s</a>"
1113 (www-uri-encode-object prev-char)
1114 "<input type=\"submit\" value=\"-\" />"
1115 ;; (www-format-encode-string
1116 ;; (char-to-string prev-char))
1120 ((eq (car exp) 'next-char)
1123 (let ((next-char (find-next-defined-code-point
1124 feature-name value)))
1126 (format "<a href=\"%s?char=%s\">%s</a>"
1128 (www-uri-encode-object next-char)
1129 "<input type=\"submit\" value=\"+\" />"
1130 ;; (www-format-encode-string
1131 ;; (char-to-string next-char))
1135 ((eq (car exp) 'link)
1137 (www-format-eval-list (nthcdr 2 exp)
1138 object feature-name lang uri-object
1139 without-tags without-edit)
1144 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1145 object feature-name lang uri-object
1146 'without-tags 'without-edit)
1147 (www-format-eval-list (nthcdr 2 exp)
1148 object feature-name lang uri-object
1149 without-tags without-edit)))
1156 (www-format-eval-list (nthcdr 2 exp) object feature-name
1158 without-tags without-edit)
1161 (defun www-format-eval-list (format-list object feature-name
1162 &optional lang uri-object
1163 without-tags without-edit)
1164 (if (consp format-list)
1167 (www-format-eval-unit exp object feature-name lang uri-object
1168 nil without-tags without-edit))
1170 (www-format-eval-unit format-list object feature-name lang uri-object
1171 nil without-tags without-edit)))
1177 (defun www-xml-format-props (props)
1181 (setq key (pop props)
1184 (setq key (symbol-name key)))
1185 (if (eq (aref key 0) ?:)
1186 (setq key (substring key 1)))
1188 (format "%s %s=\"%s\""
1190 (www-format-encode-string
1191 (format "%s" val) 'without-tags))))
1194 (defun www-xml-format-unit (format-unit)
1195 (let (name props children ret)
1197 ((stringp format-unit)
1198 (mapconcat (lambda (c)
1201 ;; ((eq c ?<) "&lt;")
1202 ;; ((eq c ?>) "&gt;")
1204 (char-to-string c))))
1205 (www-format-encode-string format-unit 'without-tags)
1208 ((consp format-unit)
1209 (setq name (car format-unit)
1210 props (nth 1 format-unit)
1211 children (nthcdr 2 format-unit))
1212 (when (eq name 'link)
1213 (setq ret (plist-get props :ref))
1214 (unless (stringp ret)
1215 (setq props (plist-remprop (copy-list props) :ref))
1217 (cons (list* 'ref nil ret)
1220 (format "<%s%s>%s</%s>"
1223 (www-xml-format-props props)
1225 (www-xml-format-list children)
1228 name (www-xml-format-props props)))
1231 (format "%s" format-unit)))))
1233 (defun www-xml-format-list (format-list)
1234 (if (atom format-list)
1235 (www-xml-format-unit format-list)
1236 (mapconcat #'www-xml-format-unit
1240 ;;; @ HTML generator
1243 (defun www-html-display-text (text)
1247 (goto-char (point-min))
1248 (while (search-forward "<" nil t)
1249 (replace-match "<" nil t))
1250 (goto-char (point-min))
1251 (while (search-forward ">" nil t)
1252 (replace-match ">" nil t))
1253 (goto-char (point-min))
1254 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1256 (format "<a href=\"%s\">%s</a>"
1260 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1261 (goto-char (point-min))
1262 (while (search-forward ">-" nil t)
1263 (replace-match "&GT-" nil t))
1266 (defun www-html-display-paragraph (text)
1268 (www-html-display-text text)
1275 (defvar coded-charset-GlyphWiki-id-alist
1276 '((=ucs "u" 4 x nil)
1277 (=ucs@JP "u" 4 x nil)
1278 (=ucs@jis "u" 4 x nil)
1279 (=ucs@gb "u" 4 x "-g")
1280 (=ucs@cns "u" 4 x "-t")
1281 (=ucs@ks "u" 4 x "-k")
1282 (=ucs@iso "u" 4 x "-u")
1283 (=ucs@unicode "u" 4 x "-us")
1284 (=adobe-japan1-6 "aj1-" 5 d nil)
1286 (=big5-cdp "cdp-" 4 x nil)
1287 (=cbeta "cb" 5 d nil)
1288 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1289 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1290 (=jis-x0208@1978 "j78-" 4 x nil)
1291 (=jis-x0208@1983 "j83-" 4 x nil)
1292 (=jis-x0208@1990 "j90-" 4 x nil)
1293 (=jis-x0212 "jsp-" 4 x nil)
1294 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1295 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1296 (=jis-x0213-2 "jx2-" 4 x nil)
1297 (=cns11643-1 "c1-" 4 x nil)
1298 (=cns11643-2 "c2-" 4 x nil)
1299 (=cns11643-3 "c3-" 4 x nil)
1300 (=cns11643-4 "c4-" 4 x nil)
1301 (=cns11643-5 "c5-" 4 x nil)
1302 (=cns11643-6 "c6-" 4 x nil)
1303 (=cns11643-7 "c7-" 4 x nil)
1304 (=daikanwa "dkw-" 5 d nil)
1305 (=gt-k "gt-k" 5 d nil)
1306 (=jef-china3 "jc3-" 4 x nil)
1307 (=big5 "b-" 4 x nil)
1308 (=ks-x1001 "k0-" 4 x nil)
1311 (defun char-GlyphWiki-id (char)
1312 (let ((rest coded-charset-GlyphWiki-id-alist)
1315 (setq spec (pop rest))
1316 (null (setq ret (char-feature char (car spec))))))
1319 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1321 ((and (or (encode-char char '=jis-x0208@1990)
1322 (encode-char char '=jis-x0212)
1323 (encode-char char '=jis-x0213-1))
1324 (setq code (encode-char char '=ucs@jis)))
1325 (format "u%04x" code)
1327 ((and (or (encode-char char '=gb2312)
1328 (encode-char char '=gb12345))
1329 (setq code (encode-char char '=ucs@gb)))
1330 (format "u%04x-g" code)
1332 ((and (or (encode-char char '=cns11643-1)
1333 (encode-char char '=cns11643-2)
1334 (encode-char char '=cns11643-3)
1335 (encode-char char '=cns11643-4)
1336 (encode-char char '=cns11643-5)
1337 (encode-char char '=cns11643-6)
1338 (encode-char char '=cns11643-7))
1339 (setq code (encode-char char '=ucs@cns)))
1340 (format "u%04x-t" code)
1342 ((and (encode-char char '=ks-x1001)
1343 (setq code (encode-char char '=ucs@ks)))
1344 (format "u%04x-k" code)
1346 (format (format "%s%%0%d%s%s"
1350 (or (nth 4 spec) ""))
1357 (provide 'cwiki-common)
1359 ;;; cwiki-common.el ends here