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))
432 (defun est-format-object (object)
433 (if (characterp object)
434 (char-to-string object)
435 (format "%s" (concord-object-id object))))
438 ;;; @ Feature name presentation
441 (defun www-format-feature-name-default (feature-name)
445 (symbol-name feature-name)
449 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
450 (let ((str (symbol-name feature-name))
453 ((string-match "\\*[^*]+$" str)
454 (setq base (substring str 0 (match-beginning 0))
455 meta (substring str (match-beginning 0)))
456 (concat (www-format-feature-name* (intern base) lang)
459 (www-format-feature-name-default feature-name)
462 (defun www-format-feature-name-as-rel-to (feature-name)
463 (concat "\u2192" (substring (symbol-name feature-name) 2)))
465 (defun www-format-feature-name-as-rel-from (feature-name)
466 (concat "\u2190" (substring (symbol-name feature-name) 2)))
468 (defun www-format-feature-name-as-CCS (feature-name)
471 (symbol-name feature-name)
473 (dest (upcase (pop rest))))
474 (when (string-match "^=+>*" dest)
475 (setq dest (concat (substring dest 0 (match-end 0))
477 (substring dest (match-end 0)))))
481 (setq dest (concat dest " " (upcase (pop rest)))))
482 (if (string-match "^[0-9]+$" (car rest))
483 (concat dest "-" (car rest))
484 (concat dest " " (upcase (car rest))))
488 (defun www-format-feature-name* (feature-name &optional lang)
489 (let (name fn parent ret)
492 (char-feature-property
494 (intern (format "name@%s" lang))))
495 (char-feature-property
496 feature-name 'name)))
497 ((and (setq name (symbol-name feature-name))
498 (string-match "\\*" name))
499 (www-format-feature-name-as-metadata feature-name lang))
501 (setq fn feature-name)
502 (while (and (setq parent (char-feature-name-parent fn))
505 (char-feature-property
507 (intern (format "name@%s" lang))))
508 (char-feature-property
513 (concat ret (substring (symbol-name feature-name)
514 (length (symbol-name parent)))))
515 ((find-charset feature-name)
516 (www-format-feature-name-as-CCS feature-name))
517 ((string-match "^\\(->\\)" name)
518 (www-format-feature-name-as-rel-to feature-name))
519 ((string-match "^\\(<-\\)" name)
520 (www-format-feature-name-as-rel-from feature-name))
522 (www-format-feature-name-default feature-name)
526 (defun www-format-feature-name (feature-name &optional lang)
527 (www-format-encode-string
528 (www-format-feature-name* feature-name lang)))
531 ;;; @ Feature value presentation
534 (defun www-format-value-as-kuten (value)
536 (- (lsh value -8) 32)
537 (- (logand value 255) 32)))
539 (defun www-format-value-default (value &optional without-tags)
543 (www-format-encode-string
547 (www-format-encode-string (format "%S" value) without-tags)))
549 (defun www-format-value-as-char-list (value &optional without-tags)
554 (www-format-encode-string
555 (format (if (characterp unit)
561 (if (characterp unit)
562 (format "<a href=\"%s?char=%s\">%s</a>"
564 (www-uri-encode-char unit)
565 (www-format-encode-string (char-to-string unit)))
566 (www-format-encode-string (format "%s" unit)))))
568 (www-format-encode-string (format "%s" value) without-tags)))
570 (defun www-format-value-as-domain-list (value &optional without-tags)
571 (let (name source0 source num dest rest unit start end ddest)
580 (setq unit (pop rest))
582 (setq name (symbol-name unit)))
587 ((string-match "^zob1968=" name)
588 (setq source (intern (substring name 0 (match-end 0)))
589 num (substring name (match-end 0)))
590 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
591 (setq start (string-to-number
592 (match-string 1 num))
593 end (string-to-number
594 (match-string 2 num)))
595 (setq start (string-to-number num)
598 (if (eq source source0)
600 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
602 (setq source0 source)
604 " <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>"
605 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
607 (setq start (1+ start))
608 (while (<= start end)
613 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
615 (setq start (1+ start)))
619 (if (eq source source0)
621 (setq source0 source)
625 (www-format-encode-string (format "%s" value) without-tags))))
627 (defun www-format-value-as-ids (value &optional without-tags)
632 (www-format-encode-string
633 (format (if (characterp unit)
639 (if (characterp unit)
640 (format "<a href=\"%s?char=%s\">%s</a>"
642 (www-uri-encode-char unit)
643 (www-format-encode-string (char-to-string unit)))
644 (www-format-encode-string (format "%s" unit)))))
645 (ideographic-structure-to-ids value) " ")
646 (www-format-encode-string (format "%s" value) without-tags)))
648 (defun www-format-value-as-S-exp (value &optional without-tags)
649 (www-format-encode-string (format "%S" value) without-tags))
651 (defun www-format-value-as-HEX (value)
654 (www-format-value-as-S-exp value)))
656 (defun www-format-value-as-CCS-default (value)
659 (www-format-value-as-HEX value)
661 (www-format-value-as-S-exp value)))
663 (defun www-format-value-as-CCS-94x94 (value)
665 (format "0x%s [%s] (%d)"
666 (www-format-value-as-HEX value)
667 (www-format-value-as-kuten value)
669 (www-format-value-as-S-exp value)))
671 (defun www-format-value-as-kangxi-radical (value)
672 (if (and (integerp value)
675 (www-format-encode-string
676 (format "%c" (ideographic-radical value)))
677 (www-format-value-as-S-exp value)))
679 (defun www-format-value (object feature-name
680 &optional value format
681 without-tags without-edit)
683 (setq value (www-get-feature-value object feature-name)))
684 (www-format-apply-value object feature-name
685 format nil value nil nil
686 without-tags without-edit)
690 ;;; @ format evaluator
693 (defun www-format-encode-string (string &optional without-tags)
696 (let (plane code start end char variants ret rret)
697 (goto-char (point-min))
698 (while (search-forward "<" nil t)
699 (replace-match "<" nil t))
700 (goto-char (point-min))
701 (while (search-forward ">" nil t)
702 (replace-match ">" nil t))
704 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
705 (let ((coded-charset-entity-reference-alist
708 '(=cns11643-1 "C1-" 4 X)
709 '(=cns11643-2 "C2-" 4 X)
710 '(=cns11643-3 "C3-" 4 X)
711 '(=cns11643-4 "C4-" 4 X)
712 '(=cns11643-5 "C5-" 4 X)
713 '(=cns11643-6 "C6-" 4 X)
714 '(=cns11643-7 "C7-" 4 X)
716 '(=gb12345 "G1-" 4 X)
717 '(=jis-x0208@1990 "J90-" 4 X)
718 '(=jis-x0212 "JSP-" 4 X)
720 '(=jis-x0208@1997 "J97-" 4 X)
721 '(=jis-x0208@1978 "J78-" 4 X)
722 '(=jis-x0208@1983 "J83-" 4 X)
723 '(=ruimoku-v6 "RUI6-" 4 X)
724 '(=zinbun-oracle "ZOB-" 4 d)
725 '(=jef-china3 "JC3-" 4 X)
726 '(=daikanwa "M-" 5 d)
727 coded-charset-entity-reference-alist)))
728 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
730 (goto-char (point-min))
731 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
732 (setq code (string-to-int (match-string 1)))
734 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
736 chise-wiki-bitmap-glyphs-url
740 (goto-char (point-min))
741 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
742 (setq plane (match-string 1)
743 code (string-to-int (match-string 2) 16))
745 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
747 chise-wiki-bitmap-glyphs-url
750 (- (logand code 255) 32))
753 (goto-char (point-min))
754 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
755 (setq plane (string-to-int (match-string 1))
756 code (string-to-int (match-string 2) 16))
758 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
760 chise-wiki-bitmap-glyphs-url
763 (- (logand code 255) 32))
766 (goto-char (point-min))
767 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
768 (setq plane (string-to-int (match-string 1))
769 code (string-to-int (match-string 2) 16))
771 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
773 chise-wiki-bitmap-glyphs-url
777 (goto-char (point-min))
778 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
779 (setq code (string-to-int (match-string 1) 16))
781 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
785 (goto-char (point-min))
786 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
787 (setq code (string-to-int (match-string 2)))
789 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
791 chise-wiki-bitmap-glyphs-url
795 (goto-char (point-min))
796 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
797 (setq code (string-to-int (match-string 2)))
799 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
801 chise-wiki-glyph-cgi-url
805 (goto-char (point-min))
806 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
807 (setq code (string-to-int (match-string 2)))
809 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
811 chise-wiki-glyph-cgi-url
815 (goto-char (point-min))
816 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
817 (setq code (string-to-int (match-string 1) 16))
819 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
821 chise-wiki-glyph-cgi-url
825 (goto-char (point-min))
826 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
827 (setq code (string-to-int (match-string 1) 16))
829 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
831 chise-wiki-glyph-cgi-url
835 (goto-char (point-min))
836 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
837 (setq code (string-to-int (match-string 1) 16))
839 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
841 chise-wiki-glyph-cgi-url
845 (goto-char (point-min))
846 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
847 (setq code (string-to-int (match-string 2) 16))
849 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
854 (goto-char (point-min))
855 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
856 (setq code (string-to-int (match-string 1) 16))
857 (setq start (match-beginning 0)
859 (setq char (decode-char 'system-char-id code))
862 (or (www-get-feature-value char '->subsumptive)
863 (www-get-feature-value char '->denotational)))
866 (setq ret (www-format-encode-string
867 (char-to-string (car variants))))
868 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
869 (setq variants (cdr variants)))
871 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
873 (delete-region start end)
876 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
877 (www-get-feature-value char 'ideographic-structure)))
882 (if (characterp (setq rret (find-char ch)))
885 (www-format-encode-string
886 (char-to-string ch) without-tags)
887 (www-format-encode-string
888 (format "%S" ch) without-tags)))
892 (delete-region start end)
896 ;; (goto-char (point-min))
897 ;; (while (search-forward ">-" nil t)
898 ;; (replace-match "&GT-" t 'literal))
901 (defun www-format-props-to-string (props &optional format)
903 (setq format (plist-get props :format)))
905 (plist-get props :flag)
906 ;; (if (plist-get props :zero-padding)
908 (if (plist-get props :len)
910 (let ((ret (plist-get props :len)))
915 ((eq format 'decimal) "d")
916 ((eq format 'hex) "x")
917 ((eq format 'HEX) "X")
918 ((eq format 'S-exp) "S")
921 (defun www-format-apply-value (object feature-name
923 &optional uri-char uri-feature
924 without-tags without-edit)
928 ((memq format '(decimal hex HEX))
930 (format (www-format-props-to-string props format)
932 (www-format-encode-string
936 ((eq format 'wiki-text)
938 (www-xml-format-list value)
939 (www-format-eval-list value object feature-name nil uri-char
940 without-tags without-edit))
943 (www-format-encode-string
944 (format (www-format-props-to-string props format)
948 (www-format-value-as-kuten value))
949 ((eq format 'kangxi-radical)
950 (www-format-value-as-kangxi-radical value))
951 ((eq format 'space-separated-char-list)
952 (www-format-value-as-char-list value without-tags))
953 ((eq format 'space-separated-ids)
954 (www-format-value-as-ids value without-tags))
955 ((eq format 'space-separated-domain-list)
956 (www-format-value-as-domain-list value without-tags))
958 (www-format-encode-string (format "%s" value) without-tags)
961 (www-format-value-default value without-tags)
966 (eq (plist-get props :mode) 'peek))
968 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
969 ><input type=\"submit\" value=\"edit\" /></a>"
972 uri-char uri-feature format))))
974 (defun www-format-eval-feature-value (char
976 &optional format lang uri-char value
977 without-tags without-edit)
979 (setq value (www-get-feature-value char feature-name)))
981 (setq format (www-feature-value-format feature-name)))
984 (www-format-apply-value
987 uri-char (www-uri-encode-feature-name feature-name)
988 without-tags without-edit)
991 (cond ((null (cdr format))
992 (setq format (car format))
993 (www-format-apply-value
995 (car format) (nth 1 format) value
996 uri-char (www-uri-encode-feature-name feature-name)
997 without-tags without-edit)
1000 (www-format-eval-list format char feature-name lang uri-char
1001 without-tags without-edit)
1004 (defun www-format-eval-unit (exp char feature-name
1005 &optional lang uri-char value
1006 without-tags without-edit)
1008 (setq value (www-get-feature-value char feature-name)))
1010 (setq uri-char (www-uri-encode-char char)))
1012 ((stringp exp) (www-format-encode-string exp))
1016 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1017 S-exp string default))
1018 (let ((fn (plist-get (nth 1 exp) :feature))
1019 domain domain-fn ret)
1022 (setq fn (intern fn)))
1023 (setq domain (char-feature-name-domain feature-name))
1024 (setq domain-fn (char-feature-name-at-domain fn domain))
1025 (if (setq ret (www-get-feature-value char domain-fn))
1026 (setq feature-name domain-fn
1028 (setq feature-name fn
1029 value (www-get-feature-value char fn)))
1030 (push feature-name chise-wiki-displayed-features)
1032 (if (eq (car exp) 'value)
1033 (www-format-eval-feature-value char feature-name
1034 (plist-get (nth 1 exp) :format)
1036 without-tags without-edit)
1037 (www-format-apply-value
1039 (car exp) (nth 1 exp) value
1040 uri-char (www-uri-encode-feature-name feature-name)
1041 without-tags without-edit))
1043 ((eq (car exp) 'name)
1044 (let ((fn (plist-get (nth 1 exp) :feature))
1047 (setq domain (char-feature-name-domain feature-name))
1049 (setq fn (intern fn)))
1050 (setq domain-fn (char-feature-name-at-domain fn domain))
1051 (setq feature-name domain-fn)))
1053 (www-format-feature-name feature-name lang)
1054 (format "<a href=\"%s\">%s</a>"
1055 (www-uri-make-feature-name-url
1056 (www-uri-encode-feature-name feature-name)
1058 (www-format-feature-name feature-name lang))
1061 ((eq (car exp) 'name-url)
1062 (let ((fn (plist-get (nth 1 exp) :feature))
1065 (setq domain (char-feature-name-domain feature-name))
1067 (setq fn (intern fn)))
1068 (setq domain-fn (char-feature-name-at-domain fn domain))
1069 (setq feature-name domain-fn)))
1070 (www-uri-make-feature-name-url
1071 (www-uri-encode-feature-name feature-name)
1074 ((eq (car exp) 'domain-name)
1075 (let ((domain (char-feature-name-domain feature-name)))
1077 (format "@%s" domain))))
1078 ((eq (car exp) 'prev-char)
1081 (let ((prev-char (find-previous-defined-code-point
1082 feature-name value)))
1084 (format "\n<a href=\"%s?char=%s\">%s</a>"
1086 (www-uri-encode-char prev-char)
1087 "<input type=\"submit\" value=\"-\" />"
1088 ;; (www-format-encode-string
1089 ;; (char-to-string prev-char))
1093 ((eq (car exp) 'next-char)
1096 (let ((next-char (find-next-defined-code-point
1097 feature-name value)))
1099 (format "<a href=\"%s?char=%s\">%s</a>"
1101 (www-uri-encode-char next-char)
1102 "<input type=\"submit\" value=\"+\" />"
1103 ;; (www-format-encode-string
1104 ;; (char-to-string next-char))
1108 ((eq (car exp) 'link)
1110 (www-format-eval-list (nthcdr 2 exp)
1111 char feature-name lang uri-char
1112 without-tags without-edit)
1117 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1118 char feature-name lang uri-char
1119 'without-tags 'without-edit)
1120 (www-format-eval-list (nthcdr 2 exp)
1121 char feature-name lang uri-char
1122 without-tags without-edit)))
1129 (www-format-eval-list (nthcdr 2 exp) char feature-name
1131 without-tags without-edit)
1134 (defun www-format-eval-list (format-list char feature-name
1135 &optional lang uri-char
1136 without-tags without-edit)
1137 (if (consp format-list)
1140 (www-format-eval-unit exp char feature-name lang uri-char
1141 nil without-tags without-edit))
1143 (www-format-eval-unit format-list char feature-name lang uri-char
1144 nil without-tags without-edit)))
1150 (defun www-xml-format-props (props)
1154 (setq key (pop props)
1157 (setq key (symbol-name key)))
1158 (if (eq (aref key 0) ?:)
1159 (setq key (substring key 1)))
1161 (format "%s %s=\"%s\""
1163 (www-format-encode-string
1164 (format "%s" val) 'without-tags))))
1167 (defun www-xml-format-unit (format-unit)
1168 (let (name props children ret)
1170 ((stringp format-unit)
1171 (mapconcat (lambda (c)
1174 ;; ((eq c ?<) "&lt;")
1175 ;; ((eq c ?>) "&gt;")
1177 (char-to-string c))))
1178 (www-format-encode-string format-unit 'without-tags)
1181 ((consp format-unit)
1182 (setq name (car format-unit)
1183 props (nth 1 format-unit)
1184 children (nthcdr 2 format-unit))
1185 (when (eq name 'link)
1186 (setq ret (plist-get props :ref))
1187 (unless (stringp ret)
1188 (setq props (plist-remprop (copy-list props) :ref))
1190 (cons (list* 'ref nil ret)
1193 (format "<%s%s>%s</%s>"
1196 (www-xml-format-props props)
1198 (www-xml-format-list children)
1201 name (www-xml-format-props props)))
1204 (format "%s" format-unit)))))
1206 (defun www-xml-format-list (format-list)
1207 (if (atom format-list)
1208 (www-xml-format-unit format-list)
1209 (mapconcat #'www-xml-format-unit
1213 ;;; @ HTML generator
1216 (defun www-html-display-text (text)
1220 (goto-char (point-min))
1221 (while (search-forward "<" nil t)
1222 (replace-match "<" nil t))
1223 (goto-char (point-min))
1224 (while (search-forward ">" nil t)
1225 (replace-match ">" nil t))
1226 (goto-char (point-min))
1227 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1229 (format "<a href=\"%s\">%s</a>"
1233 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1234 (goto-char (point-min))
1235 (while (search-forward ">-" nil t)
1236 (replace-match "&GT-" nil t))
1239 (defun www-html-display-paragraph (text)
1241 (www-html-display-text text)
1248 (defvar coded-charset-GlyphWiki-id-alist
1249 '((=ucs "u" 4 x nil)
1250 (=ucs@JP "u" 4 x nil)
1251 (=ucs@jis "u" 4 x nil)
1252 (=ucs@gb "u" 4 x "-g")
1253 (=ucs@cns "u" 4 x "-t")
1254 (=ucs@ks "u" 4 x "-k")
1255 (=ucs@iso "u" 4 x "-u")
1256 (=ucs@unicode "u" 4 x "-us")
1257 (=adobe-japan1-6 "aj1-" 5 d nil)
1259 (=big5-cdp "cdp-" 4 x nil)
1260 (=cbeta "cb" 5 d nil)
1261 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1262 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1263 (=jis-x0208@1978 "j78-" 4 x nil)
1264 (=jis-x0208@1983 "j83-" 4 x nil)
1265 (=jis-x0208@1990 "j90-" 4 x nil)
1266 (=jis-x0212 "jsp-" 4 x nil)
1267 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1268 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1269 (=jis-x0213-2 "jx2-" 4 x nil)
1270 (=cns11643-1 "c1-" 4 x nil)
1271 (=cns11643-2 "c2-" 4 x nil)
1272 (=cns11643-3 "c3-" 4 x nil)
1273 (=cns11643-4 "c4-" 4 x nil)
1274 (=cns11643-5 "c5-" 4 x nil)
1275 (=cns11643-6 "c6-" 4 x nil)
1276 (=cns11643-7 "c7-" 4 x nil)
1277 (=daikanwa "dkw-" 5 d nil)
1278 (=gt-k "gt-k" 5 d nil)
1279 (=jef-china3 "jc3-" 4 x nil)
1280 (=big5 "b-" 4 x nil)
1281 (=ks-x1001 "k0-" 4 x nil)
1284 (defun char-GlyphWiki-id (char)
1285 (let ((rest coded-charset-GlyphWiki-id-alist)
1288 (setq spec (pop rest))
1289 (null (setq ret (char-feature char (car spec))))))
1292 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1294 ((and (or (encode-char char '=jis-x0208@1990)
1295 (encode-char char '=jis-x0212)
1296 (encode-char char '=jis-x0213-1))
1297 (setq code (encode-char char '=ucs@jis)))
1298 (format "u%04x" code)
1300 ((and (or (encode-char char '=gb2312)
1301 (encode-char char '=gb12345))
1302 (setq code (encode-char char '=ucs@gb)))
1303 (format "u%04x-g" code)
1305 ((and (or (encode-char char '=cns11643-1)
1306 (encode-char char '=cns11643-2)
1307 (encode-char char '=cns11643-3)
1308 (encode-char char '=cns11643-4)
1309 (encode-char char '=cns11643-5)
1310 (encode-char char '=cns11643-6)
1311 (encode-char char '=cns11643-7))
1312 (setq code (encode-char char '=ucs@cns)))
1313 (format "u%04x-t" code)
1315 ((and (encode-char char '=ks-x1001)
1316 (setq code (encode-char char '=ucs@ks)))
1317 (format "u%04x-k" code)
1319 (format (format "%s%%0%d%s%s"
1323 (or (nth 4 spec) ""))
1330 (provide 'cwiki-common)
1332 ;;; cwiki-common.el ends here