Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Gtk2 Visual Grep

by zentara (Archbishop)
on Jan 20, 2006 at 17:40 UTC ( #524534=note: print w/replies, xml ) Need Help??

in reply to Re: Gtk2 Visual Grep
in thread Gtk2 Visual Grep

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

Replies are listed 'Best First'.
Re^3: Gtk2 Visual Grep
by svenXY (Deacon) on Jan 24, 2006 at 10:42 UTC
    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; > } > }

      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
        Thanks a bunch, ++zentara!

        Last thing I was thinking about (except excluding dirs (for me it would be .svn dirs or so)) would be a start dir parameter. But I can easily do that myself.

      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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://524534]
[LanX]: Yeah I think thats Dutch spelling rule
[erix]: but we don't sneeze any K's
[choroba]: we do
[Eily]: that was a sneeze overpowering a cough
[choroba]: Czechs sneeze "Hep-cheek"
vrk adds gingerbread cookies to the platter on the sideboard.
[erix]: I'll give that a try next time
vrk takes a cookie from the platter on the sideboard.
[Eily]: French sneeze "Atchoum", because we close our mouth when we're done :P
[erix]: Hatshepsut (no sneezing audio there)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2017-04-24 15:46 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.