File: nmzgrep.in

package info (click to toggle)
namazu2 2.0.21-22
  • links: PTS
  • area: main
  • in suites: buster
  • size: 7,032 kB
  • sloc: ansic: 14,161; perl: 10,789; sh: 9,355; lisp: 1,147; makefile: 914
file content (62 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! %PERL% -w
# -*- Perl -*-
#
# nmzgrep - search namazu-indexed documents for a given pattern and 
#           print lines matching the pattern.
# 
# $Id: nmzgrep.in,v 1.1.8.2 2004-09-19 03:37:44 opengl2772 Exp $
#
# 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
#

use strict;
use FileHandle;

if (@ARGV == 0) {
    print "usage: nmzgrep [egrep's options] <pattern> [index]...\n";
    exit 1;
}

my @opts = ();
while (defined $ARGV[0] && $ARGV[0] =~ /^-/) {
    push @opts, $ARGV[0];
    shift @ARGV;
}

if (@ARGV == 0) {
    print "usage: nmzgrep [egrep's options] <pattern> [index]...\n";
    exit 1;
}

my $pattern = shift @ARGV;
my @indices = @ARGV;
my $command = "namazu -alR $pattern @indices |\
               xargs egrep @opts $pattern /dev/null";

my $fh = new FileHandle;
$fh->open("$command |");
if (defined $fh) {
    while (<$fh>) {
	print;
    }
} else {
    die "nmzgrep: $!";
}

exit 0;