-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdequote.pl
executable file
·45 lines (35 loc) · 1008 Bytes
/
dequote.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl
foreach my $file (@ARGV) {
fix($file);
}
sub fix {
my $file = shift @_;
my $block;
return unless ( $file =~ m#\.(html|inc|js)$# );
open( FILE, "<$file" ) or die "$file: $!";
read FILE, $block, 1000000;
close FILE;
@groups = $block =~ m#\{\{(.*?)\}\}#msg;
@groups = grep( /\\['"]/, @groups );
return unless ( scalar @groups );
printf "file $file groups %i\n", scalar @groups;
$newblock = $block;
foreach $before (@groups) {
$DB::single=1;
$after = $before;
$after =~ s#\\'#'#g;
$after =~ s#\\"#"#g;
die if ($after eq $before);
my $index = index( $newblock, $before, 0);
if ($index >= 0) {
print "Replacing with $after\n";
substr($newblock,$index,length($before),$after);
} else {
die;
}
}
die "wtf" if $newblock eq $block;
open( FILE, ">$file" ) or die "$file: $!";
print FILE $newblock;
close FILE;
}