new parameter addspacechars
[swftools.git] / doc / codebeautifier.pl
1 $nr = 1;
2 while(<stdin>)
3 {
4     if(/\[CALLPERL\s+(.*)\s+left\]/ ... /\[CALLPERL end\]/) {
5         $lang = $1 if($1);
6         $code .= $_ if(!/CALLPERL/);
7         $name = $1 if(/.flash.*name=([^&][^ ]*)/);
8         $name = $1 if(/.flash.*name=&quot;([^&]*)&quot;/);
9         chomp $name;
10     } 
11     elsif(/\[CALLPERL .*right\]/ ... /\[CALLPERL end\]/) {
12         $highlight .= $_ if(!/CALLPERL/);
13     }
14     elsif ($code ne "" && ($lang eq "swfc" || $lang eq "sc")) {
15         $code =~ s/&quot;/"/g;
16
17 #           print stderr "Warning: ttf->swf\n" if($code =~ s/Arial.ttf/Arial.swf/g);
18
19         open(fi, ">tmp.sc");print fi $code;close(fi);
20         print stderr "[$lang] swfc tmp.sc ($name)\n";
21         system("../src/swfc tmp.sc >&2");
22         ($embed = `swfdump -e $name`) =~ /WIDTH="([^"]*)"/;
23         system("cp $name data");
24         $width = $1;
25         print "<td bgcolor=\"#ffffff\" width=\"$width\">";
26         print $embed;
27         print "</td>";
28         $code="";
29         print;
30         unlink "tmp.sc";
31     }
32     elsif ($code ne "" && ($lang eq "python" or $lang eq "shell")) {
33         $code =~ s/&quot;/"/g;
34         if($lang eq "python") {
35            open(fi, ">$nr.py");print fi $code;close(fi);
36             $nr = $nr + 1;
37         }
38         print "<td bgcolor=\"#ffffff\" width=\"$width\">";
39         print $embed;
40         print "</td>";
41         $code="";
42         print;
43     }
44     elsif ($code ne "") {
45         $code="";
46     }
47     elsif ($highlight ne "") {
48         $highlight =~ s/^\n\s*//g;
49         $highlight =~ s/\s*\n$//g;
50         print "<pre>\n";
51         # todo: apply syntax highlighting.
52         print $highlight."\n";
53         print "</pre>\n";
54         $highlight="";
55         print;
56     }
57     else {
58         print;
59     }
60 }