libafscp: code cleanup
[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     my $dir = dirname ($file);
22     my $out = $file;
23     unless ($out =~ s/\.in\z//) {
24         die "input file $file does not end in .in\n";
25     }
26     open (FILE, "< $file") or die "cannot open $file: $!\n";
27     open (OUT, "> $out") or die "cannot open $out: $!\n";
28     chdir $dir or die "cannot chdir to $dir: $!\n";
29     local $/ = '';
30     local $_;
31     while (<FILE>) {
32         if (/^=include\s+(\S+)/) {
33             open (INCLUDE, "< $1") or die "cannot open $1: $!\n";
34             local $/;
35             print OUT <INCLUDE> or die "cannot read/write from $1: $!\n";
36             close INCLUDE or die "cannot read from $1: $!\n";
37             print OUT "\n" or die "cannot write to $out: $!\n";
38         } else {
39             print OUT $_ or die "cannot write to $out: $!\n";
40         }
41     }
42     close OUT or die "cannot write to $out: $!\n";
43     close FILE or die "cannot read from $file\n";
44 }