3 if "%OS%" == "Windows_NT" goto WinNT
4 perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
8 if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
9 if %errorlevel% == 9009 echo You do not have Perl in your PATH.
10 if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
18 @dirs = ("src/com/hp/hpl/guess");
22 $d = new DirHandle $dr;
24 while (defined($_ = $d->read)) {
27 @dirs = (@dirs,"$dr/$_");
29 } elsif ($_ =~ /.java$/gio) {
30 @java = (@java,"$dr/$_");
37 open(OUTFILE,">scripts/Main.py");
38 open(OUTFILE2,">scripts/Main-applet.py");
40 print OUTFILE "\n# AUTOMATICALLY GENERATED\n";
41 print OUTFILE "# Defines wrapper methods that can be used as shortcuts in the interpreter\n\n";
43 print OUTFILE2 "\n# AUTOMATICALLY GENERATED\n";
44 print OUTFILE2 "# Defines wrapper methods that can be used as shortcuts in the interpreter\n\n";
53 my @d = split(/\n/,$_[0]);
59 next if ($d =~ /\@pyexport/);
65 if (defined($docs{$dfunc})) {
66 $docs{$dfunc} .= "\n$rdoc";
68 $docs{$dfunc} = "$rdoc";
72 foreach $java (@java) {
79 if ($_ =~ /^\s*\/\*\*/) {
81 } elsif ($_ =~ /^\s*\*\//) {
83 if ($doc !~ /\@pyexport/) {
89 if (($indoc) && ($_ =~ /^\s*\*/)){
95 if ($_ =~ /\@pyobj\s+(.*)/) {
99 if ($_ =~ /\@pyimport\s(.*)/) {
100 print OUTFILE $1."\n\n";
103 if ($_ =~ /\@pyexport\s*(.*)/) {
109 last if (($_ =~ /\{/) || ($_ =~ /\;/));
111 ($func) = $func =~ /(public.*)/i;
112 $func =~ s/\s+/ /gio;
113 ($funcname) = $func =~ /(\S+)\s*\(/;
114 ($args) = $func =~ /\(([^\)]+)/;
115 @args = split(/\s*\,\s*/,$args);
118 foreach $arg (@args) {
119 ($type,$name) = $arg =~ /(\S+)\s+(\S+)/;
126 ($first,@rest) = split(/\(/,$func);
127 $sig = "$first(@rest";
128 $sig =~ s/\{\s*//gio;
129 $sig =~ s/\s*\}//gio;
130 $sig =~ s/public //gio;
131 $sig =~ s/private //gio;
132 $sig =~ s/protected //gio;
134 if ($first =~ /\s+void\s+/gio) {
143 if ($pyfun =~ /\(/) {
145 print OUTFILE "def $pyfun:\n";
146 print OUTFILE "\t$void$pyobj.$funcname($args)\n\n";
147 print OUTFILE2 "def $pyfun:\n";
148 print OUTFILE2 "\t$void$pyobj.$funcname($args)\n\n";
151 #print OUTFILE "def $pyfun($args):\n";
155 #print OUTFILE "def $funcname($args):\n";
158 #print "$pyfun($args)\n";
160 $voids{$pyfun} .= "|$void";
161 $argcounts{$pyfun} .= "|$#args";
162 $argsig{$pyfun} .= "|$args";
163 $argdefs{$pyfun} .= "|$pyobj.$funcname";
165 &processdoc($doc,$pyfun,$sig);
169 #print "$java $pyobj\n" if ($pyobj ne "");
172 foreach $pyfun (keys %argcounts) {
173 next if ($pyfun =~ /HASH/);
176 @argcs = split(/\|/,$argcounts{$pyfun});
178 #print "$pyfun @argcs\n";
180 @argsig = split(/\|/,$argsig{$pyfun});
183 @argdefs = split(/\|/,$argdefs{$pyfun});
186 @voids = split(/\|/,$voids{$pyfun});
192 print OUTFILE "def $pyfun($argsig[0]):\n";
193 print OUTFILE "\t$voids[0]$argdefs[0]($argsig[0])\n\n";
194 print OUTFILE2 "def $pyfun($argsig[0]):\n";
195 print OUTFILE2 "\t$voids[0]$argdefs[0]($argsig[0])\n\n";
197 print OUTFILE "def $pyfun(*d):\n";
198 print OUTFILE2 "def $pyfun(*d):\n";
200 for ($i = 0 ; $i <= $#argcs ; $i++) {
205 print OUTFILE "\t$ifit len(d) == $req:\n";
206 print OUTFILE "\t\t$v$argdefs[$i](";
207 print OUTFILE2 "\t$ifit len(d) == $req:\n";
208 print OUTFILE2 "\t\t$v$argdefs[$i](";
209 for ($d = 0 ; $d < $req ; $d++) {
214 print OUTFILE "d[$d]";
215 print OUTFILE2 "d[$d]";
218 print OUTFILE2 ")\n";
221 print OUTFILE "\telse:\n";
222 print OUTFILE "\t\traise ValueError(\"Incorrect number of arguments\")\n";
223 print OUTFILE "\n\n";
224 print OUTFILE2 "\telse:\n";
225 print OUTFILE2 "\t\traise ValueError(\"Incorrect number of arguments\")\n";
226 print OUTFILE2 "\n\n";
232 foreach $key (keys %docs) {
233 next if ($key =~ /HASH/);
234 #print "$key\n$docs{$key}\n";
240 $dict = "\"$key\" : \"$f\"";
242 $dict .= ", \"$key\" : \"$f\"";
248 print OUTFILE "\n\n__FUNCTION_DICTIONARY = {$dict}\n\n";
249 print OUTFILE2 "\n\n__FUNCTION_DICTIONARY = {$dict}\n\n";
254 system("cat scripts/MainPre.py >> scripts/Main.py");
255 system("cat scripts/MainPre.py >> scripts/Main-applet.py");
256 system("cp scripts/MainPre.py scripts/Functions.py");