]> git.lyx.org Git - lyx.git/commitdiff
Script to finxing linebreaks in po-files.
authorKornel Benko <kornel@lyx.org>
Sun, 4 Jun 2017 16:32:47 +0000 (18:32 +0200)
committerKornel Benko <kornel@lyx.org>
Sun, 4 Jun 2017 16:32:47 +0000 (18:32 +0200)
Bad linebreaks could slip in if merging from branch on a Windows OS.

po/removeCR.pl [new file with mode: 0755]

diff --git a/po/removeCR.pl b/po/removeCR.pl
new file mode 100755 (executable)
index 0000000..3e4e2de
--- /dev/null
@@ -0,0 +1,64 @@
+#! /usr/bin/env perl
+# -*- mode: perl; -*-
+
+# file removeCR.pl
+#
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+#
+# author: Kornel Benko, kornel@lyx.org
+#
+# Remove eventually added CR's from po-file after merging from a Windows OS.
+#
+# Usage: removeCR.pl *.po
+#
+use strict;
+use warnings;
+
+use File::Temp qw/ tempfile tempdir /;
+use File::Copy qw(move);
+
+sub removeCR($);
+
+for my $file (@ARGV) {
+  if ($file =~ /\b[a-z][a-z](_[A-Z][A-Z])?\.po$/) {
+    removeCR($file);
+  }
+  else {
+    print "Not handled $file\n";
+  }
+}
+
+exit(0);
+
+sub removeCR($)
+{
+  my ($file) = @_;
+
+  print "Checking file $file ... ";
+
+  if (open(FI, $file)) {
+    my $found = 0;
+    my $fh =  File::Temp->new(UNLINK => 0);
+    my $tmpname = $fh->filename;
+    while (my $l = <FI>) {
+      while ($l =~ s/\r//) {
+       $found = 1;
+      }
+      print $fh $l;
+    }
+    close(FI);
+    close($fh);
+    if ($found) {
+      print "differs from $tmpname --> rewriting\n";
+      move($tmpname, $file);
+    }
+    else {
+      print "Ok\n";
+      unlink($tmpname);
+    }
+  }
+  else {
+    print "Could not read $file\n";
+  }
+}