#!/usr/local/bin/perl # # David MacKay April 2000 # # includer.p - reads a file and follows \input{} commands # and writes a flat file without those commands # # includer.p shah | website.p # # note the include command must come at start of line # # Wed 18/4/01 added feature to strip "
......." from included files # Substitutions like \pounds -> £ are done by website.p using s/// # $verbose = 0 ; $enddocends = 1 ; # whether \end{document} causes this program to halt its operation $skipcomments = 0 ; # whether to not print comment lines (%) eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $filelist = "" ; $filenumber=0 ; $level = 1 ; # WHLOOP: while( <>) { if (!( /^\%/ ) ) { if ( $enddocends && /\\end\{document\}/ ) { print ; last WHLOOP; } while ( s/^[#\\](input|include)\s*[\{"]([^}]+)[\}"]// ) { $f = $2 ; print STDERR "INCLUDER following input file $f \n" if ( $verbose ); &processfile ( $f ) ; } } if ( (!( /^\%/ ) ) || (!$skipcomments) ) { # print ; } } # print STDERR $filelist if ($verbose) ; # sub processfile { ($file,$rest) = @_ ; $filenumber ++ ; local($opencommand) = "open( O$filenumber , \"< $file\" ) " ; local($readcommand) = "\$_ =