From 482d0ebc6670ddcd522e42aa2649ec5d222298cd Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Sun, 4 Jun 2017 18:32:47 +0200 Subject: [PATCH] Script to finxing linebreaks in po-files. Bad linebreaks could slip in if merging from branch on a Windows OS. --- po/removeCR.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 po/removeCR.pl diff --git a/po/removeCR.pl b/po/removeCR.pl new file mode 100755 index 0000000000..3e4e2de6b5 --- /dev/null +++ b/po/removeCR.pl @@ -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 = ) { + 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"; + } +}