3 # Program to do a grep with dates and times on the debug
6 # grepdbg [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
17 # If you specify something that likes a filename and that filename
18 # has a .pm on the end of it and it exists then rather than doing
19 # the regex match it executes the "main::handle()" function passing
20 # it one line at a time.
26 # search local then perl directories
28 # root of directory tree for this system
30 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
32 unshift @INC, "$root/perl"; # this IS the right way round!
33 unshift @INC, "$root/local";
43 use vars qw(@list $fp $today $string);
46 $fp = DXLog::new('debug', 'dat', 'd');
47 $today = $fp->unixtoj(time());
54 if ($arg =~ /^\s*\-+(?:[h\?]e?l?p?)/) {
59 } elsif ($arg =~ /^\d+$/) {
61 } elsif ($arg =~ /\.pm$/) {
66 die "requiring $fn failed $@" if $@;
78 push @list, "0" unless @list;
79 for my $entry (@list) {
80 my $now = $today->sub($entry);
81 my $fh = $fp->open($now);
85 if (main->can('handle')) {
91 begin() if main->can('begin');
98 end() if main->can('end');
106 shift @prev while @prev > $nolines;
107 if ($line =~ m{$string}io) {
109 s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
110 my ($t, $l) = split /\^/, $_, 2;
111 print atime($t), ' ', $l, "\n";
112 print '----------------' if $nolines > 1;
120 die "usage: grepdbg [nn days before] [-nnn lines before] [<regexp>|<perl file name>]\n";