Merge commit 'origin/master'
[libwww-perl-eserte.git] / bin / uncuddle
blob3431b19afc5c228d71d4126d16aa656e6181bc2e
1 #!/usr/bin/perl -w
3 # Ensure uncucddled else
5 for my $file (@ARGV) {
6 open(my $old, "<$file") || do {
7 warn "Failed to open $file: $!\n";
8 next;
9 };
11 open(my $new, ">$file.new") || do {
12 warn "Failed to create $file.new: $!";
13 next;
16 my $yup;
17 while (<$old>) {
18 if (/^(\s*)\}\s*(els(?:e|if)\b.*)/) {
19 print $new "$1}\n";
20 print $new "$1$2\n";
21 $yup++;
23 else {
24 print $new $_;
28 close($old);
29 close($new);
31 if ($yup) {
32 rename($file, "$file.orig") || warn "Can't rename $file: $!";
33 rename("$file.new", $file) || warn "Can't rename $file.new: $!";
35 else {
36 unlink("$file.new") || die "Can't unlink: $!";