xref: /openbsd-src/gnu/usr.bin/perl/pod/splitpod (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1#!/usr/bin/perl
2
3use lib '../lib';  # If you haven't installed perl yet.
4use Pod::Functions;
5
6local $/ = '';
7
8$cur = '';
9while (<>) {
10
11    next unless /^=(?!cut)/ .. /^=cut/;
12
13    if (s/=item (\S+)/$1/) {
14	#$cur = "POSIX::" . $1;
15	$next{$cur} = $1;
16	$cur = $1;
17	$syn{$cur} .= $_;
18	next;
19    } else {
20	#s,L</,L<POSIX/,g;
21	s,L</,L<perlfunc/,g;
22	push @{$pod{$cur}}, $_ if $cur;
23    }
24}
25
26for $f ( keys %syn ) {
27    next unless $Type{$f};
28    $flavor = $Flavor{$f};
29    $orig = $f;
30    ($name = $f) =~ s/\W//g;
31
32    # deal with several functions sharing a description
33    $func = $orig;
34    $func = $next{$func} until $pod{$func};
35    my $body = join "", @{$pod{$func}};
36
37    # deal with unbalanced =over and =back cause by the split
38    my $has_over = $body =~ /^=over/;
39    my $has_back = $body =~ /^=back/;
40    $body =~ s/^=over\s*//m if $has_over and !$has_back;
41    $body =~ s/^=back\s*//m if $has_back and !$has_over;
42    open (POD, "> $name.pod") || die "can't open $name.pod: $!";
43    print POD <<EOF;
44=head1 NAME
45
46$orig - $flavor
47
48=head1 SYNOPSIS
49
50$syn{$orig}
51
52=head1 DESCRIPTION
53
54$body
55
56EOF
57
58    close POD;
59
60}
61