root/lang/gauche/irc-logger/trunk/lib/rawlog.scm @ 90

Revision 43, 2.0 kB (checked in by naoya_t, 16 years ago)

irc-logger in Gauche : first import

Line 
1;(require "./setting")
2
3(use srfi-1)
4(use file.util)
5
6(define (daily-log date-str filter-proc)
7  ;; date-str must be in %Y-%m-%d format
8  (define (uncolon s)
9        (cond [(string=? "" s)
10                   ""]
11                  [(eq? #\: (string-ref s 0))
12                   (substring s 1 -1)]
13                  [else s]))
14  (define (unquote s)
15        (cond [(string=? "" s)
16                   ""]
17                  [(eq? #\" (string-ref s 0))
18                   (substring s 1 (- (string-length s) 1))]
19                  [else s]))
20
21  (define (month-abbrev->number s)
22        (case (string->symbol s)
23          [(Jan) 1] [(Feb) 2] [(Mar) 3] [(Apr) 4] [(May) 5] [(Jun) 6]
24          [(Jul) 7] [(Aug) 8] [(Sep) 9] [(Oct) 10] [(Nov) 11] [(Dec) 12]
25          [else #f]))
26
27  (let1 raw-log-path (string-append log-dir "/" date-str ".log")
28        (if (file-exists? raw-log-path)
29                (string-join
30                 (filter identity
31                                 (map (lambda (line)
32                                                (let (;;[month (month-abbrev->number (substring line 0 3))]
33                                                          ;;[day (string->number (substring line 4 6))]
34                                                          [timestamp (substring line 7 15)]
35                                                          [f (string-split (substring line 17 -1) " ")])
36                                                  (if (string=? "[RECEIVED]" (car f))
37                                                          (let ([user (uncolon (regexp-replace #/!.*$/ (second f) ""))]
38                                                                        [cmd (string->symbol (third f))]
39                                                                        [room (uncolon (fourth f))])
40                                                                (case cmd
41                                                                  [(JOIN)
42                                                                   (filter-proc timestamp user cmd room "")]
43                                                                  [(PART)
44                                                                   (filter-proc timestamp user cmd room
45                                                                                                (unquote (uncolon (string-join (cddddr f) " "))))]
46                                                                  [(QUIT)
47                                                                   (filter-proc timestamp user cmd #f
48                                                                                                (unquote (uncolon (string-join (cdddr f) " "))))]
49                                                                  [(PRIVMSG)
50                                                                   (filter-proc timestamp user cmd room (uncolon (string-join (cddddr f) " ")))]
51                                                                  [(NICK)
52                                                                   (filter-proc timestamp user cmd #f (uncolon (string-join (cdddr f) " ")))]
53                                                                  [(TOPIC)
54                                                                 (filter-proc timestamp user cmd #f (uncolon (string-join (cdddr f) " ")))]
55                                                                  [else
56                                                                   (filter-proc timestamp user cmd room (uncolon (string-join (cddddr f) " ")))]
57                                                                  ))
58                                                          #f)))
59                                          (file->string-list raw-log-path))
60                                 ) "")
61                #f)))
Note: See TracBrowser for help on using the browser.