3 # Program to do a grep with dates and times on the debug
6 # grepwsjtl [nn] [-mm] <regular expression>
8 # nn - is the day you what to look at: 1 is yesterday, 0 is today
9 # and is optional if there is only one argument
11 # -mmm - print the mmm lines before the match. So -10 will print
12 # ten lines including the line matching the regular expression.
14 # <regexp> is the regular expression you are searching for,
15 # a caseless search is done. There can be more than one <regexp>
16 # a <regexp> preceeded by a '!' is treated as NOT <regexp>. Each
17 # <regexp> is implcitly ANDed together.
19 # If you specify something that likes a filename and that filename
20 # has a .pm on the end of it and it exists then rather than doing
21 # the regex match it executes the "main::handle()" function passing
22 # it one line at a time.
28 # search local then perl directories
30 # root of directory tree for this system
32 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
34 unshift @INC, "$root/perl"; # this IS the right way round!
35 unshift @INC, "$root/local";
45 use vars qw(@list $fp $today $string);
48 $fp = DXLog::new('wsjtl', 'dat', 'd');
49 $today = $fp->unixtoj(time());
54 foreach my $arg (@ARGV) {
57 if ($arg =~ /^\s*\-+(?:[h\?]e?l?p?)/) {
62 } elsif ($arg =~ /^\d+$/) {
64 } elsif ($arg =~ /\.pm$/) {
69 die "requiring $fn failed $@" if $@;
78 push @patt, '.*' unless @patt;
80 push @list, "0" unless @list;
81 for my $entry (@list) {
82 my $now = $today->sub($entry);
83 my $fh = $fp->open($now);
87 if (main->can('handle')) {
93 begin() if main->can('begin');
100 end() if main->can('end');
108 shift @prev while @prev > $nolines;
110 foreach my $p (@patt) {
112 my $r = substr $p, 1;
113 last if $line =~ m{$r}i;
115 last unless $line =~ m{$p}i;
119 if ($flag == @patt) {
121 s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
122 my ($t, $l) = split /\^/, $_, 2;
123 print atime($t), ' ', $l, "\n";
124 print '----------------' if $nolines > 1;
132 die "usage: grepwsjtl [nn days before] [-nnn lines before] [<perl file name>] [<regexp>|!<regexp>]...\n";