blob: 509ef3ec82553a7ac6d9a00ff1444b8d98ecede3 (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/usr/bin/perl
foreach $file ( split(/\n/, `find . -depth -print`) ) {
next unless $file =~ /(cgi|html)$/;
open(F,$file) or die "can't open $file for reading: $!";
@file = <F>;
#print "$file ". scalar(@file). "\n";
close $file;
$newline = ''; #avoid prepending extraneous newlines
$all = join('',@file);
$w = '';
$mode = 'html';
while ( length($all) ) {
if ( $mode eq 'html' ) {
if ( $all =~ /^(.+?)(<%=?.*)$/s && $1 !~ /<%/s ) {
$w .= $1;
$all = $2;
next;
} elsif ( $all =~ /^<%=(.*)$/s ) {
$w .= '<%';
$all = $1;
$mode = 'perlv';
#die;
next;
} elsif ( $all =~ /^<%(.*)$/s ) {
$w .= $newline; $newline = "\n";
$all = $1;
$mode = 'perlc';
#avoid newline prepend fix from borking indented first <%
$w =~ s/\n\s+\z/\n/;
$w .= "\n" if $w =~ /.+\z/;
next;
} elsif ( $all !~ /<%/s ) {
$w .= $all;
last;
} else {
warn length($all); die;
}
die;
} elsif ( $mode eq 'perlv' ) {
if ( $all =~ /^(.*?%>)(.*)$/s ) {
$w .= $1;
$all=$2;
$mode = 'html';
next;
}
die "unterminated <%= ??? (in $file):";
} elsif ( $mode eq 'perlc' ) {
if ( $all =~ /^([^\n]*?)%>(.*)$/s ) {
$w .= "%$1\n";
$all=$2;
$mode='html';
next;
}
if ( $all =~ /^([^\n]*)\n(.*)$/s ) {
$w .= "%$1\n";
$all=$2;
next;
}
} else { die };
}
system("chmod u+w $file");
select W; $| = 1; select STDOUT;
open(W,">$file") or die "can't open $file for writing: $!";
print W $w;
close W;
}
|