#!/usr/bin/perl if (scalar(@ARGV) != 2) { print("Usage : $0 sourcename imagename\n"); } else { $source=$ARGV[0]; $image=$ARGV[1]; open(image,">".$image); $line=""; $source=~ /^(.*).tex$/; $noyau=$1; if($noyau eq "") { $noyau=$source; } &dounion($source,0,""); } sub dounion { my $name=$_[0]; my $depth=$_[1]+1; my $append=$_[2]; my $test; my $newappend=""; local *source; if(!-f $name) { if(-f $name.".tex") { $name=$name.".tex"; } } if($depth>20) { print("$0 : The imbrication of files is too deep\n"); } else { if(-f $name) { print("Opening file ".$name."\n"); if($depth>1) { print image "%% Including file ".$name."\n"; } open(source,"<$name"); while() { $ligne=$_; $test=""; $test=~ /^(.?)$/; $ligne=~ /^\s?\\input\{([^\}]*)\}(.*)$/; $test=$1; if ($test eq "") { $ligne=~ /^\s?\\input\s*(.*)\s?$/; $test=$1; if ($test eq "") { $ligne=~ /^(%%% .?)/; if ($1 eq "") { $ligne=~ /^\\bibliographystyle(.*)$/; if ($1 eq "") { $ligne=~ /^\\bibliography(.*)$/; if ($1 eq "") { print image $ligne; } else { print image "%% ".$ligne; if(-f $noyau.".bbl") { &dounion($noyau.".bbl",$depth,""); } } } else { print image "%% ".$ligne; } } } else { &dounion($test,$depth,""); } } else { $newappend=$2; &dounion($test,$depth,$newappend); } } if($depth>1) { print image "%% End of file ".$name."\n"; print image $append."\n"; } close(fichier); } else { print("Could not open ".$name."\n"); print image $ligne ; } } }