Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Egrep clone with function name display

by ambrus (Abbot)
on Feb 02, 2005 at 21:05 UTC ( #427433=note: print w/ replies, xml ) Need Help??


in reply to cgrep: Egrep clone with function name display

This is a unified diff from the originally posted code to the current code.

--- cgrep.7 2005-02-02 14:36:46.000000000 +0100 +++ cgrep 2005-02-02 22:48:22.000000000 +0100 @@ -148,8 +148,8 @@ my($cregexp, @filenames, $complement, $found_any, $match, $endfile, $print_filename, $print_lineno, $before_context, $after_context, - $context, $hush_messages, $print_func, $func_cregexp); -my($file, $filename); + $context, $hush_messages, $print_func, $func_cregexp, + $file, $filename, $anyoutput, $lastoutput); sub main { @@ -175,8 +175,8 @@ sub process_file { - my($line, $func, $m, @before, $b, $after, $delimit); - ($after, $delimit, $func) = (0, 0, undef); + my($line, $func, $m, @before, $b, $after); + ($after, $func, $lastoutput) = (0, undef, -1); READ: { while (defined($line = <$file>)) { chomp $line; @@ -187,10 +187,6 @@ if ($m xor $complement) { $found_any = 1; $context and do { - 2 <= $delimit and do { - print_chunk_delimiter(); - $delimit = 0; - }; for $b (@before) { &$match(@$b[0, 1, 2]), 0 } @before = (); @@ -202,9 +198,7 @@ if (0 < $after) { &$match($line, input_line_number $file, $func, 0) +; $after--; - $delimit = 1; } else { - $delimit and $delimit = 2; push @before, [$line, input_line_number $file, $f +unc]; $before_context < @before and shift @before; } @@ -224,6 +218,12 @@ sub print_match { my($line, $lineno, $func, $m) = @_; + $context and do { + $lastoutput != $lineno - 1 && $anyoutput and + print "--\n"; + $anyoutput = 1; + $lastoutput = $lineno; + }; $print_filename and print $filename, $m ? ":" : "-"; $print_func and defined($func) and print $func, $m ? ":" : "-"; $print_lineno and print $lineno, $m ? ":" : "-"; @@ -231,10 +231,6 @@ } -sub print_chunk_delimiter { - print "--\n"; -} - sub print_name_exit { $_[3] or return; print $filename, "\n"; @@ -273,7 +269,7 @@ "line-number|n!", sub { $print_lineno = $_[1]; }, "context|C=n", sub { $after_context = $before_context = $_[1] + }, "after-context|A=n", sub { $after_context = $_[1] }, - "before-context|B=n", sub { $after_context = $_[1] }, + "before-context|B=n", sub { $before_context = $_[1] }, "files-with-match|list|l!", sub { $mode = $_[1] ? "l" : "" }, "file-without-match|missing|L!", sub { $mode = $_[1] ? "L" : +"" }, "quiet|silent|q", sub { $mode = $_[1] ? "q" : "" },


Comment on Re: Egrep clone with function name display
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://427433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-08-22 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls