2005-06-20 15:25:50 +01:00
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $root = $ENV{"rootFile"};
|
|
|
|
my $out = $ENV{"out"};
|
|
|
|
|
|
|
|
open OUT, ">$out" or die;
|
|
|
|
print OUT "[\n";
|
|
|
|
|
|
|
|
# We search for files relative to the root file. TODO: search
|
|
|
|
# relative to the paths in $TEXINPUTS.
|
|
|
|
die unless substr($root, 0, 1) eq "/";
|
|
|
|
my ($x, $path, $y) = fileparse($root);
|
|
|
|
|
|
|
|
$path =~ s/\/$//;
|
|
|
|
|
|
|
|
my @workset = ();
|
|
|
|
my %doneset = ();
|
|
|
|
|
|
|
|
push @workset, $root;
|
|
|
|
|
|
|
|
while (scalar @workset > 0) {
|
|
|
|
|
|
|
|
my $fn = pop @workset;
|
|
|
|
next if (defined $doneset{$fn});
|
|
|
|
|
2005-06-20 16:06:58 +01:00
|
|
|
$doneset{$fn} = 1;
|
|
|
|
|
2005-06-20 15:25:50 +01:00
|
|
|
if (!open FILE, "< $fn") {
|
|
|
|
print STDERR "(cannot open $fn, ignoring)\n";
|
|
|
|
next;
|
|
|
|
};
|
2005-06-20 16:06:58 +01:00
|
|
|
|
2005-06-20 15:25:50 +01:00
|
|
|
|
2005-06-20 16:06:58 +01:00
|
|
|
# Print out the full path *and* its relative path to $root.
|
|
|
|
|
|
|
|
die if substr($fn, 0, length $path) ne $path;
|
|
|
|
my $relFN = substr($fn, (length $path) + 1);
|
|
|
|
|
|
|
|
print OUT "$fn \"$relFN\"\n";
|
2005-06-20 15:25:50 +01:00
|
|
|
|
2005-06-20 16:06:58 +01:00
|
|
|
|
|
|
|
# Recursively find include in $fn.
|
2005-06-20 15:25:50 +01:00
|
|
|
while (<FILE>) {
|
|
|
|
if (/\\input\{(.*)\}/) {
|
|
|
|
my $fn2 = $1;
|
2005-06-20 16:06:58 +01:00
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
|
|
|
push @workset, $path . "/" . $fn2;
|
2005-06-20 15:25:50 +01:00
|
|
|
} elsif (/\\documentclass(\[.*\])?\{(.*)\}/) {
|
|
|
|
my $fn2 = $2;
|
2005-06-20 16:06:58 +01:00
|
|
|
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
|
|
|
push @workset, $path . "/" . $fn2 . ".cls";
|
2005-06-20 16:20:37 +01:00
|
|
|
} elsif (/\\bibliography\{(.*)\}/) {
|
|
|
|
foreach my $bib (split /,/, $1) {
|
|
|
|
$bib =~ s/^\s+//; # remove leading / trailing whitespace
|
|
|
|
$bib =~ s/\s+$//;
|
|
|
|
push @workset, $path . "/" . $bib . ".bib";
|
|
|
|
}
|
|
|
|
}
|
2005-06-20 15:25:50 +01:00
|
|
|
# !!! also support \usepackage
|
|
|
|
}
|
|
|
|
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
print OUT "]\n";
|
|
|
|
close OUT;
|