2 # Convert Webmin function comments to POD format
5 @ARGV || die "usage: webmin-to-pod.pl [--svn 'comment'] [--overwrite] <file> ...";
10 $svn || die "--svn must be followed by a commit comment";
12 elsif ($a eq "--overwrite") {
20 $tempdir = "/tmp/pod";
21 mkdir($tempdir, 0755);
26 print STDERR "Failed to open $f : $!";
29 chomp(@lines = <SRC>);
35 # Scan line by line, looking for top-level subs with comments before
37 print "Processing $f :\n";
43 if ($lines[$i] =~ /^sub\s+(\S+)\s*$/) {
44 # Start of a function .. backtrack to get comments
47 if ($cmts[0] =~ /^\#+\s*(\Q$name\E)\s*(\((.*))/) {
48 # Found args in comments .. maybe multi-line
51 while($args !~ /\)\s*$/ && @cmts) {
54 $cont =~ s/^\s*#+\s*//;
57 $args = undef if ($args =~ /^\(\s*\)$/);
60 push(@out, "=head2 $name$args");
63 @cmts = ( "MISSING DOCUMENTATION" );
72 push(@out, $lines[$i]);
76 elsif ($lines[$i] =~ /^\#/) {
77 # Comments - add to temporary list
78 push(@cmts, $lines[$i]);
80 elsif (scalar(@cmts) == $i && @cmts) {
81 # End of first comments block - convert to head1
82 push(@out, "=head1 $basef");
84 if ($cmts[0] =~ /\Q$basef\E/) {
87 foreach my $c (@cmts) {
97 # Some other line - write out, and flush comments
98 push(@out, @cmts, $lines[$i]);
103 print " Fixed $count functions\n";
105 # Write out the file to a temp location
106 $temp = "$tempdir/$basef";
107 print " Writing to $temp\n";
108 open(TEMP, ">$temp");
114 # Use perl -c to verify syntax
115 $err = `perl -c $temp 2>&1`;
117 print " Perl verification FAILED\n";
120 print " Perl verification OK\n";
125 # Copy over original file (with cat)
127 $out = `cat $temp 2>&1 >$f`;
129 print " Save FAILED : $out\n";
135 if ($overwrite && $svn) {
136 ($dirf = $f) =~ s/\/[^\/]+$//;
137 $out = `cd $dirf && svn commit -m "$svn" $basef 2>&1`;
139 print " SVN FAILED : $out\n";