Watchdbg, grepdbg args change, fix pc92c for rbn
authorDirk Koopman <djk@tobit.co.uk>
Mon, 7 Sep 2020 22:02:06 +0000 (23:02 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Mon, 7 Sep 2020 22:02:06 +0000 (23:02 +0100)
As Changes says:
1, Change interface to watchdbg & grepdbg slightly so that multiple search
   regexes are ANDed rather than ORed together. ORing is easily achieved
   already by the usual regex pattern 'PATT..|PATT..|..' whereas ANDing could
   not be done as easily without resorting lots of 'PATT.*PATH' things which
   would not necessarily get what was wanted.
2. Make sure that the pc92 C record only contains nodes and users and not
   other extranoeus things like skimmers...

Changes
perl/DXProt.pm
perl/Route.pm
perl/grepdbg
perl/watchdbg

diff --git a/Changes b/Changes
index 25d70ce6b598d64c3bb8c9162389d81a4f380ff5..9e81881b0bce6315156441ec7fa2e4c23ad02c03 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,11 @@
+07Sep20=======================================================================
+1, Change interface to watchdbg & grepdbg slightly so that multiple search
+   regexes are ANDed rather than ORed together. ORing is easily achieved 
+   already by the usual regex pattern 'PATT..|PATT..|..' whereas ANDing could
+   not be done as easily without resorting lots of 'PATT.*PATH' things which
+   would not necessarily get what was wanted.
+2. Make sure that the pc92 C record only contains nodes and users and not
+   other extranoeus things like skimmers...
 15Aug20=======================================================================
 1. Simplify the skimmer scoring mechanism.
 13Aug20=======================================================================
index b5606eff609d9d61896f2b8558a1bb0444efef91..6cc0eea4bdb9241e6bb9090ed515b64ef9c27c30 100644 (file)
@@ -928,7 +928,7 @@ sub gen_my_pc92_config
                clear_pc92_changes();           # remove any slugged data, we are generating it as now
                my @dxchan = grep { $_->call ne $main::mycall && !$_->{isolate} } DXChannel::get_all();
                dbg("ROUTE: all dxchan: " . join(',', map{$_->{call}} @dxchan)) if isdbg('routelow');
-               my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
+               my @localnodes = map { my $r = Route::get($_->{call});($_->is_node || $_->is_user) && $r ? $r : () } @dxchan;
                dbg("ROUTE: localnodes: " . join(',', map{$_->{call}} @localnodes)) if isdbg('routelow');
                return pc92c($node, @localnodes);
        } else {
index 3f264846bd74ff4210b9276e7c6ce7e4e542ab44..304b9c6830b97f77bde4767cc64ad954c2a310e1 100644 (file)
@@ -224,12 +224,14 @@ sub config
                                        my $c;
                                        if ($uref) {
                                                $c = $uref->user_call;
-                                       } else {
+                                       }
+                                       else {
                                                $c = "$ucall?";
                                        }
                                        if ((length $line) + (length $c) + 1 < $width) {
                                                $line .= $c . ' ';
-                                       } else {
+                                       }
+                                       else {
                                                $line =~ s/\s+$//;
                                                push @out, $line;
                                                $line = ' ' x ($level*2) . "$pcall->$c ";
@@ -240,7 +242,8 @@ sub config
                $line =~ s/->$//g;
                $line =~ s/\s+$//;
                push @out, $line if length $line;
-       } else {
+       }
+       else {
                # recursion detector
                if ((DXChannel::get($call) && $level > 1) || $seen->{$call} || $level > $maxlevel) {
                        return @out;
index 80a918a07cc7a0a6a998d15240dd26746711bd75..06f7df635d630e44944a7154cc6243e2038e4823 100755 (executable)
@@ -12,7 +12,9 @@
 # ten lines including the line matching the regular expression. 
 #
 # <regexp> is the regular expression you are searching for, 
-# a caseless search is done
+# a caseless search is done. There can be more than one <regexp>
+# a <regexp> preceeded by a '!' is treated as NOT <regexp>. Each
+# <regexp> is implcitly ANDed together. 
 #
 # If you specify something that likes a filename and that filename
 # has a .pm on the end of it and it exists then rather than doing
@@ -47,8 +49,9 @@ $fp = DXLog::new('debug', 'dat', 'd');
 $today = $fp->unixtoj(time()); 
 my $nolines = 1;
 my @prev;
+my @patt;
 
-for my $arg (@ARGV) {
+foreach my $arg (@ARGV) {
        if ($arg =~ /^-/) {
                $arg =~ s/^-//o;
                if ($arg =~ /^\s*\-+(?:[h\?]e?l?p?)/) {
@@ -68,12 +71,11 @@ for my $arg (@ARGV) {
                        die "$arg not found";
                }
        } else {
-               $string = $arg;
-               last;
+               push @patt, $arg;
        }
 }
 
-$string ||= '.*';
+push @patt, '.*' unless @patt;
 
 push @list, "0" unless @list;
 for my $entry (@list) {
@@ -104,7 +106,17 @@ sub process
        chomp $line;
        push @prev, $line;
        shift @prev while @prev > $nolines;
-       if ($line =~ m{$string}io) {
+       my $flag = 0;
+       foreach my $p (@patt) {
+               if ($p =~ /^!/) {
+                       my $r = substr $p, 1;
+                       last if $line =~ m{$r}i;
+               } else {
+                       last unless $line =~ m{$p}i;
+               }
+               ++$flag;
+       }               
+       if ($flag == @patt) {
                for (@prev) {
                        s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg; 
                        my ($t, $l) =  split /\^/, $_, 2;
@@ -117,6 +129,6 @@ sub process
        
 sub usage
 {
-       die "usage: grepdbg [nn days before] [-nnn lines before] [<regexp>|<perl file name>]\n";
+       die "usage: grepdbg [nn days before] [-nnn lines before] [<perl file name>] [<regexp>|!<regexp>]...\n";
 }
 exit(0);
index 8d9551d3db9e1cb366defc6186484a19a741964c..a497eff92957f5bb269c7c1ce062f08c9acb83cd 100755 (executable)
@@ -3,6 +3,10 @@
 # watch the end of the current debug file (like tail -f) applying
 # any regexes supplied on the command line.
 #
+# There can be more than one <regexp>. a <regexp> preceeded by a '!' is
+# treated as NOT <regexp>. Each <regexp> is implcitly ANDed together.
+# All <regexp> are caseless.
+#
 # examples:-
 # 
 #   watchdbg g1tlh       # watch everything g1tlh does
@@ -35,7 +39,7 @@ my $fh = $fp->open($today) or die $!;
 my $nolines = 1;
 $nolines = shift if $ARGV[0] =~ /^-?\d+$/;
 $nolines = abs $nolines if $nolines < 0;  
-my $exp = join '|', @ARGV;
+my @patt = @ARGV;
 my @prev;
 
 # seek to end of file
@@ -43,10 +47,20 @@ $fh->seek(0, 2);
 for (;;) {
        my $line = $fh->getline;
        if ($line) {
-               if ($exp) {
+               if (@patt) {
                        push @prev, $line;
                        shift @prev while @prev > $nolines; 
-                       if ($line =~ m{(?:$exp)}oi) {
+                       my $flag = 0;
+                       foreach my $p (@patt) {
+                               if ($p =~ /^!/) {
+                                       my $r = substr $p, 1;
+                                       last if $line =~ m{$r}i;
+                               } else {
+                                       last unless $line =~ m{$p}i;
+                               }
+                               ++$flag;
+                       }               
+                       if ($flag == @patt) {
                                printit(@prev); 
                                @prev = ();
                        }
@@ -80,7 +94,7 @@ sub printit
                $line =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg; 
                my ($t, $l) =  split /\^/, $line, 2;
                $t = time unless defined $t;
-               printf "%02d:%02d:%02d %s\n", (gmtime($t))[2,1,0], $l; 
+               printf "%02d:%02d:%02d %s\n", (gmtime($t))[2,1,0], $l;
        }
 }
 exit(0);