-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline.pl
More file actions
executable file
·46 lines (39 loc) · 939 Bytes
/
inline.pl
File metadata and controls
executable file
·46 lines (39 loc) · 939 Bytes
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
#!/usr/bin/perl
# Usage:
# $ cat src/class-main.php | perl inline.pl src/ > class-main.php
sub inline {
my $var= shift;
my $file= shift;
my $func= shift;
open F, $file or die("$file: $!");
<F> for 1..2;
$code = $inline = '';
$braces = 0;
while (<F>) {
if (defined $func && $_ =~ /function $func/) {
$inline = "do {\n";
$braces = 1;
next;
}
if ($braces) {
$braces += $_ =~ tr/\{//;
$braces -= $_ =~ tr/\}//;
if ($braces) {
$_ =~ s!return (.+);!$var= $1; break;!g;
$inline .= $_;
} else {
$inline .= "} while (0 /*once*/);\n";
$braces = 0;
}
} else {
$code .= $_;
}
}
close F;
return $code.$inline;
}
while (<STDIN>) {
$_ =~ s!require '([^']+)';!inline(undef, $ARGV[0]."/".$1, undef);!ge;
$_ =~ s!(\$[^ ]+) ?= ?require '([^']+)', ([^\(]+)\(([^;]+)\);!inline($1, $ARGV[0]."/".$2, $3);!ge;
print $_;
}