- (map (assoc (riece-format-identity identity) riece-log-directory-map))
- name)
- (cond (map (setq name (cdr map)))
- ((string-match riece-channel-regexp channel)
- (let ((suffix (match-string 2 channel)))
- (setq name (substring channel (match-end 1) (match-beginning 2)))
- (when (and (stringp suffix)
- (string-match "^:\\*\\.\\(.*\\)" suffix))
- (setq name (concat name "-" (match-string 1 suffix))))))
- (t (setq name "priv")))
- (if server
- (expand-file-name name (expand-file-name server riece-log-directory))
- (expand-file-name name riece-log-directory))))
+ (map (assoc (riece-format-identity identity) riece-log-directory-map)))
+ (if map
+ (expand-file-name (cdr map) riece-log-directory)
+ (expand-file-name (riece-log-encode-file-name prefix)
+ (expand-file-name
+ (concat "." (riece-log-encode-file-name server))
+ riece-log-directory)))))
+
+(defun riece-log-encode-file-name (file-name)
+ (if riece-log-file-name-coding-system
+ (setq file-name
+ (encode-coding-string file-name
+ riece-log-file-name-coding-system)))
+ (let ((index 0)
+ c)
+ (while (string-match "[^-0-9A-Za-z_\x80-\xFF]" file-name index)
+ (setq c (aref file-name (match-beginning 0)))
+ (if (eq c ?=)
+ (setq file-name (replace-match "==" nil t file-name)
+ index (1+ (match-end 0)))
+ (setq file-name (replace-match (format "=%02X" c) nil t file-name)
+ index (+ 2 (match-end 0)))))
+ file-name))
+
+(defun riece-log-decode-file-name (file-name)
+ (let ((index 0))
+ (while (string-match "==\\|=\\([0-7][0-9A-F]\\)" file-name index)
+ (setq file-name (replace-match
+ (if (eq (aref file-name (1- (match-end 0))) ?=)
+ "="
+ (char-to-string
+ (car (read-from-string
+ (concat "?\\x" (match-string 1 file-name))))))
+ nil t file-name)
+ index (1+ (match-beginning 0))))
+ file-name)
+ (if riece-log-file-name-coding-system
+ (setq file-name
+ (decode-coding-string file-name
+ riece-log-file-name-coding-system)))
+ file-name)
+
+(defun riece-log-insert (identity lines)
+ "Insert logs for IDENTITY at most LINES.
+If LINES is t, insert today's logs entirely."
+ (let* (file-name-coding-system
+ default-file-name-coding-system
+ (files (riece-log-list-files identity
+ (if (eq lines t) (current-time))))
+ name coding-system date point)
+ (while (and (or (eq lines t) (> lines 0)) files)
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (if (and (string-match
+ (concat "^" riece-log-file-name-regexp)
+ (setq name (file-name-nondirectory (car files))))
+ (match-beginning 2))
+ (progn
+ (setq coding-system
+ (intern (substring name (match-beginning 2))))
+ (if (featurep 'xemacs)
+ (setq coding-system (find-coding-system coding-system))
+ (unless (coding-system-p coding-system)
+ (setq coding-system nil)))
+ (if coding-system
+ (let ((coding-system-for-read coding-system))
+ (insert-file-contents (car files)))
+ ;;don't insert file contents if they use non
+ ;;supported coding-system.
+ ))
+ ;;if the filename has no coding-system suffix, decode with
+ ;;riece-log-coding-system.
+ (let ((coding-system-for-read riece-log-coding-system))
+ (insert-file-contents (car files))))
+ ;;lines in the file contents are in reversed order.
+ (unless (eq lines t)
+ (goto-char (point-max))
+ (setq lines (- (forward-line (- lines))))
+ (delete-region (point-min) (point)))
+ ;;add (YYYY/MM/dd) suffix on each line left in the current buffer.
+ (unless (equal (substring name 0 8) (format-time-string "%Y%m%d"))
+ (setq date (concat " (" (substring name 0 4) "/"
+ (substring name 4 6) "/"
+ (substring name 6 8) ")"))
+ (while (not (eobp))
+ (end-of-line)
+ (setq point (point))
+ (insert date)
+ (put-text-property point (point)
+ 'riece-overlay-face 'riece-log-date-face)
+ (forward-line))
+ (goto-char (point-min))))
+ (setq files (cdr files)))))