# /ruby/bin/ruby # -*- Ruby -*- # # nmzgrep - search namazu-indexed documents for a given pattern and # print lines matching the pattern. # # $Id: nmzgrep.in,v 1.1 1999/12/19 04:19:58 satoru Exp $ # # Copyright (C) 2001 Yasuhisa Kondo All rights reserved. # Original Copyright (C) 1999 Satoru Takabayashi All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either versions 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA # if ARGV.size == 0 then print "usage: nmzgrep [egrep's options] [index]...\n" exit 1 end opts = Array.new while ARGV[0] != nil && ARGV[0] =~ /^-/ opts.push(ARGV.shift) end if ARGV.size == 0 then print "usage: nmzgrep [egrep's options] [index]...\n" exit 1 end pattern = ARGV.shift indices = ARGV $, = ' ' command = "| namazu -alR #{pattern} #{indices.join} |\ xargs egrep #{opts.join} #{pattern} /dev/null" begin fh = open(command).read print fh, "\n" rescue print "nmzgrep: #{$!}" end exit