improve help for grepdbg and watchdbg
authorDirk Koopman <djk@tobit.co.uk>
Thu, 3 Feb 2022 14:55:57 +0000 (14:55 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Thu, 3 Feb 2022 14:55:57 +0000 (14:55 +0000)
Changes
perl/DXChannel.pm
perl/grepdbg
perl/watchdbg

diff --git a/Changes b/Changes
index 0f3234a35e491cac961b0f582bccb22d638d92cb..e2f1c254a282acaa69ee90c7b2d698a070088a5e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+03Feb22=======================================================================
+1. Improve/add the help text for grepdbg and watchdbg. 
 31Jan22=======================================================================
 1. Set $RBN::respottime to 3 minutes. NOTE change of name from 
    $RBN::minspottime.
 31Jan22=======================================================================
 1. Set $RBN::respottime to 3 minutes. NOTE change of name from 
    $RBN::minspottime.
index 29919c7ebcf4eb7df53c97dbe0ebc495d30819cb..8b1792cd148dc0caddb6f5180ef1907d149c7d05 100644 (file)
@@ -719,7 +719,7 @@ sub process_one
                if ($sort ne 'D') {
                        if (isdbg('chan')) {
                                if (($self->is_rbn && isdbg('rbnchan')) || !$self->is_rbn) {
                if ($sort ne 'D') {
                        if (isdbg('chan')) {
                                if (($self->is_rbn && isdbg('rbnchan')) || !$self->is_rbn) {
-                                       dbg("<- $sort $call $line") if isdbg('chan');
+                                       dbg("<- $sort $call $line") if isdbg('chan'); # you may think this is tautology, but it's needed get the correct label on the debug line
                                }
                        }
                }
                                }
                        }
                }
index f61d7cc15ad48954722eb83cd4fac3107e527b5c..8fa76857e7203b18ff7eb7ee97d243645c563a7d 100755 (executable)
@@ -8,8 +8,9 @@
 # nn - is the day you what to look at: 1 is yesterday, 0 is today
 # and is optional if there is only one argument
 #
 # nn - is the day you what to look at: 1 is yesterday, 0 is today
 # and is optional if there is only one argument
 #
-# -mmm - print the mmm lines before the match. So -10 will print
-# ten lines including the line matching the regular expression. 
+# -mmm - print the mmm lines before the match. So -3 will print
+# 4 lines altogether, the 3 lines before the line matching
+# the regular expression. 
 #
 # <regexp> is the regular expression you are searching for, 
 # a caseless search is done. There can be more than one <regexp>
 #
 # <regexp> is the regular expression you are searching for, 
 # a caseless search is done. There can be more than one <regexp>
@@ -60,7 +61,7 @@ foreach my $arg (@ARGV) {
                        usage();
                        exit(0);
                }
                        usage();
                        exit(0);
                }
-               $nolines = $arg if $arg =~ /^\d+$/;
+               $nolines += $arg if $arg =~ /^\d+$/;
        } elsif ($arg =~ /^\d+$/) {
                push @days, $arg;
        } elsif ($arg =~ /\.pm$/) {
        } elsif ($arg =~ /^\d+$/) {
                push @days, $arg;
        } elsif ($arg =~ /\.pm$/) {
@@ -136,7 +137,7 @@ sub usage
 {
        print << "XXX";
 
 {
        print << "XXX";
 
- usage: grepdbg [nn days before] [-nnn lines before] [<perl file name>] [<regexp>|!<regexp>]...
+ usage: grepdbg [nn days before] [-nnn lines before] [<perl filter module>] [<regexp>|!<regexp>]...
 
         You can have more than one <regexp> with an implicit 'and' between them. All 
         <regexes> are caseless. It's recommended to put 'not' (!<regex>) first in any list.
 
         You can have more than one <regexp> with an implicit 'and' between them. All 
         <regexes> are caseless. It's recommended to put 'not' (!<regex>) first in any list.
@@ -150,8 +151,13 @@ sub usage
 
         is a handy way of scrolling through the debug log.
 
 
         is a handy way of scrolling through the debug log.
 
+          grepdbg -2 progress
+
+        will display any line containing 'progress' and also the two lines before that.
+
         You can install your own content and display arrangement (useful for filtering data 
         in some complicated way). You call it like this (assuming it is called 'filter.pm').
         You can install your own content and display arrangement (useful for filtering data 
         in some complicated way). You call it like this (assuming it is called 'filter.pm').
+        This is what is meant by <perl filter module>.
 
         grepdbg filter.pm
 
 
         grepdbg filter.pm
 
@@ -174,8 +180,11 @@ sub usage
         You can also add a 'sub total {...}' which executes after the last line is 
         printed and grepdbg exits.
 
         You can also add a 'sub total {...}' which executes after the last line is 
         printed and grepdbg exits.
 
-        Read the code of this program and copy'n'paste the 'sub process' code and change 
-        its name to 'sub handle'. Modify it to your requirements... 
+        Read the code of this program and copy'n'paste the 'sub
+        process' code into a new file. Then change 'sub process'
+        to 'sub handle'. Add the line 'package main;' at the beginning
+        of the file and a line '1;' at the end and then modify it to
+        your requirements...
 
 XXX
 }
 
 XXX
 }
index a497eff92957f5bb269c7c1ce062f08c9acb83cd..2b1986a738bd4e4236b582ac4d1957ce6d2f4696 100755 (executable)
@@ -37,11 +37,20 @@ my $fp = DXLog::new('debug', 'dat', 'd');
 my $today = $fp->unixtoj(time()); 
 my $fh = $fp->open($today) or die $!; 
 my $nolines = 1;
 my $today = $fp->unixtoj(time()); 
 my $fh = $fp->open($today) or die $!; 
 my $nolines = 1;
-$nolines = shift if $ARGV[0] =~ /^-?\d+$/;
-$nolines = abs $nolines if $nolines < 0;  
-my @patt = @ARGV;
+my @patt;
 my @prev;
 
 my @prev;
 
+while (@ARGV) {
+       my $arg = shift;
+       if ($arg =~ /^-+(\d+)/) {
+               $nolines += $1;
+               next;
+       }
+       usage(), exit(0) if $arg =~ /^-+[h\?]/i;
+       push @patt, $arg;
+}
+
+
 # seek to end of file
 $fh->seek(0, 2);
 for (;;) {
 # seek to end of file
 $fh->seek(0, 2);
 for (;;) {
@@ -98,3 +107,21 @@ sub printit
        }
 }
 exit(0);
        }
 }
 exit(0);
+
+sub usage
+{
+       print << "XXX";
+
+ usage: watchdbg [-nnn lines before] [<regexp>|!<regexp>]...
+
+        You can have more than one <regexp> with an implicit 'and' between them. All 
+        <regexes> are caseless. It's recommended to put 'not' (!<regex>) first in any list.
+        Don't forget that you are doing this in a shell and you may need to quote your
+        <regex>s.
+          watchdbg -2 progress
+
+        will display any line containing 'progress' and also the two lines before that.
+
+XXX
+}