
# $Id$

if ($#ARGV eq -1) {
    @ARGV=`ls *.c`;
    chop(@ARGV);
}

print qq(/* THIS FILE WAS AUTOGENERATED BY STUBGEN.PL --- DO NOT EDIT BY HAND!!! */\n\n);
print qq(#include "owl.h");

foreach $file (@ARGV) {
    open(FILE, $file);

    print "/* -------------------------------- $file -------------------------------- */\n";
    while (<FILE>) {
	if (m|^\s*OWLVAR_([A-Z_0-9]+)\s*\(\s*"([^"]+)"\s*/\*\s*%OwlVarStub:?([a-z0-9_]+)?\s*\*/|) {   # "
    my $vartype = $1;
    my $varname = $2;
    my $altvarname = $2;
    $altvarname = $3 if ($3);
    if ($vartype =~ /^BOOL/) {
	print "void owl_global_set_${altvarname}_on(owl_global *g) {\n";
	print "  owl_variable_set_bool_on(&g->vars, \"$varname\");\n}\n";
	print "void owl_global_set_${altvarname}_off(owl_global *g) {\n";
	print "  owl_variable_set_bool_off(&g->vars, \"$varname\");\n}\n";
	print "int owl_global_is_$altvarname(owl_global *g) {\n";
	print "  return owl_variable_get_bool(&g->vars, \"$varname\");\n}\n";
    } elsif ($vartype =~ /^PATH/ or $vartype =~ /^STRING/) {
	print "void owl_global_set_$altvarname(owl_global *g, char *text) {\n";
	print "  owl_variable_set_string(&g->vars, \"$varname\", text);\n}\n";
	print "char *owl_global_get_$altvarname(owl_global *g) {\n";
	print "  return owl_variable_get_string(&g->vars, \"$varname\");\n}\n";
    } elsif ($vartype =~ /^INT/ or $vartype =~ /^ENUM/) {
	print "void owl_global_set_$altvarname(owl_global *g, int n) {\n";
	print "  owl_variable_set_int(&g->vars, \"$varname\", n);\n}\n";
	print "int owl_global_get_$altvarname(owl_global *g) {\n";
	print "  return owl_variable_get_int(&g->vars, \"$varname\");\n}\n";
    } 
    }
    }
    close(FILE);
    print "\n";
}
