(concat (format-time-string "%Y%m%d") ".log")
(riece-log-get-directory identity)))
+(defun riece-log-get-files (identity)
+ (let ((files (directory-files (riece-log-get-directory identity) t
+ (concat "^"
+ (riece-make-interval-regexp "[0-9]" 8)
+ "\\.log$")
+ t)))
+ (nreverse (sort files #'string-lessp))))
+
(defun riece-log-get-directory (identity)
(let ((channel (riece-identity-canonicalize-prefix
(riece-identity-prefix identity)))
(expand-file-name name (expand-file-name server riece-log-directory))
(expand-file-name name riece-log-directory))))
+(defun riece-log-flashback-1 (identity)
+ (if (eq riece-log-flashback t)
+ (let ((file (riece-log-get-file identity)))
+ (if (file-exists-p file)
+ (insert-file-contents file)))
+ (let ((files (riece-log-get-files identity))
+ (lines (- riece-log-flashback))
+ date point)
+ (while (and (< lines 0) files)
+ (if (and (file-exists-p (car files))
+ (string-match (concat "\\("
+ (riece-make-interval-regexp "[0-9]" 4)
+ "\\)\\("
+ (riece-make-interval-regexp "[0-9]" 2)
+ "\\)\\("
+ (riece-make-interval-regexp "[0-9]" 2)
+ "\\).log$")
+ (car files)))
+ (save-restriction
+ (narrow-to-region (point-min) (point-min))
+ (setq date (concat " (" (match-string 1 (car files)) "/"
+ (match-string 2 (car files)) "/"
+ (match-string 3 (car files)) ")"))
+ (insert-file-contents (car files))
+ (goto-char (point-max))
+ (setq lines (forward-line lines)
+ point (point))
+ (while (not (eobp))
+ (end-of-line)
+ (insert date)
+ (forward-line))
+ (goto-char point)))
+ (setq files (cdr files)))
+ (if (zerop lines)
+ (delete-region (point-min) (point))))))
+
(defun riece-log-flashback (identity)
(when riece-log-flashback
- (let ((file (riece-log-get-file identity)))
- (when (file-exists-p file)
- (let (string)
- (with-temp-buffer
- (insert-file-contents file)
- (if (not (integerp riece-log-flashback))
- (goto-char (point-min))
- (goto-char (point-max))
- (forward-line (- riece-log-flashback)))
- (setq string (buffer-substring (point) (point-max))))
- (let (buffer-read-only)
- (goto-char (point-max))
- (insert string)
- (goto-char (point-min))
- (while (re-search-forward
- "^[0-9][0-9]:[0-9][0-9] [<>]\\([^<>]+\\)[<>] " nil t)
- (put-text-property (match-beginning 1) (match-end 1)
- 'riece-identity
- (riece-make-identity
- (riece-match-string-no-properties 1)
- (riece-identity-server identity))))
- (when (and (memq 'riece-button riece-addons)
- riece-button-enabled)
- (riece-button-update-buffer))
- (goto-char (point-max))
- (set-window-point (get-buffer-window (current-buffer))
- (point))))))))
+ (let (buffer-read-only
+ (point (goto-char (point-max))))
+ (insert (with-temp-buffer
+ (riece-log-flashback-1 identity)
+ (buffer-string)))
+ (goto-char point)
+ (while (re-search-forward
+ "^[0-9][0-9]:[0-9][0-9] [<>]\\([^<>]+\\)[<>] " nil t)
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'riece-identity
+ (riece-make-identity
+ (riece-match-string-no-properties 1)
+ (riece-identity-server identity))))
+ (when (and (memq 'riece-button riece-addons)
+ riece-button-enabled)
+ (riece-button-update-buffer))
+ (goto-char (point-max))
+ (set-window-point (get-buffer-window (current-buffer))
+ (point)))))
(defun riece-log-open-directory (&optional channel)
(interactive)
--- /dev/null
+(require 'riece-log)
+
+(luna-define-class test-riece-log (lunit-test-case))
+
+(defun test-riece-log-delete-directory (directory)
+ (let ((files (directory-files directory t nil t)))
+ (while files
+ (if (file-directory-p (car files))
+ (unless (member (file-name-nondirectory (car files)) '("." ".."))
+ (test-riece-log-delete-directory (car files)))
+ (delete-file (car files)))
+ (setq files (cdr files)))
+ (delete-directory directory)))
+
+(luna-define-method test-riece-log-flashback ((case test-riece-log))
+ (let ((riece-log-directory
+ (expand-file-name (make-temp-name "test-riece-log")
+ (if (featurep 'xemacs)
+ (temp-directory)
+ temporary-file-directory)))
+ riece-addons)
+ (unwind-protect
+ (let ((dir (expand-file-name "riece" riece-log-directory))
+ (riece-log-flashback 2)
+ riece-log-directory-map)
+ (make-directory riece-log-directory)
+ (make-directory dir)
+ (write-region "03:14 <test> a b c\n" nil
+ (expand-file-name "20380119.log" dir) t 0)
+ (write-region "03:14 <test> 1 2 3\n" nil
+ (expand-file-name "20380118.log" dir) t 0)
+ (lunit-assert-2
+ case
+ (equal
+ "03:14 <test> 1 2 3 (2038/01/18)\n03:14 <test> a b c (2038/01/19)\n"
+ (with-temp-buffer
+ (riece-log-flashback (riece-make-identity "#riece" ""))
+ (buffer-string)))))
+ (test-riece-log-delete-directory riece-log-directory))))
+