#!/usr/bin/perl
# this tool generates JUST the autocvar declarations for cvars
use strict;
use warnings;
my @files = @ARGV;
my %cvars = ();
my %old = ();
my %menu = ();
my %defaults = ();
sub found($$$$)
{
my ($name, $type, $default, $force) = @_;
if(length $name >= 55)
{
warn "cvar $name is a Dr. honorificabilitudinitatibis causa BRLOGENSHFEGLE";
$type = 'cvar_toolong';
return;
}
# $old{$name} = 1
# if $force;
# $menu{$name} = 1
# if $force > 1;
if(exists $cvars{$name} and not defined $cvars{name})
{
# have already warned
}
elsif(exists $cvars{$name} and $type ne $cvars{$name})
{
warn "cvar $name used with different types";
if($force)
{
$defaults{$name} = $default;
$cvars{$name} = $type;
}
else
{
undef $cvars{$name}
unless $old{$name};
}
return;
}
elsif(exists $cvars{$name} and exists $defaults{$name} and $default ne $defaults{$name})
{
warn "cvar $name used with different defaults";
if($force)
{
$defaults{$name} = $default;
$cvars{$name} = $type;
}
else
{
undef $cvars{$name}
unless $old{$name};
}
}
else
{
$defaults{$name} = $default;
$cvars{$name} = $type;
}
}
for my $f(@files)
{
print STDERR "In file $f\n";
open my $fh, "<", $f;
while(<$fh>)
{
chomp;
if(/^\/\/#NO AUTOCVARS START/ .. /^\/\/#NO AUTOCVARS END/)
{
next;
}
s/\/\/.*//;
if(/^(?:var )?float autocvar_(\w+);$/)
{
found $1, 'cvar', 0, 1;
next;
}
if(/^var float autocvar_(\w+) = (.*);$/)
{
found $1, 'cvar', $2, 1;
next;
}
if(/^(?:var )?vector autocvar_(\w+);$/)
{
found $1, 'cvar_vector', "0 0 0", 1;
next;
}
if(/^var vector autocvar_(\w+) = '(.*)';$/)
{
found $1, 'cvar_vector', $2, 1;
next;
}
if(/^(?:var )?string autocvar_(\w+);$/)
{
found $1, 'cvar_string', "", 1;
next;
}
if(/^var string autocvar_(\w+) = "(.*)";$/)
{
found $1, 'cvar_string', $2, 1;
next;
}
if(/^#define autocvar_(\w+) cvar("\1")$/)
{
found $1, 'cvar', 0, 2;
next;
}
if(/^#define autocvar_(\w+) cvar_or("\1", (.*))$/)
{
found $1, 'cvar', $1, 2;
next;
}
if(/^#define autocvar_(\w+) cvar_string("\1")$/)
{
found $1, 'cvar_string', "", 2;
next;
}
while(/\bcvar\s*\(\s*"(\w+)"\s*\)/g)
{
found $1, 'cvar', 0, 0;
}
while(/\bcvar_string\s*\(\s*"(\w+)"\s*\)/g)
{
found $1, 'cvar_string', "", 0;
}
while(/\bcvar_vector\s*\(\s*"(\w+)"\s*\)/g)
{
found $1, 'cvar_vector', "0 0 0", 0;
}
while(/\bcvar_or\s*\(\s*"(\w+)"\s*,\s*([^\s)]+)\s*\)/g)
{
found $1, 'cvar', $2, 0;
}
}
}
if($ENV{AUTOCVARING_SVQC})
{
for my $f(