Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
XP is just a number
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2014-04-17 23:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (459 votes), past polls