2 # this tool generates JUST the autocvar declarations for cvars
15 my ($name, $type, $default, $force) = @_;
16 if(length $name >= 55)
18 warn "cvar $name is a Dr. honorificabilitudinitatibis causa BRLOGENSHFEGLE";
19 $type = 'cvar_toolong';
26 if(exists $cvars{$name} and not defined $cvars{name})
30 elsif(exists $cvars{$name} and $type ne $cvars{$name})
32 warn "cvar $name used with different types";
35 $defaults{$name} = $default;
36 $cvars{$name} = $type;
45 elsif(exists $cvars{$name} and exists $defaults{$name} and $default ne $defaults{$name})
47 warn "cvar $name used with different defaults";
50 $defaults{$name} = $default;
51 $cvars{$name} = $type;
61 $defaults{$name} = $default;
62 $cvars{$name} = $type;
68 print STDERR "In file $f\n";
73 if(/^\/\/#NO AUTOCVARS START/ .. /^\/\/#NO AUTOCVARS END/)
78 if(/^(?:var )?float autocvar_(\w+);$/)
80 found $1, 'cvar', 0, 1;
83 if(/^var float autocvar_(\w+) = (.*);$/)
85 found $1, 'cvar', $2, 1;
88 if(/^(?:var )?vector autocvar_(\w+);$/)
90 found $1, 'cvar_vector', "0 0 0", 1;
93 if(/^var vector autocvar_(\w+) = '(.*)';$/)
95 found $1, 'cvar_vector', $2, 1;
98 if(/^(?:var )?string autocvar_(\w+);$/)
100 found $1, 'cvar_string', "", 1;
103 if(/^var string autocvar_(\w+) = "(.*)";$/)
105 found $1, 'cvar_string', $2, 1;
108 if(/^#define autocvar_(\w+) cvar("\1")$/)
110 found $1, 'cvar', 0, 2;
113 if(/^#define autocvar_(\w+) cvar_or("\1", (.*))$/)
115 found $1, 'cvar', $1, 2;
118 if(/^#define autocvar_(\w+) cvar_string("\1")$/)
120 found $1, 'cvar_string', "", 2;
123 while(/\bcvar\s*\(\s*"(\w+)"\s*\)/g)
125 found $1, 'cvar', 0, 0;
127 while(/\bcvar_string\s*\(\s*"(\w+)"\s*\)/g)
129 found $1, 'cvar_string', "", 0;
131 while(/\bcvar_vector\s*\(\s*"(\w+)"\s*\)/g)
133 found $1, 'cvar_vector', "0 0 0", 0;
135 while(/\bcvar_or\s*\(\s*"(\w+)"\s*,\s*([^\s)]+)\s*\)/g)
137 found $1, 'cvar', $2, 0;
142 if($ENV{AUTOCVARING_SVQC})
144 for my $f(<menu/xonotic/*.c>)
146 print STDERR "In file $f\n";
147 open my $fh, "<", $f;
157 for my $f(<../maps/campaign*.txt>)
159 print STDERR "In file $f\n";
160 open my $fh, "<", $f;
171 for my $name(sort keys %cvars)
173 my $type = $cvars{$name};
174 my $menu = $menu{$name};
175 my $default = $defaults{$name};
176 die "wtf" if $name =~ /\0/;
177 if(not defined $type)
179 print "// cannot declare $name, it is used with different types\n";
181 elsif($type eq 'cvar_toolong')
183 print "// cannot declare $name, name is too long\n";
185 elsif($type eq 'cvar' and not $menu and $default eq "0")
187 print "float autocvar_$name;\n";
189 elsif($type eq 'cvar' and not $menu and $default ne "0")
191 print "var float autocvar_$name = $default;\n";
193 elsif($type eq 'cvar_vector' and not $menu and $default eq "0 0 0")
195 print "vector autocvar_$name;\n";
197 elsif($type eq 'cvar_vector' and not $menu and $default ne "0 0 0")
199 print "var vector autocvar_$name = '$default';\n";
201 elsif($type eq 'cvar_string' and not $menu and $default eq "")
203 print "string autocvar_$name;\n";
205 elsif($type eq 'cvar_string' and not $menu and $default ne "")
207 print "var string autocvar_$name = \"$default\";\n";
209 elsif($type eq 'cvar' and $menu and $default eq "0")
211 print "#define autocvar_$name cvar(\"$name\")\n";
213 elsif($type eq 'cvar' and $menu and $default ne "0")
215 print "#define autocvar_$name cvar_or(\"$name\", \"$default\")\n";
217 elsif($type eq 'cvar_string' and $menu) # sorry, no cvar_or for these
219 print "#define autocvar_$name cvar_string(\"$name\")\n";
221 elsif($type eq 'cvar_vector' and $menu) # sorry, no cvar_or for these
223 print "#define autocvar_$name cvar_vector(\"$name\")\n";
229 print STDERR "In file $f\n";
230 open my $fh, "<", $f;
235 if(/^\/\/#NO AUTOCVARS START/ .. /^\/\/#NO AUTOCVARS END/)
240 if(/^(?:var )?float autocvar_(.*);$/)
245 if(/^(?:var )?string autocvar_(.*);$/)
250 if(/^#define autocvar_(.*) cvar/)
255 s{\b(cvar|cvar_string|cvar_vector|cvar_or)\s*\(\s*"([^"]+)"\s*(?:,\s*[^\s)]+\s*)?\)}{
256 my ($type, $name) = ($1, $2);
257 $type = 'cvar' if $type eq 'cvar_or';
258 my $realtype = $cvars{$name};
260 if(defined $realtype)
262 #$r = "$realtype(\"$name\")";
263 $r = "autocvar_$name";
264 if($type eq 'cvar' && $realtype eq 'cvar_string')
268 if($type eq 'cvar_string' && $realtype eq 'cvar')