http://www.perlmonks.org?node_id=524441


in reply to Gtk2 Visual Grep

Hi,
great, thanks zentara++ !
Added it to my standard tools!
Regards,
svenXY

Replies are listed 'Best First'.
Re^2: Gtk2 Visual Grep
by zentara (Archbishop) on Jan 20, 2006 at 17:40 UTC
    Hi, I fixed a small bug which locks up the search when entering empty search strings; plus removed some useless subs. Please download again.

    I'm not really a human, but I play one on earth. flash japh
      Hi,
      thanks again. The following patch adds capability of searching with regexes (I get some utf8 errors, but it works. Do you happen to know how to fix them?):
      18c18 < my ($recurse, $name, $case,$linenums,$quick_start) =(0,0,0,0,0); --- > my ($recurse, $name, $case,$linenums,$quick_start, $use_regex) =(0,0 +,0,0,0); 21a22 > if( grep{/\bR\b/} @ARGV ){@ARGV = grep { $_ ne 'R' } @ARGV; $use_reg +ex = 1 }; 64a66 > my $vboxC3 = Gtk2::VBox->new(); 83a86,91 > my $checkbutton5 = Gtk2::CheckButton->new('Use RegEx'); > $checkbutton5->signal_connect( clicked => > sub{check_button_callback($checkbutton5, \$use_regex , +'use_regex')}); > $vboxC2->pack_start( $checkbutton5, 0, 0, 0 ); > > if($case){$checkbutton5->set_active(1);} 87c95 < $vboxC2->pack_start( $checkbutton4, 0, 0, 0 ); --- > $vboxC3->pack_start( $checkbutton4, 0, 0, 0 ); 91a100 > $hboxt->pack_start( $vboxC3, 0, 0, 0 ); 284,285c293,307 < if ($case){$regex = qr/\Q$search_str\E/} < else{$regex = qr/\Q$search_str\E/i} --- > if ($case){ > if ($use_regex) { > $regex = qr/$search_str/; > } > else { > $regex = qr/\Q$search_str\E/} > } > else { > if ($use_regex) { > $regex = qr/$search_str/i; > } > else { > $regex = qr/\Q$search_str\E/i; > } > }

      Regards,
      svenXY
        I "think" I found the answer to the "malformed utf8 errors". It probably only works for those using latin1 encoding. Possibly, it can be adjusted to use whatever encoding you use? Anyways, change the line which opens the file from
        open (FH,"<", $_); # to open (FH,"<:encoding(latin1)", $_);
        Anyways, it works for me in stopping the errors. I can't say how the regex search works in all it's complexity, for instance a really complex regex may need some special handling, but so far, so good. :-)

        Here is a complete patched snippet. I added another feature to skip search directories that begin with the number 1. (The code is commented out, but you may activate it). I store alot of html files for my categories, in 1DOCS, and I prefer not to delve into them on recursive searches. Modify to fit your needs.

        New script:


        I'm not really a human, but I play one on earth. flash japh
        Hi, I believe I found a bug in your patch , which may be causing your problem. Your line
        > if($case){$checkbutton5->set_active(1);}
        probably should be
        > if($use_regex){$checkbutton5->set_active(1);}
        That would screw up the if-else clause, by cross-linking $case and $use_regex; but I'm still testing it. :-)

        I'm not really a human, but I play one on earth. flash japh
        My first guess would be to put "use utf8" at the top of the script. But you might want to post a new toplevel question for this? I will test it today and see what I can figure out.

        I'm not really a human, but I play one on earth. flash japh