Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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" : "" },

In reply to Re: Egrep clone with function name display by ambrus
in thread cgrep: Egrep clone with function name display by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found