added db.getRemovedNodes() and db.getRemovedEdges() so that you can get at nodes...
[guess.git] / pyexport.bat
blob0d4d6593c5de992e4ef6def18b474f7f1b801af0
1 @rem = '--*-Perl-*--
2 @echo off
3 if "%OS%" == "Windows_NT" goto WinNT
4 perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
5 goto endofperl
6 :WinNT
7 perl -x -S %0 %*
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
11 goto endofperl
12 @rem ';
13 #!perl
14 #line 15
15 use DirHandle;
16 @java = ();
18 @dirs = ("src/com/hp/hpl/guess");
20 while ($#dirs >= 0) {
21     $dr = shift(@dirs);
22     $d = new DirHandle $dr;
23     if (defined $d) {
24         while (defined($_ = $d->read)) { 
25             if (-d "$dr/$_") {
26                 if ($_ !~ /\./) {
27                     @dirs = (@dirs,"$dr/$_");
28                 }
29             } elsif ($_ =~ /.java$/gio) {
30                 @java = (@java,"$dr/$_");
31             }
32         }
33         undef $d;
34     }
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";
46 %argcounts = {};
47 %argsig = {};
48 %argdefs = {};
49 %voids = {};
50 %docs = {};
52 sub processdoc() {
53     my @d = split(/\n/,$_[0]);
54     my $dfunc = $_[1];
55     my $sg = $_[2];
56     #print "$sg\n";
57     my $rdoc = "$sg\n";
58     foreach $d (@d) {
59         next if ($d =~ /\@pyexport/);
60         $d =~ s/\s*\*//;
61         $d =~ s/\@/\t/;
62         $rdoc .= "$d\n";
63         #print "$d\n";
64     }
65     if (defined($docs{$dfunc})) {
66         $docs{$dfunc} .= "\n$rdoc";
67     } else {
68         $docs{$dfunc} = "$rdoc";
69     }
72 foreach $java (@java) {
73     open(INFILE,$java);
74     $pyobj = "";
75     $doc = "";
76     $indoc = 0;
77     while(<INFILE>) {
78         $_ =~ s/\cM//gio;
79         if ($_ =~ /^\s*\/\*\*/) {
80             $indoc = 1;
81         } elsif ($_ =~ /^\s*\*\//) {
82             $indoc = 0;
83             if ($doc !~ /\@pyexport/) {
84                 $doc = "";
85             }
86             #$doc = "";
87         }
89         if (($indoc) && ($_ =~ /^\s*\*/)){
90             $doc .= $_;
91         }
93         chop($_);
94             
95         if ($_ =~ /\@pyobj\s+(.*)/) {
96             $pyobj = $1;
97             next;
98         }
99         if ($_ =~ /\@pyimport\s(.*)/) {
100             print OUTFILE $1."\n\n";
101             next;
102         }
103         if ($_ =~ /\@pyexport\s*(.*)/) {
104             $pyfun = $1;
105             $func = "";
106             while(<INFILE>) {
107                 chop($_);
108                 $func .= $_;
109                 last if (($_ =~ /\{/) || ($_ =~ /\;/));
110             }
111             ($func) = $func =~ /(public.*)/i;
112             $func =~ s/\s+/ /gio;
113             ($funcname) = $func =~ /(\S+)\s*\(/;
114             ($args) = $func =~ /\(([^\)]+)/;
115             @args = split(/\s*\,\s*/,$args);
116             $args = "";
117             $argc = $#argc;
118             foreach $arg (@args) {
119                 ($type,$name) = $arg =~ /(\S+)\s+(\S+)/;
120                 $args .= "$name,";
121             }
122             chop($args);
124             $void = "";
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;
133             #print "$sig\n";
134             if ($first =~ /\s+void\s+/gio) {
135                 $void = "";
136             } else {
137                 $void = "return ";
138             }
140             #print "$void\n";
142             if ($pyfun ne "") {
143                 if ($pyfun =~ /\(/) {
144                     # total override
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";
149                     next;
150                 } else {
151                     #print OUTFILE "def $pyfun($args):\n";
152                 }
153             } else {
154                 $pyfun = $funcname;
155                 #print OUTFILE "def $funcname($args):\n";
156             }
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);
166             $doc = "";
167         }       
168     }
169     #print "$java $pyobj\n" if ($pyobj ne "");
172 foreach $pyfun (keys %argcounts) {
173     next if ($pyfun =~ /HASH/);
174     #$print "$pyfun\n";
176     @argcs = split(/\|/,$argcounts{$pyfun});
177     shift(@argcs);
178     #print "$pyfun @argcs\n";
180     @argsig = split(/\|/,$argsig{$pyfun});
181     shift(@argsig);
183     @argdefs = split(/\|/,$argdefs{$pyfun});
184     shift(@argdefs);
186     @voids = split(/\|/,$voids{$pyfun});
187     shift(@voids);
189     #print "@voids\n";
191     if ($#argcs == 0) {
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";
196     } else {
197         print OUTFILE "def $pyfun(*d):\n";
198         print OUTFILE2 "def $pyfun(*d):\n";
199         $ifit = "if";
200         for ($i = 0 ; $i <= $#argcs ; $i++) {
201             $req = $argcs[$i];
202             $v = $voids[$i];
203             #print "$v\n";
204             $req++;
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++) {
210                 if ($d > 0) {
211                     print OUTFILE ",";
212                     print OUTFILE2 ",";
213                 }
214                 print OUTFILE "d[$d]";
215                 print OUTFILE2 "d[$d]";
216             }
217             print OUTFILE ")\n";
218             print OUTFILE2 ")\n";
219             $ifit = "elif";
220         }
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";
227     }
230 $dict = "";
232 foreach $key (keys %docs) {
233     next if ($key =~ /HASH/);
234     #print "$key\n$docs{$key}\n";
235     $f = $docs{$key};
236     $f =~ s/\n/\\n/gio;
237     $f =~ s/\t/\\t/gio;
238     $f =~ s/\"/\'/gio;
239     if ($dict eq "") {
240         $dict = "\"$key\" : \"$f\"";
241     } else {
242         $dict .= ", \"$key\" : \"$f\"";
243     }
246 #print "$dict\n";
248 print OUTFILE "\n\n__FUNCTION_DICTIONARY = {$dict}\n\n";
249 print OUTFILE2 "\n\n__FUNCTION_DICTIONARY = {$dict}\n\n";
251 close(OUTFILE);
252 close(OUTFILE2);
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");
258 __END__
259 :endofperl