123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #! /usr/bin/perl -w
- # Try to format ChangeLog in the current directory.
- # Remove unnecessary spaces. Add spaces when needed.
- use strict;
- my $progname = "trim_changelog";
- # Print message and exit (like "die", but without raising an exception).
- # System error is added at the end.
- sub error ($)
- {
- print STDERR "$progname: ERROR: " . shift(@_) . ": $!\n";
- exit 1;
- }
- if ($#ARGV != -1) {
- print STDERR "$progname accepts no arguments\n";
- exit 1;
- }
- open (CHANGELOG, "< ChangeLog") || error ("cannot open ChangeLog");
- open (CHNEW, "> ChangeLog.new") || error ("cannot open ChangeLog.new");
- # Convert initial spaces in ChangeLog to tabs.
- while (<CHANGELOG>) {
- # Trim trailing whitespace.
- s/\s*$//;
- # Make sure there are exactly 2 spaces before the e-mail.
- s/(^\w.*[^\s])\s+</$1 </;
- # Make sure there are exactly 2 spaces after numeric dates.
- s/(^[0-9]+-[0-9-]+)\s+/$1 /;
- # Up to 7 spaces and tab or up to 8 spaces -> tab.
- if (/^( {1,7}\t| {1,8})(.*)/) {
- $_ = "\t$2";
- }
- print CHNEW "$_\n";
- }
- close (CHANGELOG);
- close (CHNEW);
- system ("cmp ChangeLog ChangeLog.new >/dev/null 2>&1");
- if (($? >> 8) == 0) {
- unlink ("ChangeLog.new") || error ("Cannot remove ChangeLog.new");
- print "$progname: ChangeLog has not been changed\n";
- exit 0;
- }
- rename ("ChangeLog", "ChangeLog.bak") ||
- error ("Cannot rename ChangeLog to ChangeLog.bak");
- rename ("ChangeLog.new", "ChangeLog") ||
- error ("Cannot rename ChangeLog.new to ChangeLog");
- print "$progname: ChangeLog has been changed\n";
|