1
by Vsevolod Velichko
initial import |
1 |
#!/usr/bin/perl
|
2 |
||
3 |
#****************************************************************************
|
|
4 |
#**
|
|
5 |
#** qutIM instant messenger
|
|
6 |
#**
|
|
7 |
#** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
|
|
8 |
#**
|
|
9 |
#*****************************************************************************
|
|
10 |
#**
|
|
11 |
#** $QUTIM_BEGIN_LICENSE$
|
|
12 |
#** This program is free software: you can redistribute it and/or modify
|
|
13 |
#** it under the terms of the GNU General Public License as published by
|
|
14 |
#** the Free Software Foundation, either version 3 of the License, or
|
|
15 |
#** (at your option) any later version.
|
|
16 |
#**
|
|
17 |
#** This program is distributed in the hope that it will be useful,
|
|
18 |
#** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 |
#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
20 |
#** See the GNU General Public License for more details.
|
|
21 |
#**
|
|
22 |
#** You should have received a copy of the GNU General Public License
|
|
23 |
#** along with this program. If not, see http://www.gnu.org/licenses/.
|
|
24 |
#** $QUTIM_END_LICENSE$
|
|
25 |
#**
|
|
26 |
#****************************************************************************/
|
|
27 |
||
28 |
use strict; |
|
29 |
use warnings; |
|
30 |
||
31 |
FILE: while (my $file = <STDIN>){ |
|
32 |
chomp $file; |
|
33 |
open (my $CURFILE, "<", $file) or warn "Cannot open $file: $!", next FILE; |
|
34 |
my $found_header = 0; |
|
35 |
my $found_header_end = 0; |
|
36 |
my @list; |
|
37 |
while (my $str = <$CURFILE>){ |
|
38 |
push @list, $str; |
|
39 |
if (!$found_header){ |
|
40 |
$found_header = 1 if ($str =~ /msgid\s+["]{2}/); |
|
41 |
}
|
|
42 |
elsif (!$found_header_end) { |
|
43 |
next FILE if ($str =~ /"X-Qt-Contexts:\s*true\\n"/); |
|
44 |
if ($str =~ /^\n$/ && !$found_header_end){ |
|
45 |
pop @list; |
|
46 |
push @list, qq/"X-Qt-Contexts: true\\n"\n\n/; |
|
47 |
$found_header_end = 1; |
|
48 |
}
|
|
49 |
}
|
|
50 |
}
|
|
51 |
close ($CURFILE); |
|
52 |
open ($CURFILE, ">>", $file) or warn "Cannot modify file: $!"; # Maybe there should be created *.bak? |
|
53 |
truncate $CURFILE, 0; # well, it possible to use ">", but I don't like it because of autotruncate. |
|
54 |
print $CURFILE $_ foreach (@list); |
|
55 |
}
|