12 my $parsing_builtins = undef;
13 my $parsing_builtin = 0;
15 my $parsing_fields = undef;
16 my $parsing_globals = undef;
17 my $parsing_vm = undef;
19 for(<../*.h>, <../*.c>)
41 elsif(/^prvm_builtin_t vm_m_/)
43 $parsing_builtins = "menu";
46 elsif(/^prvm_builtin_t vm_cl_/)
48 $parsing_builtins = "csprogs";
51 elsif(/^prvm_builtin_t vm_sv_/)
53 $parsing_builtins = "progs";
58 $parsing_builtins = undef;
59 $parsing_globals = undef;
60 $parsing_fields = undef;
63 elsif(/^typedef struct entvars_s$/)
65 $parsing_fields = "fields";
66 $parsing_vm = "progs";
68 elsif(/^typedef struct cl_entvars_s$/)
70 $parsing_fields = "fields";
71 $parsing_vm = "csprogs";
73 elsif(/^typedef struct prvm_prog_fieldoffsets_s$/)
75 $parsing_fields = "fields";
77 elsif(/^typedef struct globalvars_s$/)
79 $parsing_globals = "globals";
80 $parsing_vm = "progs";
82 elsif(/^typedef struct cl_globalvars_s$/)
84 $parsing_globals = "globals";
85 $parsing_vm = "csprogs";
87 elsif(/^typedef struct m_globalvars_s$/)
89 $parsing_globals = "globals";
92 elsif(/^typedef struct prvm_prog_globaloffsets_s$/)
94 $parsing_globals = "globals";
96 elsif($parsing_builtins)
104 $parsing_builtin += 1;
106 elsif(/^(\w+)\s*,?\s*\/\/\s+#(\d+)\s*(.*)/)
109 my $builtin = int $2;
111 my $extension = "DP_UNKNOWN";
113 if($descr =~ s/\s+\(([0-9A-Z_]*)\)//)
117 # 'void(vector ang) makevectors'
122 elsif($descr eq "draw functions...")
125 elsif($descr =~ /^\/\//)
128 elsif($descr =~ /\) (\w+)/)
132 elsif($descr =~ /(\w+)\s*\(/)
136 elsif($descr =~ /^\w+$/)
142 warn "No function name found in $descr";
145 warn "builtin sequence error: #$builtin (expected: $parsing_builtin)"
146 if $builtin != $parsing_builtin;
147 $parsing_builtin = $builtin + 1;
148 $vm{$parsing_builtins}{builtins}[$builtin] = [0, $func, $extension];
152 warn "Fails to parse: $_";
155 elsif($parsing_fields || $parsing_globals)
157 my $f = $parsing_fields || $parsing_globals;
161 elsif(/^\s+(?:int|float|string_t|vec3_t|func_t)\s+(\w+);\s*(?:\/\/(.*))?/)
164 my $descr = $2 || "";
165 my $extension = "DP_UNKNOWN";
167 if $descr =~ /\b([0-9A-Z_]+)\b/;
169 $vm{menu}{$f}{$name} = ($found = [0, $extension])
170 if $descr =~ /common|menu/;
171 $vm{progs}{$f}{$name} = ($found = [0, $extension])
172 if $descr =~ /common|ssqc/;
173 $vm{csprogs}{$f}{$name} = ($found = [0, $extension])
174 if $descr =~ /common|csqc/;
175 $vm{$parsing_vm}{$f}{$name} = ($found = [0, $extension])
176 if not defined $found and defined $parsing_vm;
177 warn "$descr does not yield info about target VM"
178 if not defined $found;
181 elsif(/getglobal\w*\(\w+, "(\w+)"\)/)
183 # hack for weird DP source
184 $vm{csprogs}{globals}{$1} = [0, "DP_CSQC_SPAWNPARTICLE"];
192 ["csprogsdefs.qc", "csprogs"],
193 ["dpextensions.qc", "progs"],
194 ["menudefs.qc", "menu"],
195 ["progsdefs.qc", "progs"]
198 my ($file, $v) = @$_;
199 open my $fh, "<", "$file"
204 if(/^(?:float|entity|string|vector)\s+((?:\w+\s*,\s*)*\w+)\s*;/)
206 for(split /\s*,\s*/, $1)
208 print "// $v: Global $_ declared but not defined\n"
209 if not $vm{$v}{globals}{$_};
210 $vm{$v}{globals}{$_}[0] = 1; # documented!
213 elsif(/^\.(?:float|entity|string|vector|void)(?:.*\))?\s+((?:\w+\s*,\s*)*\w+)\s*;/)
215 for(split /\s*,\s*/, $1)
217 print "// $v: Field $_ declared but not defined\n"
218 if not $vm{$v}{fields}{$_};
219 $vm{$v}{fields}{$_}[0] = 1; # documented!
224 print "// $v: Builtin #$1 declared but not defined\n"
225 if not $vm{$v}{builtins}[$1];
226 $vm{$v}{builtins}[$1][0] = 1; # documented!
236 for my $v(sort keys %vm)
238 print "/******************************************\n";
240 print " ******************************************/\n";
241 my $b = $vm{$v}{builtins};
244 next if not defined $b->[$_];
245 my ($documented, $func, $extension) = @{$b->[$_]};
246 print "float $func(...) = #$_; // $extension\n"
249 my $g = $vm{$v}{globals};
252 my ($documented, $extension) = @{$g->{$_}};
253 print "float $_; // $extension\n"
256 my $f = $vm{$v}{fields};
259 my ($documented, $extension) = @{$f->{$_}};
260 print ".float $_; // $extension\n"
268 $Data::Dumper::Sortkeys = 1;