<?php
function compile($dirname, $sourcefile) {
	$out = array("interror" => 0, "retval" => 0, "stdout" => "", "stderr" => "");

	$fd_conf = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
	$pp = proc_open("javac -Xlint $sourcefile", $fd_conf, $fd, "$dirname");
	if(!$pp) {
		$out["interror"] = 1;
		$out["stderr"] = "Can't compile tempfile";
		return $out;
	}

	$out["stdout"] = stream_get_contents($fd[1]);
	$out["stderr"] = stream_get_contents($fd[2]);
	$ret = proc_close($pp);
	$out["retval"] = $ret;

	return $out;
}

function compile_test($dirname, $sourcefile, $testno, $sid, $link) {
	include_once("test_helper.php");

	$compile_ret = compile($dirname, $sourcefile);
	save_test($compile_ret, 1, $sid, $link);

	/*
	while(list($key, $val) = each($compile_ret)) {
		echo "$key =&gt; $val <BR>\n";
	}
	*/

	return $compile_ret;
}
?>
