Gracefuly handle spaces around the equal sign in the Authors file.
[parsecvs.git] / edit-change-log
blobb4ec67a0ef42ea7fffcae692d5385e509d7f9af7
1 #!/usr/bin/env perl
3 use Text::Wrap;
5 sub read_file {
6 my($buffer);
7 my($file) = shift;
8 local($/) = undef;
9 $buffer = <$file>;
10 return($buffer);
13 sub edit_change_log() {
14 my $file = $ARGV[0];
15 open my $f, '<', $file or die ("Failed to open file: $file\n");
16 my $logmsg = read_file ($f);
18 # We do a bunch of munging on the log message here,
19 # particularly for logs that are formatted in a ChangeLog
20 # style.
22 my $origlog = $logmsg;
24 close ($f);
26 # print "original: $logmsg\n";
28 # Kill initial date/name stamp: YYYY-MM-DD First Last <email@example.com>
30 $logmsg =~ s|^\s*\d\d*-\d\d*-\d\d*\s*[^<\n]*<[^>\n]*>\s*$|* \n|mg;
32 # Strip out nickle version numbers
33 $logmsg =~ s|^(version )?2.\d\d*$||mg;
35 # Remove initial space for each line
36 $logmsg =~ s|^[ \t]+||mg;
38 # Collapse space sequences
39 $logmsg =~ s|[ \t]+| |g;
41 # Un-fold paragraphs
42 $logmsg =~ s|([^\n])\n([^0-9*+\-\n])|$1 $2|g;
44 my @lines = split (/\n/, $logmsg);
46 $logmsg = "";
48 my $reviews = "";
50 foreach my $line (@lines) {
51 # find lines begining with '*'
52 if ($line =~ /^reviewed by:\s*/) {
53 if ($line !~ /<delete if not using/) {
54 $reviews = $reviews . "\n" . $line;
56 } else {
57 if ($line =~ s/^\*\s\s*//) {
58 # strip off filename
59 $line =~ s/^[^:]*:\s*//;
60 # strip off function names
61 while ($line =~ s/^\([^)]*\)[,:]*\s*// ) {
64 # Remove initial space for each line
65 $line =~ s|^[ \t+]+||;
67 # Collapse space sequences
68 $line =~ s|[ \t]+| |g;
71 # re line-wrap
73 $line = Text::Wrap::wrap ("", " ", $line);
75 $logmsg = $logmsg . $line . "\n";
78 $logmsg = $logmsg . $reviews;
80 # Trim initial newlines
81 $logmsg =~ s|^\n+||;
83 # collapse sequences of newlines
84 $logmsg =~ s/\n\n*/\n/g;
86 # Remove trailing whitespace
87 $logmsg =~ s/[\s\n]+\z//;
89 if (@skipped) {
90 $logmsg .= "\n\n\nSKIPPED:\n\t";
91 $logmsg .= join("\n\t", @skipped) . "\n";
94 open my $f, '>', $file or die ("Failed to open file: $file\n");
96 print $f "$logmsg\n";
97 close ($f)
100 edit_change_log ()