2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
15 use DXDebug qw(dbg isdbg);
21 our $readback = $main::is_win ? 0 : 1;
23 $readback = `which tac`;
26 #undef $readback; # yet another reason not to use the cloud!
31 use vars qw($maxmonths);
35 # print some items from the log backwards in time
37 # This command outputs a list of n lines starting from time t with $pattern tags
41 my $fcb = $DXLog::log;
42 my $from = shift // 0;
44 my $jdate = $fcb->unixtoj(shift);
51 my $tot = $from + $to;
54 $who = uc $who if defined $who;
56 dbg("from: $from to: $to pattern: $pattern hint: $hint") if isdbg('search');
59 $hint = qq{m{\Q$pattern\E}i};
61 $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}};
64 $hint .= ' && ' if $hint;
65 $hint .= q{m{\Q$who\E}i};
67 $hint = "next unless $hint" if $hint;
68 $hint .= "; next unless m{^\\d+\\^$pattern\\^}i" if $pattern;
71 $eval = qq(while (<\$fh>) {
76 last L1 if \@in >= $tot;
79 if (isdbg('search')) {
80 dbg("sh/log hint: $hint");
81 dbg("sh/log eval: $eval");
84 $fcb->close; # close any open files
89 my $fn = $fcb->fn($jdate);
90 $fh = IO::File->new("$readback $fn |");
92 $fh = $fcb->open($jdate);
94 L1: for ($months = 0; $fh && $months < $maxmonths && @in < $tot; $months++) {
99 eval $eval; # do the search on this file
100 return ("Log search error", $@) if $@;
104 my $fn = $fcb->fn($jdate->sub(1));
105 $fh = IO::File->new("$readback $fn |");
107 $fh = $fcb->openprev(); # get the next file
112 my $name = $pattern ? $pattern : "log";
113 my $s = "$who "|| '';
114 return "show/$name: ${s}not found";
117 for (sort {$a cmp $b } @in) {
118 push @out, [ split /\^/ ]
130 push @out, print_item($_);
137 # the standard log printing interpreting routine.
139 # every line that is printed should call this routine to be actually visualised
141 # Don't really know whether this is the correct place to put this stuff, but where
144 # I get a reference to an array of items
149 my $d = atime($r->[0]);
152 if ($r->[1] eq 'rcmd') {
153 $r->[6] ||= 'Unknown';
154 if ($r->[2] eq 'in') {
156 $s = "in: $r->[4] ($r->[6] priv: $r->[3]) rcmd: $r->[5]";
159 $s = "$r->[3] $r->[6] reply: $r->[4]";
161 } elsif ($r->[1] eq 'talk') {
163 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
164 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
166 $r->[4] =~ s/^\#\d+ //;
167 $s = "$r->[3] -> $r->[2] $r->[4]";