2010-07-16 01:21:26 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# POD currently doesn't support any sort of =include directive. This
|
|
|
|
# processor works around that limitation. It takes a list of files ending in
|
|
|
|
# *.in as its argument and processes any POD directives of the form =include
|
|
|
|
# <file> in that file, generating a file with the *.in suffix removed. All
|
|
|
|
# paths are taken to be relative to the directory containing the file being
|
|
|
|
# processed.
|
|
|
|
#
|
|
|
|
# Currently, only single include nesting is supported. The included file is
|
|
|
|
# not processed for additional =include statements.
|
|
|
|
|
2011-01-14 20:00:14 +00:00
|
|
|
require 5.00503;
|
2010-07-16 01:21:26 +01:00
|
|
|
|
|
|
|
use Cwd qw(getcwd);
|
|
|
|
use File::Basename qw(dirname basename);
|
|
|
|
|
|
|
|
my $start = getcwd;
|
|
|
|
for my $file (@ARGV) {
|
|
|
|
chdir $start or die "cannot chdir to $start: $!\n";
|
|
|
|
my $dir = dirname ($file);
|
|
|
|
my $out = $file;
|
|
|
|
unless ($out =~ s/\.in\z//) {
|
|
|
|
die "input file $file does not end in .in\n";
|
|
|
|
}
|
2011-01-14 20:00:14 +00:00
|
|
|
open (FILE, "< $file") or die "cannot open $file: $!\n";
|
|
|
|
open (OUT, "> $out") or die "cannot open $out: $!\n";
|
2010-07-16 01:21:26 +01:00
|
|
|
chdir $dir or die "cannot chdir to $dir: $!\n";
|
|
|
|
local $/ = '';
|
|
|
|
local $_;
|
|
|
|
while (<FILE>) {
|
|
|
|
if (/^=include\s+(\S+)/) {
|
2011-01-14 20:00:14 +00:00
|
|
|
open (INCLUDE, "< $1") or die "cannot open $1: $!\n";
|
2010-07-16 01:21:26 +01:00
|
|
|
local $/;
|
|
|
|
print OUT <INCLUDE> or die "cannot read/write from $1: $!\n";
|
|
|
|
close INCLUDE or die "cannot read from $1: $!\n";
|
|
|
|
print OUT "\n" or die "cannot write to $out: $!\n";
|
|
|
|
} else {
|
|
|
|
print OUT $_ or die "cannot write to $out: $!\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close OUT or die "cannot write to $out: $!\n";
|
|
|
|
close FILE or die "cannot read from $file\n";
|
|
|
|
}
|