From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- support/texdeps/texdeps.pl | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 support/texdeps/texdeps.pl (limited to 'support/texdeps/texdeps.pl') diff --git a/support/texdeps/texdeps.pl b/support/texdeps/texdeps.pl new file mode 100644 index 0000000000..1eeb686066 --- /dev/null +++ b/support/texdeps/texdeps.pl @@ -0,0 +1,85 @@ +#!/usr/bin/perl +# Look, it was an evening hack. If I'd known I was going to have +# users, I'd have made sure it works. + +$kpse =1; # Turn this on for kpathsea searching. +# PS: I lied about texinputs. +$debug=0; +$VERSION="0.03"; + +$initialfile = shift || usage(); +@files = $initialfile; +@deps = $initialfile; + +# This hash contains most of the program's magic. +# On the left, a stringified regexp returning a filename in $1 +# On the right, the default extension for that filename. +%magical = ( + '\\\\(?:input|include)[\\s\\{]+(.*?)[\\s\\}]+' => "tex", + '\\\\usepackage\\{(.*?)\\}' => "sty", + '\\\\bibliographystyle\\{(.*?)\\}' => "bst", + '\\\\bibliography\\{(.*?)\\}' => "bbl", + '\\\\includegraphics(?:\\[.*?\\])?\\{(.*?)\\}' => "eps" +); + +# Keep looping while there are still things to do. +while (@files) { + $filename = shift @files; + warn "Couldn't open $filename" unless open F, "<$filename"; + + # Go through each line looking for things. + while () { + # Check against each pattern in turn. + foreach $re (keys %magical) { + # The /g is very clever. Can you see why? + while (/$re/g) { + $newfile=$1; + $newfile.=".".$magical{$re} unless $newfile=~/.*\..*/; + $newfile=resolve($newfile); + push @deps, $newfile if $newfile; + push @files, $newfile if $newfile; + } + } + } + close F; +} + +# Print 'em out. +foreach (@deps) { print $_."\n"; } + +sub resolve { + $what=shift; + $resolution=""; + # Kpse is done by passing the extension and the name to + # kpsewhich. + if ($kpse) { + $ext=($what=~/.*\.(.*)/)[0]; + $resolution = `kpsewhich $ext $what`; + chomp($resolution); + print "kpsewhich $ext $what gave $resolution\n" if $debug; + warn "! kpse couldn't find $what (in $filename)\n" unless $resolution; + } else { $resolution = $what } + return unless $resolution; + warn "! Couldn't find $resolution (in $filename)\n" unless -e $resolution; + return $resolution +} + +sub usage { + print <