From e766809cb9630d7b323d63ca82808b8b03fa3510 Mon Sep 17 00:00:00 2001
From: MORIOKA Tomohiko ")
+ (www-html-display-text text)
+ (princ " ")
+ (princ
+ (www-format-eval-list
+ (or (char-feature-property (car cell) 'format)
+ '((name) " : " (value)))
+ char (car cell) lang uri-char))
+ (princ
+ (format " "
+ chise-wiki-edit-url
+ (www-format-encode-string uri-char)
+ (www-format-encode-string
+ (www-uri-encode-feature-name
+ (intern (format "%s*note" (car cell)))))))
+ (princ " \n"
+ ""
+ code
+ chise-wiki-glyphs-url
+ (/ code 1000) code)
+ t 'literal))
+
+ (goto-char (point-min))
+ (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
+ (setq plane (match-string 1)
+ code (string-to-int (match-string 2) 16))
+ (replace-match
+ (format "
"
+ plane code
+ chise-wiki-glyphs-url
+ plane
+ (- (lsh code -8) 32)
+ (- (logand code 255) 32))
+ t 'literal))
+
+ (goto-char (point-min))
+ (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
+ (setq plane (string-to-int (match-string 1))
+ code (string-to-int (match-string 2) 16))
+ (replace-match
+ (format "
"
+ plane code
+ chise-wiki-glyphs-url
+ plane
+ (- (lsh code -8) 32)
+ (- (logand code 255) 32))
+ t 'literal))
+
+ (goto-char (point-min))
+ (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
+ (setq plane (string-to-int (match-string 1))
+ code (string-to-int (match-string 2) 16))
+ (replace-match
+ (format "
"
+ plane code
+ chise-wiki-glyphs-url
+ plane code)
+ t 'literal))
+ ))
+ (goto-char (point-min))
+ (while (search-forward ">-" nil t)
+ (replace-match ">-" t 'literal))
+
+ (buffer-string))))
+
+(defun www-format-props-to-string (props &optional format)
+ (unless format
+ (setq format (plist-get props :format)))
+ (concat "%"
+ (plist-get props :flag)
+ (if (plist-get props :zero-padding)
+ "0")
+ (if (plist-get props :len)
+ (format "%d" (plist-get props :len)))
+ (cond
+ ((eq format 'decimal) "d")
+ ((eq format 'hex) "x")
+ ((eq format 'HEX) "X")
+ ((eq format 'S-exp) "S")
+ (t "s"))))
+
+(defun www-format-apply-value (format props value
+ &optional uri-char uri-feature
+ without-tags)
+ (let (ret)
+ (setq ret
+ (cond
+ ((memq format '(decimal hex HEX))
+ (if (integerp value)
+ (format (www-format-props-to-string props format)
+ value)
+ (www-format-encode-string
+ (format "%s" value)
+ without-tags))
+ )
+ ((eq format 'S-exp)
+ (www-format-encode-string
+ (format (www-format-props-to-string props format)
+ value)
+ without-tags))
+ ((eq format 'ku-ten)
+ (www-format-value-as-kuten value))
+ ((eq format 'space-separated-char-list)
+ (www-format-value-as-char-list value without-tags))
+ (t
+ (setq format 'default)
+ (www-format-encode-string
+ (format (www-format-props-to-string props 'default)
+ value)
+ without-tags))))
+ (if (or without-tags (eq (plist-get props :mode) 'peek))
+ ret
+ (format "%s "
+ ret
+ chise-wiki-edit-url
+ uri-char uri-feature format))))
+
+(defun www-format-eval-feature-value (char
+ feature-name
+ &optional format lang uri-char value)
+ (unless value
+ (setq value (char-feature char feature-name)))
+ (unless format
+ (setq format (www-feature-value-format feature-name)))
+ (cond
+ ((symbolp format)
+ (www-format-apply-value
+ format nil value
+ uri-char (www-uri-encode-feature-name feature-name))
+ )
+ ((consp format)
+ (cond ((null (cdr format))
+ (setq format (car format))
+ (www-format-apply-value
+ (car format) (nth 1 format) value
+ uri-char (www-uri-encode-feature-name feature-name))
+ )
+ (t
+ (www-format-eval-list format char feature-name lang uri-char)
+ )))))
+
+(defun www-format-eval-unit (exp char feature-name
+ &optional lang uri-char value)
+ (unless value
+ (setq value (char-feature char feature-name)))
+ (unless uri-char
+ (setq uri-char (www-uri-encode-char char)))
+ (cond
+ ((stringp exp) (www-format-encode-string exp))
+ ((null exp) "")
+ ((consp exp)
+ (cond
+ ((memq (car exp) '(value decimal hex HEX ku-ten S-exp default))
+ (if (eq (car exp) 'value)
+ (www-format-eval-feature-value char feature-name
+ (plist-get (nth 1 exp) :format)
+ lang uri-char value)
+ (www-format-apply-value
+ (car exp) (nth 1 exp) value
+ uri-char (www-uri-encode-feature-name feature-name)))
+ )
+ ((eq (car exp) 'name)
+ (format "%s"
+ chise-wiki-view-url
+ (www-uri-encode-feature-name feature-name)
+ uri-char
+ (www-format-feature-name feature-name lang))
+ )
+ ((eq (car exp) 'link)
+ (format "%s"
+ (www-format-eval-list (plist-get (nth 1 exp) :ref)
+ char feature-name lang uri-char)
+ (www-format-eval-list (nthcdr 2 exp)
+ char feature-name lang uri-char)))
+ (t
+ (format "<%s
+>%s%s
+>"
+ (car exp)
+ (www-format-eval-list (nthcdr 2 exp) char feature-name
+ lang uri-char)
+ (car exp)))))))
+
+(defun www-format-eval-list (format-list char feature-name
+ &optional lang uri-char)
+ (if (consp format-list)
+ (mapconcat
+ (lambda (exp)
+ (www-format-eval-unit exp char feature-name lang uri-char))
+ format-list "")
+ (www-format-eval-unit format-list char feature-name lang uri-char)))
+
+
+;;; @ HTML generator
+;;;
+
+(defun www-html-display-text (text)
+ (princ
+ (with-temp-buffer
+ (insert text)
+ (goto-char (point-min))
+ (while (search-forward "<" nil t)
+ (replace-match "<" nil t))
+ (goto-char (point-min))
+ (while (search-forward ">" nil t)
+ (replace-match ">" nil t))
+ (goto-char (point-min))
+ (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
+ (replace-match
+ (format "%s"
+ (match-string 2)
+ (match-string 1))
+ nil t))
+ (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
+ (goto-char (point-min))
+ (while (search-forward "&" nil t)
+ (replace-match "&" nil t))
+ (buffer-string))))
+
+(defun www-html-display-paragraph (text)
+ (princ "
%s
\n"
+ (www-format-encode-string (char-to-string char))))
+ (princ "\n")
+ )))
+
+(defun www-edit-display-feature-desc (uri-feature-name
+ uri-property-name
+ &optional lang uri-char)
+ (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
+ (property-name (www-uri-decode-feature-name uri-property-name))
+ name@lang)
+ (princ
+ (encode-coding-string
+ (format "
+
\n")
+ (princ (format "user=%s\n" user))
+ (princ (format "local user=%s\n" (user-login-name)))
+ (princ (format "lang=%S\n" lang))
+ (princ emacs-version)
+ (princ " CHISE ")
+ (princ xemacs-chise-version)
+ (princ "
+
+")
+ )
+ (error nil
+ (princ (format "%S" err)))
+ ))
diff --git a/cwiki-set.el b/cwiki-set.el
new file mode 100644
index 0000000..fc0b541
--- /dev/null
+++ b/cwiki-set.el
@@ -0,0 +1,214 @@
+;; -*- coding: utf-8-mcs-er -*-
+(defvar chise-wiki-view-url "../view.cgi")
+(defvar chise-wiki-edit-url "edit.cgi")
+
+(require 'cwiki-common)
+(require 'cwiki-view)
+
+
+(defun www-parse-string-as-space-separated-char-list (string)
+ (let (dest char)
+ (dolist (unit (split-string string " "))
+ (if (setq char (www-uri-decode-char unit))
+ (setq dest (cons char dest))))
+ (nreverse dest)))
+
+(defun www-feature-parse-string (feature-name string &optional format)
+ (unless format
+ (setq format (www-feature-value-format feature-name)))
+ (cond ((eq format 'space-separated-char-list)
+ (www-parse-string-as-space-separated-char-list string))
+ ((eq format 'decimal)
+ (string-to-number string))
+ ((or (eq format 'HEX)(eq format 'hex))
+ (string-to-number string 16))
+ ((eq format 'S-exp)
+ (if (= (length string) 0)
+ nil
+ (read string)))
+ (t string)))
+
+(defun www-set-display-char-desc (uri-char feature value format &optional lang)
+ (when (stringp feature)
+ (setq feature (intern feature)))
+ (when (stringp format)
+ (setq format (intern format)))
+ (let ((char (www-uri-decode-char uri-char)))
+ (when (characterp char)
+ (princ
+ (encode-coding-string
+ (format "
+%s
\n"
+ (www-format-encode-string (char-to-string char))))
+ (dolist (cell (sort (char-attribute-alist char)
+ (lambda (a b)
+ (char-attribute-name< (car a)(car b)))))
+ (princ "%s
\n"
+ feature-name)
+ 'utf-8-mcs-er))
+ (princ
+ (format "
+"
+ (or (www-format-feature-name feature-name) "")
+ chise-wiki-edit-url
+ ;; (char-feature-property feature-name 'name)
+ uri-feature-name ; (www-uri-encode-feature-name feature-name)
+ ))
+ (when lang
+ (princ
+ (format "
+"
+ name@lang
+ (or (www-format-encode-string
+ (char-feature-property feature-name name@lang)) "")
+ chise-wiki-edit-url
+ uri-feature-name
+ name@lang)))
+ (www-html-display-paragraph
+ (format "type : %s"
+ (or (www-feature-type feature-name)
+ ;; (char-feature-property feature-name 'type)
+ 'generic)))
+ (www-html-display-paragraph
+ (format "description : %s"
+ (or (char-feature-property feature-name 'description)
+ "")))
+ (when lang
+ (www-html-display-paragraph
+ (format "description@%s : %s"
+ lang
+ (or (char-feature-property
+ feature-name
+ (intern (format "description@%s" lang)))
+ ""))))
+ (princ "
")
+ (www-html-display-paragraph
+ (format "ã[[%c|../view.cgi?char=%s]]ãã«\u623Bã"
+ (www-uri-decode-char uri-char) uri-char))
+ ))
+
+(defun www-batch-set ()
+ (setq terminal-coding-system 'binary)
+ (condition-case err
+ (let* ((target (pop command-line-args-left))
+ (user (pop command-line-args-left))
+ (accept-language (pop command-line-args-left))
+ (lang
+ (intern (car (split-string
+ (car (split-string
+ (car (split-string accept-language ","))
+ ";"))
+ "-"))))
+ ret name val prop)
+ (princ "Content-Type: text/html; charset=UTF-8
+
+
+
+")
+ (setq target
+ (mapcar (lambda (cell)
+ (if (string-match "=" cell)
+ (progn
+ (setq name (substring
+ cell 0 (match-beginning 0))
+ val (substring cell (match-end 0)))
+ (cons
+ (intern
+ (decode-uri-string name 'utf-8-mcs-er))
+ val))
+ (list (decode-uri-string cell 'utf-8-mcs-er))))
+ (split-string target "&")))
+ (setq ret (car target))
+ (cond ((eq (car ret) 'char)
+ (setq prop (nth 2 target))
+ (www-set-display-char-desc
+ (decode-uri-string (cdr ret) 'utf-8-mcs-er)
+ (cdr (assq 'feature-name target))
+ (decode-uri-string (cdr prop) 'utf-8-mcs-er)
+ (car prop)
+ lang)
+ )
+ ((eq (car ret) 'feature)
+ (setq prop (nth 2 target))
+ (www-set-display-feature-desc
+ (intern (decode-uri-string (cdr ret) 'utf-8-mcs-er))
+ (car prop)
+ (decode-uri-string (cdr prop) 'utf-8-mcs-er)
+ lang
+ (decode-uri-string (cdr (assq 'char target))))
+ ))
+ (www-html-display-paragraph
+ (format "%S" target))
+ (princ "\n
\n")
+ (princ (format "user=%s\n" user))
+ (princ (format "local user=%s\n" (user-login-name)))
+ (princ (format "lang=%S\n" lang))
+ (princ emacs-version)
+ (princ " CHISE ")
+ (princ xemacs-chise-version)
+ (princ "
+
+")
+ )
+ (error nil
+ (princ (format "%S" err)))
+ ))
diff --git a/cwiki-view.el b/cwiki-view.el
new file mode 100644
index 0000000..2f7721e
--- /dev/null
+++ b/cwiki-view.el
@@ -0,0 +1,214 @@
+;; -*- coding: utf-8-mcs-er -*-
+(require 'cwiki-common)
+
+(defvar chise-wiki-view-url "view.cgi")
+(defvar chise-wiki-edit-url "edit/edit.cgi")
+(defvar chise-wiki-add-url "edit/add.cgi")
+
+(defun www-char-display-feature-default (char feature-name &optional value
+ lang uri-char)
+ (unless value
+ (setq value (char-feature char feature-name)))
+ (unless uri-char
+ (setq uri-char (char-to-string char)))
+ (www-html-display-paragraph
+ (format "[[%s|%?feature=%s&char=%s]] : %s [[[edit|%s?char=%s&feature=%s]]]"
+ (www-format-feature-name feature-name lang)
+ chise-wiki-view-url
+ (www-uri-encode-feature-name feature-name)
+ uri-char
+ (www-format-value value feature-name)
+ chise-wiki-edit-url
+ uri-char
+ (www-uri-encode-feature-name feature-name)
+ )))
+
+(defun www-char-display-feature-as-ucs (char feature-name &optional value)
+ (unless value
+ (setq value (char-feature char feature-name)))
+ (www-html-display-paragraph
+ (format "= [[U+%s|http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=%s]] (%d)"
+ (www-format-value-as-HEX value)
+ (www-format-value-as-HEX value)
+ value)))
+
+(defun www-display-char-desc (uri-char &optional lang level)
+ (unless level
+ (setq level 1))
+ (let ((char (www-uri-decode-char uri-char)))
+ (when (characterp char)
+ (when (= level 1)
+ (princ
+ (encode-coding-string
+ (format "
+"))
+ (dolist (cell (sort (char-attribute-alist char)
+ (lambda (a b)
+ (char-attribute-name< (car a)(car b)))))
+ (princ
+ (if (= level 1)
+ "
\n" + "
name : %s " + (or (www-format-feature-name feature-name) ""))) + (www-html-display-text + (format "[[[edit|%s?feature=%s&property=name&char=%s]]]" + ;; (char-feature-property feature-name 'name) + chise-wiki-edit-url + uri-feature-name ; (www-uri-encode-feature-name feature-name) + uri-char)) + (princ "
") + (when lang + (princ "") + (princ + (www-format-encode-string + (format "%s : %s" + name@lang + (or (char-feature-property feature-name name@lang) "")))) + (www-html-display-text + (format " [[[edit|%s?feature=%s&property=%s&char=%s]]]" + chise-wiki-edit-url + uri-feature-name + name@lang + uri-char)) + (princ "
")) + (www-html-display-paragraph + (format "type : %s" + (or (www-feature-type feature-name) + ;; (char-feature-property feature-name 'type) + 'generic))) + (www-html-display-paragraph + (format "description : %s" + (or (char-feature-property feature-name 'description) + ""))) + (when lang + (www-html-display-paragraph + (format "description@%s : %s" + lang + (or (char-feature-property + feature-name + (intern (format "description@%s" lang))) + "")))) + )) + +(defun www-batch-view () + (setq terminal-coding-system 'binary) + (condition-case err + (let* ((target (pop command-line-args-left)) + (user (pop command-line-args-left)) + (accept-language (pop command-line-args-left)) + (lang + (intern + (car (split-string + (car (split-string + (car (split-string accept-language ",")) + ";")) + "-")))) + ret) + (princ "Content-Type: text/html; charset=UTF-8 + + + +") + (cond + ((stringp target) + (setq target + (mapcar (lambda (cell) + (if (string-match "=" cell) + (cons + (intern + (decode-uri-string + (substring cell 0 (match-beginning 0)) + 'utf-8-mcs-er)) + (substring cell (match-end 0))) + (list (decode-uri-string cell 'utf-8-mcs-er)))) + (split-string target "&"))) + (setq ret (car target)) + (cond ((eq (car ret) 'char) + (www-display-char-desc + (decode-uri-string (cdr ret) 'utf-8-mcs-er) + lang) + ) + ((eq (car ret) 'feature) + (www-display-feature-desc + (decode-uri-string (cdr ret) 'utf-8-mcs-er) + (decode-uri-string (cdr (assq 'char target))) + lang) + )) + )) + (princ "\n