File: merge-pod

package info (click to toggle)
openafs 1.8.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,632 kB
  • sloc: ansic: 455,142; xml: 66,853; perl: 11,960; makefile: 9,982; sh: 7,851; objc: 6,430; java: 5,638; cpp: 2,268; asm: 1,214; yacc: 441; tcl: 249; lex: 201; csh: 85
file content (47 lines) | stat: -rwxr-xr-x 1,749 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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.

require 5.00503;

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";
    $file =~ s:\\:/:g if $^O eq 'cygwin';
    my $dir = dirname ($file);
    my $out = $file;
    unless ($out =~ s/\.in\z//) {
        die "input file $file does not end in .in\n";
    }
    open (FILE, "< $file") or die "cannot open $file: $!\n";
    binmode FILE, ':crlf' if $^O eq 'MSWin32';
    binmode FILE, ':crlf' if $^O eq 'cygwin';
    open (OUT, "> $out") or die "cannot open $out: $!\n";
    chdir $dir or die "cannot chdir to $dir: $!\n";
    local $/ = '';
    local $_;
    while (<FILE>) {
        if (/^=include\s+(\S+)/) {
            open (INCLUDE, "< $1") or die "cannot open $1: $!\n";
            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";
}