summaryrefslogtreecommitdiff
path: root/doc/codebeautifier.pl
blob: 169b23c226a4a1950bed0c3ccc99a2117bda2406 (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
$nr = 1;
while(<stdin>)
{
    if(/\[CALLPERL\s+(.*)\s+left\]/ ... /\[CALLPERL end\]/) {
	$lang = $1 if($1);
	$code .= $_ if(!/CALLPERL/);
	$name = $1 if(/.flash.*name=([^&][^ ]*)/);
	$name = $1 if(/.flash.*name=&quot;([^&]*)&quot;/);
	chomp $name;
    } 
    elsif(/\[CALLPERL .*right\]/ ... /\[CALLPERL end\]/) {
	$highlight .= $_ if(!/CALLPERL/);
    }
    elsif ($code ne "" && ($lang eq "swfc" || $lang eq "sc")) {
	$code =~ s/&quot;/"/g;

#	    print stderr "Warning: ttf->swf\n" if($code =~ s/Arial.ttf/Arial.swf/g);

	open(fi, ">tmp.sc");print fi $code;close(fi);
	print stderr "[$lang] swfc tmp.sc ($name)\n";
	system("../src/swfc tmp.sc >&2");
	($embed = `swfdump -e $name`) =~ /WIDTH="([^"]*)"/;
	system("cp $name data");
	$width = $1;
	print "<td bgcolor=\"#ffffff\" width=\"$width\">";
	print $embed;
	print "</td>";
	$code="";
	print;
	unlink "tmp.sc";
    }
    elsif ($code ne "" && ($lang eq "python" or $lang eq "shell")) {
	$code =~ s/&quot;/"/g;
	if($lang eq "python") {
	   open(fi, ">$nr.py");print fi $code;close(fi);
	    $nr = $nr + 1;
	}
	print "<td bgcolor=\"#ffffff\" width=\"$width\">";
	print $embed;
	print "</td>";
	$code="";
	print;
    }
    elsif ($code ne "") {
	$code="";
    }
    elsif ($highlight ne "") {
	$highlight =~ s/^\n\s*//g;
	$highlight =~ s/\s*\n$//g;
	print "<pre>\n";
	# todo: apply syntax highlighting.
	print $highlight."\n";
	print "</pre>\n";
	$highlight="";
	print;
    }
    else {
	print;
    }
}