2005-06-20 16:25:50 +02:00
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $root = $ENV{"rootFile"};
|
|
|
|
my $out = $ENV{"out"};
|
2007-03-12 18:55:08 +01:00
|
|
|
my $path = $ENV{"searchRelativeTo"};
|
|
|
|
my $store = $ENV{"NIX_STORE"};
|
2005-06-20 16:25:50 +02:00
|
|
|
|
|
|
|
open OUT, ">$out" or die;
|
|
|
|
print OUT "[\n";
|
|
|
|
|
|
|
|
my @workset = ();
|
|
|
|
my %doneset = ();
|
|
|
|
|
2006-11-22 08:06:10 +01:00
|
|
|
sub addToWorkSetExts {
|
|
|
|
my $base = shift;
|
|
|
|
foreach my $ext (@_) {
|
|
|
|
push @workset, "$base$ext";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:25:50 +02:00
|
|
|
push @workset, $root;
|
|
|
|
|
|
|
|
while (scalar @workset > 0) {
|
|
|
|
|
|
|
|
my $fn = pop @workset;
|
|
|
|
next if (defined $doneset{$fn});
|
|
|
|
|
2005-06-20 17:06:58 +02:00
|
|
|
$doneset{$fn} = 1;
|
|
|
|
|
2007-03-29 11:23:47 +02:00
|
|
|
if (!-e "$fn") {
|
|
|
|
print STDERR "cannot access `$fn': $!\n" if !$!{ENOENT};
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2005-09-02 17:50:55 +02:00
|
|
|
next unless -e "$fn";
|
|
|
|
|
2005-06-20 16:25:50 +02:00
|
|
|
|
2005-06-20 17:06:58 +02:00
|
|
|
# Print out the full path *and* its relative path to $root.
|
|
|
|
|
2007-03-12 18:55:08 +01:00
|
|
|
if (substr($fn, 0, length $path) eq $path) {
|
|
|
|
my $relFN = substr($fn, (length $path) + 1);
|
|
|
|
print OUT "$fn \"$relFN\"\n";
|
|
|
|
} else {
|
|
|
|
my $base = basename $fn;
|
|
|
|
my $x = substr($fn, 0, length($store) + 1);
|
|
|
|
if (substr($fn, 0, length($store) + 1) eq "$store/") {
|
|
|
|
$base = substr($base, 33);
|
|
|
|
}
|
|
|
|
print OUT "$fn \"$base\"\n";
|
|
|
|
}
|
2005-06-20 16:25:50 +02:00
|
|
|
|
2005-06-20 17:06:58 +02:00
|
|
|
|
2005-09-02 17:50:55 +02:00
|
|
|
# If this is a TeX file, recursively find include in $fn.
|
|
|
|
next unless $fn =~ /.tex$/ or $fn =~ /.ltx$/;
|
|
|
|
open FILE, "< $fn" or die;
|
|
|
|
|
2005-06-20 16:25:50 +02:00
|
|
|
while (<FILE>) {
|
|
|
|
if (/\\input\{(.*)\}/) {
|
|
|
|
my $fn2 = $1;
|
2005-06-20 17:06:58 +02:00
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2008-01-23 19:11:03 +01:00
|
|
|
push @workset, "$path/$fn2.tex";
|
2006-11-22 08:06:10 +01:00
|
|
|
push @workset, "$path/$fn2";
|
2006-06-14 12:11:21 +02:00
|
|
|
} elsif (/\\usepackage(\[.*\])?\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2006-11-22 08:06:10 +01:00
|
|
|
push @workset, "$path/$fn2.sty";
|
2005-06-20 16:25:50 +02:00
|
|
|
} elsif (/\\documentclass(\[.*\])?\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
2005-06-20 17:06:58 +02:00
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2006-11-22 08:06:10 +01:00
|
|
|
push @workset, "$path/$fn2.cls";
|
2006-07-05 15:39:22 +02:00
|
|
|
} elsif (/\\bibliographystyle\{(.*)\}/) {
|
|
|
|
my $fn2 = $1;
|
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2006-11-22 08:06:10 +01:00
|
|
|
push @workset, "$path/$fn2.bst";
|
2005-06-20 17:20:37 +02:00
|
|
|
} elsif (/\\bibliography\{(.*)\}/) {
|
|
|
|
foreach my $bib (split /,/, $1) {
|
|
|
|
$bib =~ s/^\s+//; # remove leading / trailing whitespace
|
|
|
|
$bib =~ s/\s+$//;
|
2006-11-22 08:06:10 +01:00
|
|
|
push @workset, "$path/$bib.bib";
|
2005-06-20 17:20:37 +02:00
|
|
|
}
|
2005-06-21 22:34:15 +02:00
|
|
|
} elsif (/\\includegraphics(\[.*\])?\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2006-11-22 08:06:10 +01:00
|
|
|
addToWorkSetExts("$path/$fn2", ".pdf", ".png", ".ps");
|
2005-09-02 17:50:55 +02:00
|
|
|
} elsif (/\\pgfdeclareimage(\[.*\])?\{.*\}\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
2006-11-22 08:06:10 +01:00
|
|
|
addToWorkSetExts("$path/$fn2", ".pdf", ".png", ".jpg");
|
|
|
|
} elsif (/\\pgfimage(\[.*\])?\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
|
|
|
addToWorkSetExts("$path/$fn2", ".pdf", ".png", ".jpg");
|
2005-06-20 17:20:37 +02:00
|
|
|
}
|
2005-06-20 16:25:50 +02:00
|
|
|
# !!! also support \usepackage
|
|
|
|
}
|
|
|
|
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
print OUT "]\n";
|
|
|
|
close OUT;
|