File: extpod

package info (click to toggle)
perl-tk 1%3A804.036%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,284 kB
  • sloc: ansic: 349,560; perl: 52,292; sh: 12,678; makefile: 5,700; asm: 3,565; ada: 1,681; pascal: 1,082; cpp: 1,006; yacc: 883; cs: 879
file content (111 lines) | stat: -rwxr-xr-x 2,321 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/local/bin/perl -w
use strict;
use Getopt::Std;
use ExtUtils::Manifest "/mani/";
my $tkdir = "../..";
my %opt;
getopts('e',\%opt);

my $files = maniread("$tkdir/MANIFEST");

@ARGV = grep(/\.pm$/,map("$tkdir/$_",sort keys %$files));

die "No pm files" unless @ARGV;

BEGIN
  {
    mkdir 'podnew',  0755 unless -d 'podnew';	# extracted POD
    mkdir 'podcoll', 0755 unless -d 'podcoll';  # exists  already in ../pod/
    mkdir 'tmppm',   0755 unless -d 'tmppm';	# finaly modified .pm?
  }

my $modified;  # has pod
my $outfile;   # tmp pm file
my $infile;
my $podname;
my $inpod = 0;

while (<>)
 {
  if ($. == 1)
   {
    $infile = $ARGV;
    my ($leaf) = $ARGV =~ m#/([^/]+)$#;
    $outfile    = "tmppm/$leaf";
    close(FILE) if (defined fileno(FILE));
    close(POD) if (defined fileno(POD));
    open(FILE,">$outfile") || die "Cannot open $outfile:$!";
    $modified = 0;
    $inpod = 0;
    ($podname = $leaf ) =~ s/[^.]+$/pod/;
   }
######

  if (/^=[a-z]/ && !defined(fileno(POD)))
   {
	    if (-f "$tkdir/pod/$podname")
	      {
		print "# Oops, pod name collision: $podname\n";
		open POD, ">podcoll/$podname" or die "can't open podcoll/$podname";
              }
            else
              {
		open POD, ">podnew/$podname"  or die "can't open podnew/$podname";
	      }
	    my ($targ) = $ARGV =~ m#^$tkdir/(.*)$#;
	    print POD "\n=for pm $targ\n\n";

   }

  if (/^=cut/)
    {
	$inpod = 0;
	print POD "\n" or die "can't print \\n for =cut";
    }
  elsif (/^=[a-z]/)
    {
     $inpod = 1;
    }

    if ($inpod)
      {
        $modified++;
	print POD;
      }
    else
      {
	print FILE;
      }

######
  if (eof)
   {
    close(FILE) if (defined fileno(FILE));
    if ($modified)
      {
	warn "$infile modified";
	print POD "\n\n=cut\n\n";
        close POD;
	if ($opt{'e'})
          {
	    if (-f "$infile.bak")
             {
              chmod(0644,"$infile.bak") unless -w "$infile.bak";
              unlink "$infile.bak";
             }
	    rename $infile, "$infile.bak";
	    system('p4',edit => $infile);
	    rename $outfile, $infile or die "can't rename $ARGV $outfile: $!";
          }
        print "diff -u $infile $outfile\t# $podname $modified POD lines\n";
      }
    else
      {
        unlink $outfile;
      }
    $modified = 0;
    $inpod = 0;
    $. = 0;
   }
 }