annotate postprocess.pl @ 244:c7748c19e1ff default tip

Update notes.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 23 Oct 2018 11:34:25 +0300
parents 1180249d713d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 # Perl script for filtering/post-processing the transpiled
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 # ProcessingJS code of Multipaint.JS to remove various uselessly
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 # complicated abstractions/transformations.
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 # Usage:
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 # 1) use "docompile.html" to transpile Multipaint, save to multipaint.js.orig
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 # 2) run the result through this script:
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 # perl postprocess.pl < multipaint.js.orig > multipaint.js
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 use strict;
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 use warnings;
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 while (defined(my $line = <STDIN>))
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 {
116
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
18 # The $p.parseByte()s are useless, really
74
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 $line =~ s@.p\.parseByte\(@(@g;
116
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
20
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
21 # Transform $p.parseInt(new $p.Character('x')) to direct ASCII number of the character
74
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 $line =~ s@.p\.parseInt\(\(new\s+.p\.Character\('(.)'\)\)\)@sprintf('%d',ord($1))@eg;
116
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
23
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
24 # Same for (new $p.Character('x'))
74
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 $line =~ s@\(new\s+.p\.Character\('(.)'\)\)@sprintf('%d',ord($1))@eg;
116
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
26
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
27 # Using parseInt() is wasteful, Math.trunc() is more efficient
76
b07084443528 Use Math.trunc() instead of Math.floor()
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
28 $line =~ s@.p\.parseInt\(@Math.trunc(@g;
77
62f21240ff63 Add a kludge in the post-processing script to fix the help() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
29
116
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
30 # Kludge. The switch() in help() in Interface.pde needs this to work after our
1180249d713d Add some comments to the postprocess script.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
31 # previous transformations done in this script.
77
62f21240ff63 Add a kludge in the post-processing script to fix the help() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
32 $line =~ s@switch\s*\(.p\.parseChar\(mode\)\)@switch (mode)@g;
74
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 print $line;
60892c9b4933 Add a JS post-processing script written in Perl.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }