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 (concord-object-get object latest-feature)
143 (concord-object-get object feature))
146 (defun get-previous-code-point (ccs code)
147 (let ((chars (charset-chars ccs))
148 (dim (charset-dimension ccs))
150 mask byte-min byte-max
173 (setq bytes (make-vector dim 0))
175 (aset bytes i (logand (lsh code (* i -8)) mask))
178 (while (and (< i dim)
180 (aset bytes i (1- (aref bytes i)))
181 (< (aref bytes i) byte-min)))
182 (aset bytes i byte-max)
185 (setq dest (aref bytes 0)
188 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
192 (defun get-next-code-point (ccs code)
193 (let ((chars (charset-chars ccs))
194 (dim (charset-dimension ccs))
196 mask byte-min byte-max
219 (setq bytes (make-vector dim 0))
221 (aset bytes i (logand (lsh code (* i -8)) mask))
224 (while (and (< i dim)
226 (aset bytes i (1+ (aref bytes i)))
227 (> (aref bytes i) byte-max)))
228 (aset bytes i byte-min)
231 (setq dest (aref bytes 0)
234 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
238 (defun find-previous-defined-code-point (ccs code)
239 (let ((i (get-previous-code-point ccs code))
242 ((eq ccs '=jis-x0208)
243 (setq ccs '=jis-x0208@1990))
244 ((eq ccs '=jis-x0213-1)
245 (setq ccs '=jis-x0213-1@2004)))
248 (null (setq char (decode-char ccs i
249 (unless (eq ccs '=ucs)
251 (setq i (get-previous-code-point ccs i)))
254 (defun find-next-defined-code-point (ccs code)
255 (let ((i (get-next-code-point ccs code))
257 (setq max (+ code 1000))
259 ((eq ccs '=jis-x0208)
260 (setq ccs '=jis-x0208@1990))
261 ((eq ccs '=jis-x0213-1)
262 (setq ccs '=jis-x0213-1@2004)))
265 (null (setq char (decode-char ccs i
266 (unless (eq ccs '=ucs)
268 (setq i (get-next-code-point ccs i)))
272 ;;; @ URI representation
275 (defun www-uri-decode-feature-name (uri-feature)
278 ((string-match "^from\\." uri-feature)
279 (intern (format "<-%s" (substring uri-feature (match-end 0))))
281 ((string-match "^to\\." uri-feature)
282 (intern (format "->%s" (substring uri-feature (match-end 0))))
284 ((string-match "^rep\\." uri-feature)
285 (intern (format "=%s" (substring uri-feature (match-end 0))))
287 ((string-match "^g\\." uri-feature)
288 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
290 ((string-match "^gi\\." uri-feature)
291 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
293 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
294 (intern (format "=>>%s%s"
295 (make-string (string-to-int
296 (match-string 1 uri-feature))
298 (substring uri-feature (match-end 0))))
300 ((string-match "^a\\." uri-feature)
301 (intern (format "=>%s" (substring uri-feature (match-end 0))))
303 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
304 (intern (format "%s>%s"
305 (make-string (string-to-int
306 (match-string 1 uri-feature))
308 (substring uri-feature (match-end 0))))
310 ((and (setq feature (intern (format "=>%s" uri-feature)))
311 (find-charset feature))
313 ((and (setq feature (intern (format "=>>%s" uri-feature)))
314 (find-charset feature))
316 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
317 (find-charset feature))
319 ((and (setq feature (intern (format "=%s" uri-feature)))
320 (find-charset feature))
322 (t (intern uri-feature)))))
324 (defun www-uri-encode-feature-name (feature-name)
325 (setq feature-name (symbol-name feature-name))
327 ((string-match "^=\\([^=>]+\\)" feature-name)
328 (concat "rep." (substring feature-name (match-beginning 1)))
330 ((string-match "^=>>\\([^=>]+\\)" feature-name)
331 (concat "g." (substring feature-name (match-beginning 1)))
333 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
334 (concat "gi." (substring feature-name (match-beginning 1)))
336 ((string-match "^=>>\\(>+\\)" feature-name)
338 (length (match-string 1 feature-name))
339 (substring feature-name (match-end 1)))
341 ((string-match "^=>\\([^=>]+\\)" feature-name)
342 (concat "a." (substring feature-name (match-beginning 1)))
344 ((string-match "^\\(=+\\)>" feature-name)
346 (length (match-string 1 feature-name))
347 (substring feature-name (match-end 0)))
349 ((string-match "^->" feature-name)
350 (concat "to." (substring feature-name (match-end 0)))
352 ((string-match "^<-" feature-name)
353 (concat "from." (substring feature-name (match-end 0)))
357 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
358 (format "%s?feature=%s&char=%s"
359 chise-wiki-view-url uri-feature-name uri-char))
361 (defun www-uri-decode-object (genre char-rep)
364 ((string-match "\\(%3A\\|:\\)" char-rep)
365 (setq ccs (substring char-rep 0 (match-beginning 0))
366 cpos (substring char-rep (match-end 0)))
367 (setq ccs (www-uri-decode-feature-name ccs))
369 ((string-match "^0x" cpos)
371 (string-to-number (substring cpos (match-end 0)) 16))
374 (setq cpos (car (read-from-string cpos)))
376 (if (and (eq genre 'character)
378 (decode-char ccs cpos)
379 (concord-decode-object ccs cpos genre))
382 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
384 ((eq genre 'character)
385 (when (= (length char-rep) 1)
389 (concord-decode-object
390 '=id (www-uri-decode-feature-name char-rep) 'feature)
393 (concord-decode-object
394 '=id (car (read-from-string char-rep)) genre)
397 (defun www-uri-encode-object (object)
398 (if (characterp object)
399 (if (encode-char object '=ucs)
402 (format "%%%02X" byte))
403 (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
405 (let ((ccs-list '(; =ucs
406 =cns11643-1 =cns11643-2 =cns11643-3
407 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
409 =jis-x0208 =jis-x0208@1990
412 =jis-x0213-1@2000 =jis-x0213-1@2004
413 =jis-x0208@1983 =jis-x0208@1978
414 =zinbun-oracle =>zinbun-oracle
417 =>>jis-x0208 =>>jis-x0213-1
418 =>jis-x0208 =>jis-x0213-1
425 (setq ccs (pop ccs-list))
426 (not (setq ret (encode-char object ccs 'defined-only)))))
429 (www-uri-encode-feature-name ccs)
431 ((and (setq ccs (car (split-char object)))
432 (setq ret (encode-char object ccs)))
434 (www-uri-encode-feature-name ccs)
437 (format "system-char-id:0x%X"
438 (encode-char object 'system-char-id))
440 (format "rep.id:%s" (concord-object-id object))))
442 (defun est-format-object (object)
443 (if (characterp object)
444 (char-to-string object)
445 (format "%s" (concord-object-id object))))
448 ;;; @ Feature name presentation
451 (defun www-format-feature-name-default (feature-name)
455 (symbol-name feature-name)
459 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
460 (let ((str (symbol-name feature-name))
463 ((string-match "\\*[^*]+$" str)
464 (setq base (substring str 0 (match-beginning 0))
465 meta (substring str (match-beginning 0)))
466 (concat (www-format-feature-name* (intern base) lang)
469 (www-format-feature-name-default feature-name)
472 (defun www-format-feature-name-as-rel-to (feature-name)
473 (concat "\u2192" (substring (symbol-name feature-name) 2)))
475 (defun www-format-feature-name-as-rel-from (feature-name)
476 (concat "\u2190" (substring (symbol-name feature-name) 2)))
478 (defun www-format-feature-name-as-CCS (feature-name)
481 (symbol-name feature-name)
483 (dest (upcase (pop rest))))
484 (when (string-match "^=+>*" dest)
485 (setq dest (concat (substring dest 0 (match-end 0))
487 (substring dest (match-end 0)))))
491 (setq dest (concat dest " " (upcase (pop rest)))))
492 (if (string-match "^[0-9]+$" (car rest))
493 (concat dest "-" (car rest))
494 (concat dest " " (upcase (car rest))))
498 (defun www-format-feature-name* (feature-name &optional lang)
499 (let (name fn parent ret)
502 (char-feature-property
504 (intern (format "name@%s" lang))))
505 (char-feature-property
506 feature-name 'name)))
507 ((and (setq name (symbol-name feature-name))
508 (string-match "\\*" name))
509 (www-format-feature-name-as-metadata feature-name lang))
511 (setq fn feature-name)
512 (while (and (setq parent (char-feature-name-parent fn))
515 (char-feature-property
517 (intern (format "name@%s" lang))))
518 (char-feature-property
523 (concat ret (substring (symbol-name feature-name)
524 (length (symbol-name parent)))))
525 ((find-charset feature-name)
526 (www-format-feature-name-as-CCS feature-name))
527 ((string-match "^\\(->\\)" name)
528 (www-format-feature-name-as-rel-to feature-name))
529 ((string-match "^\\(<-\\)" name)
530 (www-format-feature-name-as-rel-from feature-name))
532 (www-format-feature-name-default feature-name)
536 (defun www-format-feature-name (feature-name &optional lang)
537 (www-format-encode-string
538 (www-format-feature-name* feature-name lang)))
541 ;;; @ Feature value presentation
544 (defun www-format-value-as-kuten (value)
546 (- (lsh value -8) 32)
547 (- (logand value 255) 32)))
549 (defun www-format-value-default (value &optional without-tags)
553 (www-format-encode-string
557 (www-format-encode-string (format "%S" value) without-tags)))
559 (defun www-format-value-as-char-list (value &optional without-tags)
564 (www-format-encode-string
565 (format (if (characterp unit)
570 (let (genre-o name-f ret)
572 (if (characterp unit)
573 (format "<a href=\"%s?char=%s\">%s</a>"
575 (www-uri-encode-object unit)
576 (www-format-encode-string (char-to-string unit)))
577 (format "<a href=\"%s?%s=%s\">%s</a>"
579 (concord-object-genre unit)
580 (concord-object-id unit)
583 (www-get-feature-value
587 (concord-decode-object
589 (concord-object-genre unit)
591 (www-get-feature-value genre-o 'name)
593 (www-format-eval-feature-value
594 unit name-f nil nil nil ret
595 'without-tags 'without-edit)
598 (www-format-encode-string
603 (www-format-encode-string (format "%s" value) without-tags)))
605 (defun www-format-value-as-domain-list (value &optional without-tags)
606 (let (name source0 source num dest rest unit start end ddest)
615 (setq unit (pop rest))
617 (setq name (symbol-name unit)))
622 ((string-match "^zob1968=" name)
623 (setq source (intern (substring name 0 (match-end 0)))
624 num (substring name (match-end 0)))
625 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
626 (setq start (string-to-number
627 (match-string 1 num))
628 end (string-to-number
629 (match-string 2 num)))
630 (setq start (string-to-number num)
633 (if (eq source source0)
635 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
637 (setq source0 source)
639 " <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>"
640 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
642 (setq start (1+ start))
643 (while (<= start end)
648 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
650 (setq start (1+ start)))
654 (if (eq source source0)
656 (setq source0 source)
660 (www-format-encode-string (format "%s" value) without-tags))))
662 (defun www-format-value-as-ids (value &optional without-tags)
667 (www-format-encode-string
668 (format (if (characterp unit)
674 (if (characterp unit)
675 (format "<a href=\"%s?char=%s\">%s</a>"
677 (www-uri-encode-object unit)
678 (www-format-encode-string (char-to-string unit)))
679 (www-format-encode-string (format "%s" unit)))))
680 (ideographic-structure-to-ids value) " ")
681 (www-format-encode-string (format "%s" value) without-tags)))
683 (defun www-format-value-as-S-exp (value &optional without-tags)
684 (www-format-encode-string (format "%S" value) without-tags))
686 (defun www-format-value-as-HEX (value)
689 (www-format-value-as-S-exp value)))
691 (defun www-format-value-as-CCS-default (value)
694 (www-format-value-as-HEX value)
696 (www-format-value-as-S-exp value)))
698 (defun www-format-value-as-CCS-94x94 (value)
700 (format "0x%s [%s] (%d)"
701 (www-format-value-as-HEX value)
702 (www-format-value-as-kuten value)
704 (www-format-value-as-S-exp value)))
706 (defun www-format-value-as-kangxi-radical (value)
707 (if (and (integerp value)
710 (www-format-encode-string
711 (format "%c" (ideographic-radical value)))
712 (www-format-value-as-S-exp value)))
714 (defun www-format-value (object feature-name
715 &optional value format
716 without-tags without-edit)
718 (setq value (www-get-feature-value object feature-name)))
719 (www-format-apply-value object feature-name
720 format nil value nil nil
721 without-tags without-edit)
725 ;;; @ format evaluator
728 (defun www-format-encode-string (string &optional without-tags)
731 (let (plane code start end char variants ret rret)
732 (goto-char (point-min))
733 (while (search-forward "<" nil t)
734 (replace-match "<" nil t))
735 (goto-char (point-min))
736 (while (search-forward ">" nil t)
737 (replace-match ">" nil t))
739 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
740 (let ((coded-charset-entity-reference-alist
743 '(=cns11643-1 "C1-" 4 X)
744 '(=cns11643-2 "C2-" 4 X)
745 '(=cns11643-3 "C3-" 4 X)
746 '(=cns11643-4 "C4-" 4 X)
747 '(=cns11643-5 "C5-" 4 X)
748 '(=cns11643-6 "C6-" 4 X)
749 '(=cns11643-7 "C7-" 4 X)
751 '(=gb12345 "G1-" 4 X)
752 '(=jis-x0208@1990 "J90-" 4 X)
753 '(=jis-x0212 "JSP-" 4 X)
755 '(=jis-x0208@1997 "J97-" 4 X)
756 '(=jis-x0208@1978 "J78-" 4 X)
757 '(=jis-x0208@1983 "J83-" 4 X)
758 '(=ruimoku-v6 "RUI6-" 4 X)
759 '(=zinbun-oracle "ZOB-" 4 d)
760 '(=jef-china3 "JC3-" 4 X)
761 '(=daikanwa "M-" 5 d)
762 coded-charset-entity-reference-alist)))
763 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
765 (goto-char (point-min))
766 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
767 (setq code (string-to-int (match-string 1)))
769 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
771 chise-wiki-bitmap-glyphs-url
775 (goto-char (point-min))
776 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
777 (setq plane (match-string 1)
778 code (string-to-int (match-string 2) 16))
780 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
782 chise-wiki-bitmap-glyphs-url
785 (- (logand code 255) 32))
788 (goto-char (point-min))
789 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
790 (setq plane (string-to-int (match-string 1))
791 code (string-to-int (match-string 2) 16))
793 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
795 chise-wiki-bitmap-glyphs-url
798 (- (logand code 255) 32))
801 (goto-char (point-min))
802 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
803 (setq plane (string-to-int (match-string 1))
804 code (string-to-int (match-string 2) 16))
806 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
808 chise-wiki-bitmap-glyphs-url
812 (goto-char (point-min))
813 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
814 (setq code (string-to-int (match-string 1) 16))
816 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
820 (goto-char (point-min))
821 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
822 (setq code (string-to-int (match-string 2)))
824 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
826 chise-wiki-bitmap-glyphs-url
830 (goto-char (point-min))
831 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
832 (setq code (string-to-int (match-string 2)))
834 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
836 chise-wiki-glyph-cgi-url
840 (goto-char (point-min))
841 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
842 (setq code (string-to-int (match-string 2)))
844 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
846 chise-wiki-glyph-cgi-url
850 (goto-char (point-min))
851 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
852 (setq code (string-to-int (match-string 1) 16))
854 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
856 chise-wiki-glyph-cgi-url
860 (goto-char (point-min))
861 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
862 (setq code (string-to-int (match-string 1) 16))
864 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
866 chise-wiki-glyph-cgi-url
870 (goto-char (point-min))
871 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
872 (setq code (string-to-int (match-string 1) 16))
874 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
876 chise-wiki-glyph-cgi-url
880 (goto-char (point-min))
881 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
882 (setq code (string-to-int (match-string 2) 16))
884 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
889 (goto-char (point-min))
890 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
891 (setq code (string-to-int (match-string 1) 16))
892 (setq start (match-beginning 0)
894 (setq char (decode-char 'system-char-id code))
897 (or (www-get-feature-value char '->subsumptive)
898 (www-get-feature-value char '->denotational)))
901 (setq ret (www-format-encode-string
902 (char-to-string (car variants))))
903 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
904 (setq variants (cdr variants)))
906 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
908 (delete-region start end)
911 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
912 (www-get-feature-value char 'ideographic-structure)))
917 (if (characterp (setq rret (find-char ch)))
920 (www-format-encode-string
921 (char-to-string ch) without-tags)
922 (www-format-encode-string
923 (format "%S" ch) without-tags)))
927 (delete-region start end)
931 ;; (goto-char (point-min))
932 ;; (while (search-forward ">-" nil t)
933 ;; (replace-match "&GT-" t 'literal))
936 (defun www-format-props-to-string (props &optional format)
938 (setq format (plist-get props :format)))
940 (plist-get props :flag)
941 ;; (if (plist-get props :zero-padding)
943 (if (plist-get props :len)
945 (let ((ret (plist-get props :len)))
950 ((eq format 'decimal) "d")
951 ((eq format 'hex) "x")
952 ((eq format 'HEX) "X")
953 ((eq format 'S-exp) "S")
956 (defun www-format-apply-value (object feature-name
958 &optional uri-object uri-feature
959 without-tags without-edit)
963 ((memq format '(decimal hex HEX))
965 (format (www-format-props-to-string props format)
967 (www-format-encode-string
971 ((eq format 'wiki-text)
973 (www-xml-format-list value)
974 (www-format-eval-list value object feature-name nil uri-object
975 without-tags without-edit))
978 (www-format-encode-string
979 (format (www-format-props-to-string props format)
983 (www-format-value-as-kuten value))
984 ((eq format 'kangxi-radical)
985 (www-format-value-as-kangxi-radical value))
986 ((eq format 'space-separated-char-list)
987 (www-format-value-as-char-list value without-tags))
988 ((eq format 'space-separated-ids)
989 (www-format-value-as-ids value without-tags))
990 ((eq format 'space-separated-domain-list)
991 (www-format-value-as-domain-list value without-tags))
993 (www-format-encode-string (format "%s" value) without-tags)
996 (www-format-value-default value without-tags)
1001 (eq (plist-get props :mode) 'peek))
1003 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
1004 ><input type=\"submit\" value=\"edit\" /></a>"
1007 uri-object uri-feature format))))
1009 (defun www-format-eval-feature-value (object
1011 &optional format lang uri-object value
1012 without-tags without-edit)
1014 (setq value (www-get-feature-value object feature-name)))
1016 (setq format (www-feature-value-format feature-name)))
1019 (www-format-apply-value
1022 uri-object (www-uri-encode-feature-name feature-name)
1023 without-tags without-edit)
1026 (cond ((null (cdr format))
1027 (setq format (car format))
1028 (www-format-apply-value
1030 (car format) (nth 1 format) value
1031 uri-object (www-uri-encode-feature-name feature-name)
1032 without-tags without-edit)
1035 (www-format-eval-list format object feature-name lang uri-object
1036 without-tags without-edit)
1039 (defun www-format-eval-unit (exp object feature-name
1040 &optional lang uri-object value
1041 without-tags without-edit)
1043 (setq value (www-get-feature-value object feature-name)))
1045 (setq uri-object (www-uri-encode-object object)))
1047 ((stringp exp) (www-format-encode-string exp))
1051 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
1052 S-exp string default))
1053 (let ((fn (plist-get (nth 1 exp) :feature))
1054 domain domain-fn ret)
1057 (setq fn (intern fn)))
1058 (setq domain (char-feature-name-domain feature-name))
1059 (setq domain-fn (char-feature-name-at-domain fn domain))
1060 (if (setq ret (www-get-feature-value object domain-fn))
1061 (setq feature-name domain-fn
1063 (setq feature-name fn
1064 value (www-get-feature-value object fn)))
1065 (push feature-name chise-wiki-displayed-features)
1067 (if (eq (car exp) 'value)
1068 (www-format-eval-feature-value object feature-name
1069 (plist-get (nth 1 exp) :format)
1070 lang uri-object value
1071 without-tags without-edit)
1072 (www-format-apply-value
1074 (car exp) (nth 1 exp) value
1075 uri-object (www-uri-encode-feature-name feature-name)
1076 without-tags without-edit))
1078 ((eq (car exp) 'name)
1079 (let ((fn (plist-get (nth 1 exp) :feature))
1082 (setq domain (char-feature-name-domain feature-name))
1084 (setq fn (intern fn)))
1085 (setq domain-fn (char-feature-name-at-domain fn domain))
1086 (setq feature-name domain-fn)))
1088 (www-format-feature-name feature-name lang)
1089 (format "<a href=\"%s\">%s</a>"
1090 (www-uri-make-feature-name-url
1091 (www-uri-encode-feature-name feature-name)
1093 (www-format-feature-name feature-name lang))
1096 ((eq (car exp) 'name-url)
1097 (let ((fn (plist-get (nth 1 exp) :feature))
1100 (setq domain (char-feature-name-domain feature-name))
1102 (setq fn (intern fn)))
1103 (setq domain-fn (char-feature-name-at-domain fn domain))
1104 (setq feature-name domain-fn)))
1105 (www-uri-make-feature-name-url
1106 (www-uri-encode-feature-name feature-name)
1109 ((eq (car exp) 'domain-name)
1110 (let ((domain (char-feature-name-domain feature-name)))
1112 (format "@%s" domain))))
1113 ((eq (car exp) 'prev-char)
1116 (let ((prev-char (find-previous-defined-code-point
1117 feature-name value)))
1119 (format "\n<a href=\"%s?char=%s\">%s</a>"
1121 (www-uri-encode-object prev-char)
1122 "<input type=\"submit\" value=\"-\" />"
1123 ;; (www-format-encode-string
1124 ;; (char-to-string prev-char))
1128 ((eq (car exp) 'next-char)
1131 (let ((next-char (find-next-defined-code-point
1132 feature-name value)))
1134 (format "<a href=\"%s?char=%s\">%s</a>"
1136 (www-uri-encode-object next-char)
1137 "<input type=\"submit\" value=\"+\" />"
1138 ;; (www-format-encode-string
1139 ;; (char-to-string next-char))
1143 ((eq (car exp) 'link)
1145 (www-format-eval-list (nthcdr 2 exp)
1146 object feature-name lang uri-object
1147 without-tags without-edit)
1152 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1153 object feature-name lang uri-object
1154 'without-tags 'without-edit)
1155 (www-format-eval-list (nthcdr 2 exp)
1156 object feature-name lang uri-object
1157 without-tags without-edit)))
1164 (www-format-eval-list (nthcdr 2 exp) object feature-name
1166 without-tags without-edit)
1169 (defun www-format-eval-list (format-list object feature-name
1170 &optional lang uri-object
1171 without-tags without-edit)
1172 (if (consp format-list)
1175 (www-format-eval-unit exp object feature-name lang uri-object
1176 nil without-tags without-edit))
1178 (www-format-eval-unit format-list object feature-name lang uri-object
1179 nil without-tags without-edit)))
1185 (defun www-xml-format-props (props)
1189 (setq key (pop props)
1192 (setq key (symbol-name key)))
1193 (if (eq (aref key 0) ?:)
1194 (setq key (substring key 1)))
1196 (format "%s %s=\"%s\""
1198 (www-format-encode-string
1199 (format "%s" val) 'without-tags))))
1202 (defun www-xml-format-unit (format-unit)
1203 (let (name props children ret)
1205 ((stringp format-unit)
1206 (mapconcat (lambda (c)
1209 ;; ((eq c ?<) "&lt;")
1210 ;; ((eq c ?>) "&gt;")
1212 (char-to-string c))))
1213 (www-format-encode-string format-unit 'without-tags)
1216 ((consp format-unit)
1217 (setq name (car format-unit)
1218 props (nth 1 format-unit)
1219 children (nthcdr 2 format-unit))
1220 (when (eq name 'link)
1221 (setq ret (plist-get props :ref))
1222 (unless (stringp ret)
1223 (setq props (plist-remprop (copy-list props) :ref))
1225 (cons (list* 'ref nil ret)
1228 (format "<%s%s>%s</%s>"
1231 (www-xml-format-props props)
1233 (www-xml-format-list children)
1236 name (www-xml-format-props props)))
1239 (format "%s" format-unit)))))
1241 (defun www-xml-format-list (format-list)
1242 (if (atom format-list)
1243 (www-xml-format-unit format-list)
1244 (mapconcat #'www-xml-format-unit
1248 ;;; @ HTML generator
1251 (defun www-html-display-text (text)
1255 (goto-char (point-min))
1256 (while (search-forward "<" nil t)
1257 (replace-match "<" nil t))
1258 (goto-char (point-min))
1259 (while (search-forward ">" nil t)
1260 (replace-match ">" nil t))
1261 (goto-char (point-min))
1262 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1264 (format "<a href=\"%s\">%s</a>"
1268 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1269 (goto-char (point-min))
1270 (while (search-forward ">-" nil t)
1271 (replace-match "&GT-" nil t))
1274 (defun www-html-display-paragraph (text)
1276 (www-html-display-text text)
1283 (defvar coded-charset-GlyphWiki-id-alist
1284 '((=ucs "u" 4 x nil)
1285 (=ucs@JP "u" 4 x nil)
1286 (=ucs@jis "u" 4 x nil)
1287 (=ucs@gb "u" 4 x "-g")
1288 (=ucs@cns "u" 4 x "-t")
1289 (=ucs@ks "u" 4 x "-k")
1290 (=ucs@iso "u" 4 x "-u")
1291 (=ucs@unicode "u" 4 x "-us")
1292 (=adobe-japan1-6 "aj1-" 5 d nil)
1294 (=big5-cdp "cdp-" 4 x nil)
1295 (=cbeta "cb" 5 d nil)
1296 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1297 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1298 (=jis-x0208@1978 "j78-" 4 x nil)
1299 (=jis-x0208@1983 "j83-" 4 x nil)
1300 (=jis-x0208@1990 "j90-" 4 x nil)
1301 (=jis-x0212 "jsp-" 4 x nil)
1302 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1303 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1304 (=jis-x0213-2 "jx2-" 4 x nil)
1305 (=cns11643-1 "c1-" 4 x nil)
1306 (=cns11643-2 "c2-" 4 x nil)
1307 (=cns11643-3 "c3-" 4 x nil)
1308 (=cns11643-4 "c4-" 4 x nil)
1309 (=cns11643-5 "c5-" 4 x nil)
1310 (=cns11643-6 "c6-" 4 x nil)
1311 (=cns11643-7 "c7-" 4 x nil)
1312 (=daikanwa "dkw-" 5 d nil)
1313 (=gt-k "gt-k" 5 d nil)
1314 (=jef-china3 "jc3-" 4 x nil)
1315 (=big5 "b-" 4 x nil)
1316 (=ks-x1001 "k0-" 4 x nil)
1319 (defun char-GlyphWiki-id (char)
1320 (let ((rest coded-charset-GlyphWiki-id-alist)
1323 (setq spec (pop rest))
1324 (null (setq ret (char-feature char (car spec))))))
1327 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1329 ((and (or (encode-char char '=jis-x0208@1990)
1330 (encode-char char '=jis-x0212)
1331 (encode-char char '=jis-x0213-1))
1332 (setq code (encode-char char '=ucs@jis)))
1333 (format "u%04x" code)
1335 ((and (or (encode-char char '=gb2312)
1336 (encode-char char '=gb12345))
1337 (setq code (encode-char char '=ucs@gb)))
1338 (format "u%04x-g" code)
1340 ((and (or (encode-char char '=cns11643-1)
1341 (encode-char char '=cns11643-2)
1342 (encode-char char '=cns11643-3)
1343 (encode-char char '=cns11643-4)
1344 (encode-char char '=cns11643-5)
1345 (encode-char char '=cns11643-6)
1346 (encode-char char '=cns11643-7))
1347 (setq code (encode-char char '=ucs@cns)))
1348 (format "u%04x-t" code)
1350 ((and (encode-char char '=ks-x1001)
1351 (setq code (encode-char char '=ucs@ks)))
1352 (format "u%04x-k" code)
1354 (format (format "%s%%0%d%s%s"
1358 (or (nth 4 spec) ""))
1365 (provide 'cwiki-common)
1367 ;;; cwiki-common.el ends here