-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookup
More file actions
executable file
·39 lines (33 loc) · 893 Bytes
/
lookup
File metadata and controls
executable file
·39 lines (33 loc) · 893 Bytes
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
#!/usr/bin/perl
# Usage: lookup <string>
#
# Print all bibtex entries containing <string>.
#
# -k : match only the cite key.
# -u : print just the first matching entry, not all.
#
# SRE, Tue Mar 11 14:01:47 1997
use Getopt::Std;
use Env;
&getopts("uk");
if ($opt_k) { $do_citekey = 1;}
if ($opt_u) { $do_justone = 1;}
$search = shift;
@bibpaths = split(':',$BIBINPUTS);
$/ = "";
foreach $bibpath (@bibpaths) {
if ($bibpath eq "") { $bibpath = "."; }
opendir(BIBDIR,$bibpath) || die "couldn't open $bibpath";
@bibfiles = grep(/\.bib$/, readdir(BIBDIR));
closedir(BIBDIR);
foreach $bibfile (@bibfiles) {
open(BIBFILE, "$bibpath/$bibfile") || die "couldn't open $bibpath/$bibfile: $!\n";
while (<BIBFILE>) {
if (($do_citekey && /@\S+\s*\{$search,/) || (!$do_citekey && /$search/)) {
print;
if ($do_justone) { exit; }
}
}
close(BIBFILE);
}
}