Skip to content

Commit

Permalink
Handle paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Nov 14, 2016
1 parent eb29155 commit 66e3053
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions bibget.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/perl
#
# Extract used the bibliography elements into a single file
# See http://github.com/DSpinellis/bibget
#
# Copyright 2005-2016 Diomidis Spinellis
#
Expand All @@ -21,7 +22,7 @@ sub getcitation {
my($fname) = @_;
my($IN);
open ($IN, $fname) || die;
print STDERR "Reading $fname\n";
print STDERR "Processing $fname\n";
while(<$IN>) {
if (/\\citation\{([^\}]+)\}/) {
@cites = split(/\,/, $1);
Expand All @@ -31,28 +32,49 @@ sub getcitation {
print STDERR "Found citation $1\n";
} elsif (/\\bibdata\{([^}]+)\}/) {
@refs = split(/,/, $1);
print STDERR "Read refs from ", join(' ', @refs), "\n";
print STDERR "References in ", join(' ', @refs), "\n";
} elsif (/\\\@input\{([^}]+)\}/) {
getcitation($1);
}
}
}

getcitation($ARGV[0]);
for my $aux (@ARGV) {
getcitation($aux);
}

# Heuristic for path separation character
my $bibinputs = $ENV{'BIBINPUTS'} || '.';
my $sepchar = ($bibinputs =~ m/\;/) ? ';' : ':';

while ($f = shift @refs) {
open(IN, "/dds/bib/$f.bib") || die "Unable to open /dds/bib/$f.bib: $!\n";
# Open fiel in BIBINPUTS path
my $in;
my $found;
for my $dir (split($sepchar, $bibinputs)) {
if (open($in, "$dir/$f.bib")) {
print STDERR "Reading references from $dir/$f.bib\n";
$found = 1;
last;
}
}
if (!$found) {
print STDERR "Unable to open $f: $!\n";
exit 1;
}

check: for (;;) {
print if (/\@string.*\".*\"/i);
# Output a matched reference
if (m/^\s*\@\w+\s*[({]\s*([^,]+)/ && $used{$1}) {
print $_;
$used{$1} = 2;
while (<IN>) {
while (<$in>) {
next check if (/^\s*\@/);
print $_;
}
}
last unless ($_ = <IN>);
last unless ($_ = <$in>);
}
}

Expand Down

0 comments on commit 66e3053

Please sign in to comment.