]> git.lyx.org Git - lyx.git/blob - po/removeCR.pl
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / po / removeCR.pl
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 # file removeCR.pl
5 #
6 # This file is part of LyX, the document processor.
7 # Licence details can be found in the file COPYING.
8 #
9 # author: Kornel Benko, kornel@lyx.org
10 #
11 # Remove eventually added CR's from po-file after merging from a Windows OS.
12 #
13 # Usage: removeCR.pl *.po
14 #
15 use strict;
16 use warnings;
17
18 use File::Temp qw/ tempfile tempdir /;
19 use File::Copy qw(move);
20
21 sub removeCR($);
22
23 for my $file (@ARGV) {
24   if ($file =~ /\b[a-z][a-z](_[A-Z][A-Z])?\.po$/) {
25     removeCR($file);
26   }
27   else {
28     print "Not handled $file\n";
29   }
30 }
31
32 exit(0);
33
34 sub removeCR($)
35 {
36   my ($file) = @_;
37
38   print "Checking file $file ... ";
39
40   if (open(FI, $file)) {
41     my $found = 0;
42     my $fh =  File::Temp->new(UNLINK => 0);
43     my $tmpname = $fh->filename;
44     while (my $l = <FI>) {
45       while ($l =~ s/\r//) {
46         $found = 1;
47       }
48       print $fh $l;
49     }
50     close(FI);
51     close($fh);
52     if ($found) {
53       print "differs from $tmpname --> rewriting\n";
54       move($tmpname, $file);
55     }
56     else {
57       print "Ok\n";
58       unlink($tmpname);
59     }
60   }
61   else {
62     print "Could not read $file\n";
63   }
64 }