2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
13 use DXDebug qw(dbg isdbg);
21 use vars qw($VERSION $BRANCH $maxmonths);
22 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
23 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
24 $main::build += $VERSION;
25 $main::branch += $BRANCH;
30 # print some items from the log backwards in time
32 # This command outputs a list of n lines starting from time t with $pattern tags
36 my $fcb = $DXLog::log;
37 my $from = shift || 0;
39 my $jdate = $fcb->unixtoj(shift);
46 my $tot = $from + $to;
50 $hint = "m{\\Q$pattern\\E}i";
52 $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}";
55 $hint .= ' && ' if $hint;
56 $hint .= 'm{\\Q$who\\E}i';
58 $hint = "next unless $hint" if $hint;
59 $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern;
62 $eval = qq(while (<\$fh>) {
68 if (isdbg('search')) {
69 dbg("sh/log hint: $hint");
70 dbg("sh/log eval: $eval");
73 $fcb->close; # close any open files
76 my $fh = $fcb->open($jdate);
77 L1: for ($months = 0; $months < $maxmonths && @in < $tot; $months++) {
79 my $ring = RingBuf->new($tot);
83 eval $eval; # do the search on this file
84 return ("Log search error", $@) if $@;
86 @in = ($ring->readall, @in);
87 last L1 if @in > $tot;
90 $fh = $fcb->openprev(); # get the next file
94 @in = splice @in, -$tot, $tot if @in > $tot;
97 my @line = split /\^/ ;
98 push @out, print_item(\@line);
106 # the standard log printing interpreting routine.
108 # every line that is printed should call this routine to be actually visualised
110 # Don't really know whether this is the correct place to put this stuff, but where
113 # I get a reference to an array of items
118 my $d = atime($r->[0]);
121 if ($r->[1] eq 'rcmd') {
122 if ($r->[2] eq 'in') {
124 $s = "$r->[4] (priv: $r->[3]) rcmd: $r->[5]";
127 $s = "$r->[3] reply: $r->[4]";
129 } elsif ($r->[1] eq 'talk') {
131 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
132 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
134 $r->[4] =~ s/^\#\d+ //;
135 $s = "$r->[3] -> $r->[2] $r->[4]";