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-get-genre (object)
45 (if (characterp object)
49 (defun www-feature-type (feature-name)
50 (or (char-feature-property feature-name 'type)
51 (let ((str (symbol-name feature-name)))
53 ((string-match "\\*note\\(@[^*]+\\)?$" str)
55 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
57 ((string-match "\\*" str)
59 ((string-match "^\\(->\\|<-\\)" str)
61 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
65 (defun www-feature-format (feature-name)
66 (or (char-feature-property feature-name 'format)
68 (setq fn feature-name)
69 (while (and (setq parent (char-feature-name-parent fn))
71 (char-feature-property
75 '((name) " : " (value))))
77 (defun www-feature-value-format (feature-name)
78 (or (char-feature-property feature-name 'value-format)
80 (setq fn feature-name)
81 (while (and (setq parent (char-feature-name-parent fn))
83 (char-feature-property
84 parent 'value-format))))
87 (let ((type (www-feature-type feature-name)))
88 (cond ((eq type 'relation)
89 'space-separated-char-list)
95 (if (find-charset feature-name)
96 (if (and (= (charset-dimension feature-name) 2)
97 (= (charset-chars feature-name) 94))
99 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
100 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
102 (defun char-feature-name-at-domain (feature-name domain)
104 (let ((name (symbol-name feature-name)))
106 ((string-match "@[^*]+$" name)
107 (intern (format "%s/%s" name domain))
110 (intern (format "%s@%s" name domain))
114 (defun char-feature-name-parent (feature-name)
115 (let ((name (symbol-name feature-name)))
116 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
117 (intern (substring name 0 (car (last (match-data) 2)))))))
119 (defun char-feature-name-domain (feature-name)
120 (let ((name (symbol-name feature-name)))
121 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
122 (intern (substring name (1+ (match-beginning 0)))))))
124 (defun char-feature-name-sans-versions (feature)
125 (let ((feature-name (symbol-name feature)))
126 (if (string-match "[@/]\\$rev=latest$" feature-name)
127 (intern (substring feature-name 0 (match-beginning 0)))
130 (defun www-get-feature-value (object feature)
131 (let ((genre (www-get-genre object))
132 (latest-feature (char-feature-name-at-domain feature '$rev=latest)))
134 ((eq genre 'character)
135 (mount-char-attribute-table latest-feature)
136 (or (char-feature object latest-feature)
137 (char-feature object feature))
140 (or (concord-object-get object latest-feature)
141 (concord-object-get object feature))
144 (defun get-previous-code-point (ccs code)
145 (let ((chars (charset-chars ccs))
146 (dim (charset-dimension ccs))
148 mask byte-min byte-max
171 (setq bytes (make-vector dim 0))
173 (aset bytes i (logand (lsh code (* i -8)) mask))
176 (while (and (< i dim)
178 (aset bytes i (1- (aref bytes i)))
179 (< (aref bytes i) byte-min)))
180 (aset bytes i byte-max)
183 (setq dest (aref bytes 0)
186 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
190 (defun get-next-code-point (ccs code)
191 (let ((chars (charset-chars ccs))
192 (dim (charset-dimension ccs))
194 mask byte-min byte-max
217 (setq bytes (make-vector dim 0))
219 (aset bytes i (logand (lsh code (* i -8)) mask))
222 (while (and (< i dim)
224 (aset bytes i (1+ (aref bytes i)))
225 (> (aref bytes i) byte-max)))
226 (aset bytes i byte-min)
229 (setq dest (aref bytes 0)
232 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
236 (defun find-previous-defined-code-point (ccs code)
237 (let ((i (get-previous-code-point ccs code))
240 ((eq ccs '=jis-x0208)
241 (setq ccs '=jis-x0208@1990))
242 ((eq ccs '=jis-x0213-1)
243 (setq ccs '=jis-x0213-1@2004)))
246 (null (setq char (decode-char ccs i
247 (unless (eq ccs '=ucs)
249 (setq i (get-previous-code-point ccs i)))
252 (defun find-next-defined-code-point (ccs code)
253 (let ((i (get-next-code-point ccs code))
255 (setq max (+ code 1000))
257 ((eq ccs '=jis-x0208)
258 (setq ccs '=jis-x0208@1990))
259 ((eq ccs '=jis-x0213-1)
260 (setq ccs '=jis-x0213-1@2004)))
263 (null (setq char (decode-char ccs i
264 (unless (eq ccs '=ucs)
266 (setq i (get-next-code-point ccs i)))
270 ;;; @ URI representation
273 (defun www-uri-decode-feature-name (uri-feature)
276 ((string-match "^from\\." uri-feature)
277 (intern (format "<-%s" (substring uri-feature (match-end 0))))
279 ((string-match "^to\\." uri-feature)
280 (intern (format "->%s" (substring uri-feature (match-end 0))))
282 ((string-match "^rep\\." uri-feature)
283 (intern (format "=%s" (substring uri-feature (match-end 0))))
285 ((string-match "^g\\." uri-feature)
286 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
288 ((string-match "^gi\\." uri-feature)
289 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
291 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
292 (intern (format "=>>%s%s"
293 (make-string (string-to-int
294 (match-string 1 uri-feature))
296 (substring uri-feature (match-end 0))))
298 ((string-match "^a\\." uri-feature)
299 (intern (format "=>%s" (substring uri-feature (match-end 0))))
301 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
302 (intern (format "%s>%s"
303 (make-string (string-to-int
304 (match-string 1 uri-feature))
306 (substring uri-feature (match-end 0))))
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 ((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 (t (intern uri-feature)))))
322 (defun www-uri-encode-feature-name (feature-name)
323 (setq feature-name (symbol-name feature-name))
325 ((string-match "^=\\([^=>]+\\)" feature-name)
326 (concat "rep." (substring feature-name (match-beginning 1)))
328 ((string-match "^=>>\\([^=>]+\\)" feature-name)
329 (concat "g." (substring feature-name (match-beginning 1)))
331 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
332 (concat "gi." (substring feature-name (match-beginning 1)))
334 ((string-match "^=>>\\(>+\\)" feature-name)
336 (length (match-string 1 feature-name))
337 (substring feature-name (match-end 1)))
339 ((string-match "^=>\\([^=>]+\\)" feature-name)
340 (concat "a." (substring feature-name (match-beginning 1)))
342 ((string-match "^\\(=+\\)>" feature-name)
344 (length (match-string 1 feature-name))
345 (substring feature-name (match-end 0)))
347 ((string-match "^->" feature-name)
348 (concat "to." (substring feature-name (match-end 0)))
350 ((string-match "^<-" feature-name)
351 (concat "from." (substring feature-name (match-end 0)))
355 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
356 (format "%s?feature=%s&char=%s"
357 chise-wiki-view-url uri-feature-name uri-char))
359 (defun www-uri-decode-object (genre char-rep)
362 ((string-match "\\(%3A\\|:\\)" char-rep)
363 (setq ccs (substring char-rep 0 (match-beginning 0))
364 cpos (substring char-rep (match-end 0)))
365 (setq ccs (www-uri-decode-feature-name ccs))
367 ((string-match "^0x" cpos)
369 (string-to-number (substring cpos (match-end 0)) 16))
372 (setq cpos (car (read-from-string cpos)))
374 (if (and (eq genre 'character)
376 (decode-char ccs cpos)
377 (concord-decode-object ccs cpos genre))
380 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
382 ((eq genre 'character)
383 (when (= (length char-rep) 1)
387 (concord-decode-object
388 '=id (www-uri-decode-feature-name char-rep) 'feature)
391 (concord-decode-object
392 '=id (car (read-from-string char-rep)) genre)
395 (defun www-uri-encode-char (char)
396 (if (encode-char char '=ucs)
399 (format "%%%02X" byte))
400 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
402 (let ((ccs-list '(; =ucs
403 =cns11643-1 =cns11643-2 =cns11643-3
404 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
406 =jis-x0208 =jis-x0208@1990
409 =jis-x0213-1@2000 =jis-x0213-1@2004
410 =jis-x0208@1983 =jis-x0208@1978
411 =zinbun-oracle =>zinbun-oracle
414 =>>jis-x0208 =>>jis-x0213-1
415 =>jis-x0208 =>jis-x0213-1
422 (setq ccs (pop ccs-list))
423 (not (setq ret (encode-char char ccs 'defined-only)))))
426 (www-uri-encode-feature-name ccs)
428 ((and (setq ccs (car (split-char char)))
429 (setq ret (encode-char char ccs)))
431 (www-uri-encode-feature-name ccs)
434 (format "system-char-id:0x%X"
435 (encode-char char 'system-char-id))
439 ;;; @ Feature name presentation
442 (defun www-format-feature-name-default (feature-name)
446 (symbol-name feature-name)
450 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
451 (let ((str (symbol-name feature-name))
454 ((string-match "\\*[^*]+$" str)
455 (setq base (substring str 0 (match-beginning 0))
456 meta (substring str (match-beginning 0)))
457 (concat (www-format-feature-name* (intern base) lang)
460 (www-format-feature-name-default feature-name)
463 (defun www-format-feature-name-as-rel-to (feature-name)
464 (concat "\u2192" (substring (symbol-name feature-name) 2)))
466 (defun www-format-feature-name-as-rel-from (feature-name)
467 (concat "\u2190" (substring (symbol-name feature-name) 2)))
469 (defun www-format-feature-name-as-CCS (feature-name)
472 (symbol-name feature-name)
474 (dest (upcase (pop rest))))
475 (when (string-match "^=+>*" dest)
476 (setq dest (concat (substring dest 0 (match-end 0))
478 (substring dest (match-end 0)))))
482 (setq dest (concat dest " " (upcase (pop rest)))))
483 (if (string-match "^[0-9]+$" (car rest))
484 (concat dest "-" (car rest))
485 (concat dest " " (upcase (car rest))))
489 (defun www-format-feature-name* (feature-name &optional lang)
490 (let (name fn parent ret)
493 (char-feature-property
495 (intern (format "name@%s" lang))))
496 (char-feature-property
497 feature-name 'name)))
498 ((and (setq name (symbol-name feature-name))
499 (string-match "\\*" name))
500 (www-format-feature-name-as-metadata feature-name lang))
502 (setq fn feature-name)
503 (while (and (setq parent (char-feature-name-parent fn))
506 (char-feature-property
508 (intern (format "name@%s" lang))))
509 (char-feature-property
514 (concat ret (substring (symbol-name feature-name)
515 (length (symbol-name parent)))))
516 ((find-charset feature-name)
517 (www-format-feature-name-as-CCS feature-name))
518 ((string-match "^\\(->\\)" name)
519 (www-format-feature-name-as-rel-to feature-name))
520 ((string-match "^\\(<-\\)" name)
521 (www-format-feature-name-as-rel-from feature-name))
523 (www-format-feature-name-default feature-name)
527 (defun www-format-feature-name (feature-name &optional lang)
528 (www-format-encode-string
529 (www-format-feature-name* feature-name lang)))
532 ;;; @ Feature value presentation
535 (defun www-format-value-as-kuten (value)
537 (- (lsh value -8) 32)
538 (- (logand value 255) 32)))
540 (defun www-format-value-default (value &optional without-tags)
544 (www-format-encode-string
548 (www-format-encode-string (format "%S" value) without-tags)))
550 (defun www-format-value-as-char-list (value &optional without-tags)
555 (www-format-encode-string
556 (format (if (characterp unit)
562 (if (characterp unit)
563 (format "<a href=\"%s?char=%s\">%s</a>"
565 (www-uri-encode-char unit)
566 (www-format-encode-string (char-to-string unit)))
567 (www-format-encode-string (format "%s" unit)))))
569 (www-format-encode-string (format "%s" value) without-tags)))
571 (defun www-format-value-as-domain-list (value &optional without-tags)
572 (let (name source0 source num dest rest unit start end ddest)
581 (setq unit (pop rest))
583 (setq name (symbol-name unit)))
588 ((string-match "^zob1968=" name)
589 (setq source (intern (substring name 0 (match-end 0)))
590 num (substring name (match-end 0)))
591 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
592 (setq start (string-to-number
593 (match-string 1 num))
594 end (string-to-number
595 (match-string 2 num)))
596 (setq start (string-to-number num)
599 (if (eq source source0)
601 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
603 (setq source0 source)
605 " <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>"
606 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
608 (setq start (1+ start))
609 (while (<= start end)
614 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
616 (setq start (1+ start)))
620 (if (eq source source0)
622 (setq source0 source)
626 (www-format-encode-string (format "%s" value) without-tags))))
628 (defun www-format-value-as-ids (value &optional without-tags)
633 (www-format-encode-string
634 (format (if (characterp unit)
640 (if (characterp unit)
641 (format "<a href=\"%s?char=%s\">%s</a>"
643 (www-uri-encode-char unit)
644 (www-format-encode-string (char-to-string unit)))
645 (www-format-encode-string (format "%s" unit)))))
646 (ideographic-structure-to-ids value) " ")
647 (www-format-encode-string (format "%s" value) without-tags)))
649 (defun www-format-value-as-S-exp (value &optional without-tags)
650 (www-format-encode-string (format "%S" value) without-tags))
652 (defun www-format-value-as-HEX (value)
655 (www-format-value-as-S-exp value)))
657 (defun www-format-value-as-CCS-default (value)
660 (www-format-value-as-HEX value)
662 (www-format-value-as-S-exp value)))
664 (defun www-format-value-as-CCS-94x94 (value)
666 (format "0x%s [%s] (%d)"
667 (www-format-value-as-HEX value)
668 (www-format-value-as-kuten value)
670 (www-format-value-as-S-exp value)))
672 (defun www-format-value-as-kangxi-radical (value)
673 (if (and (integerp value)
676 (www-format-encode-string
677 (format "%c" (ideographic-radical value)))
678 (www-format-value-as-S-exp value)))
680 (defun www-format-value (object feature-name
681 &optional value format
682 without-tags without-edit)
684 (setq value (www-get-feature-value object feature-name)))
685 (www-format-apply-value object feature-name
686 format nil value nil nil
687 without-tags without-edit)
691 ;;; @ format evaluator
694 (defun www-format-encode-string (string &optional without-tags)
697 (let (plane code start end char variants ret rret)
698 (goto-char (point-min))
699 (while (search-forward "<" nil t)
700 (replace-match "<" nil t))
701 (goto-char (point-min))
702 (while (search-forward ">" nil t)
703 (replace-match ">" nil t))
705 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
706 (let ((coded-charset-entity-reference-alist
709 '(=cns11643-1 "C1-" 4 X)
710 '(=cns11643-2 "C2-" 4 X)
711 '(=cns11643-3 "C3-" 4 X)
712 '(=cns11643-4 "C4-" 4 X)
713 '(=cns11643-5 "C5-" 4 X)
714 '(=cns11643-6 "C6-" 4 X)
715 '(=cns11643-7 "C7-" 4 X)
717 '(=gb12345 "G1-" 4 X)
718 '(=jis-x0208@1990 "J90-" 4 X)
719 '(=jis-x0212 "JSP-" 4 X)
721 '(=jis-x0208@1997 "J97-" 4 X)
722 '(=jis-x0208@1978 "J78-" 4 X)
723 '(=jis-x0208@1983 "J83-" 4 X)
724 '(=ruimoku-v6 "RUI6-" 4 X)
725 '(=zinbun-oracle "ZOB-" 4 d)
726 '(=jef-china3 "JC3-" 4 X)
727 '(=daikanwa "M-" 5 d)
728 coded-charset-entity-reference-alist)))
729 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
731 (goto-char (point-min))
732 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
733 (setq code (string-to-int (match-string 1)))
735 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
737 chise-wiki-bitmap-glyphs-url
741 (goto-char (point-min))
742 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
743 (setq plane (match-string 1)
744 code (string-to-int (match-string 2) 16))
746 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
748 chise-wiki-bitmap-glyphs-url
751 (- (logand code 255) 32))
754 (goto-char (point-min))
755 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
756 (setq plane (string-to-int (match-string 1))
757 code (string-to-int (match-string 2) 16))
759 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
761 chise-wiki-bitmap-glyphs-url
764 (- (logand code 255) 32))
767 (goto-char (point-min))
768 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
769 (setq plane (string-to-int (match-string 1))
770 code (string-to-int (match-string 2) 16))
772 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
774 chise-wiki-bitmap-glyphs-url
778 (goto-char (point-min))
779 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
780 (setq code (string-to-int (match-string 1) 16))
782 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
786 (goto-char (point-min))
787 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
788 (setq code (string-to-int (match-string 2)))
790 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
792 chise-wiki-bitmap-glyphs-url
796 (goto-char (point-min))
797 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
798 (setq code (string-to-int (match-string 2)))
800 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
802 chise-wiki-glyph-cgi-url
806 (goto-char (point-min))
807 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
808 (setq code (string-to-int (match-string 2)))
810 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
812 chise-wiki-glyph-cgi-url
816 (goto-char (point-min))
817 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
818 (setq code (string-to-int (match-string 1) 16))
820 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
822 chise-wiki-glyph-cgi-url
826 (goto-char (point-min))
827 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
828 (setq code (string-to-int (match-string 1) 16))
830 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
832 chise-wiki-glyph-cgi-url
836 (goto-char (point-min))
837 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
838 (setq code (string-to-int (match-string 1) 16))
840 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
842 chise-wiki-glyph-cgi-url
846 (goto-char (point-min))
847 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
848 (setq code (string-to-int (match-string 2) 16))
850 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
855 (goto-char (point-min))
856 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
857 (setq code (string-to-int (match-string 1) 16))
858 (setq start (match-beginning 0)
860 (setq char (decode-char 'system-char-id code))
863 (or (www-get-feature-value char '->subsumptive)
864 (www-get-feature-value char '->denotational)))
867 (setq ret (www-format-encode-string
868 (char-to-string (car variants))))
869 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
870 (setq variants (cdr variants)))
872 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
874 (delete-region start end)
877 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
878 (www-get-feature-value char 'ideographic-structure)))
883 (if (characterp (setq rret (find-char ch)))
886 (www-format-encode-string
887 (char-to-string ch) without-tags)
888 (www-format-encode-string
889 (format "%S" ch) without-tags)))
893 (delete-region start end)
897 ;; (goto-char (point-min))
898 ;; (while (search-forward ">-" nil t)
899 ;; (replace-match "&GT-" t 'literal))
902 (defun www-format-props-to-string (props &optional format)
904 (setq format (plist-get props :format)))
906 (plist-get props :flag)
907 ;; (if (plist-get props :zero-padding)
909 (if (plist-get props :len)
911 (let ((ret (plist-get props :len)))
916 ((eq format 'decimal) "d")
917 ((eq format 'hex) "x")
918 ((eq format 'HEX) "X")
919 ((eq format 'S-exp) "S")
922 (defun www-format-apply-value (object feature-name
924 &optional uri-char uri-feature
925 without-tags without-edit)
929 ((memq format '(decimal hex HEX))
931 (format (www-format-props-to-string props format)
933 (www-format-encode-string
937 ((eq format 'wiki-text)
939 (www-xml-format-list value)
940 (www-format-eval-list value object feature-name nil uri-char
941 without-tags without-edit))
944 (www-format-encode-string
945 (format (www-format-props-to-string props format)
949 (www-format-value-as-kuten value))
950 ((eq format 'kangxi-radical)
951 (www-format-value-as-kangxi-radical value))
952 ((eq format 'space-separated-char-list)
953 (www-format-value-as-char-list value without-tags))
954 ((eq format 'space-separated-ids)
955 (www-format-value-as-ids value without-tags))
956 ((eq format 'space-separated-domain-list)
957 (www-format-value-as-domain-list value without-tags))
959 (www-format-encode-string (format "%s" value) without-tags)
962 (www-format-value-default value without-tags)
967 (eq (plist-get props :mode) 'peek))
969 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
970 ><input type=\"submit\" value=\"edit\" /></a>"
973 uri-char uri-feature format))))
975 (defun www-format-eval-feature-value (char
977 &optional format lang uri-char value
978 without-tags without-edit)
980 (setq value (www-get-feature-value char feature-name)))
982 (setq format (www-feature-value-format feature-name)))
985 (www-format-apply-value
988 uri-char (www-uri-encode-feature-name feature-name)
989 without-tags without-edit)
992 (cond ((null (cdr format))
993 (setq format (car format))
994 (www-format-apply-value
996 (car format) (nth 1 format) value
997 uri-char (www-uri-encode-feature-name feature-name)
998 without-tags without-edit)
1001 (www-format-eval-list format char feature-name lang uri-char
1002 without-tags without-edit)
1005 (defun www-format-eval-unit (exp char feature-name
1006 &optional lang uri-char value
1007 without-tags without-edit)
1009 (setq value (www-get-feature-value char feature-name)))
1011 (setq uri-char (www-uri-encode-char char)))
1013 ((stringp exp) (www-format-encode-string exp))
1017 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1018 S-exp string default))
1019 (let ((fn (plist-get (nth 1 exp) :feature))
1020 domain domain-fn ret)
1023 (setq fn (intern fn)))
1024 (setq domain (char-feature-name-domain feature-name))
1025 (setq domain-fn (char-feature-name-at-domain fn domain))
1026 (if (setq ret (www-get-feature-value char domain-fn))
1027 (setq feature-name domain-fn
1029 (setq feature-name fn
1030 value (www-get-feature-value char fn)))
1031 (push feature-name chise-wiki-displayed-features)
1033 (if (eq (car exp) 'value)
1034 (www-format-eval-feature-value char feature-name
1035 (plist-get (nth 1 exp) :format)
1037 without-tags without-edit)
1038 (www-format-apply-value
1040 (car exp) (nth 1 exp) value
1041 uri-char (www-uri-encode-feature-name feature-name)
1042 without-tags without-edit))
1044 ((eq (car exp) 'name)
1045 (let ((fn (plist-get (nth 1 exp) :feature))
1048 (setq domain (char-feature-name-domain feature-name))
1050 (setq fn (intern fn)))
1051 (setq domain-fn (char-feature-name-at-domain fn domain))
1052 (setq feature-name domain-fn)))
1054 (www-format-feature-name feature-name lang)
1055 (format "<a href=\"%s\">%s</a>"
1056 (www-uri-make-feature-name-url
1057 (www-uri-encode-feature-name feature-name)
1059 (www-format-feature-name feature-name lang))
1062 ((eq (car exp) 'name-url)
1063 (let ((fn (plist-get (nth 1 exp) :feature))
1066 (setq domain (char-feature-name-domain feature-name))
1068 (setq fn (intern fn)))
1069 (setq domain-fn (char-feature-name-at-domain fn domain))
1070 (setq feature-name domain-fn)))
1071 (www-uri-make-feature-name-url
1072 (www-uri-encode-feature-name feature-name)
1075 ((eq (car exp) 'domain-name)
1076 (let ((domain (char-feature-name-domain feature-name)))
1078 (format "@%s" domain))))
1079 ((eq (car exp) 'prev-char)
1082 (let ((prev-char (find-previous-defined-code-point
1083 feature-name value)))
1085 (format "\n<a href=\"%s?char=%s\">%s</a>"
1087 (www-uri-encode-char prev-char)
1088 "<input type=\"submit\" value=\"-\" />"
1089 ;; (www-format-encode-string
1090 ;; (char-to-string prev-char))
1094 ((eq (car exp) 'next-char)
1097 (let ((next-char (find-next-defined-code-point
1098 feature-name value)))
1100 (format "<a href=\"%s?char=%s\">%s</a>"
1102 (www-uri-encode-char next-char)
1103 "<input type=\"submit\" value=\"+\" />"
1104 ;; (www-format-encode-string
1105 ;; (char-to-string next-char))
1109 ((eq (car exp) 'link)
1111 (www-format-eval-list (nthcdr 2 exp)
1112 char feature-name lang uri-char
1113 without-tags without-edit)
1118 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1119 char feature-name lang uri-char
1120 'without-tags 'without-edit)
1121 (www-format-eval-list (nthcdr 2 exp)
1122 char feature-name lang uri-char
1123 without-tags without-edit)))
1130 (www-format-eval-list (nthcdr 2 exp) char feature-name
1132 without-tags without-edit)
1135 (defun www-format-eval-list (format-list char feature-name
1136 &optional lang uri-char
1137 without-tags without-edit)
1138 (if (consp format-list)
1141 (www-format-eval-unit exp char feature-name lang uri-char
1142 nil without-tags without-edit))
1144 (www-format-eval-unit format-list char feature-name lang uri-char
1145 nil without-tags without-edit)))
1151 (defun www-xml-format-props (props)
1155 (setq key (pop props)
1158 (setq key (symbol-name key)))
1159 (if (eq (aref key 0) ?:)
1160 (setq key (substring key 1)))
1162 (format "%s %s=\"%s\""
1164 (www-format-encode-string
1165 (format "%s" val) 'without-tags))))
1168 (defun www-xml-format-unit (format-unit)
1169 (let (name props children ret)
1171 ((stringp format-unit)
1172 (mapconcat (lambda (c)
1175 ;; ((eq c ?<) "&lt;")
1176 ;; ((eq c ?>) "&gt;")
1178 (char-to-string c))))
1179 (www-format-encode-string format-unit 'without-tags)
1182 ((consp format-unit)
1183 (setq name (car format-unit)
1184 props (nth 1 format-unit)
1185 children (nthcdr 2 format-unit))
1186 (when (eq name 'link)
1187 (setq ret (plist-get props :ref))
1188 (unless (stringp ret)
1189 (setq props (plist-remprop (copy-list props) :ref))
1191 (cons (list* 'ref nil ret)
1194 (format "<%s%s>%s</%s>"
1197 (www-xml-format-props props)
1199 (www-xml-format-list children)
1202 name (www-xml-format-props props)))
1205 (format "%s" format-unit)))))
1207 (defun www-xml-format-list (format-list)
1208 (if (atom format-list)
1209 (www-xml-format-unit format-list)
1210 (mapconcat #'www-xml-format-unit
1214 ;;; @ HTML generator
1217 (defun www-html-display-text (text)
1221 (goto-char (point-min))
1222 (while (search-forward "<" nil t)
1223 (replace-match "<" nil t))
1224 (goto-char (point-min))
1225 (while (search-forward ">" nil t)
1226 (replace-match ">" nil t))
1227 (goto-char (point-min))
1228 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1230 (format "<a href=\"%s\">%s</a>"
1234 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1235 (goto-char (point-min))
1236 (while (search-forward ">-" nil t)
1237 (replace-match "&GT-" nil t))
1240 (defun www-html-display-paragraph (text)
1242 (www-html-display-text text)
1249 (defvar coded-charset-GlyphWiki-id-alist
1250 '((=ucs "u" 4 x nil)
1251 (=ucs@JP "u" 4 x nil)
1252 (=ucs@jis "u" 4 x nil)
1253 (=ucs@gb "u" 4 x "-g")
1254 (=ucs@cns "u" 4 x "-t")
1255 (=ucs@ks "u" 4 x "-k")
1256 (=ucs@iso "u" 4 x "-u")
1257 (=ucs@unicode "u" 4 x "-us")
1258 (=adobe-japan1-6 "aj1-" 5 d nil)
1260 (=big5-cdp "cdp-" 4 x nil)
1261 (=cbeta "cb" 5 d nil)
1262 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1263 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1264 (=jis-x0208@1978 "j78-" 4 x nil)
1265 (=jis-x0208@1983 "j83-" 4 x nil)
1266 (=jis-x0208@1990 "j90-" 4 x nil)
1267 (=jis-x0212 "jsp-" 4 x nil)
1268 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1269 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1270 (=jis-x0213-2 "jx2-" 4 x nil)
1271 (=cns11643-1 "c1-" 4 x nil)
1272 (=cns11643-2 "c2-" 4 x nil)
1273 (=cns11643-3 "c3-" 4 x nil)
1274 (=cns11643-4 "c4-" 4 x nil)
1275 (=cns11643-5 "c5-" 4 x nil)
1276 (=cns11643-6 "c6-" 4 x nil)
1277 (=cns11643-7 "c7-" 4 x nil)
1278 (=daikanwa "dkw-" 5 d nil)
1279 (=gt-k "gt-k" 5 d nil)
1280 (=jef-china3 "jc3-" 4 x nil)
1281 (=big5 "b-" 4 x nil)
1282 (=ks-x1001 "k0-" 4 x nil)
1285 (defun char-GlyphWiki-id (char)
1286 (let ((rest coded-charset-GlyphWiki-id-alist)
1289 (setq spec (pop rest))
1290 (null (setq ret (char-feature char (car spec))))))
1293 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1295 ((and (or (encode-char char '=jis-x0208@1990)
1296 (encode-char char '=jis-x0212)
1297 (encode-char char '=jis-x0213-1))
1298 (setq code (encode-char char '=ucs@jis)))
1299 (format "u%04x" code)
1301 ((and (or (encode-char char '=gb2312)
1302 (encode-char char '=gb12345))
1303 (setq code (encode-char char '=ucs@gb)))
1304 (format "u%04x-g" code)
1306 ((and (or (encode-char char '=cns11643-1)
1307 (encode-char char '=cns11643-2)
1308 (encode-char char '=cns11643-3)
1309 (encode-char char '=cns11643-4)
1310 (encode-char char '=cns11643-5)
1311 (encode-char char '=cns11643-6)
1312 (encode-char char '=cns11643-7))
1313 (setq code (encode-char char '=ucs@cns)))
1314 (format "u%04x-t" code)
1316 ((and (encode-char char '=ks-x1001)
1317 (setq code (encode-char char '=ucs@ks)))
1318 (format "u%04x-k" code)
1320 (format (format "%s%%0%d%s%s"
1324 (or (nth 4 spec) ""))
1331 (provide 'cwiki-common)
1333 ;;; cwiki-common.el ends here