nixpkgs/pkgs/misc/tex/nix/find-includes.pl
Eelco Dolstra 04cc6b721a * Made findLaTeXIncludes pure. Previously find-includes.pl looked
outside of the Nix store for the dependencies of the root source
  file, which is impure.  That's why it needed the
  `builtins.currentTime' hack to force a rebuild.  It also didn't work
  in a chroot.  Now find-includes.pl only scans the source file at
  hand, and we use builtins.genericClosure to find all includes
  recursively.

svn path=/nixpkgs/trunk/; revision=16414
2009-07-17 15:10:01 +00:00

61 lines
1.8 KiB
Perl

use strict;
use File::Basename;
my $src = $ENV{"src"};
my $out = $ENV{"out"};
my $path = $ENV{"searchRelativeTo"};
open OUT, ">$out" or die;
print OUT "[\n";
open FILE, "< $src" or die;
sub addName {
my ($type, $name) = @_;
print OUT "{ type = \"$type\"; name = \"$name\"; }\n";
}
while (<FILE>) {
if (/\\input\{(.*)\}/) {
my $fn2 = $1;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "tex", "$fn2";
} elsif (/\\usepackage(\[.*\])?\{(.*)\}/) {
my $fn2 = $2;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "misc", "$fn2.sty";
} elsif (/\\documentclass(\[.*\])?\{(.*)\}/) {
my $fn2 = $2;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "misc", "$fn2.cls";
} elsif (/\\bibliographystyle\{(.*)\}/) {
my $fn2 = $1;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "misc", "$fn2.bst";
} elsif (/\\bibliography\{(.*)\}/) {
foreach my $bib (split /,/, $1) {
$bib =~ s/^\s+//; # remove leading / trailing whitespace
$bib =~ s/\s+$//;
addName "misc", "$bib.bib";
}
} elsif (/\\includegraphics(\[.*\])?\{(.*)\}/) {
my $fn2 = $2;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "img", "$fn2";
} elsif (/\\pgfdeclareimage(\[.*\])?\{.*\}\{(.*)\}/) {
my $fn2 = $2;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "img", "$fn2";
} elsif (/\\pgfimage(\[.*\])?\{(.*)\}/) {
my $fn2 = $2;
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
addName "img", "$fn2";
}
# !!! also support \usepackage
}
close FILE;
print OUT "]\n";
close OUT;