3 # POD currently doesn't support any sort of =include directive. This
4 # processor works around that limitation. It takes a list of files ending in
5 # *.in as its argument and processes any POD directives of the form =include
6 # <file> in that file, generating a file with the *.in suffix removed. All
7 # paths are taken to be relative to the directory containing the file being
10 # Currently, only single include nesting is supported. The included file is
11 # not processed for additional =include statements.
16 use File
::Basename
qw(dirname basename);
19 for my $file (@ARGV) {
20 chdir $start or die "cannot chdir to $start: $!\n";
21 $file =~ s
:\\:/:g
if $^O
eq 'cygwin';
22 my $dir = dirname
($file);
24 unless ($out =~ s/\.in\z//) {
25 die "input file $file does not end in .in\n";
27 open (FILE
, "< $file") or die "cannot open $file: $!\n";
28 binmode FILE
, ':crlf' if $^O
eq 'MSWin32';
29 binmode FILE
, ':crlf' if $^O
eq 'cygwin';
30 open (OUT
, "> $out") or die "cannot open $out: $!\n";
31 chdir $dir or die "cannot chdir to $dir: $!\n";
35 if (/^=include\s+(\S+)/) {
36 open (INCLUDE
, "< $1") or die "cannot open $1: $!\n";
38 print OUT
<INCLUDE
> or die "cannot read/write from $1: $!\n";
39 close INCLUDE
or die "cannot read from $1: $!\n";
40 print OUT
"\n" or die "cannot write to $out: $!\n";
42 print OUT
$_ or die "cannot write to $out: $!\n";
45 close OUT
or die "cannot write to $out: $!\n";
46 close FILE
or die "cannot read from $file\n";