Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / doc / man-pages / merge-pod
1 #!/usr/bin/perl -w
2 #
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
8 # processed.
9 #
10 # Currently, only single include nesting is supported. The included file is
11 # not processed for additional =include statements.
12
13 require 5.00503;
14
15 use Cwd qw(getcwd);
16 use File::Basename qw(dirname basename);
17
18 my $start = getcwd;
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);
23 my $out = $file;
24 unless ($out =~ s/\.in\z//) {
25 die "input file $file does not end in .in\n";
26 }
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";
32 local $/ = '';
33 local $_;
34 while (<FILE>) {
35 if (/^=include\s+(\S+)/) {
36 open (INCLUDE, "< $1") or die "cannot open $1: $!\n";
37 local $/;
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";
41 } else {
42 print OUT $_ or die "cannot write to $out: $!\n";
43 }
44 }
45 close OUT or die "cannot write to $out: $!\n";
46 close FILE or die "cannot read from $file\n";
47 }