mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
Add script to format ChangeLog in the current directory.
This commit is contained in:
parent
a66e5f511f
commit
4ea9dcf71c
65
maint/trim_changelog
Executable file
65
maint/trim_changelog
Executable file
@ -0,0 +1,65 @@
|
||||
#! /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.*\w)\s+</$1 </;
|
||||
|
||||
# Make sure there are exactly 2 spaces after numeric dates.
|
||||
if (/[0-9]+-[0-9]+-[0-9]+\w/) {
|
||||
s/(^[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";
|
Loading…
Reference in New Issue
Block a user