From: Miek Gieben Date: Fri, 10 Mar 2006 11:50:38 +0000 (+0000) Subject: finally a grep that works. Next -v and then we're ready X-Git-Tag: release-1.1.0~302 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cdea36f78b6b78eb3dcd2e4641505a2312dae0d;p=thirdparty%2Fldns.git finally a grep that works. Next -v and then we're ready --- diff --git a/pcat/pcat-diff.c b/pcat/pcat-diff.c index b65183a1..e7e534aa 100644 --- a/pcat/pcat-diff.c +++ b/pcat/pcat-diff.c @@ -27,13 +27,13 @@ usage(FILE *fp) fprintf(fp, "There are no options, is FILE2 is not given, standard input is read\n"); fprintf(fp, "\nOUTPUT FORMAT:\n"); fprintf(fp, " Line based output format, each record consists of 4 lines:\n"); - fprintf(fp, " 1. xxx\t\tdecimal sequence number\n"); + fprintf(fp, " 1. xxx:yyy\t\tdecimal sequence numbers\n"); fprintf(fp, " 2. hex dump\t\tquery in hex, network order\n"); fprintf(fp, " 3. hex dump\t\tanswer of FILE 1 in hex, network order\n"); fprintf(fp, " 4. hex dump\t\tanswer of FILE 2 in hex, network order\n\n"); fprintf(fp, " If a difference in the query is spotted the sequence nmuber\n"); fprintf(fp, " is prefixed by a 'q: ' and the query data is printed:\n"); - fprintf(fp, " 1. q: xxx\t\tdecimal sequence number\n"); + fprintf(fp, " 1. q: xxx:yyy\tdecimal sequence numbers\n"); fprintf(fp, " 2. hex dump\t\tquery in hex, network order\n"); fprintf(fp, " 3. hex dump\t\tquery of FILE 1 in hex, network order\n"); fprintf(fp, " 4. hex dump\t\tquery of FILE 2 in hex, network order\n"); diff --git a/pcat/pcat-grep.pl b/pcat/pcat-grep.pl index 333d0265..7e5e1d4a 100755 --- a/pcat/pcat-grep.pl +++ b/pcat/pcat-grep.pl @@ -7,10 +7,14 @@ # seperated by comma's # -v reverse -%numbers = (); -$reverse = 0; +use strict; -foreach $r (@ARGV) { +my %numbers = (); +my $reverse = 0; +my $i; +my $k; + +foreach my $r (@ARGV) { if ($r eq "-v") { $reverse = 1; @@ -18,7 +22,7 @@ foreach $r (@ARGV) { } if ($r =~ /-/) { - ($s, $e) = split /-/, $r; + my ($s, $e) = split /-/, $r; if ($s > $e) { next; @@ -33,40 +37,25 @@ foreach $r (@ARGV) { } # read in the input, pcat style +my $line; my $left; my $right; $i = 1; -LINE: while() { +my $print = 0; +while() { if ($i % 4 == 1) { ($left, $right) = split /:/, $_; - - if ($reverse == 0) { - foreach $k (keys %numbers) { - if ($k == $left) { - print $_; - print ; - print ; - print ; - $i++; - next LINE; - } + foreach $k (keys %numbers) { + if ($k == $left) { + $print = 1; + last; } - ; - ; - ; - } else { - foreach $k (keys %numbers) { - if ($k == $left) { - ; - ; - ; - $i++; - next LINE; - } - } - print $_; - print ; - print ; - print ; + $print = 0; } + } + if ($print == 1) { + print $_; + } + if ($i % 4 == 0) { + $print = 0; } $i++; }