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-char (char)
390 (if (encode-char char '=ucs)
393 (format "%%%02X" byte))
394 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
396 (let ((ccs-list '(; =ucs
397 =cns11643-1 =cns11643-2 =cns11643-3
398 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
400 =jis-x0208 =jis-x0208@1990
403 =jis-x0213-1@2000 =jis-x0213-1@2004
404 =jis-x0208@1983 =jis-x0208@1978
405 =zinbun-oracle =>zinbun-oracle
408 =>>jis-x0208 =>>jis-x0213-1
409 =>jis-x0208 =>jis-x0213-1
416 (setq ccs (pop ccs-list))
417 (not (setq ret (encode-char char ccs 'defined-only)))))
420 (www-uri-encode-feature-name ccs)
422 ((and (setq ccs (car (split-char char)))
423 (setq ret (encode-char char ccs)))
425 (www-uri-encode-feature-name ccs)
428 (format "system-char-id:0x%X"
429 (encode-char char 'system-char-id))
433 ;;; @ Feature name presentation
436 (defun www-format-feature-name-default (feature-name)
440 (symbol-name feature-name)
444 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
445 (let ((str (symbol-name feature-name))
448 ((string-match "\\*[^*]+$" str)
449 (setq base (substring str 0 (match-beginning 0))
450 meta (substring str (match-beginning 0)))
451 (concat (www-format-feature-name* (intern base) lang)
454 (www-format-feature-name-default feature-name)
457 (defun www-format-feature-name-as-rel-to (feature-name)
458 (concat "\u2192" (substring (symbol-name feature-name) 2)))
460 (defun www-format-feature-name-as-rel-from (feature-name)
461 (concat "\u2190" (substring (symbol-name feature-name) 2)))
463 (defun www-format-feature-name-as-CCS (feature-name)
466 (symbol-name feature-name)
468 (dest (upcase (pop rest))))
469 (when (string-match "^=+>*" dest)
470 (setq dest (concat (substring dest 0 (match-end 0))
472 (substring dest (match-end 0)))))
476 (setq dest (concat dest " " (upcase (pop rest)))))
477 (if (string-match "^[0-9]+$" (car rest))
478 (concat dest "-" (car rest))
479 (concat dest " " (upcase (car rest))))
483 (defun www-format-feature-name* (feature-name &optional lang)
484 (let (name fn parent ret)
487 (char-feature-property
489 (intern (format "name@%s" lang))))
490 (char-feature-property
491 feature-name 'name)))
492 ((and (setq name (symbol-name feature-name))
493 (string-match "\\*" name))
494 (www-format-feature-name-as-metadata feature-name lang))
496 (setq fn feature-name)
497 (while (and (setq parent (char-feature-name-parent fn))
500 (char-feature-property
502 (intern (format "name@%s" lang))))
503 (char-feature-property
508 (concat ret (substring (symbol-name feature-name)
509 (length (symbol-name parent)))))
510 ((find-charset feature-name)
511 (www-format-feature-name-as-CCS feature-name))
512 ((string-match "^\\(->\\)" name)
513 (www-format-feature-name-as-rel-to feature-name))
514 ((string-match "^\\(<-\\)" name)
515 (www-format-feature-name-as-rel-from feature-name))
517 (www-format-feature-name-default feature-name)
521 (defun www-format-feature-name (feature-name &optional lang)
522 (www-format-encode-string
523 (www-format-feature-name* feature-name lang)))
526 ;;; @ Feature value presentation
529 (defun www-format-value-as-kuten (value)
531 (- (lsh value -8) 32)
532 (- (logand value 255) 32)))
534 (defun www-format-value-default (value &optional without-tags)
538 (www-format-encode-string
542 (www-format-encode-string (format "%S" value) without-tags)))
544 (defun www-format-value-as-char-list (value &optional without-tags)
549 (www-format-encode-string
550 (format (if (characterp unit)
556 (if (characterp unit)
557 (format "<a href=\"%s?char=%s\">%s</a>"
559 (www-uri-encode-char unit)
560 (www-format-encode-string (char-to-string unit)))
561 (www-format-encode-string (format "%s" unit)))))
563 (www-format-encode-string (format "%s" value) without-tags)))
565 (defun www-format-value-as-domain-list (value &optional without-tags)
566 (let (name source0 source num dest rest unit start end ddest)
575 (setq unit (pop rest))
577 (setq name (symbol-name unit)))
582 ((string-match "^zob1968=" name)
583 (setq source (intern (substring name 0 (match-end 0)))
584 num (substring name (match-end 0)))
585 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
586 (setq start (string-to-number
587 (match-string 1 num))
588 end (string-to-number
589 (match-string 2 num)))
590 (setq start (string-to-number num)
593 (if (eq source source0)
595 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
597 (setq source0 source)
599 " <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>"
600 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
602 (setq start (1+ start))
603 (while (<= start end)
608 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
610 (setq start (1+ start)))
614 (if (eq source source0)
616 (setq source0 source)
620 (www-format-encode-string (format "%s" value) without-tags))))
622 (defun www-format-value-as-ids (value &optional without-tags)
627 (www-format-encode-string
628 (format (if (characterp unit)
634 (if (characterp unit)
635 (format "<a href=\"%s?char=%s\">%s</a>"
637 (www-uri-encode-char unit)
638 (www-format-encode-string (char-to-string unit)))
639 (www-format-encode-string (format "%s" unit)))))
640 (ideographic-structure-to-ids value) " ")
641 (www-format-encode-string (format "%s" value) without-tags)))
643 (defun www-format-value-as-S-exp (value &optional without-tags)
644 (www-format-encode-string (format "%S" value) without-tags))
646 (defun www-format-value-as-HEX (value)
649 (www-format-value-as-S-exp value)))
651 (defun www-format-value-as-CCS-default (value)
654 (www-format-value-as-HEX value)
656 (www-format-value-as-S-exp value)))
658 (defun www-format-value-as-CCS-94x94 (value)
660 (format "0x%s [%s] (%d)"
661 (www-format-value-as-HEX value)
662 (www-format-value-as-kuten value)
664 (www-format-value-as-S-exp value)))
666 (defun www-format-value-as-kangxi-radical (value)
667 (if (and (integerp value)
670 (www-format-encode-string
671 (format "%c" (ideographic-radical value)))
672 (www-format-value-as-S-exp value)))
674 (defun www-format-value (object feature-name
675 &optional value format
676 without-tags without-edit)
678 (setq value (www-get-feature-value object feature-name)))
679 (www-format-apply-value object feature-name
680 format nil value nil nil
681 without-tags without-edit)
685 ;;; @ format evaluator
688 (defun www-format-encode-string (string &optional without-tags)
691 (let (plane code start end char variants ret rret)
692 (goto-char (point-min))
693 (while (search-forward "<" nil t)
694 (replace-match "<" nil t))
695 (goto-char (point-min))
696 (while (search-forward ">" nil t)
697 (replace-match ">" nil t))
699 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
700 (let ((coded-charset-entity-reference-alist
703 '(=cns11643-1 "C1-" 4 X)
704 '(=cns11643-2 "C2-" 4 X)
705 '(=cns11643-3 "C3-" 4 X)
706 '(=cns11643-4 "C4-" 4 X)
707 '(=cns11643-5 "C5-" 4 X)
708 '(=cns11643-6 "C6-" 4 X)
709 '(=cns11643-7 "C7-" 4 X)
711 '(=gb12345 "G1-" 4 X)
712 '(=jis-x0208@1990 "J90-" 4 X)
713 '(=jis-x0212 "JSP-" 4 X)
715 '(=jis-x0208@1997 "J97-" 4 X)
716 '(=jis-x0208@1978 "J78-" 4 X)
717 '(=jis-x0208@1983 "J83-" 4 X)
718 '(=ruimoku-v6 "RUI6-" 4 X)
719 '(=zinbun-oracle "ZOB-" 4 d)
720 '(=jef-china3 "JC3-" 4 X)
721 '(=daikanwa "M-" 5 d)
722 coded-charset-entity-reference-alist)))
723 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
725 (goto-char (point-min))
726 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
727 (setq code (string-to-int (match-string 1)))
729 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
731 chise-wiki-bitmap-glyphs-url
735 (goto-char (point-min))
736 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
737 (setq plane (match-string 1)
738 code (string-to-int (match-string 2) 16))
740 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
742 chise-wiki-bitmap-glyphs-url
745 (- (logand code 255) 32))
748 (goto-char (point-min))
749 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
750 (setq plane (string-to-int (match-string 1))
751 code (string-to-int (match-string 2) 16))
753 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
755 chise-wiki-bitmap-glyphs-url
758 (- (logand code 255) 32))
761 (goto-char (point-min))
762 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
763 (setq plane (string-to-int (match-string 1))
764 code (string-to-int (match-string 2) 16))
766 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
768 chise-wiki-bitmap-glyphs-url
772 (goto-char (point-min))
773 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
774 (setq code (string-to-int (match-string 1) 16))
776 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
780 (goto-char (point-min))
781 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
782 (setq code (string-to-int (match-string 2)))
784 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
786 chise-wiki-bitmap-glyphs-url
790 (goto-char (point-min))
791 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
792 (setq code (string-to-int (match-string 2)))
794 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
796 chise-wiki-glyph-cgi-url
800 (goto-char (point-min))
801 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
802 (setq code (string-to-int (match-string 2)))
804 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
806 chise-wiki-glyph-cgi-url
810 (goto-char (point-min))
811 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
812 (setq code (string-to-int (match-string 1) 16))
814 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
816 chise-wiki-glyph-cgi-url
820 (goto-char (point-min))
821 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
822 (setq code (string-to-int (match-string 1) 16))
824 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
826 chise-wiki-glyph-cgi-url
830 (goto-char (point-min))
831 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
832 (setq code (string-to-int (match-string 1) 16))
834 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
836 chise-wiki-glyph-cgi-url
840 (goto-char (point-min))
841 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
842 (setq code (string-to-int (match-string 2) 16))
844 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
849 (goto-char (point-min))
850 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
851 (setq code (string-to-int (match-string 1) 16))
852 (setq start (match-beginning 0)
854 (setq char (decode-char 'system-char-id code))
857 (or (www-get-feature-value char '->subsumptive)
858 (www-get-feature-value char '->denotational)))
861 (setq ret (www-format-encode-string
862 (char-to-string (car variants))))
863 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
864 (setq variants (cdr variants)))
866 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
868 (delete-region start end)
871 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
872 (www-get-feature-value char 'ideographic-structure)))
877 (if (characterp (setq rret (find-char ch)))
880 (www-format-encode-string
881 (char-to-string ch) without-tags)
882 (www-format-encode-string
883 (format "%S" ch) without-tags)))
887 (delete-region start end)
891 ;; (goto-char (point-min))
892 ;; (while (search-forward ">-" nil t)
893 ;; (replace-match "&GT-" t 'literal))
896 (defun www-format-props-to-string (props &optional format)
898 (setq format (plist-get props :format)))
900 (plist-get props :flag)
901 ;; (if (plist-get props :zero-padding)
903 (if (plist-get props :len)
905 (let ((ret (plist-get props :len)))
910 ((eq format 'decimal) "d")
911 ((eq format 'hex) "x")
912 ((eq format 'HEX) "X")
913 ((eq format 'S-exp) "S")
916 (defun www-format-apply-value (object feature-name
918 &optional uri-char uri-feature
919 without-tags without-edit)
923 ((memq format '(decimal hex HEX))
925 (format (www-format-props-to-string props format)
927 (www-format-encode-string
931 ((eq format 'wiki-text)
933 (www-xml-format-list value)
934 (www-format-eval-list value object feature-name nil uri-char
935 without-tags without-edit))
938 (www-format-encode-string
939 (format (www-format-props-to-string props format)
943 (www-format-value-as-kuten value))
944 ((eq format 'kangxi-radical)
945 (www-format-value-as-kangxi-radical value))
946 ((eq format 'space-separated-char-list)
947 (www-format-value-as-char-list value without-tags))
948 ((eq format 'space-separated-ids)
949 (www-format-value-as-ids value without-tags))
950 ((eq format 'space-separated-domain-list)
951 (www-format-value-as-domain-list value without-tags))
953 (www-format-encode-string (format "%s" value) without-tags)
956 (www-format-value-default value without-tags)
961 (eq (plist-get props :mode) 'peek))
963 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
964 ><input type=\"submit\" value=\"edit\" /></a>"
967 uri-char uri-feature format))))
969 (defun www-format-eval-feature-value (char
971 &optional format lang uri-char value
972 without-tags without-edit)
974 (setq value (www-get-feature-value char feature-name)))
976 (setq format (www-feature-value-format feature-name)))
979 (www-format-apply-value
982 uri-char (www-uri-encode-feature-name feature-name)
983 without-tags without-edit)
986 (cond ((null (cdr format))
987 (setq format (car format))
988 (www-format-apply-value
990 (car format) (nth 1 format) value
991 uri-char (www-uri-encode-feature-name feature-name)
992 without-tags without-edit)
995 (www-format-eval-list format char feature-name lang uri-char
996 without-tags without-edit)
999 (defun www-format-eval-unit (exp char feature-name
1000 &optional lang uri-char value
1001 without-tags without-edit)
1003 (setq value (www-get-feature-value char feature-name)))
1005 (setq uri-char (www-uri-encode-char char)))
1007 ((stringp exp) (www-format-encode-string exp))
1011 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1012 S-exp string default))
1013 (let ((fn (plist-get (nth 1 exp) :feature))
1014 domain domain-fn ret)
1017 (setq fn (intern fn)))
1018 (setq domain (char-feature-name-domain feature-name))
1019 (setq domain-fn (char-feature-name-at-domain fn domain))
1020 (if (setq ret (www-get-feature-value char domain-fn))
1021 (setq feature-name domain-fn
1023 (setq feature-name fn
1024 value (www-get-feature-value char fn)))
1025 (push feature-name chise-wiki-displayed-features)
1027 (if (eq (car exp) 'value)
1028 (www-format-eval-feature-value char feature-name
1029 (plist-get (nth 1 exp) :format)
1031 without-tags without-edit)
1032 (www-format-apply-value
1034 (car exp) (nth 1 exp) value
1035 uri-char (www-uri-encode-feature-name feature-name)
1036 without-tags without-edit))
1038 ((eq (car exp) 'name)
1039 (let ((fn (plist-get (nth 1 exp) :feature))
1042 (setq domain (char-feature-name-domain feature-name))
1044 (setq fn (intern fn)))
1045 (setq domain-fn (char-feature-name-at-domain fn domain))
1046 (setq feature-name domain-fn)))
1048 (www-format-feature-name feature-name lang)
1049 (format "<a href=\"%s\">%s</a>"
1050 (www-uri-make-feature-name-url
1051 (www-uri-encode-feature-name feature-name)
1053 (www-format-feature-name feature-name lang))
1056 ((eq (car exp) 'name-url)
1057 (let ((fn (plist-get (nth 1 exp) :feature))
1060 (setq domain (char-feature-name-domain feature-name))
1062 (setq fn (intern fn)))
1063 (setq domain-fn (char-feature-name-at-domain fn domain))
1064 (setq feature-name domain-fn)))
1065 (www-uri-make-feature-name-url
1066 (www-uri-encode-feature-name feature-name)
1069 ((eq (car exp) 'domain-name)
1070 (let ((domain (char-feature-name-domain feature-name)))
1072 (format "@%s" domain))))
1073 ((eq (car exp) 'prev-char)
1076 (let ((prev-char (find-previous-defined-code-point
1077 feature-name value)))
1079 (format "\n<a href=\"%s?char=%s\">%s</a>"
1081 (www-uri-encode-char prev-char)
1082 "<input type=\"submit\" value=\"-\" />"
1083 ;; (www-format-encode-string
1084 ;; (char-to-string prev-char))
1088 ((eq (car exp) 'next-char)
1091 (let ((next-char (find-next-defined-code-point
1092 feature-name value)))
1094 (format "<a href=\"%s?char=%s\">%s</a>"
1096 (www-uri-encode-char next-char)
1097 "<input type=\"submit\" value=\"+\" />"
1098 ;; (www-format-encode-string
1099 ;; (char-to-string next-char))
1103 ((eq (car exp) 'link)
1105 (www-format-eval-list (nthcdr 2 exp)
1106 char feature-name lang uri-char
1107 without-tags without-edit)
1112 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1113 char feature-name lang uri-char
1114 'without-tags 'without-edit)
1115 (www-format-eval-list (nthcdr 2 exp)
1116 char feature-name lang uri-char
1117 without-tags without-edit)))
1124 (www-format-eval-list (nthcdr 2 exp) char feature-name
1126 without-tags without-edit)
1129 (defun www-format-eval-list (format-list char feature-name
1130 &optional lang uri-char
1131 without-tags without-edit)
1132 (if (consp format-list)
1135 (www-format-eval-unit exp char feature-name lang uri-char
1136 nil without-tags without-edit))
1138 (www-format-eval-unit format-list char feature-name lang uri-char
1139 nil without-tags without-edit)))
1145 (defun www-xml-format-props (props)
1149 (setq key (pop props)
1152 (setq key (symbol-name key)))
1153 (if (eq (aref key 0) ?:)
1154 (setq key (substring key 1)))
1156 (format "%s %s=\"%s\""
1158 (www-format-encode-string
1159 (format "%s" val) 'without-tags))))
1162 (defun www-xml-format-unit (format-unit)
1163 (let (name props children ret)
1165 ((stringp format-unit)
1166 (mapconcat (lambda (c)
1169 ;; ((eq c ?<) "&lt;")
1170 ;; ((eq c ?>) "&gt;")
1172 (char-to-string c))))
1173 (www-format-encode-string format-unit 'without-tags)
1176 ((consp format-unit)
1177 (setq name (car format-unit)
1178 props (nth 1 format-unit)
1179 children (nthcdr 2 format-unit))
1180 (when (eq name 'link)
1181 (setq ret (plist-get props :ref))
1182 (unless (stringp ret)
1183 (setq props (plist-remprop (copy-list props) :ref))
1185 (cons (list* 'ref nil ret)
1188 (format "<%s%s>%s</%s>"
1191 (www-xml-format-props props)
1193 (www-xml-format-list children)
1196 name (www-xml-format-props props)))
1199 (format "%s" format-unit)))))
1201 (defun www-xml-format-list (format-list)
1202 (if (atom format-list)
1203 (www-xml-format-unit format-list)
1204 (mapconcat #'www-xml-format-unit
1208 ;;; @ HTML generator
1211 (defun www-html-display-text (text)
1215 (goto-char (point-min))
1216 (while (search-forward "<" nil t)
1217 (replace-match "<" nil t))
1218 (goto-char (point-min))
1219 (while (search-forward ">" nil t)
1220 (replace-match ">" nil t))
1221 (goto-char (point-min))
1222 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1224 (format "<a href=\"%s\">%s</a>"
1228 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1229 (goto-char (point-min))
1230 (while (search-forward ">-" nil t)
1231 (replace-match "&GT-" nil t))
1234 (defun www-html-display-paragraph (text)
1236 (www-html-display-text text)
1243 (defvar coded-charset-GlyphWiki-id-alist
1244 '((=ucs "u" 4 x nil)
1245 (=ucs@JP "u" 4 x nil)
1246 (=ucs@jis "u" 4 x nil)
1247 (=ucs@gb "u" 4 x "-g")
1248 (=ucs@cns "u" 4 x "-t")
1249 (=ucs@ks "u" 4 x "-k")
1250 (=ucs@iso "u" 4 x "-u")
1251 (=ucs@unicode "u" 4 x "-us")
1252 (=adobe-japan1-6 "aj1-" 5 d nil)
1254 (=big5-cdp "cdp-" 4 x nil)
1255 (=cbeta "cb" 5 d nil)
1256 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1257 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1258 (=jis-x0208@1978 "j78-" 4 x nil)
1259 (=jis-x0208@1983 "j83-" 4 x nil)
1260 (=jis-x0208@1990 "j90-" 4 x nil)
1261 (=jis-x0212 "jsp-" 4 x nil)
1262 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1263 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1264 (=jis-x0213-2 "jx2-" 4 x nil)
1265 (=cns11643-1 "c1-" 4 x nil)
1266 (=cns11643-2 "c2-" 4 x nil)
1267 (=cns11643-3 "c3-" 4 x nil)
1268 (=cns11643-4 "c4-" 4 x nil)
1269 (=cns11643-5 "c5-" 4 x nil)
1270 (=cns11643-6 "c6-" 4 x nil)
1271 (=cns11643-7 "c7-" 4 x nil)
1272 (=daikanwa "dkw-" 5 d nil)
1273 (=gt-k "gt-k" 5 d nil)
1274 (=jef-china3 "jc3-" 4 x nil)
1275 (=big5 "b-" 4 x nil)
1276 (=ks-x1001 "k0-" 4 x nil)
1279 (defun char-GlyphWiki-id (char)
1280 (let ((rest coded-charset-GlyphWiki-id-alist)
1283 (setq spec (pop rest))
1284 (null (setq ret (char-feature char (car spec))))))
1287 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1289 ((and (or (encode-char char '=jis-x0208@1990)
1290 (encode-char char '=jis-x0212)
1291 (encode-char char '=jis-x0213-1))
1292 (setq code (encode-char char '=ucs@jis)))
1293 (format "u%04x" code)
1295 ((and (or (encode-char char '=gb2312)
1296 (encode-char char '=gb12345))
1297 (setq code (encode-char char '=ucs@gb)))
1298 (format "u%04x-g" code)
1300 ((and (or (encode-char char '=cns11643-1)
1301 (encode-char char '=cns11643-2)
1302 (encode-char char '=cns11643-3)
1303 (encode-char char '=cns11643-4)
1304 (encode-char char '=cns11643-5)
1305 (encode-char char '=cns11643-6)
1306 (encode-char char '=cns11643-7))
1307 (setq code (encode-char char '=ucs@cns)))
1308 (format "u%04x-t" code)
1310 ((and (encode-char char '=ks-x1001)
1311 (setq code (encode-char char '=ucs@ks)))
1312 (format "u%04x-k" code)
1314 (format (format "%s%%0%d%s%s"
1318 (or (nth 4 spec) ""))
1325 (provide 'cwiki-common)
1327 ;;; cwiki-common.el ends here