--Multipart_Mon_Feb_16_17:43:14_1998-1
Content-Type: text/plain; charset=ISO-2022-JP

Á°ÅĤǤ¹¡£

In message "[ruby-list:6431] Re: rgrep (Re: call for scripts)"
Shugo Maeda <shugo / po.aianet.ne.jp> wrote:

|grep¤ò¸Æ¤Ð¤Ê¤¤¤è¤¦¤Ëµ¤·¤Æ¤ß¤Þ¤¹¡¨Â

µ¤·¤Þ¤·¤¿¡¨Â
ôùðå¤ò»È¤Ã¤Æ¤¤¤ë¤Î¤Ç1.1¤Ç¤Ê¤¤¤Èư¤­¤Þ¤»¤ó¤¬¡¢1.0¤Ç¤âư¤«¤Ê¤¤¤È
¤Þ¤º¤¤¤Ç¤·¤ç¤¦¤«¡£

|# ¥ª¥×¥·¥ç¥ó¤Ê¤É¤ÏÂçÉý¤Ë¸º¤Ã¤Æ¤·¤Þ¤¤¤Ç¤¹¤¬(^^;

·ë¶Éhinqs¤Î5¤Ä¤À¤±¤Ë¤Ê¤ê¤Þ¤·¤¿¡£


--Multipart_Mon_Feb_16_17:43:14_1998-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="rgrep.rb"
Content-Transfer-Encoding: 7bit

#!/usr/local/bin/ruby

require "getopts"

$pattern  il
$filename  il
$exit_status  

ERROR_MSG_TABLE  
  Errno::ENOENT "No such file or directory",
  Errno::EACCES "Permission denied"
}

def handle_file
  begin
    yield
  rescue Errno::ENOENT, Errno::EACCES
    unless $OPT_s
      errmsg  RROR_MSG_TABLE[$!.type]
      $!.scan(/#{errmsg} - (.*)$/) do |filename|
	$stderr.puts("rgrep: #{filename}: #{errmsg}")
      end
    end
  end
end

def scan_files(path)
  if FileTest.directory?(path)
    if path[-1] ! /
      path  ath + "/"
    end
    handle_file do
      Dir.foreach(path) do |file|
	if file ! ." and file ! .."
	  # pass_block(:scan_files, path + file)
	  scan_files(path + file) do |file|
	    yield(file)
	  end
	end
      end
    end
  else
    yield(path)
  end
end

def print_usage
  $stderr.puts("usage: rgrep [-[hinqs]] <expr> [<files...>]")
end

def grep(file)
  while file.gets
    if $_ $pattern
      $exit_status  
      unless $OPT_q
	print($filename, ":") unless $OPT_h
	print($., ":") if $OPT_n
	print
      end
    end
  end
end

trap("INT") do
  exit(1)
end

unless getopts("hinqs")
  $stderr.puts("rgrep: illegal option")
  print_usage
  exit(2)
end

if ARGV.empty?
  print_usage
  exit(2)
else
  $pattern  egexp.new(ARGV.shift, $OPT_i)
end

unless $OPT_h
  $OPT_h  RGV.empty? ||
    (ARGV.size 1 && !FileTest.directory?(ARGV[0]))
end

for path in ARGV
  scan_files(path) do |file|
    $filename  ile
    handle_file do
      f  pen(file)
      begin
	grep(f)
      ensure
	f.close
      end
    end
  end
end
grep($stdin) if ARGV.empty?

exit($exit_status)

--Multipart_Mon_Feb_16_17:43:14_1998-1
Content-Type: text/plain; charset=ISO-2022-JP


-- 
Á°ÅÄ ¨Â

­­ÍõìôéðáòôßÍïî߯åâß±¶ß±·º´³º±´ß±¹¹¸­±­­