#!/usr/bin/perl -w
# CG Madness - a Marble Madness clone
# Copyright (C) 2007  Sven Reinck <sreinck@gmail.com>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

print "switch (bais.read()) {\n";

$id = 0;

while (<>)
{
	m/(\w+)\((.*)\)/;
	$name = $1;
	$paras = $2;
	@para = split /\s*,\s*/, $paras;

	print "case $id: {\n";

	foreach $index (0..(@para-1))
	{
		@pair = split /\s+/, $para[$index];
		print "$pair[0] $pair[1]; ";
		print "read(dis, $pair[1]);\n";
		$para[$index] = $pair[1];
	}

	@para = ('package.sender()', @para);

	$" = ', ';
	print "$name(@para);\n";
	print "break;\n";
	print "}\n";

	$id++;
}
print "}\n";
