2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
13 use DXDebug qw(dbg isdbg);
21 use vars qw($VERSION $BRANCH);
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;
28 # print some items from the log backwards in time
30 # This command outputs a list of n lines starting from time t with $pattern tags
34 my $fcb = $DXLog::log;
35 my $from = shift || 0;
37 my $jdate = $fcb->unixtoj(shift);
44 my $tot = $from + $to;
48 $hint = "m{\\Q$pattern\\E}i";
50 $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}";
53 $hint .= ' && ' if $hint;
54 $hint .= 'm{\\Q$who\\E}i';
56 $hint = "next unless $hint" if $hint;
57 $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern;
60 $eval = qq(while (<\$fh>) {
66 if (isdbg('search')) {
67 dbg("sh/log hint: $hint");
68 dbg("sh/log eval: $eval");
71 $fcb->close; # close any open files
73 my $fh = $fcb->open($jdate);
74 L1: for (;@in < $to;) {
76 my $ring = RingBuf->new($tot);
80 eval $eval; # do the search on this file
81 return ("Log search error", $@) if $@;
83 @in = ($ring->readall, @in);
84 last L1 if @in > $tot;
87 $fh = $fcb->openprev(); # get the next file
91 my @line = split /\^/ ;
92 push @out, print_item(\@line);
100 # the standard log printing interpreting routine.
102 # every line that is printed should call this routine to be actually visualised
104 # Don't really know whether this is the correct place to put this stuff, but where
107 # I get a reference to an array of items
112 my $d = atime($r->[0]);
115 if ($r->[1] eq 'rcmd') {
116 if ($r->[2] eq 'in') {
118 $s = "$r->[4] (priv: $r->[3]) rcmd: $r->[5]";
121 $s = "$r->[3] reply: $r->[4]";
123 } elsif ($r->[1] eq 'talk') {
125 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
126 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
128 $r->[4] =~ s/^\#\d+ //;
129 $s = "$r->[3] -> $r->[2] $r->[4]";