#!/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 <