#!/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.

($basename = $ARGV[0]) =~ s/.*\/(\w+).idl/$1/;
$class = $basename."Proxy";

$id = 0;
while (<>)
{
	m/(\w+)\((.*)\)/;
	$name = $1;
	$paras = $2;

	@para = split /\s*,\s*/, $paras;
	@var = ();

	foreach $para (@para)
	{
		@pair = split /\s+/, $para;
		$para = "const $pair[0]& $pair[1]";
		push @var, $pair[1];
	}

	@para = ('const grapple_user& client', @para);

	$" = ', ';
	print "void ".$class."::$name(@para) {\n";
	print "ByteArrayOutputStream baos;\n";
	print "baos.write($id);\n";
	print "DataOutputStream dos(baos);\n";

	foreach $var (@var)
	{
		print "write(dos, $var);\n";
	}

	print "mNetwork.send(baos.byteArray(), client);\n";

	print "}\n";
	print "\n";

	$id++;
}
