
# Generate code for speedy_perl.c to fill in the perlvars array.

my @vars = (
    #
    # Perl-type
    # Part of our package (CGI::SpeedyCGI)
    # Perl Name
    # Our name, optional
    #
    ['SVt_PVHV',  0, 'ENV'],
    ['SVt_PVAV',  0, 'ARGV'],
    ['SVt_PVIO',  0, 'STDIN'],
    ['SVt_PVIO',  0, 'STDOUT'],
    ['SVt_PVIO',  0, 'STDERR'],
    ['SVt_PV',	  0, '0',			'PROGRAM_NAME'],
    ['SVt_PV',	  0, '@',			'EVAL_ERROR'],
    ['SVt_PVCV',  0, 'CGI::_reset_globals'],
    ['SVt_IV',    1, '_opts_changed'],
    ['SVt_PVHV',  1, '_opts'],
    ['SVt_PVCV',  1, '_run_shutdown'],
    ['SVt_PV',    1, '_sub'],
    ['SVt_IV',    1, 'i_am_speedy'],
    ['SVt_PVCV',  1, '_run_cleanup'],
    ['SVt_PVCV',  1, '_fork'],
);
my $myname = 'util/perlvars';

print "/* Generated by $myname */\n\n";

sub def { my($name, $value) = @_;
    printf("#define %-25s %s\n", uc($name), $value);
}

my $i = 0;
foreach (@vars) {
    my($type, $ours, $plname, $name) = @$_;
    
    my $cast = 'SV';
    if ($type =~ /SVt_PV(..)/) {
	$cast = $1;
	$cast = 'GV' if ($cast eq 'IO');
    }

    $name ||= $plname;
    $name =~ s/.*::_*//;
    $name =~ s/^_+//;
    &def("PERLVAR_$name", "(SpeedyPerlVars[$i])");
    &def("PERLVAL_$name", "((${cast}*)(SpeedyPerlVars[$i].ptr))");
    ++$i;
}
&def('PERLVAR_COUNT', $i);

print "\nstatic SpeedyPerlVar SpeedyPerlVars[] = {\n";
foreach (@vars) {
    my($type, $ours, $plname) = @$_;

    printf("    {NULL, %-8s , %s%s},\n",
	$type, $ours ? "SPEEDY_PKG(\"$plname\")" : "\"$plname\""
    );
}
print "};\n\n";

print "/* End of generated section */\n";
