2 # this tool generates JUST the autocvar declarations for cvars
14 my ($name, $type, $force) = @_;
19 if(exists $cvars{$name} and $type ne $cvars{$name})
21 warn "cvar $name used with different types";
24 $cvars{$name} = $type;
35 $cvars{$name} = $type;
41 print STDERR "In file $f\n";
46 if(/^\/\/#NO AUTOCVARS START/ .. /^\/\/#NO AUTOCVARS END/)
51 if(/^float autocvar_(.*);$/)
56 if(/^string autocvar_(.*);$/)
58 found $1, 'cvar_string', 1;
61 if(/^#define autocvar_(.*) cvar("\1")$/)
66 if(/^#define autocvar_(.*) cvar_string("\1")$/)
68 found $1, 'cvar_string', 2;
71 while(/\b(cvar|cvar_string)\s*\(\s*"([^"]+)"\s*\)/g)
78 for my $f(<../menu/nexuiz/*.c>)
80 print STDERR "In file $f\n";
91 for my $f(<../../maps/campaign*.txt>)
93 print STDERR "In file $f\n";
104 for my $name(sort keys %cvars)
106 my $type = $cvars{$name};
107 my $menu = $menu{$name};
108 if(not defined $type)
110 print "// cannot declare $name, it is used with different types\n";
112 if($type eq 'cvar' and not $menu)
114 print "float autocvar_$name;\n";
116 if($type eq 'cvar_string' and not $menu)
118 print "string autocvar_$name;\n";
120 if($type eq 'cvar' and $menu)
122 print "#define autocvar_$name cvar(\"$name\")\n";
124 if($type eq 'cvar_string' and $menu)
126 print "#define autocvar_$name cvar_string(\"$name\")\n";
132 print STDERR "In file $f\n";
133 open my $fh, "<", $f;
138 if(/^\/\/#NO AUTOCVARS START/ .. /^\/\/#NO AUTOCVARS END/)
143 if(/^float autocvar_(.*);$/)
148 if(/^string autocvar_(.*);$/)
153 if(/^#define autocvar_(.*) cvar("\1")$/)
158 if(/^#define autocvar_(.*) cvar_string("\1")$/)
163 s{\b(cvar|cvar_string)\s*\(\s*"([^"]+)"\s*\)}{
164 my ($type, $name) = ($1, $2);
165 my $realtype = $cvars{$name};
167 if(defined $realtype)
169 #$r = "$realtype(\"$name\")";
170 $r = "autocvar_$name";
171 if($type eq 'cvar' && $realtype eq 'cvar_string')
175 if($type eq 'cvar_string' && $realtype eq 'cvar')