#!/usr/local/bin/ruby -Ks # # Copyright (C) Koji Nakamaru # # Author: Koji Nakamaru (nakamaru at gmail.com) # Modified: Apr 30 2005 # * changed the contact information. # Modified: Nov 4 2002 # * added '-r'. # * regexp is now compiled only once. # * STDOUT.sync = true # Modified: Jul 27 2002 # * fixed the incorrect logic of search(). # Created: Jul 26 2002 # Keywords: grep, multiline, two lines # # 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 version 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 GNU Emacs; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # require 'jcode' require 'nkf' OPTIONS = { 'i' => false, 'n' => false, 'e' => false, 'r' => false, } progname = $0.gsub(/.*[\/\\]/, "") USAGE = <= 2 or OPTIONS['n'] or OPTIONS['r']) ? i : nil, fi, regexp, STDOUT) end elsif (FileTest.directory?(i) and OPTIONS['r']) searchEntries(Dir.glob(i + '/*'), regexp) end end end begin regexp = Regexp.compile(ARGV.shift, OPTIONS['i']) STDOUT.sync = true if (ARGV.length() > 0) searchEntries(ARGV, regexp) else search(nil, STDIN, regexp, STDOUT) end rescue Interrupt exit((isfound) ? 0 : 1) end exit((isfound) ? 0 : 1)