On Tuesday 21 June 2005 09:49, Gerald Combs wrote:
Is there a grep-like utility that will return a variable number of context lines? I need to search through source code for occurrences of
The problem statement is modeled by a fairly simple 5 state machine. Here's a very simple Ruby implementation of the state machine. It takes one argument which is the name of the function and searchable input on STDIN for grep-like behavior. It only returns the entire function header lines. Case sensitive, of course.
#!/usr/bin/ruby
more_state = false
while $stdin.gets() if more_state == false and $_.include?( ARGV[0] ) puts $_ more_state = true if ! ( $_.include?("{") or $_.include?(";") ) elsif more_state == true puts $_ more_state = false if ( $_.include?("{") or $_.include?(";") ) end end