2 # Convert Webmin function comments to POD format
5 @ARGV || die "usage: webmin-to-pod.pl --svn 'comment' <file> ...";
10 $svn || die "--svn must be followed by a commit comment";
17 $tempdir = "/tmp/pod";
18 mkdir($tempdir, 0755);
23 print STDERR "Failed to open $f : $!";
26 chomp(@lines = <SRC>);
29 # Scan line by line, looking for top-level subs with comments before
31 print "Processing $f :\n";
37 if ($lines[$i] =~ /^sub\s+(\S+)\s*$/) {
38 # Start of a function .. backtrack to get comments
41 if ($cmts[0] =~ /^\#+\s*(\Q$name\E)\s*(\((.*))/) {
42 # Found args in comments .. maybe multi-line
45 while($args !~ /\)\s*$/ && @cmts) {
48 $cont =~ s/^\s*#+\s*//;
51 $args = undef if ($args =~ /^\(\s*\)$/);
54 push(@out, "=head2 $name$args");
57 @cmts = ( "MISSING DOCUMENTATION" );
66 push(@out, $lines[$i]);
70 elsif ($lines[$i] =~ /^\#/) {
71 # Comments - add to temporary list
72 push(@cmts, $lines[$i]);
75 # Some other line - write out, and flush comments
76 push(@out, @cmts, $lines[$i]);
81 print " Fixed $count functions\n";
83 # Write out the file to a temp location
86 $temp = "$tempdir/$basef";
87 print " Writing to $temp\n";
94 # Use perl -c to verify syntax
95 $err = `perl -c $temp 2>&1`;
97 print " Perl verification FAILED\n";
100 print " Perl verification OK\n";
105 # Copy over original file (with cat)