forked from vjohansen/emacs-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vj-search-index.pl
47 lines (41 loc) · 1.43 KB
/
vj-search-index.pl
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
# Vagn Johansen 2007 (C)
use DB_File;
use strict;
my $inputSymbol = shift @ARGV;
my $symbol = lc($inputSymbol);
my @filenames = @ARGV or die "Usage: perl $0 symbol db-filename(s)\n";
my $no_matches = 1;
print " Hi"."-lock: ((\":.*\\\\($inputSymbol\\\\)\" (1 (quote 'vj-grep-match) t)))\n";
# ^---- split to avoid problem when viewing this file in Emacs
for my $filename (@filenames)
{
my %database;
tie %database, 'DB_File', $filename,O_RDWR, 0666, $DB_BTREE;
%database or die "$0: tie $filename failed\n\nUse M-x vps-make-index RET\n\n";
$database{$symbol} or do {print "\nSymbol $symbol not in $filename\n"; next;};
$no_matches = 0;
my @ids = split(/-/, $database{$symbol});
@ids = splice(@ids, 1); # skip first
my %unique_ids;
@unique_ids{@ids} = (1) x @ids;
my %filenames_by_dir;
for (map { $database{"-$_"} } keys %unique_ids) {
m!^(.*)/([^/]*)$!;
push @{$filenames_by_dir{$1}}, $2;
}
for my $dir (keys %filenames_by_dir) {
my $filenames= join(" ",@{$filenames_by_dir{$dir}});
print "\nEntering directory `$dir'\n";
chdir $dir or warn "chdir $dir failed: $!";
my $output = `grep -niH \"\\b$symbol\\b\" $filenames`;
print $output;
if ($output eq "") {
print "$dir:0: Stale index: $filenames\ngrep *\n";
my $output = `grep -niH \"\\b$symbol\\b\" *`;
print $output;
}
print "Leaving directory `$dir'\n";
}
untie %database;
}
exit $no_matches;