Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 187 lines (156 sloc) 4.429 kB
22ed6cd @damellis Importing Processing rev. 5503 (1.0.3).
damellis authored
1 #!/usr/bin/perl -w
2
3 $basedir = 'src/processing/core';
4
5 @contents = ();
6
7 # next slurp methods from PGraphics
8 open(F, "$basedir/PGraphics.java") || die $!;
9 foreach $line (<F>) {
10 push @contents, $line;
11 }
12 close(F);
13
14 # PGraphics subclasses PImage.. now get those methods
15 open(F, "$basedir/PImage.java") || die $!;
16 foreach $line (<F>) {
17 push @contents, $line;
18 }
19 close(F);
20
21 #open(DEBUG, ">debug.java") || die $!;
22 #print DEBUG @contents;
23 #close(DEBUG);
24 #exit;
25
26
27 open(APPLET, "$basedir/PApplet.java") || die $!;
28 @applet = <APPLET>;
29 close(APPLET);
30
31
32 $insert = 'public functions for processing.core';
33
34 # an improved version of this would only rewrite if changes made
35 open(OUT, ">$basedir/PApplet.new") || die $!;
36 foreach $line (@applet) {
37 print OUT $line;
38 last if ($line =~ /$insert/);
39 }
40
41 $comments = 0;
42
43 while ($line = shift(@contents)) {
44 $decl = "";
45
46 if ($line =~ /\/\*/) {
47 $comments++;
48 #print "+[$comments] $line";
49 }
50 if ($line =~ /\*\//) {
51 $comments--;
52 #print "-[$comments] $line";
53 }
54 next if ($comments > 0);
55
56 $got_something = 0; # so it's ugly, back off
57 $got_static = 0;
58 $got_interface = 0;
59
60 if ($line =~ /^\s*public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
61 $got_something = 1;
62 $got_interface = 1;
63 } elsif ($line =~ /^\s*abstract public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
64 $got_something = 1;
65 } elsif ($line =~ /^\s*public final ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
66 $got_something = 1;
67 } elsif ($line =~ /^\s*static public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
68 $got_something = 1;
69 $got_static = 1;
70 }
71 # if function is marked "// ignore" then, uh, ignore it.
72 if (($got_something == 1) && ($line =~ /\/\/ ignore/)) {
73 $got_something = 0;
74 }
75 #if ($line =~ /^\s*public (\w+) [a-zA-z_]+\(.*$/) {
76 if ($got_something == 1) {
77 if ($1 ne 'void') {
78 $returns = 'return ';
79 } else {
80 $returns = '';
81 }
82
83 # if ($line =~ /^(\s+)abstract\s+([^;]+);/) {
84 # $line = $1 . $2 . " {\n";
85 # #print "found $1\n";
86 # # hrm
87 # }
88 # remove the 'abstract' modifier
89 $line =~ s/\sabstract\s/ /;
90
91 # replace semicolons with a start def
92 $line =~ s/\;\s*$/ {\n/;
93
94 print OUT "\n\n$line";
95
96 # if ($got_interface == 1) {
97 # $iline = $line;
98 # $iline =~ s/ \{/\;/;
99 ## print INTF "\n$iline";
100 # }
101
102 $decl .= $line;
103 while (!($line =~ /\)/)) {
104 $line = shift (@contents);
105 $decl .= $line;
106 $line =~ s/\;\s*$/ {\n/;
107 print OUT $line;
108
109 # if ($got_interface == 1) {
110 # $iline = $line;
111 # $iline =~ s/ \{/\;/;
112 ## print INTF $iline;
113 # }
114 }
115
116 #$g_line = '';
117 #$r_line = '';
118
119 $decl =~ /\s(\S+)\(/;
120 $decl_name = $1;
121 if ($got_static == 1) {
122 #print OUT " ${returns}PGraphics.${decl_name}(";
123 $g_line = " ${returns}PGraphics.${decl_name}(";
124 } else {
125 #if ($returns eq '') {
126 #print OUT " if (recorder != null) recorder.${decl_name}(";
127 $r_line = " if (recorder != null) recorder.${decl_name}(";
128 #}
129 #print OUT " ${returns}g.${decl_name}(";
130 $g_line = " ${returns}g.${decl_name}(";
131 }
132
133 $decl =~ s/\s+/ /g; # smush onto a single line
134 $decl =~ s/^.*\(//;
135 $decl =~ s/\).*$//;
136
137 $prev = 0;
138 @parts = split(', ', $decl);
139 foreach $part (@parts) {
140 #($the_type, $the_arg) = split(' ', $part);
141 @blargh = split(' ', $part);
142 $the_arg = $blargh[1];
143 $the_arg =~ s/[\[\]]//g;
144 if ($prev != 0) {
145 #print OUT ", ";
146 $g_line .= ", ";
147 $r_line .= ", ";
148 }
149 #print OUT "${the_arg}";
150 $g_line .= "${the_arg}";
151 $r_line .= "${the_arg}";
152 $prev = 1;
153 }
154 #print OUT ");\n";
155 $g_line .= ");\n";
156 $r_line .= ");\n";
157
158 if (($got_static != 1) && ($returns eq '')) {
159 print OUT $r_line;
160 }
161 print OUT $g_line;
162 print OUT " }\n";
163 }
164 }
165 print OUT "}\n";
166 #print INTF "}\n";
167
168 close(OUT);
169 #close(INTF);
170
171 $oldguy = join(' ', @applet);
172
173 open(NEWGUY, "$basedir/PApplet.new") || die $!;
174 @newbie = <NEWGUY>;
175 $newguy = join(' ', @newbie);
176 close(NEWGUY);
177
178 if ($oldguy ne $newguy) {
179 # replace him
180 print "updating PApplet with PGraphics api changes\n";
181 `mv $basedir/PApplet.new $basedir/PApplet.java`;
182 } else {
183 # just kill the new guy
184 #print "no changes to applet\n";
185 `rm -f $basedir/PApplet.new`;
186 }
Something went wrong with that request. Please try again.