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 'region@ruimoku "/usr/local/var/ruimoku/db")
15 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
17 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
20 (defvar chise-wiki-view-url "view.cgi")
21 (defvar chise-wiki-edit-url "edit.cgi")
23 (defvar chise-wiki-bitmap-glyphs-url
24 "http://chise.zinbun.kyoto-u.ac.jp/glyphs")
26 (defvar chise-wiki-glyph-cgi-url
27 "http://chise.zinbun.kyoto-u.ac.jp/chisewiki/glyph.cgi")
29 (defvar chise-wiki-displayed-features nil)
31 (defun decode-uri-string (string &optional coding-system)
32 (if (> (length string) 0)
36 (mapconcat (lambda (char)
39 (char-to-string char)))
41 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
42 (setq dest (concat dest
43 (substring string i (match-beginning 0))
46 (string-to-int (match-string 1 string) 16))))
49 (concat dest (substring string i))
52 (defun www-feature-type (feature-name)
53 (or (char-feature-property feature-name 'type)
54 (let ((str (symbol-name feature-name)))
56 ((string-match "\\*note\\(@[^*]+\\)?$" str)
58 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
60 ((string-match "\\*" str)
62 ((string-match "^\\(->\\|<-\\)" str)
64 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
68 (defun www-feature-format (feature-name)
69 (or (char-feature-property feature-name 'format)
71 (setq fn feature-name)
72 (while (and (setq parent (char-feature-name-parent fn))
74 (char-feature-property
78 '((name) " : " (value))))
80 (defun www-feature-value-format (feature-name)
81 (or (char-feature-property feature-name 'value-format)
83 (setq fn feature-name)
84 (while (and (setq parent (char-feature-name-parent fn))
86 (char-feature-property
87 parent 'value-format))))
90 (let ((type (www-feature-type feature-name)))
91 (cond ((eq type 'relation)
92 'space-separated-char-list)
98 (if (find-charset feature-name)
99 (if (and (= (charset-dimension feature-name) 2)
100 (= (charset-chars feature-name) 94))
102 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
103 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
105 (defun char-feature-name-at-domain (feature-name domain)
107 (let ((name (symbol-name feature-name)))
109 ((string-match "@[^*]+$" name)
110 (intern (format "%s/%s" name domain))
113 (intern (format "%s@%s" name domain))
117 (defun char-feature-name-parent (feature-name)
118 (let ((name (symbol-name feature-name)))
119 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
120 (intern (substring name 0 (car (last (match-data) 2)))))))
122 (defun char-feature-name-domain (feature-name)
123 (let ((name (symbol-name feature-name)))
124 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
125 (intern (substring name (1+ (match-beginning 0)))))))
127 (defun char-feature-name-sans-versions (feature)
128 (let ((feature-name (symbol-name feature)))
129 (if (string-match "[@/]\\$rev=latest$" feature-name)
130 (intern (substring feature-name 0 (match-beginning 0)))
133 (defun www-get-feature-value (object feature)
134 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
137 (mount-char-attribute-table latest-feature)
138 (or (char-feature object latest-feature)
139 (char-feature object feature))
142 (or (condition-case nil
143 (concord-object-get object latest-feature)
146 (concord-object-get object feature)
150 (defun get-previous-code-point (ccs code)
151 (let ((chars (charset-chars ccs))
152 (dim (charset-dimension ccs))
154 mask byte-min byte-max
177 (setq bytes (make-vector dim 0))
179 (aset bytes i (logand (lsh code (* i -8)) mask))
182 (while (and (< i dim)
184 (aset bytes i (1- (aref bytes i)))
185 (< (aref bytes i) byte-min)))
186 (aset bytes i byte-max)
189 (setq dest (aref bytes 0)
192 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
196 (defun get-next-code-point (ccs code)
197 (let ((chars (charset-chars ccs))
198 (dim (charset-dimension ccs))
200 mask byte-min byte-max
223 (setq bytes (make-vector dim 0))
225 (aset bytes i (logand (lsh code (* i -8)) mask))
228 (while (and (< i dim)
230 (aset bytes i (1+ (aref bytes i)))
231 (> (aref bytes i) byte-max)))
232 (aset bytes i byte-min)
235 (setq dest (aref bytes 0)
238 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
242 (defun find-previous-defined-code-point (ccs code)
243 (let ((i (get-previous-code-point ccs code))
246 ((eq ccs '=jis-x0208)
247 (setq ccs '=jis-x0208@1990))
248 ((eq ccs '=jis-x0213-1)
249 (setq ccs '=jis-x0213-1@2004)))
252 (null (setq char (decode-char ccs i
253 (unless (eq ccs '=ucs)
255 (setq i (get-previous-code-point ccs i)))
258 (defun find-next-defined-code-point (ccs code)
259 (let ((i (get-next-code-point ccs code))
261 (setq max (+ code 1000))
263 ((eq ccs '=jis-x0208)
264 (setq ccs '=jis-x0208@1990))
265 ((eq ccs '=jis-x0213-1)
266 (setq ccs '=jis-x0213-1@2004)))
269 (null (setq char (decode-char ccs i
270 (unless (eq ccs '=ucs)
272 (setq i (get-next-code-point ccs i)))
276 ;;; @ URI representation
279 (defun www-uri-decode-feature-name (uri-feature)
282 ((string-match "^from\\." uri-feature)
283 (intern (format "<-%s" (substring uri-feature (match-end 0))))
285 ((string-match "^to\\." uri-feature)
286 (intern (format "->%s" (substring uri-feature (match-end 0))))
288 ((string-match "^rep\\." uri-feature)
289 (intern (format "=%s" (substring uri-feature (match-end 0))))
291 ((string-match "^g\\." uri-feature)
292 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
294 ((string-match "^gi\\." uri-feature)
295 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
297 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
298 (intern (format "=>>%s%s"
299 (make-string (string-to-int
300 (match-string 1 uri-feature))
302 (substring uri-feature (match-end 0))))
304 ((string-match "^a\\." uri-feature)
305 (intern (format "=>%s" (substring uri-feature (match-end 0))))
307 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
308 (intern (format "%s>%s"
309 (make-string (string-to-int
310 (match-string 1 uri-feature))
312 (substring uri-feature (match-end 0))))
314 ((and (setq feature (intern (format "=>%s" uri-feature)))
315 (find-charset feature))
317 ((and (setq feature (intern (format "=>>%s" uri-feature)))
318 (find-charset feature))
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 (t (intern uri-feature)))))
328 (defun www-uri-encode-feature-name (feature-name)
329 (setq feature-name (symbol-name feature-name))
331 ((string-match "^=\\([^=>]+\\)" feature-name)
332 (concat "rep." (substring feature-name (match-beginning 1)))
334 ((string-match "^=>>\\([^=>]+\\)" feature-name)
335 (concat "g." (substring feature-name (match-beginning 1)))
337 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
338 (concat "gi." (substring feature-name (match-beginning 1)))
340 ((string-match "^=>>\\(>+\\)" feature-name)
342 (length (match-string 1 feature-name))
343 (substring feature-name (match-end 1)))
345 ((string-match "^=>\\([^=>]+\\)" feature-name)
346 (concat "a." (substring feature-name (match-beginning 1)))
348 ((string-match "^\\(=+\\)>" feature-name)
350 (length (match-string 1 feature-name))
351 (substring feature-name (match-end 0)))
353 ((string-match "^->" feature-name)
354 (concat "to." (substring feature-name (match-end 0)))
356 ((string-match "^<-" feature-name)
357 (concat "from." (substring feature-name (match-end 0)))
361 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
362 (format "%s?feature=%s&char=%s"
363 chise-wiki-view-url uri-feature-name uri-char))
365 (defun www-uri-decode-object (genre char-rep)
368 ((string-match "\\(%3A\\|:\\)" char-rep)
369 (setq ccs (substring char-rep 0 (match-beginning 0))
370 cpos (substring char-rep (match-end 0)))
371 (setq ccs (www-uri-decode-feature-name ccs))
373 ((string-match "^0x" cpos)
375 (string-to-number (substring cpos (match-end 0)) 16))
378 (setq cpos (car (read-from-string cpos)))
380 (if (and (eq genre 'character)
382 (decode-char ccs cpos)
383 (concord-decode-object ccs cpos genre))
386 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
388 ((eq genre 'character)
389 (when (= (length char-rep) 1)
393 (concord-decode-object
394 '=id (www-uri-decode-feature-name char-rep) 'feature)
397 (concord-decode-object
398 '=id (car (read-from-string char-rep)) genre)
401 (defun www-uri-encode-object (object)
402 (if (characterp object)
403 (if (encode-char object '=ucs)
406 (format "%%%02X" byte))
407 (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
409 (let ((ccs-list '(; =ucs
410 =cns11643-1 =cns11643-2 =cns11643-3
411 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
413 =jis-x0208 =jis-x0208@1990
416 =jis-x0213-1@2000 =jis-x0213-1@2004
417 =jis-x0208@1983 =jis-x0208@1978
418 =zinbun-oracle =>zinbun-oracle
421 =>>jis-x0208 =>>jis-x0213-1
422 =>jis-x0208 =>jis-x0213-1
429 (setq ccs (pop ccs-list))
430 (not (setq ret (encode-char object ccs 'defined-only)))))
433 (www-uri-encode-feature-name ccs)
435 ((and (setq ccs (car (split-char object)))
436 (setq ret (encode-char object ccs)))
438 (www-uri-encode-feature-name ccs)
441 (format "system-char-id:0x%X"
442 (encode-char object 'system-char-id))
444 (format "rep.id:%s" (concord-object-id object))))
446 (defun est-format-object (object)
447 (if (characterp object)
448 (char-to-string object)
449 (format "%s" (concord-object-id object))))
452 ;;; @ Feature name presentation
455 (defun www-format-feature-name-default (feature-name)
459 (symbol-name feature-name)
463 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
464 (let ((str (symbol-name feature-name))
467 ((string-match "\\*[^*]+$" str)
468 (setq base (substring str 0 (match-beginning 0))
469 meta (substring str (match-beginning 0)))
470 (concat (www-format-feature-name* (intern base) lang)
473 (www-format-feature-name-default feature-name)
476 (defun www-format-feature-name-as-rel-to (feature-name)
477 (concat "\u2192" (substring (symbol-name feature-name) 2)))
479 (defun www-format-feature-name-as-rel-from (feature-name)
480 (concat "\u2190" (substring (symbol-name feature-name) 2)))
482 (defun www-format-feature-name-as-CCS (feature-name)
485 (symbol-name feature-name)
487 (dest (upcase (pop rest))))
488 (when (string-match "^=+>*" dest)
489 (setq dest (concat (substring dest 0 (match-end 0))
491 (substring dest (match-end 0)))))
495 (setq dest (concat dest " " (upcase (pop rest)))))
496 (if (string-match "^[0-9]+$" (car rest))
497 (concat dest "-" (car rest))
498 (concat dest " " (upcase (car rest))))
502 (defun www-format-feature-name* (feature-name &optional lang)
503 (let (name fn parent ret)
506 (char-feature-property
508 (intern (format "name@%s" lang))))
509 (char-feature-property
510 feature-name 'name)))
511 ((and (setq name (symbol-name feature-name))
512 (string-match "\\*" name))
513 (www-format-feature-name-as-metadata feature-name lang))
515 (setq fn feature-name)
516 (while (and (setq parent (char-feature-name-parent fn))
519 (char-feature-property
521 (intern (format "name@%s" lang))))
522 (char-feature-property
527 (concat ret (substring (symbol-name feature-name)
528 (length (symbol-name parent)))))
529 ((find-charset feature-name)
530 (www-format-feature-name-as-CCS feature-name))
531 ((string-match "^\\(->\\)" name)
532 (www-format-feature-name-as-rel-to feature-name))
533 ((string-match "^\\(<-\\)" name)
534 (www-format-feature-name-as-rel-from feature-name))
536 (www-format-feature-name-default feature-name)
540 (defun www-format-feature-name (feature-name &optional lang)
541 (www-format-encode-string
542 (www-format-feature-name* feature-name lang)))
545 ;;; @ Feature value presentation
548 (defun www-format-value-as-kuten (value)
550 (- (lsh value -8) 32)
551 (- (logand value 255) 32)))
553 (defun www-format-value-default (value &optional without-tags)
557 (www-format-encode-string
561 (www-format-encode-string (format "%S" value) without-tags)))
563 (defun www-format-value-as-char-list (value &optional without-tags)
568 (www-format-encode-string
569 (format (if (characterp unit)
574 (let (genre-o name-f ret)
576 (if (characterp unit)
577 (format "<a href=\"%s?char=%s\">%s</a>"
579 (www-uri-encode-object unit)
580 (www-format-encode-string (char-to-string unit)))
581 (format "<a href=\"%s?%s=%s\">%s</a>"
583 (concord-object-genre unit)
584 (concord-object-id unit)
587 (www-get-feature-value
591 (concord-decode-object
593 (concord-object-genre unit)
595 (www-get-feature-value
597 'object-representation-format)
599 (www-format-eval-feature-value
600 unit name-f nil nil nil ret
601 'without-tags 'without-edit)
604 (www-format-encode-string
609 (www-format-encode-string (format "%s" value) without-tags)))
611 (defun www-format-value-as-domain-list (value &optional without-tags)
612 (let (name source0 source num dest rest unit start end ddest)
621 (setq unit (pop rest))
623 (setq name (symbol-name unit)))
628 ((string-match "^zob1968=" name)
629 (setq source (intern (substring name 0 (match-end 0)))
630 num (substring name (match-end 0)))
631 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
632 (setq start (string-to-number
633 (match-string 1 num))
634 end (string-to-number
635 (match-string 2 num)))
636 (setq start (string-to-number num)
639 (if (eq source source0)
641 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
643 (setq source0 source)
645 " <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>"
646 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
648 (setq start (1+ start))
649 (while (<= start end)
654 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
656 (setq start (1+ start)))
660 (if (eq source source0)
662 (setq source0 source)
666 (www-format-encode-string (format "%s" value) without-tags))))
668 (defun www-format-value-as-ids (value &optional without-tags)
673 (www-format-encode-string
674 (format (if (characterp unit)
680 (if (characterp unit)
681 (format "<a href=\"%s?char=%s\">%s</a>"
683 (www-uri-encode-object unit)
684 (www-format-encode-string (char-to-string unit)))
685 (www-format-encode-string (format "%s" unit)))))
686 (ideographic-structure-to-ids value) " ")
687 (www-format-encode-string (format "%s" value) without-tags)))
689 (defun www-format-value-as-S-exp (value &optional without-tags)
690 (www-format-encode-string (format "%S" value) without-tags))
692 (defun www-format-value-as-HEX (value)
695 (www-format-value-as-S-exp value)))
697 (defun www-format-value-as-CCS-default (value)
700 (www-format-value-as-HEX value)
702 (www-format-value-as-S-exp value)))
704 (defun www-format-value-as-CCS-94x94 (value)
706 (format "0x%s [%s] (%d)"
707 (www-format-value-as-HEX value)
708 (www-format-value-as-kuten value)
710 (www-format-value-as-S-exp value)))
712 (defun www-format-value-as-kangxi-radical (value)
713 (if (and (integerp value)
716 (www-format-encode-string
717 (format "%c" (ideographic-radical value)))
718 (www-format-value-as-S-exp value)))
720 (defun www-format-value (object feature-name
721 &optional value format
722 without-tags without-edit)
724 (setq value (www-get-feature-value object feature-name)))
725 (www-format-apply-value object feature-name
726 format nil value nil nil
727 without-tags without-edit)
731 ;;; @ format evaluator
734 (defun www-format-encode-string (string &optional without-tags)
737 (let (plane code start end char variants ret rret)
738 (goto-char (point-min))
739 (while (search-forward "<" nil t)
740 (replace-match "<" nil t))
741 (goto-char (point-min))
742 (while (search-forward ">" nil t)
743 (replace-match ">" nil t))
745 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
746 (let ((coded-charset-entity-reference-alist
749 '(=cns11643-1 "C1-" 4 X)
750 '(=cns11643-2 "C2-" 4 X)
751 '(=cns11643-3 "C3-" 4 X)
752 '(=cns11643-4 "C4-" 4 X)
753 '(=cns11643-5 "C5-" 4 X)
754 '(=cns11643-6 "C6-" 4 X)
755 '(=cns11643-7 "C7-" 4 X)
757 '(=gb12345 "G1-" 4 X)
758 '(=jis-x0208@1990 "J90-" 4 X)
759 '(=jis-x0212 "JSP-" 4 X)
761 '(=jis-x0208@1997 "J97-" 4 X)
762 '(=jis-x0208@1978 "J78-" 4 X)
763 '(=jis-x0208@1983 "J83-" 4 X)
764 '(=ruimoku-v6 "RUI6-" 4 X)
765 '(=zinbun-oracle "ZOB-" 4 d)
766 '(=jef-china3 "JC3-" 4 X)
767 '(=daikanwa "M-" 5 d)
768 coded-charset-entity-reference-alist)))
769 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
771 (goto-char (point-min))
772 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
773 (setq code (string-to-int (match-string 1)))
775 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
777 chise-wiki-bitmap-glyphs-url
781 (goto-char (point-min))
782 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
783 (setq plane (match-string 1)
784 code (string-to-int (match-string 2) 16))
786 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
788 chise-wiki-bitmap-glyphs-url
791 (- (logand code 255) 32))
794 (goto-char (point-min))
795 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
796 (setq plane (string-to-int (match-string 1))
797 code (string-to-int (match-string 2) 16))
799 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
801 chise-wiki-bitmap-glyphs-url
804 (- (logand code 255) 32))
807 (goto-char (point-min))
808 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
809 (setq plane (string-to-int (match-string 1))
810 code (string-to-int (match-string 2) 16))
812 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
814 chise-wiki-bitmap-glyphs-url
818 (goto-char (point-min))
819 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
820 (setq code (string-to-int (match-string 1) 16))
822 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
826 (goto-char (point-min))
827 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
828 (setq code (string-to-int (match-string 2)))
830 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
832 chise-wiki-bitmap-glyphs-url
836 (goto-char (point-min))
837 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
838 (setq code (string-to-int (match-string 2)))
840 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
842 chise-wiki-glyph-cgi-url
846 (goto-char (point-min))
847 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
848 (setq code (string-to-int (match-string 2)))
850 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
852 chise-wiki-glyph-cgi-url
856 (goto-char (point-min))
857 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
858 (setq code (string-to-int (match-string 1) 16))
860 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
862 chise-wiki-glyph-cgi-url
866 (goto-char (point-min))
867 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
868 (setq code (string-to-int (match-string 1) 16))
870 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
872 chise-wiki-glyph-cgi-url
876 (goto-char (point-min))
877 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
878 (setq code (string-to-int (match-string 1) 16))
880 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
882 chise-wiki-glyph-cgi-url
886 (goto-char (point-min))
887 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
888 (setq code (string-to-int (match-string 2) 16))
890 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
895 (goto-char (point-min))
896 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
897 (setq code (string-to-int (match-string 1) 16))
898 (setq start (match-beginning 0)
900 (setq char (decode-char 'system-char-id code))
903 (or (www-get-feature-value char '->subsumptive)
904 (www-get-feature-value char '->denotational)))
907 (setq ret (www-format-encode-string
908 (char-to-string (car variants))))
909 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
910 (setq variants (cdr variants)))
912 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
914 (delete-region start end)
917 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
918 (www-get-feature-value char 'ideographic-structure)))
923 (if (characterp (setq rret (find-char ch)))
926 (www-format-encode-string
927 (char-to-string ch) without-tags)
928 (www-format-encode-string
929 (format "%S" ch) without-tags)))
933 (delete-region start end)
937 ;; (goto-char (point-min))
938 ;; (while (search-forward ">-" nil t)
939 ;; (replace-match "&GT-" t 'literal))
942 (defun www-format-props-to-string (props &optional format)
944 (setq format (plist-get props :format)))
946 (plist-get props :flag)
947 ;; (if (plist-get props :zero-padding)
949 (if (plist-get props :len)
951 (let ((ret (plist-get props :len)))
956 ((eq format 'decimal) "d")
957 ((eq format 'hex) "x")
958 ((eq format 'HEX) "X")
959 ((eq format 'S-exp) "S")
962 (defun www-format-apply-value (object feature-name
964 &optional uri-object uri-feature
965 without-tags without-edit)
969 ((memq format '(decimal hex HEX))
971 (format (www-format-props-to-string props format)
973 (www-format-encode-string
977 ((eq format 'wiki-text)
979 (www-xml-format-list value)
980 (www-format-eval-list value object feature-name nil uri-object
981 without-tags without-edit))
984 (www-format-encode-string
985 (format (www-format-props-to-string props format)
989 (www-format-value-as-kuten value))
990 ((eq format 'kangxi-radical)
991 (www-format-value-as-kangxi-radical value))
992 ((eq format 'space-separated-char-list)
993 (www-format-value-as-char-list value without-tags))
994 ((eq format 'space-separated-ids)
995 (www-format-value-as-ids value without-tags))
996 ((eq format 'space-separated-domain-list)
997 (www-format-value-as-domain-list value without-tags))
999 (www-format-encode-string (format "%s" value) without-tags)
1002 (www-format-value-default value without-tags)
1005 (if (or without-tags
1007 (eq (plist-get props :mode) 'peek))
1009 (format "%s <a href=\"%s?%s=%s&feature=%s&format=%s\"
1010 ><input type=\"submit\" value=\"edit\" /></a>"
1013 (concord-object-genre object)
1014 uri-object uri-feature format))))
1016 (defun www-format-eval-feature-value (object
1018 &optional format lang uri-object value
1019 without-tags without-edit)
1021 (setq value (www-get-feature-value object feature-name)))
1023 (setq format (www-feature-value-format feature-name)))
1026 (www-format-apply-value
1029 uri-object (www-uri-encode-feature-name feature-name)
1030 without-tags without-edit)
1033 (cond ((null (cdr format))
1034 (setq format (car format))
1035 (www-format-apply-value
1037 (car format) (nth 1 format) value
1038 uri-object (www-uri-encode-feature-name feature-name)
1039 without-tags without-edit)
1042 (www-format-eval-list format object feature-name lang uri-object
1043 without-tags without-edit)
1046 (defun www-format-eval-unit (exp object feature-name
1047 &optional lang uri-object value
1048 without-tags without-edit)
1050 (setq value (www-get-feature-value object feature-name)))
1052 (setq uri-object (www-uri-encode-object object)))
1054 ((stringp exp) (www-format-encode-string exp))
1058 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1059 S-exp string default))
1060 (let ((fn (plist-get (nth 1 exp) :feature))
1061 domain domain-fn ret)
1064 (setq fn (intern fn)))
1065 (setq domain (char-feature-name-domain feature-name))
1066 (setq domain-fn (char-feature-name-at-domain fn domain))
1067 (if (setq ret (www-get-feature-value object domain-fn))
1068 (setq feature-name domain-fn
1070 (setq feature-name fn
1071 value (www-get-feature-value object fn)))
1072 (push feature-name chise-wiki-displayed-features)
1074 (if (eq (car exp) 'value)
1075 (www-format-eval-feature-value object feature-name
1076 (plist-get (nth 1 exp) :format)
1077 lang uri-object value
1078 without-tags without-edit)
1079 (www-format-apply-value
1081 (car exp) (nth 1 exp) value
1082 uri-object (www-uri-encode-feature-name feature-name)
1083 without-tags without-edit))
1085 ((eq (car exp) 'name)
1086 (let ((fn (plist-get (nth 1 exp) :feature))
1089 (setq domain (char-feature-name-domain feature-name))
1091 (setq fn (intern fn)))
1092 (setq domain-fn (char-feature-name-at-domain fn domain))
1093 (setq feature-name domain-fn)))
1095 (www-format-feature-name feature-name lang)
1096 (format "<a href=\"%s\">%s</a>"
1097 (www-uri-make-feature-name-url
1098 (www-uri-encode-feature-name feature-name)
1100 (www-format-feature-name feature-name lang))
1103 ((eq (car exp) 'name-url)
1104 (let ((fn (plist-get (nth 1 exp) :feature))
1107 (setq domain (char-feature-name-domain feature-name))
1109 (setq fn (intern fn)))
1110 (setq domain-fn (char-feature-name-at-domain fn domain))
1111 (setq feature-name domain-fn)))
1112 (www-uri-make-feature-name-url
1113 (www-uri-encode-feature-name feature-name)
1116 ((eq (car exp) 'domain-name)
1117 (let ((domain (char-feature-name-domain feature-name)))
1119 (format "@%s" domain))))
1120 ((eq (car exp) 'prev-char)
1123 (let ((prev-char (find-previous-defined-code-point
1124 feature-name value)))
1126 (format "\n<a href=\"%s?char=%s\">%s</a>"
1128 (www-uri-encode-object prev-char)
1129 "<input type=\"submit\" value=\"-\" />"
1130 ;; (www-format-encode-string
1131 ;; (char-to-string prev-char))
1135 ((eq (car exp) 'next-char)
1138 (let ((next-char (find-next-defined-code-point
1139 feature-name value)))
1141 (format "<a href=\"%s?char=%s\">%s</a>"
1143 (www-uri-encode-object next-char)
1144 "<input type=\"submit\" value=\"+\" />"
1145 ;; (www-format-encode-string
1146 ;; (char-to-string next-char))
1150 ((eq (car exp) 'link)
1152 (www-format-eval-list (nthcdr 2 exp)
1153 object feature-name lang uri-object
1154 without-tags without-edit)
1159 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1160 object feature-name lang uri-object
1161 'without-tags 'without-edit)
1162 (www-format-eval-list (nthcdr 2 exp)
1163 object feature-name lang uri-object
1164 without-tags without-edit)))
1171 (www-format-eval-list (nthcdr 2 exp) object feature-name
1173 without-tags without-edit)
1176 (defun www-format-eval-list (format-list object feature-name
1177 &optional lang uri-object
1178 without-tags without-edit)
1179 (if (consp format-list)
1182 (www-format-eval-unit exp object feature-name lang uri-object
1183 nil without-tags without-edit))
1185 (www-format-eval-unit format-list object feature-name lang uri-object
1186 nil without-tags without-edit)))
1192 (defun www-xml-format-props (props)
1196 (setq key (pop props)
1199 (setq key (symbol-name key)))
1200 (if (eq (aref key 0) ?:)
1201 (setq key (substring key 1)))
1203 (format "%s %s=\"%s\""
1205 (www-format-encode-string
1206 (format "%s" val) 'without-tags))))
1209 (defun www-xml-format-unit (format-unit)
1210 (let (name props children ret)
1212 ((stringp format-unit)
1213 (mapconcat (lambda (c)
1216 ;; ((eq c ?<) "&lt;")
1217 ;; ((eq c ?>) "&gt;")
1219 (char-to-string c))))
1220 (www-format-encode-string format-unit 'without-tags)
1223 ((consp format-unit)
1224 (setq name (car format-unit)
1225 props (nth 1 format-unit)
1226 children (nthcdr 2 format-unit))
1227 (when (eq name 'link)
1228 (setq ret (plist-get props :ref))
1229 (unless (stringp ret)
1230 (setq props (plist-remprop (copy-list props) :ref))
1232 (cons (list* 'ref nil ret)
1235 (format "<%s%s>%s</%s>"
1238 (www-xml-format-props props)
1240 (www-xml-format-list children)
1243 name (www-xml-format-props props)))
1246 (format "%s" format-unit)))))
1248 (defun www-xml-format-list (format-list)
1249 (if (atom format-list)
1250 (www-xml-format-unit format-list)
1251 (mapconcat #'www-xml-format-unit
1255 ;;; @ HTML generator
1258 (defun www-html-display-text (text)
1262 (goto-char (point-min))
1263 (while (search-forward "<" nil t)
1264 (replace-match "<" nil t))
1265 (goto-char (point-min))
1266 (while (search-forward ">" nil t)
1267 (replace-match ">" nil t))
1268 (goto-char (point-min))
1269 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1271 (format "<a href=\"%s\">%s</a>"
1275 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1276 (goto-char (point-min))
1277 (while (search-forward ">-" nil t)
1278 (replace-match "&GT-" nil t))
1281 (defun www-html-display-paragraph (text)
1283 (www-html-display-text text)
1290 (defvar coded-charset-GlyphWiki-id-alist
1291 '((=ucs "u" 4 x nil)
1292 (=ucs@JP "u" 4 x nil)
1293 (=ucs@jis "u" 4 x nil)
1294 (=ucs@gb "u" 4 x "-g")
1295 (=ucs@cns "u" 4 x "-t")
1296 (=ucs@ks "u" 4 x "-k")
1297 (=ucs@iso "u" 4 x "-u")
1298 (=ucs@unicode "u" 4 x "-us")
1299 (=adobe-japan1-6 "aj1-" 5 d nil)
1301 (=big5-cdp "cdp-" 4 x nil)
1302 (=cbeta "cb" 5 d nil)
1303 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1304 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1305 (=jis-x0208@1978 "j78-" 4 x nil)
1306 (=jis-x0208@1983 "j83-" 4 x nil)
1307 (=jis-x0208@1990 "j90-" 4 x nil)
1308 (=jis-x0212 "jsp-" 4 x nil)
1309 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1310 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1311 (=jis-x0213-2 "jx2-" 4 x nil)
1312 (=cns11643-1 "c1-" 4 x nil)
1313 (=cns11643-2 "c2-" 4 x nil)
1314 (=cns11643-3 "c3-" 4 x nil)
1315 (=cns11643-4 "c4-" 4 x nil)
1316 (=cns11643-5 "c5-" 4 x nil)
1317 (=cns11643-6 "c6-" 4 x nil)
1318 (=cns11643-7 "c7-" 4 x nil)
1319 (=daikanwa "dkw-" 5 d nil)
1320 (=gt-k "gt-k" 5 d nil)
1321 (=jef-china3 "jc3-" 4 x nil)
1322 (=big5 "b-" 4 x nil)
1323 (=ks-x1001 "k0-" 4 x nil)
1326 (defun char-GlyphWiki-id (char)
1327 (let ((rest coded-charset-GlyphWiki-id-alist)
1330 (setq spec (pop rest))
1331 (null (setq ret (char-feature char (car spec))))))
1334 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1336 ((and (or (encode-char char '=jis-x0208@1990)
1337 (encode-char char '=jis-x0212)
1338 (encode-char char '=jis-x0213-1))
1339 (setq code (encode-char char '=ucs@jis)))
1340 (format "u%04x" code)
1342 ((and (or (encode-char char '=gb2312)
1343 (encode-char char '=gb12345))
1344 (setq code (encode-char char '=ucs@gb)))
1345 (format "u%04x-g" code)
1347 ((and (or (encode-char char '=cns11643-1)
1348 (encode-char char '=cns11643-2)
1349 (encode-char char '=cns11643-3)
1350 (encode-char char '=cns11643-4)
1351 (encode-char char '=cns11643-5)
1352 (encode-char char '=cns11643-6)
1353 (encode-char char '=cns11643-7))
1354 (setq code (encode-char char '=ucs@cns)))
1355 (format "u%04x-t" code)
1357 ((and (encode-char char '=ks-x1001)
1358 (setq code (encode-char char '=ucs@ks)))
1359 (format "u%04x-k" code)
1361 (format (format "%s%%0%d%s%s"
1365 (or (nth 4 spec) ""))
1372 (provide 'cwiki-common)
1374 ;;; cwiki-common.el ends here