mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
84d9703786
Optimize match for leading numeric date.
64 lines
1.5 KiB
Perl
Executable File
64 lines
1.5 KiB
Perl
Executable File
#! /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";
|